[Avida-SVN] r1568 - branches/developers/avida-edward/source/python/AvidaGui2

baerb at myxo.css.msu.edu baerb at myxo.css.msu.edu
Thu May 17 07:28:52 PDT 2007


Author: baerb
Date: 2007-05-17 10:28:52 -0400 (Thu, 17 May 2007)
New Revision: 1568

Modified:
   branches/developers/avida-edward/source/python/AvidaGui2/pyBeforeStartingCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceView.ui
   branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeDialogCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeOrganismCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyOneAna_GraphCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyRightClickDialogCtrl.py
Log:


Implimented basic export and import in Avida-ED



Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyBeforeStartingCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyBeforeStartingCtrl.py	2007-05-17 13:39:14 UTC (rev 1567)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyBeforeStartingCtrl.py	2007-05-17 14:28:52 UTC (rev 1568)
@@ -4,6 +4,7 @@
 from pyBeforeStartingView import pyBeforeStartingView
 
 # class to pop up a dialog box before someone saves for the first time
+# (assumeing the user has not already opened/created a workspace)
 
 class pyBeforeStartingCtrl (pyBeforeStartingView):
   def __init__(self):
@@ -18,7 +19,12 @@
     self.connect(self.CreateNewPushButton, SIGNAL("clicked()"),
                  self.CreateNewSlot)
 
-  def showDialog(self):
+  def showDialog(self, verb):
+
+    # Change the propt depending if the user is trying to import or freeze
+
+    # self.BeforeStartTextLabel.setText(self.__tr("<p align=\"center\">Before you can " + verb + " a petri dish or organism<br> you must choose a workspace to work with</p>"))
+
     dialog_result = 1
     while (dialog_result > 0):
       self.exec_loop()

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceCtrl.py	2007-05-17 13:39:14 UTC (rev 1567)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceCtrl.py	2007-05-17 14:28:52 UTC (rev 1568)
@@ -14,9 +14,10 @@
 from pyPetriConfigureCtrl import pyPetriConfigureCtrl
 from pyQuitDialogCtrl import pyQuitDialogCtrl
 from pyDefaultFiles import pyDefaultFiles
-from pyButtonListDialog import pyButtonListDialog
 from pyReadFreezer import pyReadFreezer
 from pyWarnAboutTrashCtrl import pyWarnAboutTrashCtrl
+# from pyImportItemCtrl import pyImportItemCtrl
+from pyBeforeStartingCtrl import pyBeforeStartingCtrl
 import pyNewIconView
 import os.path, shutil
 from qt import *
@@ -151,7 +152,7 @@
     self.m_nav_bar_ctrl.m_list_view.setSelected(self.m_nav_bar_ctrl.m_one_population_cli, True)
     self.splitter1.setSizes([150,500,100])
 
-    # set up the trash can ot have one trash can icon that can not be selected
+    # set up the trash can to have one trash can icon that can not be selected
 
     # self.TrashCanIconView.setItemTextPos(QIconView.Right)
     # self.TrashCanIconView.setSpacing(1)
@@ -200,7 +201,7 @@
   def fileNew(self):
 
     # loop till the users selects a directory name that does not exist or
-    # choses the cancel button
+    # chooses the cancel button
 
     created = False
     dialog_caption = "Enter the name of a new workspace"
@@ -249,7 +250,6 @@
               if (os.path.exists(sourceName)):
                 shutil.copyfile(sourceName, destName)
               else:
-                descr(" BDB fileName = " + fileName + "  destName = " + destName) 
                 pyDefaultFiles(fileName, destName)
             self.m_session_mdl.m_current_workspace = str(new_dir)
             self.m_session_mdl.m_current_freezer = os.path.join(new_dir, "freezer")
@@ -277,7 +277,6 @@
 
       if not self.m_session_mdl.directory_chosen:
         initial_dir = os.path.expanduser("~")
-        print "BDB: " + os.path.join(initial_dir,"Documents")
         if os.path.exists(os.path.join(initial_dir,"Documents")):
           initial_dir = os.path.join(initial_dir,"Documents")
         elif os.path.exists(os.path.join(initial_dir,"My Documents")):
@@ -384,55 +383,140 @@
     "Export images to a file"
     self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("saveImagesSig"), ())
 
