def _create_theme_menu(self):
        theme_menu = QMenu(self)
        theme_menu.setTitle('Buttons Theme')
        theme_menu.setTearOffEnabled(True)
        theme_menu.setWindowTitle(TAG)
        theme_actions = QActionGroup(self)
        theme_actions.setExclusive(True)
        # create ordered theme list
        custom_order_theme = sorted(THEMES.iterkeys())
        custom_order_theme.remove('Maya Theme')
        custom_order_theme.insert(0, 'Maya Theme')
        default_item = True
        for theme in custom_order_theme:
            current_theme_action = QAction(theme, theme_actions)
            current_theme_action.setCheckable(True)
            current_theme_action.setChecked(
                MTTSettings.value('theme', 'Maya Theme') == theme)
            current_theme_action.triggered.connect(self.on_change_theme)
            theme_menu.addAction(current_theme_action)

            if default_item:
                theme_menu.addSeparator()
                default_item = False

        return theme_menu
Exemplo n.º 2
0
 def init_notebooks(self):
     frame = QFrame()
     layout = QVBoxLayout()
     frame.setLayout(layout)
     self.ui.scrollArea.setWidget(frame)
     for notebook_struct in self.app.provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         count = self.app.provider.get_notebook_notes_count(notebook.id)
         widget = QWidget()
         menu = QMenu(self)
         menu.addAction(self.tr('Change Name'), Slot()(partial(
             self.change_notebook, notebook=notebook,
         )))
         action = menu.addAction(self.tr('Remove Notebook'), Slot()(partial(
             self.remove_notebook, notebook=notebook,
         )))
         action.setEnabled(False)
         widget.ui = Ui_Notebook()
         widget.ui.setupUi(widget)
         widget.ui.name.setText(notebook.name)
         widget.ui.content.setText(self.tr('Containts %d notes') % count)
         widget.ui.actionBtn.setIcon(QIcon.fromTheme('gtk-properties'))
         widget.setFixedHeight(50)
         layout.addWidget(widget)
         widget.ui.actionBtn.clicked.connect(Slot()(partial(
             self.show_notebook_menu,
             menu=menu, widget=widget,
         )))
Exemplo n.º 3
0
 def contextMenuEvent(self, event):
     ''' When user right-clicks: display context menu '''
     png_action = 'Export branch to PNG, SVG or PDF'
     hl_action = 'Hyperlink'
     my_menu = QMenu(png_action)
     if not hasattr(self, '_no_hyperlink'):
         my_menu.addAction(hl_action)
     my_menu.addAction(png_action)
     action = my_menu.exec_(event.screenPos())
     if action:
         if action.text() == png_action:
             # Save a picture of the selected symbol and all its children
             filename = QFileDialog.getSaveFileName(self.window(),
                     'Export picture', '.',
                     'Picture (*.png, *.svg, *.pdf)')[0]
             if not filename:
                 return
             save_fmt = filename.split(os.extsep)[-1]
             if save_fmt not in ('png', 'svg', 'pdf'):
                 return
             self.scene().export_branch_to_picture(self, filename, save_fmt)
         elif action.text() == hl_action:
             if self.text:
                 self.hyperlink_dialog.setParent(
                         self.scene().views()[0], Qt.Dialog)
                 self.hlink_field.setText(self.text.hyperlink)
                 self.hyperlink_dialog.show()
Exemplo n.º 4
0
 def note_context_menu(self, pos):
     menu = QMenu(self.ui.notesList)
     menu.addAction(QIcon.fromTheme('gtk-edit'), self.tr('Edit'),
                    self.edit_note)
     menu.addAction(QIcon.fromTheme('gtk-delete'), self.tr('Remove'),
                    self.remove_note)
     menu.exec_(self.ui.notesList.mapToGlobal(pos))
    def _create_theme_menu(self):
        theme_menu = QMenu(self)
        theme_menu.setTitle('Buttons Theme')
        theme_menu.setTearOffEnabled(True)
        theme_menu.setWindowTitle(TAG)
        theme_actions = QActionGroup(self)
        theme_actions.setExclusive(True)
        # create ordered theme list
        custom_order_theme = sorted(THEMES.iterkeys())
        custom_order_theme.remove('Maya Theme')
        custom_order_theme.insert(0, 'Maya Theme')
        default_item = True
        for theme in custom_order_theme:
            current_theme_action = QAction(theme, theme_actions)
            current_theme_action.setCheckable(True)
            current_theme_action.setChecked(
                MTTSettings.value('theme', 'Maya Theme') == theme)
            current_theme_action.triggered.connect(self.on_change_theme)
            theme_menu.addAction(current_theme_action)

            if default_item:
                theme_menu.addSeparator()
                default_item = False

        return theme_menu
Exemplo n.º 6
0
    def create(self, window: QtGui.QMainWindow, parent_menu: QtGui.QMenu):
        if self.disabled:
            return
        if callable(self.method_name):
            method = self.method_name
        else:
            method = getattr(window, self.method_name)

        if self.sep:
            parent_menu.addSeparator()
        if self.submenu:
            menu = QtGui.QMenu(self.verbose_name, p(parent_menu))
            if self.icon:
                action = parent_menu.addMenu(get_icon(self.icon), menu)
            else:
                action = parent_menu.addMenu(menu)
            action.hovered.connect(functools.partial(self.fill_submenu, window, menu, method))
        else:
            if self.icon:
                action = QtGui.QAction(get_icon(self.icon), self.verbose_name, p(parent_menu))
            else:
                action = QtGui.QAction(self.verbose_name, p(parent_menu))
            # noinspection PyUnresolvedReferences
            action.triggered.connect(method)
            parent_menu.addAction(action)
        if self.shortcut:
            action.setShortcut(self.shortcut)
        if self.help_text:
            action.setStatusTip(self.help_text)
Exemplo n.º 7
0
 def tag_context_menu(self, pos):
     index = self.ui.tagsList.currentIndex()
     item = self.tagsModel.itemFromIndex(index)
     if hasattr(item, 'tag'):
         menu = QMenu(self.ui.tagsList)
         menu.addAction(QIcon.fromTheme('gtk-delete'), self.tr('Remove'), self.remove_tag)
         menu.exec_(self.ui.tagsList.mapToGlobal(pos))
