Esempio n. 1
0
    def executeOnUIThread(cls, callable, waitForResult=False):

        if QtCore.QThread.currentThread() == cls.__qtApplication.thread():
            # Already on the UI thread - just do it.
            return callable()

        resultCondition = threading.Condition() if waitForResult else None

        # we only use a weakref here, because we don't want to be keeping the object
        # alive from this thread, and hence deleting it from this thread. instead it
        # is deleted in _UIThreadExecutor.event().
        uiThreadExecutor = weakref.ref(
            _UIThreadExecutor(callable, resultCondition))
        uiThreadExecutor().moveToThread(cls.__qtApplication.thread())

        if resultCondition is not None:
            resultCondition.acquire()
            cls.__qtApplication.postEvent(
                uiThreadExecutor(),
                QtCore.QEvent(
                    QtCore.QEvent.Type(_UIThreadExecutor.executeEventType)))
            resultCondition.wait()
            resultCondition.release()
            return resultCondition.resultValue
        else:
            cls.__qtApplication.postEvent(
                uiThreadExecutor(),
                QtCore.QEvent(
                    QtCore.QEvent.Type(_UIThreadExecutor.executeEventType)))
            return None
Esempio n. 2
0
 def __init__(self):
     if self.__instance:
         raise Exception("This class is a singleton! Use `instance` method instead.")
     super(QEventHook, self).__init__()
     self.installEventFilter(self)
     event = QtCore.QEvent(QtCore.QEvent.User)
     QtCore.QCoreApplication.postEvent(self, event)
Esempio n. 3
0
 def __init__(self):
     if self.__init_flag:
         self.__init_flag = False
         super(QEventHook, self).__init__()
         self.installEventFilter(self)
         event = QtCore.QEvent(QtCore.QEvent.User)
         QtCore.QCoreApplication.postEvent(self, event)
Esempio n. 4
0
 def __init__(self, binder):
     if self.__init_flag:
         self.__init_flag = False
         super(BinderDispatcher, self).__init__()
         self >> event_hook(QtCore.QEvent.User, self.__bind_cls__)
     event = QtCore.QEvent(QtCore.QEvent.User)
     QtWidgets.QApplication.postEvent(self, event)
Esempio n. 5
0
    def __init__(self, binder, db_name, filters=None):
        if self._dumper_dict_.get(id(binder)):
            raise Exception("This class is a singleton! Use `instance` method instead.")
        super(BinderDumper, self).__init__()
        self.binder = binder
        self.db_name = db_name
        self._filters_ = (
            {filters}
            if isinstance(filters, str)
            else set(filters)
            if isinstance(filters, Iterable)
            else set()
        )
        folder = os.path.join(tempfile.gettempdir(), "QBinder")
        if not os.path.isdir(folder):
            os.mkdir(folder)
        self.path = os.path.join(folder, "%s.json" % db_name)

        # NOTE using timer call the __prepare__ in the next evnet loop (for loading delay)
        self >> event_hook(
            QtCore.QEvent.User, lambda: QtCore.QTimer.singleShot(0, self.__prepare__)
        )
        event = QtCore.QEvent(QtCore.QEvent.User)
        QtWidgets.QApplication.postEvent(self, event)

        self.auto_load = True
Esempio n. 6
0
 def __init__(self):
     if self.__instance:
         raise Exception("This class is a singleton! Use `instance` method instead.")
     super(BinderDispatcher, self).__init__()
     self >> event_hook(QtCore.QEvent.User, self.__bind_cls__)
     event = QtCore.QEvent(QtCore.QEvent.User)
     QtWidgets.QApplication.postEvent(self, event)
