1 # Copyright (C) 2006, Thomas Leonard
3 from rox
import g
, Dialog
, info
, confirm
10 class TimerButton(g
.Button
):
11 """An 'egg-timer' button for the main window'"""
14 g
.Button
.__init
__(self
, 'T')
17 self
.unset_flags(g
.CAN_FOCUS
)
20 tips
.set_tip(self
, _('Click here to set the count-down timer.'))
22 self
.connect('clicked', edit_timer
)
24 def set_timer(self
, secs
):
25 self
.end_time
= time
.time() + secs
27 wait
= self
.end_time
- time
.time()
33 text
= '%dm%d' % (int(wait
/ 60), int(wait
% 60))
35 text
= '%ss' % int(wait
)
38 assert self
.timeout
is None
40 self
.timeout
= gobject
.timeout_add(1000, update_timer
)
44 if dbus_notify
.is_available():
47 info(_('Memo : Time is up!'))
49 def clear_timer(self
):
53 gobject
.source_remove(self
.timeout
)
56 def edit_timer(timer
):
59 edit_timer_box
.destroy()
62 if confirm(_('The timer is already set - clear it?'), g
.STOCK_CLEAR
):
66 edit_timer_box
= Dialog(title
= _('Memo Timer'), parent
= timer
.get_toplevel(), flags
= g
.DIALOG_NO_SEPARATOR
)
69 assert edit_timer_box
is box
71 edit_timer_box
.connect('destroy', destroyed
)
73 def response(d
, resp
):
74 if resp
== int(g
.RESPONSE_OK
):
75 timer
.set_timer(min.value
* 60 + sec
.value
)
77 edit_timer_box
.connect('response', response
)
79 vbox
= g
.VBox(False, 0)
80 vbox
.set_border_width(8)
81 edit_timer_box
.vbox
.pack_start(vbox
, True, True, 0)
82 vbox
.pack_start(g
.Label(_('Set the count-down timer and click OK.')), True, True, 0)
84 hbox
= g
.HBox(False, 0)
85 vbox
.pack_start(hbox
, False, True, 8)
87 min = g
.Adjustment(0, 0, 999, 1, 1)
88 spin
= g
.SpinButton(min)
90 spin
.set_activates_default(True)
91 hbox
.pack_start(spin
, True, True, 0)
92 hbox
.pack_start(g
.Label(_('min ')), False, True, 2)
94 sec
= g
.Adjustment(0, 0, 59, 1, 1)
95 spin
= g
.SpinButton(sec
)
97 spin
.set_activates_default(True)
98 hbox
.pack_start(spin
, True, True, 0)
99 hbox
.pack_start(g
.Label(_('sec')), False, True, 2)
101 edit_timer_box
.add_button(g
.STOCK_CANCEL
, g
.RESPONSE_CANCEL
)
102 edit_timer_box
.add_button(g
.STOCK_OK
, g
.RESPONSE_OK
)
103 edit_timer_box
.set_default_response(g
.RESPONSE_OK
)
105 edit_timer_box
.show_all()