Exemplo n.º 8
0
    def showHeaderMenu( self, pos ):
        header = self.horizontalHeader()
        column = header.logicalIndexAt(pos.x())

        filterAction = QAction(self)
        filterAction.setText('Filter column')
        filterAction.triggered.connect(lambda: self.filterColumn(self.indexAt(pos)))
        symbolAction = QAction(self)
        symbolAction.setText('Symbol')
        symbolAction.triggered.connect(lambda: self.changeColumnDisplay(self.indexAt(pos),'symbol'))
        colourAction = QAction(self)
        colourAction.setText('Color')
        colourAction.triggered.connect(lambda: self.changeColumnDisplay(self.indexAt(pos),'brush'))
        sizeAction = QAction(self)
        sizeAction.setText('Size')
        sizeAction.triggered.connect(lambda: self.changeColumnDisplay(self.indexAt(pos),'size'))
        # show menu about the column
        menu = QMenu(self)
        displayMenu = menu.addMenu('Change graph display')
        displayMenu.addAction(symbolAction)
        displayMenu.addAction(colourAction)
        displayMenu.addAction(sizeAction)
        menu.addAction(filterAction)

        menu.popup(header.mapToGlobal(pos))
Exemplo n.º 9
0
 def __menu(self, pos):
     u"""Slot d'apparition du menu contextuel"""
     menu = QMenu()
     menu.addAction("Supprimer", self, SLOT("supprimer()"),
                    QKeySequence.Delete)
     menu.addAction("Nouveau", self, SLOT("nouveau()"), QKeySequence.New)
     menu.exec_(self._ui.tv.mapToGlobal(pos))
Exemplo n.º 10
0
    def popup_menu(self, position):

        selected_row = self.view.rowAt(position.y())

        if selected_row >= 0 and self._used_categories and len(
                self._used_categories) > 1:
            category_menu = QMenu(_("Categories"))
            selected_doc = self.model.object_at(selected_row)

            category_actions = []
            for category in self._used_categories:
                a = QAction(category.full_name, category_menu)
                a.setData(category)

                a.setEnabled(selected_doc.document_category_id !=
                             category.document_category_id)

                category_menu.addAction(a)
                category_actions.append(a)

            action = category_menu.exec_(QCursor.pos())

            if action:
                new_category = action.data()

                if selected_doc.document_category_id != new_category.document_category_id:
                    selected_doc.document_category_id = new_category.document_category_id
                    self.model.signal_object_change(selected_doc)
Exemplo n.º 11
0
 def showContextMenu(self, point):
     'Show the Columns context menu'
     if self.model() is None:
         return
     
     # If we are viewing a proxy model, skip to the source model
     mdl = self.model()
     while isinstance(mdl, QAbstractProxyModel):
         mdl = mdl.sourceModel()
     
     if mdl is None or not hasattr(mdl, 'columns'):
         return
     
     # Generate and show the Menu
     m = QMenu()
     for i in range(len(mdl.columns)):
         c = mdl.columns[i]
         if c.internal:
             continue
         
         a = QAction(mdl.headerData(i, Qt.Horizontal, Qt.DisplayRole), m)
         a.setCheckable(True)
         a.setChecked(not self.isColumnHidden(i))
         a.triggered.connect(partial(self.showHideColumn, c=i, s=self.isColumnHidden(i)))
         m.addAction(a)
         
     m.exec_(self.header().mapToGlobal(point))
  def createVersionEveryWhereMenuForView(self, view):

    versionEverywhereMenu = QMenu(self.actionTitle)
    self._versionActions = []
    # We look to the activeView for a selection of Clips
    clips = self.clipSelectionFromView(view)
    
    # And bail if nothing is found
    if len(clips)==0:
      return versionEverywhereMenu

    # Now, if we have just one Clip selected, we'll form a special menu, which lists all versions
    if len(clips)==1:

      # Get a reversed list of Versions, so that bigger ones appear at top
      versions = list(reversed(clips[0].binItem().items()))
      for version in versions:
        self._versionActions+=[self.makeVersionActionForSingleClip(version)]

    elif len(clips)>1:
      # We will add Max/Min/Prev/Next options, which can be called on a TrackItem, without the need for a Version object
      self._versionActions+=[self.makeAction(self.eMaxVersion,self.setTrackItemVersionForClipSelection, icon=None)]
      self._versionActions+=[self.makeAction(self.eMinVersion,self.setTrackItemVersionForClipSelection, icon=None)]
      self._versionActions+=[self.makeAction(self.eNextVersion,self.setTrackItemVersionForClipSelection, icon=None)]
      self._versionActions+=[self.makeAction(self.ePreviousVersion,self.setTrackItemVersionForClipSelection, icon=None)]
    
    for act in self._versionActions:
      versionEverywhereMenu.addAction(act)

    return versionEverywhereMenu
Exemplo n.º 13
0
 def tag_context_menu(self, pos):
     index = self.ui.tagsList.currentIndex()
     item = self.tagsModel.itemFromIndex(index)
     if hasattr(item, 'tag'):
         menu = QMenu(self.ui.tagsList)
         menu.addAction(QIcon.fromTheme('gtk-delete'), self.tr('Remove'),
                        self.remove_tag)
         menu.exec_(self.ui.tagsList.mapToGlobal(pos))
Exemplo n.º 14
0
    def popup(self,pos):
        menu = QMenu()

        saveRepAction = QAction(self)
        saveRepAction.setText('Save representation...')
        saveRepAction.triggered.connect(lambda: self.saveRep(self.indexAt(pos)))
        menu.addAction(saveRepAction)
        action = menu.exec_(self.mapToGlobal(pos))
Exemplo n.º 15
0
 def notebook_context_menu(self, pos):
     index = self.ui.notebooksList.currentIndex()
     item = self.notebooksModel.itemFromIndex(index)
     if hasattr(item, 'notebook'):
         menu = QMenu(self.ui.notebooksList)
         menu.addAction(QIcon.fromTheme('gtk-edit'), self.tr('Rename'), self.rename_notebook)
         menu.addAction(QIcon.fromTheme('gtk-delete'), self.tr('Remove'), self.remove_notebook)
         menu.exec_(self.ui.notebooksList.mapToGlobal(pos))
