예제 #1
0
    def createMenus(self):

        self.saveAsMenu = QtGui.QMenu("&Save As", self)
        for action in self.saveAsActs:
            self.saveAsMenu.addAction(action)

        fileMenu = QtGui.QMenu("&File", self)
        #fileMenu.addAction(self.openAct)
        #fileMenu.addMenu(self.saveAsMenu)
        #fileMenu.addAction(self.printAct)
        fileMenu.addAction(self.saveOverAct)
        fileMenu.addSeparator()
        fileMenu.addAction(self.exitAct)

        optionMenu = QtGui.QMenu("&Options", self)
        optionMenu.addAction(self.penColorAct)
        optionMenu.addAction(self.penWidthAct)
        #
        optionMenu.addSeparator()
        #optionMenu.addAction(self.clearScreenAct)

        helpMenu = QtGui.QMenu("&Help", self)
        helpMenu.addAction(self.aboutAct)
        #helpMenu.addAction(self.aboutQtAct)

        self.menuBar().addMenu(fileMenu)
        self.menuBar().addMenu(optionMenu)
        self.menuBar().addMenu(helpMenu)
예제 #2
0
    def __init__(self, parent=None):
        """
        Construction

        :param parent: The parent widget
        """
        QtGui.QWidget.__init__(self, parent)

        self._thumbnail = True
        self._sg_fields = []

        # compute hilight colors
        p = QtGui.QPalette()
        highlight_col = p.color(QtGui.QPalette.Active, QtGui.QPalette.Highlight)
        self._highlight_str = "rgb(%s, %s, %s)" % (
            highlight_col.red(),
            highlight_col.green(),
            highlight_col.blue(),
        )
        self._transp_highlight_str = "rgba(%s, %s, %s, 25%%)" % (
            highlight_col.red(),
            highlight_col.green(),
            highlight_col.blue(),
        )

        self._menu = QtGui.QMenu()
        self._actions = []
예제 #3
0
    def _show_filters(self, UI_filters_action):
        """
        Initialized filter menu and selected default action or previous action

        :param UI_filters_action: previous selected filter
        """
        filters_menu = QtGui.QMenu()
        filters_group = QtGui.QActionGroup(self)
        project_filter = QtGui.QAction('Current Project Tasks', filters_menu,
                                       checkable=True)
        project_filter.setData([['project', 'is', '{context.project}']])
        filters_group.addAction(project_filter)
        filters_menu.addAction(project_filter)
        all_filter = QtGui.QAction('All Tasks', filters_menu,
                                   checkable=True)
        all_filter.setData([])
        filters_group.addAction(all_filter)
        filters_menu.addAction(all_filter)
        facility_filter = QtGui.QAction('Facility Tasks', filters_menu,
                                        checkable=True)
        facility_filter.setData([['project.Project.name', 'is', 'Facility']])
        filters_group.addAction(facility_filter)
        filters_menu.addAction(facility_filter)
        if UI_filters_action:
            for filter_action in filters_menu.findChildren(QtGui.QAction):
                if filter_action.text() == UI_filters_action.text():
                    filter_action.setChecked(True)
        else:
            project_filter.setChecked(True)
        self._ui.filter_btn.setMenu(filters_menu)
        filters_group.triggered.connect(self._on_filter_changed)
예제 #4
0
def create_sgtk_disabled_menu(menu_name):
    """
    Render a special "shotgun is disabled" menu
    """
    win = Krita.instance().window().qwindow()

    # Find the shotgun menu
    menuBar = win.menuBar()
    sg_menu = None
    for action in menuBar.actions():
        if action.objectName == "shotgun":
            sg_menu = action.menu()
            break

    if sg_menu:
        # Clear all the actions before adding our item
        sg_menu.clear()
    else:
        # we need to create a new shotgun menu
        sg_menu = QtGui.QMenu("Shotgun", menuBar)
        sg_menu.setObjectName("shotgun")
        menu_action = menuBar.addMenu(sg_menu)
        menu_action.setObjectName("shotgun")

    # add the disabled action to our menu
    disabled_action = QtGui.QAction("Sgtk is disabled.")
    disabled_action.triggered.connect(sgtk_disabled_message)
    disabled_action.setObjectName("shotgun_disabled")
    def __init__(self, parent):
        """
        Constructor
        
        :param parent: QT parent object
        """
        QtGui.QWidget.__init__(self, parent)

        # make sure this widget isn't shown
        self.setVisible(False)
        
        # set up the UI
        self.ui = Ui_PublishHistoryWidget() 
        self.ui.setupUi(self)
        
        # set up action menu
        self._menu = QtGui.QMenu()   
        self._actions = []             
        self.ui.button.setMenu(self._menu)
        self.ui.button.setVisible(False)
        
        # compute hilight colors
        p = QtGui.QPalette()
        highlight_col = p.color(QtGui.QPalette.Active, QtGui.QPalette.Highlight)
        self._highlight_str = "rgb(%s, %s, %s)" % (highlight_col.red(), 
                                                   highlight_col.green(), 
                                                   highlight_col.blue())
        self._transp_highlight_str = "rgba(%s, %s, %s, 25%%)" % (highlight_col.red(), 
                                                                 highlight_col.green(), 
                                                                 highlight_col.blue())
