Example #1
0
 def mouseReleaseEvent(self, event):
     done = False
     if (QApplication.mouseButtons() & Qt.LeftButton
             and self.receivers(self.l_clicked_anywhere) > 0):
         done = True
     if (QApplication.mouseButtons() & Qt.MidButton
             and self.receivers(self.m_clicked_anywhere) > 0):
         done = True
     if (QApplication.mouseButtons() & Qt.RightButton
             and self.receivers(self.r_clicked_anywhere) > 0):
         done = True
     if not done:
         QTreeWidget.mouseReleaseEvent(self, event)
Example #2
0
 def mousePressEvent(self, event):
     done = False
     if (QApplication.mouseButtons() & Qt.LeftButton
             and self.receivers(self.l_clicked_anywhere) > 0):
         self.l_clicked_anywhere.emit(event.globalPos())
         done = True
     if (QApplication.mouseButtons() & Qt.MidButton
             and self.receivers(self.m_clicked_anywhere) > 0):
         self.m_clicked_anywhere.emit(event.globalPos())
         done = True
     if (QApplication.mouseButtons() & Qt.RightButton
             and self.receivers(self.r_clicked_anywhere) > 0):
         self.r_clicked_anywhere.emit(event.globalPos())
         done = True
     if not done:
         QTreeWidget.mousePressEvent(self, event)
Example #3
0
 def _check_input(self):
     if not self._term_em.open_connection():
         self._stop_timer()
         return
     self._conn.step_x11()
     self._term_em.receive()
     line_nums = self._term_em.dirty_lines()
     if line_nums:
         for line_num in line_nums:
             line = self._term_em.get_line(line_num)
             # replace line
             cursor: QTextCursor = self.textCursor()
             cursor.movePosition(QTextCursor.Start)
             cursor.movePosition(QTextCursor.Down, QTextCursor.MoveAnchor, line_num)
             cursor.select(QTextCursor.LineUnderCursor)
             cursor.insertText(line)
             self.setTextCursor(cursor)
         self._term_em.clear_dirty()
     x, y = self._term_em.get_cursor()
     curs: QTextCursor = self.textCursor()
     new_position = x + (self._width + 1) * y
     if not curs.hasSelection() and QApplication.mouseButtons() == Qt.NoButton:
         if curs.position() != new_position:
             curs.setPosition(new_position)
             self.setTextCursor(curs)
Example #4
0
    def updateModifiers(self, event):
        """
        Handle all canvas keyboard modifiers in one place.
        """

        if type(event) == QMouseEvent:
            buttons = event.buttons()
        else:
            buttons = QApplication.mouseButtons()

        if type(event) == QKeyEvent:
            modifiers = event.modifiers()
        else:
            modifiers = QApplication.keyboardModifiers()

        # allow only clean modifiers, no combos
        wantMultiSelect = (modifiers == Qt.ControlModifier)
        self.isMultiSelect = wantMultiSelect and ((buttons == Qt.NoButton) or
                                                  (buttons == Qt.LeftButton))
        wantPanning = (modifiers == Qt.ShiftModifier)
        self.isPanning = wantPanning and (buttons == Qt.LeftButton)
        wantRotating = (modifiers == Qt.AltModifier)
        self.isRotating = wantRotating and (buttons == Qt.LeftButton)

        if self.isPanning or self.isRotating:
            self.setCursor(Qt.ClosedHandCursor)
        elif wantPanning:
            self.setCursor(Qt.OpenHandCursor)
        elif wantRotating:
            self.setCursor(Qt.PointingHandCursor)
        elif wantMultiSelect:
            self.setCursor(Qt.CrossCursor)
        else:
            self.unsetCursor()
Example #5
0
 def __linkActivated(self, url):
     """
     Private slot handling the activation of an entry.
     
     @param url URL of the activated entry
     @type QUrl
     """
     if not url.isEmpty() and url.isValid():
         buttons = QApplication.mouseButtons()
         modifiers = QApplication.keyboardModifiers()
         
         if buttons & Qt.MidButton:
             self.newTab.emit(url)
         else:
             if (
                 modifiers & (Qt.ControlModifier | Qt.ShiftModifier) ==
                     (Qt.ControlModifier | Qt.ShiftModifier)
             ):
                 self.newBackgroundTab.emit(url)
             elif modifiers & Qt.ControlModifier:
                 self.newTab.emit(url)
             elif modifiers & Qt.ShiftModifier:
                 self.newWindow.emit(url)
             else:
                 self.openUrl.emit(url)