Exemplo n.º 16
0
class HierarchyTreeView(QTreeView):


    def __init__(self):
        super(HierarchyTreeView, self).__init__()
        
        #ukljucuje kontekstni meni
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.openMenu)
        
    
    def openMenu(self, position):
        self.contextMenu = QMenu()
        newMenu = QMenu("New") 
        self.contextMenu.addMenu(newMenu)
        
        actionNewProj = QAction("NewProject", None)
        actionNewProj.triggered.connect(self.addNode)
        
        actionRename = QAction("Rename", None)
        actionRename.triggered.connect(self.renameNode)
        
        actionRemProj = QAction("Delete", None)
        actionRemProj.triggered.connect(self.removeNode)
        
        newMenu.addAction(actionNewProj)
        self.contextMenu.addAction(actionRename)
        self.contextMenu.addAction(actionRemProj)
        
        #prikaz kontekstnog menija
        self.contextMenu.exec_(self.viewport().mapToGlobal(position))
        
    def addNode(self):
        model = self.model()
        
        node = Node("NoviCvor")
        
        
        
        if not self.currentIndex().isValid():
            model.insertRow(model.rowCount(self.currentIndex()), node)
        else:
            model.insertRow(model.rowCount(self.currentIndex()), node, self.currentIndex())
        self.expand(self.currentIndex())
    
    def removeNode(self):
        model = self.model()
        model.removeRow(self.currentIndex().internalPointer().getIndex(), self.currentIndex().parent())    
        
    def renameNode(self):
        self.currentIndex().internalPointer().setName("NOVO")
    
    
    def mousePressEvent(self, event):
        if(self.selectionMode() == QAbstractItemView.SingleSelection):
            self.clearSelection()
            self.setCurrentIndex(QModelIndex())
        super(HierarchyTreeView, self).mousePressEvent(event)
Exemplo n.º 17
0
 def sort_menu(self):
     sort_by=QMenu("Sort By")
     sort_by.setIcon( QIcon(appicon("default_menu")) )
     sorting=["Year","Title","Oldest","Newest","My Rating","IMDb Rating","ASC","DESC"]
     for i in sorting:
         k=SortbyAction(i,self)
         k.triggered.connect(self.click_event)
         sort_by.addAction(k)
     return sort_by
Exemplo n.º 18
0
 def _setupContextMenu(self):
   from visualscrape.lib.data import ActionStore
   context_menu = QMenu(self)
   export_action = NamedAction(self.tr("Export ..."), self, name="export")
   export_action.triggered.connect(self._requestTabExport)
   context_menu.addAction(export_action)
   self.setTabBar(ContextMenuTabBar(context_menu))
   action_store = ActionStore.get_instance()
   action_store.register_action(export_action)
Exemplo n.º 19
0
    def __LobbyListMenu( self, position ):
        lobby_menu      = QMenu()

        rm_from_lobby   = QAction( self )
        rm_from_lobby.setText( "Remove player from lobby" )
        rm_from_lobby.triggered.connect( self._RemoveFromLobbyListAction )

        lobby_menu.addAction( rm_from_lobby )

        lobby_menu.exec_( self.window.lobby_lst.viewport().mapToGlobal( position ) )
Exemplo n.º 20
0
 def notebook_context_menu(self, pos):
     index = self.ui.notebooksList.currentIndex()
     item = self.notebooksModel.itemFromIndex(index)
     if hasattr(item, 'notebook'):
         menu = QMenu(self.ui.notebooksList)
         menu.addAction(QIcon.fromTheme('gtk-edit'), self.tr('Rename'),
                        self.rename_notebook)
         menu.addAction(QIcon.fromTheme('gtk-delete'), self.tr('Remove'),
                        self.remove_notebook)
         menu.exec_(self.ui.notebooksList.mapToGlobal(pos))
Exemplo n.º 21
0
    def contextMenuEvent(self, event):
        """
        Handles the ``contextMenuEvent`` event for :class:`CmdPromptInput`.

        :param `event`: a `QContextMenuEvent` event to be processed.
        """
        menu = QMenu(self)
        menu.addSeparator()
        # TODO: Extra stuff
        menu.addAction(QAction("TODO: Add Extra stuff", self))
        menu.exec_(event.globalPos())
Exemplo n.º 22
0
    def contextMenuEvent(self, event):
        """
        Handles the ``contextMenuEvent`` event for :class:`CmdPromptInput`.

        :param `event`: a `QContextMenuEvent` event to be processed.
        """
        menu = QMenu(self)
        menu.addSeparator()
        # TODO: Extra stuff
        menu.addAction(QAction("TODO: Add Extra stuff", self))
        menu.exec_(event.globalPos())
Exemplo n.º 23
0
 def click(self, res, event):
     """Open resource"""
     button = event.button()
     if button == Qt.LeftButton:
         subprocess.Popen(["xdg-open", res.file_path])
     elif button == Qt.RightButton:
         menu = QMenu(self.parent)
         if not res.in_content:
             menu.addAction(self.parent.tr("Remove Resource"), Slot()(partial(self.remove, res=res)))
         menu.addAction(self.parent.tr("Save As"), Slot()(partial(self.save, res=res)))
         menu.exec_(event.globalPos())
 def __init__(self, parent=None):
     QMainWindow.__init__(self, parent)
     # activate the window and use the full screen
     self.setWindowState(Qt.WindowFullScreen | Qt.WindowActive)
     # empty the mouse cursor
     self.setCursor(Qt.BlankCursor)
     # add a menu to close the window
     appmenu = QMenu('&Application', self)
     quit = QAction('&Quit', self)
     appmenu.addAction(quit)
     self.menuBar().addMenu(appmenu)
     quit.triggered.connect(QApplication.instance().quit)
Exemplo n.º 25
0
    def loadContextMenu(self):
        def cmd_loadSelected():
            selObjects = pymel.core.ls(sl=1)
            if not selObjects: return
            cuItem = self.treeWidget.currentItem()
            cuItem.setText(1, selObjects[0].name())

        menu = QMenu(self.treeWidget)
        menu.addAction("Load Object", cmd_loadSelected)
        pos = QCursor.pos()
        point = QtCore.QPoint(pos.x() + 10, pos.y())
        menu.exec_(point)
Exemplo n.º 26
0
 def __init__(self, parent=None):
     QMainWindow.__init__(self, parent)
     # activate the window and use the full screen
     self.setWindowState(Qt.WindowFullScreen | Qt.WindowActive)
     # empty the mouse cursor
     self.setCursor(Qt.BlankCursor)
     # add a menu to close the window
     appmenu = QMenu('&Application', self)
     quit = QAction('&Quit', self)
     appmenu.addAction(quit)
     self.menuBar().addMenu(appmenu)
     quit.triggered.connect(QApplication.instance().quit)
