15 | 15 |
|
16 | 16 |
from gettext import gettext as _
|
17 | 17 |
|
|
18 |
def _icon_exists(name):
|
|
19 |
if name == '':
|
|
20 |
return False
|
|
21 |
|
|
22 |
theme = gtk.icon_theme_get_default()
|
|
23 |
info = theme.lookup_icon(name, 0, 0)
|
|
24 |
if info:
|
|
25 |
return True
|
|
26 |
|
|
27 |
return False
|
|
28 |
|
18 | 29 |
class IconToolButton(ToolButton):
|
19 | |
def __init__(self, icon_name, text, cb, help_cb=None):
|
|
30 |
def __init__(self, icon_name, text, cb, help_cb=None, alt_html=''):
|
20 | 31 |
ToolButton.__init__(self)
|
21 | 32 |
|
22 | |
label = gtk.Label()
|
23 | |
label.set_markup(icon_name)
|
24 | |
label.show()
|
25 | |
self.set_label_widget(label)
|
|
33 |
if _icon_exists(icon_name):
|
|
34 |
self.set_icon(icon_name)
|
|
35 |
else:
|
|
36 |
if alt_html == '':
|
|
37 |
alt_html = icon_name
|
|
38 |
|
|
39 |
label = gtk.Label()
|
|
40 |
label.set_markup(alt_html)
|
|
41 |
label.show()
|
|
42 |
self.set_label_widget(label)
|
26 | 43 |
|
27 | 44 |
self.create_palette(text, help_cb)
|
28 | 45 |
|
|
39 | 56 |
|
40 | 57 |
self.set_palette(p)
|
41 | 58 |
|
42 | |
class IconToggleToolButton(gtk.ToggleToolButton):
|
43 | |
def __init__(self, items, cb):
|
44 | |
gtk.ToggleToolButton.__init__(self)
|
|
59 |
class IconToggleToolButton(ToggleToolButton):
|
|
60 |
|
|
61 |
def __init__(self, items, cb, desc):
|
|
62 |
ToggleToolButton.__init__(self)
|
45 | 63 |
self.items = items
|
46 | |
self.set_label(items[0][0])
|
|
64 |
if _icon_exists(items[0][0]):
|
|
65 |
self.set_named_icon(items[0][0])
|
|
66 |
else:
|
|
67 |
self.set_label(items[0][0])
|
47 | 68 |
# self.set_tooltip(items[0][1])
|
|
69 |
self.set_tooltip(desc)
|
48 | 70 |
self.selected = 0
|
49 | 71 |
self.connect('clicked', self.toggle_button)
|
50 | 72 |
self.callback = cb
|
|
52 | 74 |
def toggle_button(self, w):
|
53 | 75 |
self.selected = (self.selected + 1) % len(self.items)
|
54 | 76 |
but = self.items[self.selected]
|
55 | |
self.set_label(but[0])
|
|
77 |
if _icon_exists(but[0]):
|
|
78 |
self.set_named_icon(but[0])
|
|
79 |
else:
|
|
80 |
self.set_label(but[0])
|
56 | 81 |
# self.set_tooltip(but[1])
|
57 | 82 |
if self.callback is not None:
|
58 | 83 |
self.callback(but[0])
|
|
82 | 107 |
def __init__(self, calc):
|
83 | 108 |
gtk.Toolbar.__init__(self)
|
84 | 109 |
|
85 | |
self.insert(IconToolButton('copy', _('Copy'),
|
86 | |
lambda x: calc.text_copy()), -1)
|
87 | |
|
88 | |
self.insert(IconToolButton('paste', _('Paste'),
|
89 | |
lambda x: calc.text_paste()), -1)
|
90 | |
|
91 | |
self.insert(IconToolButton('cut', _('Cut'),
|
92 | |
lambda x: calc.text_cut()), -1)
|
|
110 |
self.insert(IconToolButton('edit-copy', _('Copy'),
|
|
111 |
lambda x: calc.text_copy(),
|
|
112 |
alt_html='Copy'), -1)
|
|
113 |
|
|
114 |
self.insert(IconToolButton('edit-paste', _('Paste'),
|
|
115 |
lambda x: calc.text_paste(),
|
|
116 |
alt_html='Paste'), -1)
|
|
117 |
|
|
118 |
self.insert(IconToolButton('edit-cut', _('Cut'),
|
|
119 |
lambda x: calc.text_cut(),
|
|
120 |
alt_html='Cut'), -1)
|
93 | 121 |
|
94 | 122 |
class AlgebraToolbar(gtk.Toolbar):
|
95 | 123 |
def __init__(self, calc):
|
96 | 124 |
gtk.Toolbar.__init__(self)
|
97 | 125 |
|
98 | |
self.insert(IconToolButton('x<sup>2</sup>', _('Square'),
|
|
126 |
self.insert(IconToolButton('square', _('Square'),
|
99 | 127 |
lambda x: calc.button_pressed(calc.TYPE_OP_POST, '^2'),
|
100 | |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(square)')), -1)
|
101 | |
|
102 | |
self.insert(IconToolButton('√x', _('Square root'),
|
|
128 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(square)'),
|
|
129 |
alt_html='x<sup>2</sup>'), -1)
|
|
130 |
|
|
131 |
self.insert(IconToolButton('sqrt', _('Square root'),
|
103 | 132 |
lambda x: calc.button_pressed(calc.TYPE_FUNCTION, 'sqrt'),
|
104 | |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(sqrt)')), -1)
|
105 | |
|
106 | |
self.insert(IconToolButton('x<sup>-1</sup>', _('Inverse'),
|
|
133 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(sqrt)'),
|
|
134 |
alt_html='√x'), -1)
|
|
135 |
|
|
136 |
self.insert(IconToolButton('xinv', _('Inverse'),
|
107 | 137 |
lambda x: calc.button_pressed(calc.TYPE_OP_POST, '^-1'),
|
108 | |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(sqrt)')), -1)
|
109 | |
|
110 | |
self.insert(LineSeparator(), -1)
|
111 | |
|
112 | |
self.insert(IconToolButton('e<sup>x</sup>', _('e to the power x'),
|
|
138 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(inv)'),
|
|
139 |
alt_html='x<sup>-1</sup>'), -1)
|
|
140 |
|
|
141 |
self.insert(LineSeparator(), -1)
|
|
142 |
|
|
143 |
self.insert(IconToolButton('exp', _('e to the power x'),
|
113 | 144 |
lambda x: calc.button_pressed(calc.TYPE_FUNCTION, 'exp'),
|
114 | |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(exp)')), -1)
|
115 | |
|
116 | |
self.insert(IconToolButton('x<sup>y</sup>', _('x to the power y'),
|
|
145 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(exp)'),
|
|
146 |
alt_html='e<sup>x</sup>'), -1)
|
|
147 |
|
|
148 |
self.insert(IconToolButton('xpowy', _('x to the power y'),
|
117 | 149 |
lambda x: calc.button_pressed(calc.TYPE_FUNCTION, 'pow'),
|
118 | |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(pow)')), -1)
|
|
150 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(pow)'),
|
|
151 |
alt_html='x<sup>y</sup>'), -1)
|
119 | 152 |
|
120 | 153 |
self.insert(IconToolButton('ln', _('Natural logarithm'),
|
121 | 154 |
lambda x: calc.button_pressed(calc.TYPE_FUNCTION, 'ln'),
|
122 | |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(sqrt)')), -1)
|
|
155 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'help(ln)')), -1)
|
123 | 156 |
|
124 | 157 |
self.insert(LineSeparator(), -1)
|
125 | 158 |
|
|
199 | 232 |
def __init__(self, calc):
|
200 | 233 |
gtk.Toolbar.__init__(self)
|
201 | 234 |
|
202 | |
self.insert(IconToolButton('π', _('Pi'),
|
203 | |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'pi')), -1)
|
|
235 |
self.insert(IconToolButton('pi', _('Pi'),
|
|
236 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'pi'),
|
|
237 |
alt_html='π'), -1)
|
204 | 238 |
|
205 | 239 |
self.insert(IconToolButton('e', _('e'),
|
206 | 240 |
lambda x: calc.button_pressed(calc.TYPE_TEXT, 'e')), -1)
|
|
213 | 247 |
['rad', _('Radians')]
|
214 | 248 |
]
|
215 | 249 |
self.insert(IconToggleToolButton(el,
|
216 | |
lambda x: self.update_angle_type(x, calc)), -1)
|
|
250 |
lambda x: self.update_angle_type(x, calc),
|
|
251 |
_('Degrees / radians')), -1)
|
217 | 252 |
|
218 | 253 |
def update_angle_type(self, text, calc):
|
219 | 254 |
if text == 'deg':
|