From 392242dff010e29950b22f8b9eb5885392183b94 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 2 Aug 2022 11:02:29 +0200 Subject: [PATCH] Implemented home state and open action activating modes --- gemgraph/main.py | 75 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/gemgraph/main.py b/gemgraph/main.py index 1773047..619e99b 100644 --- a/gemgraph/main.py +++ b/gemgraph/main.py @@ -27,14 +27,14 @@ 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): - - ENABLE = True - DISABLE = False - super().__init__(application_id='org.example.App', flags=Gio.ApplicationFlags.FLAGS_NONE) @@ -45,14 +45,42 @@ class GemGraphApplication(Adw.Application): self.create_action('togglesidebar', self.on_togglesidebar_action, ENABLE) # Create later actions (mode) - self.create_action('editmode', self.on_editmode_action, DISABLE, ['e']) - self.create_action('runmode', self.on_runmode_action, DISABLE, ['r']) - self.create_action('presentmode', self.on_presentmode_action, DISABLE, ['p']) + self.editmode_action = \ + self.create_action( + 'editmode', + self.on_editmode_action, + DISABLE, + ['e']) + + self.runmode_action = \ + self.create_action( + 'runmode', + self.on_runmode_action, + DISABLE, + ['r']) + + self.presentmode_action = \ + self.create_action( + 'presentmode', + self.on_presentmode_action, + DISABLE, + ['p']) # Create file actions - self.create_action('openfile', self.do_open, DISABLE) - self.create_action('closefile', self.on_close_action, DISABLE) - self.create_action('savefile', self.on_save_action, DISABLE, ['s']) + 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, + ['s']) def do_activate(self): """Called when the application is activated. @@ -69,7 +97,7 @@ class GemGraphApplication(Adw.Application): win.stack_switch_mode("home") win.present() - def do_open(self): + 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 @@ -85,14 +113,34 @@ class GemGraphApplication(Adw.Application): # Open file pass - # Display run mode by default - win.stack_switch_mode("run") + # 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, _): @@ -150,6 +198,7 @@ class GemGraphApplication(Adw.Application): self.add_action(action) if shortcuts: self.set_accels_for_action(f"app.{name}", shortcuts) + return action def main(version):