-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exit handling, more decimals, context menu style inheritance
- Loading branch information
Showing
7 changed files
with
228 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from PyQt5.QtCore import QEvent, QCoreApplication | ||
from PyQt5.QtWidgets import QMenu | ||
from pyqtgraph.parametertree.ParameterItem import ParameterItem | ||
|
||
translate = QCoreApplication.translate | ||
|
||
|
||
def custom_context_menu_event(ev: QEvent, param_item: ParameterItem): | ||
""" | ||
Re-implemented to provide style inherited from GUI main window | ||
""" | ||
opts = param_item.param.opts | ||
|
||
if not opts.get('removable', False) and not opts.get('renamable', False) \ | ||
and "context" not in opts: | ||
return | ||
|
||
## Generate context menu for renaming/removing parameter | ||
|
||
# Loop to identify the GUI object | ||
max_iter = 12 | ||
iter_count = 0 | ||
current_parent = param_item.param | ||
gui = None | ||
|
||
while True: | ||
if iter_count > max_iter: | ||
break | ||
current_parent = current_parent.parent() | ||
if hasattr(current_parent, "status_bar"): | ||
gui = current_parent.status_bar.parent() | ||
break | ||
|
||
ss = gui.themes[gui.current_theme] | ||
param_item.contextMenu = QMenu(parent=gui) # Put in global name space to prevent garbage collection | ||
param_item.contextMenu.setStyleSheet(f"QMenu::item:selected {{ color: {ss['menu-main-color']}; background-color: {ss['menu-item-selected-color']} }} ") | ||
param_item.contextMenu.addSeparator() | ||
if opts.get('renamable', False): | ||
param_item.contextMenu.addAction(translate("ParameterItem", 'Rename')).triggered.connect(param_item.editName) | ||
if opts.get('removable', False): | ||
param_item.contextMenu.addAction(translate("ParameterItem", "Remove")).triggered.connect(param_item.requestRemove) | ||
|
||
# context menu | ||
context = opts.get('context', None) | ||
if isinstance(context, list): | ||
for name in context: | ||
param_item.contextMenu.addAction(name).triggered.connect( | ||
param_item.contextMenuTriggered(name)) | ||
elif isinstance(context, dict): | ||
for name, title in context.items(): | ||
param_item.contextMenu.addAction(title).triggered.connect( | ||
param_item.contextMenuTriggered(name)) | ||
|
||
param_item.contextMenu.popup(ev.globalPos()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.