예제 #6
0
    def _on_selected_file_changed(self, file, env):
        """
        """
        # get the available actions for this file:
        file_actions = self._get_available_file_actions(file, env)

        if not file_actions:
            # disable both the open and open options buttons:
            self._ui.open_btn.setEnabled(False)
            self._ui.open_options_btn.setEnabled(False)
            self._default_open_action = None
            return

        # update the open button:
        self._ui.open_btn.setEnabled(True)
        self._ui.open_btn.setText(file_actions[0].label)
        self._default_open_action = file_actions[0]

        # if we have more than one action then update the open options button:
        if len(file_actions) > 1:
            # enable the button:
            self._ui.open_options_btn.setEnabled(True)

            # build the menu and add the actions to it:
            menu = self._ui.open_options_btn.menu()
            if not menu:
                menu = QtGui.QMenu(self._ui.open_options_btn)
                self._ui.open_options_btn.setMenu(menu)
            menu.clear()
            self._populate_open_menu(menu, file_actions[1:])
        else:
            # just disable the button:
            self._ui.open_options_btn.setEnabled(False)
예제 #7
0
    def create_shotgun_menu(self):
        """
        Creates the main shotgun menu in Krita.
        Note that this only creates the menu, not the child actions.

        :return: bool
        """
        window = self._kritaInstance.window().qwindow()
        menuBar = window.menuBar()
        # only create the shotgun menu if not in batch mode and menu doesn't already exist
        if self.has_ui and not self._has_menu():
            menu = QtGui.QMenu("Shotgun", window.menuBar())
            menu.setObjectName("shotgun")

            menu_action = menuBar.addMenu(menu)
            menu_action.setObjectName("shotgun")

            #tk_krita = self.import_module("tk_krita")
            #self._menu_generator = tk_maya.MenuGenerator(self, self._menu_handle)
            ## hook things up so that the menu is created every time it is clicked
            #self._menu_handle.postMenuCommand(self._menu_generator.create_menu)

            ## Restore the persisted Shotgun app panels.
            #tk_maya.panel_generation.restore_panels(self)
            return True

        return False
    def __init__(self, widget_factory, parent):
        """
        :param widget_factory: Qt Designer-generated widget factory.
        :param parent: Parent widget
        """
        QtGui.QWidget.__init__(self, parent)

        # make sure this widget isn't shown
        self.setVisible(False)

        # set up the UI
        self.ui = widget_factory()
        self.ui.setupUi(self)

        # set up action menu
        self._menu = QtGui.QMenu()
        self._actions = []
        self.ui.button.setMenu(self._menu)
        self.ui.button.setVisible(False)

        # compute highlight colors
        highlight_col = self.palette().highlight().color()
        self._highlight_str = "rgb(%s, %s, %s)" % (
            highlight_col.red(),
            highlight_col.green(),
            highlight_col.blue(),
        )
        self._transp_highlight_str = "rgba(%s, %s, %s, 25%%)" % (
            highlight_col.red(),
            highlight_col.green(),
            highlight_col.blue(),
        )
예제 #9
0
    def _parse_options_x_app(self, groups, favourites, sort_options=True):
        parsed_options = []

        for (app_name, app_display_name), options in groups.items():
            first_option = options[0]
            caption = first_option[0]
            callback = first_option[1]
            options_number = len(options)

            if options_number <= 0:
                continue

            if options_number == 1 and (app_name, caption) not in favourites:
                is_submenu = False
                data = caption, callback
                label = caption
            elif options_number > 1:
                is_submenu = True
                label = app_display_name

                data = QtGui.QMenu()
                data.setTitle(app_display_name)
                for caption, callback in options:
                    data.addAction(caption, callback)

            parsed_options.append((label, is_submenu, data))

        if sort_options:
            parsed_options.sort(key=lambda option: option[0])

        return parsed_options
