def onPopupMenu(self, statusIcon, button, time): """ The user asks for the popup menu """ if self.popupMenu is None: wTree = loadGladeFile('StatusIconMenu.ui') self.menuPlay = wTree.get_object('item-play') self.menuStop = wTree.get_object('item-stop') self.menuNext = wTree.get_object('item-next') self.popupMenu = wTree.get_object('menu-popup') self.menuPause = wTree.get_object('item-pause') self.menuPrevious = wTree.get_object('item-previous') self.menuSeparator = wTree.get_object('item-separator') # Connect handlers wTree.get_object('item-quit').connect('activate', lambda btn: modules.postQuitMsg()) wTree.get_object('item-preferences').connect('activate', lambda btn: modules.showPreferences()) self.menuPlay.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)) self.menuStop.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_STOP)) self.menuNext.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_NEXT)) self.menuPrevious.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_PREVIOUS)) self.menuPause.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)) self.popupMenu.show_all() # Enable only relevant menu entries self.menuStop.set_sensitive(self.isPlaying) self.menuNext.set_sensitive(self.isPlaying and self.trackHasNext) self.menuPause.set_sensitive(self.isPlaying and not self.isPaused) self.menuPrevious.set_sensitive(self.isPlaying and self.trackHasPrev) self.menuPlay.set_sensitive((not (self.isPlaying or self.emptyTracklist)) or self.isPaused) self.popupMenu.popup(None, None, gtk.status_icon_position_menu, button, time, statusIcon)
def onShowPopupMenu(self, tree, button, time, path): """ Show a popup menu """ if self.popup is None: self.popup = tools.loadGladeFile('AudioCDMenu.glade') self.popup.get_widget('menu-popup').show_all() self.popup.get_widget('item-add').connect('activate', lambda widget: self.playPaths(tree, None, False)) self.popup.get_widget('item-play').connect('activate', lambda widget: self.playPaths(tree, None, True)) self.popup.get_widget('item-refresh').connect('activate', lambda widget: self.reloadDisc()) self.popup.get_widget('menu-popup').popup(None, None, None, button, time)
def getAuthInfo(id, reason, defaultLogin=None, force=False, parent=None): """ The parameter id may be any arbitrary string, but it must be unique as it identifies the login information given by the user. If a {login/password} is already known for this identifier, it is immediately returned without asking anything to the user. If no login is currently known, ask the user for the authentication information. """ global mBtnOk, mAuthDlg, mChkStore, mTxtLogin, mTxtPasswd if not force: authInfo = __loadAuthInfo(id) if authInfo is not None: return authInfo if mAuthDlg is None: wTree = tools.loadGladeFile('Authentication.glade') mBtnOk = wTree.get_widget('btn-ok') mAuthDlg = wTree.get_widget('dlg-main') mChkStore = wTree.get_widget('chk-store') mTxtLogin = wTree.get_widget('txt-login') mTxtPasswd = wTree.get_widget('txt-passwd') wTree.get_widget('lbl-reason').set_text(_('Enter your username and password for\n%(reason)s') % {'reason': reason}) wTree.get_widget('dlg-action_area').set_child_secondary(wTree.get_widget('btn-help'), True) # Glade fails to do that wTree.get_widget('lbl-title').set_markup('<big><big><big><b>%s</b></big></big></big>' % _('Password required')) mAuthDlg.set_title(consts.appName) mAuthDlg.resize_children() mAuthDlg.connect('response', onResponse) mTxtLogin.connect('changed', lambda entry: mBtnOk.set_sensitive(mTxtLogin.get_text() != '' and mTxtPasswd.get_text() != '')) mTxtPasswd.connect('changed', lambda entry: mBtnOk.set_sensitive(mTxtLogin.get_text() != '' and mTxtPasswd.get_text() != '')) if defaultLogin is not None: mTxtLogin.set_text(defaultLogin) mTxtPasswd.set_text('') mTxtPasswd.grab_focus() else: mTxtLogin.set_text('') mTxtPasswd.set_text('') mTxtLogin.grab_focus() mBtnOk.set_sensitive(False) mAuthDlg.show_all() respId = mAuthDlg.run() mAuthDlg.hide() if respId == gtk.RESPONSE_OK: login = mTxtLogin.get_text() passwd = mTxtPasswd.get_text() if mChkStore.get_active(): __storeAuthInfo(id, login, passwd) return (login, passwd) return None
def main(): log.logger.info('Started') # Localization locale.setlocale(locale.LC_ALL, '') gettext.textdomain(consts.appNameShort) gettext.bindtextdomain(consts.appNameShort, consts.dirLocale) # Command line prefs.setCmdLine((optOptions, optArgs)) # PyGTK initialization gobject.threads_init() gtk.window_set_default_icon_list( gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon16), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon24), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon32), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon48), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon64), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon128)) # Create the GUI wTree = loadGladeFile('MainWindow.ui') paned = wTree.get_object('pan-main') window = wTree.get_object('win-main') prefs.setWidgetsTree(wTree) # RGBA support try: colormap = window.get_screen().get_rgba_colormap() if colormap: gtk.widget_set_default_colormap(colormap) except: log.logger.info('No RGBA support (requires PyGTK 2.10+)') # Show all widgets and restore the window size BEFORE hiding some of them # when restoring the view mode # Resizing must be done before showing the window to make sure that the WM # correctly places the window if prefs.get(__name__, 'win-is-maximized', DEFAULT_MAXIMIZED_STATE): window.maximize() height = prefs.get(__name__, 'win-height', DEFAULT_WIN_HEIGHT) window.resize(prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH), height) window.show_all() # Restore sizes once more #window.resize(prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH), height) paned.set_position(prefs.get(__name__, 'paned-pos', DEFAULT_PANED_POS)) # Initialization done, let's continue the show gobject.idle_add(realStartup, window, paned) gtk.main()
def main(): log.logger.info('Started') # Localization locale.setlocale(locale.LC_ALL, '') gettext.textdomain(consts.appNameShort) gettext.bindtextdomain(consts.appNameShort, consts.dirLocale) # Command line prefs.setCmdLine((optOptions, optArgs)) # Create the GUI wTree = loadGladeFile('MainWindow.ui') paned = wTree.get_object('pan-main') window = wTree.get_object('win-main') prefs.setWidgetsTree(wTree) window.set_icon_list([ GdkPixbuf.Pixbuf.new_from_file(consts.fileImgIcon16), GdkPixbuf.Pixbuf.new_from_file(consts.fileImgIcon24), GdkPixbuf.Pixbuf.new_from_file(consts.fileImgIcon32), GdkPixbuf.Pixbuf.new_from_file(consts.fileImgIcon48), GdkPixbuf.Pixbuf.new_from_file(consts.fileImgIcon64), GdkPixbuf.Pixbuf.new_from_file(consts.fileImgIcon128)]) # RGBA support # TODO: Is this still needed? visual = window.get_screen().get_rgba_visual() window.set_visual(visual) # Show all widgets and restore the window size BEFORE hiding some of them # when restoring the view mode # Resizing must be done before showing the window to make sure that the WM # correctly places the window if prefs.get(__name__, 'win-is-maximized', DEFAULT_MAXIMIZED_STATE): window.maximize() height = prefs.get(__name__, 'win-height', DEFAULT_WIN_HEIGHT) window.resize(prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH), height) window.show_all() # Restore sizes once more #window.resize(prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH), height) paned.set_position(prefs.get(__name__, 'paned-pos', DEFAULT_PANED_POS)) # Initialization done, let's continue the show GObject.idle_add(realStartup, window, paned) Gtk.main()
def __init__(self, title): """ Constructor """ global mDlg, mTxtBuffer if mDlg is None: wTree = tools.loadGladeFile('HelpDlg.ui') mDlg = wTree.get_object('dlg-main') mTxtBuffer = wTree.get_object('txt-help').get_buffer() mDlg.set_title(tools.consts.appName) mTxtBuffer.create_tag('title', weight=pango.WEIGHT_BOLD, scale=pango.SCALE_X_LARGE) mTxtBuffer.create_tag('section', weight=pango.WEIGHT_BOLD, scale=pango.SCALE_LARGE) self.nbSections = 0 mTxtBuffer.set_text('') mTxtBuffer.insert_with_tags_by_name(mTxtBuffer.get_end_iter(), title + '\n', 'title')
def __init__(self, resFile, container, modName, title, defaultWidth, defaultHeight): """ Constructor """ GObject.GObject.__init__(self) # Load only the top-level container of the given .ui file _, self.wBuilder = tools.loadGladeFile(resFile, container) self.visible = False self.modName = modName # Configure the window self.set_title(title) self.wBuilder.get_object(container).reparent(self) if tools.prefs.get(modName, 'win-is-maximized', False): self.maximize() self.resize(tools.prefs.get(modName, 'win-width', defaultWidth), tools.prefs.get(modName, 'win-height', defaultHeight)) self.set_position(Gtk.WindowPosition.CENTER) # Connect GTK handlers self.connect('delete-event', self.onDelete) self.connect('size-allocate', self.onResize) self.connect('window-state-event', self.onState)
def __init__(self, resFile, container, modName, title, defaultWidth, defaultHeight): """ Constructor """ gtk.Window.__init__(self) # Load only the top-level container of the given glade file self.wTree = tools.loadGladeFile(resFile, container) self.visible = False self.modName = modName # Configure the window self.set_title(title) self.add(self.wTree.get_widget(container)) if tools.prefs.get(modName, 'win-is-maximized', False): self.maximize() self.resize(tools.prefs.get(modName, 'win-width', defaultWidth), tools.prefs.get(modName, 'win-height', defaultHeight)) self.set_position(gtk.WIN_POS_CENTER) # Connect GTK handlers self.connect('delete-event', self.onDelete) self.connect('size-allocate', self.onResize) self.connect('window-state-event', self.onState)
def __init__(self, title): """ Constructor """ wTree = tools.loadGladeFile('HelpDlg.ui') self.dialog = wTree.get_object('dlg-main') self.text_buffer = wTree.get_object('txt-help').get_buffer() self.dialog.set_title(tools.consts.appName) self.text_buffer.create_tag('title', weight=Pango.Weight.BOLD, scale=PANGO_SCALE_FACTOR**2) self.text_buffer.create_tag('section', weight=Pango.Weight.BOLD, scale=PANGO_SCALE_FACTOR) self.nbSections = 0 self.text_buffer.set_text('') self.text_buffer.insert_with_tags_by_name( self.text_buffer.get_end_iter(), title + '\n', 'title')
def __init__(self, title, parent, forbiddenNames=[], forbiddenChars=[]): """ Constructor """ wTree = tools.loadGladeFile('SelectPath.glade') self.btnOk = wTree.get_widget('btn-ok') self.dialog = wTree.get_widget('dlg') self.txtName = wTree.get_widget('txt-name') self.txtPath = wTree.get_widget('txt-path') self.btnOpen = wTree.get_widget('btn-open') self.forbiddenNames = forbiddenNames self.forbiddenChars = forbiddenChars self.dialog.set_title(title) self.dialog.set_transient_for(parent) # Handlers self.btnOpen.connect('clicked', self.onBtnOpen) self.txtName.connect('changed', self.onTxtFieldChanged) self.txtPath.connect('changed', self.onTxtFieldChanged) self.dialog.connect('response', self.onCheckDlgResponse)
def __init__(self, parent, primaryText, secondaryText): """ Contructor """ self.parent = parent self.cancelled = False # Widgets self.wTree = tools.loadGladeFile('Progress.glade') self.dialog = self.wTree.get_widget('dlg') self.lblCurrent = self.wTree.get_widget('lbl-current') self.progressBar = self.wTree.get_widget('progress-bar') # GTK+ handlers self.wTree.get_widget('btn-cancel').connect('clicked', self.onCancel) # Configure and show the progress dialog if parent is not None: parent.set_sensitive(False) self.dialog.set_transient_for(parent) self.setPrimaryText(primaryText) self.setSecondaryText(secondaryText) self.dialog.set_title(tools.consts.appName) self.dialog.set_deletable(False) self.dialog.show_all()
gettext.textdomain(consts.appNameShort) gettext.bindtextdomain(consts.appNameShort, consts.dirLocale) # PyGTK initialization gobject.threads_init() gtk.window_set_default_icon_list(gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon16), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon24), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon32), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon48), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon64), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon128)) # Create the GUI wtree = loadGladeFile('MainWindow.ui') window = wtree.get_object('win-main') prefs.setWidgetsTree(wtree) # RGBA support try: colormap = window.get_screen().get_rgba_colormap() if colormap: gtk.widget_set_default_colormap(colormap) except: log.logger.info('No RGBA support (requires PyGTK 2.10+)') # This object takes care of the window (mainly event handlers) mainWindow.MainWindow(wtree, window)
# Command line parser = optparse.OptionParser(usage='Usage: %prog [options] [FILE(s)]') parser.add_option('-p', '--playbin2', action='store_true', default=False, help='use the playbin2 GStreamer component (unstable)') prefs.setCmdLine(parser.parse_args()) # PyGTK initialization gobject.threads_init() gtk.window_set_default_icon_list(gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon16), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon24), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon32), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon48), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon64), gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon128)) # Create the GUI wTree = loadGladeFile('MainWindow.glade') paned = wTree.get_widget('pan-main') window = wTree.get_widget('win-main') prefs.setWidgetsTree(wTree) # RGBA support try: colormap = window.get_screen().get_rgba_colormap() if colormap: gtk.widget_set_default_colormap(colormap) except: log.logger.info('No RGBA support (requires PyGTK 2.10+)') # Show all widgets and restore the window size BEFORE hiding some of them when restoring the view mode # Resizing must be done before showing the window to make sure that the WM correctly places the window if prefs.get(__name__, 'win-is-maximized', DEFAULT_MAXIMIZED_STATE):