gem-graph-client/gemgraph/window.py

92 lines
3.1 KiB
Python

# window.py
#
# Copyright (C) 2022 Libre en Communs <contact@a-lec.org>
# Copyright (C) 2022 Adrien Bourmault <neox@a-lec.org>
# Copyright (C) 2022 Jean Sirmai <jean@a-lec.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk
@Gtk.Template(filename='ui/gemgraph.ui')
class GemGraphWindow(Gtk.ApplicationWindow):
"""
Window class
"""
__gtype_name__ = 'main'
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):
Gtk.AboutDialog.__init__(self)
self.props.program_name = 'GemGraph'
self.props.version = "0.0.1"
self.props.authors = ['Adrien Bourmault', 'Jean Sirmai']
self.props.copyright = 'Copyright © 2022 Libre en Communs'
self.props.logo_icon_name = 'application-x-executable'
self.props.modal = True
self.set_transient_for(parent)