Subversion Repositories basico

Rev

Rev 4 | 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: uifuncs.py
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
 
14
from .service import Service
15
 
16
class UIFuncs(Service):
17
    def initialize(self):
18
        self.gui = self.app.get_service('GUI')
19
        self.cb = self.app.get_service('Callbacks')
20
        self.im = self.app.get_service('IM')
21
 
22
 
74 t00mlabs 23
    def get_gtk_version(self):
24
        return Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version()
25
 
26
 
27
    def check_gtk_version(self):
28
        vmajor, vminor, vmicro =  self.get_gtk_version()
29
        self.log.debug("GTK+ Version: %d.%d.%d" % (vmajor, vminor, vmicro))
30
 
31
        if vmajor == 3 and vminor >= 18:
32
            self.log.debug("GTK+ version supported")
33
            return True
34
        else:
35
            self.log.error("Please, install a modern version of GTK+ (>= 3.18)")
36
            return False
37
 
38
 
4 t00mlabs 39
    def get_label(self, text, xalign=0.5, yalign=0.5):
40
        label = Gtk.Label()
41
        label.set_selectable(False)
42
        label.set_markup(text)
43
        label.props.xalign = xalign
44
        label.props.yalign = yalign
45
        label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
46
 
47
        return label
48
 
49
 
50
    def get_separator(self, draw=False, expand=False):
51
            separator = Gtk.SeparatorToolItem.new ()
52
            separator.set_expand(expand)
53
            separator.set_draw(draw)
54
 
55
            return separator
56
 
57
 
58
    def create_textview(self):
59
        scrolledwindow = Gtk.ScrolledWindow()
60
        scrolledwindow.set_hexpand(True)
61
        scrolledwindow.set_vexpand(True)
62
        scrolledwindow.set_shadow_type(Gtk.ShadowType.IN)
63
        textview = Gtk.TextView()
64
        textbuffer = textview.get_buffer()
65
        textbuffer.set_text("This is some text inside of a Gtk.TextView. "
66
            + "Select text and click one of the buttons 'bold', 'italic', "
67
            + "or 'underline' to modify the text accordingly.")
68
        scrolledwindow.add(textview)
69
 
70
        return scrolledwindow
71
 
72
 
73
    def get_box(self):
74
        if Gtk.get_minor_version() < 14:
75
            return Gtk.Alignment()
76
        else:
77
            return Gtk.Box()
78
 
79
 
80
    def create_item(self, name, action, icon):
81
        item = Gio.MenuItem.new(name, action)
82
        if len(icon) > 0:
83
            item.set_icon(Gio.ThemedIcon.new(icon))
84
            #~ icon = self.im.get_themed_icon(icon)
85
 
86
        return item
87
 
88
 
89
    def create_action(self, name, callback=None, user_data=None):
90
        action = Gio.SimpleAction.new(name, None)
91
 
92
        if callback is None:
93
            window = self.gui.get_widget('mainwindow')
94
            action.connect('activate', self.cb.execute_action, user_data)
95
        else:
96
            action.connect('activate', callback, user_data)
97
        return action
98
 
99
 
100
    def message_dialog(self, head, body):
101
        dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "%s" % head)
102
        dialog.format_secondary_text("%s" % body)
103
        dialog.run()
104
        dialog.destroy()
105
 
106
 
107
    def fullscreen(self, switch, do_fullscreen=None):
108
        window = self.gui.get_widget('mainwindow')
109
 
110
        if do_fullscreen is None:
111
            #~ Get state from button:
112
            toggle = self.gui.get_widget('tgbFullScreen')
113
            do_fullscreen = toggle.get_active()
114
 
115
        if do_fullscreen == True:
116
            #~ window.fullscreen()
117
            window.maximize()
118
        else:
119
            #~ window.unfullscreen()
120
            window.unmaximize()
121
 
122