Example #6
0
 def mouseReleaseEvent(self, event):
     done = False
     if (
             QApplication.mouseButtons() & Qt.LeftButton and 
             self.receivers(self.l_clicked_anywhere) > 0):
         done = True
     if (
             QApplication.mouseButtons() & Qt.MidButton and 
             self.receivers(self.m_clicked_anywhere) > 0):
         done = True
     if (
             QApplication.mouseButtons() & Qt.RightButton and 
             self.receivers(self.r_clicked_anywhere) > 0):
         done = True
     if not done:
         QTreeWidget.mouseReleaseEvent(self, event)
Example #7
0
 def scrollContentsBy(self, dx, dy):
     super(MouseTrackerTextEdit, self).scrollContentsBy(dx, dy)
     self.scrollbar_displacement += dy
     event = QMouseEvent(QEvent.MouseMove, QPoint(self.x,
                                                  self.y), Qt.NoButton,
                         QApplication.mouseButtons(), Qt.NoModifier)
     self.mouseMoveEvent(event)
     print(self.scrollbar_displacement)
Example #8
0
 def eventFilter(self, obj, event):
     if obj == self:
         if QApplication.mouseButtons() == Qt.LeftButton:
             self.setSelectedSection(QDateTimeEdit.DaySection)
             return True
         else:
             return False
     else:
         return PyDateEdit.eventFilter(obj, event)
Example #9
0
 def mousePressEvent(self, event):
     done = False
     if (
             QApplication.mouseButtons() & Qt.LeftButton and 
             self.receivers(self.l_clicked_anywhere) > 0):
         self.l_clicked_anywhere.emit(event.globalPos())
         done = True
     if (
             QApplication.mouseButtons() & Qt.MidButton and 
             self.receivers(self.m_clicked_anywhere) > 0):
         self.m_clicked_anywhere.emit(event.globalPos())
         done = True
     if (
             QApplication.mouseButtons() & Qt.RightButton and 
             self.receivers(self.r_clicked_anywhere) > 0):
         self.r_clicked_anywhere.emit(event.globalPos())
         done = True
     if not done:
         QTreeWidget.mousePressEvent(self, event)
Example #10
0
 def on_proxy_select(self):
     button = QApplication.mouseButtons()
     index = self.ui.proxyListView.currentIndex().row()
     name = self.PL_table_model.mylist[index][0]
     piority = self.PL_table_model.mylist[index][2]
     self.load_proxy_by_name(name)
     self.ui.priorityEdit.setText(str(piority))
     if button == Qt.RightButton:
         proxy = self.get_proxy_by_name(name)
         QApplication.instance().clipboard().setText(proxy)
         self.statusBar().showMessage('proxy copied to clipboard', 3000)
Example #11
0
 def _post_mouse_event(self, type, button, x, y):
     q_button = {
         # TODO perhaps add right button here
         "left": Qt.LeftButton,
         "nobutton": Qt.NoButton,
     }.get(button)
     point = QPointF(x, y)
     buttons = QApplication.mouseButtons()
     modifiers = QApplication.keyboardModifiers()
     event = QMouseEvent(type, point, q_button, buttons, modifiers)
     QApplication.postEvent(self.web_page, event)
Example #12
0
 def _post_mouse_event(self, type, button, x, y):
     q_button = {
         # TODO perhaps add right button here
         "left": Qt.LeftButton,
         "nobutton": Qt.NoButton,
     }.get(button)
     point = QPointF(x, y)
     buttons = QApplication.mouseButtons()
     modifiers = QApplication.keyboardModifiers()
     event = QMouseEvent(type, point, q_button, buttons, modifiers)
     QApplication.postEvent(self.web_page, event)
