def setupUi(self, Item): Item.setObjectName("Item") Item.resize(329, 65) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Item.sizePolicy().hasHeightForWidth()) Item.setSizePolicy(sizePolicy) Item.setMinimumSize(QtCore.QSize(0, 65)) self.verticalLayout = QtGui.QVBoxLayout(Item) self.verticalLayout.setSpacing(2) self.verticalLayout.setContentsMargins(2, 2, 2, 2) self.verticalLayout.setObjectName("verticalLayout") self.background = ClickBubblingGroupBox(Item) self.background.setTitle("") self.background.setObjectName("background") self.horizontalLayout = QtGui.QHBoxLayout(self.background) self.horizontalLayout.setSpacing(8) self.horizontalLayout.setContentsMargins(10, 2, 2, 2) self.horizontalLayout.setObjectName("horizontalLayout") self.light = QtGui.QLabel(self.background) self.light.setText("") self.light.setPixmap(QtGui.QPixmap(":/res/empty_bullet.png")) self.light.setObjectName("light") self.horizontalLayout.addWidget(self.light) self.thumbnail = ThumbnailLabel(self.background) self.thumbnail.setMinimumSize(QtCore.QSize(60, 40)) self.thumbnail.setMaximumSize(QtCore.QSize(60, 40)) self.thumbnail.setText("") self.thumbnail.setPixmap(QtGui.QPixmap(":/res/no_thumb.png")) self.thumbnail.setScaledContents(False) self.thumbnail.setAlignment(QtCore.Qt.AlignCenter) self.thumbnail.setObjectName("thumbnail") self.horizontalLayout.addWidget(self.thumbnail) self.details = QtGui.QLabel(self.background) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.details.sizePolicy().hasHeightForWidth()) self.details.setSizePolicy(sizePolicy) self.details.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.details.setWordWrap(True) self.details.setObjectName("details") self.horizontalLayout.addWidget(self.details) self.verticalLayout.addWidget(self.background) self.retranslateUi(Item) QtCore.QMetaObject.connectSlotsByName(Item)
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) if sys.platform == "darwin": self.setAttribute(QtCore.Qt.WA_MacNoShadow) self.filter = self.ApplicationEventFilter(self) QtGui.QApplication.instance().installEventFilter(self.filter) self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint) self.__state = None # pinned or windowed self.__anchor_side = None # which side the anchor is currently pinned on self.__content_layout = None # layout whose margin will be set to contain the anchor self.__mouse_down_pos = None # track position when dragging self.__mouse_down_global = None # track global position when dragging # setup the anchor self.__bottom_anchor = QtGui.QPixmap(":/tk-desktop/anchor_arrow.png") self.__top_anchor = self.__bottom_anchor.transformed( QtGui.QTransform(1, 0, 0, -1, 0, 0)) self.__right_anchor = self.__bottom_anchor.transformed( QtGui.QTransform(0, 1, 1, 0, 0, 0)) self.__left_anchor = self.__bottom_anchor.transformed( QtGui.QTransform(0, 1, -1, 0, 0, 0)) # radius for rounded corners self.__corner_radius = 4 # widgets that will trigger the drag to move behavior self.__drag_widgets = [] # create the system tray icon self.systray = ShotgunSystemTrayIcon(self) self.systray.show() # hook up handler for when the systray is clicked self.systray.clicked.connect(self.systray_clicked)
def show_dialog(app): """ Show the main loader dialog :param app: The parent App """ # defer imports so that the app works gracefully in batch modes from .dialog import AppDialog # Create and display the splash screen splash_pix = QtGui.QPixmap(":/res/splash.png") splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) splash.show() QtCore.QCoreApplication.processEvents() # create the action manager for the Loader UI: from .loader_action_manager import LoaderActionManager action_manager = LoaderActionManager() # start ui ui_title = app.get_setting("title_name") w = app.engine.show_dialog(ui_title, app, AppDialog, action_manager) # Keep pointer to dialog so as to be able to hide/show it in actions engine_name = app.engine.instance_name # attach splash screen to the main window to help GC w.__splash_screen = splash # hide splash screen after loader UI show splash.finish(w.window()) # pop up help screen if w.is_first_launch(): # wait a bit before show window QtCore.QTimer.singleShot(1400, w.show_help_popup)
def __init__(self, display_widget, parent=None): """ Initialize the widget. :param display_widget: The ``DISPLAY`` widget instance :type display_widget: :class:`~PySide.QtGui.QWidget` :param parent: The parent widget or ``None`` :type parent: :class:`~PySide.QtGui.QWidget` """ super(ShotgunFieldNotEditable, self).__init__(parent) self._display_widget = display_widget # this is the "no edit" label that will show on hover self._no_edit_lbl = QtGui.QLabel(self) self._no_edit_lbl.setPixmap( QtGui.QPixmap(":/qtwidgets-shotgun-fields/not_editable.png") ) self._no_edit_lbl.setFixedSize(QtCore.QSize(16, 16)) self._no_edit_lbl.hide() spacer = QtGui.QWidget() spacer.setFixedHeight(self._no_edit_lbl.height()) spacer.setFixedWidth(4) layout = QtGui.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(display_widget) layout.addWidget(spacer) layout.addWidget(self._no_edit_lbl) layout.addStretch(10) self.installEventFilter(self) # forward the display widget's value changed signal self._display_widget.value_changed.connect(self.value_changed.emit)
def populateUI(self, widget, exportTemplate): # prior to 10.5v1, this method created the layout. in 10.5v1 and later, # the widget already has a layout if self.app.get_nuke_version_tuple() >= (10, 5, 1): layout = widget.layout() else: # create a layout with custom top and bottom widgets layout = QtGui.QVBoxLayout(widget) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(9) top = QtGui.QWidget() top_layout = QtGui.QVBoxLayout() top_layout.setContentsMargins(9, 0, 9, 0) create_version_checkbox = QtGui.QCheckBox("Create SG Version", widget) create_version_checkbox.setToolTip( "Create a Version in SG for this transcode.\n\n" "If the output format is not a quicktime, then\n" "a quicktime will be created. The quicktime will\n" "be uploaded to SG as Screening Room media." ) create_version_checkbox.setCheckState(QtCore.Qt.Checked) if not self._preset._properties.get("create_version", True): create_version_checkbox.setCheckState(QtCore.Qt.Unchecked) create_version_checkbox.stateChanged.connect(self.create_version_changed) top_layout.addWidget(create_version_checkbox) top.setLayout(top_layout) middle = QtGui.QWidget() # prior to 10.5v1, the layout was set in the base class. in 10.5v1, the # base class expects the widget to already have a layout. if self.app.get_nuke_version_tuple() >= (10, 5, 1): middle.setLayout(QtGui.QVBoxLayout()) # populate the middle with the standard layout FnTranscodeExporterUI.TranscodeExporterUI.populateUI( self, middle, exportTemplate ) layout.addWidget(top) layout.addWidget(middle) # Handle any custom widget work the user did via the custom_export_ui # hook. custom_widget = self._get_custom_widget( parent=widget, create_method="create_transcode_exporter_widget", get_method="get_transcode_exporter_ui_properties", set_method="set_transcode_exporter_ui_properties", ) if custom_widget is not None: layout.addWidget(custom_widget)
def create_round_thumbnail(image): """ Create a 200 px wide circle thumbnail :param image: QImage representing a thumbnail :returns: Round QPixmap """ CANVAS_SIZE = 200 # get the 512 base image base_image = QtGui.QPixmap(CANVAS_SIZE, CANVAS_SIZE) base_image.fill(QtCore.Qt.transparent) # now attempt to load the image # pixmap will be a null pixmap if load fails thumb = QtGui.QPixmap.fromImage(image) if not thumb.isNull(): # scale it down to fit inside a frame of maximum 512x512 thumb_scaled = thumb.scaled( CANVAS_SIZE, CANVAS_SIZE, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation, ) # now composite the thumbnail on top of the base image # bottom align it to make it look nice thumb_img = thumb_scaled.toImage() brush = QtGui.QBrush(thumb_img) painter = QtGui.QPainter(base_image) painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.setBrush(brush) painter.drawEllipse(0, 0, CANVAS_SIZE, CANVAS_SIZE) painter.end() return base_image
def __create_tank_disabled_menu(details): """ Creates a std "disabled" shotgun menu """ from sgtk.platform.qt import QtGui if Configuration.get("KATANA_UI_MODE"): sg_menu = MenuGenerator.get_or_create_root_menu("Shotgun") if sg_menu is not None: sg_menu.clear() cmd = lambda d=details: __show_tank_disabled_message(d) action = QtGui.QAction("Toolkit is disabled", sg_menu, triggered=cmd) sg_menu.addAction(action) else: print("The Shotgun Pipeline Toolkit is disabled: %s" % details)
def open_attachments(self): """ Sets the attachments editor into its "open mode" which will allow the user to attach files to the note. """ self.ui.attachment_list_tree.clear() for file_path in self._attachments: self.ui.attachment_list_tree.addTopLevelItem( QtGui.QTreeWidgetItem([file_path])) self.ui.stacked_widget.setCurrentIndex(self._ATTACHMENTS_WIDGET_INDEX) self._adjust_ui() self._add_attachments()
def show_success(self): """ Shows standard "publish completed successfully!" prompt """ self.ui.icon.setPixmap( QtGui.QPixmap(":/tk_multi_publish2/publish_complete.png") ) self.ui.label.setText("Publish\nComplete") self.ui.info.setText("For more details, <b><u>click here</u></b>.") self.ui.publish_again.setText("To publish again, <b><u>click here</u></b>.") self.ui.publish_again.show() self.show()
def _clear_model(self, add_loading_item=True): """ Clears the current data in the model. :param add_loading_item: if true, a "loading please wait" item will be added. """ # clear model self._model.clear() if add_loading_item: item = QtGui.QStandardItem("Loading data...") item.setData(self.MODE_LOADING, self.MODE_ROLE) self._model.appendRow(item)
def _populate_default_thumbnail(self, item): """ Called whenever an item needs to get a default thumbnail attached to a node. When thumbnails are loaded, this will be called first, when an object is either created from scratch or when it has been loaded from a cache, then later on a call to _populate_thumbnail will follow where the subclassing implementation can populate the real image. """ # set up publishes with a "thumbnail loading" icon item.setData(self._loading_icon, SgPublishHistoryModel.PUBLISH_THUMB_ROLE) thumb = utils.create_overlayed_user_publish_thumbnail( item.data(SgPublishHistoryModel.PUBLISH_THUMB_ROLE), None) item.setIcon(QtGui.QIcon(thumb))
def __init__(self, parent, bg_task_manager): """ Constructor """ # folder icon self._loading_icon = QtGui.QPixmap(":/res/loading_100x100.png") app = sgtk.platform.current_bundle() ShotgunModel.__init__( self, parent, download_thumbs=app.get_setting("download_thumbnails"), schema_generation=2, bg_load_thumbs=True, bg_task_manager=bg_task_manager)
def _clear_model(self, add_loading_item=True): """ Clears the current data in the model. :param add_loading_item: if true, a "loading please wait" item will be added. """ # clear model self._model.clear() if add_loading_item: item = QtGui.QStandardItem("Hold on, loading...") item.setData(None, self._SG_DATA_ROLE) self._model.appendRow(item)
def __init__(self, parent, settings): """ :param parent: Parent widget. :param settings: Settings object to persist and restore state. """ super(CommandPanel, self).__init__(parent) # The app style sheet styles this widget so give it the proper name. self.setObjectName("command_panel") self._layout = QtGui.QVBoxLayout(self) self._layout.setContentsMargins(0, 10, 0, 0) self._layout.addStretch(1) self.setLayout(self._layout) # We want the background color to apply to the entire surface of the widget # in PySide instead of just under its children self.setAttribute(QtCore.Qt.WA_StyledBackground, True) self.setMouseTracking(True) self.setFocusPolicy(QtCore.Qt.NoFocus) self.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Preferred) filter = ResizeEventFilter(parent) filter.resized.connect(self._on_parent_resized) parent.installEventFilter(filter) self.command_triggered.connect(self._update_recents_list) # Settings object allowing to read and write settings. self._settings = settings # The widget for the recently launched command. Will be None if # the recent list is disabled or if there are no recent commands. self._recents_widget = None # Dictionary of the commands that were executed recently. # Follows this structure: # self._recents = { # 'launch_nuke': { # 'timestamp': datetime.datetime(2016, 5, 20, 21, 48, 17, 495234), # 'added': False}, # ... # } self._recents = {} # Keeps track of all the command information so we can easily build the recent # command list. self._command_info = {} # List of section names that the widget knows about. The sections # will be displayed in that order. self._section_names = [] # If True, the recent list will be displayed. self._show_recents = False # Keeps a reference to scroll view that owns this widget. self._scroll_view_owner = parent
def __init__(self, view): self.tray_view = view shotgun_view.WidgetDelegate.__init__(self, view) self.__selection_model = view.selectionModel() self._pen = QtGui.QPen(QtCore.Qt.white, 1, QtCore.Qt.SolidLine) self._ORIGINAL_THUMBNAIL = QtCore.Qt.UserRole + 1702 self._FILTER_THUMBNAIL = QtCore.Qt.UserRole + 1703 self._PINNED_THUMBNAIL = QtCore.Qt.UserRole + 1704 # pinned icon try: f = os.path.join(os.path.dirname(os.path.abspath(__file__)), "review_app_pinned.png") self.pin_pixmap = QtGui.QPixmap(f) f2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ae.jpeg") self.missing_pixmap = QtGui.QPixmap(f2) except Exception as e: print "ERROR: cant load pin %r" % e
def setup_ui(self, page_id): BasePage.setup_ui(self, page_id) # Setup buttongroup by hand since in PySide it breaks the ui compilation wiz = self.wizard() self._config_button_group = QtGui.QButtonGroup(self) self._config_button_group.addButton(wiz.ui.select_default_config, self.DEFAULT_ID) self._config_button_group.addButton(wiz.ui.select_multiroot_config, self.MULTIROOT_ID) self._config_button_group.addButton(wiz.ui.select_games_config, self.GAMES_ID) self._config_button_group.addButton(wiz.ui.select_flame_config, self.FLAME_ID)
def show_no_items_error(self): """ Shows a special message when there is no items collected under an alternate UI operation determined by the 'enable_manual_load' application option. """ self.ui.icon.setPixmap( QtGui.QPixmap(":/tk_multi_publish2/publish_failed.png")) # Hardcoding line break so the message displays on 2 lines. # Usage of label's own word wrap displays the message below on 3 lines. # NOTE: Can't manually break line when using <p></p> self.ui.label.setText("Could not find any\nitems to publish.") self.ui.info.setText("For more details, <b><u>click here</u></b>.") self.ui.publish_again.hide() self.show()
def _upload_image(self): """ Display a file browser and process the selected file path. """ file_path = QtGui.QFileDialog.getOpenFileName( self, caption="Replace Image", options=QtGui.QFileDialog.DontResolveSymlinks)[0] if file_path: self.setPixmap(QtGui.QPixmap(file_path)) self._image_path = file_path self._value = file_path self.value_changed.emit()
def __init__(self): # loading a pixmap self.loading = create_rectangular_thumbnail( QtGui.QPixmap(":/tk_framework_qtwidgets.global_search_widget/loading.png") ) # more typing required self.keyboard = create_rectangular_thumbnail( QtGui.QPixmap(":/tk_framework_qtwidgets.global_search_widget/keyboard.png") ) # no matches found self.no_matches = create_rectangular_thumbnail( QtGui.QPixmap(":/tk_framework_qtwidgets.global_search_widget/no_match.png") ) # no thumbnail for the entity self.no_thumbnail = create_rectangular_thumbnail( QtGui.QPixmap( ":/tk_framework_qtwidgets.global_search_widget/no_thumbnail.png" ) )
def _get_item_thumbnail(item): """ Return the thumbnail data for item. :param item: The model item :type item: QStandardItem """ thumbnail = item.data(QtCore.Qt.DecorationRole) if thumbnail is None: thumbnail = QtGui.QPixmap() return thumbnail
def __init__(self, parent=None): """ Initialize the info widget. :param parent: The widget's parent. """ super(_PythonInputInfoWidget, self).__init__(parent) self._column_lbl = QtGui.QLabel() layout = QtGui.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addStretch() layout.addWidget(self._column_lbl) self._text_grey = colorize( self.palette().window().color(), 1, self.palette().windowText().color(), 1, ).name()
def __init__(self, parent=None): super(ScribbleArea, self).__init__(parent) self.setAttribute(QtCore.Qt.WA_StaticContents) self.modified = False self.scribbling = False self.myPenWidth = 3 self.myPenColor = QtCore.Qt.red imageSize = QtCore.QSize(500, 500) self.image = QtGui.QImage(imageSize, QtGui.QImage.Format_RGB32) self.lastPoint = QtCore.QPoint()
def __init__(self, layout, text, editor): """ :param layout: Layout to add the widget into. :param text: Text on the left of the editor widget. :param editor: Widget used to edit the value. """ super(WidgetHandler, self).__init__(editor) self._layout = QtGui.QHBoxLayout() self._check_box = QtGui.QCheckBox(text) self._label = QtGui.QLabel(text) # FIXME: Should take the size of the text + icon as the minimum width. self._check_box.setMinimumWidth(50) self._label.setMinimumWidth(50) self._check_box.stateChanged.connect(self._on_state_changed) self._layout.addWidget(self._check_box) self._layout.addWidget(self._label) self._layout.addWidget(self.editor) layout.addRow(self._layout)
def __init__(self, parent, overlay_widget, publish_type_model): """ Model which represents the latest publishes for an entity """ self._publish_type_model = publish_type_model self._no_pubs_found_icon = QtGui.QPixmap( ":/res/no_publishes_found.png") self._folder_icon = QtGui.QIcon( QtGui.QPixmap(":/res/folder_512x400.png")) self._loading_icon = QtGui.QIcon( QtGui.QPixmap(":/res/loading_512x400.png")) self._associated_items = {} app = sgtk.platform.current_bundle() # init base class ShotgunOverlayModel.__init__( self, parent, overlay_widget, download_thumbs=app.get_setting("download_thumbnails"), schema_generation=5)
def show_loading(self): """ Shows standard "loading stuff" prompt """ self.ui.icon.setPixmap( QtGui.QPixmap(":/tk_multi_publish2/overlay_loading.png") ) self.ui.label.setText("Loading and processing") self.ui.info.setText("Hold tight while we analyze your data") self.ui.publish_again.hide() self.ui.publish_again.setText("") self.show()
def addAction(self, action_definition): """ Adds an action to the context menu. Action definitions passed in must take the following form: dict( callback=callable, text=str, required_selection="single" ) Where the callback is a callable object that expects to receive a list of Version entity dictionaries as returned by the Shotgun Python API. The text key contains the string labels of the action in the QMenu, and the required_selection is one of "single", "multi", or "either". Any action requiring a "single" selection will be enabled only if there is a single item selected in the Version list view, those requiring "multi" selection require 2 or more selected items, and the "either" requirement results in the action being enabled if one or more items are selected. :param action_definition: The action defition to add to the menu. This takes the form of a dictionary of a structure described in the method docs above. :type action_definition: dict :returns: :class:`QtGui.QAction` """ action = QtGui.QAction(action_definition.get("text"), self) num_selected = len(self._selected_entities) required_selection = action_definition.get("required_selection") # Now we can enable or disable the action according to # how many items have been reported as being selected. if not num_selected: action.setEnabled(False) elif required_selection == "single": action.setEnabled((num_selected == 1)) elif required_selection == "multi": action.setEnabled((num_selected > 1)) elif required_selection == "either": action.setEnabled(True) else: # This shouldn't ever happen. action.setEnabled(False) self._actions[action] = action_definition return super(SelectionContextMenu, self).addAction(action)
def show_fail(self): """ Shows standard "publish failed!" prompt """ self.ui.icon.setPixmap( QtGui.QPixmap(":/tk_multi_publish2/publish_failed.png") ) self.ui.label.setText("Publish\nFailed!") self.ui.info.setText("For more details, <b><u>click here</u></b>.") self.ui.publish_again.hide() self.ui.publish_again.setText("") self.show()
def setup_ui(self, page_id): BasePage.setup_ui(self, page_id) # Setup buttongroup by hand since in PySide it breaks the ui compilation wiz = self.wizard() self._config_type_button_group = QtGui.QButtonGroup(self) self._config_type_button_group.addButton(wiz.ui.select_standard, self.STANDARD_ID) self._config_type_button_group.addButton(wiz.ui.select_project, self.PROJECT_ID) self._config_type_button_group.addButton(wiz.ui.select_github, self.GITHUB_ID) self._config_type_button_group.addButton(wiz.ui.select_disk, self.DISK_ID)
def _get_default_detail_actions(self, sg_data): """ Returns a list of default actions for the detail area :param sg_data: Shotgun data directory """ refresh = QtGui.QAction("Refresh", None) refresh.triggered[()].connect(lambda f=sg_data: self._refresh(f)) view_in_sg = QtGui.QAction("View in Shotgun", None) view_in_sg.triggered[()].connect(lambda f=sg_data: self._show_in_sg(f)) copy_url = QtGui.QAction("Copy Shotgun url to clipboard", None) copy_url.triggered[( )].connect(lambda f=sg_data: self._copy_to_clipboard(f)) show_docs = QtGui.QAction("Documentation", None) show_docs.triggered[()].connect(self._show_docs) separator = QtGui.QAction(None) separator.setSeparator(True) return [refresh, view_in_sg, copy_url, show_docs, separator]
def _clear_model(self, add_loading_item=True, add_more_text_item=False): """ Clears the current data in the model. :param add_loading_item: if true, a "loading please wait" item will be added. :param add_more_text_item: if true, a "type at least 3 characers..." item will be added. """ # clear model self.model().clear() if add_loading_item: item = QtGui.QStandardItem("Loading search results...") item.setData(self.MODE_LOADING, self.MODE_ROLE) self.model().appendRow(item) item.setIcon(QtGui.QIcon(self._pixmaps.loading)) if add_more_text_item: item = QtGui.QStandardItem("Type at least %s characters..." % (self.COMPLETE_MINIMUM_CHARACTERS, )) item.setData(self.MODE_NOT_ENOUGH_TEXT, self.MODE_ROLE) item.setIcon(QtGui.QIcon(self._pixmaps.keyboard)) self.model().appendRow(item)