4343from mapclient .tools .pmr .settings .general import PMR
4444from mapclient .settings .general import get_virtualenv_directory , is_workflow
4545from mapclient .core .workflow .workflowerror import WorkflowError
46- from mapclient .settings .definitions import SHOW_STEP_NAMES , CLOSE_AFTER , USE_EXTERNAL_GIT , PREVIOUS_WORKFLOW ,\
47- RECENTS_ABSOLUTE_PATHS , RECENTS_LENGTH
46+ from mapclient .settings .definitions import SHOW_STEP_NAMES , CLOSE_AFTER , USE_EXTERNAL_GIT , PREVIOUS_WORKFLOW , \
47+ RECENTS_ABSOLUTE_PATHS , RECENTS_LENGTH , ANIMATE_LAYOUT_UPDATES
4848
4949from mapclient .core .workflow .workflowitems import MetaStep
5050from mapclient .view .workflow .importconfigdialog import ImportConfigDialog
@@ -65,6 +65,8 @@ def __init__(self, main_window):
6565 self ._undoStack = QtGui .QUndoStack (self )
6666
6767 self ._workflowManager = self ._main_window .model ().workflowManager ()
68+ self ._options_manager = self ._main_window .model ().optionsManager ()
69+
6870 self ._graphicsScene = WorkflowGraphicsScene (self )
6971
7072 self ._ui .graphicsView .setScene (self ._graphicsScene )
@@ -106,7 +108,7 @@ def _filter_text_changed(self, text):
106108 def _update_ui (self ):
107109 if hasattr (self , '_main_window' ):
108110 try :
109- wfm = self ._main_window . model (). workflowManager ()
111+ wfm = self ._workflowManager
110112 self ._main_window .setWindowTitle (wfm .title ())
111113 except RuntimeError :
112114 return
@@ -138,14 +140,13 @@ def updateStepTree(self):
138140 self ._ui .stepTreeView .expandAll ()
139141
140142 def applyOptions (self ):
141- om = self ._main_window .model ().optionsManager ()
142- show_step_names = om .getOption (SHOW_STEP_NAMES )
143+ show_step_names = self ._options_manager .getOption (SHOW_STEP_NAMES )
143144 self ._graphicsScene .showStepNames (show_step_names )
144145 self ._check_recents_length ()
145146 self ._update_recent_menu ()
146147
147148 def undoStackIndexChanged (self , index ):
148- self ._main_window . model (). workflowManager () .undoStackIndexChanged (index )
149+ self ._workflowManager .undoStackIndexChanged (index )
149150 self ._update_ui ()
150151
151152 def undoRedoStack (self ):
@@ -171,7 +172,7 @@ def executeNext(self):
171172 raise ClientRuntimeError ('Error in workflow execution' , str (e ))
172173
173174 def executeWorkflow (self ):
174- wfm = self ._main_window . model (). workflowManager ()
175+ wfm = self ._workflowManager
175176 errors = []
176177
177178 if wfm .isModified ():
@@ -208,11 +209,14 @@ def _abort_workflow(self):
208209 self ._abort_execution ()
209210 self ._reset_workflow_direction ()
210211
212+ def _do_layout (self , layout_type ):
213+ self ._workflowManager .layout_workflow (layout_type , self ._options_manager .getOption (ANIMATE_LAYOUT_UPDATES ))
214+
211215 def _spring_force_layout (self ):
212- self ._main_window . layout_workflow ("spring_force" )
216+ self ._do_layout ("spring_force" )
213217
214218 def _force_directed_layout (self ):
215- self ._main_window . layout_workflow ("force_directed" )
219+ self ._do_layout ("force_directed" )
216220
217221 def _reverse_workflow_direction (self ):
218222 self ._main_window .set_workflow_direction (not self .action_Reverse .isChecked ())
@@ -222,7 +226,7 @@ def _reset_workflow_direction(self):
222226 self ._main_window .set_workflow_direction (True )
223227
224228 def identifierOccursCount (self , identifier ):
225- return self ._main_window . model (). workflowManager () .identifierOccursCount (identifier )
229+ return self ._workflowManager .identifierOccursCount (identifier )
226230
227231 def setCurrentWidget (self , widget ):
228232 self ._main_window .set_current_widget (widget )
@@ -239,7 +243,7 @@ def new(self, pmr=False):
239243
240244 def _workflow_finished (self , successfully ):
241245 if successfully :
242- close_after = self ._main_window . model (). optionsManager () .getOption (CLOSE_AFTER )
246+ close_after = self ._options_manager .getOption (CLOSE_AFTER )
243247 mb = MessageBox (QtWidgets .QMessageBox .Icon .Information , "Workflow Finished" ,
244248 "Workflow finished successfully." ,
245249 QtWidgets .QMessageBox .StandardButton .Ok | QtWidgets .QMessageBox .StandardButton .Default ,
@@ -251,7 +255,7 @@ def _workflow_finished(self, successfully):
251255 self ._reset_workflow_direction ()
252256
253257 def _get_workflow_dir (self ):
254- m = self ._main_window . model (). workflowManager ()
258+ m = self ._workflowManager
255259 workflow_dir = QtWidgets .QFileDialog .getExistingDirectory (self ._main_window , caption = 'Select Workflow Directory' , dir = m .previousLocation ())
256260 if workflow_dir is None :
257261 # user abort
@@ -296,14 +300,13 @@ def rm_tree_unsuccessful(_one, _two, _three):
296300 @handle_runtime_error
297301 @set_wait_cursor
298302 def _create_new_workflow (self , workflow_dir , pmr ):
299- m = self ._main_window .model ().workflowManager ()
300- om = self ._main_window .model ().optionsManager ()
303+ m = self ._workflowManager
301304 m .new (workflow_dir )
302305 m .setPreviousLocation (workflow_dir )
303306
304307 if pmr :
305308 pmr_info = PMR ()
306- pmr_tool = PMRTool (pmr_info , use_external_git = om .getOption (USE_EXTERNAL_GIT ))
309+ pmr_tool = PMRTool (pmr_info , use_external_git = self . _options_manager .getOption (USE_EXTERNAL_GIT ))
307310 if pmr_tool .has_access ():
308311 dir_name = os .path .basename (workflow_dir )
309312 try :
@@ -326,7 +329,7 @@ def newpmr(self):
326329 self .new (pmr = True )
327330
328331 def open (self ):
329- wm = self ._main_window . model (). workflowManager ()
332+ wm = self ._workflowManager
330333
331334 primary_filter = f"Workflow configuration file ({ DEFAULT_WORKFLOW_PROJECT_FILENAME } )"
332335
@@ -449,7 +452,7 @@ def performWorkflowChecks(self, workflow_dir):
449452 5. Check for errors
450453 6. Update step tree
451454 """
452- # wm = self._main_window.model().workflowManager()
455+ # wm = self._workflowManager
453456 pm = self ._main_window .model ().pluginManager ()
454457 steps_to_install = pm .checkPlugins (workflow_dir )
455458 dependencies_to_install = pm .checkDependencies (workflow_dir )
@@ -470,7 +473,7 @@ def performWorkflowChecks(self, workflow_dir):
470473 @set_wait_cursor
471474 def _load (self , workflow_dir ):
472475 try :
473- m = self ._main_window . model (). workflowManager ()
476+ m = self ._workflowManager
474477 m .load (workflow_dir , self ._graphicsScene .sceneRect ())
475478 m .setPreviousLocation (workflow_dir )
476479 self ._graphicsScene .update_model ()
@@ -482,16 +485,15 @@ def _load(self, workflow_dir):
482485 self .close ()
483486 raise
484487
485- om = self ._main_window .model ().optionsManager ()
486- om .setOption (PREVIOUS_WORKFLOW , workflow_dir )
488+ self ._options_manager .setOption (PREVIOUS_WORKFLOW , workflow_dir )
487489
488490 def reload (self ):
489- m = self ._main_window . model (). workflowManager ()
491+ m = self ._workflowManager
490492 self ._load (m .location ())
491493
492494 def close (self ):
493495 self ._main_window .confirm_close ()
494- m = self ._main_window . model (). workflowManager ()
496+ m = self ._workflowManager
495497 self ._undoStack .clear ()
496498 self ._graphicsScene .clear ()
497499 m .close ()
@@ -501,7 +503,7 @@ def pixmap(self):
501503 return self ._ui .graphicsView .grab ()
502504
503505 def save (self ):
504- m = self ._main_window . model (). workflowManager ()
506+ m = self ._workflowManager
505507 location_set = os .path .exists (m .location ())
506508 if location_set :
507509 self ._updateLocation ()
@@ -518,7 +520,7 @@ def save(self):
518520 self ._update_ui ()
519521
520522 def saveAs (self ):
521- wm = self ._main_window . model (). workflowManager ()
523+ wm = self ._workflowManager
522524 workflow_dir = wm .location ()
523525 location_set = self ._set_location ()
524526 if location_set :
@@ -528,15 +530,15 @@ def saveAs(self):
528530 shutil .copytree (src_git_dir , os .path .join (wm .location (), '.git' ), dirs_exist_ok = True )
529531
530532 def _updateLocation (self ):
531- m = self ._main_window . model (). workflowManager ()
533+ m = self ._workflowManager
532534 workflow_dir = m .location ()
533535 if m .set_location (workflow_dir ):
534536 self ._ui .graphicsView .setLocation (workflow_dir )
535537 self ._graphicsScene .update_model ()
536538
537539 def _set_location (self ):
538540 location_set = False
539- m = self ._main_window . model (). workflowManager ()
541+ m = self ._workflowManager
540542 workflow_dir = self ._get_workflow_dir ()
541543 if workflow_dir :
542544 m .setPreviousLocation (workflow_dir )
@@ -548,9 +550,8 @@ def _set_location(self):
548550 return location_set
549551
550552 def commitChanges (self , workflowDir ):
551- om = self ._main_window .model ().optionsManager ()
552553 pmr_info = PMR ()
553- pmr_tool = PMRTool (pmr_info , use_external_git = om .getOption (USE_EXTERNAL_GIT ))
554+ pmr_tool = PMRTool (pmr_info , use_external_git = self . _options_manager .getOption (USE_EXTERNAL_GIT ))
554555 if not pmr_tool .is_pmr_workflow (workflowDir ):
555556 # nothing to commit.
556557 return True
@@ -560,10 +561,8 @@ def commitChanges(self, workflowDir):
560561 @handle_runtime_error
561562 @set_wait_cursor
562563 def _commitChanges (self , workflowDir , comment ):
563- committed_changes = False
564- om = self ._main_window .model ().optionsManager ()
565564 pmr_info = PMR ()
566- pmr_tool = PMRTool (pmr_info , use_external_git = om .getOption (USE_EXTERNAL_GIT ))
565+ pmr_tool = PMRTool (pmr_info , use_external_git = self . _options_manager .getOption (USE_EXTERNAL_GIT ))
567566 try :
568567 # If the user has added a .gitignore to the workflow root directory, let this automatically filter the files that are committed.
569568 if os .path .isfile (os .path .join (workflowDir , ".gitignore" )):
@@ -597,9 +596,8 @@ def _commitChanges(self, workflowDir, comment):
597596 @handle_runtime_error
598597 @set_wait_cursor
599598 def _setIndexerFile (self , workflow_dir ):
600- om = self ._main_window .model ().optionsManager ()
601599 pmr_info = PMR ()
602- pmr_tool = PMRTool (pmr_info , use_external_git = om .getOption (USE_EXTERNAL_GIT ))
600+ pmr_tool = PMRTool (pmr_info , use_external_git = self . _options_manager .getOption (USE_EXTERNAL_GIT ))
603601
604602 if not pmr_tool .is_pmr_workflow (workflow_dir ):
605603 return
@@ -628,7 +626,7 @@ def reset_zoom(self):
628626 self ._ui .graphicsView .reset_zoom ()
629627
630628 def import_cfg (self ):
631- m = self ._main_window . model (). workflowManager ()
629+ m = self ._workflowManager
632630 import_source , _ = QtWidgets .QFileDialog .getOpenFileName (self ._main_window , caption = 'Select Import File' , dir = m .previousLocation (),
633631 filter = f"Data files(*.zip);;MAP Client Project file({ DEFAULT_WORKFLOW_PROJECT_FILENAME } )" )
634632
@@ -743,7 +741,7 @@ def _create_menu_items(self):
743741 menu_workflow_layout .addAction (self .action_ForceDirectedLayout )
744742
745743 def _update_recent_menu (self ):
746- absolute_paths = self ._main_window . model (). optionsManager () .getOption (RECENTS_ABSOLUTE_PATHS )
744+ absolute_paths = self ._options_manager .getOption (RECENTS_ABSOLUTE_PATHS )
747745
748746 self .menu_recent .clear ()
749747 for path , name in self ._recent_workflow_paths ().items ():
@@ -780,8 +778,7 @@ def _recent_workflow_paths(self):
780778 return directory_map
781779
782780 def _check_recents_length (self ):
783- options_manager = self ._main_window .model ().optionsManager ()
784- recents_length = options_manager .getOption (RECENTS_LENGTH )
781+ recents_length = self ._options_manager .getOption (RECENTS_LENGTH )
785782
786783 recent_paths = self .model ().get_recent_workflows ()
787784 removals = len (recent_paths ) - recents_length
0 commit comments