Subversion Repositories basico

Rev

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