From 0a30e5c30b334c47f022e0fa54a197be4172eaf5 Mon Sep 17 00:00:00 2001 From: Gama Anderson Date: Sun, 8 May 2016 20:20:07 +0200 Subject: [PATCH 1/2] add separator de mode menu --- artview/components/menu.py | 10 ++++++++++ artview/modes.py | 20 ++++++++++++++++---- artview/plugins/cmap.py | 2 ++ artview/scripts/_common.py | 34 ++++++++++++++++++++-------------- artview/scripts/standard.py | 19 +++++++------------ artview/view.py | 4 ++-- 6 files changed, 57 insertions(+), 32 deletions(-) diff --git a/artview/components/menu.py b/artview/components/menu.py index d1d63fc..7588ddd 100644 --- a/artview/components/menu.py +++ b/artview/components/menu.py @@ -240,6 +240,16 @@ def addMenuAction(self, position, *args): menus = {} return menu.addAction(*args) + def addMenuSeparator(self, position, *args): + menu, menus = self.menus() + for key in position: + if key in menus: + menu, menus = menus[key] + else: + menu = menu.addMenu(key) + menus = {} + return menu.addSeparator(*args) + def CreateMenu(self): '''Create the main menubar.''' self.menubar = self.menuBar() diff --git a/artview/modes.py b/artview/modes.py index a557fe5..77d4394 100644 --- a/artview/modes.py +++ b/artview/modes.py @@ -175,27 +175,39 @@ modes = [ {'label': 'Add RadarDisplay', + 'group': 'graph', 'action': radar_mode}, {'label': 'Add GridDisplay', + 'group': 'graph', 'action': grid_mode}, {'label': 'Map Radar to Grid', + 'group': 'map', 'action': map_to_grid_mode}, {'label': 'Apply corrections to Radar', + 'group': 'correct', 'action': corrections_mode}, {'label': 'Apply a filter to gates', + 'group': 'correct', 'action': gatefilter_mode}, + {'label': 'Apply a filter to data', + 'group': 'correct', + 'action': manual_filter_mode}, + {'label': 'Manually unfold velocity', + 'group': 'correct', + 'action': manual_unfold_mode}, {'label': 'Query a selectable region of interest ', + 'group': 'select', 'action': select_region_mode}, {'label': 'Extract a selected region of points', + 'group': 'select', 'action': extract_points_mode}, - {'label': 'Manually unfold velocity', - 'action': manual_unfold_mode}, - {'label': 'Apply a filter to data', - 'action': manual_filter_mode}, {'label': 'File navigator', + 'group': 'io', 'action': navigate_mode}, {'label': 'File details', + 'group': 'io', 'action': filedetail_mode}, {'label': 'Directory View', + 'group': 'io', 'action': filelist_mode}, ] diff --git a/artview/plugins/cmap.py b/artview/plugins/cmap.py index ff2bf9a..3e8f698 100644 --- a/artview/plugins/cmap.py +++ b/artview/plugins/cmap.py @@ -301,8 +301,10 @@ def NewColormap(self, variable, strong): _modes = [ {'label': 'Edit Colormap (radar)', + 'group': 'graph', 'action': radar_mode}, {'label': 'Edit Colormap (grid)', + 'group': 'graph', 'action': grid_mode}, ] diff --git a/artview/scripts/_common.py b/artview/scripts/_common.py index 9334cab..56f10ce 100644 --- a/artview/scripts/_common.py +++ b/artview/scripts/_common.py @@ -71,21 +71,27 @@ def startMainMenu(DirIn=None, filename=None): MainMenu = Menu(DirIn, filename, mode=("Radar", "Grid")) - try: + if True: + #try: from ..modes import modes - for mode in modes: - action = QtGui.QAction(mode['label'], MainMenu) - action.triggered[()].connect( - lambda mode=mode: MainMenu.change_mode(mode['action'])) - if (mode['label'] != 'Directory View' and - mode['label'] != 'File details' and - mode['label'] != 'File navigator'): - MainMenu.addMenuAction(("Modes",), action) - else: - MainMenu.addMenuAction(("File",), action) - except: - import warnings - warnings.warn("Loading Modes Fail") + group_names = [m['group'] for m in modes] + seen = set() + group_names = [x for x in group_names if x not in seen and not seen.add(x)] + groups = [[m for m in modes if m['group']==name] for name in group_names] + for group in groups: + for mode in group: + action = QtGui.QAction(mode['label'], MainMenu) + action.triggered[()].connect( + lambda mode=mode: MainMenu.change_mode(mode['action'])) + if mode['group'] != 'io': + MainMenu.addMenuAction(("Modes",), action) + else: + MainMenu.addMenuAction(("File",), action) + MainMenu.addMenuSeparator(("Modes",)) + +# except: +# import warnings +# warnings.warn("Loading Modes Fail") _add_all_advanced_tools(MainMenu) diff --git a/artview/scripts/standard.py b/artview/scripts/standard.py index 4b76fd6..0e5e95d 100644 --- a/artview/scripts/standard.py +++ b/artview/scripts/standard.py @@ -31,13 +31,8 @@ def run(DirIn=None, filename=None, field=None): from ._common import startMainMenu from .. import view - app = QtGui.QApplication(sys.argv) - if view.checkifmac(): - app.setAttribute(QtCore.Qt.AA_MacPluginApplication, True) - - # start Menu and initiate Vradar - MainMenu = startMainMenu(DirIn, filename) - Vradar = MainMenu.Vradar + view.start(DirIn, filename) + Vradar = view.MainMenu.Vradar # handle input if field is None: @@ -50,9 +45,9 @@ def run(DirIn=None, filename=None, field=None): # start Displays Vtilt = Variable(0) plot1 = RadarDisplay(Vradar, Variable(field), Vtilt, name="Display1", - parent=MainMenu) + parent=view.MainMenu) plot2 = RadarDisplay(Vradar, Variable(field), Vtilt, name="Display2", - parent=MainMenu) + parent=view.MainMenu) # start ComponentsControl control = LinkSharedVariables() @@ -60,7 +55,7 @@ def run(DirIn=None, filename=None, field=None): control.setComponent1(plot2.name) # add control to Menu - MainMenu.addLayoutWidget(control) + view.MainMenu.addLayoutWidget(control) # Replace in Screen desktop_rect = QtGui.QDesktopWidget().screenGeometry() @@ -71,13 +66,13 @@ def run(DirIn=None, filename=None, field=None): menu_width = 500 menu_height = 180 - MainMenu.setGeometry(0, 0, menu_width, menu_height) + view.MainMenu.setGeometry(0, 0, menu_width, menu_height) plot_size = min(height-60-menu_height, width/2) - 50 plot1.setGeometry(0, height-plot_size, plot_size, plot_size) plot2.setGeometry(width/2, height-plot_size, plot_size, plot_size) # start program - app.exec_() + view.execute() print("You used ARTView. What you think and what you need of ARTView? " "Send your comment to artview-users@googlegroups.com") diff --git a/artview/view.py b/artview/view.py index 16097a7..4264ed3 100644 --- a/artview/view.py +++ b/artview/view.py @@ -62,7 +62,7 @@ def view(containers, field=reflectivity): execute() -def start(): +def start(DirIn=os.getcwd(), filename=False): ''' Start Qt Application and :py:class:`~artview.components.Menu` ''' global app if app is None: @@ -71,7 +71,7 @@ def start(): app.setAttribute(QtCore.Qt.AA_MacPluginApplication, True) global MainMenu - MainMenu = startMainMenu(os.getcwd(), False) + MainMenu = startMainMenu(DirIn, filename) # resize menu menu_width = 300 From 7fdbd23c3495f21a347c7d6ffe53ce98ef3abc4d Mon Sep 17 00:00:00 2001 From: Gama Anderson Date: Sun, 8 May 2016 20:25:10 +0200 Subject: [PATCH 2/2] amend to previus commit --- artview/scripts/_common.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/artview/scripts/_common.py b/artview/scripts/_common.py index 56f10ce..b93d046 100644 --- a/artview/scripts/_common.py +++ b/artview/scripts/_common.py @@ -71,8 +71,7 @@ def startMainMenu(DirIn=None, filename=None): MainMenu = Menu(DirIn, filename, mode=("Radar", "Grid")) - if True: - #try: + try: from ..modes import modes group_names = [m['group'] for m in modes] seen = set() @@ -88,10 +87,9 @@ def startMainMenu(DirIn=None, filename=None): else: MainMenu.addMenuAction(("File",), action) MainMenu.addMenuSeparator(("Modes",)) - -# except: -# import warnings -# warnings.warn("Loading Modes Fail") + except: + import warnings + warnings.warn("Loading Modes Fail") _add_all_advanced_tools(MainMenu)