+  def fileImportItem(self):
+    "Import a freezer item that was previously exported"
+
+    # self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("importFreezerItemSig"), ())
+    # m_import_freeze_item = pyImportItemCtrl()
+    # item_to_import = m_import_freeze_item.showDialog(self.m_session_mdl)
+
+    # If the user has not already chosen an active workspace for this session
+    # make them do so now. If they chose not to pick a workspace, don't let
+    # them import the file
+
+    if (self.m_session_mdl.directory_chosen == False):
+      m_prompt_dir = pyBeforeStartingCtrl()
+      m_prompt_dir.construct(self.m_session_mdl)
+      if (m_prompt_dir.showDialog("import") == 0):
+        return ''
+
+    tmpDialogCap = "Select an exported dish or organism (*.aex)"
+    foundFile = False
+    input_item_name = ""
+    initial_dir = ""
+
+    while (foundFile == False):
+
+      # start on the ~/Documents on the Mac ~ on Linux and $HOME/My 
+      # Documents on Windows
+
+      if (len(initial_dir.strip()) == 0):
+        initial_dir = os.path.expanduser("~")
+        if os.path.exists(os.path.join(initial_dir,"Documents")):
+          initial_dir = os.path.join(initial_dir,"Documents")
+        elif os.path.exists(os.path.join(initial_dir,"My Documents")):
+          initial_dir = os.path.join(initial_dir,"My Documents")
+
+      input_item_name = QFileDialog.getOpenFileName(
+                    initial_dir,
+                    "Avida-ED Export Files (*.aex)",
+                    None,
+                    "Import Item",
+                    tmpDialogCap,
+                    "Configured Dishes",
+                    True)
+      input_item_name = str(input_item_name)
+      input_item_name = input_item_name.strip()
+
+      # If a valid name is found or the user hit cancel leave the loop
+      # otherwise prompt for the wrong name and continue
+
+      if (input_item_name == "") or (input_item_name.endswith(".aex")):
+        foundFile = True
+      else:
+        foundFile = False
+        tmpDialogCap = "Not a valid file.  Please try again"
+
+    if input_item_name != "":
+      junk, input_core_file_name = os.path.split(input_item_name)
+      input_name_no_ext, junk = os.path.splitext(input_core_file_name) 
+      input_file =  open(input_item_name,"r")
+      try:
+        for line in input_file:
+
+          # If we find a *File line open a new file
+
+          if (line.startswith("*File:")):
+            if (line.find(".empty") > -1):
+              new_file_name = os.path.join(self.m_session_mdl.m_current_freezer,
+                                           "imp_" + input_name_no_ext + ".empty")
+            elif (line.find(".organism") > -1):
+              new_file_name = os.path.join(self.m_session_mdl.m_current_freezer,
+                                           "imp_" + input_name_no_ext + ".organism")
+            elif (line.find(".full") > -1):
+              new_dir_name = os.path.join(self.m_session_mdl.m_current_freezer,
+                                          "imp_" + input_name_no_ext + ".full")
+              if (not os.path.exists(new_dir_name)):
+                os.mkdir(new_dir_name)
+              sub_file_name = line[line.rfind(":")+2:]
+              new_file_name = os.path.join(new_dir_name, sub_file_name)
+              
+            new_file = open(new_file_name.strip(),'w')
+          else:
+            new_file.write(line)
+      finally:
+        input_file.close()
+        new_file.close()
+
   # public slot
 
   def fileExit(self):
-    print "pyEduWorkspaceCtrl.fileExit(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.fileExit(): Not implemented yet")
 
   # public slot
 
   def editUndo(self):
-    print "pyEduWorkspaceCtrl.editUndo(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.editUndo(): Not implemented yet")
 
   # public slot
 
   def editRedo(self):
-    print "pyEduWorkspaceCtrl.editRedo(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.editRedo(): Not implemented yet")
 
   # public slot
 
   def editCut(self):
-    print "pyEduWorkspaceCtrl.editCut(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.editCut(): Not implemented yet")
 
   # public slot
 
   def editCopy(self):
-    print "pyEduWorkspaceCtrl.editCopy(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.editCopy(): Not implemented yet")
 
   # public slot
 
   def editPaste(self):
-    print "pyEduWorkspaceCtrl.editPaste(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.editPaste(): Not implemented yet")
 
   # public slot
 
   def editFind(self):
-    print "pyEduWorkspaceCtrl.editFind(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.editFind(): Not implemented yet")
 
   # public slot
 
   def helpIndex(self):
-    print "pyEduWorkspaceCtrl.helpIndex(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.helpIndex(): Not implemented yet")
 
   # public slot
 
   def helpContents(self):
