def save(self, content=None, icon=None, version=True, force=False): """ @type content: list[str] @type icon: str @type version: str @type force: bool """ e = RecordEvent(record=self) self.savingEvent(e) if not content: content = [] if not self.name(): raise Exception( 'Cannot save record! Please set a name for the record.') if not self.plugin(): raise Exception( 'Cannot save record! Please set a plugin for the record.') window = self.window() if window: folders = window.selectedFolders() if len(folders) != 1: raise Exception('Please select ONE folder.') self.setFolder(folders[0]) if self.exists(): if force: self.retire() elif window: result = window.questionDialog( "The chosen name '%s' already exists!\n Would you like to create a new version?" % self.name(), 'New version') if result == QtGui.QMessageBox.Yes: self.retire() else: raise Exception( "Cannot save record because record already exists! '%s'" % self.name()) else: raise Exception( "Cannot save record because record already exists! '%s'" % self.name()) studiolibrary.Folder.save(self) if icon: shutil.move(icon, self.icon()) for path in content or []: basename = os.path.basename(path) destination = self.dirname() + '/' + basename shutil.move(path, destination) self.reloadRecords() studiolibrary.analytics().logEvent('Create', self.plugin().name()) self.savedEvent(e) if window: selected = window.selectedRecords() if not selected and window.filter(): msg = 'Successfully created! \nHowever it could not be selected \nbecause a search filter is active!' window.informationDialog(msg)
def save(self, content = None, icon = None, version = True, force = False): """ @type content: list[str] @type icon: str @type version: str @type force: bool """ e = RecordEvent(record=self) self.savingEvent(e) if not content: content = [] if not self.name(): raise Exception('Cannot save record! Please set a name for the record.') if not self.plugin(): raise Exception('Cannot save record! Please set a plugin for the record.') window = self.window() if window: folders = window.selectedFolders() if len(folders) != 1: raise Exception('Please select ONE folder.') self.setFolder(folders[0]) if self.exists(): if force: self.retire() elif window: result = window.questionDialog("The chosen name '%s' already exists!\n Would you like to create a new version?" % self.name(), 'New version') if result == QtGui.QMessageBox.Yes: self.retire() else: raise Exception("Cannot save record because record already exists! '%s'" % self.name()) else: raise Exception("Cannot save record because record already exists! '%s'" % self.name()) studiolibrary.Folder.save(self) if icon: shutil.move(icon, self.icon()) for path in content or []: basename = os.path.basename(path) destination = self.dirname() + '/' + basename shutil.move(path, destination) self.reloadRecords() studiolibrary.analytics().logEvent('Create', self.plugin().name()) self.savedEvent(e) if window: selected = window.selectedRecords() if not selected and window.filter(): msg = 'Successfully created! \nHowever it could not be selected \nbecause a search filter is active!' window.informationDialog(msg)
def main( name=None, path=None, show=True, plugins=None, analytics=True, root=None, # Legacy **kwargs ): """ The main entry point for creating and loading a library. :type name: str :type path: str :type show: bool :type plugins: list[str] :type analytics: bool :type root: str :type kwargs: dict :rtype: studiolibrary.Library """ studiolibrary.analytics().setEnabled(analytics) if not name: library = studiolibrary.Library.default() else: library = studiolibrary.Library.instance(name) if plugins is None: library.setPlugins(studiolibrary.Library.DEFAULT_PLUGINS) else: library.setPlugins(plugins) if root: # Legacy path = root if path: library.setPath(path) studiolibrary.enableMayaClosedEvent() if show: with studioqt.app(): library.show(**kwargs) return library
def main( name=None, path=None, show=True, analytics=True, **kwargs ): """ The main entry point for creating and loading a library. :type name: str :type path: str :type show: bool :type analytics: bool :type kwargs: dict :rtype: studiolibrary.Library """ studiolibrary.analytics().setEnabled(analytics) isNewUser = not path and not studiolibrary.libraries() if show and isNewUser: library = studiolibrary.showWelcomeDialog(showOnAccepted=False) elif name: library = studiolibrary.Library.instance(name) else: library = studiolibrary.Library.default() if path: library.setPath(path) library.setKwargs(kwargs) studiolibrary.enableMayaClosedEvent() if show: library.show() return library
def __init__(self, library): """ :type library: studiolibrary.Library """ QtGui.QWidget.__init__(self, None) studiolibrary.MayaDockWidgetMixin.__init__(self, None) studioqt.loadUi(self) logger.info("Loading library window '{0}'".format(library.name())) self.setUniqueObjectName('studiolibrary') studiolibrary.analytics().logScreen('MainWindow') self._pSize = None self._pShow = None self._library = None self._isDebug = False self._isLocked = False self._isLoaded = False self._showFolders = False self._updateThread = None self._showLabelsAction = True self._saveSettingsOnClose = True self.ui.dialogWidget = None self.ui.createWidget = None self.ui.previewWidget = None self._isFoldersWidgetVisible = True self._isPreviewWidgetVisible = True self._isMenuBarWidgetVisible = True self._isStatusBarWidgetVisible = True self.ui.previewFrame = QtGui.QFrame(self) self.ui.statusWidget = studiolibrary.StatusWidget(self) self.ui.recordsWidget = studioqt.ListWidget(self) self.ui.foldersWidget = studiolibrary.FoldersWidget(self) self.setMinimumWidth(5) self.setMinimumHeight(5) pixmap = studioqt.pixmap('settings', color=self.iconColor()) self.ui.settingsButton.setIconSize(QtCore.QSize(26, 26)) self.ui.settingsButton.setIcon(pixmap) pixmap = studioqt.pixmap('add', color=self.iconColor()) self.ui.createButton.setIconSize(QtCore.QSize(32, 32)) self.ui.createButton.setIcon(pixmap) self.ui.updateButton.hide() self.layout().setContentsMargins(0, 0, 0, 0) self.ui.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal, self) self.ui.splitter.setHandleWidth(1) self.ui.splitter.setChildrenCollapsible(False) self.ui.viewLayout.insertWidget(1, self.ui.splitter) self.ui.splitter.insertWidget(0, self.ui.foldersWidget) self.ui.splitter.insertWidget(1, self.ui.recordsWidget) self.ui.splitter.setStretchFactor(0, False) self.ui.splitter.setStretchFactor(2, False) vbox = QtGui.QVBoxLayout() self.ui.previewFrame.setLayout(vbox) self.ui.previewFrame.layout().setSpacing(0) self.ui.previewFrame.layout().setContentsMargins(0, 0, 0, 0) self.ui.previewFrame.setMinimumWidth(5) self.ui.viewLayout.insertWidget(2, self.ui.previewFrame) self.ui.splitter.insertWidget(2, self.ui.previewFrame) self.ui.statusLayout.addWidget(self.ui.statusWidget) self.ui.updateButton.clicked.connect(self.help) self.ui.createButton.clicked.connect(self.showNewMenu) self.ui.settingsButton.clicked.connect(self.showSettingsMenu) self.dockingChanged.connect(self.updateWindowTitle) folderWidget = self.foldersWidget() folderWidget.onDropped.connect(self.onRecordDropped) folderWidget.onSelectionChanged.connect(self.folderSelectionChanged) folderWidget.onShowContextMenu.connect(self.onShowFolderContextMenu) recordsWidget = self.recordsWidget() recordsWidget.itemDropped.connect(self.onRecordDropped) recordsWidget.itemOrderChanged.connect(self.onRecordOrderChanged) recordsWidget.onShowContextMenu.connect(self.onShowRecordContextMenu) recordsWidget.onSelectionChanged.connect(self.onRecordSelectionChanged) studiolibrary.Record.onSaved.connect(self.onRecordSaved) studiolibrary.SettingsDialog.onColorChanged.connect(self.onSettingsColorChanged) studiolibrary.SettingsDialog.onBackgroundColorChanged.connect(self.onSettingsBackgroundColorChanged) self.checkForUpdates() self.setLibrary(library)
def __init__(self, library): """ :type library: studiolibrary.Library """ QtGui.QWidget.__init__(self, None) studiolibrary.MayaDockWidgetMixin.__init__(self, None) studioqt.loadUi(self) logger.info("Loading library window '{0}'".format(library.name())) self.setUniqueObjectName('studiolibrary') studiolibrary.analytics().logScreen('MainWindow') self._pSize = None self._pShow = None self._library = None self._isDebug = False self._isLocked = False self._isLoaded = False self._showFolders = False self._updateThread = None self._showLabelsAction = True self._saveSettingsOnClose = True self.ui.dialogWidget = None self.ui.createWidget = None self.ui.previewWidget = None self._isFoldersWidgetVisible = True self._isPreviewWidgetVisible = True self._isMenuBarWidgetVisible = True self._isStatusBarWidgetVisible = True self.ui.previewFrame = QtGui.QFrame(self) self.ui.statusWidget = studiolibrary.StatusWidget(self) self.ui.recordsWidget = studioqt.ListWidget(self) self.ui.foldersWidget = studiolibrary.FoldersWidget(self) self.setMinimumWidth(5) self.setMinimumHeight(5) pixmap = studioqt.pixmap('settings', color=self.iconColor()) self.ui.settingsButton.setIconSize(QtCore.QSize(26, 26)) self.ui.settingsButton.setIcon(pixmap) pixmap = studioqt.pixmap('add', color=self.iconColor()) self.ui.createButton.setIconSize(QtCore.QSize(32, 32)) self.ui.createButton.setIcon(pixmap) self.ui.updateButton.hide() self.layout().setContentsMargins(0, 0, 0, 0) self.ui.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal, self) self.ui.splitter.setHandleWidth(1) self.ui.splitter.setChildrenCollapsible(False) self.ui.viewLayout.insertWidget(1, self.ui.splitter) self.ui.splitter.insertWidget(0, self.ui.foldersWidget) self.ui.splitter.insertWidget(1, self.ui.recordsWidget) self.ui.splitter.setStretchFactor(0, False) self.ui.splitter.setStretchFactor(2, False) vbox = QtGui.QVBoxLayout() self.ui.previewFrame.setLayout(vbox) self.ui.previewFrame.layout().setSpacing(0) self.ui.previewFrame.layout().setContentsMargins(0, 0, 0, 0) self.ui.previewFrame.setMinimumWidth(5) self.ui.viewLayout.insertWidget(2, self.ui.previewFrame) self.ui.splitter.insertWidget(2, self.ui.previewFrame) self.ui.statusLayout.addWidget(self.ui.statusWidget) self.ui.updateButton.clicked.connect(self.help) self.ui.createButton.clicked.connect(self.showNewMenu) self.ui.settingsButton.clicked.connect(self.showSettingsMenu) self.dockingChanged.connect(self.updateWindowTitle) folderWidget = self.foldersWidget() folderWidget.onDropped.connect(self.onRecordDropped) folderWidget.onSelectionChanged.connect(self.folderSelectionChanged) folderWidget.onShowContextMenu.connect(self.onShowFolderContextMenu) recordsWidget = self.recordsWidget() recordsWidget.itemDropped.connect(self.onRecordDropped) recordsWidget.itemOrderChanged.connect(self.onRecordOrderChanged) recordsWidget.onShowContextMenu.connect(self.onShowRecordContextMenu) recordsWidget.onSelectionChanged.connect(self.onRecordSelectionChanged) studiolibrary.Record.onSaved.connect(self.onRecordSaved) studiolibrary.SettingsDialog.onColorChanged.connect( self.onSettingsColorChanged) studiolibrary.SettingsDialog.onBackgroundColorChanged.connect( self.onSettingsBackgroundColorChanged) self.checkForUpdates() self.setLibrary(library)