#!/usr/bin/python3

# Graphs
# Plot and manipulate data
#
# https://apps.gnome.org/Graphs/
# https://gitlab.gnome.org/World/Graphs
#
# Copyright 2022 - 2024 Sjoerd Stendahl et al.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Main graphs module."""

import gettext
import locale
import logging
import os
import signal
import sys


if __name__ == "__main__":
    import gi

    gi.require_version("Adw", "1")
    gi.require_version("Gtk", "4.0")
    gi.require_version("Graphs", "1")

    graph_path_dir = "/usr/share/graphs"
    if os.environ.get("GRAPHS_DEVEL_PATH"):
        graph_path_dir = os.environ.get("GRAPHS_DEVEL_PATH")
    sys.path.insert(1, graph_path_dir)
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    localedir = "/usr/share/locale"
    if os.environ.get('GRAPHS_OVERRIDE_LOCALEDIR'):
        localedir = os.environ.get('GRAPHS_OVERRIDE_LOCALEDIR')
    locale.bindtextdomain("graphs", localedir)
    locale.textdomain("graphs")
    gettext.bindtextdomain("graphs", localedir)
    gettext.textdomain("graphs")

    from gi.repository import Gio
    gresource_location = os.path.join("/usr/share/graphs", "se.sjoerd.Graphs.gresource")
    if os.environ.get("GRAPHS_OVERRIDE_RESOURCES"):
        gresource_location = os.environ.get('GRAPHS_OVERRIDE_RESOURCES')
    resource = Gio.Resource.load(gresource_location)
    resource._register()

    debug = False

    loglevel = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(format="%(levelname)s: %(message)s", level=loglevel)
    logging.getLogger("matplotlib.font_manager").disabled = True

    from graphs.application import PythonApplication
    sys.exit(PythonApplication("se.sjoerd.Graphs", debug=debug).run(sys.argv))
