def configure(self, parent): """ Show the configuration window """ if self.cfgWin is None: import gui # Create the window self.cfgWin = gui.window.Window('DesktopNotification.ui', 'vbox1', __name__, MOD_INFO[modules.MODINFO_L10N], 355, 345) self.cfgWin.getWidget('btn-ok').connect('clicked', self.onBtnOk) self.cfgWin.getWidget('btn-help').connect('clicked', self.onBtnHelp) self.cfgWin.getWidget('btn-cancel').connect( 'clicked', lambda btn: self.cfgWin.hide()) # Disable the 'Skip track' button if the server doesn't support buttons in notifications if 'actions' not in Notify.get_server_caps(): self.cfgWin.getWidget('chk-skipTrack').set_sensitive(False) if not self.cfgWin.isVisible(): self.cfgWin.getWidget('txt-title').set_text( prefs.get(__name__, 'title', PREFS_DEFAULT_TITLE)) self.cfgWin.getWidget('spn-duration').set_value( prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT)) self.cfgWin.getWidget('txt-body').get_buffer().set_text( prefs.get(__name__, 'body', PREFS_DEFAULT_BODY)) self.cfgWin.getWidget('chk-skipTrack').set_active( prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK)) self.cfgWin.getWidget('btn-ok').grab_focus() self.cfgWin.show()
def onAppStarted(self): """ The module has been loaded """ self.tree = None self.cfgWin = None self.folders = prefs.get(__name__, 'media-folders', PREFS_DEFAULT_MEDIA_FOLDERS) self.scrolled = gtk.ScrolledWindow() self.currRoot = None self.treeState = prefs.get(__name__, 'saved-states', {}) self.addByFilename = prefs.get(__name__, 'add-by-filename', PREFS_DEFAULT_ADD_BY_FILENAME) self.showHiddenFiles = prefs.get(__name__, 'show-hidden-files', PREFS_DEFAULT_SHOW_HIDDEN_FILES) self.scrolled.set_shadow_type(gtk.SHADOW_IN) self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.scrolled.show() for name in self.folders: modules.postMsg( consts.MSG_CMD_EXPLORER_ADD, { 'modName': MOD_L10N, 'expName': name, 'icon': icons.dirMenuIcon(), 'widget': self.scrolled })
def showNotification(self): """ Show the notification based on the current track """ self.timeout = None # Can this happen? if self.currTrack is None: return False # Contents body = self.currTrack.formatHTMLSafe( prefs.get(__name__, 'body', PREFS_DEFAULT_BODY)) title = self.currTrack.format( prefs.get(__name__, 'title', PREFS_DEFAULT_TITLE)) # Icon if self.currCover is None: img = consts.fileImgIcon64 else: img = self.currCover if os.path.isfile(img): icon = 'file://' + img else: icon = Gtk.STOCK_DIALOG_INFO # Create / Update the notification and show it if self.notif is None: self.__createNotification(title, body, icon) else: self.notif.update(title, body, icon) ## Catch errors that occur when pynotify is not installed properly try: self.notif.show() except GObject.GError: pass return False
def onBtnOk(self, btn): """ Save new preferences """ # Skipping tracks newSkipTrack = self.cfgWin.getWidget('chk-skipTrack').get_active() oldSkipTrack = prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK) prefs.set(__name__, 'skip-track', newSkipTrack) if oldSkipTrack != newSkipTrack and self.notif is not None: if newSkipTrack: self.notif.add_action('stop', _('Skip track'), self.onSkipTrack) else: self.notif.clear_actions() # Timeout newTimeout = int(self.cfgWin.getWidget('spn-duration').get_value()) oldTimeout = prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT) prefs.set(__name__, 'timeout', newTimeout) if oldTimeout != newTimeout and self.notif is not None: self.notif.set_timeout(newTimeout * 1000) # Other preferences prefs.set(__name__, 'title', self.cfgWin.getWidget('txt-title').get_text()) (start, end) = self.cfgWin.getWidget('txt-body').get_buffer().get_bounds() prefs.set(__name__, 'body', self.cfgWin.getWidget('txt-body').get_buffer().get_text(start, end)) self.cfgWin.hide()
def __loadAuthInfo(id): """ Load the login/password associated with id, either from the Gnome keyring or from the prefs """ try: import gnomekeyring as gk useGK = True except: useGK = False # No Gnome keyring if not useGK: login = prefs.get(__name__, id + '_login', None) passwd = prefs.get(__name__, id + '_passwd', None) if login is not None and passwd is not None: return (login, b64decode(passwd)) else: return None # From here we can use the Gnome keyring __loadKeyring() try: gk.create_sync(__keyring, None) except gk.AlreadyExistsError: pass token = prefs.get(__name__, id + '_gkToken', None) if token is not None: try: login, passwd = gk.item_get_info_sync(__keyring, token).get_secret().split('\n') return (login, passwd) except: pass return None
def configure(self, parent): """ Show the configuration window """ if self.cfgWin is None: self.cfgWin = gui.window.Window("AudioCD.ui", "vbox1", __name__, MOD_L10N, 335, 270) self.cfgWin.getWidget("btn-ok").connect("clicked", self.onBtnOk) self.cfgWin.getWidget("btn-help").connect("clicked", self.onBtnHelp) self.cfgWin.getWidget("chk-useCDDB").connect("toggled", self.onUseCDDBToggled) self.cfgWin.getWidget("btn-clearCache").connect("clicked", self.onBtnClearCache) self.cfgWin.getWidget("btn-cancel").connect("clicked", lambda btn: self.cfgWin.hide()) # Set up the combo box combo = self.cfgWin.getWidget("combo-read-speed") txtRenderer = gtk.CellRendererText() combo.pack_start(txtRenderer, True) combo.add_attribute(txtRenderer, "text", 0) combo.set_sensitive(True) txtRenderer.set_property("xpad", 6) # Setup the liststore store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT) combo.set_model(store) for speed in sorted(READ_SPEEDS.iterkeys()): store.append(("%ux" % speed, speed)) if not self.cfgWin.isVisible(): self.cfgWin.getWidget("btn-ok").grab_focus() self.cfgWin.getWidget("txt-device").set_text(prefs.get(__name__, "device", PREFS_DFT_DEVICE)) self.cfgWin.getWidget("chk-useCDDB").set_active(prefs.get(__name__, "use-cddb", PREFS_DFT_USE_CDDB)) self.cfgWin.getWidget("chk-useCache").set_sensitive(prefs.get(__name__, "use-cddb", PREFS_DFT_USE_CDDB)) self.cfgWin.getWidget("chk-useCache").set_active(prefs.get(__name__, "use-cache", PREFS_DFT_USE_CACHE)) self.cfgWin.getWidget("combo-read-speed").set_active( READ_SPEEDS[prefs.get(__name__, "read-speed", PREFS_DFT_READ_SPEED)] ) self.cfgWin.show()
def showNotification(self): """ Show the notification based on the current track """ self.timeout = None # Can this happen? if self.currTrack is None: return False # Contents body = self.currTrack.formatHTMLSafe(prefs.get(__name__, 'body', PREFS_DEFAULT_BODY)) title = self.currTrack.format(prefs.get(__name__, 'title', PREFS_DEFAULT_TITLE)) # Icon if self.currCover is None: img = os.path.join(consts.dirPix, 'decibel-audio-player-64.png') else: img = self.currCover if os.path.isfile(img): icon = 'file://' + img else: icon = gtk.STOCK_DIALOG_INFO # Create / Update the notification and show it if self.notif is None: self.__createNotification(title, body, icon) else: self.notif.update(title, body, icon) self.notif.show() return False
def showNotification(self): """ Show the notification based on the current track """ self.timeout = None # Can this happen? if self.currTrack is None: return False # Contents body = self.currTrack.formatHTMLSafe(prefs.get(__name__, 'body', PREFS_DEFAULT_BODY)) title = self.currTrack.format(prefs.get(__name__, 'title', PREFS_DEFAULT_TITLE)) # Icon if self.currCover is None: img = consts.fileImgIcon64 else: img = self.currCover if os.path.isfile(img): icon = 'file://' + img else: icon = gtk.STOCK_DIALOG_INFO # Create / Update the notification and show it if self.notif is None: self.__createNotification(title, body, icon) else: self.notif.update(title, body, icon) ## Catch errors that occur when pynotify is not installed properly try: self.notif.show() except gobject.GError: pass return False
def onBtnOk(self, btn): """ Save new preferences """ # Skipping tracks newSkipTrack = self.cfgWin.getWidget('chk-skipTrack').get_active() oldSkipTrack = prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK) prefs.set(__name__, 'skip-track', newSkipTrack) if oldSkipTrack != newSkipTrack and self.notif is not None: if newSkipTrack: self.notif.add_action('stop', _('Skip track'), self.onSkipTrack) else: self.notif.clear_actions() # Timeout newTimeout = int(self.cfgWin.getWidget('spn-duration').get_value()) oldTimeout = prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT) prefs.set(__name__, 'timeout', newTimeout) if oldTimeout != newTimeout and self.notif is not None: self.notif.set_timeout(newTimeout * 1000) # Other preferences prefs.set(__name__, 'title', self.cfgWin.getWidget('txt-title').get_text()) (start, end) = self.cfgWin.getWidget('txt-body').get_buffer().get_bounds() prefs.set( __name__, 'body', self.cfgWin.getWidget('txt-body').get_buffer().get_text( start, end, False)) self.cfgWin.hide()
def modInit(self): """ Initialize the module """ self.lvls = prefs.get(__name__, 'levels', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.preset = prefs.get(__name__, 'preset', _('Flat')) self.cfgWindow = None modules.addMenuItem(_('Equalizer'), self.configure, '<Control>E')
def onModLoaded(self): """ The module has been loaded """ self.startTime = 0 self.paused = prefs.get(__name__, 'was-paused', False) self.playing = prefs.get(__name__, 'was-playing', False) self.currPos = prefs.get(__name__, 'position', 0) self.currTrack = prefs.get(__name__, 'track', None) self.currTracklist = prefs.get(__name__, 'tracklist', [])
def updateFile(self, track): """ Show the notification based on the given track """ output = open(prefs.get(__name__, "file", PREFS_DEFAULT_FILE), "w") if track is None: output.write("") else: output.write(track.format(prefs.get(__name__, "status", PREFS_DEFAULT_STATUS))) output.close()
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 onAppStarted(self): """ This is the real initialization function, called when the module has been loaded """ self.tree = None self.currLib = None self.cfgWindow = None self.libraries = prefs.get(__name__, 'libraries', PREFS_DEFAULT_LIBRARIES) self.treeState = prefs.get(__name__, 'tree-state', PREFS_DEFAULT_TREE_STATE) # Scroll window self.scrolled = gtk.ScrolledWindow() self.scrolled.set_shadow_type(gtk.SHADOW_IN) self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.scrolled.show()
def onNewTrack(self, track): """ A new track is being played, try to retrieve the corresponding cover """ # Make sure we have enough information if track.getArtist() == consts.UNKNOWN_ARTIST or track.getAlbum() == consts.UNKNOWN_ALBUM: modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': None, 'pathFullSize': None}) return album = track.getAlbum().lower() artist = track.getArtist().lower() coverKey = artist + album rawCover = None self.currTrack = track # Let's see whether we already have the cover if coverKey in self.coverMap: covers = self.coverMap[coverKey] pathFullSize = covers[CVR_FULL] pathThumbnail = covers[CVR_THUMB] # Make sure the files are still there if os.path.exists(pathThumbnail) and os.path.exists(pathFullSize): modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': pathThumbnail, 'pathFullSize': pathFullSize}) return # Should we check for a user cover? if not prefs.get(__name__, 'download-covers', PREFS_DFT_DOWNLOAD_COVERS) \ or prefs.get(__name__, 'prefer-user-covers', PREFS_DFT_PREFER_USER_COVERS): rawCover = self.getUserCover(os.path.dirname(track.getFilePath())) # Is it in our cache? if rawCover is None: rawCover = self.getFromCache(artist, album) # If we still don't have a cover, maybe we can try to download it if rawCover is None: modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': None, 'pathFullSize': None}) if prefs.get(__name__, 'download-covers', PREFS_DFT_DOWNLOAD_COVERS): rawCover = self.getFromInternet(artist, album) # If we still don't have a cover, too bad # Otherwise, generate a thumbnail and a full size cover, and add it to our cover map if rawCover is not None: thumbnail = tempfile.mktemp() + '.png' fullSizeCover = tempfile.mktemp() + '.png' self.generateThumbnail(rawCover, thumbnail, 'PNG') self.generateFullSizeCover(rawCover, fullSizeCover, 'PNG') if os.path.exists(thumbnail) and os.path.exists(fullSizeCover): self.coverMap[coverKey] = (thumbnail, fullSizeCover) modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': thumbnail, 'pathFullSize': fullSizeCover}) else: modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': None, 'pathFullSize': None})
def __init__(self, wtree, window): """ Constructor """ self.wtree = wtree self.paned = wtree.get_object('pan-main') self.window = window # Enable the right radio menu button viewmode = prefs.get(__name__, 'view-mode', DEFAULT_VIEW_MODE) if viewmode == consts.VIEW_MODE_FULL: self.wtree.get_object('menu-mode-full').set_active(True) elif viewmode == consts.VIEW_MODE_LEAN: self.wtree.get_object('menu-mode-lean').set_active(True) elif viewmode == consts.VIEW_MODE_MINI: self.wtree.get_object('menu-mode-mini').set_active(True) elif viewmode == consts.VIEW_MODE_NETBOOK: self.wtree.get_object('menu-mode-netbook').set_active(True) elif viewmode == consts.VIEW_MODE_PLAYLIST: self.wtree.get_object('menu-mode-playlist').set_active(True) # Restore the size and the state of the window if prefs.get(__name__, 'win-is-maximized', DEFAULT_MAXIMIZED_STATE): self.window.maximize() savedWidth = prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH) savedHeight = prefs.get(__name__, 'win-height', DEFAULT_WIN_HEIGHT) savedPanPos = prefs.get(__name__, 'paned-pos', DEFAULT_PANED_POS) self.window.resize(savedWidth, savedHeight) self.paned.set_position(savedPanPos) self.window.show_all() # Restore the view mode # We set the mode to VIEW_MODE_FULL in the preferences because the window is currently in this mode (initial startup state) prefs.set(__name__, 'view-mode', consts.VIEW_MODE_FULL) self.setViewMode(viewmode) # Restore once again the size (may have been modified while restoring the view mode) self.window.resize(savedWidth, savedHeight) self.paned.set_position(savedPanPos) # Finally connect the event handlers self.window.connect('delete-event', self.onDelete) self.window.connect('size-allocate', self.onResize) self.window.connect('window-state-event', self.onState) self.wtree.get_object('menu-mode-mini').connect('activate', self.onViewMode, consts.VIEW_MODE_MINI) self.wtree.get_object('menu-mode-full').connect('activate', self.onViewMode, consts.VIEW_MODE_FULL) self.wtree.get_object('menu-mode-lean').connect('activate', self.onViewMode, consts.VIEW_MODE_LEAN) self.wtree.get_object('menu-mode-netbook').connect('activate', self.onViewMode, consts.VIEW_MODE_NETBOOK) self.wtree.get_object('menu-mode-playlist').connect('activate', self.onViewMode, consts.VIEW_MODE_PLAYLIST) self.wtree.get_object('menu-help').connect('activate', self.onHelp) self.wtree.get_object('menu-about').connect('activate', self.onAbout) self.wtree.get_object('menu-preferences').connect('activate', self.onShowPreferences) self.wtree.get_object('menu-quit').connect('activate', lambda item: self.onDelete(window, None)) self.wtree.get_object('pan-main').connect('size-allocate', lambda win, rect: prefs.set(__name__, 'paned-pos', self.paned.get_position()))
def __createNotification(self, title, body, icon): """ Create the Notification object """ import pynotify if not pynotify.init(consts.appNameShort): logger.error('[%s] Initialization of pynotify failed' % MOD_INFO[modules.MODINFO_NAME]) self.notif = pynotify.Notification(title, body, icon) self.notif.set_urgency(pynotify.URGENCY_LOW) self.notif.set_timeout(prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT) * 1000) if prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK): self.notif.add_action('stop', _('Skip track'), self.onSkipTrack)
def __createNotification(self, title, body, icon): """ Create the Notification object """ if not Notify.init(consts.appNameShort): logger.error('[%s] Initialization of python-notify failed' % MOD_INFO[modules.MODINFO_NAME]) self.notif = Notify.Notification.new(title, body, icon) self.notif.set_urgency(Notify.Urgency.LOW) self.notif.set_timeout( prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT) * 1000) if prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK): self.notif.add_action('stop', _('Skip track'), self.onSkipTrack)
def configure(self, parent): """ Show the configuration window """ if self.cfgWindow is None: from gui.window import Window self.cfgWindow = Window('IMStatus.ui', 'vbox1', __name__, _(MOD_NAME), 440, 290) # GTK handlers self.cfgWindow.getWidget('rad-stopDoNothing').connect('toggled', self.onRadToggled) self.cfgWindow.getWidget('rad-stopSetStatus').connect('toggled', self.onRadToggled) self.cfgWindow.getWidget('btn-ok').connect('clicked', self.onBtnOk) self.cfgWindow.getWidget('btn-cancel').connect('clicked', lambda btn: self.cfgWindow.hide()) self.cfgWindow.getWidget('btn-help').connect('clicked', self.onBtnHelp) if not self.cfgWindow.isVisible(): self.cfgWindow.getWidget('txt-status').set_text(prefs.get(__name__, 'status-msg', DEFAULT_STATUS_MSG)) self.cfgWindow.getWidget('chk-updateOnPaused').set_active(prefs.get(__name__, 'update-on-paused', DEFAULT_UPDATE_ON_PAUSED)) self.cfgWindow.getWidget('chk-updateWhenAway').set_active(prefs.get(__name__, 'update-when-away', DEFAULT_UPDATE_WHEN_AWAY)) self.cfgWindow.getWidget('rad-stopDoNothing').set_active(prefs.get(__name__, 'stop-action', DEFAULT_STOP_ACTION) == STOP_DO_NOTHING) self.cfgWindow.getWidget('rad-stopSetStatus').set_active(prefs.get(__name__, 'stop-action', DEFAULT_STOP_ACTION) == STOP_SET_STATUS) self.cfgWindow.getWidget('txt-stopStatus').set_sensitive(prefs.get(__name__, 'stop-action', DEFAULT_STOP_ACTION) == STOP_SET_STATUS) self.cfgWindow.getWidget('txt-stopStatus').set_text(prefs.get(__name__, 'stop-status', DEFAULT_STOP_STATUS)) self.cfgWindow.getWidget('txt-sanitizedWords').get_buffer().set_text(prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS)) self.cfgWindow.getWidget('btn-ok').grab_focus() self.cfgWindow.show()
def __format(self, string, track): """ Replace the special fields in the given string by their corresponding value and sanitize the result """ result = track.format(string) if len(prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS)) != 0: lowerResult = result.lower() for word in [w.lower() for w in prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS).split('\n') if len(w) > 2]: pos = lowerResult.find(word) while pos != -1: result = result[:pos+1] + ('*' * (len(word)-2)) + result[pos+len(word)-1:] lowerResult = lowerResult[:pos+1] + ('*' * (len(word)-2)) + lowerResult[pos+len(word)-1:] pos = lowerResult.find(word) return result
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 onAppStarted(self): """ Real initialization function, called when this module has been loaded """ # Widgets self.currTrack = None show_thumb = prefs.get(__name__, 'show_thumb', True) self.cover_spot = CoverSpot(show_thumb)
def onAppStarted(self): """ Real initialization function, called when this module has been loaded """ self.currTrackLength = 0 self.sclBeingDragged = False # Widgets wTree = prefs.getWidgetsTree() # self.btnStop = wTree.get_widget('btn-stop') self.btnPlay = wTree.get_widget('btn-play') # self.btnNext = wTree.get_widget('btn-next') self.btnPrev = wTree.get_widget('btn-previous') self.sclSeek = wTree.get_widget('scl-position') self.btnVolume = wTree.get_widget('btn-volume') self.lblElapsed = wTree.get_widget('lbl-elapsedTime') self.lblRemaining = wTree.get_widget('lbl-remainingTime') # Initial state self.onStopped() self.btnPlay.set_sensitive(False) # GTK handlers # self.btnStop.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_STOP)) # self.btnNext.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_NEXT)) self.btnPrev.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_PREVIOUS)) self.btnPlay.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)) self.sclSeek.connect('change-value', self.onSeekChangeValue) # We need to keep the handler ID for this one to be able to disconnect it when needed self.seekHandler = self.sclSeek.connect('value-changed', self.onSeekValueChanged) self.volumeHandler = self.btnVolume.connect('value-changed', self.onVolumeValueChanged) # We must make sure that the handler will be called: this is not the case if the new value is the same as the old one volumeValue = prefs.get(__name__, 'volume', PREFS_DEFAULT_VOLUME) if self.btnVolume.get_value() != volumeValue: self.btnVolume.set_value(volumeValue) else: self.onVolumeValueChanged(self.btnVolume, volumeValue)
def onAppStarted(self): """ Real initialization function, called when this module has been loaded """ self.currTrackLength = 0 self.sclBeingDragged = False # Widgets wTree = prefs.getWidgetsTree() self.btnStop = wTree.get_object('btn-stop') self.btnPlay = wTree.get_object('btn-play') self.btnNext = wTree.get_object('btn-next') self.btnPrev = wTree.get_object('btn-previous') self.sclSeek = wTree.get_object('scl-position') self.btnVolume = wTree.get_object('btn-volume') self.lblElapsed = wTree.get_object('lbl-elapsedTime') self.lblRemaining = wTree.get_object('lbl-remainingTime') # Don't show the volume button when using playbin2 and pulseaudio together (#511589) if not tools.isPulseAudioRunning() or prefs.getCmdLine()[0].playbin or prefs.getCmdLine()[0].volume_button: self.btnVolume.show() # Restore the volume volume = prefs.get(__name__, 'volume', PREFS_DEFAULT_VOLUME) self.btnVolume.set_value(volume) modules.postMsg(consts.MSG_CMD_SET_VOLUME, {'value': volume}) # GTK handlers self.btnStop.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_STOP)) self.btnNext.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_NEXT)) self.btnPrev.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_PREVIOUS)) self.btnPlay.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)) self.sclSeek.connect('change-value', self.onSeekChangingValue) self.sclSeek.connect('value-changed', self.onSeekValueChanged) self.btnVolume.connect('value-changed', self.onVolumeValueChanged) self.sclSeek.connect('button-press-event', self.onSeekButtonPressed) self.sclSeek.connect('button-release-event', self.onSeekButtonReleased)
def __fillComboBox(self): """ Fill the combo box """ idx = self.combo.get_active() restoredIdx = None self.timeout = None previousModule = None if idx == -1: selectedModule, selectedExplorer = prefs.get(__name__, 'last-explorer', DEFAULT_LAST_EXPLORER) else: selectedModule, selectedExplorer = self.store[idx][ROW_MODULE], self.store[idx][ROW_NAME] self.combo.freeze_child_notify() self.store.clear() for (module, explorer), (pixbuf, widget) in sorted(self.allExplorers.iteritems()): if module != previousModule: self.store.append((None, '<b>%s</b>' % module, '', -1, True)) previousModule = module self.store.append((pixbuf, explorer, module, self.notebookPages[widget], False)) if module == selectedModule and explorer == selectedExplorer: restoredIdx = len(self.store) - 1 if restoredIdx is None: self.currExplorerIdx = 0 self.notebook.set_current_page(0) else: self.combo.set_active(restoredIdx) self.combo.set_sensitive(len(self.store) != 0) self.combo.thaw_child_notify() return False
def onModLoaded(self): """ The module has been loaded """ self.tree = None self.cfgWin = None self.folders = prefs.get(__name__, 'media-folders', PREFS_DEFAULT_MEDIA_FOLDERS) self.scrolled = gtk.ScrolledWindow() self.currRoot = None self.addByFilename = prefs.get(__name__, 'add-by-filename', PREFS_DEFAULT_ADD_BY_FILENAME) self.showHiddenFiles = prefs.get(__name__, 'show-hidden-files', PREFS_DEFAULT_SHOW_HIDDEN_FILES) self.scrolled.set_shadow_type(gtk.SHADOW_IN) self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.scrolled.show() for name in self.folders: modules.postMsg(consts.MSG_CMD_EXPLORER_ADD, {'modName': MOD_L10N, 'expName': name, 'icon': None, 'widget': self.scrolled})
def delayedStartup(): """ Perform all the initialization stuff that is not mandatory to display the window This function should be called within the GTK main loop, once the window has been displayed """ import atexit, dbus.mainloop.glib, modules, signal def atExit(): """ Final function, called just before exiting the Python interpreter """ prefs.save() log.logger.info('Stopped') def onInterrupt(window): """ Handler for interrupt signals e.g., Ctrl-C """ window.hide() modules.postQuitMsg() # D-Bus dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) # Register a few handlers atexit.register(atExit) signal.signal(signal.SIGINT, lambda sig, frame: onInterrupt(window)) signal.signal(signal.SIGTERM, lambda sig, frame: onInterrupt(window)) # Now we can start all modules gobject.idle_add(modules.postMsg, consts.MSG_EVT_APP_STARTED) # Immediately show the preferences the first time the application is started if prefs.get(__name__, 'first-time', True): prefs.set(__name__, 'first-time', False) gobject.idle_add(modules.showPreferences)
def setViewMode(self, mode): """ Change the view mode to the given one """ currMode = prefs.get(__name__, 'view-mode', DEFAULT_VIEW_MODE) # Give up if the new mode is the same as the current one if currMode == mode: return requestedSize = self.window.get_size() # First restore the initial window state (e.g., VIEW_MODE_FULL) if currMode == consts.VIEW_MODE_LEAN: requestedSize = self.__fromModeLean(requestedSize) elif currMode == consts.VIEW_MODE_MINI: requestedSize = self.__fromModeMini(requestedSize) elif currMode == consts.VIEW_MODE_NETBOOK: requestedSize = self.__fromModeNetbook(requestedSize) elif currMode == consts.VIEW_MODE_PLAYLIST: requestedSize = self.__fromModePlaylist(requestedSize) # Now we can switch to the new mode if mode == consts.VIEW_MODE_LEAN: requestedSize = self.__toModeLean(requestedSize) elif mode == consts.VIEW_MODE_MINI: requestedSize = self.__toModeMini(requestedSize) elif mode == consts.VIEW_MODE_NETBOOK: requestedSize = self.__toModeNetbook(requestedSize) elif mode == consts.VIEW_MODE_PLAYLIST: requestedSize = self.__toModePlaylist(requestedSize) # Do only one resize(), because intermediate get_size() don't return the correct size until the event queue has been processed by GTK self.window.resize(requestedSize[0], requestedSize[1]) # Save the new mode prefs.set(__name__, 'view-mode', mode)
def setStatusMsg(self, account, msg): """ Change the status message of the given account """ try: currentStatus = self.dbusInterface.get_status(account) if currentStatus in ('online', 'chat') or prefs.get(__name__, 'update-when-away', DEFAULT_UPDATE_WHEN_AWAY): self.dbusInterface.change_status(currentStatus, msg, account) except: logger.error('[%s] Unable to set Gajim status\n\n%s' % (MOD_NAME, traceback.format_exc()))
def onResize(win, rect): """ Save the new size of the window """ if win.window is not None and not win.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED: prefs.set(__name__, 'win-width', rect.width) prefs.set(__name__, 'win-height', rect.height) if prefs.get(__name__, 'view-mode', DEFAULT_VIEW_MODE)in (consts.VIEW_MODE_FULL, consts.VIEW_MODE_PLAYLIST): prefs.set(__name__, 'full-win-height', rect.height)
def setStatusMsg(self, account, msg): """ Change the status message of the given account """ try: currentStatus, currentMsg = self.dbusInterface.GetPresence('') if currentStatus == 'available' or prefs.get(__name__, 'update-when-away', DEFAULT_UPDATE_WHEN_AWAY): self.dbusInterface.SetPresence(currentStatus, msg) except: logger.error('[%s] Unable to set Gossip status\n\n%s' % (MOD_NAME, traceback.format_exc()))
def onModLoaded(self): """ This is the real initialization function, called when the module has been loaded """ self.tree = None self.currLib = None self.allGenres = {} self.currGenre = None self.cfgWindow = None self.libraries = prefs.get(__name__, 'libraries', PREFS_DEFAULT_LIBRARIES) self.favorites = None self.treeStates = prefs.get(__name__, 'tree-states-2', PREFS_DEFAULT_TREE_STATE) self.showOnlyFavs = prefs.get(__name__, 'show-only-favorites', PREFS_DEFAULT_SHOW_ONLY_FAVORITES) # Scroll window self.scrolled = gtk.ScrolledWindow() self.scrolled.set_shadow_type(gtk.SHADOW_IN) self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.scrolled.show() idle_add(self.addAllExplorers)
def configure(self, parent): """ Show the configuration window """ if self.cfgWin is None: self.cfgWin = gui.window.Window('AudioCD.glade', 'vbox1', __name__, MOD_L10N, 335, 270) self.cfgWin.getWidget('btn-ok').connect('clicked', self.onBtnOk) self.cfgWin.getWidget('btn-help').connect('clicked', self.onBtnHelp) self.cfgWin.getWidget('chk-useCDDB').connect('toggled', self.onUseCDDBToggled) self.cfgWin.getWidget('btn-clearCache').connect('clicked', self.onBtnClearCache) self.cfgWin.getWidget('btn-cancel').connect('clicked', lambda btn: self.cfgWin.hide()) if not self.cfgWin.isVisible(): self.cfgWin.getWidget('btn-ok').grab_focus() self.cfgWin.getWidget('txt-device').set_text(prefs.get(__name__, 'device', PREFS_DFT_DEVICE)) self.cfgWin.getWidget('chk-useCDDB').set_active(prefs.get(__name__, 'use-cddb', PREFS_DFT_USE_CDDB)) self.cfgWin.getWidget('chk-useCache').set_sensitive(prefs.get(__name__, 'use-cddb', PREFS_DFT_USE_CDDB)) self.cfgWin.getWidget('chk-useCache').set_active(prefs.get(__name__, 'use-cache', PREFS_DFT_USE_CACHE)) self.cfgWin.show()
def handleMsg(self, msg, params): """ Handle messages sent to this module """ if msg == consts.MSG_EVT_EXPLORER_CHANGED and params['modName'] == MOD_L10N and self.currRoot != params['expName']: newRoot = params['expName'] # Create the tree if needed (this is done only the very first time) if self.tree is None: columns = (('', [(gtk.CellRendererPixbuf(), gtk.gdk.Pixbuf), (gtk.CellRendererText(), TYPE_STRING)], True), (None, [(None, TYPE_INT)], False), (None, [(None, TYPE_STRING)], False)) self.tree = extTreeview.ExtTreeView(columns, True) self.scrolled.add(self.tree) self.tree.setDNDSources([consts.DND_TARGETS[consts.DND_DAP_URI]]) self.tree.connect('drag-data-get', self.onDragDataGet) self.tree.connect('key-press-event', self.onKeyPressed) self.tree.connect('exttreeview-button-pressed', self.onMouseButton) self.tree.connect('exttreeview-row-collapsed', self.onRowCollapsed) self.expandedHandler = self.tree.connect('exttreeview-row-expanded', self.onRowExpanded) savedStates = prefs.get(__name__, 'saved-states', {}) # Save the current state if needed if self.currRoot is not None: savedStates[self.currRoot] = { 'tree-state': self.dumpTree(), 'selected-paths': self.tree.getSelectedPaths(), 'vscrollbar-pos': self.scrolled.get_vscrollbar().get_value(), 'hscrollbar-pos': self.scrolled.get_hscrollbar().get_value(), } prefs.set(__name__, 'saved-states', savedStates) self.tree.clear() self.currRoot = newRoot if newRoot not in savedStates: self.exploreDir(None, self.folders[self.currRoot]) if len(self.tree) != 0: self.tree.scroll_to_cell(0) else: savedState = savedStates[newRoot] self.tree.disconnect(self.expandedHandler) self.restoreTree(savedState['tree-state']) self.expandedHandler = self.tree.connect('exttreeview-row-expanded', self.onRowExpanded) idle_add(self.scrolled.get_vscrollbar().set_value, savedState['vscrollbar-pos']) idle_add(self.scrolled.get_hscrollbar().set_value, savedState['hscrollbar-pos']) idle_add(self.tree.selectPaths, savedState['selected-paths']) idle_add(self.refresh) elif msg == consts.MSG_EVT_APP_STARTED: self.onModLoaded() elif msg == consts.MSG_EVT_APP_QUIT: self.onModUnloaded()
def __fromModeMini(self, requestedSize): """ Switch from mini mode to full mode """ self.paned.get_child1().show() self.wtree.get_object('statusbar').show() self.wtree.get_object('box-btn-tracklist').show() self.wtree.get_object('scrolled-tracklist').show() (winWidth, winHeight) = requestedSize return (winWidth + self.paned.get_position(), prefs.get(__name__, 'full-win-height', 470))
def onResize(win, rect): """ Save the new size of the window """ maximized = win.get_state() & Gdk.WindowState.MAXIMIZED if not maximized: prefs.set(__name__, 'win-width', rect.width) prefs.set(__name__, 'win-height', rect.height) view_mode = prefs.get(__name__, 'view-mode', DEFAULT_VIEW_MODE) if view_mode in (consts.VIEW_MODE_FULL, consts.VIEW_MODE_PLAYLIST): prefs.set(__name__, 'full-win-height', rect.height)
def setViewMode(mode, resize): """ Change the view mode to the given one """ lastMode = prefs.get(__name__, 'view-mode', DEFAULT_VIEW_MODE) prefs.set(__name__, 'view-mode', mode) (winWidth, winHeight) = window.get_size() if mode == consts.VIEW_MODE_FULL: paned.get_child1().show() wTree.get_widget('statusbar').show() wTree.get_widget('box-btn-tracklist').show() wTree.get_widget('scrolled-tracklist').show() wTree.get_widget('box-trkinfo').show() if resize: if lastMode != consts.VIEW_MODE_FULL: winWidth = winWidth + paned.get_position() if lastMode == consts.VIEW_MODE_MINI: winHeight = prefs.get(__name__, 'full-win-height', DEFAULT_WIN_HEIGHT) window.resize(winWidth, winHeight) return paned.get_child1().hide() if resize and lastMode == consts.VIEW_MODE_FULL: winWidth = winWidth - paned.get_position() window.resize(winWidth, winHeight) if mode == consts.VIEW_MODE_PLAYLIST: wTree.get_widget('statusbar').show() wTree.get_widget('box-btn-tracklist').hide() wTree.get_widget('scrolled-tracklist').show() wTree.get_widget('box-trkinfo').show() if resize and lastMode == consts.VIEW_MODE_MINI: window.resize(winWidth, prefs.get(__name__, 'full-win-height', DEFAULT_WIN_HEIGHT)) return wTree.get_widget('statusbar').hide() wTree.get_widget('box-btn-tracklist').hide() wTree.get_widget('scrolled-tracklist').hide() if mode == consts.VIEW_MODE_MINI: wTree.get_widget('box-trkinfo').show() else: wTree.get_widget('box-trkinfo').hide() if resize: window.resize(winWidth, 1)
def configure(self, parent): """ Show the configuration window """ if self.cfgWin is None: from gui.window import Window self.cfgWin = Window('Covers.ui', 'vbox1', __name__, MOD_INFO[modules.MODINFO_L10N], 320, 265) self.cfgWin.getWidget('btn-ok').connect('clicked', self.onBtnOk) self.cfgWin.getWidget('img-lastfm').set_from_file( os.path.join(consts.dirPix, 'audioscrobbler.png')) self.cfgWin.getWidget('btn-help').connect('clicked', self.onBtnHelp) self.cfgWin.getWidget('chk-downloadCovers').connect( 'toggled', self.onDownloadCoversToggled) self.cfgWin.getWidget('btn-cancel').connect( 'clicked', lambda btn: self.cfgWin.hide()) if not self.cfgWin.isVisible(): downloadCovers = prefs.get(__name__, 'download-covers', PREFS_DFT_DOWNLOAD_COVERS) preferUserCovers = prefs.get(__name__, 'prefer-user-covers', PREFS_DFT_PREFER_USER_COVERS) userCoverFilenames = prefs.get(__name__, 'user-cover-filenames', PREFS_DFT_USER_COVER_FILENAMES) self.cfgWin.getWidget('btn-ok').grab_focus() self.cfgWin.getWidget('txt-filenames').set_text( ', '.join(userCoverFilenames)) self.cfgWin.getWidget('chk-downloadCovers').set_active( downloadCovers) self.cfgWin.getWidget('chk-preferUserCovers').set_active( preferUserCovers) self.cfgWin.getWidget('chk-preferUserCovers').set_sensitive( downloadCovers) self.cfgWin.show()
def getUserCover(self, trackPath): """ Return the path to a cover file in trackPath, None if no cover found """ # Create a dictionary with candidates candidates = {} for (file, path) in tools.listDir(trackPath, True): (name, ext) = os.path.splitext(file.lower()) if ext in ACCEPTED_FILE_FORMATS: candidates[name] = path # Check each possible name using the its index in the list as its priority for name in prefs.get(__name__, 'user-cover-filenames', PREFS_DFT_USER_COVER_FILENAMES): if name in candidates: return candidates[name] if name == '*' and len(candidates) != 0: return next(iter(candidates.values())) return None
def select_last_played_track(self): last_path = prefs.get(__name__, 'last-played-track', None) if last_path: parent_path = (last_path[0],) GObject.idle_add(self.tree.scroll_to_cell, parent_path) self.tree.get_selection().select_path(parent_path)
def realStartup(window, paned): """ Perform all the initialization stuff which is not mandatory to display the window. This function should be called within the GTK main loop, once the window has been displayed """ # Is the application started for the first time? first_start = prefs.get(__name__, 'first-time', True) logging.debug('First start: {}'.format(first_start)) if first_start: prefs.set(__name__, 'first-time', False) # Enable some modules by default prefs.set('modules', 'enabled_modules', ['Covers', 'Desktop Notification']) import atexit import signal import dbus.mainloop.glib import modules modules.load_enabled_modules() def onDelete(win, event): """ Use our own quit sequence, that will itself destroy the window """ win.hide() modules.postQuitMsg() return True def onResize(win, rect): """ Save the new size of the window """ maximized = win.get_state() & Gdk.WindowState.MAXIMIZED if not maximized: prefs.set(__name__, 'win-width', rect.width) prefs.set(__name__, 'win-height', rect.height) view_mode = prefs.get(__name__, 'view-mode', DEFAULT_VIEW_MODE) if view_mode in (consts.VIEW_MODE_FULL, consts.VIEW_MODE_PLAYLIST): prefs.set(__name__, 'full-win-height', rect.height) def onPanedResize(win, rect): prefs.set(__name__, 'paned-pos', paned.get_position()) def onState(win, event): """ Save the new state of the window """ if event.changed_mask & Gdk.WindowState.MAXIMIZED: maximized = bool(event.new_window_state & Gdk.WindowState.MAXIMIZED) prefs.set(__name__, 'win-is-maximized', maximized) def atExit(): """ Final function, called just before exiting the Python interpreter """ prefs.save() log.logger.info('Stopped') # D-Bus dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) # Register some handlers (Signal SIGKILL cannot be caught) atexit.register(atExit) signal.signal(signal.SIGINT, lambda sig, frame: onDelete(window, None)) signal.signal(signal.SIGTERM, lambda sig, frame: onDelete(window, None)) # GTK handlers window.connect('delete-event', onDelete) window.connect('size-allocate', onResize) window.connect('window-state-event', onState) paned.connect('size-allocate', onPanedResize) # Let's go GObject.idle_add(modules.postMsg, consts.MSG_EVT_APP_STARTED)
func(*args) else: self.handlers[msg](**params) # --== Entry point ==-- mModDir = os.path.dirname(__file__) # Where modules are located mModules = {} # All known modules associated to an 'active' boolean mHandlers = dict([(msg, set()) for msg in range(consts.MSG_END_VALUE) ]) # For each message, store the set of registered modules mModulesLock = threading.Lock( ) # Protects the modules list from concurrent access mHandlersLock = threading.Lock( ) # Protects the handlers list from concurrent access mEnabledModules = prefs.get(__name__, 'enabled_modules', []) # List of modules currently enabled # Do not load modules in blacklist. They also won't show up in the preferences. blacklist = ['__init__.py'] def load_enabled_modules(): # Find modules, instantiate those that are mandatory or that have been previously enabled by the user sys.path.append(mModDir) for file in sorted( os.path.splitext(file)[0] for file in os.listdir(mModDir) if file.endswith('.py') and file not in blacklist): try: pModule = __import__(file) modInfo = getattr(pModule, 'MOD_INFO')
def onNewTrack(self, track): """ A new track is being played, try to retrieve the corresponding cover """ # Make sure we have enough information if track.getArtist() == consts.UNKNOWN_ARTIST or track.getAlbum( ) == consts.UNKNOWN_ALBUM: modules.postMsg(consts.MSG_CMD_SET_COVER, { 'track': track, 'pathThumbnail': None, 'pathFullSize': None }) return album = track.getAlbum().lower() artist = track.getArtist().lower() rawCover = None self.currTrack = track # Let's see whether we already have the cover if (artist, album) in self.coverMap: covers = self.coverMap[(artist, album)] pathFullSize = covers[CVR_FULL] pathThumbnail = covers[CVR_THUMB] # Make sure the files are still there if os.path.exists(pathThumbnail) and os.path.exists(pathFullSize): modules.postMsg( consts.MSG_CMD_SET_COVER, { 'track': track, 'pathThumbnail': pathThumbnail, 'pathFullSize': pathFullSize }) return # Should we check for a user cover? if not prefs.get(__name__, 'download-covers', PREFS_DFT_DOWNLOAD_COVERS) \ or prefs.get(__name__, 'prefer-user-covers', PREFS_DFT_PREFER_USER_COVERS): rawCover = self.getUserCover(os.path.dirname(track.getFilePath())) # Is it in our cache? if rawCover is None: rawCover = self.getFromCache(artist, album) # If we still don't have a cover, maybe we can try to download it if rawCover is None: modules.postMsg(consts.MSG_CMD_SET_COVER, { 'track': track, 'pathThumbnail': None, 'pathFullSize': None }) if prefs.get(__name__, 'download-covers', PREFS_DFT_DOWNLOAD_COVERS): rawCover = self.getFromInternet(artist, album) # If we still don't have a cover, too bad # Otherwise, generate a thumbnail and a full size cover, and add it to our cover map if rawCover is not None: import tempfile thumbnail = tempfile.mktemp() + '.png' fullSizeCover = tempfile.mktemp() + '.png' self.generateThumbnail(rawCover, thumbnail, 'PNG') self.generateFullSizeCover(rawCover, fullSizeCover, 'PNG') if os.path.exists(thumbnail) and os.path.exists(fullSizeCover): self.coverMap[(artist, album)] = (thumbnail, fullSizeCover) modules.postMsg( consts.MSG_CMD_SET_COVER, { 'track': track, 'pathThumbnail': thumbnail, 'pathFullSize': fullSizeCover }) else: modules.postMsg(consts.MSG_CMD_SET_COVER, { 'track': track, 'pathThumbnail': None, 'pathFullSize': None })
def modInit(self): """ Initialize the module """ self.lvls = prefs.get(__name__, 'levels', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.preset = prefs.get(__name__, 'preset', 'Flat') self.cfgWindow = None