def key_press_event(window, event): if blagui.is_accel(event, "Escape"): window.child.emit("toggle_fullscreen") elif blagui.is_accel(event, "space"): player.play_pause() elif blagui.is_accel(event, "<Ctrl>Q"): blaplay.shutdown()
def __tray_menu(self, icon, button, activation_time): import blaplay menu = blaguiutils.create_control_popup_menu() menu.append(gtk.SeparatorMenuItem()) # Add last.fm submenu. submenu = blafm.create_popup_menu() if submenu: m = gtk.MenuItem("last.fm") m.set_submenu(submenu) menu.append(m) menu.append(gtk.SeparatorMenuItem()) # Add quit option. m = gtk.MenuItem("Quit") m.connect("activate", lambda *x: blaplay.shutdown()) menu.append(m) menu.show_all() menu.popup(None, None, None, button, activation_time)
def idle_quit(): import blaplay blaplay.shutdown()
def Quit(self): import blaplay blaplay.shutdown()
def __init__(self): super(BlaMainWindow, self).__init__(gtk.WINDOW_TOPLEVEL) self.set_resizable(True) self.connect("delete_event", self.__delete_event) self.enable_tracking(is_main_window=True) # Set up the fullscreen window. self.__fullscreen_window = gtk.Window() def map_(window): pass self.__fullscreen_window.connect("map", map_) self.__fullscreen_window.set_modal(True) self.__fullscreen_window.set_transient_for(self) self.__fullscreen_window.connect_object( "window_state_event", BlaMainWindow.__window_state_event, self) def key_press_event(window, event): if blagui.is_accel(event, "Escape"): window.child.emit("toggle_fullscreen") elif blagui.is_accel(event, "space"): player.play_pause() elif blagui.is_accel(event, "<Ctrl>Q"): blaplay.shutdown() self.__fullscreen_window.connect_object( "key_press_event", key_press_event, self.__fullscreen_window) # Realize the fullscreen window. If we don't do this here and reparent # the drawingarea to it later that in turn will get unrealized again, # causing bad X window errors. self.__fullscreen_window.realize() # Install a global mouse hook. If connected callbacks don't consume the # event by returning True this hook gets called for every widget in the # hierarchy that re-emits the event. We therefore cache the event's # timestamp to detect and ignore signal re-emissions. def button_press_hook(receiver, event): event_time = event.get_time() if event_time != self.__previous_event_time: self.__previous_event_time = event_time if event.button == 8: player.previous() elif event.button == 9: player.next() # This behaves like gobject.{timeout|idle}_add: if the callback # doesn't return True it's only called once. It does NOT prevent # signal callbacks from executing. return True self.__previous_event_time = -1 gobject.add_emission_hook(self, "button_press_event", button_press_hook) # Main menu ui_manager = blaplay.bla.ui_manager self.add_accel_group(ui_manager.get_accel_group()) actions = [ # Menus and submenus ("File", None, "_File"), ("Edit", None, "_Edit"), ("Select", None, "S_elect"), ("Selection", None, "Se_lection"), ("NewPlaylistFrom", None, "_New playlist from"), ("PlayOrder", None, "_Order"), ("View", None, "_View"), ("Help", None, "_Help"), # Menu items ("OpenPlaylist", None, "Open playlist...", None, "", self.__open_playlist), ("AddFiles", None, "Add _files...", None, "", lambda *x: self.__add_tracks()), ("AddDirectories", None, "_Add directories...", None, "", lambda *x: self.__add_tracks(files=False)), ("SavePlaylist", None, "_Save playlist...", None, "", self.__save_playlist), ("Quit", gtk.STOCK_QUIT, "_Quit", "<Ctrl>Q", "", lambda *x: blaplay.shutdown()), ("Preferences", None, "Pre_ferences...", None, "", BlaPreferences), ("About", None, "_About...", None, "", BlaAbout) ] ui_manager.add_actions(actions) toggle_actions = [ ("Statusbar", None, "St_atusbar", None, "", self.__toggle_statusbar, blacfg.getboolean("general", "statusbar")), ("Visualization", None, "Visualization", None, "", self.__toggle_visualization, blacfg.getboolean("general", "show.visualization")) ] ui_manager.add_toggle_actions(toggle_actions) radio_actions = [ ("OrderNormal", None, "_Normal", None, "", blaconst.ORDER_NORMAL), ("OrderRepeat", None, "_Repeat", None, "", blaconst.ORDER_REPEAT), ("OrderShuffle", None, "_Shuffle", None, "", blaconst.ORDER_SHUFFLE) ] # TODO: Emit "order_changed" signal in the on_change handler instead # and let interested widgets handle this instead. ui_manager.add_radio_actions( radio_actions, value=blacfg.getint("general", "play.order"), on_change=BlaStatusbar.set_order) # This is the topmost box that holds all the other components. self.add(gtk.VBox()) # Create instances of the main parts of the GUI. self.__toolbar = BlaToolbar() self.__browsers = BlaBrowsers() self.__visualization = BlaVisualization() self.__view = BlaView() self.__statusbar = BlaStatusbar() # Group browsers and visualization widget. self.__vbox_left = gtk.VBox(spacing=blaconst.WIDGET_SPACING) self.__vbox_left.pack_start(self.__browsers, expand=True) self.__vbox_left.pack_start(self.__visualization, expand=False) self.__vbox_left.show() # Pack the browser + view-widget into a gtk.HPane instance. hpane = gtk.HPaned() hpane.pack1(self.__vbox_left, resize=False, shrink=False) hpane.pack2(self.__view, resize=True, shrink=True) hpane.show() # Restore pane positions. def notify(pane, propspec, key): blacfg.set("general", key, str(pane.get_position())) for pane, side in [(hpane, "left"), (self.__view, "right")]: key = "pane.pos.%s" % side try: pane.set_position(blacfg.getint("general", key)) except TypeError: pass pane.connect("notify", notify, key) # Create a vbox hpane and the statusbar. This allows for setting a # border around those items which excludes the menubar and the toolbar. vbox = gtk.VBox(spacing=blaconst.BORDER_PADDING) vbox.set_border_width(blaconst.BORDER_PADDING) vbox.pack_start(hpane) vbox.pack_start(self.__statusbar, expand=False) vbox.show() self.child.pack_start(ui_manager.get_widget("/Menu"), expand=False) self.child.pack_start(self.__toolbar, expand=False) self.child.pack_start(vbox) self.child.show() self.__tray = BlaTray() def update_title(*args): self.__update_title() player.connect("state_changed", update_title) library.connect("library_updated", update_title) self.__update_title()
def __delete_event(self, window, event): if blacfg.getboolean("general", "close.to.tray"): self.toggle_hide() return True blaplay.shutdown() return False