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)
Esempio n. 2
0
    def get_actions_for_publish(self, sg_data, ui_area):
        """
        See documentation for :func:`get_actions_for_publishes`. The functionality is the same,
        but only for a single publish.

        :param dict sg_data: Standard Shotgun entity dictionary with keys type, id and name.
        :param ui_area: Indicates which part of the UI the request is coming from.
            Currently one of `UI_AREA_MAIN`, `UI_AREA_DETAILS` and UI_AREA_HISTORY`.

        :returns: A :class:`list` of QAction instances.
        """
        actions = []
        open_action = QtGui.QAction("Open", self)
        cb_1 = partial(self._on_open, sg_data, policy=None)
        open_action.triggered.connect(cb_1)
        actions.append(open_action)
        if ui_area in [self.UI_AREA_DETAILS, self.UI_AREA_MAIN]:
            open_latest = QtGui.QAction("Open Latest", self)
            cb_2 = partial(self._on_open,
                           sg_data,
                           policy=self._handler.LATEST_POLICY)
            open_latest.triggered.connect(cb_2)
            open_latest_complete = QtGui.QAction("Open Latest Complete", self)
            cb_3 = partial(self._on_open,
                           sg_data,
                           policy=self._handler.LATEST_COMPLETE_POLICY)
            open_latest_complete.triggered.connect(cb_3)
            actions.append(open_latest)
            actions.append(open_latest_complete)
        return actions
Esempio n. 3
0
    def __init__(self, parent):
        """
        Construction

        :param parent:  The parent QWidget for this form
        """
        QtGui.QWidget.__init__(self, parent)

        self._current_file = None

        # create a single instance of the task manager that manages all
        # asynchrounous work/tasks.
        self._bg_task_manager = BackgroundTaskManager(self, max_threads=8)
        monitor_qobject_lifetime(self._bg_task_manager, "Main task manager")
        self._bg_task_manager.start_processing()

        shotgun_globals.register_bg_task_manager(self._bg_task_manager)

        # build the various models:
        self._my_tasks_model = self._build_my_tasks_model()
        self._entity_models = self._build_entity_models()
        self._file_model = self._build_file_model()

        # add refresh action with appropriate keyboard shortcut:
        refresh_action = QtGui.QAction("Refresh", self)
        refresh_action.setShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Refresh))
        refresh_action.triggered.connect(self._on_refresh_triggered)
        self.addAction(refresh_action)

        # on OSX, also add support for F5 (the default for OSX is Cmd+R)
        if sys.platform == "darwin":
            osx_f5_refresh_action = QtGui.QAction("Refresh (F5)", self)
            osx_f5_refresh_action.setShortcut(QtGui.QKeySequence(QtCore.Qt.Key_F5))
            osx_f5_refresh_action.triggered.connect(self._on_refresh_triggered)
            self.addAction(osx_f5_refresh_action)
    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
Esempio n. 5
0
    def createActions(self):
        self.openAct = QtGui.QAction("&Open...", self, shortcut="Ctrl+O",
                triggered=self.open)

        self.printAct = QtGui.QAction("&Print...", self, shortcut="Ctrl+P",
                enabled=False, triggered=self.print_)

        self.exitAct = QtGui.QAction("E&xit", self, shortcut="Ctrl+Q",
                triggered=self.close)

        self.zoomInAct = QtGui.QAction("Zoom &In (25%)", self,
                shortcut="Ctrl++", enabled=False, triggered=self.zoomIn)

        self.zoomOutAct = QtGui.QAction("Zoom &Out (25%)", self,
                shortcut="Ctrl+-", enabled=False, triggered=self.zoomOut)

        self.normalSizeAct = QtGui.QAction("&Normal Size", self,
                shortcut="Ctrl+S", enabled=False, triggered=self.normalSize)

        self.fitToWindowAct = QtGui.QAction("&Fit to Window", self,
                enabled=False, checkable=True, shortcut="Ctrl+F",
                triggered=self.fitToWindow)

        self.aboutAct = QtGui.QAction("&About", self, triggered=self.about)

        self.aboutQtAct = QtGui.QAction("About &Qt", self,
                triggered=QtGui.qApp.aboutQt)
