[Avida-cvs] [Avida2-svn] r64 - trunk/source/python/AvidaGui2

kaben at myxo.css.msu.edu kaben at myxo.css.msu.edu
Mon Mar 21 08:25:51 PST 2005


Author: kaben
Date: 2005-03-21 11:25:51 -0500 (Mon, 21 Mar 2005)
New Revision: 64

Modified:
   trunk/source/python/AvidaGui2/pyEduSessionMenuBarHdlr.py
   trunk/source/python/AvidaGui2/pySessionCtrl.py
Log:

* Code for selecting the temporary working directory for a session in AvidaEd.



Modified: trunk/source/python/AvidaGui2/pyEduSessionMenuBarHdlr.py
===================================================================
--- trunk/source/python/AvidaGui2/pyEduSessionMenuBarHdlr.py	2005-03-21 11:34:23 UTC (rev 63)
+++ trunk/source/python/AvidaGui2/pyEduSessionMenuBarHdlr.py	2005-03-21 16:25:51 UTC (rev 64)
@@ -124,7 +124,8 @@
       self.m_session_mdl.m_session_mdtr.m_edu_session_menu_bar_hdlr_mdtr, qt.PYSIGNAL("doMinimizeWindowSig"))
     main_window.m_menu_bar.insertItem("Window", main_window.m_window_menu)
 
-    # main_window.setupCustomMenus(self)
+    if hasattr(main_window, 'setupCustomMenus'):
+      main_window.setupCustomMenus(self)
 
 # Unit tests.
 

Modified: trunk/source/python/AvidaGui2/pySessionCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pySessionCtrl.py	2005-03-21 11:34:23 UTC (rev 63)
+++ trunk/source/python/AvidaGui2/pySessionCtrl.py	2005-03-21 16:25:51 UTC (rev 64)
@@ -1,5 +1,3 @@
-#from pyAvidaCoreData import pyAvidaCoreData
-#from pyAvidaThreadedDriver import pyAvidaThreadedDriver
 from pyEduSessionMenuBarHdlr import *
 from pyEduWorkspaceCtrl import *
 from pyAvidaCoreData import *
@@ -7,13 +5,30 @@
 from pySessionControllerFactory import *
 from pySessionDumbCtrl import *
 from pySessionWorkThreadHdlr import *
+
 from AvidaCore import cString
+
 import qt
 
+import os
+import tempfile
+
 class pySessionCtrl(qt.QObject):
   def __init__(self):
     qt.QObject.__init__(self, None, self.__class__.__name__)
-  def construct(self, main_mdl, genesis_filename):
+
+  def __del__(self):
+    # Clean this session's temporary subdirectory.
+    print 'pySessionCtrl.__del__() about to remove %s...' % self.m_session_mdl.m_tempdir
+    for root, dirs, files in os.walk(self.m_session_mdl.m_tempdir, topdown=False):
+      for name in files:
+        os.remove(os.path.join(root, name))
+      for name in dirs:
+        os.rmdir(os.path.join(root, name))
+    os.removedirs(self.m_session_mdl.m_tempdir)
+    print 'pySessionCtrl.__del__() done.'
+
+  def construct(self, main_mdl):
     print("""
     FIXME : pySessionCtrl
     I'm using the wrong locking model in the driver threads...
@@ -22,39 +37,30 @@
     ...But I'd say it's okay for the moment, since we can't run more than one instance of Avida concurrently (yet)...
     """)
 
-    # create "model" for storing state data
+    # Create "model" for storing state data.
     class pyMdl: pass
     self.m_session_mdl = pyMdl()
-    self.m_session_mdl.m_genesis_filename = genesis_filename
-    #self.m_session_mdl.m_main_mdl = main_mdl
 
-    # create session mediator
+    # Create a temporary subdirectory for general use in this session.
+    self.m_session_mdl.m_tempdir = tempfile.mkdtemp('-pid%d'%os.getpid(),'AvidaEd-')
+
+    # Create session mediator.
     self.m_session_mdl.m_session_mdtr = pyMdtr()
 
-    # create session controller factory
+    # create session controller factory.
     self.m_session_controller_factory = pySessionControllerFactory()
     self.m_session_controller_factory.construct(self.m_session_mdl)
 
-    # create an avida processing thread
-    ## XXX excising obsolete code. @kgn
-    # self.m_session_mdl.m_avida_core_data = pyAvidaCoreData()
-    # self.m_session_mdl.m_avida_core_data.construct(self.m_session_mdl.m_genesis_filename)
-
-    # connect various session controller creators to the controller
+    # Connect various session controller creators to the controller
     # factory.
     self.m_session_controller_factory.addControllerCreator("pyEduSessionMenuBarHdlr", pyEduSessionMenuBarHdlr)
