Skip to content

Commit

Permalink
canvas: Float Widgets on Top option
Browse files Browse the repository at this point in the history
  • Loading branch information
astaric committed May 21, 2018
1 parent a8ea66b commit fd08364
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
21 changes: 21 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,15 @@ 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):
from Orange.canvas.scheme.widgetsscheme import WidgetManager
wm = self.current_document().scheme().widget_manager # type: WidgetManager

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
33 changes: 32 additions & 1 deletion Orange/canvas/scheme/widgetsscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from AnyQt.QtWidgets import QWidget, QShortcut, QLabel, QSizePolicy, QAction
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 @@ -597,6 +597,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 +630,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.
"""
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 +802,25 @@ 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)
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

0 comments on commit fd08364

Please sign in to comment.