Esempio n. 6
0
    def get_actions_for_folder(self, sg_data):
        """
        Returns a list of actions for a folder object.
        """
        fs = QtGui.QAction("Show in the file system", None)
        fs.triggered[()].connect(lambda f=sg_data: self._show_in_fs(f))

        sg = QtGui.QAction("Show details in Shotgun", None)
        sg.triggered[()].connect(lambda f=sg_data: self._show_in_sg(f))

        sr = QtGui.QAction("Show in Screening Room", None)
        sr.triggered[()].connect(lambda f=sg_data: self._show_in_sr(f))

        return [fs, sg, sr]
Esempio n. 7
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)
    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)
Esempio n. 9
0
    def createActions(self):
        self.openAct = QtGui.QAction("&Open...",
                                     self,
                                     shortcut="Ctrl+O",
                                     triggered=self.open)

        for format in QtGui.QImageWriter.supportedImageFormats():
            format = str(format)

            text = format.upper() + "..."

            action = QtGui.QAction(text, self, triggered=self.save)
            action.setData(format)
            self.saveAsActs.append(action)

        self.printAct = QtGui.QAction("&Print...",
                                      self,
                                      triggered=self.scribbleArea.print_)

        self.exitAct = QtGui.QAction("E&xit",
                                     self,
                                     shortcut="Ctrl+Q",
                                     triggered=self.close)

        self.saveOverAct = QtGui.QAction("Save and Exit",
                                         self,
                                         shortcut="Ctrl+S",
                                         triggered=self.saveOver)

        self.penColorAct = QtGui.QAction("&Pen Color...",
                                         self,
                                         triggered=self.penColor)

        self.penWidthAct = QtGui.QAction("Pen &Width...",
                                         self,
                                         triggered=self.penWidth)

        self.clearScreenAct = QtGui.QAction(
            "&Clear Screen",
            self,
            shortcut="Ctrl+L",
            triggered=self.scribbleArea.clearImage)

        self.aboutAct = QtGui.QAction("&About", self, triggered=self.about)

        self.aboutQtAct = QtGui.QAction("About &Qt",
                                        self,
                                        triggered=QtGui.qApp.aboutQt)
 def _on_before_selection(self, widget, model_index, style_options):
     """
     Called when the associated widget is selected. This method 
     implements all the setting up and initialization of the widget
     that needs to take place prior to a user starting to interact with it.
     
     :param widget: The widget to operate on (created via _create_widget)
     :param model_index: The model index to operate on
     :param style_options: QT style options
     """
     # do std drawing first
     self._on_before_paint(widget, model_index, style_options)        
     widget.set_selected(True)
     
     # set up the menu
     sg_item = shotgun_model.get_sg_data(model_index)
     actions = self._action_manager.get_actions_for_publish(sg_item, self._action_manager.UI_AREA_HISTORY)
     
     # if there is a version associated, add View in Screening Room Action
     if sg_item.get("version"):
         sg_url = sgtk.platform.current_bundle().shotgun.base_url
         url = "%s/page/screening_room?entity_type=%s&entity_id=%d" % (sg_url, 
                                                                       sg_item["version"]["type"], 
                                                                       sg_item["version"]["id"])                    
         
         fn = lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))                    
         a = QtGui.QAction("View in Screening Room", None)
         a.triggered[()].connect(fn)
         actions.append(a)
     
     # add actions to actions menu
     widget.set_actions(actions)            
