Subversion Repositories basico

Rev

Rev 264 | Rev 279 | 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 -*-
264 t00m 3
"""
251 t00m 4
# File: srv_uif.py
4 t00mlabs 5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: Generic UI functions service
264 t00m 8
"""
4 t00mlabs 9
 
10
from gi.repository import Gtk
11
from gi.repository import Gio
12
from gi.repository import Pango
13
from gi.repository.GdkPixbuf import Pixbuf
14
 
243 t00m 15
from basico.core.mod_srv import Service
4 t00mlabs 16
 
17
class UIFuncs(Service):
18
    def initialize(self):
223 t00m 19
        self.get_services()
20
 
21
 
22
    def get_services(self):
247 t00m 23
        self.srvgui = self.app.get_service('GUI')
24
        self.srvclb = self.app.get_service('Callbacks')
25
        self.srvicm = self.app.get_service('IM')
26
        self.srvdtb = self.app.get_service('DB')
4 t00mlabs 27
 
28
 
74 t00mlabs 29
    def get_gtk_version(self):
30
        return Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version()
31
 
32
 
33
    def check_gtk_version(self):
34
        vmajor, vminor, vmicro =  self.get_gtk_version()
133 t00mlabs 35
        self.debug("GTK+ Version: %d.%d.%d" % (vmajor, vminor, vmicro))
74 t00mlabs 36
 
37
        if vmajor == 3 and vminor >= 18:
38
            return True
39
        else:
40
            self.log.error("Please, install a modern version of GTK+ (>= 3.18)")
41
            return False
42
 
43
 
4 t00mlabs 44
    def message_dialog(self, head, body):
45
        dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "%s" % head)
46
        dialog.format_secondary_text("%s" % body)
47
        dialog.run()
48
        dialog.destroy()
142 t00mlabs 49
 
50
 
51
    def statusbar_msg(self, message):
247 t00m 52
        statusbar = self.srvgui.get_widget('widget_statusbar')
142 t00mlabs 53
        context = statusbar.get_context_id("basico")
54
        statusbar.push(context, message)
184 t00m 55
 
56
 
57
    def create_menuview_button(self, view):
58
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
247 t00m 59
        icon = self.srvicm.get_pixbuf_icon('basico-%s' % view, 24, 24)
184 t00m 60
        image = Gtk.Image()
61
        image.set_from_pixbuf(icon)
62
        label = Gtk.Label("View by %s" % view)
63
        hbox.pack_start(image, False, False, 3)
64
        hbox.pack_start(label, False, False, 3)
65
        button = Gtk.Button()
66
        button.add(hbox)
67
        button.set_relief(Gtk.ReliefStyle.NONE)
247 t00m 68
        button.connect('clicked', self.srvclb.gui_refresh_view, '%s' % view)
184 t00m 69
 
70
        return button
193 t00m 71
 
255 t00m 72
    def create_notebook_tab_label(self, iconname, title):
73
        hbox = Gtk.HBox()
74
        icon = self.srvicm.get_new_image_icon(iconname)
75
        label = Gtk.Label()
76
        label.set_markup(title)
77
        hbox.pack_start(icon, False, False, 3)
78
        hbox.pack_start(label, False, False, 0)
79
        hbox.show_all()
193 t00m 80
 
255 t00m 81
        return hbox
82
 
83
 
196 t00mlabs 84
    def create_button(self, icon_name=None, icon_width=32, icon_heigth=32, title=''):
193 t00m 85
        button = Gtk.Button()
86
        button.set_relief(Gtk.ReliefStyle.NONE)
87
        hbox = Gtk.HBox()
247 t00m 88
        icon = self.srvicm.get_new_image_icon(icon_name, icon_width, icon_heigth)
193 t00m 89
        label = Gtk.Label()
90
        label.set_markup(title)
91
        label.set_xalign(0.0)
92
        hbox.pack_start(icon, False, False, 6)
93
        hbox.pack_start(label, True, True, 0)
94
        button.add(hbox)
95
 
96
        return button
212 t00m 97
 
98
 
264 t00m 99
    # ~ def warning_message_default(self, question, explanation):
