237
230
gobject.type_register( inputBox )
240
class TinyArrow(gtk.DrawingArea):
244
def __init__(self, arrow_type, shadow=gtk.SHADOW_NONE):
245
gtk.DrawingArea.__init__(self)
246
self.arrow_type = arrow_type
250
self.set_size_request(*self.get_size())
251
self.connect("expose_event", self.expose)
254
if self.arrow_type in (gtk.ARROW_LEFT, gtk.ARROW_RIGHT):
255
return (TinyArrow.WIDTH + self.margin*2, \
256
TinyArrow.LENGTH + self.margin*2)
258
return (TinyArrow.LENGTH + self.margin*2, \
259
TinyArrow.WIDTH + self.margin*2)
261
def expose(self, widget=None, event=None):
262
if self.window is None:
265
width, height = self.get_size()
266
self.get_style().paint_arrow(self.window, self.state, \
267
self.shadow, None, self, '', self.arrow_type, True, \
272
def set(self, arrow_type, shadow=gtk.SHADOW_NONE, margin=None):
273
self.arrow_type = arrow_type
275
if margin is not None:
277
self.set_size_request(*self.get_size())
281
class WidgetToggleBox(gtk.Widget):
232
class WidgetToggleBox(gtk.EventBox):
282
233
'''A box that represents a widget and allows toggling its visibility'''
284
235
def __init__(self, config, key, description, label):
285
gtk.Widget.__init__(self)
236
gtk.EventBox.__init__(self)
237
self.set_border_width(1)
286
238
self.description = description
287
239
self.label = label
288
240
self.config = config
290
242
self.enabled = False
291
243
self.inside = False
244
# this colors as no particular reason, I liked them
245
# change them if you want. -arielj
246
self.enabledColor = gtk.gdk.Color(17408, 19200, 51456)
247
self.insideColor = gtk.gdk.Color(31744, 40704, 62208)
248
self.disabledColor = gtk.gdk.Color(51456, 51456, 51456)
292
249
if self.config and key:
293
250
self.enabled = self.config.user[key]
295
def do_realize(self):
296
'''Initializes the gtk window'''
297
self.set_flags(gtk.REALIZED)
299
mask = gtk.gdk.EXPOSURE_MASK | gtk.gdk.BUTTON_PRESS_MASK | \
300
gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.ENTER_NOTIFY_MASK
302
self.window = gtk.gdk.Window(
303
self.get_parent_window(),
306
width=self.allocation.width,
307
height=self.allocation.height,
308
window_type=gtk.gdk.WINDOW_CHILD,
309
wclass=gtk.gdk.INPUT_OUTPUT,
310
event_mask=self.get_events() | mask)
312
self.window.set_user_data(self)
313
self.style2 = self.style.copy()
314
self.style2.attach(self.window)
315
self.style2.set_background(self.window, self.state)
316
self.window.move_resize(*self.allocation)
318
if gtk.gtk_version >= (2, 12, 0) and \
319
gtk.pygtk_version >= (2, 12, 0) and self.description:
320
self.set_tooltip_text(self.description.replace("_", ""))
322
def do_unrealize(self):
323
'''Destroys the window'''
324
self.window.set_user_data(None)
325
self.window.destroy()
327
def do_size_allocate(self, allocation):
328
'''Resizes the window'''
329
self.allocation = allocation
330
if self.flags() & gtk.REALIZED:
331
self.window.move_resize(*allocation)
333
def do_expose_event(self, event):
253
def update_color(self):
334
254
'''Renders the box'''
336
state = gtk.STATE_SELECTED
256
color = self.enabledColor
339
state = gtk.STATE_PRELIGHT
341
state = gtk.STATE_NORMAL
258
color = self.disabledColor
261
color = self.insideColor
343
self.style2.paint_box(self.window, state,
344
gtk.SHADOW_ETCHED_IN, event.area, self, '', 0, 0,
345
self.allocation.width, self.allocation.height)
263
self.modify_bg(gtk.STATE_NORMAL, color)
264
self.modify_bg(gtk.STATE_ACTIVE, color)
265
self.modify_bg(gtk.STATE_PRELIGHT, color)
347
268
def do_button_press_event(self, event):
348
269
'''Called when the user clicks the widget'''
350
271
self.enabled = not self.enabled
353
275
self.config.user[self.key] = self.enabled