예제 #10
0
    def __init__(self, parent):
        """
        Constructor
        
        :param parent: QT parent object
        """
        QtGui.QWidget.__init__(self, parent)

        # make sure this widget isn't shown
        self.setVisible(False)
        
        # set up the UI
        self.ui = Ui_ListItemWidget() 
        self.ui.setupUi(self)
        
        # the property stylesheet syntax seems brittle and hacky so 
        # keeping the style sheet modifications local here rather
        # than in global css
        
        # todo: figure out a better way to do this!

        self._css_decorated = """
            #box { border-width: 2px; 
                   border-radius: 4px;
                   border-color: rgb(48, 167, 227); 
                   border-style: solid;
            }
            """
        
        self._css_selected = """
            #box { border-width: 2px; 
                   border-radius: 4px;
                   border-color: rgb(48, 167, 227); 
                   border-style: solid; 
                   background-color: rgba(48, 167, 227, 25%);
            }        
            """                                    

        self._no_style = """
            #box { border-width: 2px; 
                   border-radius: 4px;
                   border-color: rgba(0, 0, 0, 0%); 
                   border-style: solid; 
            }        
            """

        # set up action menu. parent it to the button to prevent cases where it
        # shows up elsewhere on screen (as in Houdini)
        self._menu = QtGui.QMenu(self.ui.button)
        self._actions = []
        self.ui.button.setMenu(self._menu)
        self.ui.button.setVisible(False)
                                  
        # this forces the menu to be right aligned with the button. This is
        # preferable since many DCCs show the embed panel on the far right.  In
        # houdini at least, before forcing this layout direction, the menu was
        # showing up partially offscreen.
        self.ui.button.setLayoutDirection(QtCore.Qt.RightToLeft)
    def mousePressEvent (self, event ):
        if event.button() == QtCore.Qt.LeftButton:
            if QtGui.QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier :
                print "add to selection", self.notification
            elif QtGui.QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier :
                print "next"
                self.myfinished()
            else :
                print "select", self.notification

        if event.button() == QtCore.Qt.RightButton:
            globalPos = self.mapToGlobal(event.pos());
            menu = QtGui.QMenu()
            
            ag = QtGui.QActionGroup(menu, exclusive=True)
            docAction =  QtGui.QAction("Show news",  menu , triggered=lambda: self.radioButtonClicked(0)) 
            docAction.setCheckable( True )
            if self.radioChecked == 0 :
                docAction.setChecked( True )


            a = ag.addAction(docAction)
            menu.addAction(a)
            notiAction =  QtGui.QAction("Show notification",  menu , triggered=lambda: self.radioButtonClicked(1)) 
            notiAction.setCheckable( True )
            if self.radioChecked == 1 :
                notiAction.setChecked( True )
            a = ag.addAction(notiAction)
            menu.addAction(a)


            muteAction =  QtGui.QAction("Mute",  menu ,  triggered = lambda: self.radioButtonClicked(2) ) 
            muteAction.setCheckable( True )
            if self.radioChecked == 2 :
                muteAction.setChecked( True )
            a = ag.addAction(muteAction)
            menu.addAction(a)


            """
            notificationMenu = menu.addAction(QtGui.QIcon(getRessources("notification.png")),"Notify somebody",  self.writeNotification  ) 
            menu.addAction(notificationMenu)
            """

            #menu.addAction( QtGui.QAction("Remove", menu) )
            #menu.addAction( QtGui.QAction("Answer", menu) )
            #menu.addAction( QtGui.QAction("Status", menu) )
            self.animate.pause()
            menu.exec_(globalPos)
            if self.notificationList :   
                print "resume !"
                self.animate.resume()
            else :
                print self.animate.state()


            self.menu = menu
예제 #12
0
def create_qt_menu(name):
    """
    Helper function to create a Qt menu with the given name.

    :param name: The menu name.
    :returns: The menu created.
    :rtype: QtGui.QMenu
    """

    menu = QtGui.QMenu()
    menu.setTitle(name)
    return menu
예제 #13
0
    def _configure_widget(self, widget, item, style_options):
        # defaults if no children
        menu = None
        popup_mode = widget.DelayedPopup
        button_icon = item.data(QtCore.Qt.DecorationRole)
        button_tooltip = item.toolTip()

        # gather list of actions if the button has multiple commands
        children = ProjectCommandModel.get_item_children_in_order(item)
        first_child = True
        if children:
            # create the menu when we have children
            menu = QtGui.QMenu()
            for child in children:
                icon = child.data(QtCore.Qt.DecorationRole)
                menu_name = child.data(ProjectCommandModel.MENU_NAME_ROLE)
                if first_child:
                    button_icon = icon
                    button_tooltip = child.toolTip()
                    if len(children) > 1:
                        menu_name = "%s*" % menu_name

                action = menu.addAction(menu_name)
                action.setData({
                    "command": child.data(ProjectCommandModel.COMMAND_ROLE),
                    "button": child.data(ProjectCommandModel.BUTTON_NAME_ROLE),
                })
                action.setToolTip(child.toolTip())
                action.setIconVisibleInMenu(False)

                if icon is not None:
                    action.setIcon(icon)

                first_child = False

            widget.setMenu(menu)

            # setup the widget to handle the menu click
            popup_mode = widget.MenuButtonPopup
            menu.triggered.connect(self._handle_clicked)

        # update button
        widget.setMenu(menu)
        widget.setPopupMode(popup_mode)
        if button_icon is None:
            widget.setIcon(QtGui.QIcon())
        else:
            widget.setIcon(button_icon)
        widget.setToolTip(button_tooltip)
        widget.setText(" %s" % item.data(ProjectCommandModel.BUTTON_NAME_ROLE))

        widget.setIconSize(self.ICON_SIZE)
        widget.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
예제 #14
0
    def createMenus(self):
        self.fileMenu = QtGui.QMenu("&File", self)
        self.fileMenu.addAction(self.openAct)
        self.fileMenu.addAction(self.printAct)
        self.fileMenu.addSeparator()
        self.fileMenu.addAction(self.exitAct)

        self.viewMenu = QtGui.QMenu("&View", self)
        self.viewMenu.addAction(self.zoomInAct)
        self.viewMenu.addAction(self.zoomOutAct)
        self.viewMenu.addAction(self.normalSizeAct)
        self.viewMenu.addSeparator()
        self.viewMenu.addAction(self.fitToWindowAct)

        self.helpMenu = QtGui.QMenu("&Help", self)
        self.helpMenu.addAction(self.aboutAct)
        self.helpMenu.addAction(self.aboutQtAct)

        self.menuBar().addMenu(self.fileMenu)
        self.menuBar().addMenu(self.viewMenu)
        self.menuBar().addMenu(self.helpMenu)