Example #13
0
    def mouseMoveEvent(self, event):
        modifierPressed = QApplication.keyboardModifiers()
        Mmodo = QApplication.mouseButtons()

        if event.buttons() & QtCore.Qt.LeftButton and self.current_poly and not self.selection_mode and not self.modify_mode:
            r = QtCore.QRectF(self.current_poly_begin, event.scenePos()).normalized()
            self.current_poly.setPolygon(QtGui.QPolygonF(r))
            self.current_poly_size.setPos(event.scenePos() - QtCore.QPointF(0, 11))
            self.current_poly_size.setText(f"({int(r.width())} x {int(r.height())})")

        if (event.buttons() & QtCore.Qt.RightButton) and not (event.buttons() & QtCore.Qt.LeftButton):
            delta = event.lastScreenPos() - event.screenPos()
            x = self.view.horizontalScrollBar().value() + delta.x()
            y = self.view.verticalScrollBar().value() + delta.y()
            self.view.horizontalScrollBar().setValue(x)
            self.view.verticalScrollBar().setValue(y)

        #  and
        if (bool(Mmodo == QtCore.Qt.LeftButton)) and (bool(modifierPressed == Qt.ShiftModifier)) and self.current_poly and self.shift_mode and self.modify_mode and not self.selection_mode:
            r = QtCore.QRectF(self.current_poly_begin, event.scenePos()).normalized()
            self.current_poly.setPolygon(QtGui.QPolygonF(r))
            self.current_poly_size.setPos(event.scenePos() - QtCore.QPointF(0, 11))
            self.current_poly_size.setText(f"({int(r.width())} x {int(r.height())})")

        x = event.scenePos().x()
        y = event.scenePos().y()
        scene_min = self.view.mapToScene(0, 0)
        scene_max = self.view.mapToScene(self.view.width(), self.view.height())
        x_min = scene_min.x()
        y_min = scene_min.y()
        x_max = scene_max.x()
        y_max = scene_max.y()

        if not self.current_vertical_line:
            self.current_vertical_line = self.addLine(x, y_min, x, y_max, QtGui.QPen(QtCore.Qt.gray, 1))
            self.current_vertical_line.setZValue(0.5)
        else:
            self.current_vertical_line.setLine(x, y_min, x, y_max)
        if not self.current_horizontal_line:
            self.current_horizontal_line = self.addLine(x_min, y, x_max, y, QtGui.QPen(QtCore.Qt.gray, 1))
            self.current_horizontal_line.setZValue(0.5)
        else:
            self.current_horizontal_line.setLine(x_min, y, x_max, y)

        return super().mouseMoveEvent(event)
Example #14
0
    def itemChange(self, change, value):

        if ((change == QGraphicsItem.ItemPositionChange)
                and (self.scene() != None)):
            newPos = value

            if (QApplication.mouseButtons() == Qt.LeftButton
                    and self.scene() != None and self.scene().snap):
                gridSize = self.scene().gridSize
                xV = round(newPos.x() / gridSize) * gridSize
                yV = round(newPos.y() / gridSize) * gridSize
                return QPointF(xV, yV)

            else:

                return newPos

        else:
            return QGraphicsItem.itemChange(self, change, value)
Example #15
0
    def itemChange(self, change: QGraphicsItem.GraphicsItemChange,
                   value: Union[QPointF]) -> Any:
        """
        Handle component's view changes. Snap to grid in case of item position change.

        Args:
            change: Item change type
            value: Value of the change

        Returns:
            Changed value
        """
        if change == QGraphicsItem.ItemPositionChange:
            new_position: QPointF = value
            if QApplication.mouseButtons() == Qt.LeftButton:
                return snap_to_grid(grid_size=25, new_position=new_position)
            else:
                return new_position
        else:
            return super().itemChange(change, value)
Example #16
0
    def timerEvent(self, ev) -> None:
        if ev.timerId() == self._mouse_move_timer:
            buttons = QApplication.mouseButtons()
            if not buttons & Qt.LeftButton:
                # dispose the widget when the mouse button is released
                self.hide()
                self.killTimer(self._mouse_move_timer)
                self._mouse_move_timer = None
            else:
                # update the mouse position
                pos = QCursor.pos()
                x = pos.x() + 16
                y = pos.y() - 12
                self.move(x, y)

                # FIXME: Qt-bug? .keyboardModifiers() doesn't update until
                # the mouse is moved. .queryKeyboardModifiers() reads
                # straight from the input device and updates properly.
                modifiers = QApplication.queryKeyboardModifiers()

                old_text = self._text

                if modifiers & Qt.ControlModifier and modifiers & Qt.ShiftModifier:
                    self._text = "Link"
                elif modifiers & Qt.ControlModifier:
                    self._text = "Copy"
                elif modifiers & Qt.ShiftModifier:
                    self._text = "Move"
                elif modifiers & Qt.AltModifier:
                    self._text = "Link"
                else:
                    self._text = None

                if old_text != self._text:
                    if self._text is None:
                        # print("Hide")
                        self.hide()
                    else:
                        # print("Show")
                        self.show()
                        self.repaint()
