Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Orange/canvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,13 @@ def setup_actions(self):
QAction(self.tr("Reset Widget Settings..."), self,
triggered=self.reset_widget_settings)

self.float_widgets_on_top_action = \
QAction(self.tr("Float Widgets on Top"), self,
checkable=True,
toolTip=self.tr("Widgets are always displayed above other windows."))
self.float_widgets_on_top_action.toggled.connect(
self.set_float_widgets_on_top_enabled)

def setup_menu(self):
if sys.platform == "darwin" and QT_VERSION >= 0x50000:
self.__menu_glob = QMenuBar(None)
Expand Down Expand Up @@ -694,6 +701,7 @@ def setup_menu(self):
self.view_menu.addSeparator()

self.view_menu.addAction(self.toogle_margins_action)
self.view_menu.addAction(self.float_widgets_on_top_action)
menu_bar.addMenu(self.view_menu)

# Options menu
Expand Down Expand Up @@ -760,6 +768,10 @@ def restore(self):
settings.value("quick-help/visible", True, type=bool)
)

self.float_widgets_on_top_action.setChecked(
settings.value("widgets-float-on-top", False, type=bool)
)

self.__update_from_settings()

def set_document_title(self, title):
Expand Down Expand Up @@ -1655,6 +1667,14 @@ def reset_widget_settings(self):
"Settings will still be reset at next application start",
parent=self)

def set_float_widgets_on_top_enabled(self, enabled):
wm = self.current_document().scheme().widget_manager

settings = QSettings()
settings.setValue("mainwindow/widgets-float-on-top", bool(enabled))
wm.show_widgets_on_top_changed()


def show_report_view(self):
from Orange.canvas.report.owreport import OWReport
doc = self.current_document()
Expand Down
3 changes: 3 additions & 0 deletions Orange/canvas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def init():
"Use a popover menu to select a widget when clicking on a category "
"button"),

("mainwindow/widgets-float-on-top", bool, False,
"Float widgets on top of other windows"),

("mainwindow/number-of-recent-schemes", int, 15,
"Number of recent workflows to keep in history"),

Expand Down
44 changes: 42 additions & 2 deletions Orange/canvas/scheme/widgetsscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

import sip

from AnyQt.QtWidgets import QWidget, QShortcut, QLabel, QSizePolicy, QAction
from AnyQt.QtWidgets import QWidget, QShortcut, QLabel, QSizePolicy, QAction, qApp
from AnyQt.QtGui import QKeySequence, QWhatsThisClickedEvent

from AnyQt.QtCore import Qt, QObject, QCoreApplication, QTimer, QEvent
from AnyQt.QtCore import Qt, QObject, QCoreApplication, QTimer, QEvent, QSettings
from AnyQt.QtCore import pyqtSignal as Signal

from .signalmanager import SignalManager, compress_signals, can_enable_dynamic
Expand Down Expand Up @@ -258,6 +258,11 @@ def __init__(self, parent=None):
# Tracks the widget in the update loop by the SignalManager
self.__updating_widget = None

if hasattr(qApp, "applicationStateChanged"):
# disables/enables widget floating when app (de)activates
# available in Qt >= 5.2
qApp.applicationStateChanged.connect(self.show_widgets_on_top_changed)

def set_scheme(self, scheme):
"""
Set the :class:`WidgetsScheme` instance to manage.
Expand Down Expand Up @@ -597,6 +602,9 @@ def create_widget_instance(self, node):
widget.setCaption(node.title)
# befriend class Report
widget._Report__report_view = self.scheme().report_view

self.__set_float_on_top(widget)

# Schedule an update with the signal manager, due to the cleared
# implicit Initializing flag
self.signal_manager()._update()
Expand Down Expand Up @@ -627,6 +635,15 @@ def widget_processing_state(self, widget):
"""
return self.__widget_processing_state[widget]

def show_widgets_on_top_changed(self):
"""
`Float Widgets on Top` menu option has changed.

Update the flag on existing widgets.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to a setter (def set_show_widgets_on_top(self, state):) record the state in an instance attribute, and use that instead of querying QSettings in __set_float_on_top, so the state is local to the workflow and not shared between them.

for widget in self.__widget_for_node.values():
self.__set_float_on_top(widget)

def __create_delayed(self):
if self.__init_queue:
state = self.__init_queue.popleft()
Expand Down Expand Up @@ -790,6 +807,29 @@ def __on_env_changed(self, key, newvalue, oldvalue):
for widget in self.__widget_for_node.values():
widget.workflowEnvChanged(key, newvalue, oldvalue)

def __set_float_on_top(self, widget):
"""Set or unset widget's float on top flag"""
settings = QSettings()
should_float_on_top = settings.value("mainwindow/widgets-float-on-top", False, type=bool)
if hasattr(qApp, "applicationState"):
# only float on top when the application is active
# available in Qt >= 5.2
should_float_on_top &= qApp.applicationState() == Qt.ApplicationActive
float_on_top = widget.windowFlags() & Qt.WindowStaysOnTopHint

if float_on_top == should_float_on_top:
return

widget_was_visible = widget.isVisible()
if should_float_on_top:
widget.setWindowFlags(Qt.WindowStaysOnTopHint)
else:
widget.setWindowFlags(widget.windowFlags() & ~Qt.WindowStaysOnTopHint)

# Changing window flags hid the widget
if widget_was_visible:
widget.show()


def user_message_from_state(message_group):
return UserMessage(
Expand Down