예제 #15
0
    def __init__(self, parent):
        """
        Constructor
        
        :param parent: QT parent object
        """
        QtGui.QWidget.__init__(self, parent)

        # make sure this widget isn't shown
        self.setVisible(False)

        # set up the UI
        self.ui = Ui_ListItemWidget()
        self.ui.setupUi(self)

        # the property stylesheet syntax seems brittle and hacky so
        # keeping the style sheet modifications local here rather
        # than in global css

        # todo: figure out a better way to do this!

        self._css_decorated = """
            #box { border-width: 2px; 
                   border-radius: 4px;
                   border-color: rgb(48, 167, 227); 
                   border-style: solid;
            }
            """

        self._css_selected = """
            #box { border-width: 2px; 
                   border-radius: 4px;
                   border-color: rgb(48, 167, 227); 
                   border-style: solid; 
                   background-color: rgba(48, 167, 227, 25%);
            }        
            """

        self._no_style = """
            #box { border-width: 2px; 
                   border-radius: 4px;
                   border-color: rgba(0, 0, 0, 0%); 
                   border-style: solid; 
            }        
            """

        # set up action menu
        self._menu = QtGui.QMenu()
        self._actions = []
        self.ui.button.setMenu(self._menu)
        self.ui.button.setVisible(False)
예제 #16
0
    def _show_menu(self, view, index, pos):
        """
        Callback triggered from the ViewItemDelegate when Menu Button action is triggered.

        Create and show the actions menu.
        """

        menu = QtGui.QMenu(self)

        if isinstance(index.model(), BasicListItemModel):
            # NOTE: ShotgunDemoModel is not set up to handle setting loading state and separator data per item,
            # but it could be extended to achieve this functionality

            # Toggle showing loading indicator for this index
            toggle_loading_action = QtGui.QAction("Toggle Loading", self)
            toggle_loading_action.triggered.connect(
                lambda: index.model().toggle_data(
                    index, index.model().VIEW_ITEM_LOADING_ROLE
                )
            )
            # Toggle showing separator for this index
            toggle_separator_action = QtGui.QAction("Toggle Separator", self)
            toggle_separator_action.triggered.connect(
                lambda: index.model().toggle_data(
                    index, index.model().VIEW_ITEM_SEPARATOR_ROLE
                )
            )
            menu.addActions([toggle_loading_action, toggle_separator_action])

        # Non-index specific actions
        # Toggle showing loading indactors for all items
        toggle_all_loading_action = QtGui.QAction("Toggle All Loading", self)
        toggle_all_loading_action.triggered.connect(
            lambda: index.model().toggle_data(
                None, index.model().VIEW_ITEM_LOADING_ROLE
            )
        )
        # Toggle showing separators for all items
        toggle_all_separator_action = QtGui.QAction("Toggle All Separators", self)
        toggle_all_separator_action.triggered.connect(
            lambda: index.model().toggle_data(
                None, index.model().VIEW_ITEM_SEPARATOR_ROLE
            )
        )
        menu.addActions([toggle_all_loading_action, toggle_all_separator_action])

        # Show the menu at the given position relative to the view widget
        menu_pos = view.mapToGlobal(pos)
        menu.exec_(menu_pos)
예제 #17
0
            def addAction(self, action):
                """
                Override the addAction method to create a QMenu object here, that will hold
                any button menu actions. Normally, the QMenu object would be created on show,
                in the C++ source QToolButton::popupTimerDone(), but since we've monkey patched
                the QMenu object, we need to create it on the Python side to make sure we use our
                QMenuPatch object instead of QMenu.
                :param action: The QAction object to add to our QToolButton menu.
                """

                if self.menu() is None:
                    self._patch_menu = QtGui.QMenu()
                    self.setMenu(self._patch_menu)

                self.menu().addAction(action)
예제 #18
0
    def __init__(self, parent, command_name, button_name, icon, tooltip):
        """
        :param parent: Parent widget.
        :param str command_name: Name of the default command to execute.
        :param str button_name: Name of the button.
        :param str icon: Path to the icon.
        :param str tooltip: Tooltip for the button.
        """
        super(CommandButton, self).__init__(parent)
        self.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                           QtGui.QSizePolicy.MinimumExpanding)
        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.setIconSize(ICON_SIZE)
        self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.setStyleSheet(BUTTON_STYLE)

        self.setText(" %s" % button_name)

        self._set_default(tooltip, icon)

        self._commands = []

        # This menu will implement the drop down behaviour of the tool button.
        self._menu = QtGui.QMenu(self)
        self._button_name = button_name
        # The data of an action contains the command name.
        self._menu.triggered.connect(
            # The .data method returns a unicode string in Python 2, so force it to a utf8 str.
            lambda action: self.command_triggered.emit(
                six.ensure_str(action.data())))

        # This is a workaround for a PySide2 issue where the hover state of the button
        # is not properly cleared when the menu is dismissed or an action clicked.
        #
        # Inspired by this workaround:
        # https://forum.qt.io/topic/36348/solved-how-do-i-clear-hover-state-on-a-qgraphicswidget-wrapped-qtoolbutton
        def cleanup():
            self.setAttribute(
                QtCore.Qt.WA_UnderMouse,
                # Check if the cursor is still over the widget and set the under mouse
                # property appropriately.
                self.rect().contains(self.mapFromGlobal(QtGui.QCursor.pos())),
            )

        self._menu.aboutToHide.connect(cleanup)

        # Clicking on the button triggers the first action.
        self.clicked.connect(lambda: self._menu.actions()[0].trigger())
