Subversion Repositories basico

Rev

Rev 341 | Rev 369 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
340 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
"""
4
# File: srv_gui.py
5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: GUI service
8
"""
9
 
10
import gi
11
gi.require_version('Gtk', '3.0')
12
from gi.repository import Gtk
13
from gi.repository import GLib
14
from gi.repository import GObject
15
from gi.repository import Gio
16
from basico.core.mod_srv import Service
17
from basico.core.mod_win import GtkAppWindow
18
from basico.core.mod_log import get_logger
19
 
20
 
21
class UIApp(Gtk.Application):
22
    """
23
    Missing class docstring (missing-docstring)
24
    """
25
    uiapp = None
26
    window = None
27
 
28
    def __init__(self, *args, **kwargs):
29
        """
30
        Missing method docstring (missing-docstring)
31
        """
32
        super().__init__(application_id="net.t00mlabs.basico", flags=Gio.ApplicationFlags.FLAGS_NONE)
33
        GLib.set_application_name("Basico")
34
        GLib.set_prgname('basico')
35
        self.log = get_logger(__class__.__name__)
36
        self.app = args[0]
37
        self.get_services()
38
 
39
 
40
    def do_activate(self):
41
        # DOC: https://wiki.gnome.org/HowDoI/GtkApplication
42
        # https://stackoverflow.com/questions/41883527/uniqueness-of-gtk-application-without-creating-any-window
43
        if not hasattr(self, "my_app_settings"):
44
            self.hold()
45
            self.my_app_settings = "Primary application instance."
46
            self.window = self.srvgui.add_widget('gtk_app_window_main', GtkAppWindow(self))
47
            self.window.connect("delete-event", self.srvgui.quit)
48
            self.log.debug("New Basico instance created")
49
            self.srvuif.statusbar_msg("Welcome to Basico", True)
50
        else:
51
            self.log.debug("Basico is already running!")
52
 
53
 
54
    def get_services(self):
55
        """
56
        Missing method docstring (missing-docstring)
57
        """
58
        self.srvgui = self.app.get_service('GUI')
59
        self.srvclb = self.app.get_service('Callbacks')
60
        self.srvuif = self.app.get_service('UIF')
61
 
62
 
63
    def get_window(self):
64
        """
65
        Missing method docstring (missing-docstring)
66
        """
67
        return self.window
68
 
69
 
70
    def get_controller(self):
71
        """
72
        Missing method docstring (missing-docstring)
73
        """
74
        return self.app
75
 
76
 
77
class GUI(Service):
78
    """
79
    Missing class docstring (missing-docstring)
80
    """
81
    uiapp = None
82
    srvsap = None
83
    widgets = {} # Widget name : Object
84
    keys = {} # Key : Value; keys: doctype, property, values
85
 
86
    def initialize(self):
87
        """
88
        Setup GUI Service
89
        """
90
        self.srvsap = self.get_service('SAP')
91
 
92
 
93
    def run(self):
94
        """
95
        Let GUI service start
96
        """
97
        GObject.threads_init()
98
        self.uiapp = UIApp(self.app)
99
        self.log.debug("Setting up GUI")
361 t00mlabs 100
        window = self.get_window()
340 t00mlabs 101
        self.uiapp.run()
102
 
103
 
104
    def quit(self, window, event):
105
        """
106
        GUI destroyed
107
        """
108
        self.app.stop()
109
 
110
 
111
    def end(self):
112
        """
113
        End GUI Service
114
        """
115
        self.uiapp.quit()
116
        self.log.debug("GUI terminated")
117
 
118
 
119
    def swap_widget(self, parent, widget):
120
        """
121
        Swap widget inside a container
122
        """
123
        try:
124
            child = parent.get_children()[0]
125
            parent.remove(child)
126
            parent.add(widget)
127
        except IndexError:
128
            parent.add(widget)
129
        except Exception:
130
            self.print_traceback()
131
            raise
132
 
133
        widget.show_all()
134
 
135
 
136
    def get_keys(self):
137
        return self.keys
138
 
139
 
140
    def get_key_value(self, key):
141
        """
142
        Return current value from var cache
143
        """
144
        return self.keys[key]
145
 
146
 
147
    def set_key_value(self, key, value):
148
        """
149
        Set current value for var cache
150
        """
151
        self.keys[key] = value
152
 
153
 
154
    def add_widget(self, name, obj=None):
155
        """
156
        Add widget to cache
157
        """
158
        if obj is not None:
159
            self.widgets[name] = obj
160
 
161
        return obj
162
 
163
 
164
    def get_widget(self, name):
165
        """
166
        Return widget from cache
167
        """
168
        try:
169
            return self.widgets[name]
170
        except KeyError:
171
            return None
172
 
173
 
174
    def get_widgets(self):
175
        """
176
        Missing method docstring (missing-docstring)
177
        """
178
        return self.widgets
179
 
180
 
181
    def get_app(self):
182
        """
183
        Missing method docstring (missing-docstring)
184
        """
185
        return self.uiapp
186
 
187
 
188
    def get_window(self):
189
        """
190
        Missing method docstring (missing-docstring)
191
        """
192
        return self.uiapp.get_window()