Exemplo n.º 27
0
Arquivo: app.py Projeto: lite/pystut
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
#        self.setObjectName("MainWindow")
        self.resize(731, 475)
        centralwidget = QWidget(self)
#        centralwidget.setObjectName("centralwidget")
        gridLayout = QGridLayout(centralwidget)
#        gridLayout.setObjectName("gridLayout")
        # textEdit needs to be a class variable.
        self.textEdit = QTextEdit(centralwidget)
#        self.textEdit.setObjectName("textEdit")
        gridLayout.addWidget(self.textEdit, 0, 0, 1, 1)
        self.setCentralWidget(centralwidget)
        menubar = QMenuBar(self)
        menubar.setGeometry(QRect(0, 0, 731, 29))
#        menubar.setObjectName("menubar")
        menu_File = QMenu(menubar)
#        menu_File.setObjectName("menu_File")
        self.setMenuBar(menubar)
        statusbar = QStatusBar(self)
#        statusbar.setObjectName("statusbar")
        self.setStatusBar(statusbar)
        actionShow_GPL = QAction(self)
#        actionShow_GPL.setObjectName("actionShow_GPL")
        actionShow_GPL.triggered.connect(self.showGPL)
        action_About = QAction(self)
#        action_About.setObjectName("action_About")
        action_About.triggered.connect(self.about)       
        iconToolBar = self.addToolBar("iconBar.png")
#------------------------------------------------------
# Add icons to appear in tool bar - step 1
        actionShow_GPL.setIcon(QIcon(":/showgpl.png"))
        action_About.setIcon(QIcon(":/about.png"))
        action_Close = QAction(self)
        action_Close.setCheckable(False)
        action_Close.setObjectName("action_Close")       
        action_Close.setIcon(QIcon(":/quit.png"))
#------------------------------------------------------
# Show a tip on the Status Bar - step 2
        actionShow_GPL.setStatusTip("Show GPL Licence")
        action_About.setStatusTip("Pop up the About dialog.")
        action_Close.setStatusTip("Close the program.")
#------------------------------------------------------
        menu_File.addAction(actionShow_GPL)
        menu_File.addAction(action_About)
        menu_File.addAction(action_Close)
        menubar.addAction(menu_File.menuAction())
 
        iconToolBar.addAction(actionShow_GPL)
        iconToolBar.addAction(action_About)
        iconToolBar.addAction(action_Close)
        action_Close.triggered.connect(self.close)
Exemplo n.º 28
0
Arquivo: app.py Projeto: lite/pystut
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        #        self.setObjectName("MainWindow")
        self.resize(731, 475)
        centralwidget = QWidget(self)
        #        centralwidget.setObjectName("centralwidget")
        gridLayout = QGridLayout(centralwidget)
        #        gridLayout.setObjectName("gridLayout")
        # textEdit needs to be a class variable.
        self.textEdit = QTextEdit(centralwidget)
        #        self.textEdit.setObjectName("textEdit")
        gridLayout.addWidget(self.textEdit, 0, 0, 1, 1)
        self.setCentralWidget(centralwidget)
        menubar = QMenuBar(self)
        menubar.setGeometry(QRect(0, 0, 731, 29))
        #        menubar.setObjectName("menubar")
        menu_File = QMenu(menubar)
        #        menu_File.setObjectName("menu_File")
        self.setMenuBar(menubar)
        statusbar = QStatusBar(self)
        #        statusbar.setObjectName("statusbar")
        self.setStatusBar(statusbar)
        actionShow_GPL = QAction(self)
        #        actionShow_GPL.setObjectName("actionShow_GPL")
        actionShow_GPL.triggered.connect(self.showGPL)
        action_About = QAction(self)
        #        action_About.setObjectName("action_About")
        action_About.triggered.connect(self.about)
        iconToolBar = self.addToolBar("iconBar.png")
        #------------------------------------------------------
        # Add icons to appear in tool bar - step 1
        actionShow_GPL.setIcon(QIcon(":/showgpl.png"))
        action_About.setIcon(QIcon(":/about.png"))
        action_Close = QAction(self)
        action_Close.setCheckable(False)
        action_Close.setObjectName("action_Close")
        action_Close.setIcon(QIcon(":/quit.png"))
        #------------------------------------------------------
        # Show a tip on the Status Bar - step 2
        actionShow_GPL.setStatusTip("Show GPL Licence")
        action_About.setStatusTip("Pop up the About dialog.")
        action_Close.setStatusTip("Close the program.")
        #------------------------------------------------------
        menu_File.addAction(actionShow_GPL)
        menu_File.addAction(action_About)
        menu_File.addAction(action_Close)
        menubar.addAction(menu_File.menuAction())

        iconToolBar.addAction(actionShow_GPL)
        iconToolBar.addAction(action_About)
        iconToolBar.addAction(action_Close)
        action_Close.triggered.connect(self.close)
Exemplo n.º 29
0
Arquivo: Menu.py Projeto: wiz21b/koi
    def as_QMenu(self):
        menu = QMenu()
        for item in self._items:

            if isinstance(item, Action):
                a = item.as_QAction()
                a.setEnabled(item.is_enabled())
                menu.addAction(item)

            elif isinstance(item, Menu):
                menu.addMenu(item.as_QMenu())

        return menu
Exemplo n.º 30
0
def main():
    setStyle()
    app = QApplication(sys.argv)
    
    settings = SettingsWindow()
    
    image_output = TestImageOutput(settings)
    ir_board = ir.IrBoard(image_output)
    print u"Версия библиотеки инфракрасная ручка ",ir_board.getVersion()
    
    win = MainWindow(settings)
    win.show()
    
    tray_menu = QMenu()
    tray_menu.addAction(QIcon(':/main/restore.png'), u"Восстановить", win.show)
    tray_menu.addAction(QIcon(':/main/calibrate.png'), u"Калибровка", win.calibrate)
    tray_menu.addAction(QIcon(':/main/cogwheel.png'), u"Настройка", win.settings_window.show)
    tray_menu.addSeparator()
    tray_menu.addAction(QIcon(':/main/close.png'), u"Выход", app.quit)

    tray = QSystemTrayIcon()
    tray.setIcon(QIcon(':/main/webcam.png'))
    tray.setContextMenu(tray_menu)
    tray.show()

    return app.exec_()
