Merge pull request #12 from APEbbers/Develop
Fixed click events in windows
142
.gitignore
vendored
|
@ -1,2 +1,142 @@
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
pip-wheel-metadata/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
.vscode/
|
||||||
__pycache__
|
__pycache__
|
||||||
/gif
|
.pre-commit-config.yaml
|
||||||
|
.pre-commit-search-and-replace.yaml
|
||||||
|
.pttx
|
||||||
|
*.pptx
|
||||||
|
/CreateTranslations.bat
|
||||||
|
*.bak
|
||||||
|
Backups/
|
||||||
|
RibbonDataFile*.dat
|
||||||
|
RibbonStructure.json
|
||||||
|
RibbonStructure_default.json
|
||||||
|
|
16
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# .pre-commit-config.yaml
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/mattlqx/pre-commit-search-and-replace
|
||||||
|
rev: v1.1.8
|
||||||
|
hooks:
|
||||||
|
- id: search-and-replace
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v5.0.0 # this is optional, use `pre-commit autoupdate` to get the latest rev!
|
||||||
|
hooks:
|
||||||
|
- id: check-yaml
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 24.10.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
6
.pre-commit-search-and-replace.yaml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
- search: PySide6
|
||||||
|
replacement: PySide
|
||||||
|
- search: PySide2
|
||||||
|
replacement: PySide
|
||||||
|
- search: pyqtribbon as
|
||||||
|
replacement: pyqtribbon_local as
|
|
@ -3,40 +3,84 @@
|
||||||
|
|
||||||
import SearchResults
|
import SearchResults
|
||||||
|
|
||||||
SearchResults.registerResultProvider('refreshTools',
|
SearchResults.registerResultProvider(
|
||||||
getItemGroupsCached = lambda: __import__('ResultsRefreshTools').refreshToolsResultsProvider(),
|
"refreshTools",
|
||||||
getItemGroupsUncached = lambda: [])
|
getItemGroupsCached=lambda: __import__(
|
||||||
SearchResults.registerResultProvider('document',
|
"ResultsRefreshTools"
|
||||||
getItemGroupsCached = lambda: [],
|
).refreshToolsResultsProvider(),
|
||||||
getItemGroupsUncached = lambda: __import__('ResultsDocument').documentResultsProvider())
|
getItemGroupsUncached=lambda: [],
|
||||||
SearchResults.registerResultProvider('toolbar',
|
)
|
||||||
getItemGroupsCached = lambda: __import__('ResultsToolbar').toolbarResultsProvider(),
|
SearchResults.registerResultProvider(
|
||||||
getItemGroupsUncached = lambda: [])
|
"document",
|
||||||
SearchResults.registerResultProvider('param',
|
getItemGroupsCached=lambda: [],
|
||||||
getItemGroupsCached = lambda: __import__('ResultsPreferences').paramResultsProvider(),
|
getItemGroupsUncached=lambda: __import__(
|
||||||
getItemGroupsUncached = lambda: [])
|
"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',
|
SearchResults.registerResultHandler(
|
||||||
action = lambda nfo: __import__('ResultsRefreshTools').refreshToolsAction(nfo),
|
"refreshTools",
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsRefreshTools').refreshToolsToolTip(nfo, setParent))
|
action=lambda nfo: __import__("ResultsRefreshTools").refreshToolsAction(nfo),
|
||||||
SearchResults.registerResultHandler('toolbar',
|
toolTip=lambda nfo, setParent: __import__(
|
||||||
action = lambda nfo: __import__('ResultsToolbar').toolbarAction(nfo),
|
"ResultsRefreshTools"
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsToolbar').toolbarToolTip(nfo, setParent))
|
).refreshToolsToolTip(nfo, setParent),
|
||||||
SearchResults.registerResultHandler('tool',
|
)
|
||||||
action = lambda nfo : __import__('ResultsToolbar').subToolAction(nfo),
|
SearchResults.registerResultHandler(
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsToolbar').subToolToolTip(nfo, setParent))
|
"toolbar",
|
||||||
SearchResults.registerResultHandler('subTool',
|
action=lambda nfo: __import__("ResultsToolbar").toolbarAction(nfo),
|
||||||
action = lambda nfo : __import__('ResultsToolbar').subToolAction(nfo),
|
toolTip=lambda nfo, setParent: __import__("ResultsToolbar").toolbarToolTip(
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsToolbar').subToolToolTip(nfo, setParent))
|
nfo, setParent
|
||||||
SearchResults.registerResultHandler('document',
|
),
|
||||||
action = lambda nfo : __import__('ResultsDocument').documentAction(nfo),
|
)
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsDocument').documentToolTip(nfo, setParent))
|
SearchResults.registerResultHandler(
|
||||||
SearchResults.registerResultHandler('documentObject',
|
"tool",
|
||||||
action = lambda nfo : __import__('ResultsDocument').documentObjectAction(nfo),
|
action=lambda nfo: __import__("ResultsToolbar").subToolAction(nfo),
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsDocument').documentObjectToolTip(nfo, setParent))
|
toolTip=lambda nfo, setParent: __import__("ResultsToolbar").subToolToolTip(
|
||||||
SearchResults.registerResultHandler('param',
|
nfo, setParent
|
||||||
action = lambda nfo : __import__('ResultsPreferences').paramAction(nfo),
|
),
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsPreferences').paramToolTip(nfo, setParent))
|
)
|
||||||
SearchResults.registerResultHandler('paramGroup',
|
SearchResults.registerResultHandler(
|
||||||
action = lambda nfo : __import__('ResultsPreferences').paramGroupAction(nfo),
|
"subTool",
|
||||||
toolTip = lambda nfo, setParent: __import__('ResultsPreferences').paramGroupToolTip(nfo, setParent))
|
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
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
import FreeCAD as App
|
||||||
|
import FreeCADGui as Gui
|
||||||
|
|
||||||
globalGroups = []
|
globalGroups = []
|
||||||
|
|
||||||
itemGroups = None
|
itemGroups = None
|
||||||
serializedItemGroups = None
|
serializedItemGroups = None
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
|
||||||
def onResultSelected(index, groupId):
|
def onResultSelected(index, groupId):
|
||||||
global globalGroups
|
global globalGroups
|
||||||
|
@ -17,8 +23,11 @@ def onResultSelected(index, groupId):
|
||||||
|
|
||||||
QtGui.QMessageBox.warning(
|
QtGui.QMessageBox.warning(
|
||||||
None,
|
None,
|
||||||
"Could not execute this action",
|
translate("SearchBar", "Could not execute this action"),
|
||||||
|
translate(
|
||||||
|
"SearchBar",
|
||||||
"Could not execute this action, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.",
|
"Could not execute this action, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +40,10 @@ def getToolTip(groupId, setParent):
|
||||||
if handlerName in SearchResults.toolTipHandlers:
|
if handlerName in SearchResults.toolTipHandlers:
|
||||||
return SearchResults.toolTipHandlers[handlerName](nfo, setParent)
|
return SearchResults.toolTipHandlers[handlerName](nfo, setParent)
|
||||||
else:
|
else:
|
||||||
return "Could not load tooltip for this tool, it could be from a Mod that has been uninstalled. Try refreshing the list of tools."
|
return translate(
|
||||||
|
"SearchBar",
|
||||||
|
"Could not load tooltip for this tool, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def getItemGroups():
|
def getItemGroups():
|
||||||
|
|
36
InitGui.py
|
@ -1,32 +1,58 @@
|
||||||
|
import FreeCAD as App
|
||||||
|
import FreeCADGui as Gui
|
||||||
|
|
||||||
# Avoid garbage collection by storing the action in a global variable
|
# Avoid garbage collection by storing the action in a global variable
|
||||||
wax = None
|
wax = None
|
||||||
sea = None
|
sea = None
|
||||||
tbr = None
|
tbr = None
|
||||||
|
|
||||||
|
|
||||||
|
def QT_TRANSLATE_NOOP(context, text):
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def addToolSearchBox():
|
def addToolSearchBox():
|
||||||
import FreeCADGui
|
import FreeCADGui
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
import SearchBoxLight
|
import SearchBoxLight
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
global wax, sea, tbr
|
global wax, sea, tbr
|
||||||
mw = FreeCADGui.getMainWindow()
|
mw = FreeCADGui.getMainWindow()
|
||||||
if mw:
|
if mw:
|
||||||
if sea is None:
|
if sea is None:
|
||||||
sea = SearchBoxLight.SearchBoxLight(
|
sea = SearchBoxLight.SearchBoxLight(
|
||||||
getItemGroups=lambda: __import__("GetItemGroups").getItemGroups(),
|
getItemGroups=lambda: __import__("GetItemGroups").getItemGroups(),
|
||||||
getToolTip=lambda groupId, setParent: __import__("GetItemGroups").getToolTip(groupId, setParent),
|
getToolTip=lambda groupId, setParent: __import__(
|
||||||
getItemDelegate=lambda: __import__("IndentedItemDelegate").IndentedItemDelegate(),
|
"GetItemGroups"
|
||||||
|
).getToolTip(groupId, setParent),
|
||||||
|
getItemDelegate=lambda: __import__(
|
||||||
|
"IndentedItemDelegate"
|
||||||
|
).IndentedItemDelegate(),
|
||||||
)
|
)
|
||||||
sea.resultSelected.connect(
|
sea.resultSelected.connect(
|
||||||
lambda index, groupId: __import__("GetItemGroups").onResultSelected(index, groupId)
|
lambda index, groupId: __import__("GetItemGroups").onResultSelected(
|
||||||
|
index, groupId
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if wax is None:
|
if wax is None:
|
||||||
wax = QtGui.QWidgetAction(None)
|
wax = QtGui.QWidgetAction(None)
|
||||||
wax.setWhatsThis("Use this search bar to find tools, document objects, preferences and more")
|
wax.setWhatsThis(
|
||||||
|
translate(
|
||||||
|
"SearchBar",
|
||||||
|
"Use this search bar to find tools, document objects, preferences and more",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
sea.setWhatsThis("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",
|
||||||
|
)
|
||||||
|
)
|
||||||
wax.setDefaultWidget(sea)
|
wax.setDefaultWidget(sea)
|
||||||
##mbr.addWidget(sea)
|
##mbr.addWidget(sea)
|
||||||
# mbr.addAction(wax)
|
# mbr.addAction(wax)
|
||||||
|
|
80
Parameters_SearchBar.py
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
import FreeCAD as App
|
||||||
|
import FreeCADGui as Gui
|
||||||
|
from PySide.QtGui import QColor
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
preferences = App.ParamGet("User parameter:BaseApp/Preferences/Mod/FreeCAD-Ribbon")
|
||||||
|
|
||||||
|
|
||||||
|
class Settings:
|
||||||
|
|
||||||
|
# region -- Functions to read the settings from the FreeCAD Parameters
|
||||||
|
# and make sure that a None type result is ""
|
||||||
|
def GetStringSetting(settingName: str) -> str:
|
||||||
|
result = preferences.GetString(settingName)
|
||||||
|
|
||||||
|
if result.lower() == "none":
|
||||||
|
result = ""
|
||||||
|
return result
|
||||||
|
|
||||||
|
def GetIntSetting(settingName: str) -> int:
|
||||||
|
result = preferences.GetInt(settingName)
|
||||||
|
if result == "":
|
||||||
|
result = None
|
||||||
|
return result
|
||||||
|
|
||||||
|
def GetFloatSetting(settingName: str) -> int:
|
||||||
|
result = preferences.GetFloat(settingName)
|
||||||
|
if result == "":
|
||||||
|
result = None
|
||||||
|
return result
|
||||||
|
|
||||||
|
def GetBoolSetting(settingName: str) -> bool:
|
||||||
|
result = preferences.GetBool(settingName)
|
||||||
|
if str(result).lower() == "none":
|
||||||
|
result = False
|
||||||
|
return result
|
||||||
|
|
||||||
|
def GetColorSetting(settingName: str) -> object:
|
||||||
|
# Create a tuple from the int value of the color
|
||||||
|
result = QColor.fromRgba(preferences.GetUnsigned(settingName)).toTuple()
|
||||||
|
|
||||||
|
# correct the order of the tuple and divide them by 255
|
||||||
|
result = (result[3] / 255, result[0] / 255, result[1] / 255, result[2] / 255)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region - Functions to write settings to the FreeCAD Parameters
|
||||||
|
#
|
||||||
|
#
|
||||||
|
def SetStringSetting(settingName: str, value: str):
|
||||||
|
if value.lower() == "none":
|
||||||
|
value = ""
|
||||||
|
preferences.SetString(settingName, value)
|
||||||
|
return
|
||||||
|
|
||||||
|
def SetBoolSetting(settingName: str, value):
|
||||||
|
if str(value).lower() == "true":
|
||||||
|
Bool = True
|
||||||
|
if str(value).lower() == "none" or str(value).lower() != "true":
|
||||||
|
Bool = False
|
||||||
|
preferences.SetBool(settingName, Bool)
|
||||||
|
return
|
||||||
|
|
||||||
|
def SetIntSetting(settingName: str, value: int):
|
||||||
|
if str(value).lower() != "":
|
||||||
|
preferences.SetInt(settingName, value)
|
||||||
|
|
||||||
|
|
||||||
|
# region - Define the resources ----------------------------------------------------------------------------------------
|
||||||
|
ICON_LOCATION = os.path.join(os.path.dirname(__file__), "Resources", "Icons")
|
||||||
|
# endregion ------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# The pixmap for the general tool icon
|
||||||
|
genericToolIcon_Pixmap = os.path.join(ICON_LOCATION, "Tango-Tools-spanner-hammer.svg")
|
|
@ -14,7 +14,7 @@ It can be extended by other mods, by adding a new result provider.
|
||||||
|
|
||||||
The search bar appears next to the [`What's this?`](https://wiki.freecad.org/Std_WhatsThis) tool <a href="https://wiki.freecad.org/Std_WhatsThis"><img src="https://user-images.githubusercontent.com/4140247/156215976-5dfadb0c-cac4-44b2-8ad4-b67462a5f7fa.png" alt="drawing" width="20px" height="20px"/></a> in FreeCAD's default File toolbar.
|
The search bar appears next to the [`What's this?`](https://wiki.freecad.org/Std_WhatsThis) tool <a href="https://wiki.freecad.org/Std_WhatsThis"><img src="https://user-images.githubusercontent.com/4140247/156215976-5dfadb0c-cac4-44b2-8ad4-b67462a5f7fa.png" alt="drawing" width="20px" height="20px"/></a> in FreeCAD's default File toolbar.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
When using the search bar for the first time, it will contain only the tools of the workbenches which have already been loaded in FreeCAD.
|
When using the search bar for the first time, it will contain only the tools of the workbenches which have already been loaded in FreeCAD.
|
||||||
To include results from other workbenches, select the first search result "Refresh list of tools" which will load all FreeCAD workbenches
|
To include results from other workbenches, select the first search result "Refresh list of tools" which will load all FreeCAD workbenches
|
||||||
|
@ -22,14 +22,14 @@ and memorize their tools. After restarting FreeCAD, the search result will inclu
|
||||||
been loaded yet. When selecting a tool from the search results, SearchBar will attempt to automatically load the workbenches which could
|
been loaded yet. When selecting a tool from the search results, SearchBar will attempt to automatically load the workbenches which could
|
||||||
have provided that tool.
|
have provided that tool.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
To navigate the search results, use the up and down arrows. Typing characters will filter the results on the fly. The extended information
|
To navigate the search results, use the up and down arrows. Typing characters will filter the results on the fly. The extended information
|
||||||
panel next to the search results provides further documentation about the results, e.g. Python snippets which can be copy-pasted (note:
|
panel next to the search results provides further documentation about the results, e.g. Python snippets which can be copy-pasted (note:
|
||||||
currently a bug crashes FreeCAD if using the context menu to perform the copy, please do not use the context menu until
|
currently a bug crashes FreeCAD if using the context menu to perform the copy, please do not use the context menu until
|
||||||
https://github.com/SuzanneSoy/SearchBar/issues/12 is fixed.
|
https://github.com/SuzanneSoy/SearchBar/issues/12 is fixed.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,28 @@
|
||||||
import os
|
import os
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
|
||||||
def loadAllWorkbenches():
|
def loadAllWorkbenches():
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
import FreeCADGui
|
import FreeCADGui
|
||||||
|
|
||||||
activeWorkbench = FreeCADGui.activeWorkbench().name()
|
activeWorkbench = FreeCADGui.activeWorkbench().name()
|
||||||
lbl = QtGui.QLabel("Loading workbench … (…/…)")
|
lbl = QtGui.QLabel(translate("SearchBar", "Loading workbench … (…/…)"))
|
||||||
lbl.show()
|
lbl.show()
|
||||||
lst = FreeCADGui.listWorkbenches()
|
lst = FreeCADGui.listWorkbenches()
|
||||||
for i, wb in enumerate(lst):
|
for i, wb in enumerate(lst):
|
||||||
msg = "Loading workbench " + wb + " (" + str(i) + "/" + str(len(lst)) + ")"
|
msg = (
|
||||||
|
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()
|
||||||
|
@ -88,8 +99,11 @@ def refreshToolsAction():
|
||||||
fw.clearFocus()
|
fw.clearFocus()
|
||||||
reply = QtGui.QMessageBox.question(
|
reply = QtGui.QMessageBox.question(
|
||||||
None,
|
None,
|
||||||
"Load all workbenches?",
|
translate("SearchBar", "Load all workbenches?"),
|
||||||
|
translate(
|
||||||
|
"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,
|
||||||
)
|
)
|
||||||
|
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 683 KiB After Width: | Height: | Size: 683 KiB |
Before Width: | Height: | Size: 404 KiB After Width: | Height: | Size: 404 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
@ -5,6 +5,9 @@ import FreeCADGui
|
||||||
import SafeViewer
|
import SafeViewer
|
||||||
import SearchBox
|
import SearchBox
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
|
||||||
def documentAction(nfo):
|
def documentAction(nfo):
|
||||||
act = nfo["action"]
|
act = nfo["action"]
|
||||||
|
@ -58,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.
|
# 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))
|
# safeViewerInstance.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed))
|
||||||
self.preview = App._SearchBar3DViewer
|
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
|
# This is really a bad way to do this… to prevent the setExtraInfo function from
|
||||||
# finalizing the object, we remove the parent ourselves.
|
# finalizing the object, we remove the parent ourselves.
|
||||||
|
@ -112,12 +120,22 @@ def documentResultsProvider():
|
||||||
group = []
|
group = []
|
||||||
for o in doc.Objects:
|
for o in doc.Objects:
|
||||||
# all_actions.append(lambda: )
|
# 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 = {
|
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 + ")",
|
"text": o.Label + " (" + o.Name + ")",
|
||||||
# TODO: preview of the object
|
# 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,
|
"action": action,
|
||||||
"subitems": [],
|
"subitems": [],
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ import FreeCAD as App
|
||||||
import FreeCADGui
|
import FreeCADGui
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
import Serialize_SearchBar
|
import Serialize_SearchBar
|
||||||
|
import Parameters_SearchBar as Parameters
|
||||||
|
|
||||||
genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.dirname(__file__) + "/Tango-Tools-spanner-hammer.svg"))
|
genericToolIcon = QtGui.QIcon(QtGui.QIcon(Parameters.genericToolIcon_Pixmap))
|
||||||
|
|
||||||
|
|
||||||
def getParam(grpPath, type_, name):
|
def getParam(grpPath, type_, name):
|
||||||
|
@ -41,7 +42,12 @@ def getParamGroups(nameInConfig, nameInPath):
|
||||||
def recur(atRoot, path, name, tree):
|
def recur(atRoot, path, name, tree):
|
||||||
params = [] if atRoot else getParamGroup(path)
|
params = [] if atRoot else getParamGroup(path)
|
||||||
subgroups = [
|
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()
|
for child in tree.getchildren()
|
||||||
if child.tag == "FCParamGroup"
|
if child.tag == "FCParamGroup"
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
|
import FreeCAD as App
|
||||||
|
import FreeCADGui as Gui
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
import Serialize_SearchBar
|
import Serialize_SearchBar
|
||||||
|
import Parameters_SearchBar as Parameters
|
||||||
|
|
||||||
|
genericToolIcon = QtGui.QIcon(QtGui.QIcon(Parameters.genericToolIcon_Pixmap))
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
|
||||||
def refreshToolsAction(nfo):
|
def refreshToolsAction(nfo):
|
||||||
|
@ -12,11 +21,13 @@ def refreshToolsAction(nfo):
|
||||||
def refreshToolsToolTip(nfo, setParent):
|
def refreshToolsToolTip(nfo, setParent):
|
||||||
return (
|
return (
|
||||||
Serialize_SearchBar.iconToHTML(genericToolIcon)
|
Serialize_SearchBar.iconToHTML(genericToolIcon)
|
||||||
+ "<p>Load all workbenches to refresh this list of tools. This may take a minute, depending on the number of installed workbenches.</p>"
|
+ "<p>"
|
||||||
|
+ translate(
|
||||||
|
"SearchBar",
|
||||||
|
"Load all workbenches to refresh this list of tools. This may take a minute, depending on the number of installed workbenches.",
|
||||||
|
)
|
||||||
|
+ "</p>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.dirname(__file__) + "/Tango-Tools-spanner-hammer.svg"))
|
|
||||||
|
|
||||||
|
|
||||||
def refreshToolsResultsProvider():
|
def refreshToolsResultsProvider():
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
|
import FreeCAD as App
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
import FreeCADGui
|
import FreeCADGui
|
||||||
import Serialize_SearchBar
|
import Serialize_SearchBar
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
|
||||||
def toolbarAction(nfo):
|
def toolbarAction(nfo):
|
||||||
act = nfo["action"]
|
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):
|
def subToolAction(nfo):
|
||||||
|
@ -41,7 +50,10 @@ def subToolAction(nfo):
|
||||||
return True
|
return True
|
||||||
elif action is not None:
|
elif action is not None:
|
||||||
print(
|
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()
|
action.trigger()
|
||||||
return True
|
return True
|
||||||
|
@ -55,14 +67,22 @@ def subToolAction(nfo):
|
||||||
FreeCADGui.activateWorkbench(workbench)
|
FreeCADGui.activateWorkbench(workbench)
|
||||||
if runTool():
|
if runTool():
|
||||||
return
|
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):
|
def toolbarToolTip(nfo, setParent):
|
||||||
workbenches = FreeCADGui.listWorkbenches()
|
workbenches = FreeCADGui.listWorkbenches()
|
||||||
in_workbenches = [
|
in_workbenches = [
|
||||||
"<li>"
|
"<li>"
|
||||||
+ (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
|
+ wb
|
||||||
+ "</li>"
|
+ "</li>"
|
||||||
for wb in nfo["action"]["workbenches"]
|
for wb in nfo["action"]["workbenches"]
|
||||||
|
@ -77,7 +97,12 @@ def toolbarToolTip(nfo, setParent):
|
||||||
|
|
||||||
|
|
||||||
def subToolToolTip(nfo, setParent):
|
def subToolToolTip(nfo, setParent):
|
||||||
return Serialize_SearchBar.iconToHTML(nfo["icon"], 32) + "<p>" + nfo["toolTip"] + "</p>"
|
return (
|
||||||
|
Serialize_SearchBar.iconToHTML(nfo["icon"], 32)
|
||||||
|
+ "<p>"
|
||||||
|
+ nfo["toolTip"]
|
||||||
|
+ "</p>"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def getAllToolbars():
|
def getAllToolbars():
|
||||||
|
@ -140,10 +165,20 @@ def toolbarResultsProvider():
|
||||||
"showMenu": bool(men),
|
"showMenu": bool(men),
|
||||||
}
|
}
|
||||||
group.append(
|
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
|
# TODO: move the 'workbenches' field to the itemgroup
|
||||||
action = {"handler": "toolbar", "workbenches": toolbarIsInWorkbenches, "toolbar": toolbarName}
|
action = {
|
||||||
|
"handler": "toolbar",
|
||||||
|
"workbenches": toolbarIsInWorkbenches,
|
||||||
|
"toolbar": toolbarName,
|
||||||
|
}
|
||||||
itemGroups.append(
|
itemGroups.append(
|
||||||
{
|
{
|
||||||
"icon": QtGui.QIcon(":/icons/Group.svg"),
|
"icon": QtGui.QIcon(":/icons/Group.svg"),
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
import FreeCAD
|
import FreeCAD as App
|
||||||
|
|
||||||
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
|
||||||
class SafeViewer(QtGui.QWidget):
|
class SafeViewer(QtGui.QWidget):
|
||||||
"""FreeCAD uses a modified version of QuarterWidget, so the import pivy.quarter one will cause segfaults.
|
"""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.
|
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 = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").GetBool("PreviewEnabled", False)
|
enabled = App.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").GetBool(
|
||||||
|
"PreviewEnabled", False
|
||||||
|
)
|
||||||
instances = []
|
instances = []
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
@ -27,12 +33,23 @@ class SafeViewer(QtGui.QWidget):
|
||||||
self.lbl_warning.setReadOnly(True)
|
self.lbl_warning.setReadOnly(True)
|
||||||
self.lbl_warning.setAlignment(QtCore.Qt.AlignTop)
|
self.lbl_warning.setAlignment(QtCore.Qt.AlignTop)
|
||||||
self.lbl_warning.setText(
|
self.lbl_warning.setText(
|
||||||
"Warning: the 3D preview has some stability issues. It can cause FreeCAD to crash (usually when quitting the application) and could in theory cause data loss, inside and outside of FreeCAD."
|
translate(
|
||||||
|
"SearchBar",
|
||||||
|
"Warning: the 3D preview has some stability issues. It can cause FreeCAD to crash (usually when quitting the application) and could in theory cause data loss, inside and outside of App.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
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_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_this_session = QtGui.QPushButton("Enable 3D preview for this session")
|
|
||||||
self.btn_enable_for_this_session.clicked.connect(self.enable_for_this_session)
|
|
||||||
self.btn_enable_for_future_sessions = QtGui.QPushButton("Enable 3D preview for future sessions")
|
|
||||||
self.btn_enable_for_future_sessions.clicked.connect(self.enable_for_future_sessions)
|
|
||||||
self.setLayout(QtGui.QVBoxLayout())
|
self.setLayout(QtGui.QVBoxLayout())
|
||||||
self.layout().addWidget(self.lbl_warning)
|
self.layout().addWidget(self.lbl_warning)
|
||||||
self.layout().addWidget(self.btn_enable_for_this_session)
|
self.layout().addWidget(self.btn_enable_for_this_session)
|
||||||
|
@ -46,7 +63,9 @@ class SafeViewer(QtGui.QWidget):
|
||||||
def enable_for_future_sessions(self):
|
def enable_for_future_sessions(self):
|
||||||
if not SafeViewer.enabled:
|
if not SafeViewer.enabled:
|
||||||
# Store in prefs
|
# Store in prefs
|
||||||
FreeCAD.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
|
# Then enable as usual
|
||||||
self.enable_for_this_session()
|
self.enable_for_this_session()
|
||||||
|
|
||||||
|
@ -67,7 +86,9 @@ class SafeViewer(QtGui.QWidget):
|
||||||
self.graphicsView = self.viewer.graphicsView()
|
self.graphicsView = self.viewer.graphicsView()
|
||||||
self.oldGraphicsViewParent = self.graphicsView.parent()
|
self.oldGraphicsViewParent = self.graphicsView.parent()
|
||||||
self.oldGraphicsViewParentParent = self.oldGraphicsViewParent.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.
|
# Avoid segfault but still hide the undesired window by moving it to a new hidden MDI area.
|
||||||
self.hiddenQMDIArea = QtGui.QMdiArea()
|
self.hiddenQMDIArea = QtGui.QMdiArea()
|
||||||
|
|
210
SearchBox.py
|
@ -1,23 +1,63 @@
|
||||||
|
import FreeCAD as App
|
||||||
|
import FreeCADGui as Gui
|
||||||
import os
|
import os
|
||||||
from PySide import QtGui
|
|
||||||
from PySide import QtCore
|
from PySide.QtCore import (
|
||||||
import FreeCADGui # just used for FreeCADGui.updateGui()
|
Qt,
|
||||||
|
SIGNAL,
|
||||||
|
QSize,
|
||||||
|
QIdentityProxyModel,
|
||||||
|
QPoint,
|
||||||
|
)
|
||||||
|
from PySide.QtWidgets import (
|
||||||
|
QTabWidget,
|
||||||
|
QSlider,
|
||||||
|
QSpinBox,
|
||||||
|
QCheckBox,
|
||||||
|
QComboBox,
|
||||||
|
QLabel,
|
||||||
|
QTabWidget,
|
||||||
|
QSizePolicy,
|
||||||
|
QPushButton,
|
||||||
|
QLineEdit,
|
||||||
|
QTextEdit,
|
||||||
|
QListView,
|
||||||
|
QAbstractItemView,
|
||||||
|
QWidget,
|
||||||
|
QVBoxLayout,
|
||||||
|
QApplication,
|
||||||
|
QListWidget,
|
||||||
|
)
|
||||||
|
from PySide.QtGui import (
|
||||||
|
QIcon,
|
||||||
|
QPixmap,
|
||||||
|
QColor,
|
||||||
|
QStandardItemModel,
|
||||||
|
QShortcut,
|
||||||
|
QKeySequence,
|
||||||
|
QStandardItem,
|
||||||
|
)
|
||||||
|
|
||||||
from SearchBoxLight import SearchBoxLight
|
from SearchBoxLight import SearchBoxLight
|
||||||
|
import Parameters_SearchBar as Parameters
|
||||||
|
|
||||||
|
genericToolIcon = QIcon(Parameters.genericToolIcon_Pixmap)
|
||||||
|
|
||||||
globalIgnoreFocusOut = False
|
globalIgnoreFocusOut = False
|
||||||
|
|
||||||
genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.dirname(__file__) + "/Tango-Tools-spanner-hammer.svg"))
|
# Define the translation
|
||||||
|
translate = App.Qt.translate
|
||||||
|
|
||||||
|
|
||||||
def easyToolTipWidget(html):
|
def easyToolTipWidget(html):
|
||||||
foo = QtGui.QTextEdit()
|
foo = QTextEdit()
|
||||||
foo.setReadOnly(True)
|
foo.setReadOnly(True)
|
||||||
foo.setAlignment(QtCore.Qt.AlignTop)
|
foo.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||||
foo.setText(html)
|
foo.setText(html)
|
||||||
return foo
|
return foo
|
||||||
|
|
||||||
|
|
||||||
class SearchBox(QtGui.QLineEdit):
|
class SearchBox(QLineEdit):
|
||||||
# The following block of code is present in the lightweight proxy SearchBoxLight
|
# The following block of code is present in the lightweight proxy SearchBoxLight
|
||||||
"""
|
"""
|
||||||
resultSelected = QtCore.Signal(int, int)
|
resultSelected = QtCore.Signal(int, int)
|
||||||
|
@ -38,8 +78,8 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
# Connect signals and slots
|
# Connect signals and slots
|
||||||
self.textChanged.connect(self.filterModel)
|
self.textChanged.connect(self.filterModel)
|
||||||
# Thanks to https://saurabhg.com/programming/search-box-using-qlineedit/ for indicating a few useful options
|
# Thanks to https://saurabhg.com/programming/search-box-using-qlineedit/ for indicating a few useful options
|
||||||
ico = QtGui.QIcon(':/icons/help-browser.svg')
|
ico = QIcon(':/icons/help-browser.svg')
|
||||||
#ico = QtGui.QIcon(':/icons/WhatsThis.svg')
|
#ico = QIcon(':/icons/WhatsThis.svg')
|
||||||
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')
|
||||||
|
@ -51,27 +91,32 @@ class SearchBox(QtGui.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 = maxVisibleRows # TODO: use this to compute the correct height
|
self.maxVisibleRows = (
|
||||||
|
maxVisibleRows # TODO: use this to compute the correct height
|
||||||
|
)
|
||||||
# Create proxy model
|
# Create proxy model
|
||||||
self.proxyModel = QtCore.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.
|
||||||
self.mdl = QtGui.QStandardItemModel()
|
self.mdl = QStandardItemModel()
|
||||||
# self.proxyModel.setModel(self.model)
|
# self.proxyModel.setModel(self.model)
|
||||||
# Create list view
|
# Create list view
|
||||||
self.listView = QtGui.QListView(self)
|
self.listView = QListView(self)
|
||||||
self.listView.setWindowFlags(QtGui.Qt.ToolTip)
|
self.listView.setWindowFlags(Qt.WindowType.ToolTip)
|
||||||
self.listView.setWindowFlag(QtGui.Qt.FramelessWindowHint)
|
self.listView.setWindowFlag(Qt.WindowType.FramelessWindowHint)
|
||||||
self.listView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
|
self.listView.setSelectionMode(self.listView.SelectionMode.SingleSelection)
|
||||||
self.listView.setModel(self.proxyModel)
|
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
|
# make the QListView non-editable
|
||||||
self.listView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
|
self.listView.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
|
||||||
# Create pane for showing extra info about the currently-selected tool
|
# Create pane for showing extra info about the currently-selected tool
|
||||||
# self.extraInfo = QtGui.QLabel()
|
# self.extraInfo = QtGui.QLabel()
|
||||||
self.extraInfo = QtGui.QWidget()
|
self.extraInfo = QWidget()
|
||||||
self.extraInfo.setWindowFlags(QtGui.Qt.ToolTip)
|
self.extraInfo.setWindowFlags(Qt.WindowType.ToolTip)
|
||||||
self.extraInfo.setWindowFlag(QtGui.Qt.FramelessWindowHint)
|
self.extraInfo.setWindowFlag(Qt.WindowType.FramelessWindowHint)
|
||||||
self.extraInfo.setLayout(QtGui.QVBoxLayout())
|
self.extraInfo.setLayout(QVBoxLayout())
|
||||||
self.extraInfo.layout().setContentsMargins(0, 0, 0, 0)
|
self.extraInfo.layout().setContentsMargins(0, 0, 0, 0)
|
||||||
self.setExtraInfoIsActive = False
|
self.setExtraInfoIsActive = False
|
||||||
self.pendingExtraInfo = None
|
self.pendingExtraInfo = None
|
||||||
|
@ -79,40 +124,52 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
# Connect signals and slots
|
# Connect signals and slots
|
||||||
self.listView.clicked.connect(lambda x: self.selectResult("select", x))
|
self.listView.clicked.connect(lambda x: self.selectResult("select", x))
|
||||||
self.listView.selectionModel().selectionChanged.connect(self.onSelectionChanged)
|
self.listView.selectionModel().selectionChanged.connect(self.onSelectionChanged)
|
||||||
|
# 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
|
||||||
|
self.listView.mousePressEvent = lambda event: self.proxyMousePressEvent(event)
|
||||||
|
self.listView.mouseMoveEvent = lambda event: self.proxyMouseMoveEvent(event)
|
||||||
|
|
||||||
# Note: should probably use the eventFilter method instead...
|
# Note: should probably use the eventFilter method instead...
|
||||||
wdgctx = QtCore.Qt.ShortcutContext.WidgetShortcut
|
wdgctx = Qt.ShortcutContext.WidgetShortcut
|
||||||
|
|
||||||
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Down), self, context=wdgctx).activated.connect(self.listDown)
|
QShortcut(
|
||||||
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Up), self, context=wdgctx).activated.connect(self.listUp)
|
QKeySequence(Qt.Key.Key_Down), self, context=wdgctx
|
||||||
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_PageDown), self, context=wdgctx).activated.connect(
|
).activated.connect(self.listDown)
|
||||||
self.listPageDown
|
QShortcut(QKeySequence(Qt.Key.Key_Up), self, context=wdgctx).activated.connect(
|
||||||
)
|
self.listUp
|
||||||
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_PageUp), self, context=wdgctx).activated.connect(
|
|
||||||
self.listPageUp
|
|
||||||
)
|
)
|
||||||
|
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.
|
||||||
# QtGui.QShortcut(QtGui.QKeySequence.MoveToEndOfDocument, self, context = wdgctx).activated.connect(self.listEnd)
|
# QShortcut(QKeySequence.MoveToEndOfDocument, self, context = wdgctx).activated.connect(self.listEnd)
|
||||||
# QtGui.QShortcut(QtGui.QKeySequence.MoveToStartOfDocument, self, context = wdgctx).activated.connect(self.listStart)
|
# QShortcut(QKeySequence.MoveToStartOfDocument, self, context = wdgctx).activated.connect(self.listStart)
|
||||||
# QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_End), self, context = wdgctx).activated.connect(self.listEnd)
|
# QShortcut(QKeySequence(Qt.Key.Key_End), self, context = wdgctx).activated.connect(self.listEnd)
|
||||||
# QtGui.QShortcut(QtGui.QKeySequence('Home'), self, context = wdgctx).activated.connect(self.listStart)
|
# QShortcut(QKeySequence('Home'), self, context = wdgctx).activated.connect(self.listStart)
|
||||||
|
|
||||||
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Enter), self, context=wdgctx).activated.connect(
|
QShortcut(
|
||||||
self.listAccept
|
QKeySequence(Qt.Key.Key_Enter), self, context=wdgctx
|
||||||
)
|
).activated.connect(self.listAccept)
|
||||||
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Return), self, context=wdgctx).activated.connect(
|
QShortcut(
|
||||||
self.listAccept
|
QKeySequence(Qt.Key.Key_Return), self, context=wdgctx
|
||||||
)
|
).activated.connect(self.listAccept)
|
||||||
QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Return"), self, context=wdgctx).activated.connect(
|
QShortcut(QKeySequence("Ctrl+Return"), self, context=wdgctx).activated.connect(
|
||||||
self.listAcceptToggle
|
self.listAcceptToggle
|
||||||
)
|
)
|
||||||
QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Enter"), self, context=wdgctx).activated.connect(self.listAcceptToggle)
|
QShortcut(QKeySequence("Ctrl+Enter"), self, context=wdgctx).activated.connect(
|
||||||
QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Space"), self, context=wdgctx).activated.connect(self.listAcceptToggle)
|
self.listAcceptToggle
|
||||||
|
|
||||||
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Escape), self, context=wdgctx).activated.connect(
|
|
||||||
self.listCancel
|
|
||||||
)
|
)
|
||||||
|
QShortcut(QKeySequence("Ctrl+Space"), self, context=wdgctx).activated.connect(
|
||||||
|
self.listAcceptToggle
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
# 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
|
||||||
|
@ -120,6 +177,16 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
self.isInitialized = True
|
self.isInitialized = True
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def proxyMousePressEvent(self, event):
|
||||||
|
self.selectResult(mode=None, index=self.listView.currentIndex())
|
||||||
|
return
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def proxyMouseMoveEvent(self, arg__1):
|
||||||
|
self.listView.setCurrentIndex(self.listView.indexAt(arg__1.pos()))
|
||||||
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def refreshItemGroups(self):
|
def refreshItemGroups(self):
|
||||||
self.itemGroups = self.getItemGroups()
|
self.itemGroups = self.getItemGroups()
|
||||||
|
@ -128,18 +195,23 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def proxyFocusInEvent(self, qFocusEvent):
|
def proxyFocusInEvent(self, qFocusEvent):
|
||||||
if self.firstShowList:
|
if self.firstShowList:
|
||||||
mdl = QtGui.QStandardItemModel()
|
mdl = QStandardItemModel()
|
||||||
mdl.appendRow(
|
mdl.appendRow(
|
||||||
[
|
[
|
||||||
QtGui.QStandardItem(genericToolIcon, "Please wait, loading results from cache…"),
|
QStandardItem(
|
||||||
QtGui.QStandardItem("0"),
|
genericToolIcon,
|
||||||
QtGui.QStandardItem("-1"),
|
translate(
|
||||||
|
"SearchBar", "Please wait, loading results from cache…"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
QStandardItem("0"),
|
||||||
|
QStandardItem("-1"),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
self.proxyModel.setSourceModel(mdl)
|
self.proxyModel.setSourceModel(mdl)
|
||||||
self.showList()
|
self.showList()
|
||||||
self.firstShowList = False
|
self.firstShowList = False
|
||||||
FreeCADGui.updateGui()
|
Gui.updateGui()
|
||||||
global globalIgnoreFocusOut
|
global globalIgnoreFocusOut
|
||||||
if not globalIgnoreFocusOut:
|
if not globalIgnoreFocusOut:
|
||||||
self.refreshItemGroups()
|
self.refreshItemGroups()
|
||||||
|
@ -175,11 +247,17 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def proxyListPageDown(self):
|
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
|
@staticmethod
|
||||||
def proxyListPageUp(self):
|
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
|
@staticmethod
|
||||||
def proxyListEnd(self):
|
def proxyListEnd(self):
|
||||||
|
@ -191,6 +269,7 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def acceptKey(self, mode):
|
def acceptKey(self, mode):
|
||||||
|
print(f"Got here, {mode}")
|
||||||
currentIndex = self.listView.currentIndex()
|
currentIndex = self.listView.currentIndex()
|
||||||
self.showList()
|
self.showList()
|
||||||
if currentIndex.isValid():
|
if currentIndex.isValid():
|
||||||
|
@ -219,9 +298,9 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
key = qKeyEvent.key()
|
key = qKeyEvent.key()
|
||||||
modifiers = qKeyEvent.modifiers()
|
modifiers = qKeyEvent.modifiers()
|
||||||
self.showList()
|
self.showList()
|
||||||
if key == QtCore.Qt.Key_Home and modifiers & QtCore.Qt.CTRL != 0:
|
if key == Qt.Key.Key_Home and modifiers & Qt.Key.CTRL != 0:
|
||||||
self.listStart()
|
self.listStart()
|
||||||
elif key == QtCore.Qt.Key_End and modifiers & QtCore.Qt.CTRL != 0:
|
elif key == Qt.Key.Key_End and modifiers & Qt.Key.CTRL != 0:
|
||||||
self.listEnd()
|
self.listEnd()
|
||||||
else:
|
else:
|
||||||
super(SearchBoxLight, self).keyPressEvent(qKeyEvent)
|
super(SearchBoxLight, self).keyPressEvent(qKeyEvent)
|
||||||
|
@ -243,8 +322,9 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
self.extraInfo.hide()
|
self.extraInfo.hide()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def selectResult(self, mode, index):
|
def selectResult(self, mode: None, index):
|
||||||
groupId = int(index.model().itemData(index.siblingAtColumn(2))[0])
|
groupId = int(index.model().itemData(index.siblingAtColumn(2))[0])
|
||||||
|
print(f"Got here, {index}")
|
||||||
self.hideList()
|
self.hideList()
|
||||||
# TODO: allow other options, e.g. some items could act as combinators / cumulative filters
|
# TODO: allow other options, e.g. some items could act as combinators / cumulative filters
|
||||||
self.setText("")
|
self.setText("")
|
||||||
|
@ -280,7 +360,7 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
groups = (filterGroup(group) for group in groups)
|
groups = (filterGroup(group) for group in groups)
|
||||||
return [group for group in groups if group is not None]
|
return [group for group in groups if group is not None]
|
||||||
|
|
||||||
self.mdl = QtGui.QStandardItemModel()
|
self.mdl = QStandardItemModel()
|
||||||
self.mdl.appendColumn([])
|
self.mdl.appendColumn([])
|
||||||
|
|
||||||
def addGroups(filteredGroups, depth=0):
|
def addGroups(filteredGroups, depth=0):
|
||||||
|
@ -288,9 +368,9 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
# TODO: this is not very clean, we should memorize the index from the original itemgroups
|
# TODO: this is not very clean, we should memorize the index from the original itemgroups
|
||||||
self.mdl.appendRow(
|
self.mdl.appendRow(
|
||||||
[
|
[
|
||||||
QtGui.QStandardItem(group["icon"] or genericToolIcon, group["text"]),
|
QStandardItem(group["icon"] or genericToolIcon, group["text"]),
|
||||||
QtGui.QStandardItem(str(depth)),
|
QStandardItem(str(depth)),
|
||||||
QtGui.QStandardItem(str(group["id"])),
|
QStandardItem(str(group["id"])),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
addGroups(group["subitems"], depth + 1)
|
addGroups(group["subitems"], depth + 1)
|
||||||
|
@ -313,12 +393,14 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
def getScreenPosition(widget):
|
def getScreenPosition(widget):
|
||||||
geo = widget.geometry()
|
geo = widget.geometry()
|
||||||
parent = widget.parent()
|
parent = widget.parent()
|
||||||
parentPos = getScreenPosition(parent) if parent is not None else QtCore.QPoint(0, 0)
|
parentPos = (
|
||||||
return QtCore.QPoint(geo.x() + parentPos.x(), geo.y() + parentPos.y())
|
getScreenPosition(parent) if parent is not None else QPoint(0, 0)
|
||||||
|
)
|
||||||
|
return QPoint(geo.x() + parentPos.x(), geo.y() + parentPos.y())
|
||||||
|
|
||||||
pos = getScreenPosition(self)
|
pos = getScreenPosition(self)
|
||||||
siz = self.size()
|
siz = self.size()
|
||||||
screen = QtGui.QGuiApplication.screenAt(pos)
|
screen = QApplication.screenAt(pos)
|
||||||
x = pos.x()
|
x = pos.x()
|
||||||
y = pos.y() + siz.height()
|
y = pos.y() + siz.height()
|
||||||
hint_w = self.listView.sizeHint().width()
|
hint_w = self.listView.sizeHint().width()
|
||||||
|
@ -345,7 +427,7 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def proxyOnSelectionChanged(self, selected, deselected):
|
def proxyOnSelectionChanged(self, selected, deselected):
|
||||||
# The list has .setSelectionMode(QtGui.QAbstractItemView.SingleSelection),
|
# The list has .setSelectionMode(QAbstractItemView.SingleSelection),
|
||||||
# so there is always at most one index in selected.indexes() and at most one
|
# so there is always at most one index in selected.indexes() and at most one
|
||||||
# index in deselected.indexes()
|
# index in deselected.indexes()
|
||||||
selected = selected.indexes()
|
selected = selected.indexes()
|
||||||
|
|
|
@ -6,7 +6,9 @@ from PySide import QtCore
|
||||||
class SearchBoxLight(QtGui.QLineEdit):
|
class SearchBoxLight(QtGui.QLineEdit):
|
||||||
resultSelected = QtCore.Signal(int, int)
|
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
|
self.isInitialized = False
|
||||||
|
|
||||||
# Store arguments
|
# Store arguments
|
||||||
|
@ -25,7 +27,9 @@ 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(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):
|
def lazyInit(self):
|
||||||
pass
|
pass
|
||||||
|
@ -41,6 +45,12 @@ class SearchBoxLight(QtGui.QLineEdit):
|
||||||
|
|
||||||
return types.MethodType(f, self)
|
return types.MethodType(f, self)
|
||||||
|
|
||||||
|
def MousePressEvent(self, *args, **kwargs):
|
||||||
|
return self.proxyMousePressEvent(*args, **kwargs)
|
||||||
|
|
||||||
|
def MouseMoveEvent(self, *args, **kwargs):
|
||||||
|
return self.proxyMouseMoveEvent(*args, **kwargs)
|
||||||
|
|
||||||
def focusInEvent(self, *args, **kwargs):
|
def focusInEvent(self, *args, **kwargs):
|
||||||
return self.proxyFocusInEvent(*args, **kwargs)
|
return self.proxyFocusInEvent(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
actionHandlers = { }
|
actionHandlers = {}
|
||||||
toolTipHandlers = { }
|
toolTipHandlers = {}
|
||||||
resultProvidersCached = { }
|
resultProvidersCached = {}
|
||||||
resultProvidersUncached = { }
|
resultProvidersUncached = {}
|
||||||
|
|
||||||
|
|
||||||
# name : string
|
# name : string
|
||||||
# getItemGroupsCached: () -> [itemGroup]
|
# getItemGroupsCached: () -> [itemGroup]
|
||||||
|
@ -10,6 +11,7 @@ def registerResultProvider(name, getItemGroupsCached, getItemGroupsUncached):
|
||||||
resultProvidersCached[name] = getItemGroupsCached
|
resultProvidersCached[name] = getItemGroupsCached
|
||||||
resultProvidersUncached[name] = getItemGroupsUncached
|
resultProvidersUncached[name] = getItemGroupsUncached
|
||||||
|
|
||||||
|
|
||||||
# name : str
|
# name : str
|
||||||
# action : act -> None
|
# action : act -> None
|
||||||
# toolTip : groupId, setParent -> (str or QWidget)
|
# toolTip : groupId, setParent -> (str or QWidget)
|
||||||
|
|
|
@ -3,7 +3,12 @@ from PySide import QtGui
|
||||||
import json
|
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.
|
Converts a QIcon to a Base64-encoded string representation of its pixmap.
|
||||||
|
|
||||||
|
@ -59,8 +64,13 @@ def serializeIcon(icon):
|
||||||
"selected": QtGui.QIcon.Mode.Selected,
|
"selected": QtGui.QIcon.Mode.Selected,
|
||||||
}.items():
|
}.items():
|
||||||
iconPixmaps[strW][strH][strMode] = {}
|
iconPixmaps[strW][strH][strMode] = {}
|
||||||
for strState, state in {"off": QtGui.QIcon.State.Off, "on": QtGui.QIcon.State.On}.items():
|
for strState, state in {
|
||||||
iconPixmaps[strW][strH][strMode][strState] = iconToBase64(icon, sz, mode, state)
|
"off": QtGui.QIcon.State.Off,
|
||||||
|
"on": QtGui.QIcon.State.On,
|
||||||
|
}.items():
|
||||||
|
iconPixmaps[strW][strH][strMode][strState] = iconToBase64(
|
||||||
|
icon, sz, mode, state
|
||||||
|
)
|
||||||
return iconPixmaps
|
return iconPixmaps
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,9 +97,15 @@ def deserializeIcon(iconPixmaps):
|
||||||
"selected": QtGui.QIcon.Mode.Selected,
|
"selected": QtGui.QIcon.Mode.Selected,
|
||||||
}[strMode]
|
}[strMode]
|
||||||
for strState, statePixmap in modePixmaps.items():
|
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 = 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)
|
ico.addPixmap(pxm, mode, state)
|
||||||
return ico
|
return ico
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<description>Adds a search bar widget for tools, document objects, and preferences</description>
|
<description>Adds a search bar widget for tools, document objects, and preferences</description>
|
||||||
|
|
||||||
<version>1.2.1</version>
|
<version>1.3.0</version>
|
||||||
|
|
||||||
<date>2022-06-01</date>
|
<date>2022-06-01</date>
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
<content>
|
<content>
|
||||||
<workbench>
|
<workbench>
|
||||||
<name>SearchBar</name>
|
<name>SearchBar</name>
|
||||||
<icon>Tango-System-search.svg</icon>
|
<icon>Resource/Icons/Tango-System-search.svg</icon>
|
||||||
<subdirectory>./</subdirectory>
|
<subdirectory>./</subdirectory>
|
||||||
<tag>search</tag>
|
<tag>search</tag>
|
||||||
<tag>widget</tag>
|
<tag>widget</tag>
|
||||||
|
|
104
translations/README.md
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
# About translating Ribbon Addon
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> All commands **must** be run in `./translations/` directory.
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> If you want to update/release the files you need to have installed
|
||||||
|
> `lupdate` and `lrelease` from Qt6 version. Using the versions from
|
||||||
|
> Qt5 is not advised because they're buggy.
|
||||||
|
|
||||||
|
## Updating translations template file
|
||||||
|
|
||||||
|
To update the template file from source files you should use this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./update_translation.sh -U
|
||||||
|
```
|
||||||
|
|
||||||
|
Once done you can commit the changes and upload the new file to CrowdIn platform
|
||||||
|
at <https://crowdin.com/project/freecad-addons> webpage and find the **Ribbon** project.
|
||||||
|
|
||||||
|
## Creating file for missing locale
|
||||||
|
|
||||||
|
### Using script
|
||||||
|
|
||||||
|
To create a file for a new language with all **Ribbon** translatable strings execute
|
||||||
|
the script with `-u` flag plus your locale:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./update_translation.sh -u de
|
||||||
|
```
|
||||||
|
|
||||||
|
### Renaming file
|
||||||
|
|
||||||
|
Also you can rename new `SearchBar.ts` file by appending the locale code,
|
||||||
|
for example, `SearchBar_de.ts` for German and change
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<TS version="2.1">
|
||||||
|
```
|
||||||
|
|
||||||
|
to
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<TS version="2.1" language="de" sourcelanguage="en">
|
||||||
|
```
|
||||||
|
|
||||||
|
As of 2024/10/28 the supported locales on FreeCAD
|
||||||
|
(according to `FreeCADGui.supportedLocales()`) are 44:
|
||||||
|
|
||||||
|
```python
|
||||||
|
{'English': 'en', 'Afrikaans': 'af', 'Arabic': 'ar', 'Basque': 'eu',
|
||||||
|
'Belarusian': 'be', 'Bulgarian': 'bg', 'Catalan': 'ca',
|
||||||
|
'Chinese Simplified': 'zh-CN', 'Chinese Traditional': 'zh-TW', 'Croatian': 'hr',
|
||||||
|
'Czech': 'cs', 'Danish': 'da', 'Dutch': 'nl', 'Filipino': 'fil', 'Finnish': 'fi',
|
||||||
|
'French': 'fr', 'Galician': 'gl', 'Georgian': 'ka', 'German': 'de', 'Greek': 'el',
|
||||||
|
'Hungarian': 'hu', 'Indonesian': 'id', 'Italian': 'it', 'Japanese': 'ja',
|
||||||
|
'Kabyle': 'kab', 'Korean': 'ko', 'Lithuanian': 'lt', 'Norwegian': 'no',
|
||||||
|
'Polish': 'pl', 'Portuguese': 'pt-PT', 'Portuguese, Brazilian': 'pt-BR',
|
||||||
|
'Romanian': 'ro', 'Russian': 'ru', 'Serbian': 'sr', 'Serbian, Latin': 'sr-CS',
|
||||||
|
'Slovak': 'sk', 'Slovenian': 'sl', 'Spanish': 'es-ES', 'Spanish, Argentina': 'es-AR',
|
||||||
|
'Swedish': 'sv-SE', 'Turkish': 'tr', 'Ukrainian': 'uk', 'Valencian': 'val-ES',
|
||||||
|
'Vietnamese': 'vi'}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Translating
|
||||||
|
|
||||||
|
To edit your language file open your file in `Qt Linguist` from `qt5-tools`/`qt6-tools`
|
||||||
|
package or in a text editor like `xed`, `mousepad`, `gedit`, `nano`, `vim`/`nvim`,
|
||||||
|
`geany` etc. and translate it.
|
||||||
|
|
||||||
|
Alternatively you can visit the **FreeCAD-addons** project on CrowdIn platform
|
||||||
|
at <https://crowdin.com/project/freecad-addons> webpage and find your language,
|
||||||
|
once done, look for the **Ribbon** project.
|
||||||
|
|
||||||
|
## Compiling translations
|
||||||
|
|
||||||
|
To convert all `.ts` files to `.qm` files (merge) you can use this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./update_translation.sh -R
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are a translator that wants to update only their language file
|
||||||
|
to test it on **FreeCAD** before doing a PR you can use this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./update_translation.sh -r de
|
||||||
|
```
|
||||||
|
|
||||||
|
This will update the `.qm` file for your language (German in this case).
|
||||||
|
|
||||||
|
## Sending translations
|
||||||
|
|
||||||
|
Now you can contribute your translated `.ts` file to **Ribbon** repository,
|
||||||
|
also include the `.qm` file.
|
||||||
|
|
||||||
|
<https://github.com/APEbbers/FreeCAD-Ribbon>
|
||||||
|
|
||||||
|
## More information
|
||||||
|
|
||||||
|
You can read more about translating external workbenches here:
|
||||||
|
|
||||||
|
<https://wiki.freecad.org/Translating_an_external_workbench>
|
166
translations/update_translation.sh
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Create, update and release translation files.
|
||||||
|
#
|
||||||
|
# Supported locales on FreeCAD <2024-10-14, FreeCADGui.supportedLocales(), total=44>:
|
||||||
|
# {'English': 'en', 'Afrikaans': 'af', 'Arabic': 'ar', 'Basque': 'eu', 'Belarusian': 'be',
|
||||||
|
# 'Bulgarian': 'bg', 'Catalan': 'ca', 'Chinese Simplified': 'zh-CN',
|
||||||
|
# 'Chinese Traditional': 'zh-TW', 'Croatian': 'hr', 'Czech': 'cs', 'Danish': 'da',
|
||||||
|
# 'Dutch': 'nl', 'Filipino': 'fil', 'Finnish': 'fi', 'French': 'fr', 'Galician': 'gl',
|
||||||
|
# 'Georgian': 'ka', 'German': 'de', 'Greek': 'el', 'Hungarian': 'hu', 'Indonesian': 'id',
|
||||||
|
# 'Italian': 'it', 'Japanese': 'ja', 'Kabyle': 'kab', 'Korean': 'ko', 'Lithuanian': 'lt',
|
||||||
|
# 'Norwegian': 'no', 'Polish': 'pl', 'Portuguese': 'pt-PT', 'Portuguese, Brazilian': 'pt-BR',
|
||||||
|
# 'Romanian': 'ro', 'Russian': 'ru', 'Serbian': 'sr', 'Serbian, Latin': 'sr-CS', 'Slovak': 'sk',
|
||||||
|
# 'Slovenian': 'sl', 'Spanish': 'es-ES', 'Spanish, Argentina': 'es-AR', 'Swedish': 'sv-SE',
|
||||||
|
# 'Turkish': 'tr', 'Ukrainian': 'uk', 'Valencian': 'val-ES', 'Vietnamese': 'vi'}
|
||||||
|
#
|
||||||
|
# NOTE: PREPARATION
|
||||||
|
# - Install Qt tools
|
||||||
|
# Debian-based (e.g., Ubuntu): $ sudo apt-get install qttools5-dev-tools pyqt6-dev-tools
|
||||||
|
# Fedora-based: $ sudo dnf install qt6-linguist qt6-devel
|
||||||
|
# Arch-based: $ sudo pacman -S qt6-tools python-pyqt6
|
||||||
|
# - Make the script executable
|
||||||
|
# $ chmod +x update_translation.sh
|
||||||
|
# - The script has to be executed within the `translations` directory.
|
||||||
|
# Executing the script with no flags invokes the help.
|
||||||
|
# $ ./update_translation.sh
|
||||||
|
#
|
||||||
|
# NOTE: WORKFLOW TRANSLATOR (LOCAL)
|
||||||
|
# - Execute the script passing the `-u` flag plus locale code as argument
|
||||||
|
# Only update the file(s) you're translating!
|
||||||
|
# $ ./update_translation.sh -u es-ES
|
||||||
|
# - Do the translation via Qt Linguist and use `File>Release`
|
||||||
|
# - If releasing with the script execute it passing the `-r` flag
|
||||||
|
# plus locale code as argument
|
||||||
|
# $ ./update_translation.sh -r es-ES
|
||||||
|
#
|
||||||
|
# NOTE: WORKFLOW MAINTAINER (CROWDIN)
|
||||||
|
# - Execute the script passing the '-U' flag
|
||||||
|
# $ ./update_translation.sh -U
|
||||||
|
# - Once done, download the translated files, copy them to `translations`
|
||||||
|
# - Upload the updated file to CrowdIn and wait for translators do their thing ;-)
|
||||||
|
# and release all the files to update the changes
|
||||||
|
# $ ./update_translation.sh -R
|
||||||
|
#
|
||||||
|
# --------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
supported_locales=(
|
||||||
|
"en" "af" "ar" "eu" "be" "bg" "ca" "zh-CN" "zh-TW" "hr"
|
||||||
|
"cs" "da" "nl" "fil" "fi" "fr" "gl" "ka" "de" "el"
|
||||||
|
"hu" "id" "it" "ja" "kab" "ko" "lt" "no" "pl" "pt-PT"
|
||||||
|
"pt-BR" "ro" "ru" "sr" "sr-CS" "sk" "sl" "es-ES" "es-AR" "sv-SE"
|
||||||
|
"tr" "uk" "val-ES" "vi"
|
||||||
|
)
|
||||||
|
|
||||||
|
is_locale_supported() {
|
||||||
|
local locale="$1"
|
||||||
|
for supported_locale in "${supported_locales[@]}"; do
|
||||||
|
[ "$supported_locale" == "$locale" ] && return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
update_locale() {
|
||||||
|
local locale="$1"
|
||||||
|
local u=${locale:+_} # Conditional underscore
|
||||||
|
FILES="../*.py ../Resources/ui/*.ui"
|
||||||
|
|
||||||
|
# NOTE: Execute the right commands depending on:
|
||||||
|
# - if it's a locale file or the main, agnostic one
|
||||||
|
[ ! -f "${WB}${u}${locale}.ts" ] && action="Creating" || action="Updating"
|
||||||
|
echo -e "\033[1;34m\n\t<<< ${action} '${WB}${u}${locale}.ts' file >>>\n\033[m"
|
||||||
|
if [ "$u" == "" ]; then
|
||||||
|
eval $LUPDATE "$FILES" -ts "${WB}.ts" # locale-agnostic file
|
||||||
|
else
|
||||||
|
eval $LUPDATE "$FILES" -source-language en_US -target-language "${locale//-/_}" \
|
||||||
|
-ts "${WB}_${locale}.ts"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
normalize_crowdin_files() {
|
||||||
|
# Rename files which locales are different on FreeCAD and delete not supported locales
|
||||||
|
crowdin_fixes=(af-ZA ar-SA be-BY bg-BG ca-ES cs-CZ da-DK de-DE el-GR eu-ES fi-FI
|
||||||
|
fil-PH fr-FR gl-ES hr-HR hu-HU it-IT ja-JP ka-GE kab-KAB ko-KR lt-LT nl-NL
|
||||||
|
no-NO pl-PL ro-RO ru-RU sk-SK sl-SI sr-SP tr-TR uk-UA vi-VN)
|
||||||
|
|
||||||
|
crowdin_deletes=(az-AZ bn-BD br-FR bs-BA en en-GB en-US eo-UY es-CO es-VE et-EE fa-IR he-IL
|
||||||
|
hi-IN hy-AM id-ID kaa lv-LV mk-MK ms-MY sat-IN si-LK ta-IN te-IN th-TH ur-PK xav yo-NG)
|
||||||
|
|
||||||
|
for pattern in "${crowdin_fixes[@]}"; do
|
||||||
|
find . -type f -name "*_${pattern}\.*" | while read -r file; do
|
||||||
|
mv -v "$file" "${file//-*./.}"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
for pattern in "${crowdin_deletes[@]}"; do
|
||||||
|
find . -type f -name "*_${pattern}\.*" -delete
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo -e "\nDescription:"
|
||||||
|
echo -e "\tCreate, update and release translation files."
|
||||||
|
echo -e "\nUsage:"
|
||||||
|
echo -e "\t./update_translation.sh [-R] [-U] [-r <locale>] [-u <locale>]"
|
||||||
|
echo -e "\nFlags:"
|
||||||
|
echo -e " -R\n\tRelease all translations (qm files)"
|
||||||
|
echo -e " -U\n\tUpdate all translations (ts files)"
|
||||||
|
echo -e " -r <locale>\n\tRelease the specified locale"
|
||||||
|
echo -e " -u <locale>\n\tUpdate strings for the specified locale"
|
||||||
|
echo -e " -N\n\tNormalize CrowdIn filenames"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main function ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
LUPDATE=/usr/lib/qt6/bin/lupdate # from Qt6
|
||||||
|
# LUPDATE=lupdate # from Qt5
|
||||||
|
LRELEASE=/usr/lib/qt6/bin/lrelease # from Qt6
|
||||||
|
# LRELEASE=lrelease # from Qt5
|
||||||
|
WB="SearchBar"
|
||||||
|
|
||||||
|
sed -i '3s/-/_/' ${WB}*.ts # Enforce underscore on locales
|
||||||
|
sed -i '3s/\"en\"/\"en_US\"/g' ${WB}*.ts # Use en_US
|
||||||
|
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
if [ "$1" == "-R" ]; then
|
||||||
|
find . -type f -name '*_*.ts' | while IFS= read -r file; do
|
||||||
|
# Release all locales
|
||||||
|
$LRELEASE -nounfinished "$file"
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
elif [ "$1" == "-U" ]; then
|
||||||
|
for locale in "${supported_locales[@]}"; do
|
||||||
|
update_locale "$locale"
|
||||||
|
done
|
||||||
|
elif [ "$1" == "-u" ]; then
|
||||||
|
update_locale # Update main file (agnostic)
|
||||||
|
elif [ "$1" == "-N" ]; then
|
||||||
|
normalize_crowdin_files
|
||||||
|
else
|
||||||
|
help
|
||||||
|
fi
|
||||||
|
elif [ $# -eq 2 ]; then
|
||||||
|
LOCALE="$2"
|
||||||
|
if is_locale_supported "$LOCALE"; then
|
||||||
|
if [ "$1" == "-r" ]; then
|
||||||
|
# Release locale (creation of *.qm file from *.ts file)
|
||||||
|
$LRELEASE -nounfinished "${WB}_${LOCALE}.ts"
|
||||||
|
elif [ "$1" == "-u" ]; then
|
||||||
|
# Update main & locale files
|
||||||
|
update_locale
|
||||||
|
update_locale "$LOCALE"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Verify your language code. Case sensitive."
|
||||||
|
echo "If it's correct, ask a maintainer to add support for your language on FreeCAD."
|
||||||
|
echo -e "\nSupported locales, '\033[1;34mFreeCADGui.supportedLocales()\033[m': \033[1;33m"
|
||||||
|
for locale in $(printf "%s\n" "${supported_locales[@]}" | sort); do
|
||||||
|
echo -n "$locale "
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
help
|
||||||
|
fi
|