100
        # ~ window = self.srvgui.get_window()
101
        # ~ icon = self.srvicm.get_new_image_icon('basico-priority', 96, 96)
102
        # ~ icon.show_all()
103
        # ~ dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.QUESTION,
104
            # ~ Gtk.ButtonsType.YES_NO, question)
105
        dialog.set_size_request(800, 600);
106
        # ~ dialog.set_image(icon)
107
        # ~ dialog.format_secondary_text(explanation)
241 t00m 108
 
264 t00m 109
        # ~ return dialog
241 t00m 110
 
111
 
212 t00m 112
    def warning_message(self, widget, question, explanation, bag):
247 t00m 113
        window = self.srvgui.get_widget('gtk_app_window_main')
114
        icon = self.srvicm.get_new_image_icon('basico-delete', 96, 96)
212 t00m 115
        icon.show_all()
116
        dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.QUESTION,
117
            Gtk.ButtonsType.YES_NO, question)
264 t00m 118
        dialog.set_size_request(600, 380);
212 t00m 119
        content_area = dialog.get_content_area()
120
        vbox = Gtk.VBox()
121
        label = Gtk.Label()
264 t00m 122
        label.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
123
        label.set_property('selectable', True)
124
        label.set_xalign(0.0)
125
        label.grab_focus()
126
        msg = '\t<b>This is the list of SAP Notes to be deleted:</b>'
212 t00m 127
        vbox.pack_start(label, False, False, 0)
128
        scr = Gtk.ScrolledWindow()
129
        scr.set_shadow_type(Gtk.ShadowType.NONE)
130
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
264 t00m 131
 
132
        msg += '\n\n'
133
        for sid in bag:
134
            self.log.debug(sid)
135
            msg += '\t%s - %s\t\n' % (sid, self.srvdtb.get_title(sid))
136
        msg += '\n'
137
        label.set_markup(msg)
138
 
212 t00m 139
        vbox.pack_start(scr, True, True, 0)
140
        content_area.pack_start(vbox, True, True, 0)
141
        content_area.show_all()
142
        dialog.set_image(icon)
143
        dialog.format_secondary_text(explanation)
144
        response = dialog.run()
145
        if response == Gtk.ResponseType.YES:
146
            answer = True
264 t00m 147
        else:
212 t00m 148
            answer = False
149
        dialog.destroy()
150
 
151
        return answer
221 t00m 152
 
153
 
223 t00m 154
    def set_widget_visibility(self, widget_name, visibility):
247 t00m 155
        widget = self.srvgui.get_widget(widget_name)
223 t00m 156
        if visibility:
157
            widget.set_no_show_all(False)
158
            widget.show_all()
159
        else:
160
            widget.set_no_show_all(True)
161
            widget.hide()
162
 
163
 
221 t00m 164
    def get_combobox_text(self, combobox, col):
165
        treeiter = combobox.get_active_iter()
166
        model = combobox.get_model()
167
        return model[treeiter][col]
168
 
223 t00m 169
 
221 t00m 170
    def set_combobox_active(self, combobox, value):
171
        model = combobox.get_model()
172
        for treeiter in model:
173
            self.debug (model[treeiter][0])
174
 
240 t00m 175
 
221 t00m 176
    def get_textview_text(self, textview):
177
        textbuffer = textview.get_buffer()
178
        istart, iend = textbuffer.get_bounds()
179
        return textbuffer.get_text(istart, iend, False)
180
 
240 t00m 181
 
221 t00m 182
    def set_textview_text(self, textview, text):
183
        textbuffer = textview.get_buffer()
184
        textbuffer.set_text(text)
241 t00m 185
 
186
    def dialog_info(self, title, message):
247 t00m 187
        window = self.srvgui.get_window()
241 t00m 188
        dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, title)
189
        dialog.format_secondary_text(message)
190
        dialog.run()
191
        dialog.destroy()
262 t00m 192
 
193
 
277 t00m 194
    # ~ def webkit_support(self):
195
        # ~ import gi
196
        # ~ try:
197
            # ~ gi.require_version('WebKit', '3.0')
198
            # ~ return True
199
        # ~ except:
200
            # ~ return False