Esempio n. 11
0
    def _populate_open_menu(self, menu, file_actions):
        """
        Creates menu entries based on a list of file actions.

        :param menu: Target menu for the entries.
        :param file_actions: List of Actions to add under the menu.
        """
        add_separators = False
        for action in file_actions:
            if isinstance(action, SeparatorAction):
                if add_separators:
                    menu.addSeparator()
                # ensure that we only add separators after at least one action item and
                # never more than one!
                add_separators = False
            elif isinstance(action, ActionGroup):
                # This is an action group, so we'll add the entries in a sub-menu.
                self._populate_open_menu(menu.addMenu(action.label), action.actions)
                add_separators = True
            else:
                q_action = QtGui.QAction(action.label, menu)
                q_action.triggered[()].connect(
                    lambda a=action, checked=False: self._perform_action(a)
                )
                menu.addAction(q_action)
                add_separators = True
Esempio n. 12
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 _on_before_selection(self, widget, model_index, style_options):
        """
        Called when the associated widget is being set up. Initialize
        things that shall persist, for example action menu items.
        """
        # do std drawing first
        self._on_before_paint(widget, model_index, style_options)
        widget.set_selected(True)

        # set up the menu
        sg_item = shotgun_model.get_sg_data(model_index)
        actions = self._action_manager.get_actions_for_publish(
            sg_item, self._action_manager.UI_AREA_HISTORY)

        # if there is a version associated, add View in Screening Room Action
        if sg_item.get("version"):
            sg_url = sgtk.platform.current_bundle().shotgun.base_url
            url = "%s/page/screening_room?entity_type=%s&entity_id=%d" % (
                sg_url, sg_item["version"]["type"], sg_item["version"]["id"])

            fn = lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
            a = QtGui.QAction("View in Screening Room", None)
            a.triggered[()].connect(fn)
            actions.append(a)

        # add actions to actions menu
        widget.set_actions(actions)
Esempio n. 14
0
    def __init__(self, group_id, show_limit_increment=5):
        """
        Constructor. Initialize the filter group's instance members.
        """

        # The unique identifier for this filter group.
        self.group_id = group_id

        # The incremental amount to the limited number of items shown in the group; e.g.
        # the group may have a limit to show only 5 items, if the user requets to increase
        # the number of items shown, this is the amount that the limit will increase by.
        self._show_limit_increment = show_limit_increment
        # The limit to how many items are shown in the group.
        self._show_limit = self._show_limit_increment

        # The header QWidgetAction for this group.
        self.header_action = None
        # The show/hide action to toggle the filter group visibility.
        self.show_hide_action = None
        # The list of FilterItem objects that belong to this group.
        self.filter_items = []
        # The mapping of FilterItem id to its corresponding QWidgetAction.
        self.filter_actions = {}

        # A reserve list of actions, which are hidden, but ready to be shown on user request.
        # There is a limit to how many items are shown at a given time to avoid having an
        # overwhelming amount of items in a menu). These items will incrementally show when
        # the "Show More..." action is triggered.
        self.more_actions = []
        # This action will trigger showing more items in the group incrementall. It will always
        # be shown as the last item in the group.
        self.show_more_action = QtGui.QAction("Show More...", None)
        self.show_more_action.triggered.connect(self.show_more)
Esempio n. 15
0
    def _on_before_paint(self, widget, model_index, style_options):
        """
        Called by the base class when the associated widget should be
        painted in the view. This method should implement setting of all
        static elements (labels, pixmaps etc) but not dynamic ones (e.g. buttons)

        :param widget: The widget to operate on (created via _create_widget)
        :param model_index: The model index to operate on
        :param style_options: QT style options
        """
        icon = shotgun_model.get_sanitized_data(model_index, QtCore.Qt.DecorationRole)
        widget.set_thumbnail(icon)

        # get the shotgun data
        sg_item = shotgun_model.get_sg_data(model_index)

        # fill the content of the widget with the data of the loaded ShotGrid
        # item
        widget.set_text(sg_item)

        # add an action to the widget toolbox to be able to open the ShotGrid Web page of the current item
        sg_url = sgtk.platform.current_bundle().shotgun.base_url
        url = "%s/page/project_overview?project_id=%d" % (sg_url, sg_item["id"])
        fn = lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
        a = QtGui.QAction("View in Shotgun", None)
        a.triggered[()].connect(fn)

        widget.set_actions([a])
    def _get_qaction(self, field, display_name):
        """
        Add an action for the given field to the menu. The data for the action will contain
        a dictionary where the selected field is set for the "field" key.

        :param field: The field to add, in bubbled notation (eg 'entity.Shot.code')
        :type field: String

        :param display_name: The text to display for the action
        :type display_name: String
        """
        action = QtGui.QAction(display_name, self)

        action.setData({"field": field})

        if self._checked_filter:
            action.setCheckable(True)
            action.setChecked(self._checked_filter(field))
        else:
            action.setCheckable(False)

        if self._disabled_filter:
            action.setDisabled(self._disabled_filter(field))

        return action
