def reload(self): """ :rtype: None """ self.clear() if self._enableSelectContent: action = selectContentAction(item=self.item(), parent=self) self.addAction(action) self.addSeparator() selectionSets = self.selectionSets() if selectionSets: for selectionSet in selectionSets: dirname = os.path.basename(os.path.dirname( selectionSet.path())) basename = os.path.basename(selectionSet.path()) basename = basename.replace(selectionSet.EXTENSION, "") nicename = dirname + ": " + basename action = QtWidgets.QAction(nicename, self) callback = partial(selectionSet.load, namespaces=self.namespaces()) action.triggered.connect(callback) self.addAction(action) else: action = QtWidgets.QAction("No selection sets found!", self) action.setEnabled(False) self.addAction(action)
def createActions(self): """ Crate the actions to be shown in the menu. :rtype: None """ # Create the menu actions for setting the accent color action = SeparatorAction("Accent", self) self.addAction(action) themes = self._themes if not themes: themes = themePresets() for theme in themes: if theme.accentColor(): action = ThemeAction(theme, self) self.addAction(action) if self.ENABLE_CUSTOM_ACTION: action = QtWidgets.QAction("Custom", self) action.triggered.connect(self.theme().browseAccentColor) color = self.theme().accentColor().toString() icon = studiolibrary.resource.icon(ThemesMenu.THEME_ICON, color=color) action.setIcon(icon) self.addAction(action) # Create the menu actions for setting the background color action = SeparatorAction("Background", self) self.addAction(action) for theme in themes: if not theme.accentColor() and theme.backgroundColor(): action = ThemeAction(theme, self) self.addAction(action) if self.ENABLE_CUSTOM_ACTION: action = QtWidgets.QAction("Custom", self) action.triggered.connect(self._theme.browseBackgroundColor) color = self._theme.backgroundColor().toString() icon = studiolibrary.resource.icon(ThemesMenu.THEME_ICON, color=color) action.setIcon(icon) self.addAction(action) self.triggered.connect(self._triggered)
def contextEditMenu(self, menu, items=None): """ Called when creating the context menu for the item. :type menu: QtWidgets.QMenu :type items: list[FolderItem] or None """ super(FolderItem, self).contextEditMenu(menu, items=items) action = QtWidgets.QAction("Show in Preview", menu) action.triggered.connect(self._showPreviewFromMenu) menu.addAction(action) menu.addSeparator() action = studiolibrary.widgets.colorpicker.ColorPickerAction(menu) action.picker().setColors(self.DEFAULT_ICON_COLORS) action.picker().colorChanged.connect(self.setIconColor) action.picker().setCurrentColor(self.iconColor()) action.picker().menuButton().hide() menu.addAction(action) iconName = self.itemData().get("icon", "") action = studiolibrary.widgets.iconpicker.IconPickerAction(menu) action.picker().setIcons(self.DEFAULT_ICONS) action.picker().setCurrentIcon(iconName) action.picker().iconChanged.connect(self.setCustomIcon) action.picker().menuButton().hide() menu.addAction(action)
def addAction(self, path, text, tip, callback): """ Add an action to the tool bar. :type path: str :type text: str :type tip: str :type callback: func :rtype: QtWidgets.QAction """ icon = studioqt.Icon.fa( path, color="rgb(250,250,250,160)", color_active="rgb(250,250,250,250)", color_disabled="rgb(0,0,0,20)" ) action = QtWidgets.QAction(icon, text, self._toolBar) action.setToolTip(tip) # action.setStatusTip(tip) # action.setWhatsThis(tip) self._toolBar.insertAction(self._firstSpacer, action) action.triggered.connect(callback) return action
def __init__(self, libraryWindow=None): super(LibrariesMenu, self).__init__(libraryWindow) self.setTitle('Libraries') libraries = studiolibrary.readSettings() default = studiolibrary.defaultLibrary() for name in libraries: library = libraries[name] path = library.get('path', '') kwargs = library.get('kwargs', {}) enabled = True if libraryWindow: enabled = name != libraryWindow.name() text = name if name == default and name.lower() != "default": text = name + " (default)" action = QtWidgets.QAction(text, self) action.setEnabled(enabled) callback = partial(self.showLibrary, name, path, **kwargs) action.triggered.connect(callback) self.addAction(action)
def selectContentAction(item, parent=None): """ :param item: mayabaseitem.MayaBaseItem :param parent: QtWidgets.QMenu """ arrowIcon = QtGui.QIcon(ARROW_ICON_PATH) action = QtWidgets.QAction(arrowIcon, "Select content", parent) action.triggered.connect(item.selectContent) return action
def createOverwriteMenu(self, menu): """ Create a menu or action to trigger the overwrite method. :type menu: QtWidgets.QMenu """ if not self.isReadOnly(): menu.addSeparator() action = QtWidgets.QAction("Overwrite", menu) action.triggered.connect(self.overwrite) menu.addAction(action)
def createSpaceOperatorMenu(self, parent=None): """ Return the menu for changing the space operator. :type parent: QGui.QMenu :rtype: QGui.QMenu """ menu = QtWidgets.QMenu(parent) menu.setTitle("Space Operator") # Create the space operator for the OR operator action = QtWidgets.QAction(menu) action.setText("OR") action.setCheckable(True) callback = partial(self.setSpaceOperator, "or") action.triggered.connect(callback) if self.spaceOperator() == "or": action.setChecked(True) menu.addAction(action) # Create the space operator for the AND operator action = QtWidgets.QAction(menu) action.setText("AND") action.setCheckable(True) callback = partial(self.setSpaceOperator, "and") action.triggered.connect(callback) if self.spaceOperator() == "and": action.setChecked(True) menu.addAction(action) return menu
def __init__(self, path, force=False, parent=None): """ Thumbnail capture menu. :type path: str :type force: bool :type parent: None or QtWidgets.QWidget """ QtWidgets.QMenu.__init__(self, parent) self._path = path self._force = force changeImageAction = QtWidgets.QAction('Capture new image', self) changeImageAction.triggered.connect(self.capture) self.addAction(changeImageAction) changeImageAction = QtWidgets.QAction('Show Capture window', self) changeImageAction.triggered.connect(self.showCaptureWindow) self.addAction(changeImageAction) loadImageAction = QtWidgets.QAction('Load image from disk', self) loadImageAction.triggered.connect(self.showLoadImageDialog) self.addAction(loadImageAction)
def createSettingsMenu(self): """ Create and return the settings menu for the widget. :rtype: QtWidgets.QMenu """ menu = QtWidgets.QMenu("Item View", self) menu.addSeparator() action = QtWidgets.QAction("Show labels", menu) action.setCheckable(True) action.setChecked(self.isItemTextVisible()) action.triggered[bool].connect(self.setItemTextVisible) menu.addAction(action) menu.addSeparator() copyTextMenu = self.treeWidget().createCopyTextMenu() menu.addMenu(copyTextMenu) menu.addSeparator() action = SliderAction("Size", menu) action.slider().setMinimum(10) action.slider().setMaximum(200) action.slider().setValue(self.zoomAmount()) action.slider().valueChanged.connect(self.setZoomAmount) menu.addAction(action) action = SliderAction("Border", menu) action.slider().setMinimum(0) action.slider().setMaximum(20) action.slider().setValue(self.padding()) action.slider().valueChanged.connect(self.setPadding) menu.addAction(action) # action = SliderAction("Spacing", menu) action.slider().setMinimum(self.DEFAULT_MIN_SPACING) action.slider().setMaximum(self.DEFAULT_MAX_SPACING) action.slider().setValue(self.spacing()) action.slider().valueChanged.connect(self.setSpacing) menu.addAction(action) return menu
def createAction(cls, menu, libraryWindow): """ Return the action to be displayed when the user ks the "plus" icon. :type menu: QtWidgets.QMenu :type libraryWindow: studiolibrary.LibraryWindow :rtype: QtCore.QAction """ if cls.NAME: icon = QtGui.QIcon(cls.ICON_PATH) callback = partial(cls.showSaveWidget, libraryWindow) action = QtWidgets.QAction(icon, cls.NAME, menu) action.triggered.connect(callback) return action
def createSettingsMenu(self): menu = QtWidgets.QMenu("Item View", self) action = SeparatorAction("View Settings", menu) menu.addAction(action) action = SliderAction("Size", menu) action.slider().setMinimum(10) action.slider().setMaximum(200) action.slider().setValue(self.zoomAmount()) action.slider().valueChanged.connect(self.setZoomAmount) menu.addAction(action) action = SliderAction("Border", menu) action.slider().setMinimum(0) action.slider().setMaximum(20) action.slider().setValue(self.padding()) action.slider().valueChanged.connect(self.setPadding) menu.addAction(action) # action = SliderAction("Spacing", menu) action.slider().setMinimum(self.DEFAULT_MIN_SPACING) action.slider().setMaximum(self.DEFAULT_MAX_SPACING) action.slider().setValue(self.spacing()) action.slider().valueChanged.connect(self.setSpacing) menu.addAction(action) action = SeparatorAction("Label Options", menu) menu.addAction(action) for option in LabelDisplayOption.values(): action = QtWidgets.QAction(option.title(), menu) action.setCheckable(True) action.setChecked(option == self.labelDisplayOption()) callback = functools.partial(self.setLabelDisplayOption, option) action.triggered.connect(callback) menu.addAction(action) return menu
def showExample(): """ Run a simple example of the widget. :rtype: QtWidgets.QWidget """ with studioqt.app(): menuBarWidget = MenuBarWidget(None) def setIconColor(): menuBarWidget.setIconColor(QtGui.QColor(255, 255, 0)) def collapse(): menuBarWidget.collapse() menuBarWidget.show() action = menuBarWidget.addAction("Collapse") action.triggered.connect(collapse) w = QtWidgets.QLineEdit() menuBarWidget.addWidget(w) icon = studiolibrary.resource.icon("add") menuBarWidget.addAction(icon, "Plus") menuBarWidget.setStyleSheet(""" background-color: rgb(0,200,100); spacing:5px; """) menuBarWidget.setChildrenHeight(50) action = QtWidgets.QAction("Yellow", None) action.triggered.connect(setIconColor) menuBarWidget.insertAction("Plus", action) menuBarWidget.setGeometry(400, 400, 400, 100) menuBarWidget.expand()
def createItemSettingsMenu(self): menu = QtWidgets.QMenu("Item View", self) action = SeparatorAction("View Settings", menu) menu.addAction(action) action = SliderAction("Size", menu) action.slider().setMinimum(10) action.slider().setMaximum(200) action.slider().setValue(self.zoomAmount()) action.slider().valueChanged.connect(self.setZoomAmount) menu.addAction(action) action = SliderAction("Border", menu) action.slider().setMinimum(0) action.slider().setMaximum(20) action.slider().setValue(self.padding()) action.slider().valueChanged.connect(self.setPadding) menu.addAction(action) # action = SliderAction("Spacing", menu) action.slider().setMinimum(self.DEFAULT_MIN_SPACING) action.slider().setMaximum(self.DEFAULT_MAX_SPACING) action.slider().setValue(self.spacing()) action.slider().valueChanged.connect(self.setSpacing) menu.addAction(action) action = SeparatorAction("Item Options", menu) menu.addAction(action) action = QtWidgets.QAction("Show labels", menu) action.setCheckable(True) action.setChecked(self.isItemTextVisible()) action.triggered[bool].connect(self.setItemTextVisible) menu.addAction(action) return menu
def createItemsMenu(self, items=None): """ Create the item menu for given item. :rtype: QtWidgets.QMenu """ item = items or self.selectedItem() menu = QtWidgets.QMenu(self) if item: try: item.contextMenu(menu) except Exception as error: logger.exception(error) else: action = QtWidgets.QAction(menu) action.setText("No Item selected") action.setDisabled(True) menu.addAction(action) return menu
def contextEditMenu(self, menu, items=None): """ Called when the user would like to edit the item from the menu. The given menu is shown as a submenu of the main context menu. :type menu: QtWidgets.QMenu :type items: list[LibraryItem] :rtype: None """ action = QtWidgets.QAction("Rename", menu) action.triggered.connect(self.showRenameDialog) menu.addAction(action) action = QtWidgets.QAction("Move to", menu) action.triggered.connect(self.showMoveDialog) menu.addAction(action) action = QtWidgets.QAction("Copy Path", menu) action.triggered.connect(self.copyPathToClipboard) menu.addAction(action) if self.libraryWindow(): action = QtWidgets.QAction("Select Folder", menu) action.triggered.connect(self.selectFolder) menu.addAction(action) action = QtWidgets.QAction("Show in Folder", menu) action.triggered.connect(self.showInFolder) menu.addAction(action) if self.isDeletable(): menu.addSeparator() action = QtWidgets.QAction("Delete", menu) action.triggered.connect(self.showDeleteDialog) menu.addAction(action) self.createOverwriteMenu(menu)