Implemented home state and open action activating modes

This commit is contained in:
Adrien Bourmault 2022-08-02 11:02:29 +02:00
parent a866f117b1
commit 392242dff0
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
1 changed files with 62 additions and 13 deletions

View File

@ -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, ['<primary>e'])
self.create_action('runmode', self.on_runmode_action, DISABLE, ['<primary>r'])
self.create_action('presentmode', self.on_presentmode_action, DISABLE, ['<primary>p'])
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, DISABLE)
self.create_action('closefile', self.on_close_action, DISABLE)
self.create_action('savefile', self.on_save_action, DISABLE, ['<primary>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,
['<primary>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):