Esempio n. 7
0
    def get_current_Binders(self):
        uid = uuid.uuid4()
        if self.Binders:
            last_uid = list(self.Binders.keys())[-1]
            if self.__flag__:
                uid = last_uid
                self >> event_hook(QtCore.QEvent.User, lambda: self.set_flag(False))
                event = QtCore.QEvent(QtCore.QEvent.User)
                QtWidgets.QApplication.postEvent(self, event)
            else:
                self.set_flag(True)

        BinderCollector.Binders.setdefault(uid, [])
        return BinderCollector.Binders[uid]
    def __init__(self, items=None):
        """
        Base custom QMenu
        """
        QtWidgets.QMenu.__init__(self)

        # Transparency is set to false on some linux systems that do not support it.
        #             A mask will be used if transparency is not supported
        self.transparent = self.testSystemTransparentSupport()
        # Draw cursor line - If true a line is drawn from the center to the cursor
        self.draw_cursor_line = True
        # Erase cursor line - Controls when the cursor line is painted.
        self.erase_cursor_line = False
        # Filter used when the qApp's mouse press event is needed to show the menu
        self.mousePressFilter = None

        # Window settings
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint
                            | QtCore.Qt.NoDropShadowWindowHint)
        if self.transparent:
            self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

        # Ratio for different screen sizes
        self.screen_ratio = get_screen_ratio()

        # Dimensions
        self.width = 1000 * self.screen_ratio
        self.height = 2000 * self.screen_ratio
        self.setFixedSize(self.width, self.height)

        # Timer for gestures
        self.timer = QtCore.QTimer()
        self.timer.setTimerType(QtCore.Qt.PreciseTimer)
        self.timer.timeout.connect(self.trackCursor)
        self.timer.setInterval(2)

        # Turns off when the cursor stops moving
        self.gesture = True

        # Main painter
        self.painter = QtGui.QPainter()
        # Mask painter
        self.painterMask = QtGui.QPainter()
        self.maskPixmap = QtGui.QPixmap(self.width, self.height)
        self.maskPixmap.fill(QtCore.Qt.white)
        # Track if mask has been set
        self.isMaskSet = False
        # Radius of origin circle
        self.originRadius = 8.0 * self.screen_ratio
        # Right click widget - Stores the mouse press event of the widget
        #                      the menu is opened from when right clicked
        self.right_click_widget_mouse_press_event = None
        # Stores which item is active
        self.activeItem = None
        # Pens
        gray = QtGui.QColor(128, 128, 128, 255)
        self.penOrigin = QtGui.QPen(gray, 5, QtCore.Qt.SolidLine)
        self.penCursorLine = QtGui.QPen(gray, 3, QtCore.Qt.SolidLine)
        self.penBlack = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine)
        self.penActive = QtGui.QPen(QtCore.Qt.red, 20, QtCore.Qt.SolidLine)
        self.penWhite = QtGui.QPen(QtCore.Qt.white, 5, QtCore.Qt.SolidLine)
        self.transparentPen = QtGui.QPen(QtCore.Qt.transparent, 5000)

        ##########################################################
        # Items
        ##########################################################
        self.itemHeight = 40.0 * self.screen_ratio
        self.items = list()
        # Events sent to items to highlight them
        self.leaveButtonEvent = QtCore.QEvent(QtCore.QEvent.Leave)
        self.enterButtonEvent = QtCore.QEvent(QtCore.QEvent.Enter)

        # Radial item positions relative to center of radial menu
        r = self.screen_ratio
        self.position_xy = {
            'N': [0 * r, -100 * r],
            'S': [0 * r, 100 * r],
            'E': [120 * r, 0 * r],
            'W': [-120 * r, 0 * r],
            'NE': [85 * r, -45 * r],
            'NW': [-85 * r, -45 * r],
            'SE': [85 * r, 45 * r],
            'SW': [-85 * r, 45 * r]
        }
        # Slices - Each number represents a 22.5 degree slice, so each
        #          position gets a 45 degree slice of the pie
        self.slices = {
            'E': [15, 0],
            'SE': [1, 2],
            'S': [3, 4],
            'SW': [5, 6],
            'W': [7, 8],
            'NW': [9, 10],
            'N': [11, 12],
            'NE': [13, 14]
        }

        # Column widget
        self.column_widget = QtWidgets.QWidget()
        self.column_widget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents)
        self.column_widget.setParent(self)
        self.column_widget.items = list()
        self.column_widget.rects = list()

        # Draw radial menu and its mask
        self.column_widget_rect = None
        self.paintMask()
Esempio n. 9
0
 def __init__(self):
     super(PanelEvent, self).__init__()
     event = QtCore.QEvent(QtCore.QEvent.User)
     QtWidgets.QApplication.postEvent(self, event)
     self.installEventFilter(self)