def _update_status_button(self): current_state = self._timer.get_state() if current_state == core.Timer.STATE_IDLE: print 'Idle' # This label text should not be visible because the label # is hidden when the timer is idle. self._status_button.set_label('--:--:--') self._status_button.set_tooltip( _('Click to start a new timer countdown.')) elif current_state == core.Timer.STATE_RUNNING: print 'Running' elif current_state == core.Timer.STATE_PAUSED: print 'Paused' self._status_button.set_tooltip( _('Paused. Click to continue timer countdown.')) elif current_state == core.Timer.STATE_FINISHED: print 'Finished' self._status_button.set_label(_('Finished')) name_str = self._timer.get_name() time_str = utils.get_display_text_from_datetime( self._timer.get_end_time()) if len(name_str) > 0: # "<timer name>" finished at <time> self._status_button.set_tooltip( _('"%s" finished at %s.\nClick to stop timer.') % (name_str, time_str)) else: # Timer finished at <time> self._status_button.set_tooltip( _('Timer finished at %s.\nClick to stop timer.') % time_str) self._status_button.set_sensitized( current_state == core.Timer.STATE_RUNNING or current_state == core.Timer.STATE_FINISHED) self._status_button.set_use_icon( current_state == core.Timer.STATE_IDLE) self._status_button.set_show_remaining_time( current_state != core.Timer.STATE_IDLE and self._mateconf.get_bool(TimerApplet._SHOW_REMAINING_TIME_KEY)) if current_state == core.Timer.STATE_PAUSED: self._status_button.set_pie_fill_color(0.4, 0.4, 0.4) else: # Use theme color color = self._applet.style.base[gtk.STATE_SELECTED] red = color.red / 65535.0 green = color.green / 65535.0 blue = color.blue / 65535.0 self._status_button.set_pie_fill_color(red, green, blue) orientation = self._applet.get_orient() size = self._applet.get_size() use_vertical = (orientation == mateapplet.ORIENT_LEFT or orientation == mateapplet.ORIENT_RIGHT or size >= mateapplet.SIZE_MEDIUM) self._status_button.set_use_vertical_layout(use_vertical)
def _update_status_button(self): current_state = self.timer.get_state() if current_state == Timer.STATE_IDLE: print 'Idle' # This label text should not be visible because the label # is hidden when the timer is idle. self.status_button.set_label('--:--:--') self.status_button.set_tooltip(_('Click to start a new timer countdown.')) elif current_state == Timer.STATE_RUNNING: print 'Running' elif current_state == Timer.STATE_PAUSED: print 'Paused' self.status_button.set_tooltip(_('Paused. Click to continue timer countdown.')) elif current_state == Timer.STATE_FINISHED: print 'Finished' self.status_button.set_label(_('Finished')) name_str = self.timer.get_name() time_str = utils.get_display_text_from_datetime(self.timer.get_end_time()) if len(name_str) > 0: # "<timer name>" finished at <time> self.status_button.set_tooltip(_('"%s" finished at %s.\nClick to stop timer.') % (name_str, time_str)) else: # Timer finished at <time> self.status_button.set_tooltip(_('Timer finished at %s.\nClick to stop timer.') % time_str) self.status_button.set_sensitized(current_state == Timer.STATE_RUNNING or current_state == Timer.STATE_FINISHED) self.status_button.set_use_icon(current_state == Timer.STATE_IDLE) self.status_button.set_show_remaining_time(current_state != Timer.STATE_IDLE and self.gsettings.get_boolean(TimerApplet.KEY_SHOW_REMAINING_TIME)) if current_state == Timer.STATE_PAUSED: self.status_button.set_pie_fill_color(0.4, 0.4, 0.4) else: # Use theme color color = self.applet.style.base[Gtk.StateType.SELECTED] red = color.red / 65535.0 green = color.green / 65535.0 blue = color.blue / 65535.0 self.status_button.set_pie_fill_color(red, green, blue) orientation = self.applet.get_orient() size = self.applet.get_size() # FIX ME: I lost size here. should have size >= mateapplet.SIZE_MEDIUM, # but I can't find it in any MatePanelApplet use_vertical = (orientation == MatePanelApplet.AppletOrient.ORIENT_LEFT or orientation == MatePanelApplet.AppletOrient.ORIENT_RIGHT) self.status_button.set_use_vertical_layout(use_vertical)
def _on_timer_state_changed(self, timer, data=None): # TODO: # Refactor me! print 'State changed' new_state = timer.get_state() print ' new state: %d' % new_state # These actions should be done once upon a state change. # That's why they're done here and not in self._update_status_button(); # self._update_status_button() could be called multiple times # while in the same state. if new_state == Timer.STATE_FINISHED: name = self.timer.get_name() command = self.timer.get_command() end_time = self.timer.get_end_time() time_text = utils.get_display_text_from_datetime(end_time) summary = None message = None if len(name) > 0: # "<timer name>" Finished summary = (_('"%s" Finished') % name) # "<timer name>" finished at <time> message = (_('"%s" finished at %s') % (name, time_text)) else: summary = _('Timer Finished') # Timer finished at <time> message = (_('Timer finished at %s') % time_text) def reminder_message_func(): elapsed_time = datetime.now() - end_time message = None if elapsed_time < timedelta(seconds=60): message = ngettext('Timer finished about <b>%d second</b> ago', 'Timer finished about <b>%d seconds</b> ago', elapsed_time.seconds) % elapsed_time.seconds else: minutes = elapsed_time.seconds / 60 message = ngettext('Timer finished about <b>%d minute</b> ago', 'Timer finished about <b>%d minutes</b> ago', minutes) % minutes return message # TODO: # FIXME: # Reason for using a Python thread: # To do all the procedures after timer has ended. If I don't do # this then after the timer ended and it had an auto-start and next # timer defined, it would directly switch without any notification. # Trying time.sleep() doesn't work as expected; it correctly starts # the next timer, but it doesn't show the notification and the # rest. class MyThread(threading.Thread): def __init__(self, timer_instance): threading.Thread.__init__(self) self.timer = timer_instance def run(self): print "Starting thread..." print "Calling popup notification.", self.timer._call_notify(summary, message, reminder_message_func) print "Starting pulsing button.", self.timer._start_pulsing_button() print "Playing notification sound.", self.timer._play_notification_sound() print "Running custom command.", self.timer._run_custom_command(command) print "Ending Thread..." thread = MyThread(self) thread.start() thread.join() next_timer = self.timer.get_next_timer() auto_start = self.timer.get_auto_start() if auto_start and next_timer: # Start next timer self._stop_sound() self._call_notify(show=False) self._stop_pulsing_button() self._start_next_timer() elif not(auto_start) and next_timer: self.status_button.props.sensitive = False dialog_result = self.start_next_timer_dialog.get_response() self.status_button.props.sensitive = True if dialog_result: # Start next timer self._stop_sound() self._call_notify(show=False) self._stop_pulsing_button() self._start_next_timer() else: self._stop_sound() self._call_notify(show=False) self._stop_pulsing_button() print "Updating status button..." self._update_status_button() print "Updating popup menu..." self._update_popup_menu()
def _on_timer_state_changed(self, timer, data=None): # TODO: # Refactor me! print 'State changed' new_state = timer.get_state() print ' new state: %d' % new_state # These actions should be done once upon a state change. # That's why they're done here and not in self._update_status_button(); # self._update_status_button() could be called multiple times # while in the same state. if new_state == core.Timer.STATE_FINISHED: name = self._timer.get_name() command = self._timer.get_command() end_time = self._timer.get_end_time() time_text = utils.get_display_text_from_datetime(end_time) summary = None message = None if len(name) > 0: # "<timer name>" Finished summary = (_('"%s" Finished') % name) # "<timer name>" finished at <time> message = (_('"%s" finished at %s') % (name, time_text)) else: summary = _('Timer Finished') # Timer finished at <time> message = (_('Timer finished at %s') % time_text) def reminder_message_func(): elapsed_time = datetime.now() - end_time message = None if elapsed_time < timedelta(seconds=60): message = ngettext( 'Timer finished about <b>%d second</b> ago', 'Timer finished about <b>%d seconds</b> ago', elapsed_time.seconds) % elapsed_time.seconds else: minutes = elapsed_time.seconds / 60 message = ngettext( 'Timer finished about <b>%d minute</b> ago', 'Timer finished about <b>%d minutes</b> ago', minutes) % minutes return message # TODO: # FIXME: # Reason for using a Python thread: # To do all the procedures after timer has ended. If I don't do # this then after the timer ended and it had an auto-start and next # timer defined, it would directly switch without any notification. # Trying time.sleep() doesn't work as expected; it correctly starts # the next timer, but it doesn't show the notification and the # rest. class MyThread(threading.Thread): def __init__(self, timer_instance): threading.Thread.__init__(self) self.timer = timer_instance def run(self): print "Starting thread..." print "Calling popup notification.", self.timer._call_notify(summary, message, reminder_message_func) print "Starting pulsing button.", self.timer._start_pulsing_button() print "Playing notification sound.", self.timer._play_notification_sound() print "Running custom command.", self.timer._run_custom_command(command) print "Ending Thread..." thread = MyThread(self) thread.start() thread.join() next_timer = self._timer.get_next_timer() auto_start = self._timer.get_auto_start() if auto_start and next_timer: # Start next timer self._stop_sound() self._call_notify(show=False) self._stop_pulsing_button() self._start_next_timer() elif not (auto_start) and next_timer: self._status_button.props.sensitive = False dialog_result = self._start_next_timer_dialog.get_response() self._status_button.props.sensitive = True if dialog_result: # Start next timer self._stop_sound() self._call_notify(show=False) self._stop_pulsing_button() self._start_next_timer() else: self._stop_sound() self._call_notify(show=False) self._stop_pulsing_button() print "Updating status button..." self._update_status_button() print "Updating popup menu..." self._update_popup_menu()