diff --git a/gemgraph/main.py b/gemgraph/main.py index 86591de..4fe60c0 100644 --- a/gemgraph/main.py +++ b/gemgraph/main.py @@ -65,18 +65,26 @@ class GemGraphApplication(Adw.Application): 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, shortcuts=None): """Add an application action. diff --git a/gemgraph/window.py b/gemgraph/window.py index e3a00a0..8364bdc 100644 --- a/gemgraph/window.py +++ b/gemgraph/window.py @@ -22,14 +22,61 @@ from gi.repository import Gtk @Gtk.Template(filename='ui/gemgraph.ui') class GemGraphWindow(Gtk.ApplicationWindow): + """ + Window class + """ __gtype_name__ = 'main' - # label = Gtk.Template.Child() + main_stack = Gtk.Template.Child() + side_stack = Gtk.Template.Child() + main_paned = Gtk.Template.Child() + main_box_edit = Gtk.Template.Child() + main_box_run = Gtk.Template.Child() + main_box_presentation = Gtk.Template.Child() + side_box_edit = Gtk.Template.Child() + side_box_run = Gtk.Template.Child() + side_box_presentation = Gtk.Template.Child() + + __STACK_OK = False def __init__(self, **kwargs): super().__init__(**kwargs) + def init_stack(self): + # Init both mode stacks + self.main_stack.add_named(self.main_box_edit, "main_box_edit") + self.main_stack.add_named(self.main_box_run, "main_box_run") + self.main_stack.add_named(self.main_box_presentation, + "main_box_presentation") + self.side_stack.add_named(self.side_box_edit, "side_box_edit") + self.side_stack.add_named(self.side_box_run, "side_box_run") + self.side_stack.add_named(self.side_box_presentation, + "side_box_presentation") + + 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(250) + + def stack_switch_mode(self, mode): + """ + Sets the active mode from stack. Mode is the name of the mode (string) + """ + + if not self.__STACK_OK: + self.init_stack() + self.__STACK_OK = True + + main_newmode = self.main_stack.set_visible_child_name ("main_box_"+mode) + side_newmode = self.side_stack.set_visible_child_name ("side_box_"+mode) + class AboutDialog(Gtk.AboutDialog): def __init__(self, parent): diff --git a/ui/gemgraph.ui b/ui/gemgraph.ui index d29256d..eed91b8 100644 --- a/ui/gemgraph.ui +++ b/ui/gemgraph.ui @@ -30,7 +30,7 @@ @@ -46,20 +46,82 @@ -