3131from psyplot_gui .compat .qtcompat import (
3232 QMainWindow , QApplication , Qt , QMenu , QAction , QDesktopWidget , QLabel ,
3333 QFileDialog , QKeySequence , QtCore , with_qt5 , QMessageBox , QIcon ,
34- QInputDialog )
34+ QInputDialog , QActionGroup )
3535from psyplot_gui .content_widget import (
3636 ProjectContentWidget , DatasetTree , FiguresTree )
3737from psyplot_gui .plot_creator import PlotCreator
@@ -108,6 +108,10 @@ class MainWindow(QMainWindow):
108108 #: The current keyboard shortcuts
109109 current_shortcuts = []
110110
111+ #: The key for the central widget for the main window in the
112+ #: :attr:`plugins` dictionary
113+ central_widget_key = 'console'
114+
111115 @property
112116 def logger (self ):
113117 """The logger of this instance"""
@@ -368,6 +372,7 @@ def __init__(self, show=True):
368372
369373 # load plugin widgets
370374 self .plugins = plugins = OrderedDict ([
375+ ('console' , self .console ),
371376 ('project_content' , self .project_content ),
372377 ('ds_tree' , self .ds_tree ),
373378 ('figures_tree' , self .figures_tree ),
@@ -381,11 +386,13 @@ def __init__(self, show=True):
381386 self .add_mp_to_menu ()
382387 psy .Project .oncpchange .connect (self .eventually_add_mp_to_menu )
383388 self .windows_menu .addSeparator ()
389+
384390 self .window_layouts_menu = QMenu ('Window layouts' , self )
385391 self .restore_layout_action = QAction ('Restore default layout' , self )
386392 self .restore_layout_action .triggered .connect (self .setup_default_layout )
387393 self .window_layouts_menu .addAction (self .restore_layout_action )
388394 self .windows_menu .addMenu (self .window_layouts_menu )
395+
389396 self .panes_menu = QMenu ('Panes' , self )
390397 self .windows_menu .addMenu (self .panes_menu )
391398
@@ -396,6 +403,11 @@ def __init__(self, show=True):
396403 self .dataframe_menu .addSeparator ()
397404 self .windows_menu .addMenu (self .dataframe_menu )
398405
406+ self .central_widgets_menu = menu = QMenu ('Central widget' , self )
407+ self .windows_menu .addMenu (menu )
408+ self .central_widgets_actions = group = QActionGroup (self )
409+ group .setExclusive (True )
410+
399411 # ---------------------------------------------------------------------
400412 # -------------------------- connections ------------------------------
401413 # ---------------------------------------------------------------------
@@ -461,15 +473,19 @@ def __init__(self, show=True):
461473
462474 # save the default widths after they have been shown
463475 for w in self .plugins .values ():
464- self .default_widths [w ] = w .dock .size ().width ()
476+ if w .dock is not None :
477+ self .default_widths [w ] = w .dock .size ().width ()
465478
466479 # hide plugin widgets that should be hidden at startup. Although this
467480 # has been executed by :meth:`setup_default_layout`, we have to execute
468481 # it again after the call of showMaximized
469- for w in self .plugins .values ():
470- w .to_dock (self )
471- if w .hidden :
472- w .hide_plugin ()
482+ for name , w in self .plugins .items ():
483+ if name != self .central_widget_key :
484+ w .to_dock (self )
485+ if w .hidden :
486+ w .hide_plugin ()
487+ else :
488+ w .create_central_widget_action (self ).setChecked (True )
473489
474490 self ._is_open = True
475491
@@ -514,17 +530,19 @@ def setup_default_layout(self):
514530
515531 modify_widths = bool (self .default_widths )
516532 for w in map (self .plugins .__getitem__ , self .default_plugins ):
517- w .show_plugin ()
533+ if w .dock is not None :
534+ w .show_plugin ()
518535
519- if modify_widths and with_qt5 :
520- self .resizeDocks ([w .dock ], [self .default_widths [w ]],
521- Qt .Horizontal )
536+ if modify_widths and with_qt5 :
537+ self .resizeDocks ([w .dock ], [self .default_widths [w ]],
538+ Qt .Horizontal )
522539
523540 # hide plugin widgets that should be hidden at startup
524- for w in self .plugins .values ():
525- w .to_dock (self )
526- if w .hidden :
527- w .hide_plugin ()
541+ for name , w in self .plugins .items ():
542+ if name != self .central_widget_key :
543+ w .to_dock (self )
544+ if w .hidden :
545+ w .hide_plugin ()
528546
529547 action2shortcut = defaultdict (list )
530548 for s , a in self .default_shortcuts :
@@ -533,6 +551,34 @@ def setup_default_layout(self):
533551 for a , s in action2shortcut .items ():
534552 self .register_shortcut (a , s )
535553
554+ def set_central_widget (self , name ):
555+ """Set the central widget
556+
557+ Parameters
558+ ----------
559+ name: str or QWidget
560+ The key or the plugin widget in the :attr:`plugins` dictionary"""
561+ current = self .centralWidget ()
562+ if isinstance (name , six .string_types ):
563+ new = self .plugins [name ]
564+ else :
565+ new = name
566+ name = next (key for key , val in self .plugins .items () if val is new )
567+ if new is not current :
568+ self .removeDockWidget (new .dock )
569+ new .dock .close ()
570+ self .panes_menu .removeAction (new ._view_action )
571+ self .dataframe_menu .removeAction (new ._view_action )
572+ new .dock = new ._view_action = None
573+ self .central_widget_key = name
574+ current .to_dock (self )
575+ self .setCentralWidget (new )
576+ new ._set_central_action .setChecked (True )
577+ current .show_plugin ()
578+ current .to_dock (self )
579+ if current .hidden :
580+ current .hide_plugin ()
581+
536582 def _save_project (self , p , new_fname = False , * args , ** kwargs ):
537583 if new_fname or 'project_file' not in p .attrs :
538584 fname = QFileDialog .getSaveFileName (
@@ -734,16 +780,6 @@ def eventually_add_mp_to_menu(self, p):
734780 if p .num not in self .project_actions :
735781 self .add_mp_to_menu ()
736782
737- def addDockWidget (self , area , dockwidget , docktype = None , * args , ** kwargs ):
738- """Reimplemented to add widgets to the windows menu"""
739- ret = super (MainWindow , self ).addDockWidget (area , dockwidget , * args ,
740- ** kwargs )
741- if docktype == 'pane' :
742- self .panes_menu .addAction (dockwidget .toggleViewAction ())
743- elif docktype == 'df' :
744- self .dataframe_menu .addAction (dockwidget .toggleViewAction ())
745- return ret
746-
747783 def start_open_files_server (self ):
748784 """This method listens to the open_files_port and opens the plot
749785 creator for new files
0 commit comments