Implemented work mode with GtkStacks
This commit is contained in:
parent
b33e9806c7
commit
d00e036a7e
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -46,13 +46,75 @@
|
|||
<object class="GtkPaned" id="main_paned">
|
||||
<property name="position">250</property>
|
||||
<child>
|
||||
<object class="GtkFrame" id="main_sideframe">
|
||||
<property name="opacity">0.0</property>
|
||||
<object class="GtkStack" id="side_stack">
|
||||
<child>
|
||||
<object class="GtkBox" id="side_box_run">
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="labelsiderun">
|
||||
<property name="justify">center</property>
|
||||
<property name="label" translatable="yes"><b>Sidebar: run mode</b></property>
|
||||
<property name="use-markup">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="side_box_presentation">
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="labelsidepresentation">
|
||||
<property name="justify">center</property>
|
||||
<property name="label" translatable="yes"><b>Sidebar: presentation mode</b></property>
|
||||
<property name="use-markup">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="side_box_edit">
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="labelsideedit">
|
||||
<property name="justify">center</property>
|
||||
<property name="label" translatable="yes"><b>Sidebar: edit mode</b></property>
|
||||
<property name="use-markup">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkFrame" id="main_frame">
|
||||
<property name="opacity">0.0</property>
|
||||
<object class="GtkStack" id="main_stack">
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="main_box_run">
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="halign">center</property>
|
||||
<property name="label" translatable="yes"><b>Main zone: run mode</b></property>
|
||||
<property name="use-markup">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="main_box_presentation">
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="halign">center</property>
|
||||
<property name="label" translatable="yes"><b>Main zone: presentation mode</b></property>
|
||||
<property name="use-markup">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="main_box_edit">
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="halign">center</property>
|
||||
<property name="label" translatable="yes"><b>Main zone: edit mode</b></property>
|
||||
<property name="use-markup">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
|
Loading…
Reference in New Issue