Esempio n. 17
0
    def _setup_version_sort_by_menu(self):
        """
        Sets up the sort-by menu in the Versions tab.
        """
        self._version_sort_menu = ShotgunMenu(self)
        self._version_sort_menu.setObjectName("version_sort_menu")

        ascending = QtGui.QAction("Ascending", self)
        descending = QtGui.QAction("Descending", self)
        ascending.setCheckable(True)
        descending.setCheckable(True)
        descending.setChecked(True)

        self._version_sort_menu_directions = QtGui.QActionGroup(self)
        self._version_sort_menu_fields = QtGui.QActionGroup(self)
        self._version_sort_menu_directions.setExclusive(True)
        self._version_sort_menu_fields.setExclusive(True)

        self._version_sort_menu_directions.addAction(ascending)
        self._version_sort_menu_directions.addAction(descending)
        self._version_sort_menu.add_group([ascending, descending],
                                          title="Direction")

        field_actions = []

        for field_name in self._version_list_sort_by_fields:
            display_name = shotgun_globals.get_field_display_name(
                "Version",
                field_name,
            )

            action = QtGui.QAction(display_name, self)

            # We store the database field name on the action, but
            # display the "pretty" name for users.
            action.setData(field_name)
            action.setCheckable(True)
            action.setChecked((field_name == "id"))
            self._version_sort_menu_fields.addAction(action)
            field_actions.append(action)

        self._version_sort_menu.add_group(field_actions, title="By Field")
        self._version_sort_menu_directions.triggered.connect(
            self._toggle_sort_order)
        self._version_sort_menu_fields.triggered.connect(
            self._sort_version_list)
        self.ui.version_sort_button.setMenu(self._version_sort_menu)
Esempio n. 18
0
    def __init__(self):
        """
        Constructor
        """
        # get app bundle
        self._app = sgtk.platform.current_bundle()
        # call the base class and let it do its thing.
        QtGui.QWidget.__init__(self)

        # # Set up our own logger (other than shotgun logger) for storing timestamp
        # self.set_logger(logging.INFO)
        # now load in the UI that was created in the UI designer
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.current_project = self._app.context.project['name']

        # create a background task manager
        self._task_manager = task_manager.BackgroundTaskManager(
            self, start_processing=True, max_threads=4)
        monitor_qobject_lifetime(self._task_manager, "Main task manager")
        self._task_manager.start_processing()

        # lastly, set up our very basic UI
        self.user = sgtk.util.get_current_user(self._app.sgtk)
        # self.ui.textBrowser.setText("Hello, %s!" % self.user['firstname'])
        # create my tasks form and my time form:
        self.createTasksForm()
        self.createManagementForm()
        self.createTimeForm()
        self.createTimelogTable()
        # time summary labels
        self._get_time_sum()
        self.ui.time_sum_label.setFont(QtGui.QFont("Arial", 80))

        # add refresh action with appropriate keyboard shortcut:
        refresh_action = QtGui.QAction("Refresh", self)
        refresh_action.setShortcut(
            QtGui.QKeySequence(QtGui.QKeySequence.Refresh))
        refresh_action.triggered.connect(self._on_refresh_triggered)
        self.addAction(refresh_action)
        # on OSX, also add support for F5 (the default for OSX is Cmd+R)
        if sys.platform == "darwin":
            osx_f5_refresh_action = QtGui.QAction("Refresh (F5)", self)
            osx_f5_refresh_action.setShortcut(
                QtGui.QKeySequence(QtCore.Qt.Key_F5))
            osx_f5_refresh_action.triggered.connect(self._on_refresh_triggered)
            self.addAction(osx_f5_refresh_action)
