From c767c9649457b37d3c495499213d122d76fb5760 Mon Sep 17 00:00:00 2001 From: Pete Peterson <petersonpf@ornl.gov> Date: Thu, 16 Aug 2018 09:13:22 -0400 Subject: [PATCH] Consolidate configuration into less places --- .../workbench/workbench/app/mainwindow.py | 32 +++++++------------ .../workbench/workbench/config/__init__.py | 6 ++-- .../workbench/workbench/config/user.py | 3 +- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/qt/applications/workbench/workbench/app/mainwindow.py b/qt/applications/workbench/workbench/app/mainwindow.py index 7abbebc8a54..6e279d4444b 100644 --- a/qt/applications/workbench/workbench/app/mainwindow.py +++ b/qt/applications/workbench/workbench/app/mainwindow.py @@ -53,8 +53,7 @@ from mantidqt.utils.qt import plugins, widget_updates_disabled # noqa # Pre-application setup plugins.setup_library_paths() -from mantid.kernel import version_str -from workbench.config import APPNAME, CONF, ORG_DOMAIN, ORGANIZATION +from workbench.config import APPNAME, CONF, ORG_DOMAIN, ORGANIZATION # noqa # ----------------------------------------------------------------------------- @@ -71,12 +70,13 @@ def qapplication(): if app is None: QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts) argv = sys.argv[:] - argv[0] = 'Mantid Workbench' # replace application name + argv[0] = APPNAME # replace application name app = QApplication(argv) app.setOrganizationName(ORGANIZATION) app.setOrganizationDomain(ORG_DOMAIN) app.setApplicationName(APPNAME) - app.setApplicationVersion(version_str()) + # not calling app.setApplicationVersion(mantid.kernel.version_str()) + # because it needs to happen after logging is monkey-patched in return app @@ -267,8 +267,6 @@ class MainWindow(QMainWindow): def setup_for_first_run(self): """Assume this is a first run of the application and set layouts accordingly""" - windowstate = None - self.setWindowState(Qt.WindowMaximized) # TODO get from config.CONF desktop = QDesktopWidget() self.setup_default_layouts() @@ -384,23 +382,16 @@ class MainWindow(QMainWindow): self.move(window_pos) # restore window state - windowstate = Qt.WindowNoState - if settings.has('main/window/state'): # preferred - settings.get('main/window/state') - elif settings.get('main/window/is_maximized'): - windowstate = Qt.WindowMaximized - elif settings.get('main/window/is_fullscreen'): - windowstate = Qt.WindowFullScreen - self.setWindowState(windowstate) + if settings.has('main/window/state'): + self.restoreState(settings.get('main/window/state')) + else: + self.setWindowState(Qt.WindowMaximized | Qt.WindowFullScreen) def writeSettings(self, settings): - settings.set('main/window/size', self.size()) - settings.set('main/window/position', self.pos()) + settings.set('main/window/size', self.size()) # QSize + settings.set('main/window/position', self.pos()) # QPoint + settings.set('main/window/state', self.saveState()) # QByteArray - # remove keys that come from the defaults - settings.set('main/window/state', self.saveState()) - settings.remove('main/window/is_maximized') - settings.remove('main/window/is_fullscreen') def initialize(): """Perform an initialization of the application instance. Most notably @@ -483,6 +474,5 @@ def main(): ORIGINAL_SYS_EXIT(exit_value) - if __name__ == '__main__': main() diff --git a/qt/applications/workbench/workbench/config/__init__.py b/qt/applications/workbench/workbench/config/__init__.py index 9937f631cd7..89f8d58fb99 100644 --- a/qt/applications/workbench/workbench/config/__init__.py +++ b/qt/applications/workbench/workbench/config/__init__.py @@ -19,7 +19,7 @@ A singleton instance called CONF is defined. Modules wishing to access the settings should import the CONF object as - from workbench.config.main import CONF + from workbench.config import CONF and use it to access the settings """ @@ -32,7 +32,7 @@ from workbench.config.user import UserConfig # ----------------------------------------------------------------------------- ORGANIZATION = 'mantidproject' ORG_DOMAIN = 'mantidproject.org' -APPNAME = 'workbench' +APPNAME = 'mantidworkbench' # Iterable containing defaults for each configurable section of the code # General application settings are in the main section @@ -41,8 +41,6 @@ DEFAULTS = { 'high_dpi_scaling': True, 'window/size': (1260, 740), 'window/position': (10, 10), - 'window/is_maximized': True, - 'window/is_fullscreen': False, } } diff --git a/qt/applications/workbench/workbench/config/user.py b/qt/applications/workbench/workbench/config/user.py index cfce377d88d..6d60ed6865e 100644 --- a/qt/applications/workbench/workbench/config/user.py +++ b/qt/applications/workbench/workbench/config/user.py @@ -21,6 +21,7 @@ from mantidqt.py3compat import is_text_string from posixpath import join as joinsettings from qtpy.QtCore import QSettings + class UserConfig(object): """Holds user configuration option. Options are assigned a section and a key must only be unique within a section. @@ -130,7 +131,7 @@ class UserConfig(object): result = {} for key in input_dict: value = input_dict[key] - if type(value) == type(dict()): + if isinstance(value, dict): value = UserConfig._flatten_defaults(value) for key_inner in value.keys(): result[joinsettings(key, key_inner)] = value[key_inner] -- GitLab