Exemplo n.º 31
0
 def send_to_popup(self):
     drive_option=QMenu(self.parent())
     opts=config.SEND_TO[0:(len(config.SEND_TO)-1)]
     for cnf in opts:
         k=QAction(QIcon(appicon("explore")),cnf,self )
         k.triggered.connect(self.click_event)
         drive_option.addAction(k)
     drive_option.exec_(QtGui.QCursor.pos())
     
     
     
     
     
     
Exemplo n.º 32
0
 def __init__(self, repo, selected_items, parent=None):
     super(CommitDialog, self).__init__(parent=parent)
     self.repo = repo
     self.dialog_buttons.button(QDialogButtonBox.Ok).setEnabled(False)
     self.selected_items = selected_items
     if len(selected_items) == 1 and isinstance(selected_items[0],
             WorkspaceDirectory):
         self.root_dir = selected_items[0]
     else:
         self.root_dir = None
     fixed_font = QFont('Courier', self.message_text.font().pointSize())
     fixed_font.setStyleHint(QFont.Monospace)
     self.message_text.setFont(fixed_font)
     self.text_pos_label.setFont(fixed_font)
     with busy_cursor():
         self.staged_changes_model = StagedChangesModel(repo, self.root_dir,
             parent=self)
         self.local_changes_model = LocalChangesModel(repo.workspace,
             parent=self)
         self.local_changes_model.file_source = lambda: tuple(deep_item
             for selected_item in selected_items
             for deep_item in deep_file_list(selected_item)
             if exclude_unmodified(deep_item) and exclude_ignored(deep_item))
         if self.root_dir:
             self.staged_changes_button.setChecked(True)
             self.show_staged_changes()
         else:
             self.local_changes_button.setChecked(True)
             self.show_local_changes()
         if self.repo.head_ref:
             (self.last_commit,) = self.repo.log(max_commits=1)
         else:
             self.last_commit = None
             self.action_reuse_last_msg.setEnabled(False)
             self.action_reuse_log_msg.setEnabled(False)
             self.amend_checkbox.setEnabled(False)
     self.staged_changes_button.clicked.connect(self.show_staged_changes)
     self.local_changes_button.clicked.connect(self.show_local_changes)
     self.local_changes_model.dataChanged.connect(self.local_change_toggled)
     self.message_text.cursorPositionChanged.connect(self.text_pos_changed)
     self.message_text.textChanged.connect(self.message_text_changed)
     reuse_menu = QMenu()
     reuse_menu.addAction(self.action_reuse_last_msg)
     reuse_menu.addAction(self.action_reuse_log_msg)
     self.reuse_msg_button.setDefaultAction(self.action_reuse_last_msg)
     self.reuse_msg_button.setMenu(reuse_menu)
     self.action_reuse_last_msg.triggered.connect(self.reuse_last_message)
     self.action_reuse_log_msg.triggered.connect(self.select_old_message)
     self.amend_checkbox.toggled.connect(self.amend_toggled)
Exemplo n.º 33
0
    def __init__(self, parent=None):
        icon = self.loadIcon()
        QSystemTrayIcon.__init__(self, icon, parent)

        menu = QMenu(parent)
        VBoxMenu.build(menu)
        menu.addSeparator()
        menu.addAction("Exit", lambda: sys.exit(0))
        self.connect(menu, SIGNAL("aboutToShow()"), VBoxMenu.check_state)

        self.setContextMenu(menu)
        self.setToolTip("VBoxTrayIco")

        traySignal = "activated(QSystemTrayIcon::ActivationReason)"
        QObject.connect(self, SIGNAL(traySignal), self.showMenu)
Exemplo n.º 34
0
    def __PlayersListMenu( self, position ):
        list_menu           = QMenu()

        add_player_to_lobby = QAction( self )
        add_player_to_lobby.setText( "Add player to lobby" )
        add_player_to_lobby.triggered.connect( self._AddToLobbyAction )

        rm_player           = QAction( self )
        rm_player.setText( "Remove player" )
        rm_player.triggered.connect( self._RemoveFromPlayersListAction )

        list_menu.addAction( rm_player )
        list_menu.addAction( add_player_to_lobby )

        list_menu.exec_( self.window.players_lst.viewport().mapToGlobal( position ) )
Exemplo n.º 35
0
 def drive_menu(self):
     send_to=QMenu("Send To")
     send_to.setIcon(QIcon(appicon("send_to")))
     for i in self.drives:
         if util.isWindows():
             k=SendtoAction("%s (%s)"%(i[1],i[0][0:2]),i[0],self)
             k.triggered.connect(self.click_event)
             #k.clicked.connect(self.click_drive_menu)
             send_to.addAction(k)
             
         elif util.isLinux():
             k=SendtoAction("%s"%(i[1]),i[0],self)
             k.triggered.connect(self.click_event)
             #k.clicked.connect(self.click_drive_menu)
             send_to.addAction(k)
     return send_to
Exemplo n.º 36
0
 def create_size_menu(self):
     """ Create the toolbar's buttons size menu
     """
     menu = QMenu(self)
     group = QActionGroup(self)
     sizes = (_("Tiny"), 16), (_("Small"), 32), (_("Medium"),
                                                 48), (_("Big"), 64)
     for name, size in sizes:
         action = QAction(name, menu)
         action.setCheckable(True)
         if size == self.base.toolbar_size:
             action.setChecked(True)
         action.triggered.connect(partial(self.set_btn_size, size))
         group.addAction(action)
         menu.addAction(action)
     return menu
Exemplo n.º 37
0
    def showContextMenu(self, pos):
        """
        Shows a context menu to add a node in the graph widget
        """
        gpos = self.graphicsView.mapToGlobal(pos)
        menu = QMenu()
        actionAddNode = menu.addAction("Add Node")
        QAction = menu.exec_(gpos)

        if (actionAddNode == QAction):
            (text,
             ok) = QInputDialog.getText(self.graphicsView, "Insert Node Name",
                                        "Please insert a name for the node")
            if ok:
                if text not in self.nodesToQNodes:
                    #User clicked on ok. Otherwise do nothing
                    self.gv.add_node(text)
                    node = self.gv.get_node(text)
                    qnode = self.createQtNode(node, 0, 0,
                                              QColor(204, 255, 255))

                    self.graphicsView.scene().addItem(qnode)
                    qnode.setPos(self.graphicsView.mapToScene(gpos))
                    qnode.setPos(qnode.x(), qnode.y() - 200)
                    self.nodesToQNodes[node] = qnode
                else:
                    msg = QMessageBox()
                    msg.setText("The node already exists.")
                    msg.exec_()
                self.searchNode(text)
