def __init__(self): QMainWindow.__init__(self) self.__updateDirs = True self.__dirsToUpdate = [] global add_shortcuts global remove_shortcuts add_shortcuts = self.addShortcuts remove_shortcuts = self.removeShortcuts plugins.add_shortcuts = add_shortcuts self.emits = ['loadFiles', 'always', 'dirsmoved', 'libfilesedited', 'enable_preview_mode', 'disable_preview_mode'] self.receives = [('writeselected', self.writeTags), ('filesloaded', self._filesLoaded), ('viewfilled', self._viewFilled), ('filesselected', self._filesSelected), ('renamedirs', self.renameDirs), ('filesloaded', self.updateTotalStats), ('filesselected', self.updateSelectedStats), ('onetomany', self.writeOneToMany), ('dirschanged', self._dirChanged), ('writepreview', self._writePreview), ('clearpreview', self._clearPreview), ('renameselected', self._renameSelected), ('playlistchanged', self._dirChanged), ('adddock', self.addDock), ('writeaction', self.writeAction), ('onetomanypreview', self.writeSinglePreview), ('manypreview', self.writeManyPreview)] self.gensettings = [('&Load last folder at startup', False, 1)] self._playlist = None plugin_dialogs, plugin_modules = load_plugins() self.setWindowTitle("puddletag") self.setDockNestingEnabled(True) self._table = TagTable() self.connect(self._table, SIGNAL('dirsmoved'), self.updateDirs) win = QSplitter() layout = QVBoxLayout() layout.addWidget(self._table) win.setLayout(layout) self.setCentralWidget(win) PuddleDock._controls = { 'table': self._table, 'mainwin': self, 'funcs': mainfuncs.obj,} status['mainwin'] = self status['model'] = self._table.model() status['table'] = self._table ls.create_files() winactions, self._docks = create_tool_windows(self) status['dialogs'] = PuddleDock._controls self.createStatusBar() actions = ls.get_actions(self) menus = ls.get_menus('menu') previewactions = mainwin.previews.create_actions(self) all_actions = actions + winactions + previewactions controls = PuddleDock._controls toolgroup = ls.get_menus('toolbar') toolbar = ls.toolbar(toolgroup, all_actions, controls) toolbar.setObjectName(translate("Menus", 'Toolbar')) self.addToolBar(toolbar) menubar, winmenu, self._menus = ls.menubar(menus, all_actions) temp_winactions = winmenu.actions() [winmenu.addAction(a) for a in winactions if a not in temp_winactions] if winmenu: winmenu.addSeparator() self._winmenu = winmenu else: self._winmenu = QMenu(translate("Settings", '&Windows'), self) menubar.addMenu(self._winmenu) self.setMenuBar(menubar) menubar.addMenu(help_menu(self)) mainfuncs.connect_status(actions) connect_actions(actions, controls) connect_action_shortcuts(all_actions) create_context_menus(controls, all_actions) status['actions'] = all_actions for m in plugin_modules: if hasattr(m, 'init'): try: m.init(parent=self) except: traceback.print_exc() continue for win in plugin_dialogs: try: self.addDock(*win, connect=False) except: print "Error while loading Plugin dialog." traceback.print_exc() self.restoreSettings() self.emit(SIGNAL('always'), True)
def __init__(self): QMainWindow.__init__(self) self.__updateDirs = True self.__dirsToUpdate = [] global add_shortcuts global remove_shortcuts add_shortcuts = self.addShortcuts remove_shortcuts = self.removeShortcuts plugins.add_shortcuts = add_shortcuts self.emits = [ 'loadFiles', 'always', 'dirsmoved', 'libfilesedited', 'enable_preview_mode', 'disable_preview_mode' ] self.receives = [('writeselected', self.writeTags), ('filesloaded', self._filesLoaded), ('viewfilled', self._viewFilled), ('filesselected', self._filesSelected), ('renamedirs', self.renameDirs), ('filesloaded', self.updateTotalStats), ('filesselected', self.updateSelectedStats), ('onetomany', self.writeOneToMany), ('dirschanged', self._dirChanged), ('writepreview', self._writePreview), ('clearpreview', self._clearPreview), ('renameselected', self._renameSelected), ('playlistchanged', self._dirChanged), ('adddock', self.addDock), ('writeaction', self.writeAction), ('onetomanypreview', self.writeSinglePreview), ('manypreview', self.writeManyPreview)] self.gensettings = [('&Load last folder at startup', False, 1)] self._playlist = None plugin_dialogs, plugin_modules = load_plugins() self.setWindowTitle("puddletag") self.setDockNestingEnabled(True) self._table = TagTable() self.connect(self._table, SIGNAL('dirsmoved'), self.updateDirs) win = QSplitter() layout = QVBoxLayout() layout.addWidget(self._table) win.setLayout(layout) self.setCentralWidget(win) PuddleDock._controls = { 'table': self._table, 'mainwin': self, 'funcs': mainfuncs.obj, } status['mainwin'] = self status['model'] = self._table.model() status['table'] = self._table ls.create_files() winactions, self._docks = create_tool_windows(self) status['dialogs'] = PuddleDock._controls self.createStatusBar() actions = ls.get_actions(self) menus = ls.get_menus('menu') previewactions = mainwin.previews.create_actions(self) all_actions = actions + winactions + previewactions controls = PuddleDock._controls toolgroup = ls.get_menus('toolbar') toolbar = ls.toolbar(toolgroup, all_actions, controls) toolbar.setObjectName(translate("Menus", 'Toolbar')) self.addToolBar(toolbar) menubar, winmenu, self._menus = ls.menubar(menus, all_actions) temp_winactions = winmenu.actions() [winmenu.addAction(a) for a in winactions if a not in temp_winactions] if winmenu: winmenu.addSeparator() self._winmenu = winmenu else: self._winmenu = QMenu(translate("Settings", '&Windows'), self) menubar.addMenu(self._winmenu) self.setMenuBar(menubar) menubar.addMenu(help_menu(self)) mainfuncs.connect_status(actions) connect_actions(actions, controls) connect_action_shortcuts(all_actions) create_context_menus(controls, all_actions) status['actions'] = all_actions for m in plugin_modules: if hasattr(m, 'init'): try: m.init(parent=self) except: traceback.print_exc() continue for win in plugin_dialogs: try: self.addDock(*win, connect=False) except: logging.exception("Error while loading Plugin dialog.") self.restoreSettings() self.emit(SIGNAL('always'), True)
class MainWin(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.__updateDirs = True self.__dirsToUpdate = [] global add_shortcuts global remove_shortcuts add_shortcuts = self.addShortcuts remove_shortcuts = self.removeShortcuts plugins.add_shortcuts = add_shortcuts self.emits = ['loadFiles', 'always', 'dirsmoved', 'libfilesedited', 'enable_preview_mode', 'disable_preview_mode'] self.receives = [('writeselected', self.writeTags), ('filesloaded', self._filesLoaded), ('viewfilled', self._viewFilled), ('filesselected', self._filesSelected), ('renamedirs', self.renameDirs), ('filesloaded', self.updateTotalStats), ('filesselected', self.updateSelectedStats), ('onetomany', self.writeOneToMany), ('dirschanged', self._dirChanged), ('writepreview', self._writePreview), ('clearpreview', self._clearPreview), ('renameselected', self._renameSelected), ('playlistchanged', self._dirChanged), ('adddock', self.addDock), ('writeaction', self.writeAction), ('onetomanypreview', self.writeSinglePreview), ('manypreview', self.writeManyPreview)] self.gensettings = [('&Load last folder at startup', False, 1)] self._playlist = None plugin_dialogs, plugin_modules = load_plugins() self.setWindowTitle("puddletag") self.setDockNestingEnabled(True) self._table = TagTable() self.connect(self._table, SIGNAL('dirsmoved'), self.updateDirs) win = QSplitter() layout = QVBoxLayout() layout.addWidget(self._table) win.setLayout(layout) self.setCentralWidget(win) PuddleDock._controls = { 'table': self._table, 'mainwin': self, 'funcs': mainfuncs.obj,} status['mainwin'] = self status['model'] = self._table.model() status['table'] = self._table ls.create_files() winactions, self._docks = create_tool_windows(self) status['dialogs'] = PuddleDock._controls self.createStatusBar() actions = ls.get_actions(self) menus = ls.get_menus('menu') previewactions = mainwin.previews.create_actions(self) all_actions = actions + winactions + previewactions controls = PuddleDock._controls toolgroup = ls.get_menus('toolbar') toolbar = ls.toolbar(toolgroup, all_actions, controls) toolbar.setObjectName(translate("Menus", 'Toolbar')) self.addToolBar(toolbar) menubar, winmenu, self._menus = ls.menubar(menus, all_actions) temp_winactions = winmenu.actions() [winmenu.addAction(a) for a in winactions if a not in temp_winactions] if winmenu: winmenu.addSeparator() self._winmenu = winmenu else: self._winmenu = QMenu(translate("Settings", '&Windows'), self) menubar.addMenu(self._winmenu) self.setMenuBar(menubar) menubar.addMenu(help_menu(self)) mainfuncs.connect_status(actions) connect_actions(actions, controls) connect_action_shortcuts(all_actions) create_context_menus(controls, all_actions) status['actions'] = all_actions for m in plugin_modules: if hasattr(m, 'init'): try: m.init(parent=self) except: traceback.print_exc() continue for win in plugin_dialogs: try: self.addDock(*win, connect=False) except: print "Error while loading Plugin dialog." traceback.print_exc() self.restoreSettings() self.emit(SIGNAL('always'), True) def addDock(self, name, dialog, position, visibility=True, connect=True): controls = PuddleDock._controls.values() dock = PuddleDock(name, dialog, self, status) self.addDockWidget(position, dock) self._winmenu.addAction(dock.toggleViewAction()) if connect: connect_control(PuddleDock._controls[name], controls) dock.setVisible(visibility) self.restoreDockWidget(dock) return PuddleDock._controls[name] def addShortcuts(self, menu_title, actions, toolbar=False, save=False): if not actions: return if menu_title in self._menus: menu = self._menus[menu_title][0] else: menu = QMenu(menu_title) self._menus[menu_title] = [menu] + actions self.menuBar().insertMenu(self._menus['&Windows'][0].menuAction(), menu) status['actions'].extend(actions) map(menu.addAction, actions) if toolbar: map(self.toolbar.addAction, actions) if save: shortcutsettings.ActionEditorDialog.saveSettings(status['actions']) def _status(self, controls): x = {} def status(k): if k in x: return x[value]() controls = controls.values() connect = self.connect(c, SIGNAL('getstatus'), status) [x.update(z.status) for z in controls] self._status = x self.connect(control, 'getstatus', getstatus) def _clearPreview(self): self._table.model().unSetTestData() def createShortcut(self, text, slot, *args,**kwargs): action = ls.create_action(self, text, None, slot) connect_actions([action], PuddleDock._controls) def _dirChanged(self, dirs): if not dirs: self.setWindowTitle('puddletag') return if isinstance(dirs, basestring): dirs = [dirs] dirs = [encode_fn(d) for d in dirs] if self._lastdir: initial = self._lastdir[0] else: initial = None if initial not in dirs: initial = dirs[0] if isinstance(initial, str): initial = initial.decode('utf8', 'replace') if len(dirs) > 1: self.setWindowTitle(translate("Main Window", 'puddletag: %1 + others').arg(initial)) else: self.setWindowTitle(translate("Main Window", 'puddletag: %1').arg(initial)) self._lastdir = dirs def _getDir(self): dirname = self._lastdir[0] if self._lastdir else QDir.homePath() filedlg = QFileDialog() filedlg.setFileMode(filedlg.DirectoryOnly) filedlg.setResolveSymlinks(False) filename = unicode(filedlg.getExistingDirectory(self, translate("Main Window", 'Import directory...'), dirname ,QFileDialog.ShowDirsOnly)) return filename def appendDir(self, filename=None): self.openDir(filename, append=True) def _filesLoaded(self, val): self.emit(SIGNAL('filesloaded'), val) def _filesSelected(self, val): self.emit(SIGNAL('filesselected'), val) def applyGenSettings(self, settings, level=None): pass def closeEvent(self, e): preview_msg = translate('Previews', 'Some files have uncommited previews. ' 'These changes will be lost once you exit puddletag. <br />' 'Do you want to exit without writing those changes?<br />') if tagmodel.has_previews(parent=self, msg=preview_msg): e.ignore() return False controls = PuddleDock._controls for control in PuddleDock._controls.values(): if hasattr(control, 'saveSettings'): try: control.saveSettings(self) except TypeError: control.saveSettings() cparser = PuddleConfig() settings = QSettings(constants.QT_CONFIG, QSettings.IniFormat) if self._lastdir: cparser.set('main', 'lastfolder', unicode(self._lastdir[0], 'utf8')) cparser.set("main", "maximized", self.isMaximized()) settings.setValue('main/state', QVariant(self.saveState())) headstate = self._table.horizontalHeader().saveState() settings.setValue('table/header', QVariant(headstate)) genres.save_genres(status['genres']) e.accept() def createStatusBar(self): statusbar = self.statusBar() statuslabel = QLabel() statuslabel.setFrameStyle(QFrame.NoFrame) statusbar.addPermanentWidget(statuslabel, 1) self._totalstats = QLabel('00 (00:00:00 | 00 MB)') self._selectedstats = QLabel('00 (00:00:00 | 00 MB)') preview_status = PreviewLabel(translate("Previews", 'Preview Mode: Off')) statusbar.addPermanentWidget(preview_status, 0) statusbar.addPermanentWidget(self._selectedstats, 0) statusbar.addPermanentWidget(self._totalstats, 0) def set_preview_status(value): if value: preview_status.setText(translate("Previews", '<b>Preview Mode: On</b>')) else: preview_status.setText(translate("Previews", 'Preview Mode: Off')) def change_preview(value): if value: self.emit(SIGNAL('enable_preview_mode')) else: self.emit(SIGNAL('disable_preview_mode')) self.connect(preview_status, SIGNAL('valueChanged'), change_preview) self.connect(self._table.model(), SIGNAL('previewModeChanged'), set_preview_status) statusbar.setMaximumHeight(statusbar.height()) self.connect(statusbar,SIGNAL("messageChanged (const QString&)"), statuslabel.setText) def loadPlayList(self): filedlg = QFileDialog() dirname = self._lastdir[0] if self._lastdir else QDir.homePath() filename = unicode(filedlg.getOpenFileName(self, translate("Playlist", translate("Playlist", 'Select m3u file...')), )) if not filename: return try: files = m3u.readm3u(filename) self.emit(SIGNAL('loadFiles'), files, None, None, None, filename) except (OSError, IOError), e: QMessageBox.information(self._table, translate("Defaults", 'Error'), translate("Playlist", 'An error occured while reading <b>%1</b> (%2)').arg(filename).arg(e.strerror), QMessageBox.Ok, QMessageBox.NoButton) except Exception, e: QMessageBox.information(self._table, translate("Defaults", 'Error'), translate("Playlist", 'An error occured while reading <b>%1</b> (%2)').arg(filename).arg(unicode(e)), QMessageBox.Ok)
class MainWin(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.__updateDirs = True self.__dirsToUpdate = [] global add_shortcuts global remove_shortcuts add_shortcuts = self.addShortcuts remove_shortcuts = self.removeShortcuts plugins.add_shortcuts = add_shortcuts self.emits = [ 'loadFiles', 'always', 'dirsmoved', 'libfilesedited', 'enable_preview_mode', 'disable_preview_mode' ] self.receives = [('writeselected', self.writeTags), ('filesloaded', self._filesLoaded), ('viewfilled', self._viewFilled), ('filesselected', self._filesSelected), ('renamedirs', self.renameDirs), ('filesloaded', self.updateTotalStats), ('filesselected', self.updateSelectedStats), ('onetomany', self.writeOneToMany), ('dirschanged', self._dirChanged), ('writepreview', self._writePreview), ('clearpreview', self._clearPreview), ('renameselected', self._renameSelected), ('playlistchanged', self._dirChanged), ('adddock', self.addDock), ('writeaction', self.writeAction), ('onetomanypreview', self.writeSinglePreview), ('manypreview', self.writeManyPreview)] self.gensettings = [('&Load last folder at startup', False, 1)] self._playlist = None plugin_dialogs, plugin_modules = load_plugins() self.setWindowTitle("puddletag") self.setDockNestingEnabled(True) self._table = TagTable() self.connect(self._table, SIGNAL('dirsmoved'), self.updateDirs) win = QSplitter() layout = QVBoxLayout() layout.addWidget(self._table) win.setLayout(layout) self.setCentralWidget(win) PuddleDock._controls = { 'table': self._table, 'mainwin': self, 'funcs': mainfuncs.obj, } status['mainwin'] = self status['model'] = self._table.model() status['table'] = self._table ls.create_files() winactions, self._docks = create_tool_windows(self) status['dialogs'] = PuddleDock._controls self.createStatusBar() actions = ls.get_actions(self) menus = ls.get_menus('menu') previewactions = mainwin.previews.create_actions(self) all_actions = actions + winactions + previewactions controls = PuddleDock._controls toolgroup = ls.get_menus('toolbar') toolbar = ls.toolbar(toolgroup, all_actions, controls) toolbar.setObjectName(translate("Menus", 'Toolbar')) self.addToolBar(toolbar) menubar, winmenu, self._menus = ls.menubar(menus, all_actions) temp_winactions = winmenu.actions() [winmenu.addAction(a) for a in winactions if a not in temp_winactions] if winmenu: winmenu.addSeparator() self._winmenu = winmenu else: self._winmenu = QMenu(translate("Settings", '&Windows'), self) menubar.addMenu(self._winmenu) self.setMenuBar(menubar) menubar.addMenu(help_menu(self)) mainfuncs.connect_status(actions) connect_actions(actions, controls) connect_action_shortcuts(all_actions) create_context_menus(controls, all_actions) status['actions'] = all_actions for m in plugin_modules: if hasattr(m, 'init'): try: m.init(parent=self) except: traceback.print_exc() continue for win in plugin_dialogs: try: self.addDock(*win, connect=False) except: logging.exception("Error while loading Plugin dialog.") self.restoreSettings() self.emit(SIGNAL('always'), True) def addDock(self, name, dialog, position, visibility=True, connect=True): controls = PuddleDock._controls.values() dock = PuddleDock(name, dialog, self, status) self.addDockWidget(position, dock) self._winmenu.addAction(dock.toggleViewAction()) if connect: connect_control(PuddleDock._controls[name], controls) dock.setVisible(visibility) self.restoreDockWidget(dock) return PuddleDock._controls[name] def addShortcuts(self, menu_title, actions, toolbar=False, save=False): if not actions: return if menu_title in self._menus: menu = self._menus[menu_title][0] else: menu = QMenu(menu_title) self._menus[menu_title] = [menu] + actions self.menuBar().insertMenu(self._menus['&Windows'][0].menuAction(), menu) status['actions'].extend(actions) map(menu.addAction, actions) if toolbar: map(self.toolbar.addAction, actions) if save: shortcutsettings.ActionEditorDialog.saveSettings(status['actions']) def _status(self, controls): x = {} def status(k): if k in x: return x[value]() controls = controls.values() connect = self.connect(c, SIGNAL('getstatus'), status) [x.update(z.status) for z in controls] self._status = x self.connect(control, 'getstatus', getstatus) def _clearPreview(self): self._table.model().unSetTestData() def createShortcut(self, text, slot, *args, **kwargs): action = ls.create_action(self, text, None, slot) connect_actions([action], PuddleDock._controls) def _dirChanged(self, dirs): if not dirs: self.setWindowTitle('puddletag') return if isinstance(dirs, basestring): dirs = [dirs] dirs = [encode_fn(d) for d in dirs] if self._lastdir: initial = self._lastdir[0] else: initial = None if initial not in dirs: initial = dirs[0] if isinstance(initial, str): initial = initial.decode('utf8', 'replace') if len(dirs) > 1: self.setWindowTitle( translate("Main Window", 'puddletag: %1 + others').arg(initial)) else: self.setWindowTitle( translate("Main Window", 'puddletag: %1').arg(initial)) self._lastdir = dirs def _getDir(self): dirname = self._lastdir[0] if self._lastdir else QDir.homePath() filedlg = QFileDialog() filedlg.setFileMode(filedlg.DirectoryOnly) filedlg.setResolveSymlinks(False) filename = unicode( filedlg.getExistingDirectory( self, translate("Main Window", 'Import directory...'), dirname, QFileDialog.ShowDirsOnly)) return filename def appendDir(self, filename=None): self.openDir(filename, append=True) def _filesLoaded(self, val): self.emit(SIGNAL('filesloaded'), val) def _filesSelected(self, val): self.emit(SIGNAL('filesselected'), val) def applyGenSettings(self, settings, level=None): pass def closeEvent(self, e): preview_msg = translate( 'Previews', 'Some files have uncommited previews. ' 'These changes will be lost once you exit puddletag. <br />' 'Do you want to exit without writing those changes?<br />') if tagmodel.has_previews(parent=self, msg=preview_msg): e.ignore() return False controls = PuddleDock._controls for control in PuddleDock._controls.values(): if hasattr(control, 'saveSettings'): try: control.saveSettings(self) except TypeError: control.saveSettings() cparser = PuddleConfig() settings = QSettings(constants.QT_CONFIG, QSettings.IniFormat) if self._lastdir: cparser.set('main', 'lastfolder', unicode(self._lastdir[0], 'utf8')) cparser.set("main", "maximized", self.isMaximized()) settings.setValue('main/state', QVariant(self.saveState())) headstate = self._table.horizontalHeader().saveState() settings.setValue('table/header', QVariant(headstate)) genres.save_genres(status['genres']) e.accept() def createStatusBar(self): statusbar = self.statusBar() statuslabel = QLabel() statuslabel.setFrameStyle(QFrame.NoFrame) statusbar.addPermanentWidget(statuslabel, 1) self._totalstats = QLabel('00 (00:00:00 | 00 MB)') self._selectedstats = QLabel('00 (00:00:00 | 00 MB)') preview_status = PreviewLabel( translate("Previews", 'Preview Mode: Off')) statusbar.addPermanentWidget(preview_status, 0) statusbar.addPermanentWidget(self._selectedstats, 0) statusbar.addPermanentWidget(self._totalstats, 0) def set_preview_status(value): if value: preview_status.setText( translate("Previews", '<b>Preview Mode: On</b>')) else: preview_status.setText( translate("Previews", 'Preview Mode: Off')) def change_preview(value): if value: self.emit(SIGNAL('enable_preview_mode')) else: self.emit(SIGNAL('disable_preview_mode')) self.connect(preview_status, SIGNAL('valueChanged'), change_preview) self.connect(self._table.model(), SIGNAL('previewModeChanged'), set_preview_status) statusbar.setMaximumHeight(statusbar.height()) self.connect(statusbar, SIGNAL("messageChanged (const QString&)"), statuslabel.setText) def loadPlayList(self): filedlg = QFileDialog() dirname = self._lastdir[0] if self._lastdir else QDir.homePath() filename = unicode( filedlg.getOpenFileName( self, translate("Playlist", translate("Playlist", 'Select m3u file...')), )) if not filename: return try: files = m3u.readm3u(filename) self.emit(SIGNAL('loadFiles'), files, None, None, None, filename) except (OSError, IOError), e: QMessageBox.information( self._table, translate("Defaults", 'Error'), translate("Playlist", 'An error occured while reading <b>%1</b> (%2)').arg( filename).arg(e.strerror), QMessageBox.Ok, QMessageBox.NoButton) except Exception, e: QMessageBox.information( self._table, translate("Defaults", 'Error'), translate("Playlist", 'An error occured while reading <b>%1</b> (%2)').arg( filename).arg(unicode(e)), QMessageBox.Ok)