예제 #19
0
    def _show_filters(self, UI_filters_action):
        """
        Initialized filter menu and selected default action or previous action

        :param UI_filters_action: previous selected filter
        """
        filters_menu = QtGui.QMenu()
        filters_group = QtGui.QActionGroup(self)
        project_filter = QtGui.QAction('Current Project Tasks',
                                       filters_menu,
                                       checkable=True)
        project_filter.setData([['project', 'is', '{context.project}']])
        filters_group.addAction(project_filter)
        filters_menu.addAction(project_filter)
        #all_filter = QtGui.QAction('All Tasks', filters_menu,
        #                           checkable=True)
        #all_filter.setData([])
        #filters_group.addAction(all_filter)
        #filters_menu.addAction(all_filter)
        #facility_filter = QtGui.QAction('Facility Tasks', filters_menu,
        #                                checkable=True)
        #facility_filter.setData([['project.Project.name', 'is', 'Facility']])
        #filters_group.addAction(facility_filter)
        #filters_menu.addAction(facility_filter)

        self._app = sgtk.platform.current_bundle()
        sg = self._app.context.tank.shotgun
        project_list = sg.find("Project", [
            ['name', 'not_contains', '_'],
            ['sg_status', 'is', 'Active'],
            ['id', 'is_not', self._app.context.project['id']],
        ], ['name'])
        for project_ent in project_list:
            temp_filter = QtGui.QAction(project_ent['name'],
                                        filters_menu,
                                        checkable=True)
            temp_filter.setData([['project', 'is', project_ent]])
            filters_group.addAction(temp_filter)
            filters_menu.addAction(temp_filter)

        if UI_filters_action:
            for filter_action in filters_menu.findChildren(QtGui.QAction):
                if filter_action.text() == UI_filters_action.text():
                    filter_action.setChecked(True)
        else:
            project_filter.setChecked(True)
        self._ui.filter_btn.setMenu(filters_menu)
        filters_group.triggered.connect(self._on_filter_changed)
예제 #20
0
    def open_menu(self, position):
        """
        Context menu in my task tree

        :param position: where the time event is dropped
        """
        menu = QtGui.QMenu()
        addTimeAction = menu.addAction("New Time Log")
        action = menu.exec_(self.task_tree.viewport().mapToGlobal(position))
        if action == addTimeAction:
            task = self._get_selected_task()
            time = timelogEvent("Custom Time", date.today(), timedelta(-1))
            if task:
                timelog_dl = NewTimeLogForm(time, task, parent=self.parent)
                timelog_dl.exec_()
                logger.debug("New timelog submitted to Shotgun")
예제 #21
0
    def create(self):
        """
        Render the entire Shotgun menu.
        """

        self._engine.logger.debug("Creating Shotgun Menu")

        # Destroy root menu if exists
        if self.exists:
            self.destroy()

        # Create root menu
        window = self._engine.get_vred_main_window()
        menubar = window.menuBar()
        root_menu = QtGui.QMenu()
        root_menu.setTitle(self.ROOT_MENU_TEXT)

        # Get all options and sort them
        options = [(caption, data)
                   for caption, data in self._engine.commands.items()]
        if options:
            options.sort(key=lambda option: option[0])

        # Context submenu
        root_menu.addMenu(self._create_context_submenu(options))
        root_menu.addSeparator()

        # Favourites
        favourites = self._create_favourites(options)
        [
            root_menu.addAction(caption, callback)
            for caption, callback in favourites
        ]
        if favourites:
            root_menu.addSeparator()

        # Apps
        apps = self._create_apps(options)
        for label, is_submenu, data in apps:
            if is_submenu:
                root_menu.addMenu(data)
            else:
                caption, callback = data
                root_menu.addAction(caption, callback)

        actions = menubar.actions()
        menubar.insertMenu(actions[-1], root_menu)
    def createMenu(self):

        fileMenu = QtGui.QMenu()
        for a in self.values["files"][0]:
            fct = lambda a=a: self.launchFromPath(a)
            fileMenu.addAction(os.path.basename(a), fct)

        for m, files in self.values["files"][1].iteritems():
            fileNameMenu = fileMenu.addMenu(m)
            for path in files:
                fct = lambda path=path: self.launchFromPath(path)
                fileNameMenu.addAction(os.path.basename(path), fct)

        path = self.values["files"][2]
        fct = lambda path=path: self.launchFromContext(path)
        fileMenu.addAction("Empty Scene", fct)
        return fileMenu