Exemplo n.º 38
0
    def qmenu(self):
        if self._qmenu is not None:
            return self._qmenu

        if self.parent is not None:
            menu = QMenu(self.caption, self.parent)
        else:
            menu = QMenu(self.caption)

        for entry in self.entries:
            if isinstance(entry, MenuEntry):
                action = menu.addAction(entry.caption, entry.action)  # type: QAction
                if entry.shortcut is not None:
                    action.setShortcut(entry.shortcut)
                if entry.checkable:
                    action.setCheckable(True)
                    action.setChecked(entry.checked_initially)
                entry.qaction = action
            elif isinstance(entry, MenuSeparator):
                menu.addSeparator()
            else:
                raise Exception('Unsupported type %s' % type(entry))

        self._qmenu = menu

        return menu
Exemplo n.º 39
0
 def __init__(self, icon, parent=None):
     QSystemTrayIcon.__init__(self, icon, parent)
     self.setToolTip("usb-resetter 1.0 (Left\Right-Click)")
     self.parent = parent
     self.activated.connect(self.toggleP)
     menu = QMenu(parent)
     self.fmenu = QMenu("Fast reset", parent)
     self.fmenu.setToolTip("List of filtered devices to fast reset")
     aboutAction = QAction("About", self)
     aboutAction.triggered.connect(parent.show_about)
     quitAction = QAction("Exit", self)
     quitAction.triggered.connect(parent.exitEvent)
     menu.addMenu(self.fmenu)
     menu.addSeparator()
     menu.addAction(aboutAction)
     menu.addAction(quitAction)
     self.setContextMenu(menu)
Exemplo n.º 40
0
class SystemTrayIcon(QSystemTrayIcon):
    def __init__(self, icon, parent=None):
        QSystemTrayIcon.__init__(self, icon, parent)
        self.setToolTip("usb-resetter 1.0 (Left\Right-Click)")
        self.parent = parent
        self.activated.connect(self.toggleP)
        menu = QMenu(parent)
        self.fmenu = QMenu("Fast reset", parent)
        self.fmenu.setToolTip("List of filtered devices to fast reset")
        aboutAction = QAction("About", self)
        aboutAction.triggered.connect(parent.show_about)
        quitAction = QAction("Exit", self)
        quitAction.triggered.connect(parent.exitEvent)
        menu.addMenu(self.fmenu)
        menu.addSeparator()
        menu.addAction(aboutAction)
        menu.addAction(quitAction)
        self.setContextMenu(menu)

    def toggleP(self, ar):
        actions = [QSystemTrayIcon.ActivationReason.Context,
                   QSystemTrayIcon.ActivationReason.Trigger]
        if ar in actions:
            self.set_Freset()
        else:
            if self.parent.Hidden:
                self.parent.show()
                self.parent.Hidden = None
            else:
                self.parent.hide()
                self.parent.Hidden = True

    def set_Freset(self):
        self.fmenu.clear()
        for l in self.parent.get_list():
            ac = QAction(l, self)

            def actdo(t):
                if resetit(t):
                    self.parent.statusbar.setStyleSheet(self.parent.s_norm)
                    self.parent.statusbar.showMessage(
                        "# Done: usb device got reset")
                    return True
                self.parent.statusbar.setStyleSheet(self.parent.s_error)
            ac.triggered.connect(partial(actdo, l))
            self.fmenu.addAction(ac)
Exemplo n.º 41
0
 def showAttributeMenu(self, attribute):
     m = QMenu()
     m.addAction('Overlay/Filter')
     c = m.addMenu('Compare to')
     for h in self.headers:
         c.addAction(h)
     m.addAction('Sort...')
     choice = m.exec_(QCursor.pos())
     
     if choice != None:
         choice = choice.text()
         if choice == 'Overlay/Filter':
             self.changeOverlay(attribute)
         elif choice == 'Sort...':
             # TODO
             pass
         else:
             self.showScatterplot(choice,attribute)
Exemplo n.º 42
0
 def contextMenuEvent(self, e):
     ''' calls context menu if right click:
      - set server
      - trigger server (storts or stops the server)
     in case of righ click on point, a plot is added
     '''
     i = 0
     for pp in self.points:
         i += 1
         if (e.pos()-pp).manhattanLength() > 5:
             continue
         else:
             self.addPlot(str(i))
             return
     menu = QMenu()
     menu.addAction("Set Server", self.setServer)
     menu.addAction("Trigger Server", self.stream)
     menu.exec_(e.globalPos())
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self._dateEdit = QDateEdit()

        self._dateEdit.setDisplayFormat("dd/MM/yyyy")
        self._bttn = QPushButton("")
        self._bttn.setObjectName("MenuBttn")

        menu = QMenu(self._bttn)
        cal = QCalendarWidget()
        action = QWidgetAction(self._bttn)
        action.setDefaultWidget(cal)
        menu.addAction(action)
        self._bttn.setMenu(menu)
        cal.clicked[QtCore.QDate].connect(self._dateEdit.setDate)

        self.setupUI()