Esempio n. 19
0
    def __init__(self, parent=None):
        """
        Initialize the demo widget.
        """

        # call the base class init
        super(ShotgunMenuDemo, self).__init__(parent)

        # --- build a shotgun menu

        sg_menu = shotgun_menus.ShotgunMenu(self)
        submenu = shotgun_menus.ShotgunMenu(self)
        submenu.setTitle("Submenu")

        # create some dummy actions
        action1 = QtGui.QAction("Action 1", self)
        action2 = QtGui.QAction("Action 2", self)
        action3 = QtGui.QAction("Action 3", self)
        action4 = QtGui.QAction("Action 4", self)

        # add a group of actions to the top-level menu
        sg_menu.add_group([action1, action2, submenu], "Menu Actions")

        # add some actions to the sub menu
        submenu.add_group([action3, action4], "Submenu Actions")

        # a button to trigger the menu
        sg_menu_button = QtGui.QPushButton("ShotgunMenu")
        sg_menu_button.setFixedWidth(100)
        sg_menu_button.clicked.connect(
            lambda: sg_menu.exec_(QtGui.QCursor.pos()))
        sg_menu_button.setObjectName("sg_menu_button")

        # help label
        doc = QtGui.QLabel("Click the button to show the menu.")
        doc.setAlignment(QtCore.Qt.AlignCenter)

        # lay out and align the widgets
        layout = QtGui.QVBoxLayout(self)
        layout.addStretch()
        layout.addWidget(doc)
        layout.addSpacing(8)
        layout.addWidget(sg_menu_button)
        layout.addStretch()

        layout.setAlignment(sg_menu_button, QtCore.Qt.AlignCenter)
    def __init__(self, parent):
        """
        """
        QtGui.QMenu.__init__(self, parent)

        self._current_user_id = (
            g_user_cache.current_user["id"] if g_user_cache.current_user else None
        )
        self._available_users = {}
        self._checked_user_ids = set()

        # build the base menu - this won't change:
        menu_action = QtGui.QWidgetAction(self)
        menu_label = QtGui.QLabel("<i>Choose Who To Display Files For</i>", self)
        ss = "QLabel {margin: 3px;}"
        menu_label.setStyleSheet(ss)
        menu_action.setDefaultWidget(menu_label)
        self.addAction(menu_action)
        self.addSeparator()

        self._current_user_action = QtGui.QAction("Show My Files", self)
        self._current_user_action.setCheckable(True)
        toggled_slot = lambda toggled: self._on_user_toggled(
            self._current_user_id, toggled
        )
        self._current_user_action.toggled.connect(toggled_slot)
        self.addAction(self._current_user_action)

        self._all_users_action = QtGui.QAction("Show Files For All Other Users", self)
        self._all_users_action.setCheckable(True)
        self._all_users_action.toggled.connect(self._on_all_other_users_toggled)
        self.addAction(self._all_users_action)

        menu_action = QtGui.QWidgetAction(self)
        menu_label = QtGui.QLabel("<i>Other Users:</i>", self)
        ss = "QLabel {margin: 3px;margin-top: 6px;}"
        menu_label.setStyleSheet(ss)
        menu_action.setDefaultWidget(menu_label)
        self.addAction(menu_action)
        self.addSeparator()

        self._no_other_users_action = self._add_no_other_users_action()
Esempio n. 21
0
    def _get_default_detail_actions(self, sg_data):
        """
        Returns a list of default actions for the detail area
        """
        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]
Esempio n. 22
0
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)
Esempio n. 23
0
    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)