예제 #23
0
    def _create_context_submenu(self, options):
        submenu = QtGui.QMenu()
        submenu.setTitle(self.context_name)

        submenu.addAction(self.JUMP_TO_SG_TEXT, self.jump_to_sg)
        submenu.addAction(self.JUMP_TO_FS_TEXT, self.jump_to_fs)
        submenu.addSeparator()

        filtered_options = [
            (caption, data) for caption, data in options
            if data.get("properties").get("type") == "context_menu"
        ]

        for caption, data in filtered_options:
            callback = data.get("callback")
            submenu.addAction(caption, callback)

        return submenu
예제 #24
0
    def _show_context_menu(self, pos):

        item = self.itemAt(pos)
        row = self.row(item)
        if row >= self.count() - 1:
            return

        menu = QtGui.QMenu()
        menu.addAction(
            QtGui.QIcon(res.get_path('preview.png')),
            'preview',
            partial(self._preview_item_at, pos),
        )
        menu.addAction(
            QtGui.QIcon(res.get_path('clear.png')),
            'remove',
            partial(self._remove_item_at, pos),
        )
        menu.exec_(self.mapToGlobal(pos))
    def _get_gists_action(self, parent):
        """
        Returns a ``QtGui.QAction`` for loading gists.

        The returned action is a menu action showing actions for each gist
        for the users defined in ``GITHUB_GIST_USERS``.

        :param parent: The ``QtGui.QObject`` to use as the action's parent
        """

        app = self.parent

        gists_menu = QtGui.QMenu("Gists", parent)

        icon = QtGui.QIcon(":/tk_multi_pythonconsole/github.png")
        gists_menu.setIcon(icon)

        for gist_user in GITHUB_GIST_USERS:

            if not gist_user in QUERIED_GISTS:
                # query gists for this user
                QUERIED_GISTS[gist_user] = get_gists(gist_user, app)

            gists = QUERIED_GISTS[gist_user]

            # no gists for this user, don't create a submenu
            if not gists:
                continue

            # construct a menu for this user
            gist_user_menu = gists_menu.addMenu(gist_user)

            for gist in gists:

                gist_action = QtGui.QAction(gist["file_name"], gist_user_menu)
                # PySide2 seems to pass the checked state through as an args instead of a kwarg
                # so we need to provide a kwarg for it to pass the check state without overriding the gist value.
                add_gist = lambda checked=False, g=gist: self._add_gist_tab(g)
                gist_action.triggered.connect(add_gist)
                gist_user_menu.addAction(gist_action)

        return gists_menu.menuAction()
예제 #26
0
    def _on_browser_context_menu_requested(self, file, env, pnt):
        """
        """
        if not file:
            return

        # get the file actions:
        file_actions = self._get_available_file_actions(file, env)
        if not file_actions:
            return

        # build the context menu:
        context_menu = QtGui.QMenu(self.sender())
        self._populate_open_menu(context_menu, file_actions[1:])

        # map the point to a global position:
        pnt = self.sender().mapToGlobal(pnt)

        # finally, show the context menu:
        context_menu.exec_(pnt)
    def _get_gists_action(self, parent):
        """
        Returns a ``QtGui.QAction`` for loading gists.

        The returned action is a menu action showing actions for each gist
        for the users defined in ``GITHUB_GIST_USERS``.

        :param parent: The ``QtGui.QObject`` to use as the action's parent
        """

        app = self.parent

        gists_menu = QtGui.QMenu("Gists", parent)

        icon = QtGui.QIcon(":/tk_multi_pythonconsole/github.png")
        gists_menu.setIcon(icon)

        for gist_user in GITHUB_GIST_USERS:

            if not gist_user in QUERIED_GISTS:
                # query gists for this user
                QUERIED_GISTS[gist_user] = get_gists(gist_user, app)

            gists = QUERIED_GISTS[gist_user]

            # no gists for this user, don't create a submenu
            if not gists:
                continue

            # construct a menu for this user
            gist_user_menu = gists_menu.addMenu(gist_user)

            for gist in gists:

                gist_action = QtGui.QAction(gist["file_name"], gist_user_menu)
                gist_action.triggered.connect(lambda g=gist: self._add_gist_tab(g))
                gist_user_menu.addAction(gist_action)

        return gists_menu.menuAction()
예제 #28
0
    def _on_popup_btn_click(self):
        """
        Display a context menu based on the current field value.
        """

        popup_menu = QtGui.QMenu()

        if self._value:
            link_type = self._value["link_type"]
        else:
            link_type = None

        if not link_type:
            # no link type, display options for each type
            popup_menu.addAction(self._upload_file_action)
            popup_menu.addAction(self._web_page_link_action)
            popup_menu.addAction(self._local_path_action)
        elif link_type == "upload":
            popup_menu.addAction(self._edit_upload_file_action)
            popup_menu.addAction(self._replace_with_web_page_link_action)
            popup_menu.addAction(self._replace_with_local_path_action)
            popup_menu.addAction(self._remove_link_action)
        elif link_type == "web":
            popup_menu.addAction(self._replace_with_upload_file_action)
            popup_menu.addAction(self._edit_web_page_link_action)
            popup_menu.addAction(self._replace_with_local_path_action)
            popup_menu.addAction(self._remove_link_action)
        elif link_type == "local":
            popup_menu.addAction(self._replace_with_upload_file_action)
            popup_menu.addAction(self._replace_with_web_page_link_action)
            popup_menu.addAction(self._edit_local_path_action)
            popup_menu.addAction(self._remove_link_action)

        # show the menu below the button
        popup_menu.exec_(
            self._popup_btn.mapToGlobal(
                QtCore.QPoint(0, self._popup_btn.height())
            )
        )
