Subversion Repositories basico

Rev

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

Rev Author Line No. Line
4 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
# File: gui.py
4
# Author: Tomás Vírseda
5
# License: GPL v3
6
# Description: GUI module
7
 
8
import os
9
import sys
10
import subprocess
11
 
12
from datetime import datetime
13
 
14
import gi
15
gi.require_version('Gtk', '3.0')
16
from gi.repository import Gtk
17
from gi.repository import Gdk
18
from gi.repository.GdkPixbuf import Pixbuf
19
from gi.repository import Pango
20
from gi.repository import GLib
21
from gi.repository import GObject
22
from gi.repository import Gio
23
 
243 t00m 24
from basico.core.mod_srv import Service
25
from basico.core.mod_uiapp import UIApp
26
from basico.core.mod_env import STATS
4 t00mlabs 27
 
28
 
29
class GUI(Service):
30
    def initialize(self):
31
        '''
32
        Setup GUI Service
33
        '''
34
        # Invoke services
35
        self.sap = self.app.get_service('SAP')
36
 
37
        # Setup caches
38
        self.widgets = {} # Widget name : Object
39
        self.keys = {} # Key : Value; keys: doctype, property, values
40
 
41
 
42
    def run(self):
43
        '''
44
        Let GUI service start
45
        '''
133 t00mlabs 46
        self.debug("Setting up GUI")
4 t00mlabs 47
        GObject.threads_init()
48
        self.sap.run()
49
        self.ui = UIApp(self.app)
126 t00mlabs 50
        DEBUG_END_TIME = datetime.now()
51
        STATS['BASICO_STARTUP_END'] = datetime.now()
133 t00mlabs 52
        self.debug("Startup duration: %s" % (STATS['BASICO_STARTUP_END'] - STATS['BASICO_STARTUP_START']))
4 t00mlabs 53
        self.ui.run()
54
 
55
 
56
    def quit(self, *args):
57
        '''
58
        GUI destroyed
59
        '''
60
        self.app.stop()
61
 
62
 
63
    def end(self):
64
        '''
65
        End GUI Service
66
        '''
133 t00mlabs 67
        self.debug("GUI terminated")
4 t00mlabs 68
        self.ui.quit()
69
 
70
 
71
    def swap_widget(self, parent, widget):
72
        '''
73
        Swap widget inside a container
74
        '''
75
        try:
76
            child = parent.get_children()[0]
77
            parent.remove(child)
78
            parent.add(widget)
131 t00mlabs 79
        except IndexError:
4 t00mlabs 80
            parent.add(widget)
131 t00mlabs 81
        except Exception as error:
82
            self.print_traceback()
141 t00mlabs 83
            raise
131 t00mlabs 84
 
4 t00mlabs 85
        widget.show_all()
86
 
87
 
88
    def get_key(self, key):
89
        '''
90
        Return current value from var cache
91
        '''
92
        return self.keys[key]
93
 
94
 
95
    def set_key(self, key, value):
96
        '''
97
        Set current value for var cache
98
        '''
99
        self.keys[key] = value
100
 
101
 
102
    def add_widget(self, name, obj=None):
103
        '''
104
        Add widget to cache
105
        '''
106
        try:
107
            if obj is not None:
108
                self.widgets[name] = obj
137 t00mlabs 109
                return self.widgets[name]
4 t00mlabs 110
            else:
137 t00mlabs 111
                return None
205 t00m 112
        except Exception as error:
113
            self.debug(error)
4 t00mlabs 114
            return None
115
 
116
 
117
    def get_widget(self, name):
118
        '''
119
        Return widget from cache
120
        '''
121
        try:
122
            return self.widgets[name]
123
        except KeyError:
124
            return self.add_widget(name)
125
 
126
 
127
    def get_widgets(self):
128
        return self.widgets
129
 
130
 
131
    def get_app(self):
132
        return self.ui
133
 
134
 
135
    def get_window(self):
136
        return self.ui.get_window()