Example #17
0
    def timerEvent(self, ev) -> None:
        if ev.timerId() == self._mouse_move_timer:
            buttons = QApplication.mouseButtons()
            if not buttons & Qt.LeftButton:
                # dispose the widget when the mouse button is released
                self.hide()
                self.killTimer(self._mouse_move_timer)
                self._mouse_move_timer = None
            else:
                # update the mouse position
                pos = QCursor.pos()
                x = pos.x() + 16
                y = pos.y() - 12
                self.move(x, y)

                # FIXME: Qt-bug? .keyboardModifiers() doesn't update until
                # the mouse is moved. .queryKeyboardModifiers() reads
                # straight from the input device and updates properly.
                modifiers = QApplication.queryKeyboardModifiers()

                old_text = self._text

                if modifiers & Qt.ControlModifier and modifiers & Qt.ShiftModifier:
                    self._text = "Link"
                elif modifiers & Qt.ControlModifier:
                    self._text = "Copy"
                elif modifiers & Qt.ShiftModifier:
                    self._text = "Move"
                elif modifiers & Qt.AltModifier:
                    self._text = "Link"
                else:
                    self._text = None

                if old_text != self._text:
                    if self._text is None:
                        # print("Hide")
                        self.hide()
                    else:
                        # print("Show")
                        self.show()
                        self.repaint()
Example #18
0
	def updateDragPosition ( self ):
		if not self.dragInProgress (): return
		if not QApplication.mouseButtons () & Qt.LeftButton :
			self.finishDrag ()
			return

		pos = QCursor.pos ()
		self.dragIndicator.move ( pos + QPoint (1, 1) )
		foundWrapper = False
		window = QApplication.topLevelAt ( pos )
		for wrapper in self.wrappers:
			if wrapper.window () == window:
				if wrapper.rect ().contains ( wrapper.mapFromGlobal (pos) ):
					self.findSuggestions ( wrapper )
					if len ( self.suggestions ) > 0:
						#starting or restarting timer
						if self.dropSuggestionSwitchTimer.isActive ():
							self.dropSuggestionSwitchTimer.stop ()
						self.dropSuggestionSwitchTimer.start ()
						foundWrapper = True
				break
		if not foundWrapper:
			self.handleNoSuggestions ()
    def itemChange(self, change, value):
        if change == self.ItemPositionChange:
            self._lastPos = self.pos()
            if self.snapToGrid() and self.scene() and self.scene().gridEnabled(
            ):
                if QApplication.mouseButtons() == Qt.LeftButton and self.scene(
                ):
                    grid_sizex = self.scene().gridSizeX()
                    grid_sizey = self.scene().gridSizeY()
                    o = self.scene().gridOrigin()
                    ox = o.x() % grid_sizex
                    oy = o.y() % grid_sizey

                    x = round(value.x() / grid_sizex) * grid_sizex
                    y = round(value.y() / grid_sizey) * grid_sizey
                    value = QPointF(x + ox, y + oy)
            return value
        elif change == self.ItemPositionHasChanged:
            delta = value - self._lastPos
            self.positionChanged.emit(value)
            self.positionChangedDelta.emit(delta)
            return value
        else:
            return super().itemChange(change, value)
Example #20
0
 def mousePressEvent(self, ev):
     if QApplication.mouseButtons() & Qt.LeftButton:
         self.clicked.emit()
Example #21
0
 def itemPressed(self, index):
     item = self.result_model.itemFromIndex(index)
     if QApplication.mouseButtons() == Qt.LeftButton:
         self.showItem(item)
Example #22
0
 def itemPressed(self, index):
     item = self.result_model.itemFromIndex(index)
     if QApplication.mouseButtons() == Qt.LeftButton:
         self.showItem(item)