Cleanup & refactor
This commit is contained in:
parent
a8ecb75b2d
commit
9f3d83af65
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,47 +0,0 @@
|
||||||
#!/bin/python3
|
|
||||||
|
|
||||||
# Copyright (C) 2022 Libre en Communs <contact@a-lec.org>
|
|
||||||
# Copyright (C) 2022 Adrien Bourmault <neox@a-lec.org>
|
|
||||||
# Copyright (C) 2022 Jean Sirmai <jean@a-lec.org>
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import signal
|
|
||||||
import locale
|
|
||||||
import gettext
|
|
||||||
|
|
||||||
VERSION = '0.0.1'
|
|
||||||
#pkgdatadir = '@pkgdatadir@'
|
|
||||||
#localedir = '@localedir@'
|
|
||||||
|
|
||||||
#sys.path.insert(1, pkgdatadir)
|
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
||||||
#locale.bindtextdomain('gemgraph', localedir)
|
|
||||||
#locale.textdomain('gemgraph')
|
|
||||||
#gettext.install('gemgraph', localedir)
|
|
||||||
|
|
||||||
if __name__ == "__main__" and __package__ is None:
|
|
||||||
__package__ = "gemgraph"
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
import gi
|
|
||||||
|
|
||||||
from gi.repository import Gio
|
|
||||||
#resource = Gio.Resource.load(os.path.join(pkgdatadir, 'gemgraph.gresource'))
|
|
||||||
#resource._register()
|
|
||||||
|
|
||||||
from gemgraph import main
|
|
||||||
sys.exit(main.main(VERSION))
|
|
|
@ -1,207 +0,0 @@
|
||||||
# main.py
|
|
||||||
#
|
|
||||||
# Copyright (C) 2022 Libre en Communs <contact@a-lec.org>
|
|
||||||
# Copyright (C) 2022 Adrien Bourmault <neox@a-lec.org>
|
|
||||||
# Copyright (C) 2022 Jean Sirmai <jean@a-lec.org>
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import gi
|
|
||||||
|
|
||||||
gi.require_version('Gtk', '4.0')
|
|
||||||
gi.require_version('Adw', '1')
|
|
||||||
|
|
||||||
from gi.repository import Gtk, Gio, Adw
|
|
||||||
from .window import GemGraphWindow, AboutDialog
|
|
||||||
|
|
||||||
|
|
||||||
ENABLE = True
|
|
||||||
DISABLE = False
|
|
||||||
|
|
||||||
|
|
||||||
class GemGraphApplication(Adw.Application):
|
|
||||||
"""The main application singleton class."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__(application_id='org.example.App',
|
|
||||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
|
||||||
|
|
||||||
# Create base actions
|
|
||||||
self.create_action('quit', self.quit, ENABLE, ['<primary>q'])
|
|
||||||
self.create_action('about', self.on_about_action, ENABLE)
|
|
||||||
self.create_action('preferences', self.on_preferences_action, ENABLE)
|
|
||||||
self.create_action('togglesidebar', self.on_togglesidebar_action, ENABLE)
|
|
||||||
|
|
||||||
# Create later actions (mode)
|
|
||||||
self.editmode_action = \
|
|
||||||
self.create_action(
|
|
||||||
'editmode',
|
|
||||||
self.on_editmode_action,
|
|
||||||
DISABLE,
|
|
||||||
['<primary>e'])
|
|
||||||
|
|
||||||
self.runmode_action = \
|
|
||||||
self.create_action(
|
|
||||||
'runmode',
|
|
||||||
self.on_runmode_action,
|
|
||||||
DISABLE,
|
|
||||||
['<primary>r'])
|
|
||||||
|
|
||||||
self.presentmode_action = \
|
|
||||||
self.create_action(
|
|
||||||
'presentmode',
|
|
||||||
self.on_presentmode_action,
|
|
||||||
DISABLE,
|
|
||||||
['<primary>p'])
|
|
||||||
|
|
||||||
# Create file actions
|
|
||||||
self.create_action('openfile', self.do_open, ENABLE)
|
|
||||||
|
|
||||||
self.close_action = \
|
|
||||||
self.create_action(
|
|
||||||
'closefile',
|
|
||||||
self.on_close_action,
|
|
||||||
DISABLE)
|
|
||||||
|
|
||||||
self.save_action = \
|
|
||||||
self.create_action(
|
|
||||||
'savefile',
|
|
||||||
self.on_save_action,
|
|
||||||
DISABLE,
|
|
||||||
['<primary>s'])
|
|
||||||
|
|
||||||
def do_activate(self):
|
|
||||||
"""Called when the application is activated.
|
|
||||||
|
|
||||||
We raise the application's main window, creating it if
|
|
||||||
necessary.
|
|
||||||
"""
|
|
||||||
print("app.do_activate called")
|
|
||||||
win = self.props.active_window
|
|
||||||
if not win:
|
|
||||||
win = GemGraphWindow(application=self)
|
|
||||||
|
|
||||||
# Display home mode by default
|
|
||||||
win.stack_switch_mode("home")
|
|
||||||
win.present()
|
|
||||||
|
|
||||||
def do_open(self, widget, _):
|
|
||||||
"""Called when the application is activated with a file to open.
|
|
||||||
|
|
||||||
We raise the application's main window, creating it if
|
|
||||||
necessary.
|
|
||||||
|
|
||||||
Also a callback for the app.openfile action
|
|
||||||
"""
|
|
||||||
print("app.do_open called")
|
|
||||||
win = self.props.active_window
|
|
||||||
if not win:
|
|
||||||
win = GemGraphWindow(application=self)
|
|
||||||
|
|
||||||
# Open file
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Activate file actions
|
|
||||||
self.close_action.set_enabled(True)
|
|
||||||
self.save_action.set_enabled(True)
|
|
||||||
|
|
||||||
# Activate mode actions
|
|
||||||
self.runmode_action.set_enabled(True)
|
|
||||||
self.editmode_action.set_enabled(True)
|
|
||||||
self.presentmode_action.set_enabled(True)
|
|
||||||
|
|
||||||
# Display edit mode
|
|
||||||
win.stack_switch_mode("edit")
|
|
||||||
win.present()
|
|
||||||
|
|
||||||
def on_close_action(self, widget, _):
|
|
||||||
"""Callback for the app.closefile action."""
|
|
||||||
print('app.closefile action activated')
|
|
||||||
win = self.props.active_window
|
|
||||||
|
|
||||||
# Disable file actions
|
|
||||||
self.close_action.set_enabled(False)
|
|
||||||
self.save_action.set_enabled(False)
|
|
||||||
|
|
||||||
# Disable mode actions
|
|
||||||
self.runmode_action.set_enabled(False)
|
|
||||||
self.editmode_action.set_enabled(False)
|
|
||||||
self.presentmode_action.set_enabled(False)
|
|
||||||
|
|
||||||
# Get home
|
|
||||||
win.stack_switch_mode("home")
|
|
||||||
|
|
||||||
def on_save_action(self, widget, _):
|
|
||||||
"""Callback for the app.savefile action."""
|
|
||||||
print('app.savefile action activated')
|
|
||||||
win = self.props.active_window
|
|
||||||
|
|
||||||
def on_about_action(self, widget, _):
|
|
||||||
"""Callback for the app.about action."""
|
|
||||||
about = AboutDialog(self.props.active_window)
|
|
||||||
about.present()
|
|
||||||
|
|
||||||
def on_preferences_action(self, widget, _):
|
|
||||||
"""Callback for the app.preferences action."""
|
|
||||||
print('app.preferences action activated')
|
|
||||||
win = self.props.active_window
|
|
||||||
win.send_toast("Not implemented at this time (sorry!)")
|
|
||||||
|
|
||||||
def on_editmode_action(self, widget, _):
|
|
||||||
"""Callback for the app.editmode action."""
|
|
||||||
print('app.editmode action activated')
|
|
||||||
win = self.props.active_window
|
|
||||||
win.stack_switch_mode("edit")
|
|
||||||
|
|
||||||
def on_runmode_action(self, widget, _):
|
|
||||||
"""Callback for the app.runmode action."""
|
|
||||||
print('app.runmode action activated')
|
|
||||||
win = self.props.active_window
|
|
||||||
win.stack_switch_mode("run")
|
|
||||||
|
|
||||||
def on_presentmode_action(self, widget, _):
|
|
||||||
"""Callback for the app.presentmode action."""
|
|
||||||
print('app.presentmode action activated')
|
|
||||||
win = self.props.active_window
|
|
||||||
win.stack_switch_mode("presentation")
|
|
||||||
|
|
||||||
def on_togglesidebar_action(self, widget, _):
|
|
||||||
"""Callback for the app.togglesidebar action."""
|
|
||||||
print('app.togglesidebar action activated')
|
|
||||||
win = self.props.active_window
|
|
||||||
win.toggle_sidebar()
|
|
||||||
|
|
||||||
def create_action(self, name, callback, is_enabled, shortcuts=None):
|
|
||||||
"""Add an application action.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
name: the name of the action
|
|
||||||
callback: the function to be called when the action is
|
|
||||||
activated
|
|
||||||
shortcuts: an optional list of accelerators
|
|
||||||
"""
|
|
||||||
action = Gio.SimpleAction.new(name, None)
|
|
||||||
action.connect("activate", callback)
|
|
||||||
action.set_enabled(is_enabled)
|
|
||||||
self.add_action(action)
|
|
||||||
if shortcuts:
|
|
||||||
self.set_accels_for_action(f"app.{name}", shortcuts)
|
|
||||||
return action
|
|
||||||
|
|
||||||
|
|
||||||
def main(version):
|
|
||||||
"""The application's entry point."""
|
|
||||||
app = GemGraphApplication()
|
|
||||||
return app.run(sys.argv)
|
|
|
@ -1,82 +0,0 @@
|
||||||
# window.py
|
|
||||||
#
|
|
||||||
# Copyright (C) 2022 Libre en Communs <contact@a-lec.org>
|
|
||||||
# Copyright (C) 2022 Adrien Bourmault <neox@a-lec.org>
|
|
||||||
# Copyright (C) 2022 Jean Sirmai <jean@a-lec.org>
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
|
|
||||||
from gi.repository import Gtk, Adw
|
|
||||||
|
|
||||||
|
|
||||||
@Gtk.Template(filename='ui/gemgraph.ui')
|
|
||||||
class GemGraphWindow(Gtk.ApplicationWindow):
|
|
||||||
"""
|
|
||||||
Window class
|
|
||||||
"""
|
|
||||||
__gtype_name__ = 'main'
|
|
||||||
|
|
||||||
main_stack = Gtk.Template.Child()
|
|
||||||
side_stack = Gtk.Template.Child()
|
|
||||||
main_paned = Gtk.Template.Child()
|
|
||||||
main_button_mode = Gtk.Template.Child()
|
|
||||||
toast_overlay = Gtk.Template.Child()
|
|
||||||
main_button_sidebar = Gtk.Template.Child()
|
|
||||||
|
|
||||||
__mode_icon = {
|
|
||||||
"mode_home":"user-home-symbolic" ,
|
|
||||||
"mode_edit":"document-edit-symbolic" ,
|
|
||||||
"mode_run":"system-run-symbolic" ,
|
|
||||||
"mode_presentation":"x-office-presentation-symbolic"
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
|
|
||||||
def toggle_sidebar(self):
|
|
||||||
"""
|
|
||||||
Sets the sidebar position to open or closed
|
|
||||||
"""
|
|
||||||
position = self.main_paned.get_position()
|
|
||||||
|
|
||||||
if position != 0:
|
|
||||||
self.main_paned.set_position(0)
|
|
||||||
else:
|
|
||||||
self.main_paned.set_position(300)
|
|
||||||
|
|
||||||
self.main_button_sidebar.toggled()
|
|
||||||
|
|
||||||
def stack_switch_mode(self, mode):
|
|
||||||
"""
|
|
||||||
Sets the active mode from stack. Mode is the name of the mode (string)
|
|
||||||
"""
|
|
||||||
self.main_stack.set_visible_child_full("main_"+mode, Gtk.StackTransitionType.CROSSFADE)
|
|
||||||
self.side_stack.set_visible_child_full("side_"+mode, Gtk.StackTransitionType.CROSSFADE)
|
|
||||||
self.main_button_mode.props.icon_name = self.__mode_icon["mode_"+mode]
|
|
||||||
|
|
||||||
def send_toast(self, message):
|
|
||||||
self.toast_overlay.add_toast(Adw.Toast(title=message))
|
|
||||||
|
|
||||||
class AboutDialog(Gtk.AboutDialog):
|
|
||||||
|
|
||||||
def __init__(self, parent):
|
|
||||||
Gtk.AboutDialog.__init__(self)
|
|
||||||
self.props.program_name = 'GemGraph'
|
|
||||||
self.props.version = "0.0.0"
|
|
||||||
self.props.authors = ['Adrien Bourmault', 'Jean Sirmai']
|
|
||||||
self.props.copyright = 'Copyright © 2022 Libre en Communs'
|
|
||||||
self.props.logo_icon_name = 'application-x-executable'
|
|
||||||
self.props.modal = True
|
|
||||||
self.set_transient_for(parent)
|
|
||||||
|
|
Loading…
Reference in New Issue