def update_timer(self): """ Updates the timer, sets the tooltip and calls the dialog. Refactor this function. """ # Keep working if self.current_status == 0 and self.timer.time_left: time_left = seconds_to_minutes(self.timer.time_left) time_str = 'Pomodoro4linux - %02d:%02d' % (time_left) self.status_icon.set_tooltip(time_str) # Go get some coffee elif self.current_status == 0 and not self.timer.time_left: self.warn_coffee_break() # Keep breaking elif self.current_status == 1 and self.timer.time_left: self._set_icon() time_left = seconds_to_minutes(self.timer.time_left) label_str = 'Coffee Break\nRest for %02d:%02d minutes.' % \ (time_left) self._set_label(label_str) # Come back to work, lazy boy elif self.current_status == 1 and not self.timer.time_left: label_str = 'You should be working now!' self._set_label(label_str) self.pause_timer() self.current_status = 0 self.timer.time_left = self.timer.work_time return True
def update_timer(self): """ Updates the timer, sets the tooltip and calls the dialog. Refactor this function. """ # Keep working if self.current_status == 0 and self.timer.time_left: time_left = seconds_to_minutes(self.timer.time_left) time_str = 'Pomodoro4linux - %02d:%02d' % (time_left) self.status_icon.set_tooltip(time_str) # Go get some coffee elif self.current_status == 0 and not self.timer.time_left: if self.break_count < self.timer.max_break_count: self.image.set_from_file(REST_ICON) self.break_count += 1 self.warn_coffee_break() else: self.image.set_from_file(LONG_REST_ICON) self.break_count = 0 self.warn_long_break() # Keep breaking elif self.current_status == 1 and self.timer.time_left: self._set_icon() time_left = seconds_to_minutes(self.timer.time_left) if self.break_count == 0: label_str = 'Long Break\nRest for %02d:%02d minutes.' % \ (time_left) else: label_str = 'Coffee Break\nRest for %02d:%02d minutes. (%d/%d)' % \ (time_left[0],time_left[1],self.break_count,self.timer.max_break_count) self.dialog.set_markup(label_str) # Come back to work, lazy boy elif self.current_status == 1 and not self.timer.time_left: label_str = 'You should be working now!' self.image.set_from_file(WORK_ICON) self.dialog.set_markup(label_str) self.pause_timer() self.current_status = 0 self.timer.time_left = self.timer.work_time return True
def warn_long_break(self): """ The dialog. """ self.current_status = 1 self.timer.time_left = self.timer.long_rest_time time_left = seconds_to_minutes(self.timer.time_left) label_str = 'Long Break\nRest for %02d:%02d minutes.' % \ (time_left) self.dialog.set_markup(label_str) self.dialog.show_all() timeout_add(1000, self.update_timer) self.dialog.run() self.dialog.hide() self.timer.time_left = self.timer.work_time self.start_timer()
def warn_coffee_break(self): """ The dialog. """ self.current_status = 1 self.timer.time_left = self.timer.rest_time time_left = seconds_to_minutes(self.timer.time_left) label_str = 'Coffee Break\nRest for %02d:%02d minutes. (%d/%d)' % \ (time_left[0],time_left[1],self.break_count,self.timer.max_break_count) self.dialog.set_markup(label_str) self.dialog.show_all() timeout_add(1000, self.update_timer) self.dialog.run() self.dialog.hide() self.timer.time_left = self.timer.work_time self.start_timer()
def warn_coffee_break(self): """ The dialog. """ self.current_status = 1 self.timer.time_left = self.timer.rest_time self.dialog.set_default_size(180, 120) self.dialog.set_keep_above(True) self.dialog.set_icon_from_file(WORK_ICON) time_left = seconds_to_minutes(self.timer.time_left) label = 'Coffee Break\nRest for %02d:%02d minutes.' % (time_left) self.label.set_text(label) self.dialog.vbox.pack_start(self.label) self.label.show_now() self.dialog.show_now() timeout_add(1000, self.update_timer) self.dialog.run() self.dialog.destroy() self.timer.time_left = self.timer.work_time self.start_timer()