From f35228c43f038c48d8dcd0242a0591f3eb90f24d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 18:32:25 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- BuiltInSearchResults.py | 116 ++++++++++++++++-------- InitGui.py | 22 ++++- README.md | 4 +- RefreshTools.py | 10 +- Resources/Icons/Tango-System-search.svg | 2 +- ResultsDocument.py | 25 ++++- ResultsPreferences.py | 7 +- ResultsToolbar.py | 45 +++++++-- SafeViewer.py | 23 +++-- SearchBox.py | 69 ++++++++++---- SearchBoxLight.py | 8 +- SearchResults.py | 18 ++-- Serialize_SearchBar.py | 26 +++++- package.xml | 22 ++--- 14 files changed, 291 insertions(+), 106 deletions(-) diff --git a/BuiltInSearchResults.py b/BuiltInSearchResults.py index c35be2d..50af4cb 100644 --- a/BuiltInSearchResults.py +++ b/BuiltInSearchResults.py @@ -3,40 +3,84 @@ import SearchResults -SearchResults.registerResultProvider('refreshTools', - getItemGroupsCached = lambda: __import__('ResultsRefreshTools').refreshToolsResultsProvider(), - getItemGroupsUncached = lambda: []) -SearchResults.registerResultProvider('document', - getItemGroupsCached = lambda: [], - getItemGroupsUncached = lambda: __import__('ResultsDocument').documentResultsProvider()) -SearchResults.registerResultProvider('toolbar', - getItemGroupsCached = lambda: __import__('ResultsToolbar').toolbarResultsProvider(), - getItemGroupsUncached = lambda: []) -SearchResults.registerResultProvider('param', - getItemGroupsCached = lambda: __import__('ResultsPreferences').paramResultsProvider(), - getItemGroupsUncached = lambda: []) +SearchResults.registerResultProvider( + "refreshTools", + getItemGroupsCached=lambda: __import__( + "ResultsRefreshTools" + ).refreshToolsResultsProvider(), + getItemGroupsUncached=lambda: [], +) +SearchResults.registerResultProvider( + "document", + getItemGroupsCached=lambda: [], + getItemGroupsUncached=lambda: __import__( + "ResultsDocument" + ).documentResultsProvider(), +) +SearchResults.registerResultProvider( + "toolbar", + getItemGroupsCached=lambda: __import__("ResultsToolbar").toolbarResultsProvider(), + getItemGroupsUncached=lambda: [], +) +SearchResults.registerResultProvider( + "param", + getItemGroupsCached=lambda: __import__("ResultsPreferences").paramResultsProvider(), + getItemGroupsUncached=lambda: [], +) -SearchResults.registerResultHandler('refreshTools', - action = lambda nfo: __import__('ResultsRefreshTools').refreshToolsAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsRefreshTools').refreshToolsToolTip(nfo, setParent)) -SearchResults.registerResultHandler('toolbar', - action = lambda nfo: __import__('ResultsToolbar').toolbarAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsToolbar').toolbarToolTip(nfo, setParent)) -SearchResults.registerResultHandler('tool', - action = lambda nfo : __import__('ResultsToolbar').subToolAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsToolbar').subToolToolTip(nfo, setParent)) -SearchResults.registerResultHandler('subTool', - action = lambda nfo : __import__('ResultsToolbar').subToolAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsToolbar').subToolToolTip(nfo, setParent)) -SearchResults.registerResultHandler('document', - action = lambda nfo : __import__('ResultsDocument').documentAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsDocument').documentToolTip(nfo, setParent)) -SearchResults.registerResultHandler('documentObject', - action = lambda nfo : __import__('ResultsDocument').documentObjectAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsDocument').documentObjectToolTip(nfo, setParent)) -SearchResults.registerResultHandler('param', - action = lambda nfo : __import__('ResultsPreferences').paramAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsPreferences').paramToolTip(nfo, setParent)) -SearchResults.registerResultHandler('paramGroup', - action = lambda nfo : __import__('ResultsPreferences').paramGroupAction(nfo), - toolTip = lambda nfo, setParent: __import__('ResultsPreferences').paramGroupToolTip(nfo, setParent)) +SearchResults.registerResultHandler( + "refreshTools", + action=lambda nfo: __import__("ResultsRefreshTools").refreshToolsAction(nfo), + toolTip=lambda nfo, setParent: __import__( + "ResultsRefreshTools" + ).refreshToolsToolTip(nfo, setParent), +) +SearchResults.registerResultHandler( + "toolbar", + action=lambda nfo: __import__("ResultsToolbar").toolbarAction(nfo), + toolTip=lambda nfo, setParent: __import__("ResultsToolbar").toolbarToolTip( + nfo, setParent + ), +) +SearchResults.registerResultHandler( + "tool", + action=lambda nfo: __import__("ResultsToolbar").subToolAction(nfo), + toolTip=lambda nfo, setParent: __import__("ResultsToolbar").subToolToolTip( + nfo, setParent + ), +) +SearchResults.registerResultHandler( + "subTool", + action=lambda nfo: __import__("ResultsToolbar").subToolAction(nfo), + toolTip=lambda nfo, setParent: __import__("ResultsToolbar").subToolToolTip( + nfo, setParent + ), +) +SearchResults.registerResultHandler( + "document", + action=lambda nfo: __import__("ResultsDocument").documentAction(nfo), + toolTip=lambda nfo, setParent: __import__("ResultsDocument").documentToolTip( + nfo, setParent + ), +) +SearchResults.registerResultHandler( + "documentObject", + action=lambda nfo: __import__("ResultsDocument").documentObjectAction(nfo), + toolTip=lambda nfo, setParent: __import__("ResultsDocument").documentObjectToolTip( + nfo, setParent + ), +) +SearchResults.registerResultHandler( + "param", + action=lambda nfo: __import__("ResultsPreferences").paramAction(nfo), + toolTip=lambda nfo, setParent: __import__("ResultsPreferences").paramToolTip( + nfo, setParent + ), +) +SearchResults.registerResultHandler( + "paramGroup", + action=lambda nfo: __import__("ResultsPreferences").paramGroupAction(nfo), + toolTip=lambda nfo, setParent: __import__("ResultsPreferences").paramGroupToolTip( + nfo, setParent + ), +) diff --git a/InitGui.py b/InitGui.py index 66ad11d..bd5ca57 100644 --- a/InitGui.py +++ b/InitGui.py @@ -25,21 +25,33 @@ def addToolSearchBox(): if sea is None: sea = SearchBoxLight.SearchBoxLight( getItemGroups=lambda: __import__("GetItemGroups").getItemGroups(), - getToolTip=lambda groupId, setParent: __import__("GetItemGroups").getToolTip(groupId, setParent), - getItemDelegate=lambda: __import__("IndentedItemDelegate").IndentedItemDelegate(), + getToolTip=lambda groupId, setParent: __import__( + "GetItemGroups" + ).getToolTip(groupId, setParent), + getItemDelegate=lambda: __import__( + "IndentedItemDelegate" + ).IndentedItemDelegate(), ) sea.resultSelected.connect( - lambda index, groupId: __import__("GetItemGroups").onResultSelected(index, groupId) + lambda index, groupId: __import__("GetItemGroups").onResultSelected( + index, groupId + ) ) if wax is None: wax = QtGui.QWidgetAction(None) wax.setWhatsThis( - translate("SearchBar", "Use this search bar to find tools, document objects, preferences and more") + translate( + "SearchBar", + "Use this search bar to find tools, document objects, preferences and more", + ) ) sea.setWhatsThis( - translate("SearchBar", "Use this search bar to find tools, document objects, preferences and more") + translate( + "SearchBar", + "Use this search bar to find tools, document objects, preferences and more", + ) ) wax.setDefaultWidget(sea) ##mbr.addWidget(sea) diff --git a/README.md b/README.md index 9a7862c..066c948 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ https://github.com/SuzanneSoy/SearchBar/issues/12 is fixed. #### Automatic Install -Install **SearchBar** addon via the FreeCAD Addon Manager from the **Tools** :arrow_right: **Addon Manager** dropdown menu. +Install **SearchBar** addon via the FreeCAD Addon Manager from the **Tools** :arrow_right: **Addon Manager** dropdown menu. #### Manual Install @@ -64,7 +64,7 @@ Clone the GIT repository or extract the `.zip` downloaded from GitHub to the fol ### Feedback -To report bugs or feature enhancements, please open a ticket in the [issue queue](https://github.com/APEbbers/SearchBar/issues). Best place to discuss feedback or issues in on the [dedicated FreeCAD forum discussion]() for SearchBar. +To report bugs or feature enhancements, please open a ticket in the [issue queue](https://github.com/APEbbers/SearchBar/issues). Best place to discuss feedback or issues in on the [dedicated FreeCAD forum discussion]() for SearchBar. ### License [![License: CC0 v1.0.](https://img.shields.io/badge/license-CC0-blue.svg)](https://creativecommons.org/publicdomain/zero/1.0/) See [LICENSE](LICENSE). diff --git a/RefreshTools.py b/RefreshTools.py index 170d705..0f5db32 100644 --- a/RefreshTools.py +++ b/RefreshTools.py @@ -14,7 +14,15 @@ def loadAllWorkbenches(): lbl.show() lst = FreeCADGui.listWorkbenches() for i, wb in enumerate(lst): - msg = translate("SearchBar", "Loading workbench ") + wb + " (" + str(i) + "/" + str(len(lst)) + ")" + msg = ( + translate("SearchBar", "Loading workbench ") + + wb + + " (" + + str(i) + + "/" + + str(len(lst)) + + ")" + ) print(msg) lbl.setText(msg) geo = lbl.geometry() diff --git a/Resources/Icons/Tango-System-search.svg b/Resources/Icons/Tango-System-search.svg index f98b2ea..192bc55 100644 --- a/Resources/Icons/Tango-System-search.svg +++ b/Resources/Icons/Tango-System-search.svg @@ -43,4 +43,4 @@ - \ No newline at end of file + diff --git a/ResultsDocument.py b/ResultsDocument.py index 41b6fa0..0d98edb 100644 --- a/ResultsDocument.py +++ b/ResultsDocument.py @@ -61,9 +61,14 @@ class DocumentObjectToolTipWidget(QtGui.QWidget): # Tried setting the preview to a fixed size to prevent it from disappearing when changing its contents, this sets it to a fixed size but doesn't actually pick the size, .resize does that but isn't enough to fix the bug. # safeViewerInstance.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)) self.preview = App._SearchBar3DViewer - App._SearchBar3DViewer, App._SearchBar3DViewerB = App._SearchBar3DViewerB, App._SearchBar3DViewer + App._SearchBar3DViewer, App._SearchBar3DViewerB = ( + App._SearchBar3DViewerB, + App._SearchBar3DViewer, + ) - obj = App.getDocument(str(nfo["toolTip"]["docName"])).getObject(str(nfo["toolTip"]["name"])) + obj = App.getDocument(str(nfo["toolTip"]["docName"])).getObject( + str(nfo["toolTip"]["name"]) + ) # This is really a bad way to do this… to prevent the setExtraInfo function from # finalizing the object, we remove the parent ourselves. @@ -115,12 +120,22 @@ def documentResultsProvider(): group = [] for o in doc.Objects: # all_actions.append(lambda: ) - action = {"handler": "documentObject", "document": o.Document.Name, "object": o.Name} + action = { + "handler": "documentObject", + "document": o.Document.Name, + "object": o.Name, + } item = { - "icon": o.ViewObject.Icon if o.ViewObject and o.ViewObject.Icon else None, + "icon": ( + o.ViewObject.Icon if o.ViewObject and o.ViewObject.Icon else None + ), "text": o.Label + " (" + o.Name + ")", # TODO: preview of the object - "toolTip": {"label": o.Label, "name": o.Name, "docName": o.Document.Name}, + "toolTip": { + "label": o.Label, + "name": o.Name, + "docName": o.Document.Name, + }, "action": action, "subitems": [], } diff --git a/ResultsPreferences.py b/ResultsPreferences.py index ff01bbe..4079c1d 100644 --- a/ResultsPreferences.py +++ b/ResultsPreferences.py @@ -42,7 +42,12 @@ def getParamGroups(nameInConfig, nameInPath): def recur(atRoot, path, name, tree): params = [] if atRoot else getParamGroup(path) subgroups = [ - recur(False, path + (":" if atRoot else "/") + child.attrib["Name"], child.attrib["Name"], child) + recur( + False, + path + (":" if atRoot else "/") + child.attrib["Name"], + child.attrib["Name"], + child, + ) for child in tree.getchildren() if child.tag == "FCParamGroup" ] diff --git a/ResultsToolbar.py b/ResultsToolbar.py index 77967a4..ac49aca 100644 --- a/ResultsToolbar.py +++ b/ResultsToolbar.py @@ -9,7 +9,12 @@ translate = App.Qt.translate def toolbarAction(nfo): act = nfo["action"] - print("show toolbar " + act["toolbar"] + " from workbenches " + repr(act["workbenches"])) + print( + "show toolbar " + + act["toolbar"] + + " from workbenches " + + repr(act["workbenches"]) + ) def subToolAction(nfo): @@ -45,7 +50,10 @@ def subToolAction(nfo): return True elif action is not None: print( - "Run action of tool " + toolPath + " available in workbenches " + repr(act["workbenches"]) + "Run action of tool " + + toolPath + + " available in workbenches " + + repr(act["workbenches"]) ) action.trigger() return True @@ -59,14 +67,22 @@ def subToolAction(nfo): FreeCADGui.activateWorkbench(workbench) if runTool(): return - print("Tool " + toolPath + " not found, was it offered by an extension that is no longer present?") + print( + "Tool " + + toolPath + + " not found, was it offered by an extension that is no longer present?" + ) def toolbarToolTip(nfo, setParent): workbenches = FreeCADGui.listWorkbenches() in_workbenches = [ "
  • " - + (Serialize_SearchBar.iconToHTML(QtGui.QIcon(workbenches[wb].Icon)) if wb in workbenches else "? ") + + ( + Serialize_SearchBar.iconToHTML(QtGui.QIcon(workbenches[wb].Icon)) + if wb in workbenches + else "? " + ) + wb + "
  • " for wb in nfo["action"]["workbenches"] @@ -81,7 +97,12 @@ def toolbarToolTip(nfo, setParent): def subToolToolTip(nfo, setParent): - return Serialize_SearchBar.iconToHTML(nfo["icon"], 32) + "

    " + nfo["toolTip"] + "

    " + return ( + Serialize_SearchBar.iconToHTML(nfo["icon"], 32) + + "

    " + + nfo["toolTip"] + + "

    " + ) def getAllToolbars(): @@ -144,10 +165,20 @@ def toolbarResultsProvider(): "showMenu": bool(men), } group.append( - {"icon": icon, "text": text, "toolTip": tbt.toolTip(), "action": action, "subitems": subgroup} + { + "icon": icon, + "text": text, + "toolTip": tbt.toolTip(), + "action": action, + "subitems": subgroup, + } ) # TODO: move the 'workbenches' field to the itemgroup - action = {"handler": "toolbar", "workbenches": toolbarIsInWorkbenches, "toolbar": toolbarName} + action = { + "handler": "toolbar", + "workbenches": toolbarIsInWorkbenches, + "toolbar": toolbarName, + } itemGroups.append( { "icon": QtGui.QIcon(":/icons/Group.svg"), diff --git a/SafeViewer.py b/SafeViewer.py index dbf5a61..1154dc3 100644 --- a/SafeViewer.py +++ b/SafeViewer.py @@ -8,9 +8,12 @@ translate = App.Qt.translate class SafeViewer(QtGui.QWidget): """FreeCAD uses a modified version of QuarterWidget, so the import pivy.quarter one will cause segfaults. FreeCAD's FreeCADGui.createViewer() puts the viewer widget inside an MDI window, and detaching it without causing segfaults on exit is tricky. - This class contains some kludges to extract the viewer as a standalone widget and destroy it safely.""" + This class contains some kludges to extract the viewer as a standalone widget and destroy it safely. + """ - enabled = App.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").GetBool("PreviewEnabled", False) + enabled = App.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").GetBool( + "PreviewEnabled", False + ) instances = [] def __init__(self, parent=None): @@ -38,11 +41,15 @@ class SafeViewer(QtGui.QWidget): self.btn_enable_for_this_session = QtGui.QPushButton( translate("SearchBar", "Enable 3D preview for this session") ) - self.btn_enable_for_this_session.clicked.connect(self.enable_for_this_session) + self.btn_enable_for_this_session.clicked.connect( + self.enable_for_this_session + ) self.btn_enable_for_future_sessions = QtGui.QPushButton( translate("SearchBar", "Enable 3D preview for future sessions") ) - self.btn_enable_for_future_sessions.clicked.connect(self.enable_for_future_sessions) + self.btn_enable_for_future_sessions.clicked.connect( + self.enable_for_future_sessions + ) self.setLayout(QtGui.QVBoxLayout()) self.layout().addWidget(self.lbl_warning) self.layout().addWidget(self.btn_enable_for_this_session) @@ -56,7 +63,9 @@ class SafeViewer(QtGui.QWidget): def enable_for_future_sessions(self): if not SafeViewer.enabled: # Store in prefs - App.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").SetBool("PreviewEnabled", True) + App.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").SetBool( + "PreviewEnabled", True + ) # Then enable as usual self.enable_for_this_session() @@ -77,7 +86,9 @@ class SafeViewer(QtGui.QWidget): self.graphicsView = self.viewer.graphicsView() self.oldGraphicsViewParent = self.graphicsView.parent() self.oldGraphicsViewParentParent = self.oldGraphicsViewParent.parent() - self.oldGraphicsViewParentParentParent = self.oldGraphicsViewParentParent.parent() + self.oldGraphicsViewParentParentParent = ( + self.oldGraphicsViewParentParent.parent() + ) # Avoid segfault but still hide the undesired window by moving it to a new hidden MDI area. self.hiddenQMDIArea = QtGui.QMdiArea() diff --git a/SearchBox.py b/SearchBox.py index 45fd0be..b5633b1 100644 --- a/SearchBox.py +++ b/SearchBox.py @@ -91,7 +91,9 @@ 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. @@ -103,7 +105,9 @@ 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) @@ -128,10 +132,18 @@ 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) @@ -139,13 +151,25 @@ 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 @@ -174,7 +198,12 @@ class SearchBox(QLineEdit): mdl = QStandardItemModel() mdl.appendRow( [ - QStandardItem(genericToolIcon, translate("SearchBar", "Please wait, loading results from cache…")), + QStandardItem( + genericToolIcon, + translate( + "SearchBar", "Please wait, loading results from cache…" + ), + ), QStandardItem("0"), QStandardItem("-1"), ] @@ -218,11 +247,17 @@ 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): @@ -358,7 +393,9 @@ 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) diff --git a/SearchBoxLight.py b/SearchBoxLight.py index ace81b2..90c4a23 100644 --- a/SearchBoxLight.py +++ b/SearchBoxLight.py @@ -6,7 +6,9 @@ from PySide import QtCore class SearchBoxLight(QtGui.QLineEdit): resultSelected = QtCore.Signal(int, int) - def __init__(self, getItemGroups, getToolTip, getItemDelegate, maxVisibleRows=20, parent=None): + def __init__( + self, getItemGroups, getToolTip, getItemDelegate, maxVisibleRows=20, parent=None + ): self.isInitialized = False # Store arguments @@ -25,7 +27,9 @@ class SearchBoxLight(QtGui.QLineEdit): self.addAction(ico, QtGui.QLineEdit.LeadingPosition) self.setClearButtonEnabled(True) self.setPlaceholderText("Search tools, prefs & tree") - self.setFixedWidth(200) # needed to avoid a change of width when the clear button appears/disappears + self.setFixedWidth( + 200 + ) # needed to avoid a change of width when the clear button appears/disappears def lazyInit(self): pass diff --git a/SearchResults.py b/SearchResults.py index 58252fa..70e8ada 100644 --- a/SearchResults.py +++ b/SearchResults.py @@ -1,18 +1,20 @@ -actionHandlers = { } -toolTipHandlers = { } -resultProvidersCached = { } -resultProvidersUncached = { } +actionHandlers = {} +toolTipHandlers = {} +resultProvidersCached = {} +resultProvidersUncached = {} + # name : string # getItemGroupsCached: () -> [itemGroup] # getItemGroupsUncached: () -> [itemGroup] def registerResultProvider(name, getItemGroupsCached, getItemGroupsUncached): - resultProvidersCached[name] = getItemGroupsCached - resultProvidersUncached[name] = getItemGroupsUncached + resultProvidersCached[name] = getItemGroupsCached + resultProvidersUncached[name] = getItemGroupsUncached + # name : str # action : act -> None # toolTip : groupId, setParent -> (str or QWidget) def registerResultHandler(name, action, toolTip): - actionHandlers[name] = action - toolTipHandlers[name] = toolTip + actionHandlers[name] = action + toolTipHandlers[name] = toolTip diff --git a/Serialize_SearchBar.py b/Serialize_SearchBar.py index e2c0847..86a498f 100644 --- a/Serialize_SearchBar.py +++ b/Serialize_SearchBar.py @@ -3,7 +3,12 @@ from PySide import QtGui import json -def iconToBase64(icon: QtGui.QIcon, sz=QtCore.QSize(64, 64), mode=QtGui.QIcon.Mode.Normal, state=QtGui.QIcon.State.On): +def iconToBase64( + icon: QtGui.QIcon, + sz=QtCore.QSize(64, 64), + mode=QtGui.QIcon.Mode.Normal, + state=QtGui.QIcon.State.On, +): """ Converts a QIcon to a Base64-encoded string representation of its pixmap. @@ -59,8 +64,13 @@ def serializeIcon(icon): "selected": QtGui.QIcon.Mode.Selected, }.items(): iconPixmaps[strW][strH][strMode] = {} - for strState, state in {"off": QtGui.QIcon.State.Off, "on": QtGui.QIcon.State.On}.items(): - iconPixmaps[strW][strH][strMode][strState] = iconToBase64(icon, sz, mode, state) + for strState, state in { + "off": QtGui.QIcon.State.Off, + "on": QtGui.QIcon.State.On, + }.items(): + iconPixmaps[strW][strH][strMode][strState] = iconToBase64( + icon, sz, mode, state + ) return iconPixmaps @@ -87,9 +97,15 @@ def deserializeIcon(iconPixmaps): "selected": QtGui.QIcon.Mode.Selected, }[strMode] for strState, statePixmap in modePixmaps.items(): - state = {"off": QtGui.QIcon.State.Off, "on": QtGui.QIcon.State.On}[strState] + state = {"off": QtGui.QIcon.State.Off, "on": QtGui.QIcon.State.On}[ + strState + ] pxm = QtGui.QPixmap() - pxm.loadFromData(QtCore.QByteArray.fromBase64(bytearray(statePixmap.encode("utf-8")))) + pxm.loadFromData( + QtCore.QByteArray.fromBase64( + bytearray(statePixmap.encode("utf-8")) + ) + ) ico.addPixmap(pxm, mode, state) return ico diff --git a/package.xml b/package.xml index 9a7f9f1..76cebb9 100644 --- a/package.xml +++ b/package.xml @@ -1,24 +1,24 @@ - + SearchBar - + Adds a search bar widget for tools, document objects, and preferences - + 1.3.x - + 2022-06-01 - + Paul Ebbers - + CCOv1 - + https://github.com/APEbbers/SearchBar - + https://github.com/APEbbers/SearchBar/issues - + https://github.com/APEbbers/SearchBar - + lxml @@ -30,5 +30,5 @@ ui/ux - +