27
28
from ibus._gtk import PangoAttrList
29
class Label(gtk.Label): pass
30
class EventBox(gtk.EventBox):
32
super(EventBox, self).__init__()
33
self.connect("realize", self.__realize_cb)
35
def __realize_cb(self, widget):
36
widget.window.set_cursor(gdk.Cursor(gdk.HAND2))
38
gobject.type_register(EventBox, "IBusEventBox")
40
class Label(gtk.Label):
30
42
gobject.type_register(Label, "IBusPanelLabel")
32
44
class HSeparator(gtk.HBox):
34
gtk.HBox.__init__ (self)
46
super(HSeparator, self).__init__()
35
47
self.pack_start(gtk.HSeparator(), True, True, 4)
37
49
class VSeparator(gtk.VBox):
39
gtk.VBox.__init__ (self)
51
super(VSeparator, self).__init__()
40
52
self.pack_start(gtk.VSeparator(), True, True, 4)
42
54
class CandidateArea(gtk.HBox):
56
"candidate-clicked" : (
57
gobject.SIGNAL_RUN_FIRST,
59
(gobject.TYPE_UINT, gobject.TYPE_UINT, gobject.TYPE_UINT )),
43
62
def __init__ (self, orientation):
44
63
gtk.HBox.__init__ (self)
45
64
self.__orientation = orientation
66
self.__candidates = []
49
69
def __create_ui(self):
56
76
self.pack_start(VSeparator(), False, False, 0)
57
77
self.pack_start(self.__vbox2, True, True, 4)
59
for i in xrange(1, 11):
60
label1 = Label("%d." % (i % 10))
79
for i in range(0, 16):
80
label1 = Label("%c." % ("1234567890abcdef"[i]))
61
81
label1.set_alignment(0.0, 0.5)
62
label1.set_no_show_all(True)
65
85
label2.set_alignment(0.0, 0.5)
66
label2.set_no_show_all(True)
68
88
if self.__orientation == gtk.ORIENTATION_VERTICAL:
69
89
label1.set_property("xpad", 8)
70
90
label2.set_property("xpad", 8)
71
self.__vbox1.pack_start(label1, False, False, 2)
72
self.__vbox2.pack_start(label2, False, False, 2)
92
ebox1.set_no_show_all(True)
95
ebox2.set_no_show_all(True)
97
self.__vbox1.pack_start(ebox1, False, False, 2)
98
self.__vbox2.pack_start(ebox2, False, False, 2)
99
self.__candidates.append((ebox1, ebox2))
75
103
hbox.pack_start(label1, False, False, 1)
76
104
hbox.pack_start(label2, False, False, 1)
77
self.pack_start(hbox, False, False, 4)
106
ebox.set_no_show_all(True)
108
self.pack_start(ebox, False, False, 4)
109
self.__candidates.append((ebox,))
79
111
self.__labels.append((label1, label2))
81
self.__labels[0][0].show()
82
self.__labels[0][1].show()
113
cursor = gdk.Cursor(gdk.HAND1)
114
for i, ws in enumerate(self.__candidates):
116
w.connect("button-press-event", lambda w, e, i:self.emit("candidate-clicked", i, e.button, e.state), i)
118
def set_labels(self, labels):
120
for i in xrange(0, 16):
121
self.__labels[i][0].set_text("%c." % ("1234567890abcdef"[i]))
122
self.__labels[i][0].set_property("attributes", None)
126
for text, attrs in labels:
127
self.__labels[i][0].set_text(text)
128
self.__labels[i][0].set_property("attributes", attrs)
84
133
def set_candidates(self, candidates, focus_candidate = 0, show_cursor = True):
85
134
assert len(candidates) <= len(self.__labels)
87
for text, attrs in candidates:
135
for i, (text, attrs) in enumerate(candidates):
88
136
if i == focus_candidate and show_cursor:
90
138
attrs = pango.AttrList()
97
145
attrs.insert(attr)
99
147
self.__labels[i][1].set_text(text)
148
self.__labels[i][1].show()
100
149
self.__labels[i][1].set_property("attributes", attrs)
101
self.__labels[i][0].show()
102
self.__labels[i][1].show()
106
for label1, label2 in self.__labels[max(1, len(candidates)):]:
110
if len(candidates) == 0:
111
self.__labels[0][0].set_text("")
112
self.__labels[0][1].set_text("")
114
self.__labels[0][0].set_text("1.")
150
for w in self.__candidates[i]:
153
for w in reduce(operator.add, self.__candidates[len(candidates):]):
116
156
class CandidatePanel(gtk.VBox):
117
157
__gproperties__ = {
203
256
self.__prev_button = gtk.Button()
204
self.__prev_button.connect("clicked", lambda x: self.emit("cursor-up"))
257
self.__prev_button.connect("clicked", lambda x: self.emit("page-up"))
205
258
self.__prev_button.set_relief(gtk.RELIEF_NONE)
206
self.__tooltips.set_tip(self.__prev_button, "Previous candidate")
259
self.__tooltips.set_tip(self.__prev_button, "Previous page")
208
261
self.__next_button = gtk.Button()
209
self.__next_button.connect("clicked", lambda x: self.emit("cursor-down"))
262
self.__next_button.connect("clicked", lambda x: self.emit("page-down"))
210
263
self.__next_button.set_relief(gtk.RELIEF_NONE)
211
self.__tooltips.set_tip(self.__next_button, "Next candidate")
264
self.__tooltips.set_tip(self.__next_button, "Next page")
213
266
self.__pack_all_widgets()
304
358
self.__aux_attrs = attrs
305
359
self.__aux_label.set_attributes(attrs)
361
def __refresh_labels(self):
362
labels = self.__lookup_table.get_labels()
364
labels = map(lambda x: (x.text, PangoAttrList(x.attributes, x.text)), labels)
367
self.__candidate_area.set_labels(labels)
307
370
def __refresh_candidates(self):
308
371
candidates = self.__lookup_table.get_candidates_in_current_page()
309
372
candidates = map(lambda x: (x.text, PangoAttrList(x.attributes, x.text)), candidates)