Updated text
This commit is contained in:
parent
a1e4c817d4
commit
b06f6bd460
|
@ -14,15 +14,7 @@ def loadAllWorkbenches():
|
||||||
lbl.show()
|
lbl.show()
|
||||||
lst = FreeCADGui.listWorkbenches()
|
lst = FreeCADGui.listWorkbenches()
|
||||||
for i, wb in enumerate(lst):
|
for i, wb in enumerate(lst):
|
||||||
msg = (
|
msg = translate("SearchBar", "Loading workbench ") + wb + " (" + str(i) + "/" + str(len(lst)) + ")"
|
||||||
translate("SearchBar", "Loading workbench ")
|
|
||||||
+ wb
|
|
||||||
+ " ("
|
|
||||||
+ str(i)
|
|
||||||
+ "/"
|
|
||||||
+ str(len(lst))
|
|
||||||
+ ")"
|
|
||||||
)
|
|
||||||
print(msg)
|
print(msg)
|
||||||
lbl.setText(msg)
|
lbl.setText(msg)
|
||||||
geo = lbl.geometry()
|
geo = lbl.geometry()
|
||||||
|
@ -102,7 +94,7 @@ def refreshToolsAction():
|
||||||
translate("SearchBar", "Load all workbenches?"),
|
translate("SearchBar", "Load all workbenches?"),
|
||||||
translate(
|
translate(
|
||||||
"SearchBar",
|
"SearchBar",
|
||||||
'Load all workbenches? This can cause FreeCAD to become unstable, and this "reload tools" feature contained a bug that crashed freecad systematically, so please make sure you save your work before. It\'s a good idea to restart FreeCAD after this operation.',
|
"""Load all workbenches? This can cause FreeCAD to become unstable, and this "reload tools" feature contained a bug that crashed freecad systematically, so please make sure you save your work before. It\'s a good idea to restart FreeCAD after this operation.""",
|
||||||
),
|
),
|
||||||
QtGui.QMessageBox.Yes,
|
QtGui.QMessageBox.Yes,
|
||||||
QtGui.QMessageBox.No,
|
QtGui.QMessageBox.No,
|
||||||
|
|
|
@ -24,7 +24,7 @@ def refreshToolsToolTip(nfo, setParent):
|
||||||
+ "<p>"
|
+ "<p>"
|
||||||
+ translate(
|
+ translate(
|
||||||
"SearchBar",
|
"SearchBar",
|
||||||
"Load all workbenches to refresh this list of tools. This may take a minute, depending on the number of installed workbenches.",
|
"Load all workbenches to refresh the cached results. This may take a minute, depending on the number of installed workbenches.",
|
||||||
)
|
)
|
||||||
+ "</p>"
|
+ "</p>"
|
||||||
)
|
)
|
||||||
|
@ -34,7 +34,7 @@ def refreshToolsResultsProvider():
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"icon": genericToolIcon,
|
"icon": genericToolIcon,
|
||||||
"text": "Refresh list of tools",
|
"text": translate("SearchBar", "Refresh cached results"),
|
||||||
"toolTip": "",
|
"toolTip": "",
|
||||||
"action": {"handler": "refreshTools"},
|
"action": {"handler": "refreshTools"},
|
||||||
"subitems": [],
|
"subitems": [],
|
||||||
|
|
90
SearchBox.py
90
SearchBox.py
|
@ -91,9 +91,7 @@ class SearchBox(QLineEdit):
|
||||||
self.getItemGroups = getItemGroups
|
self.getItemGroups = getItemGroups
|
||||||
self.getToolTip = getToolTip
|
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.itemGroups = None # Will be initialized by calling getItemGroups() the first time the search box gains focus, through focusInEvent and refreshItemGroups
|
||||||
self.maxVisibleRows = (
|
self.maxVisibleRows = maxVisibleRows # TODO: use this to compute the correct height
|
||||||
maxVisibleRows # TODO: use this to compute the correct height
|
|
||||||
)
|
|
||||||
# Create proxy model
|
# Create proxy model
|
||||||
self.proxyModel = QIdentityProxyModel()
|
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.
|
# 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.setWindowFlag(Qt.WindowType.FramelessWindowHint)
|
||||||
self.listView.setSelectionMode(self.listView.SelectionMode.SingleSelection)
|
self.listView.setSelectionMode(self.listView.SelectionMode.SingleSelection)
|
||||||
self.listView.setModel(self.proxyModel)
|
self.listView.setModel(self.proxyModel)
|
||||||
self.listView.setItemDelegate(
|
self.listView.setItemDelegate(getItemDelegate()) # https://stackoverflow.com/a/65930408/324969
|
||||||
getItemDelegate()
|
|
||||||
) # https://stackoverflow.com/a/65930408/324969
|
|
||||||
self.listView.setMouseTracking(True)
|
self.listView.setMouseTracking(True)
|
||||||
# make the QListView non-editable
|
# make the QListView non-editable
|
||||||
self.listView.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
|
self.listView.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
|
||||||
|
@ -122,8 +118,12 @@ class SearchBox(QLineEdit):
|
||||||
self.pendingExtraInfo = None
|
self.pendingExtraInfo = None
|
||||||
self.currentExtraInfo = None
|
self.currentExtraInfo = None
|
||||||
# Connect signals and slots
|
# Connect signals and slots
|
||||||
self.listView.clicked.connect(lambda x: self.selectResult("select", x))
|
self.listView.clicked.connect(
|
||||||
# self.listView.selectionModel().selectionChanged.connect(self.onSelectionChanged)
|
lambda x: self.selectResult("select", x)
|
||||||
|
) # This makes all workbenches appear. TODO: findout why, a click event seems not logic
|
||||||
|
self.listView.selectionModel().selectionChanged.connect(
|
||||||
|
self.onSelectionChanged
|
||||||
|
) # This updates the details when using the keyboard
|
||||||
# Add custom mouse events. On windows the click events were not working for Searcbar versions 1.2.x and older.
|
# Add custom mouse events. On windows the click events were not working for Searcbar versions 1.2.x and older.
|
||||||
# These events and their proxies in the SearchBorLight fixes this
|
# These events and their proxies in the SearchBorLight fixes this
|
||||||
self.listView.mousePressEvent = lambda event: self.proxyMousePressEvent(event)
|
self.listView.mousePressEvent = lambda event: self.proxyMousePressEvent(event)
|
||||||
|
@ -133,18 +133,10 @@ class SearchBox(QLineEdit):
|
||||||
# Note: should probably use the eventFilter method instead...
|
# Note: should probably use the eventFilter method instead...
|
||||||
wdgctx = Qt.ShortcutContext.WidgetShortcut
|
wdgctx = Qt.ShortcutContext.WidgetShortcut
|
||||||
|
|
||||||
QShortcut(
|
QShortcut(QKeySequence(Qt.Key.Key_Down), self, context=wdgctx).activated.connect(self.listDown)
|
||||||
QKeySequence(Qt.Key.Key_Down), self, context=wdgctx
|
QShortcut(QKeySequence(Qt.Key.Key_Up), self, context=wdgctx).activated.connect(self.listUp)
|
||||||
).activated.connect(self.listDown)
|
QShortcut(QKeySequence(Qt.Key.Key_PageDown), self, context=wdgctx).activated.connect(self.listPageDown)
|
||||||
QShortcut(QKeySequence(Qt.Key.Key_Up), self, context=wdgctx).activated.connect(
|
QShortcut(QKeySequence(Qt.Key.Key_PageUp), self, context=wdgctx).activated.connect(self.listPageUp)
|
||||||
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.
|
# Home and End do not work, for some reason.
|
||||||
# QShortcut(QKeySequence.MoveToEndOfDocument, self, context = wdgctx).activated.connect(self.listEnd)
|
# QShortcut(QKeySequence.MoveToEndOfDocument, self, context = wdgctx).activated.connect(self.listEnd)
|
||||||
|
@ -152,25 +144,13 @@ class SearchBox(QLineEdit):
|
||||||
# QShortcut(QKeySequence(Qt.Key.Key_End), self, context = wdgctx).activated.connect(self.listEnd)
|
# 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('Home'), self, context = wdgctx).activated.connect(self.listStart)
|
||||||
|
|
||||||
QShortcut(
|
QShortcut(QKeySequence(Qt.Key.Key_Enter), self, context=wdgctx).activated.connect(self.listAccept)
|
||||||
QKeySequence(Qt.Key.Key_Enter), self, context=wdgctx
|
QShortcut(QKeySequence(Qt.Key.Key_Return), self, context=wdgctx).activated.connect(self.listAccept)
|
||||||
).activated.connect(self.listAccept)
|
QShortcut(QKeySequence("Ctrl+Return"), self, context=wdgctx).activated.connect(self.listAcceptToggle)
|
||||||
QShortcut(
|
QShortcut(QKeySequence("Ctrl+Enter"), self, context=wdgctx).activated.connect(self.listAcceptToggle)
|
||||||
QKeySequence(Qt.Key.Key_Return), self, context=wdgctx
|
QShortcut(QKeySequence("Ctrl+Space"), self, context=wdgctx).activated.connect(self.listAcceptToggle)
|
||||||
).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(
|
QShortcut(QKeySequence(Qt.Key.Key_Escape), self, context=wdgctx).activated.connect(self.listCancel)
|
||||||
QKeySequence(Qt.Key.Key_Escape), self, context=wdgctx
|
|
||||||
).activated.connect(self.listCancel)
|
|
||||||
|
|
||||||
# Initialize the model with the full list (assuming the text() is empty)
|
# 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
|
# self.proxyFilterModel(self.text()) # This is done by refreshItemGroups on focusInEvent, because the initial loading from cache can take time
|
||||||
|
@ -217,9 +197,7 @@ class SearchBox(QLineEdit):
|
||||||
[
|
[
|
||||||
QStandardItem(
|
QStandardItem(
|
||||||
genericToolIcon,
|
genericToolIcon,
|
||||||
translate(
|
translate("SearchBar", "Please wait, loading results from cache…"),
|
||||||
"SearchBar", "Please wait, loading results from cache…"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
QStandardItem("0"),
|
QStandardItem("0"),
|
||||||
QStandardItem("-1"),
|
QStandardItem("-1"),
|
||||||
|
@ -271,17 +249,11 @@ class SearchBox(QLineEdit):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def proxyListPageDown(self):
|
def proxyListPageDown(self):
|
||||||
self.movementKey(
|
self.movementKey(lambda current, nbRows: min(current + max(1, self.maxVisibleRows / 2), nbRows - 1))
|
||||||
lambda current, nbRows: min(
|
|
||||||
current + max(1, self.maxVisibleRows / 2), nbRows - 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def proxyListPageUp(self):
|
def proxyListPageUp(self):
|
||||||
self.movementKey(
|
self.movementKey(lambda current, nbRows: max(current - max(1, self.maxVisibleRows / 2), 0))
|
||||||
lambda current, nbRows: max(current - max(1, self.maxVisibleRows / 2), 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def proxyListEnd(self):
|
def proxyListEnd(self):
|
||||||
|
@ -415,9 +387,7 @@ class SearchBox(QLineEdit):
|
||||||
def getScreenPosition(widget):
|
def getScreenPosition(widget):
|
||||||
geo = widget.geometry()
|
geo = widget.geometry()
|
||||||
parent = widget.parent()
|
parent = widget.parent()
|
||||||
parentPos = (
|
parentPos = getScreenPosition(parent) if parent is not None else QPoint(0, 0)
|
||||||
getScreenPosition(parent) if parent is not None else QPoint(0, 0)
|
|
||||||
)
|
|
||||||
return QPoint(geo.x() + parentPos.x(), geo.y() + parentPos.y())
|
return QPoint(geo.x() + parentPos.x(), geo.y() + parentPos.y())
|
||||||
|
|
||||||
pos = getScreenPosition(self)
|
pos = getScreenPosition(self)
|
||||||
|
@ -447,6 +417,22 @@ class SearchBox(QLineEdit):
|
||||||
self.listView.setGeometry(x, y, w, h)
|
self.listView.setGeometry(x, y, w, h)
|
||||||
self.extraInfo.setGeometry(extrax, y, extraw, h)
|
self.extraInfo.setGeometry(extrax, y, extraw, h)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def proxyOnSelectionChanged(self, selected, deselected):
|
||||||
|
# The list has .setSelectionMode(QAbstractItemView.SingleSelection),
|
||||||
|
# so there is always at most one index in selected.indexes() and at most one
|
||||||
|
# index in deselected.indexes()
|
||||||
|
selected = selected.indexes()
|
||||||
|
deselected = deselected.indexes()
|
||||||
|
if len(selected) > 0:
|
||||||
|
index = selected[0]
|
||||||
|
self.setExtraInfo(index)
|
||||||
|
# Poor attempt to circumvent a glitch where the extra info pane stays visible after pressing Return
|
||||||
|
if not self.listView.isHidden():
|
||||||
|
self.showExtraInfo()
|
||||||
|
elif len(deselected) > 0:
|
||||||
|
self.hideExtraInfo()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def setExtraInfo(self, index):
|
def setExtraInfo(self, index):
|
||||||
if self.currentExtraInfo == (index.row(), index.column(), index.model()):
|
if self.currentExtraInfo == (index.row(), index.column(), index.model()):
|
||||||
|
|
|
@ -6,9 +6,7 @@ from PySide import QtCore
|
||||||
class SearchBoxLight(QtGui.QLineEdit):
|
class SearchBoxLight(QtGui.QLineEdit):
|
||||||
resultSelected = QtCore.Signal(int, int)
|
resultSelected = QtCore.Signal(int, int)
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, getItemGroups, getToolTip, getItemDelegate, maxVisibleRows=20, parent=None):
|
||||||
self, getItemGroups, getToolTip, getItemDelegate, maxVisibleRows=20, parent=None
|
|
||||||
):
|
|
||||||
self.isInitialized = False
|
self.isInitialized = False
|
||||||
|
|
||||||
# Store arguments
|
# Store arguments
|
||||||
|
@ -27,9 +25,7 @@ class SearchBoxLight(QtGui.QLineEdit):
|
||||||
self.addAction(ico, QtGui.QLineEdit.LeadingPosition)
|
self.addAction(ico, QtGui.QLineEdit.LeadingPosition)
|
||||||
self.setClearButtonEnabled(True)
|
self.setClearButtonEnabled(True)
|
||||||
self.setPlaceholderText("Search tools, prefs & tree")
|
self.setPlaceholderText("Search tools, prefs & tree")
|
||||||
self.setFixedWidth(
|
self.setFixedWidth(200) # needed to avoid a change of width when the clear button appears/disappears
|
||||||
200
|
|
||||||
) # needed to avoid a change of width when the clear button appears/disappears
|
|
||||||
|
|
||||||
def lazyInit(self):
|
def lazyInit(self):
|
||||||
pass
|
pass
|
||||||
|
@ -63,8 +59,8 @@ class SearchBoxLight(QtGui.QLineEdit):
|
||||||
def keyPressEvent(self, *args, **kwargs):
|
def keyPressEvent(self, *args, **kwargs):
|
||||||
return self.proxyKeyPressEvent(*args, **kwargs)
|
return self.proxyKeyPressEvent(*args, **kwargs)
|
||||||
|
|
||||||
# def onSelectionChanged(self, *args, **kwargs):
|
def onSelectionChanged(self, *args, **kwargs):
|
||||||
# return self.proxyOnSelectionChanged(*args, **kwargs)
|
return self.proxyOnSelectionChanged(*args, **kwargs)
|
||||||
|
|
||||||
def filterModel(self, *args, **kwargs):
|
def filterModel(self, *args, **kwargs):
|
||||||
return self.proxyFilterModel(*args, **kwargs)
|
return self.proxyFilterModel(*args, **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user