Exemplo n.º 44
0
    def mousePressEvent(self, mouse_event):
        if mouse_event.button() == Qt.RightButton:
            if self._spec_index is None:
                print("spec_index is None")
                print(self)
                print(self._running_providers)
                return
            pos = mouse_event.pos()
            items = [
                item for item in self.items(pos)
                if isinstance(item, NodeItem) and item._label.text()
            ]
            if len(items) != 1:
                print("wrong number of things",
                      [x._label.text() for x in items])
                return

            name = items[0]._label.text().rstrip('(default)').strip()
            if name not in self._spec_index.provider_names:
                print(name, "Not in list of providers")
                return
            provider = self._spec_index.providers[name]

            def start_trigger():
                # TODO: replace 'capability_server' with user provided server name
                service_name = '/{0}/start_capability'.format(
                    'capability_server')
                rospy.wait_for_service(service_name)
                start_capability = rospy.ServiceProxy(service_name,
                                                      StartCapability)
                start_capability(provider.implements, name)

            def stop_trigger():
                # TODO: replace 'capability_server' with user provided server name
                service_name = '/{0}/stop_capability'.format(
                    'capability_server')
                rospy.wait_for_service(service_name)
                stop_capability = rospy.ServiceProxy(service_name,
                                                     StopCapability)
                stop_capability(provider.implements)

            if name not in self._running_providers:
                trigger = start_trigger
                msg = "start => "
            else:
                trigger = stop_trigger
                msg = "stop => "

            menu = QMenu()
            action = menu.addAction(msg + name)
            action.triggered.connect(trigger)
            pos = mouse_event.globalPos()
            pos = QPoint(pos.x(), pos.y())
            menu.exec_(pos)
        else:
            InteractiveGraphicsView.mousePressEvent(self, mouse_event)
Exemplo n.º 45
0
 def testMenu(self):
     self._actionDestroyed = False
     w = QWidget()
     menu = QMenu(w)
     act = menu.addAction("MENU")
     _ref = weakref.ref(act, self.actionDestroyed)
     act = None
     self.assertFalse(self._actionDestroyed)
     menu.clear()
     self.assertTrue(self._actionDestroyed)
Exemplo n.º 46
0
    def __init__(self, parent=None):
        super(Status, self).__init__(parent)
        self.setupUi(self)
        self.base = parent

        self.wait_anim = QMovie(":/stuff/wait.gif")
        self.anim_lbl.setMovie(self.wait_anim)
        self.anim_lbl.hide()

        self.show_menu = QMenu(self)
        for i in [
                self.act_page, self.act_date, self.act_text, self.act_comment
        ]:
            self.show_menu.addAction(i)
            # noinspection PyUnresolvedReferences
            i.triggered.connect(self.on_show_items)
            i.setChecked(True)

        sort_menu = QMenu(self)
        ico_sort = QIcon(":/stuff/sort.png")
        group = QActionGroup(self)

        action = QAction(_("Date"), sort_menu)
        action.setCheckable(True)
        action.setChecked(not self.base.high_by_page)
        action.triggered.connect(self.base.set_highlight_sort)
        action.setData(False)
        group.addAction(action)
        sort_menu.addAction(action)

        action = QAction(_("Page"), sort_menu)
        action.setCheckable(True)
        action.setChecked(self.base.high_by_page)
        action.triggered.connect(self.base.set_highlight_sort)
        action.setData(True)
        group.addAction(action)
        sort_menu.addAction(action)

        sort_menu.setIcon(ico_sort)
        sort_menu.setTitle(_("Sort by"))
        self.show_menu.addMenu(sort_menu)

        self.show_items_btn.setMenu(self.show_menu)
Exemplo n.º 47
0
 def testMenu(self):
     self._actionDestroyed = False
     w = QWidget()
     menu = QMenu(w)
     act = menu.addAction("MENU")
     _ref = weakref.ref(act, self.actionDestroyed)
     act = None
     self.assertFalse(self._actionDestroyed)
     menu.clear()
     self.assertTrue(self._actionDestroyed)
Exemplo n.º 48
0
 def openMenu(self, position):
     self.contextMenu = QMenu()
     newMenu = QMenu("New") 
     self.contextMenu.addMenu(newMenu)
     
     actionNewProj = QAction("NewProject", None)
     actionNewProj.triggered.connect(self.addNode)
     
     actionRename = QAction("Rename", None)
     actionRename.triggered.connect(self.renameNode)
     
     actionRemProj = QAction("Delete", None)
     actionRemProj.triggered.connect(self.removeNode)
     
     newMenu.addAction(actionNewProj)
     self.contextMenu.addAction(actionRename)
     self.contextMenu.addAction(actionRemProj)
     
     #prikaz kontekstnog menija
     self.contextMenu.exec_(self.viewport().mapToGlobal(position))
Exemplo n.º 49
0
class QMenuAddAction(UsesQApplication):
    def setUp(self):
        super(QMenuAddAction, self).setUp()
        self.menu = QMenu()

    def tearDown(self):
        del self.menu
        super(QMenuAddAction, self).tearDown()

    def testAddActionWithoutKeySequenceCallable(self):
        # bug #280
        action = self.menu.addAction(self.app.tr('aaa'), lambda: 1)

    def testAddActionKeySequenceCallable(self):
        # bug #228
        action = self.menu.addAction(self.app.tr('aaa'), lambda: 1,
                                     QKeySequence(self.app.tr('Ctrl+O')))

    def testAddActionKeySequenceSlot(self):
        action = self.menu.addAction('Quit', self.app, SLOT('quit()'),
                                     QKeySequence('Ctrl+O'))
Exemplo n.º 50
0
 def updateRecentFilesMenu(self):
     recentAction = self.fileActions.openRecentAction
     if self.recent_files:
         self.recent_files = [
             filename for filename in self.recent_files
             if filename and os.path.exists(filename)
         ]
     if not self.recent_files:
         recentAction.setEnabled(False)
     else:
         recentAction.setEnabled(True)
         menu = QMenu(self)
         for i, filename in enumerate(self.recent_files, 1):
             action = QAction(
                 QIcon(":/document-open.svg"),
                 "&{} {}".format(i,
                                 QDir.toNativeSeparators(filename)), menu)
             action.triggered.connect(
                 lambda filename=filename: self.openXix(filename))
             menu.addAction(action)
         recentAction.setMenu(menu)
Exemplo n.º 51
0
    def setup_ui(self):
        """ Setup the UI for the window.

        """
        central_widget = QWidget()
        layout = QVBoxLayout()
        layout.addWidget(self.clock_view)
        layout.addWidget(self.message_view)
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

        menubar = self.menuBar()

        file_menu = QMenu('File')

        preferences_action = QAction('Preferences', file_menu)
        preferences_action.triggered.connect(self.on_preferences_triggered)

        quit_action = QAction('Quit', file_menu)
        quit_action.triggered.connect(self.on_quit_triggered)

        file_menu.addAction(preferences_action)
        file_menu.addAction(quit_action)
        menubar.addMenu(file_menu)

        view_menu = QMenu('View')

        fullscreen_action = QAction('Fullscreen', view_menu)
        fullscreen_action.setCheckable(True)
        fullscreen_action.setChecked(Config.get('FULLSCREEN', True))
        fullscreen_action.setShortcut('Ctrl+Meta+F')
        fullscreen_action.toggled.connect(self.on_fullscreen_changed)

        view_menu.addAction(fullscreen_action)
        menubar.addMenu(view_menu)