-    ## XXX excising obsolete code. @kgn
-    # self.m_session_controller_factory.addControllerCreator("pySessionWorkThreadHdlr", pySessionWorkThreadHdlr)
     self.m_session_controller_factory.addControllerCreator("pySessionDumbCtrl", pySessionDumbCtrl)
     self.m_session_controller_factory.addControllerCreator("pyEduWorkspaceCtrl", pyEduWorkspaceCtrl)
 
     self.m_session_mdl.m_session_mdtr.m_session_controller_factory_mdtr.emit(
       qt.PYSIGNAL("newSessionControllerSig"), ("pyEduSessionMenuBarHdlr",))
-    ## XXX this was temporary code, now kept around for reference. @kgn
-    # self.m_session_mdl.m_session_mdtr.m_session_controller_factory_mdtr.emit(
-    #   qt.PYSIGNAL("newSessionControllerSig"), ("pySessionWorkThreadHdlr",))
     
-    ## XXX temporary. cause instantiation of a dumb gui for testing. @kgn
+    ## XXX Temporary. Cause instantiation of a dumb gui for testing. @kgn
     self.m_session_mdl.m_session_mdtr.m_session_controller_factory_mdtr.emit(
       qt.PYSIGNAL("newSessionControllerSig"), ("pySessionDumbCtrl",))
 
@@ -68,7 +74,7 @@
     FIXME : pySessionCtrl
     In doOrphanSessionSlot, do cleanup, i.e., if session not saved, ask user to verify session close.
     """
-    ## XXX temporary.
+    ## XXX Temporary.
     print """
     FIXME : pySessionCtrl
     There's gotta be a better way for the session to close itself than this...
@@ -77,52 +83,7 @@
       qt.PYSIGNAL("deleteControllerSig"), (self,))
   def unitTest(self, recurse = False):
     return pyUnitTestSuiteRecurser("pySessionCtrl", globals(), recurse).construct().runTest().lastResult()
-  #def __del__(self):
-  #  print("""
-  #  FIXME : pySessionCtrl
-  #  __del__() doesn't clean-up correctly (halt the processing thread,
-  #  then delete it before exiting), probably because I'm locking
-  #  per-thread rather than on the Avida library.
 
-  #  I'm using the wrong locking model in the driver threads...
-  #  I need to lock on access to the Avida core library, rather than on
-  #  per-thread locks (in order to protect static data in the library).
-  #  """)
-  #  # Explicit deletion, rather than reliance on refcounting, permits
-  #  # the thread to delete itself in a thread-safe way.
-  #  #self.m_session_mdl.m_session_controllers_list.reverse()
-  #  #self.avida_threaded_driver = self.session_mdl.avida_threaded_driver
-  #  #for controller in self.session_mdl.session_controllers_list:
-  #  #  print "pySessionCtrl.destruct() deleting controller:", controller
-  #  #  controller.destruct()
-  #  #  del controller
-
-  #  #while 0 < len(self.m_session_mdl.m_session_controllers_list):
-  #  #  print "pySessionCtrl.destruct() again deleting controller:", self.m_session_mdl.m_session_controllers_list[0]
-  #  #  del self.m_session_mdl.m_session_controllers_list[0]
-
-  #  print """
-  #  FIXME: pySessionCtrl
-  #  why do I need to check for presence of attribute self.m_session_mdl.m_avida_threaded_driver?
-  #  """
-  #  if hasattr(self.m_session_mdl, "m_avida_threaded_driver"):
-  #    del self.m_session_mdl.m_avida_threaded_driver
-  #  else:
-  #    print("pySessionCtrl.destruct() self.session_mdl.avida_threaded_driver missing.")
-
-  #  del self.m_session_mdl.m_avida_core_data
-  #  del self.m_session_controller_factory
-  #  del self.m_session_mdl.m_session_mdtr
-  #  del self.m_session_mdl.m_main_mdl
-
-  #  print """
-  #  FIXME: pySessionCtrl
-  #  why do I need to check for presence of attribute self.m_session_mdl?
-  #  """
-  #  if hasattr(self, "m_session_mdl"):
-  #    del self.m_session_mdl
-
-
 # Unit tests.
 
 from py_test_utils import *




More information about the Avida-cvs mailing list