Exemplo n.º 1
0
 def PopupMenu( self, window: QW.QWidget, menu: QW.QMenu ):
     
     if HC.PLATFORM_MACOS and window.window().isModal():
         
         # Ok, seems like Big Sur can't do menus at the moment lmao. it shows the menu but the mouse can't interact with it
         
         from hydrus.core import HydrusGlobals as HG
         
         if HG.client_controller.new_options.GetBoolean( 'do_macos_debug_dialog_menus' ):
             
             from hydrus.client.gui import ClientGUICoreMenuDebug
             
             ClientGUICoreMenuDebug.ShowMenuDialog( window, menu )
             
             ClientGUIMenus.DestroyMenu( menu )
             
             return
             
         
     
     if not menu.isEmpty():
         
         self._menu_open = True
         
         menu.exec_( QG.QCursor.pos() ) # This could also be window.mapToGlobal( QC.QPoint( 0, 0 ) ), but in practice, popping up at the current cursor position feels better.
         
         self._menu_open = False
         
     
     ClientGUIMenus.DestroyMenu( menu )
Exemplo n.º 2
0
 def test_add_actions_with_qmenu_target(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_menu = QMenu()
     add_actions(test_menu, [test_act_1, test_act_2])
     self.assertFalse(test_menu.isEmpty())
Exemplo n.º 3
0
 def test_add_actions_with_qmenu_target(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_menu = QMenu()
     add_actions(test_menu, [test_act_1, test_act_2])
     self.assertFalse(test_menu.isEmpty())
Exemplo n.º 4
0
class FilterWidget(filterBase):
    __clsName = "LocFilter"
    filterChangeDelay = 200

    varNameRex = re.compile(r"\{(\w*)\}")

    def tr(self, string):
        return QCoreApplication.translate(self.__clsName, string)

    def __init__(self, parent=None):
        super().__init__(parent)
        self._ui = filterClass()
        self._ui.setupUi(self)

        self._delayTimer = QTimer(self)
        self._delayTimer.setInterval(self.filterChangeDelay)
        self._delayTimer.setSingleShot(True)
        if not (qtpy.PYQT4 or qtpy.PYSIDE):
            self._delayTimer.setTimerType(Qt.PreciseTimer)
        self._delayTimer.timeout.connect(self.filterChanged)

        self._ui.filterEdit.textChanged.connect(self._delayTimer.start)

        self._menu = QMenu()
        self._menu.triggered.connect(self._addVariable)

    filterChanged = Signal()

    @Slot(list)
    def setVariables(self, var):
        self._menu.clear()
        for v in var:
            self._menu.addAction(v)

    def setFilterString(self, filt):
        self._ui.filterEdit.setPlainText(filt)

    @Property(str, fset=setFilterString, doc="String describing the filter")
    def filterString(self):
        s = self._ui.filterEdit.toPlainText()
        return self.varNameRex.subn("\\1", s)[0]

    def getFilter(self):
        filterStr = self.filterString
        filterStrList = filterStr.split("\n")

        def filterFunc(data):
            filter = np.ones(len(data), dtype=bool)
            for f in filterStrList:
                with suppress(Exception):
                    filter &= data.eval(f, local_dict={}, global_dict={})
            return filter

        return filterFunc

    @Slot(QAction)
    def _addVariable(self, act):
        self._ui.filterEdit.textCursor().insertText(act.text())

    @Slot(str)
    def on_showVarLabel_linkActivated(self, link):
        if not self._menu.isEmpty():
            self._menu.exec(QCursor.pos())