Skip to content

Commit d01dd4d

Browse files
committed
OWWidget: Define the 'Help' action in the OWWidget
1 parent 509479e commit d01dd4d

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

Orange/canvas/scheme/widgetsscheme.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import sip
2727

28-
from AnyQt.QtWidgets import QWidget, QShortcut, QLabel, QSizePolicy
28+
from AnyQt.QtWidgets import QWidget, QShortcut, QLabel, QSizePolicy, QAction
2929
from AnyQt.QtGui import QKeySequence, QWhatsThisClickedEvent
3030

3131
from AnyQt.QtCore import Qt, QObject, QCoreApplication, QTimer, QEvent
@@ -514,8 +514,11 @@ def create_widget_instance(self, node):
514514
node.set_progress(widget.progressBarValue)
515515

516516
# Install a help shortcut on the widget
517-
help_shortcut = QShortcut(QKeySequence("F1"), widget)
518-
help_shortcut.activated.connect(self.__on_help_request)
517+
help_action = widget.findChild(QAction, "action-help")
518+
if help_action is not None:
519+
help_action.setEnabled(True)
520+
help_action.setVisible(True)
521+
help_action.triggered.connect(self.__on_help_request)
519522

520523
# Up shortcut (activate/open parent)
521524
up_shortcut = QShortcut(

Orange/widgets/widget.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from AnyQt.QtWidgets import (
99
QWidget, QDialog, QVBoxLayout, QSizePolicy, QApplication, QStyle,
1010
QShortcut, QSplitter, QSplitterHandle, QPushButton, QStatusBar,
11-
QProgressBar
11+
QProgressBar, QAction
1212
)
1313
from AnyQt.QtCore import (
1414
Qt, QByteArray, QSettings, QUrl, pyqtSignal as Signal
@@ -170,6 +170,7 @@ class OWWidget(QDialog, OWComponent, Report, ProgressBarMixin,
170170
contextOpened = Signal()
171171
contextClosed = Signal()
172172

173+
# pylint: disable=protected-access
173174
def __new__(cls, *args, captionTitle=None, **kwargs):
174175
self = super().__new__(cls, None, cls.get_flags())
175176
QDialog.__init__(self, None, self.get_flags())
@@ -208,6 +209,12 @@ def __new__(cls, *args, captionTitle=None, **kwargs):
208209
self.__msgwidget = None
209210
self.__msgchoice = 0
210211

212+
self.__help_action = QAction(
213+
"Help", self, objectName="action-help", toolTip="Show help",
214+
enabled=False, visible=False, shortcut=QKeySequence(Qt.Key_F1)
215+
)
216+
self.addAction(self.__help_action)
217+
211218
self.left_side = None
212219
self.controlArea = self.mainArea = self.buttonsArea = None
213220
self.splitter = None
@@ -219,6 +226,7 @@ def __new__(cls, *args, captionTitle=None, **kwargs):
219226

220227
sc = QShortcut(QKeySequence.Copy, self)
221228
sc.activated.connect(self.copy_to_clipboard)
229+
222230
if self.controlArea is not None:
223231
# Otherwise, the first control has focus
224232
self.controlArea.setFocus(Qt.ActiveWindowFocusReason)
@@ -347,11 +355,20 @@ def set_basic_layout(self):
347355
sb.setSizeGripEnabled(self.resizing_enabled)
348356
c.layout().addWidget(sb)
349357

350-
b = SimpleButton(
358+
help = self.__help_action
359+
help_button = SimpleButton(
351360
icon=QIcon(gui.resource_filename("icons/help.svg")),
352-
toolTip="Show widget help",
361+
toolTip="Show widget help", visible=help.isVisible(),
353362
)
354-
sb.addWidget(b)
363+
@help.changed.connect
364+
def _():
365+
help_button.setVisible(help.isVisible())
366+
help_button.setEnabled(help.isEnabled())
367+
if not help.icon().isNull():
368+
help_button.setIcon(help.icon())
369+
help_button.clicked.connect(help.trigger)
370+
sb.addWidget(help_button)
371+
355372
if self.graph_name is not None:
356373
b = SimpleButton(
357374
icon=QIcon(gui.resource_filename("icons/chart.svg")),

0 commit comments

Comments
 (0)