-    print "pyEduWorkspaceCtrl.helpContents(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.helpContents(): Not implemented yet")
 
   # public slot
 
   def helpAbout(self):
-    print "pyEduWorkspaceCtrl.helpAbout(): Not implemented yet"
+    descr("pyEduWorkspaceCtrl.helpAbout(): Not implemented yet")
 
   def next_UpdateActionSlot(self):
     self.m_session_mdl.m_session_mdtr.emit(

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceView.ui
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceView.ui	2007-05-17 13:39:14 UTC (rev 1567)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceView.ui	2007-05-17 14:28:52 UTC (rev 1568)
@@ -33,8 +33,8 @@
     </property>
     <property name="minimumSize">
         <size>
-            <width>1024</width>
-            <height>700</height>
+            <width>195</width>
+            <height>501</height>
         </size>
     </property>
     <property name="maximumSize">
@@ -193,6 +193,7 @@
         <separator/>
         <action name="fileExportAction"/>
         <action name="fileSaveImagesAction"/>
+        <action name="fileImportItemAction"/>
         <separator/>
         <action name="m_print_action"/>
     </item>
@@ -304,6 +305,8 @@
         <property type="0">-1</property>
         <property type="1">pyFreezerView</property>
         <property type="0">-1</property>
+        <property type="1">pyFreezerView</property>
+        <property type="0">-1</property>
         <property type="pyFreezerView"></property>
         <property type="-1">1</property>
     </customwidget>
@@ -381,6 +384,8 @@
         <property type="0">-1</property>
         <property type="1">pyNavBarView</property>
         <property type="0">-1</property>
+        <property type="1">pyNavBarView</property>
+        <property type="0">-1</property>
         <property type="pyNavBarView"></property>
         <property type="-1">1</property>
     </customwidget>
@@ -866,6 +871,20 @@
             <string>Open Analysis View</string>
         </property>
     </action>
+    <action>
+        <property name="name">
+            <cstring>fileImportItemAction</cstring>
+        </property>
+        <property name="text">
+            <string>Import Item</string>
+        </property>
+        <property name="menuText">
+            <string>Import Item</string>
+        </property>
+        <property name="toolTip">
+            <string>Import Freezer Items</string>
+        </property>
+    </action>
 </actions>
 <images>
     <image name="image0">
@@ -1008,7 +1027,16 @@
         <receiver>pyEduWorkspaceView</receiver>
         <slot>helpAbout()</slot>
     </connection>
+    <connection>
+        <sender>fileImportItemAction</sender>
+        <signal>activated()</signal>
+        <receiver>pyEduWorkspaceView</receiver>
+        <slot>fileImportItem()</slot>
+    </connection>
 </connections>
+<includes>
+    <include location="local" impldecl="in implementation">pyEduWorkspaceView.ui.h</include>
+</includes>
 <slots>
     <slot>fileNew()</slot>
     <slot>fileOpen()</slot>
@@ -1027,6 +1055,7 @@
     <slot>helpIndex()</slot>
     <slot>helpContents()</slot>
     <slot>helpAbout()</slot>
+    <slot>fileImportItem()</slot>
 </slots>
 <layoutdefaults spacing="6" margin="11"/>
 <includehints>

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeDialogCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeDialogCtrl.py	2007-05-17 13:39:14 UTC (rev 1567)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeDialogCtrl.py	2007-05-17 14:28:52 UTC (rev 1568)
@@ -24,7 +24,7 @@
     if (session_mdl.directory_chosen == False):
       m_prompt_dir = pyBeforeStartingCtrl()
       m_prompt_dir.construct(session_mdl)
-      if (m_prompt_dir.showDialog() == 0):
+      if (m_prompt_dir.showDialog("freeze") == 0):
         return ''
     
     # If the user selects to open existing/create new workspace then hits

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeOrganismCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeOrganismCtrl.py	2007-05-17 13:39:14 UTC (rev 1567)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyFreezeOrganismCtrl.py	2007-05-17 14:28:52 UTC (rev 1568)
@@ -23,7 +23,7 @@
     if (session_mdl.directory_chosen == False):
       m_prompt_dir = pyBeforeStartingCtrl()
       m_prompt_dir.construct(session_mdl)
-      if (m_prompt_dir.showDialog() == 0):
+      if (m_prompt_dir.showDialog('freeze') == 0):
         return ''
     
     # If the user selects to open existing/create new workspace then hits

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOneAna_GraphCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOneAna_GraphCtrl.py	2007-05-17 13:39:14 UTC (rev 1567)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOneAna_GraphCtrl.py	2007-05-17 14:28:52 UTC (rev 1568)
@@ -363,7 +363,6 @@
 
 
   def petriDropped(self, freezer_item_name): 
-    descr("BDB")
 
     # a check in pyOneAnalyzeCtrl.py makes sure this is a valid path
 

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyRightClickDialogCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyRightClickDialogCtrl.py	2007-05-17 13:39:14 UTC (rev 1567)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyRightClickDialogCtrl.py	2007-05-17 14:28:52 UTC (rev 1568)
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+from descr import *
+
 from qt import *
 from pyRightClickDialogView import pyRightClickDialogView
 import shutil, os, os.path
@@ -71,22 +73,68 @@
         self.change = True
 
     elif dialog_result == self.SaveAsFlag:
-      file_dialog = QFileDialog (os.path.join(self.file_dir, '..'), 
-        '.junk1234junk', self, 'Export', False)
-      file_dialog.setCaption('Export ' + self.file_ext.lstrip('.') + " " + 
-        self.item_name + ' to:')
-      file_dialog.setMode(QFileDialog.DirectoryOnly)
-      # file_dialog.setSelection (self.file_core_name)
-      file_dialog.show()
-      file_dialog.exec_loop()
-      if file_dialog.result() == True:
-        export_file_name = os.path.join(str(file_dialog.selectedFile()),
-         self.file_core_name)
-        if (self.file_ext == '.full'):
-          shutil.copytree(self.file_name, str(export_file_name))
-        else:
-          shutil.copyfile(self.file_name, str(export_file_name))
+      # file_dialog = QFileDialog (os.path.join(self.file_dir, '..'), 
+      #   '.junk1234junk', self, 'Export', False)
+      # file_dialog.setCaption('Export ' + self.file_ext.lstrip('.') + " " + 
+      #   self.item_name + ' to:')
+      # file_dialog.setMode(QFileDialog.DirectoryOnly)
+      # # file_dialog.setSelection (self.file_core_name)
+      # file_dialog.show()
+      # file_dialog.exec_loop()
+      # if file_dialog.result() == True:
+      #   export_file_name = os.path.join(str(file_dialog.selectedFile()),
+      #    self.file_core_name)
+      #   if (self.file_ext == '.full'):
+      #     shutil.copytree(self.file_name, str(export_file_name))
+      #   else:
+      #     shutil.copyfile(self.file_name, str(export_file_name))
 
+      # If the directory has not been chosen self.file_dir is not
+      # correct (at least on the Mac).  It is a relative path where
+      # QFileDialog.getSaveFileName seems to require an absolut path
+
+      abs_dir = os.path.abspath(self.file_dir);
+      if (os.path.exists(abs_dir) == False):
+        initial_dir = os.path.expanduser("~")
+        if os.path.exists(os.path.join(initial_dir,"Documents")):
+          initial_dir = os.path.join(initial_dir,"Documents")
+        elif os.path.exists(os.path.join(initial_dir,"My Documents")):
+          initial_dir = os.path.join(initial_dir,"My Documents")
+      else:
+        initial_dir = abs_dir
+      no_ext_name, ext = os.path.splitext(self.file_core_name)
+      initial_file_name = os.path.join(initial_dir,no_ext_name + ".aex")
+
+      export_file_name = QFileDialog.getSaveFileName(
+        initial_file_name,
+        "Avida_ED export (*.aex);;",
+        None,
+        "Export Item",
+        "Export dish or organism")
+      export_file = open(str(export_file_name), "w")
+      if (self.file_ext == '.full'):
+        files_in_full = os.listdir(self.file_name)
+        for indiv_file_name in files_in_full:
+
+          # Read each file, write the name and content of the file
+          # into the export file
+
+          if (not indiv_file_name.startswith('.')):
+            individual_file = open(os.path.join(self.file_name,indiv_file_name), "r")
+            export_file.write("*File: " + self.file_ext + ": " + indiv_file_name + "\n")
+            lines = individual_file.readlines()
+            for line in lines:
+              export_file.write(line)
+            individual_file.close()
+      else:
+        individual_file = open(self.file_name, "r")
+        export_file.write("*File: " + self.file_ext + "\n")
+        lines = individual_file.readlines()
+        for line in lines:
+          export_file.write(line)
+        individual_file.close()
+      export_file.close()
+
     elif dialog_result == self.OpenFlag:
       self.open_obj = True
 




More information about the Avida-cvs mailing list