def _update_popup_menu(self): popup = self.applet.get_popup_component() timer_state = self.timer.get_state() has_next_timer = self.timer.get_next_timer() show_pause = (timer_state == Timer.STATE_RUNNING) show_continue = (timer_state == Timer.STATE_PAUSED) show_stop = (timer_state == Timer.STATE_RUNNING or timer_state == Timer.STATE_PAUSED or timer_state == Timer.STATE_FINISHED) show_restart = (timer_state == Timer.STATE_RUNNING or timer_state == Timer.STATE_PAUSED or timer_state == Timer.STATE_FINISHED) show_next_timer = ((timer_state == Timer.STATE_RUNNING or timer_state == Timer.STATE_PAUSED or timer_state == Timer.STATE_FINISHED) and # Only show this popup menu item if it has a # next_timer defined. Clever, huh? ;) has_next_timer) show_presets_menu = (len(self.presets_store.get_model()) > 0) show_separator = ( show_presets_menu or show_pause or show_next_timer or show_continue or show_stop or show_restart) to_hidden_str = lambda show: ('0', '1')[not show] popup.set_prop('/commands/PauseTimer', 'hidden', to_hidden_str(show_pause)) popup.set_prop('/commands/ContinueTimer', 'hidden', to_hidden_str(show_continue)) popup.set_prop('/commands/StopTimer', 'hidden', to_hidden_str(show_stop)) popup.set_prop('/commands/RestartTimer', 'hidden', to_hidden_str(show_restart)) popup.set_prop('/commands/StartNextTimer', 'hidden', to_hidden_str(show_next_timer)) popup.set_prop(TimerApplet.PRESETS_PATH, 'hidden', to_hidden_str(show_presets_menu)) popup.set_prop('/popups/popup/Separator1', 'hidden', to_hidden_str(show_separator)) # Rebuild the Presets submenu if popup.path_exists(TimerApplet.PRESETS_PLACEHOLDER_PATH): popup.rm(TimerApplet.PRESETS_PLACEHOLDER_PATH) popup.set_translate(TimerApplet.PRESETS_PATH, '<placeholder name="%s"/>' % TimerApplet.PRESETS_PLACEHOLDER_NAME) preset_number = 1 row_iter = self.presets_store.get_model().get_iter_first() while row_iter is not None: verb = ('Preset_%d' % preset_number) preset_number += 1 display_text = utils.get_preset_display_text(self._presets_store, row_iter) node_xml = '<menuitem verb="%s" name="%s" label="%s"/>' % (verb, verb, display_text) popup.set_translate(TimerApplet.PRESETS_PLACEHOLDER_PATH, node_xml) popup.add_verb(verb, self._on_presets_submenu_item_activated, self.presets_store.get_model().get_path(row_iter)) row_iter = self.presets_store.get_model().iter_next(row_iter)
def __init__(self): self.presets_store = PresetsStore(config.PRESETS_PATH) self.manage_presets_dialog = ManagePresetsDialog( self.presets_store.get_model(), lambda row_iter: utils.get_preset_display_text(self._presets_store, row_iter)) self.manage_presets_dialog.connect('clicked-add', self.on_mgr_clicked_add) self.manage_presets_dialog.connect('clicked-edit', self.on_mgr_clicked_edit) self.manage_presets_dialog.connect('clicked-remove', self.on_mgr_clicked_remove) Gtk.Window.set_default_icon_from_file(config.ICON_PATH)
def __init__(self): self._presets_store = core.PresetsStore(config.PRESETS_PATH) self._manage_presets_dialog = ui.ManagePresetsDialog(config.GLADE_PATH, self._presets_store.get_model(), lambda row_iter: utils.get_preset_display_text(self._presets_store, row_iter)) self._manage_presets_dialog.connect('clicked-add', self._on_mgr_clicked_add) self._manage_presets_dialog.connect('clicked-edit', self._on_mgr_clicked_edit) self._manage_presets_dialog.connect('clicked-remove', self._on_mgr_clicked_remove) gtk.window_set_default_icon_from_file(config.ICON_PATH)
def __init__(self, presets_store, manage_presets_dialog, applet, timer, gsettings): self.presets_store = presets_store self.manage_presets_dialog = manage_presets_dialog self.applet = applet self.timer = timer self.gsettings = gsettings self.gst_playbin = gst.element_factory_make('playbin', 'player') def bus_event(bus, message): t = message.type if t == gst.MESSAGE_EOS: self.gst_playbin.set_state(gst.STATE_NULL) elif t == gst.MESSAGE_ERROR: self.gst_playbin.set_state(gst.STATE_NULL) err, debug = message.parse_error() print 'Error playing sound: %s' % err, debug return True self.gst_playbin.get_bus().add_watch(bus_event) self.status_button = StatusButton() self.notifier = Notifier('TimerApplet', Gtk.STOCK_DIALOG_INFO, self.status_button) self.start_next_timer_dialog = StartNextTimerDialog( "Start next timer", "Would you like to start the next timer?") self.start_timer_dialog = StartTimerDialog( lambda name: utils.is_valid_preset_name(name, self._presets_store), self.presets_store.get_model(), lambda row_iter: utils.get_preset_display_text(self._presets_store, row_iter)) self.continue_dialog = ContinueTimerDialog(_('Continue timer countdown?'), _('The timer is currently paused. Would you like to continue countdown?')) self.preferences_dialog = PreferencesDialog() self.about_dialog = AboutDialog() # FIX ME: this needs to fix #self.applet.set_applet_flags(mateapplet.EXPAND_MINOR) # FIX ME: need a Gtk.ActionGroup here! # Learn how to add an ActionGroup action_group = Gtk.ActionGroup("applet_actions") action_group.add_actions( [('PauseTimer', Gtk.STOCK_MEDIA_PAUSE, _("PauseTimer"), None, None, lambda action: self.timer.stop()), ('ContinueTimer', Gtk.STOCK_MEDIA_PLAY, _("ContinueTimer"), None, None, lambda action: self.timer.start()), ('StopTimer', Gtk.STOCK_MEDIA_STOP, _("StopTimer"), None, None, lambda action: self.timer.reset()), ('RestartTimer', Gtk.STOCK_REFRESH, _("RestartTimer"), None, None, lambda action: self._restart_timer()), ('StartNextTimer', Gtk.STOCK_MEDIA_NEXT, _("StartNextTimer"), None, None, lambda action: self._start_next_timer()), ('ManagePresets', Gtk.STOCK_INFO, _("ManagePresets"), None, None, lambda action: self.manage_presets_dialog.show()), ('Preferences', Gtk.STOCK_PREFERENCES, _("Preferences"), None, None, lambda action: self.preferences_dialog.show()), ('About', Gtk.STOCK_ABOUT, _("About"), None, None, lambda action: self.about_dialog.show())] ) self.applet.setup_menu_from_file( config.POPUP_MENU_FILE_PATH, action_group ) self.applet.add(self.status_button) # Remove padding around button contents. force_no_focus_padding(self.status_button) # TODO: # Fix bug in which button would not propogate middle-clicks # and right-clicks to the applet. self.status_button.connect('button-press-event', on_widget_button_press_event) self.status_button.set_relief(Gtk.ReliefStyle.NONE) #self.status_button.set_icon(config.ICON_PATH); self.applet.set_tooltip_text(_("Timer Applet")) self._connect_signals() #self._update_status_button() #self._update_popup_menu() #self._update_preferences_dialog() self.status_button.show() self.applet.show_all()
def __init__(self, presets_store, manage_presets_dialog, applet, timer, mateconf_wrapper): self._presets_store = presets_store self._manage_presets_dialog = manage_presets_dialog self._applet = applet self._timer = timer self._gst_playbin = gst.element_factory_make('playbin', 'player') def bus_event(bus, message): t = message.type if t == gst.MESSAGE_EOS: self._gst_playbin.set_state(gst.STATE_NULL) elif t == gst.MESSAGE_ERROR: self._gst_playbin.set_state(gst.STATE_NULL) err, debug = message.parse_error() print 'Error playing sound: %s' % err, debug return True self._gst_playbin.get_bus().add_watch(bus_event) self._status_button = ui.StatusButton() self._notifier = ui.Notifier('TimerApplet', gtk.STOCK_DIALOG_INFO, self._status_button) self._start_next_timer_dialog = ui.StartNextTimerDialog( config.GLADE_PATH, "Start next timer", "Would you like to start the next timer?") self._start_timer_dialog = ui.StartTimerDialog(config.GLADE_PATH, lambda name: utils.is_valid_preset_name(name, self._presets_store), self._presets_store.get_model(), lambda row_iter: utils.get_preset_display_text(self._presets_store, row_iter)) self._continue_dialog = ui.ContinueTimerDialog(config.GLADE_PATH, _('Continue timer countdown?'), _('The timer is currently paused. Would you like to continue countdown?')) self._preferences_dialog = ui.PreferencesDialog(config.GLADE_PATH) self._mateconf = mateconf_wrapper self._about_dialog = glade.XML(config.GLADE_PATH, 'about_dialog').get_widget('about_dialog') self._about_dialog.set_version(config.VERSION) self._applet.set_applet_flags(mateapplet.EXPAND_MINOR) self._applet.setup_menu_from_file( None, config.POPUP_MENU_FILE_PATH, None, [('PauseTimer', lambda component, verb: self._timer.stop()), ('ContinueTimer', lambda component, verb: self._timer.start()), ('StopTimer', lambda component, verb: self._timer.reset()), ('RestartTimer', lambda component, verb: self._restart_timer()), ('StartNextTimer', lambda component, verb: self._start_next_timer()), ('ManagePresets', lambda component, verb: self._manage_presets_dialog.show()), ('Preferences', lambda component, verb: self._preferences_dialog.show()), ('About', lambda component, verb: self._about_dialog.show())] ) self._applet.add(self._status_button) # Remove padding around button contents. force_no_focus_padding(self._status_button) # TODO: # Fix bug in which button would not propogate middle-clicks # and right-clicks to the applet. self._status_button.connect('button-press-event', on_widget_button_press_event) self._status_button.set_relief(gtk.RELIEF_NONE) self._status_button.set_icon(config.ICON_PATH); self._applet.set_tooltip_text(_("Timer Applet")) self._connect_signals() self._update_status_button() self._update_popup_menu() self._update_preferences_dialog() self._status_button.show() self._applet.show()
def __init__(self, presets_store, manage_presets_dialog, applet, timer, mateconf_wrapper): self._presets_store = presets_store self._manage_presets_dialog = manage_presets_dialog self._applet = applet self._timer = timer self._gst_playbin = gst.element_factory_make('playbin', 'player') def bus_event(bus, message): t = message.type if t == gst.MESSAGE_EOS: self._gst_playbin.set_state(gst.STATE_NULL) elif t == gst.MESSAGE_ERROR: self._gst_playbin.set_state(gst.STATE_NULL) err, debug = message.parse_error() print 'Error playing sound: %s' % err, debug return True self._gst_playbin.get_bus().add_watch(bus_event) self._status_button = ui.StatusButton() self._notifier = ui.Notifier('TimerApplet', gtk.STOCK_DIALOG_INFO, self._status_button) self._start_next_timer_dialog = ui.StartNextTimerDialog( config.GLADE_PATH, "Start next timer", "Would you like to start the next timer?") self._start_timer_dialog = ui.StartTimerDialog( config.GLADE_PATH, lambda name: utils.is_valid_preset_name(name, self._presets_store), self._presets_store.get_model(), lambda row_iter: utils.get_preset_display_text( self._presets_store, row_iter)) self._continue_dialog = ui.ContinueTimerDialog( config.GLADE_PATH, _('Continue timer countdown?'), _('The timer is currently paused. Would you like to continue countdown?' )) self._preferences_dialog = ui.PreferencesDialog(config.GLADE_PATH) self._mateconf = mateconf_wrapper self._about_dialog = glade.XML( config.GLADE_PATH, 'about_dialog').get_widget('about_dialog') self._about_dialog.set_version(config.VERSION) self._applet.set_applet_flags(mateapplet.EXPAND_MINOR) self._applet.setup_menu_from_file( None, config.POPUP_MENU_FILE_PATH, None, [('PauseTimer', lambda component, verb: self._timer.stop()), ('ContinueTimer', lambda component, verb: self._timer.start()), ('StopTimer', lambda component, verb: self._timer.reset()), ('RestartTimer', lambda component, verb: self._restart_timer()), ('StartNextTimer', lambda component, verb: self._start_next_timer()), ('ManagePresets', lambda component, verb: self._manage_presets_dialog.show()), ('Preferences', lambda component, verb: self._preferences_dialog.show()), ('About', lambda component, verb: self._about_dialog.show())]) self._applet.add(self._status_button) # Remove padding around button contents. force_no_focus_padding(self._status_button) # TODO: # Fix bug in which button would not propogate middle-clicks # and right-clicks to the applet. self._status_button.connect('button-press-event', on_widget_button_press_event) self._status_button.set_relief(gtk.RELIEF_NONE) self._status_button.set_icon(config.ICON_PATH) self._applet.set_tooltip_text(_("Timer Applet")) self._connect_signals() self._update_status_button() self._update_popup_menu() self._update_preferences_dialog() self._status_button.show() self._applet.show()
def _update_popup_menu(self): popup = self._applet.get_popup_component() timer_state = self._timer.get_state() has_next_timer = self._timer.get_next_timer() show_pause = (timer_state == core.Timer.STATE_RUNNING) show_continue = (timer_state == core.Timer.STATE_PAUSED) show_stop = (timer_state == core.Timer.STATE_RUNNING or timer_state == core.Timer.STATE_PAUSED or timer_state == core.Timer.STATE_FINISHED) show_restart = (timer_state == core.Timer.STATE_RUNNING or timer_state == core.Timer.STATE_PAUSED or timer_state == core.Timer.STATE_FINISHED) show_next_timer = ( (timer_state == core.Timer.STATE_RUNNING or timer_state == core.Timer.STATE_PAUSED or timer_state == core.Timer.STATE_FINISHED) and # Only show this popup menu item if it has a # next_timer defined. Clever, huh? ;) has_next_timer) show_presets_menu = (len(self._presets_store.get_model()) > 0) show_separator = (show_presets_menu or show_pause or show_next_timer or show_continue or show_stop or show_restart) to_hidden_str = lambda show: ('0', '1')[not show] popup.set_prop('/commands/PauseTimer', 'hidden', to_hidden_str(show_pause)) popup.set_prop('/commands/ContinueTimer', 'hidden', to_hidden_str(show_continue)) popup.set_prop('/commands/StopTimer', 'hidden', to_hidden_str(show_stop)) popup.set_prop('/commands/RestartTimer', 'hidden', to_hidden_str(show_restart)) popup.set_prop('/commands/StartNextTimer', 'hidden', to_hidden_str(show_next_timer)) popup.set_prop(TimerApplet._PRESETS_PATH, 'hidden', to_hidden_str(show_presets_menu)) popup.set_prop('/popups/popup/Separator1', 'hidden', to_hidden_str(show_separator)) # Rebuild the Presets submenu if popup.path_exists(TimerApplet._PRESETS_PLACEHOLDER_PATH): popup.rm(TimerApplet._PRESETS_PLACEHOLDER_PATH) popup.set_translate( TimerApplet._PRESETS_PATH, '<placeholder name="%s"/>' % TimerApplet._PRESETS_PLACEHOLDER_NAME) preset_number = 1 row_iter = self._presets_store.get_model().get_iter_first() while row_iter is not None: verb = ('Preset_%d' % preset_number) preset_number += 1 display_text = utils.get_preset_display_text( self._presets_store, row_iter) node_xml = '<menuitem verb="%s" name="%s" label="%s"/>' % ( verb, verb, display_text) popup.set_translate(TimerApplet._PRESETS_PLACEHOLDER_PATH, node_xml) popup.add_verb(verb, self._on_presets_submenu_item_activated, self._presets_store.get_model().get_path(row_iter)) row_iter = self._presets_store.get_model().iter_next(row_iter)