Created home mode at startup

This commit is contained in:
Adrien Bourmault 2022-08-02 10:29:48 +02:00
parent 4acc10e72d
commit a866f117b1
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
3 changed files with 68 additions and 13 deletions

View File

@ -31,15 +31,28 @@ 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)
self.create_action('quit', self.quit, ['<primary>q'])
self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action)
self.create_action('editmode', self.on_editmode_action, ['<primary>e'])
self.create_action('runmode', self.on_runmode_action, ['<primary>r'])
self.create_action('presentmode', self.on_presentmode_action, ['<primary>p'])
self.create_action('togglesidebar', self.on_togglesidebar_action)
# 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.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'])
# 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'])
def do_activate(self):
"""Called when the application is activated.
@ -53,7 +66,7 @@ class GemGraphApplication(Adw.Application):
win = GemGraphWindow(application=self)
# Display run mode by default
win.stack_switch_mode("run")
win.stack_switch_mode("home")
win.present()
def do_open(self):
@ -61,6 +74,8 @@ class GemGraphApplication(Adw.Application):
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
@ -74,6 +89,17 @@ class GemGraphApplication(Adw.Application):
win.stack_switch_mode("run")
win.present()
def on_close_action(self, widget, _):
"""Callback for the app.closefile action."""
print('app.closefile action activated')
win = self.props.active_window
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)
@ -109,7 +135,7 @@ class GemGraphApplication(Adw.Application):
win = self.props.active_window
win.toggle_sidebar()
def create_action(self, name, callback, shortcuts=None):
def create_action(self, name, callback, is_enabled, shortcuts=None):
"""Add an application action.
Args:
@ -120,6 +146,7 @@ class GemGraphApplication(Adw.Application):
"""
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)

View File

@ -32,11 +32,13 @@ class GemGraphWindow(Gtk.ApplicationWindow):
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":"video-display-symbolic"
"mode_presentation":"x-office-presentation-symbolic"
}
def __init__(self, **kwargs):
@ -53,6 +55,8 @@ class GemGraphWindow(Gtk.ApplicationWindow):
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)

View File

@ -61,6 +61,18 @@
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">side_home</property>
<property name="child">
<object class="GtkLabel" id="labelsidehome">
<property name="justify">center</property>
<property name="label" translatable="yes">&lt;b&gt;Sidebar: home&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">side_presentation</property>
@ -101,6 +113,18 @@
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">main_home</property>
<property name="child">
<object class="GtkLabel">
<property name="justify">center</property>
<property name="label" translatable="yes">&lt;b&gt;Main zone: home&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">main_presentation</property>
@ -137,15 +161,15 @@
<section>
<item>
<attribute name="label" translatable="yes">_Open...</attribute>
<attribute name="action">app.open_file</attribute>
<attribute name="action">app.openfile</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Close</attribute>
<attribute name="action">app.close_file</attribute>
<attribute name="action">app.closefile</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Save</attribute>
<attribute name="action">app.save_file</attribute>
<attribute name="action">app.savefile</attribute>
</item>
</section>
<section>