Exemplo n.º 52
0
 def click(self, res, event):
     """Open resource"""
     button = event.button()
     if button == Qt.LeftButton:
         subprocess.Popen(['xdg-open', res.file_path])
     elif button == Qt.RightButton:
         menu = QMenu(self.parent)
         menu.addAction(
             self.app.translate('ResourceEdit', 'Put to Content'),
             Slot()(partial(
                 self.to_content,
                 res=res,
             )),
         )
         if not self.parent.note_edit.in_content(res):
             menu.addAction(
                 self.app.translate('ResourceEdit', 'Remove Resource'),
                 Slot()(partial(
                     self.remove,
                     res=res,
                 )))
         menu.addAction(self.app.translate('ResourceEdit', 'Save As'),
                        Slot()(partial(
                            self.save,
                            res=res,
                        )))
         menu.exec_(event.globalPos())
Exemplo n.º 53
0
 def click(self, res, event):
     """Open resource"""
     button = event.button()
     if button == Qt.LeftButton:
         subprocess.Popen(['xdg-open', res.file_path])
     elif button == Qt.RightButton:
         menu = QMenu(self.parent)
         if res.mime.find('image') == 0:
             menu.addAction(
                 self.parent.tr('Put to Content'), Slot()(partial(
                     self.to_content, res=res,
                 )),
             )
         if not self.parent.note_edit.in_content(res):
             menu.addAction(
                 self.parent.tr('Remove Resource'), Slot()(partial(
                     self.remove, res=res,
                 ))
             )
         menu.addAction(
             self.parent.tr('Save As'), Slot()(partial(
                 self.save, res=res,
             ))
         )
         menu.exec_(event.globalPos())
Exemplo n.º 54
0
    def _customMenu(self):
        selectedItems = self.pushupsListWidget.selectedItems()

        if selectedItems is not None:
            selectedItem = selectedItems[0]

            if selectedItem.parent() is not None:  # Child Item selected
                menu = QMenu()

                delete = QAction(self.pushupsListWidget)
                delete.setText("Delete this pushup")
                delete.triggered.connect(self._emitDeleteSignal)
                menu.addAction(delete)
                menu.exec_(QCursor.pos())
            else:  # Top level Item selected
                menu = QMenu()

                delete = QAction(self.pushupsListWidget)
                delete.setText("Delete this day and all of its exercises")
                delete.triggered.connect(self._emitDeleteDaySignal)
                menu.addAction(delete)
                menu.exec_(QCursor.pos())
Exemplo n.º 55
0
 def refreshBookmarks(self):
     enable = bool(self.state.model) and self.state.model.hasBookmarks()
     self.gotoActions.bookmarksAction.setEnabled(enable)
     self.bookmarksToolButton.setEnabled(enable)
     if enable:
         menu = QMenu(self)
         accels = collections.deque("123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
         for eid, term, istop in self.state.model.bookmarks():
             term = "{} {}".format(
                 MAIN_INDICATOR if istop else SUB_INDICATOR,
                 Lib.elide(term))
             if accels:
                 term = "&{} {}".format(accels.popleft(), term)
             action = QAction(QIcon(":/bookmark.svg"), term, menu)
             action.triggered.connect(
                 lambda eid=eid: self.gotoActions.gotoEid(eid))
             menu.addAction(action)
         self.gotoActions.bookmarksAction.setMenu(menu)
         self.bookmarksToolButton.setMenu(menu)
     else:
         self.gotoActions.bookmarksAction.setMenu(None)
         self.bookmarksToolButton.setMenu(None)
Exemplo n.º 56
0
    def contextMenuEvent(self, event):
        """
        Create a nice looking popup menu.
        """
        popup_menu = self.createStandardContextMenu()

        cursor = self.textCursor()
        cursor.select(cursor.WordUnderCursor)
        self.setTextCursor(cursor)

        if self.textCursor().hasSelection():
            text = unicode(self.textCursor().selectedText())
            if not self.dict.check(text):
                spell_menu = QMenu('Suggestions')
                for word in self.dict.suggest(text):
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    spell_menu.addAction(action)
                if len(spell_menu.actions()):
                    popup_menu.insertSeparator(popup_menu.actions()[0])
                    popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)

        popup_menu.exec_(event.globalPos())
Exemplo n.º 57
0
def open_new_shader_menu():
    """
    Open menu using QMenu with all maps
    :return: 
    """
    try:
        from PySide.QtGui import QMenu, QAction, QCursor
    except:
        from PySide2.QtGui import QCursor
        from PySide2.QtWidgets import QMenu, QAction
    maps = SuperShader._get_maps()
    if not maps:
        return
    menu = QMenu(hou.ui.mainQtWindow())
    menu.setStyleSheet(hou.ui.qtStyleSheet())
    for m in maps:
        if m.get('allow_creation'):
            menu.addAction(QAction(m['name'], menu))
    act = menu.exec_(QCursor.pos())
    if not act:
        return
    new_shader_map = ([x for x in maps if x['name'] == act.text()] or [None])[0]
    return new_shader_map
Exemplo n.º 58
0
class ColorWidget(QFrame):
    color_changed = Signal(int)

    def __init__(self, parent=None):
        self.color = QColor(0, 0, 0)
        super().__init__(parent)
        self.setFrameStyle(QFrame.Panel | QFrame.Raised)

        dial = QColorDial(self)
        dial.sliderMoved.connect(self.set_color)

        action = QWidgetAction(self)
        action.setDefaultWidget(dial)
        self.menu = QMenu()
        self.menu.addAction(action)

        #self.addAction(action)
        #self.setContextMenuPolicy(Qt.ActionsContextMenu)

    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)
        painter.fillRect(event.rect(), self.color)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.menu.exec_(self.mapToGlobal(event.pos()))

    def sizeHint(self):
        return QSize(24, 20)

    def set_color(self, color):
        self.color = QColor(color, color, color)
        self.color_changed.emit(color)
        self.update()