From 8d41c037e4f463aa64385ef0a9ccff4cf57b8493 Mon Sep 17 00:00:00 2001 From: Paul Ebbers Date: Sun, 12 Jan 2025 20:17:08 +0100 Subject: [PATCH] fix import PySide6 --- SearchBox.py | 72 ++++++++++++++-------------------------------------- 1 file changed, 19 insertions(+), 53 deletions(-) diff --git a/SearchBox.py b/SearchBox.py index b9d07ad..c78c0d4 100644 --- a/SearchBox.py +++ b/SearchBox.py @@ -2,14 +2,14 @@ import FreeCAD as App import FreeCADGui as Gui import os -from PySide6.QtCore import ( +from PySide.QtCore import ( Qt, SIGNAL, QSize, QIdentityProxyModel, QPoint, ) -from PySide6.QtWidgets import ( +from PySide.QtWidgets import ( QTabWidget, QSlider, QSpinBox, @@ -28,7 +28,7 @@ from PySide6.QtWidgets import ( QApplication, QListWidget, ) -from PySide6.QtGui import ( +from PySide.QtGui import ( QIcon, QPixmap, QColor, @@ -91,9 +91,7 @@ class SearchBox(QLineEdit): self.getItemGroups = getItemGroups self.getToolTip = getToolTip self.itemGroups = None # Will be initialized by calling getItemGroups() the first time the search box gains focus, through focusInEvent and refreshItemGroups - self.maxVisibleRows = ( - maxVisibleRows # TODO: use this to compute the correct height - ) + self.maxVisibleRows = maxVisibleRows # TODO: use this to compute the correct height # Create proxy model self.proxyModel = QIdentityProxyModel() # Filtered model to which items are manually added. Store it as a property of the object instead of a local variable, to prevent grbage collection. @@ -105,9 +103,7 @@ class SearchBox(QLineEdit): self.listView.setWindowFlag(Qt.WindowType.FramelessWindowHint) self.listView.setSelectionMode(self.listView.SelectionMode.SingleSelection) self.listView.setModel(self.proxyModel) - self.listView.setItemDelegate( - getItemDelegate() - ) # https://stackoverflow.com/a/65930408/324969 + self.listView.setItemDelegate(getItemDelegate()) # https://stackoverflow.com/a/65930408/324969 self.listView.setMouseTracking(True) # make the QListView non-editable self.listView.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) @@ -137,18 +133,10 @@ class SearchBox(QLineEdit): # Note: should probably use the eventFilter method instead... wdgctx = Qt.ShortcutContext.WidgetShortcut - QShortcut( - QKeySequence(Qt.Key.Key_Down), self, context=wdgctx - ).activated.connect(self.listDown) - QShortcut(QKeySequence(Qt.Key.Key_Up), self, context=wdgctx).activated.connect( - self.listUp - ) - QShortcut( - QKeySequence(Qt.Key.Key_PageDown), self, context=wdgctx - ).activated.connect(self.listPageDown) - QShortcut( - QKeySequence(Qt.Key.Key_PageUp), self, context=wdgctx - ).activated.connect(self.listPageUp) + QShortcut(QKeySequence(Qt.Key.Key_Down), self, context=wdgctx).activated.connect(self.listDown) + QShortcut(QKeySequence(Qt.Key.Key_Up), self, context=wdgctx).activated.connect(self.listUp) + QShortcut(QKeySequence(Qt.Key.Key_PageDown), self, context=wdgctx).activated.connect(self.listPageDown) + QShortcut(QKeySequence(Qt.Key.Key_PageUp), self, context=wdgctx).activated.connect(self.listPageUp) # Home and End do not work, for some reason. # QShortcut(QKeySequence.MoveToEndOfDocument, self, context = wdgctx).activated.connect(self.listEnd) @@ -156,25 +144,13 @@ class SearchBox(QLineEdit): # QShortcut(QKeySequence(Qt.Key.Key_End), self, context = wdgctx).activated.connect(self.listEnd) # QShortcut(QKeySequence('Home'), self, context = wdgctx).activated.connect(self.listStart) - QShortcut( - QKeySequence(Qt.Key.Key_Enter), self, context=wdgctx - ).activated.connect(self.listAccept) - QShortcut( - QKeySequence(Qt.Key.Key_Return), self, context=wdgctx - ).activated.connect(self.listAccept) - QShortcut(QKeySequence("Ctrl+Return"), self, context=wdgctx).activated.connect( - self.listAcceptToggle - ) - QShortcut(QKeySequence("Ctrl+Enter"), self, context=wdgctx).activated.connect( - self.listAcceptToggle - ) - QShortcut(QKeySequence("Ctrl+Space"), self, context=wdgctx).activated.connect( - self.listAcceptToggle - ) + QShortcut(QKeySequence(Qt.Key.Key_Enter), self, context=wdgctx).activated.connect(self.listAccept) + QShortcut(QKeySequence(Qt.Key.Key_Return), self, context=wdgctx).activated.connect(self.listAccept) + QShortcut(QKeySequence("Ctrl+Return"), self, context=wdgctx).activated.connect(self.listAcceptToggle) + QShortcut(QKeySequence("Ctrl+Enter"), self, context=wdgctx).activated.connect(self.listAcceptToggle) + QShortcut(QKeySequence("Ctrl+Space"), self, context=wdgctx).activated.connect(self.listAcceptToggle) - QShortcut( - QKeySequence(Qt.Key.Key_Escape), self, context=wdgctx - ).activated.connect(self.listCancel) + QShortcut(QKeySequence(Qt.Key.Key_Escape), self, context=wdgctx).activated.connect(self.listCancel) # Initialize the model with the full list (assuming the text() is empty) # self.proxyFilterModel(self.text()) # This is done by refreshItemGroups on focusInEvent, because the initial loading from cache can take time @@ -221,9 +197,7 @@ class SearchBox(QLineEdit): [ QStandardItem( genericToolIcon, - translate( - "SearchBar", "Please wait, loading results from cache…" - ), + translate("SearchBar", "Please wait, loading results from cache…"), ), QStandardItem("0"), QStandardItem("-1"), @@ -275,17 +249,11 @@ class SearchBox(QLineEdit): @staticmethod def proxyListPageDown(self): - self.movementKey( - lambda current, nbRows: min( - current + max(1, self.maxVisibleRows / 2), nbRows - 1 - ) - ) + self.movementKey(lambda current, nbRows: min(current + max(1, self.maxVisibleRows / 2), nbRows - 1)) @staticmethod def proxyListPageUp(self): - self.movementKey( - lambda current, nbRows: max(current - max(1, self.maxVisibleRows / 2), 0) - ) + self.movementKey(lambda current, nbRows: max(current - max(1, self.maxVisibleRows / 2), 0)) @staticmethod def proxyListEnd(self): @@ -422,9 +390,7 @@ class SearchBox(QLineEdit): def getScreenPosition(widget): geo = widget.geometry() parent = widget.parent() - parentPos = ( - getScreenPosition(parent) if parent is not None else QPoint(0, 0) - ) + parentPos = getScreenPosition(parent) if parent is not None else QPoint(0, 0) return QPoint(geo.x() + parentPos.x(), geo.y() + parentPos.y()) pos = getScreenPosition(self)