Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guis not staying in front of main workbench window #23294

Closed
Matthew-Andrew opened this issue Aug 20, 2018 · 7 comments
Closed

Guis not staying in front of main workbench window #23294

Matthew-Andrew opened this issue Aug 20, 2018 · 7 comments
Labels
GUI Issues and pull requests specific to the Mantid Workbench GUI. ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS

Comments

@Matthew-Andrew
Copy link
Contributor

Matthew-Andrew commented Aug 20, 2018

The new ISIS SANS GUI is not currently staying in front of the Mantidplot window. This is due to a difference in behavior between python and C++ interfaces.

Having investigated the following seems to be the case:

  • On windows the C++ interfaces are set as children of the main window and then have their parent removed and reset when the window is minimized or maximized. This is taking advantage of the fact that on windows child widgets always stay in front of their parents. This is the behavior most of the scientists are used to. An example of how it is achieved can be found here https://github.com/mantidproject/mantid/blob/master/MantidPlot/src/FloatingWindow.cpp#L85.
  • On Ubuntu child widgets do not stay on top of their parents. So interfaces always drop behind the main Mantidplot window. This is currently worked around by having interfaces docked by default. You cannot currently dock python interfaces however and making it so you can may be difficult.
  • I think getting the expected behaviour on windows is most important here as not many users are on Ubuntu and there is a workaround to pin a window to the front.
@TTitcombe
Copy link
Contributor

TTitcombe commented Jun 20, 2019

This is behaviour is wanted by several interfaces on Mantid, so any solution should be discussed with the wider Mantid team. It is also necessary for the solution to provide the same behaviour on all platforms Mantid supports.

I have found a solution which keeps the SANS gui on top of mantid, but removes its minimise/maximise buttons. In ISIS_SANS.py
Add the following imports

from qtpy.QtCore import Qt

from mantid.gui_helper import get_application

We then get the MantidPlot/Workbench object:

mainapp, _ = get_qapplication()
mainwindow = main.appactiveWindow()

We set the workbench/mantidplot object as the parent of the SANS gui, and give it the flag "Tool"

ui = sans_data_processor_gui.SANSDataProcessorGui(mainwindow)
flags = ui.windowFlags() | Qt.Tool
ui.setWindowFlags(flags)

This requires SANSDataProcessorGui to be changed in the following way:

def __init__(self, parent=None):
    super(QMainWindow, self).__init__(parent=parent)

Adding flags such as WindowMinimizeButtonHint does not provide the buttons we need. It should be confirmed whether this solution works on other operating systems, as I can find no reference online to Qt::Tool taking away minimise/maximise functionality

@TTitcombe
Copy link
Contributor

TTitcombe commented Jun 24, 2019

Some sources state this as a difficult problem to solve for Mac, at least (fredrikaverpil/pyvfx-boilerplate#12). The pertinent bit is :

This is really difficult to solve unfortunately. The Qt documentation for QWidget says that parenting a window to another will make it float above the other window, but the documentation is wrong and the behaviour is dependent on the window management policy for your platform. Having a floating window which doesn't get hidden when the application goes to the background is deemed un-Mac-like behaviour and not allowed. The only ways to get windows to float are to use Qt.Tool or Qt.WindowStaysOnTopHint which both have problems. In particular, Qt.WindowStaysOnTopHint makes the window stay on top of all windows even when the application is in the background. Nuke gets round this problem by manipulating the Qt.WindowStaysOnTopHint during application activation and deactivation, but to do this correctly requires writing Objective-C code and can't be done from Python (the equivalent Qt events don't get delivered at the correct time for this).

@TTitcombe TTitcombe added the GUI Issues and pull requests specific to the Mantid Workbench GUI. label Jun 24, 2019
@TTitcombe TTitcombe modified the milestones: Release 4.1, Release 4.2 Jun 24, 2019
@TTitcombe TTitcombe changed the title SANS GUI not staying in front of main mantidplot window Guis not staying in front of main workbench window Jun 27, 2019
@TTitcombe
Copy link
Contributor

Moved from a SANS issue to workbench as behaviour wanted by several groups

@gemmaguest gemmaguest added the ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS label Jul 24, 2019
@dtasev
Copy link
Contributor

dtasev commented Jul 29, 2019

Note that the Ubuntu pinning is not by default part of the GNOME 3 GUI for 18.04/19.04

@NickDraper
Copy link
Contributor

@hsautessella Can you drop Matthew some hints about what you did for the plot windows

@ghost
Copy link

ghost commented Oct 24, 2019

The best I could do on Linux for the plot windows was look out for QApplication.focusWindowChanged events, checking if the focus has been switched to the main window (which has a specific objectName), and raising the plot window if so. See #27049 for the code.

As stated in the PR, this is not perfect behaviour as the window is hidden briefly and then brought forward. This causes a slight flicker effect. But, as hinted by Tom above, this doesn't seem to be a problem with a perfect solution.

That said, if the window doesn't need a minimize/maximize button, then passing it the Qt.Tool flag will keep it on top.

@NickDraper NickDraper modified the milestones: Release 4.2, Release 4.3 Oct 25, 2019
@NickDraper NickDraper removed this from the Release 5.0 milestone Feb 21, 2020
@Matthew-Andrew Matthew-Andrew removed their assignment Sep 1, 2020
@Matthew-Andrew
Copy link
Contributor Author

@gemmaguest I am closing this for now as this is a long running issue with most interfaces on workbench.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI Issues and pull requests specific to the Mantid Workbench GUI. ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS
Projects
None yet
Development

No branches or pull requests

5 participants