Subversion Repositories basico

Rev

Rev 141 | 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
 
24
from .service import Service
25
from .uiapp import UIApp
126 t00mlabs 26
from .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)
144 t00mlabs 78
            del (child)
4 t00mlabs 79
            parent.add(widget)
131 t00mlabs 80
        except IndexError:
4 t00mlabs 81
            parent.add(widget)
131 t00mlabs 82
        except Exception as error:
83
            self.print_traceback()
141 t00mlabs 84
            raise
131 t00mlabs 85
 
4 t00mlabs 86
        widget.show_all()
87
 
88
 
89
    def get_key(self, key):
90
        '''
91
        Return current value from var cache
92
        '''
93
        return self.keys[key]
94
 
95
 
96
    def set_key(self, key, value):
97
        '''
98
        Set current value for var cache
99
        '''
100
        self.keys[key] = value
101
 
102
 
103
    def add_widget(self, name, obj=None):
104
        '''
105
        Add widget to cache
106
        '''
107
        try:
108
            if obj is not None:
109
                self.widgets[name] = obj
137 t00mlabs 110
                return self.widgets[name]
4 t00mlabs 111
            else:
137 t00mlabs 112
                return None
113
        except:
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()