예제 #29
0
    def setup_widget(self):
        """
        Prepare the widget for display.

        Called by the metaclass during initialization.
        """
        self._pixmap = None
        self._image_path = None
        self._editable = False
        self._scaled_width = self.width()

        self.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)

        if self._delegate:
            # in delegate mode. that means this widget is being used to display
            # multiple entity's image fields. so setting up a data retriever to
            # download for a specific entity is pointless.
            self._needs_download = False
        else:
            self._needs_download = True

            # start up a data retriever to fetch the thumbnail in the background
            self._data_retriever = shotgun_data.ShotgunDataRetriever(
                bg_task_manager=self._bg_task_manager)
            self._data_retriever.start()
            self._data_retriever.work_completed.connect(self._on_worker_signal)
            self._data_retriever.work_failure.connect(self._on_worker_failure)

        self.setSizePolicy(QtGui.QSizePolicy.Expanding,
                           QtGui.QSizePolicy.Expanding)

        # menu display button for showing the popup menu
        self._popup_btn = QtGui.QPushButton(self)
        self._popup_btn.setIcon(
            QtGui.QIcon(":/qtwidgets-shotgun-fields/image_menu.png"))
        self._popup_btn.setFixedSize(QtCore.QSize(18, 12))
        self._popup_btn.hide()

        if not self._delegate:
            # not sure why, but when the widget is being used in a delegate,
            # this causes editor to close immediately when clicked.
            self._popup_btn.setFocusPolicy(QtCore.Qt.NoFocus)

        # make sure there's never a bg color or border
        self._popup_btn.setStyleSheet("background-color: none; border: none;")

        # actions
        self._clear_action = QtGui.QAction("Clear Thumbnail", self)
        self._clear_action.triggered.connect(self._clear_image)

        self._replace_action = QtGui.QAction("Replace Thumbnail", self)
        self._replace_action.triggered.connect(self._upload_image)

        self._view_action = QtGui.QAction("View Image", self)
        self._view_action.triggered.connect(self._show_image)

        self._upload_action = QtGui.QAction("Upload Thumbnail", self)
        self._upload_action.triggered.connect(self._upload_image)

        self._popup_edit_menu = QtGui.QMenu()
        self._popup_edit_menu.addAction(self._clear_action)
        self._popup_edit_menu.addAction(self._replace_action)
        self._popup_edit_menu.addAction(self._view_action)

        self._popup_display_menu = QtGui.QMenu()
        self._popup_display_menu.addAction(self._view_action)

        self._popup_upload_menu = QtGui.QMenu()
        self._popup_upload_menu.addAction(self._upload_action)

        self.installEventFilter(self)

        self._display_default()
        self._update_btn_position()

        # ---- connect signals

        self._popup_btn.clicked.connect(self._on_popup_btn_click)
        self.linkActivated.connect(self._on_link_activated)
