Skip to content

Commit

Permalink
Merge pull request #23778 from mantidproject/modernize_event_filter_gui
Browse files Browse the repository at this point in the history
Modernize event filter gui
  • Loading branch information
martyngigg committed Oct 16, 2018
2 parents 77d46e2 + 5e0262e commit 66a3df7
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 594 deletions.
16 changes: 16 additions & 0 deletions MantidPlot/mantidplot.py
Expand Up @@ -13,8 +13,24 @@
from __future__ import (absolute_import, division,
print_function)

import os.path as osp
import pymantidplot
from pymantidplot import *

# and the old qtiplot stuff
import pymantidplot.qtiplot

def load_ui(caller_filename, ui_relfilename, baseinstance=None):
'''This is copied from mantidqt.utils.qt and should be deprecated as
soon as possible.'''
from qtpy.uic import loadUi, loadUiType # noqa

filepath = osp.join(osp.dirname(caller_filename), ui_relfilename)
if not osp.exists(filepath):
raise ImportError('File "{}" does not exist'.format(filepath))
if not osp.isfile(filepath):
raise ImportError('File "{}" is not a file'.format(filepath))
if baseinstance is not None:
return loadUi(filepath, baseinstance=baseinstance)
else:
return loadUiType(filepath)
25 changes: 13 additions & 12 deletions qt/applications/workbench/workbench/app/mainwindow.py
Expand Up @@ -250,13 +250,8 @@ def populate_menus(self):
add_actions(self.file_menu, self.file_menu_actions)
add_actions(self.view_menu, self.view_menu_actions)

def launchCustomGUI(self, name):
try:
importlib.import_module(name)
except ImportError:
from mantid.kernel import logger
logger.error(str('Failed to load {} interface'.format(name))) # TODO logger should accept unicode
raise
def launchCustomGUI(self, script):
exec(open(script).read())

def populateAfterMantidImport(self):
from mantid.kernel import ConfigService, logger
Expand All @@ -266,16 +261,18 @@ def populateAfterMantidImport(self):

# list of custom interfaces that have been made qt4/qt5 compatible
# TODO need to make *anything* compatible
GUI_WHITELIST = []
GUI_WHITELIST = ['FilterEvents.py']

# detect the python interfaces
interfaces = {}
for item in items:
key,scriptname = item.split('/')
key, scriptname = item.split('/')
# TODO logger should accept unicode
if not os.path.exists(os.path.join(interface_dir, scriptname)):
logger.warning('Failed to find script "{}" in "{}"'.format(scriptname, interface_dir))
logger.warning(str('Failed to find script "{}" in "{}"'.format(scriptname, interface_dir)))
continue
if scriptname not in GUI_WHITELIST:
logger.information(str('Not adding gui "{}"'.format(scriptname)))
continue
temp = interfaces.get(key, [])
temp.append(scriptname)
Expand All @@ -290,8 +287,8 @@ def populateAfterMantidImport(self):
names.sort()
for name in names:
action = submenu.addAction(name.replace('.py', '').replace('_', ' '))
script = name.replace('.py', '')
action.triggered.connect(lambda checked, script=script:self.launchCustomGUI(script))
script = os.path.join(interface_dir, name)
action.triggered.connect(lambda checked, script=script: self.launchCustomGUI(script))

def add_dockwidget(self, plugin):
"""Create a dockwidget around a plugin and add the dock to window"""
Expand Down Expand Up @@ -380,6 +377,10 @@ def closeEvent(self, event):
import matplotlib.pyplot as plt # noqa
plt.close('all')

app = QApplication.instance()
if app is not None:
app.closeAllWindows()

event.accept()
else:
# Cancel was pressed when closing an editor
Expand Down
4 changes: 4 additions & 0 deletions qt/python/mantidqt/utils/qt/__init__.py
Expand Up @@ -77,6 +77,10 @@ def load_ui(caller_filename, ui_relfilename, baseinstance=None):
return the form class
"""
filepath = osp.join(osp.dirname(caller_filename), ui_relfilename)
if not osp.exists(filepath):
raise ImportError('File "{}" does not exist'.format(filepath))
if not osp.isfile(filepath):
raise ImportError('File "{}" is not a file'.format(filepath))
if baseinstance is not None:
return loadUi(filepath, baseinstance=baseinstance)
else:
Expand Down
4 changes: 1 addition & 3 deletions scripts/CMakeLists.txt
@@ -1,14 +1,13 @@

# Subdirectories from which ui files need processing to py files
add_subdirectory(FilterEvents)
# FilterEvents doesn't need any special work
add_subdirectory(Interface/ui)
add_subdirectory(TofConverter)
add_subdirectory(HFIR_4Circle_Reduction)
add_subdirectory(ErrorReporter)

# Chain all required interface custom targets into CompilePyUI
add_custom_target(CompilePyUI DEPENDS
CompileUIFilterEvents
CompileUITofConverter
CompileUIUI
CompileUIHFIR_4Circle_Reduction
Expand All @@ -17,7 +16,6 @@ add_custom_target(CompilePyUI DEPENDS

# Put them into the 'CompileUI' folder or group in VS and the like, for convenience
set_property ( TARGET CompilePyUI PROPERTY FOLDER "CompilePyUI" )
set_property ( TARGET CompileUIFilterEvents PROPERTY FOLDER "CompilePyUI" )
set_property ( TARGET CompileUITofConverter PROPERTY FOLDER "CompilePyUI" )
set_property ( TARGET CompileUIUI PROPERTY FOLDER "CompilePyUI" )
set_property ( TARGET CompileUIHFIR_4Circle_Reduction PROPERTY FOLDER "CompilePyUI" )
Expand Down
21 changes: 7 additions & 14 deletions scripts/FilterEvents.py
Expand Up @@ -4,23 +4,16 @@
# NScD Oak Ridge National Laboratory, European Spallation Source
# & Institut Laue - Langevin
# SPDX - License - Identifier: GPL - 3.0 +
#pylint: disable=invalid-name
# pylint: disable=invalid-name
from __future__ import (absolute_import, division, print_function)
from FilterEvents import eventFilterGUI
from PyQt4 import QtGui
import sys
from gui_helper import set_matplotlib_backend, get_qapplication
set_matplotlib_backend() # must be called before anything tries to use matplotlib
from FilterEvents import eventFilterGUI # noqa


def qapp():
if QtGui.QApplication.instance():
_app = QtGui.QApplication.instance()
else:
_app = QtGui.QApplication(sys.argv)
return _app


app = qapp()
app, within_mantid = get_qapplication()

reducer = eventFilterGUI.MainWindow() #the main ui class in this file is called MainWindow
reducer.show()
app.exec_()
if not within_mantid:
sys.exit(app.exec_())
11 changes: 0 additions & 11 deletions scripts/FilterEvents/CMakeLists.txt

This file was deleted.

230 changes: 0 additions & 230 deletions scripts/FilterEvents/ErrorMessage.ui

This file was deleted.

0 comments on commit 66a3df7

Please sign in to comment.