forked from emesene/emesene
/
StatusCombo.py
82 lines (65 loc) · 2.76 KB
/
StatusCombo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'''module to define the StatusCombo class, used by plugin.py'''
import gtk
import gobject
import gui
import utils
import protocol
class StatusCombo(gtk.ComboBox):
"""a widget to select the status like the one in emesene 1.0"""
NAME = 'Status Combo'
DESCRIPTION = 'A combo to select the status like emesene 1.0'
AUTHOR = 'Mariano Guerra'
WEBSITE = 'www.emesene.org'
def __init__(self, main_window):
"""constructor"""
self.model = gtk.ListStore(gtk.gdk.Pixbuf, \
gobject.TYPE_INT, gobject.TYPE_STRING)
gtk.ComboBox.__init__(self, self.model)
self.main_window = main_window
self.status = None
status_pixbuf_cell = gtk.CellRendererPixbuf()
status_text_cell = gtk.CellRendererText()
self.pack_start(status_pixbuf_cell, False)
self.pack_start(status_text_cell, False)
status_pixbuf_cell.set_property('xalign', 0.0)
status_pixbuf_cell.set_property('xpad', 5)
status_text_cell.set_property('xalign', 0.0)
status_text_cell.set_property('xpad', 5)
status_text_cell.set_property('width', 158)
self.add_attribute(status_pixbuf_cell, 'pixbuf', 0)
self.add_attribute(status_text_cell, 'text', 2)
self.set_resize_mode(0)
self.set_wrap_width(1)
current_status = main_window.session.account.status
active = 0
count = 0
for stat in protocol.status.ORDERED:
status_name = protocol.status.STATUS[stat]
if stat == current_status:
active = count
pixbuf = utils.safe_gtk_pixbuf_load(gui.theme.status_icons[stat])
pixbuf.scale_simple(20, 20, gtk.gdk.INTERP_BILINEAR)
self.model.append([pixbuf, stat, status_name]) # re-gettext-it
count += 1
self.set_active(active)
self.connect('scroll-event', self.on_scroll_event)
self.connect('changed', self.on_status_changed)
main_window.session.signals.status_change_succeed.subscribe(
self.on_status_change_succeed)
print 'constructor'
def on_status_changed(self , *args):
"""called when a status is selected"""
stat = self.model.get(self.get_active_iter(), 1)[0]
if self.status != stat:
self.status = stat
self.main_window.session.set_status(stat)
def on_status_change_succeed(self, stat):
"""called when the status was changed on another place"""
if stat in protocol.status.ORDERED:
self.status = stat
index = protocol.status.ORDERED.index(stat)
self.set_active(index)
def on_scroll_event(self, button, event):
"""called when a scroll is made over the combo"""
self.popup()
return True