Esempio n. 24
0
    def _get_qaction_for_context(self, context):
        """
        Helper method to build a QAction for the supplied context.
        """

        # get the display string and icon path for the context
        context_display = _get_context_display(context, plain_text=True)
        icon_path = _get_context_icon_path(context)

        # construct the action
        action = QtGui.QAction(self)
        action.setText(context_display)
        action.setIcon(QtGui.QIcon(icon_path))
        action.setData(context)
        action.triggered.connect(lambda: self._on_context_activated(context))

        return action
    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()
    def get_default_action_for_publish(self, sg_data, ui_area):
        """
        Get the default action for the specified publish data.
        
        For the open dialog, the default action is to open the publish the action
        is triggered for.

        :param sg_data: Shotgun data for a publish
        :param ui_area: Indicates which part of the UI the request is coming from. 
                        Currently one of UI_AREA_MAIN, UI_AREA_DETAILS and UI_AREA_HISTORY
        :returns:       The QAction object representing the default action for this publish        
        """
        # create the default action:
        action = QtGui.QAction(None, None)

        # connect the default action so that the default_action_triggered
        # is emitted:
        default_action_cb = lambda sg=sg_data: self.default_action_triggered.emit(sg)
        action.triggered[()].connect(default_action_cb)
        
        return action
    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()
Esempio n. 28
0
    def __init__(self, text, editable=True, parent=None):

        QtGui.QTextEdit.__init__(self, text, parent)
        if editable:
            self.setReadOnly(True)
            self.setFrameStyle(QtGui.QFrame.NoFrame)
            pal = QtGui.QPalette()
            pal.setColor(QtGui.QPalette.Base, QtCore.Qt.transparent)
            self.setPalette(pal)

            self.setLineWrapMode(QtGui.QTextEdit.WidgetWidth)
            self.setWordWrapMode(QtGui.QTextOption.WrapAnywhere)

            self.document().documentLayout().documentSizeChanged.connect(
                self.adjustMinimumSize)
        else:
            action = QtGui.QAction(self)
            action.setShortcuts(["Ctrl+Enter", "Ctrl+Return"])
            action.triggered.connect(self.actionReturn)
            self.addAction(action)

            self.setToolTip("Ctrl+Enter to create without pushing button")
Esempio n. 29
0
def __create_tank_error_menu():
    """
    Creates a std "error" sgtk menu and grabs the current context.
    Make sure that this is called from inside an except clause.
    """
    from sgtk.platform.qt import QtGui
    (exc_type, exc_value, exc_traceback) = sys.exc_info()
    message = ""
    message += "Message: Shotgun encountered a problem starting the Engine.\n"
    message += "Please contact [email protected]\n\n"
    message += "Exception: %s - %s\n" % (exc_type, exc_value)
    message += "Traceback (most recent call last):\n"
    message += "\n".join( traceback.format_tb(exc_traceback))

    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 m=message: __show_tank_message("Shotgun Pipeline Toolkit caught an error", m)
            action = QtGui.QAction("[Shotgun Error - Click for details]", sg_menu, triggered=cmd)
            sg_menu.addAction(action)
    else:
        print("The Shotgun Pipeline Toolkit caught an error: %s" % message)
Esempio n. 30
0
    def __init__(self, parent=None):
        """
        Construction
        
        :param parent:    The parent QWidget
        """
        browser_widget.BrowserWidget.__init__(self, parent)

        # tweak style
        self.title_style = "none"
        self.enable_search(False)
        self.enable_multi_select(True)
        self.set_label("")
        self.ui.browser_header.setVisible(False)

        # cache of publish images that we've looked up from Shotgun.  Used to
        # avoid unnecessary lookups.
        self.__publish_images = {}

        # add right-click menu to remove items:
        self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
        remove_action = QtGui.QAction("Remove Selected Publishes", self)
        self.addAction(remove_action)
        remove_action.triggered[()].connect(self._on_remove_selected_publishes)