예제 #30
0
    def __init__(self, parent=None):
        """
        Initialize the console.

        :param parent: The console's parent widget.
        """
        super(PythonConsoleWidget, self).__init__(parent)

        self.tabs = PythonTabWidget(self)

        # ---- output related buttons

        # clear output
        out_clear_btn = QtGui.QToolButton(self)
        out_clear_btn.setMinimumSize(QtCore.QSize(30, 30))
        out_clear_btn.setMaximumSize(QtCore.QSize(30, 30))
        out_clear_btn.setObjectName("out_clear_btn")
        out_clear_btn.setToolTip("Clear all output.")

        # echo output
        self._out_echo_btn = QtGui.QToolButton()
        self._out_echo_btn.setCheckable(True)
        self._out_echo_btn.setChecked(True)
        self._out_echo_btn.setDown(True)
        self._out_echo_btn.setMinimumSize(QtCore.QSize(30, 30))
        self._out_echo_btn.setMaximumSize(QtCore.QSize(30, 30))
        self._out_echo_btn.setObjectName("out_echo_btn")
        self._out_echo_btn.setToolTip("Echo python commands in output.")

        # output buttons layout
        out_btn_box = QtGui.QVBoxLayout()
        out_btn_box.setContentsMargins(0, 0, 0, 0)
        out_btn_box.addWidget(out_clear_btn)
        out_btn_box.addSpacing(10)
        out_btn_box.addWidget(self._out_echo_btn)
        out_btn_box.addSpacing(10)
        out_btn_box.addStretch()

        # ---- input

        # clear input
        in_clear_btn = QtGui.QToolButton()
        in_clear_btn.setMinimumSize(QtCore.QSize(30, 30))
        in_clear_btn.setMaximumSize(QtCore.QSize(30, 30))
        in_clear_btn.setObjectName("in_clear_btn")
        in_clear_btn.setToolTip("Clear all input.")

        # show/hide line numbers
        self._line_num_btn = QtGui.QToolButton()
        self._line_num_btn.setCheckable(True)
        self._line_num_btn.setChecked(True)
        self._line_num_btn.setDown(True)
        self._line_num_btn.setMinimumSize(QtCore.QSize(30, 30))
        self._line_num_btn.setMaximumSize(QtCore.QSize(30, 30))
        self._line_num_btn.setObjectName("line_num_btn")
        self._line_num_btn.setToolTip("Show/hide line numbers.")

        # open file
        self._open_file_menu = QtGui.QMenu(self)
        self._open_file_menu.aboutToShow.connect(self._build_open_file_menu)

        self._cached_static_actions = {}

        in_open_btn = QtGui.QToolButton()
        in_open_btn.setMinimumSize(QtCore.QSize(30, 30))
        in_open_btn.setMaximumSize(QtCore.QSize(30, 30))
        in_open_btn.setObjectName("in_open_btn")
        in_open_btn.setToolTip("Load python script from a file.")
        in_open_btn.setMenu(self._open_file_menu)
        in_open_btn.setPopupMode(QtGui.QToolButton.DelayedPopup)

        # reusable action for opening from disk
        open_file_icon = QtGui.QIcon(":/tk_multi_pythonconsole/open.png")
        self._open_file_action = QtGui.QAction(open_file_icon,
                                               "Load from disk...", self)
        self._open_file_action.triggered.connect(self.open)

        # save file
        self._in_save_btn = QtGui.QToolButton()
        self._in_save_btn.setMinimumSize(QtCore.QSize(30, 30))
        self._in_save_btn.setMaximumSize(QtCore.QSize(30, 30))
        self._in_save_btn.setObjectName("in_save_btn")
        self._in_save_btn.setToolTip("Save current python script to a file.")

        # execute
        self._in_exec_btn = QtGui.QToolButton()
        self._in_exec_btn.setMinimumSize(QtCore.QSize(30, 30))
        self._in_exec_btn.setMaximumSize(QtCore.QSize(30, 30))
        self._in_exec_btn.setObjectName("in_exec_btn")
        self._in_exec_btn.setToolTip(
            "Execute the current python script. Shortcut: Ctrl+Enter")

        # add tab
        add_tab_btn = QtGui.QToolButton(self)
        add_tab_btn.setMinimumSize(QtCore.QSize(12, 12))
        add_tab_btn.setMaximumSize(QtCore.QSize(12, 12))
        add_tab_btn.setObjectName("add_tab_btn")
        add_tab_btn.setToolTip("Add a new tab")

        # input buttons layout
        in_btn_box = QtGui.QVBoxLayout()
        in_btn_box.setContentsMargins(0, 0, 0, 0)
        in_btn_box.addStretch()
        in_btn_box.addWidget(self._in_exec_btn)
        in_btn_box.addSpacing(10)
        in_btn_box.addWidget(self._in_save_btn)
        in_btn_box.addSpacing(10)
        in_btn_box.addWidget(in_open_btn)
        in_btn_box.addSpacing(10)
        in_btn_box.addWidget(in_clear_btn)
        in_btn_box.addSpacing(10)
        in_btn_box.addWidget(self._line_num_btn)
        in_btn_box.addSpacing(20)
        in_btn_box.addWidget(add_tab_btn)
        in_btn_box.addSpacing(4)

        in_btn_box.setAlignment(add_tab_btn,
                                QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter)

        button_layout = QtGui.QVBoxLayout()
        button_layout.setContentsMargins(0, 0, 0, 0)
        button_layout.setSpacing(0)
        button_layout.addLayout(out_btn_box)
        button_layout.addStretch()
        button_layout.addLayout(in_btn_box)

        # main layout
        layout = QtGui.QHBoxLayout(self)
        layout.setContentsMargins(4, 4, 4, 4)
        layout.setSpacing(4)
        layout.addWidget(self.tabs)
        layout.addLayout(button_layout)

        layout.setStretchFactor(self.tabs, 100)

        # ---- connect singals and slots

        self._cur_tab_widget = lambda: self.tabs.currentWidget()

        # buttons clicked
        out_clear_btn.clicked.connect(
            lambda: self._cur_tab_widget().output_widget.clear())

        self._in_save_btn.clicked.connect(
            lambda: self._cur_tab_widget().input_widget.save())

        in_open_btn.clicked.connect(self.open)

        in_clear_btn.clicked.connect(
            lambda: self._cur_tab_widget().input_widget.clear())

        self._in_exec_btn.clicked.connect(
            lambda: self._cur_tab_widget().input_widget.execute())

        add_tab_btn.clicked.connect(self.tabs.add_tab)

        # toggles
        self._out_echo_btn.toggled.connect(
            lambda t: self._cur_tab_widget().input_widget.toggle_echo(t))

        self._line_num_btn.toggled.connect(lambda t: self._cur_tab_widget().
                                           input_widget.toggle_line_numbers(t))

        self.tabs.input_text_changed.connect(self._check_button_state)
        self.tabs.currentChanged.connect(self._check_button_state)

        # ---- set the default state

        # no point in saving until there are contents
        self._in_save_btn.setEnabled(False)