[Avida-cvs] [avida-svn] r736 - branches/developers/avida-edward/source/python/AvidaGui2

gerrishj@myxo.css.msu.edu gerrishj at myxo.css.msu.edu
Tue Jun 6 11:43:10 PDT 2006


Author: gerrishj
Date: 2006-06-06 14:43:10 -0400 (Tue, 06 Jun 2006)
New Revision: 736

Modified:
   branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaStatsInterface.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/pyOneAna_GraphCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_GraphCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/to-do_list
Log:
Exporting of graph data to comma delimited works in population view now
Moved some duplicated stat loading functions into pyAvidaStatsInterface.py
Removed extra print menu item.  Dialog lets user select which object to print


Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaStatsInterface.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaStatsInterface.py	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaStatsInterface.py	2006-06-06 18:43:10 UTC (rev 736)
@@ -1,5 +1,10 @@
 
+from AvidaCore import cInitFile, cString
 from AvidaCore import cPopulation, cStats
+from Numeric import *
+from pyButtonListDialog import pyButtonListDialog
+from qt import QFileDialog
+import os.path
 
 class pyAvidaStatsInterface:
   def __init__(self):
@@ -22,6 +27,73 @@
 #      ('Number of Births',              'count.dat',     9, lambda s: s.GetNumBirths()),
 #      ('Number of Deaths',              'count.dat',    10, lambda s: s.GetNumDeaths()),
     )
+
   def getValue(self, entry_index, stats):
     if entry_index:
       return self.m_entries[entry_index][3](stats)
+
+  def load(self, path, filename, colx, coly):
+    "Load stats from file"
+    init_file = cInitFile(cString(os.path.join(path, filename)))
+    init_file.Load()
+    init_file.Compress()
+
+    x_array = zeros(init_file.GetNumLines(), Float)
+    y_array = zeros(init_file.GetNumLines(), Float)
+
+    for line_id in xrange(init_file.GetNumLines()):
+      line = init_file.GetLine(line_id)
+      x_array[line_id] = line.GetWord(colx - 1).AsDouble()
+      y_array[line_id] = line.GetWord(coly - 1).AsDouble()
+    return x_array, y_array
+
+  def export(self, path):
+    "Export stats to a file"
+    dialog_caption = "Export Analysis"
+    fd = QFileDialog.getSaveFileName("", "CSV (Excel compatible) (*.csv)", None,
+                                     "export as", dialog_caption)
+    filename = str(fd)
+    if (filename[-4:].lower() != ".csv"):
+      filename += ".csv"
+
+    checks = []
+    # dictionary indexed by stat name so we can lookup stats to export
+    stats = {}
+    stat_cnt = 0
+    for stat in self.m_entries:
+      # Note: this relies on labeling dummy stats with None
+      if stat[0] != "None":
+        stats[stat[0]] = stat_cnt
+        checks.append(stat[0])
+      stat_cnt += 1
+
+    dialog = pyButtonListDialog(dialog_caption, "Choose stats to export",
+                                checks, True)
+    # enable checkboxes
+    for button in dialog.buttons:
+      button.setOn(True)
+
+    res = dialog.showDialog()
+    if res == []:
+      return
+
+    data = {}
+
+    # Load stats for selected exports
+    # TODO: more efficient loading
+    for item in res:
+      idx = stats[item]
+      label1 = self.m_entries[idx][0]
+      data[item] = self.load(path, self.m_entries[idx][1], 1,
+                             self.m_entries[idx][2])
+
+    out_file = open(filename, 'w')
+    out_file.write("Update,%s\n" % (",".join(res)))
+    # TODO: get it working with zip
+    #print zip([data[elem][1][i] for elem in res])        
+    num_updates = len(data[res[0]][0])
+    for i in range(num_updates):
+      out_file.write("%d,%s\n"
+                     % (i, ",".join([str(data[elem][1][i]) for elem in res])))
+
+    out_file.close()

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceCtrl.py	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceCtrl.py	2006-06-06 18:43:10 UTC (rev 736)
@@ -12,6 +12,7 @@
 from pyPetriConfigureCtrl import pyPetriConfigureCtrl
 from pyQuitDialogCtrl import pyQuitDialogCtrl
 from pyDefaultFiles import pyDefaultFiles
+from pyButtonListDialog import pyButtonListDialog
 import os.path, shutil
 
 
@@ -298,15 +299,9 @@
 
   # public slot
 
-  def filePrintPetriDish(self):
-    print "pyEduWorkspaceCtrl.filePrintPetriDish() emitting printPetriDishSig via self.m_session_mdl.m_session_mdtr"
-    self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("printPetriDishSig"), ())
-
-  # public slot
-
   def filePrint(self):
-    print "pyEduWorkspaceCtrl.filePrint() emitting printGraphSig via self.m_session_mdl.m_session_mdtr"
-    self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("printGraphSig"), ())
+    "Print petri dish or graph"
+    self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("printSig"), ())
 
   # public slot
 

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceView.ui
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceView.ui	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyEduWorkspaceView.ui	2006-06-06 18:43:10 UTC (rev 736)
@@ -156,8 +156,7 @@
         <action name="fileExportAction"/>
         <action name="fileSaveImagesAction"/>
         <separator/>
-        <action name="m_petri_print_action"/>
-        <action name="m_graph_print_action"/>
+        <action name="m_print_action"/>
     </item>
     <item text="&amp;Edit" name="editMenu">
         <action name="editUndoAction"/>
@@ -397,35 +396,18 @@
     </action>
     <action>
         <property name="name">
-            <cstring>m_petri_print_action</cstring>
+            <cstring>m_print_action</cstring>
         </property>
         <property name="iconSet">
             <iconset>image4</iconset>
         </property>
         <property name="text">
-            <string>Print Petri &amp;Dish...</string>
+            <string>&amp;Print</string>
         </property>
         <property name="menuText">
-            <string>Print Petri &amp;Dish...</string>
+            <string>&amp;Print</string>
         </property>
         <property name="accel">
-            <string>Ctrl+D</string>
-        </property>
-    </action>
-    <action>
-        <property name="name">
-            <cstring>m_graph_print_action</cstring>
-        </property>
-        <property name="iconSet">
-            <iconset>image4</iconset>
-        </property>
-        <property name="text">
-            <string>&amp;Print Graph...</string>
-        </property>
-        <property name="menuText">
-            <string>&amp;Print Graph...</string>
-        </property>
-        <property name="accel">
             <string>Ctrl+P</string>
         </property>
     </action>
@@ -788,15 +770,9 @@
         <slot>fileSaveImages()</slot>
     </connection>
     <connection>
-        <sender>m_petri_print_action</sender>
+        <sender>m_print_action</sender>
         <signal>activated()</signal>
         <receiver>pyEduWorkspaceView</receiver>
-        <slot>filePrintPetriDish()</slot>
-    </connection>
-    <connection>
-        <sender>m_graph_print_action</sender>
-        <signal>activated()</signal>
-        <receiver>pyEduWorkspaceView</receiver>
         <slot>filePrint()</slot>
     </connection>
     <connection>
@@ -866,6 +842,7 @@
     <slot>fileSave()</slot>
     <slot>fileSaveAs()</slot>
     <slot>fileExport()</slot>
+    <slot>fileSaveImages()</slot>
     <slot>filePrint()</slot>
     <slot>fileExit()</slot>
     <slot>editUndo()</slot>

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOneAna_GraphCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOneAna_GraphCtrl.py	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOneAna_GraphCtrl.py	2006-06-06 18:43:10 UTC (rev 736)
@@ -1,15 +1,12 @@
 # -*- coding: utf-8 -*-
 
-from AvidaCore import cInitFile, cString
 from Numeric import *
 from pyAvidaStatsInterface import pyAvidaStatsInterface
 from pyOneAna_GraphView import pyOneAna_GraphView
-from pyButtonListDialog import pyButtonListDialog
 from pyGraphCtrl import PrintFilter
 from qt import *
 from qwt import *
 import os.path
-import os.path
 
 class pyOneAna_GraphCtrl(pyOneAna_GraphView):
 
@@ -78,21 +75,6 @@
     self.m_combo_box_2_color.setCurrentItem(2)
 
     self.modeActivatedSlot() 
-
-  def load(self, filename, colx, coly):
-    
-    init_file = cInitFile(cString(os.path.join(str(self.m_petri_dish_dir_path), filename)))
-    init_file.Load()
-    init_file.Compress()
-
-    x_array = zeros(init_file.GetNumLines(), Float)
-    y_array = zeros(init_file.GetNumLines(), Float)
-
-    for line_id in xrange(init_file.GetNumLines()):
-      line = init_file.GetLine(line_id)
-      x_array[line_id] = line.GetWord(colx - 1).AsDouble()
-      y_array[line_id] = line.GetWord(coly - 1).AsDouble()
-    return x_array, y_array
   
   def modeActivatedSlot(self, index = None): #note: index is not used
     self.m_graph_ctrl.clear()
@@ -120,7 +102,8 @@
         self.m_graph_ctrl.setAxisAutoScale(QwtPlot.yLeft)
         print "index_1[2] is"
         print self.m_avida_stats_interface.m_entries[index_1][2]
-        self.m_curve_1_arrays = self.load(
+        self.m_curve_1_arrays = self.m_avida_stats_interface.load(
+            str(self.m_petri_dish_dir_path),
             self.m_avida_stats_interface.m_entries[index_1][1],
             1,
             self.m_avida_stats_interface.m_entries[index_1][2]
@@ -142,7 +125,8 @@
         self.m_graph_ctrl.setAxisTitle(QwtPlot.yRight, self.m_avida_stats_interface.m_entries[index_2][0])
         self.m_graph_ctrl.enableYRightAxis(True)      
         self.m_graph_ctrl.setAxisAutoScale(QwtPlot.yRight)
-        self.m_curve_2_arrays = self.load(
+        self.m_curve_2_arrays = self.m_avida_stats_interface.load(
+            str(self.m_petri_dish_dir_path),
             self.m_avida_stats_interface.m_entries[index_2][1],
             1,
             self.m_avida_stats_interface.m_entries[index_2][2]
@@ -181,7 +165,7 @@
 
     self.m_graph_ctrl.replot()
       
-  def printGraphSlot(self):
+  def printSlot(self):
     printer = QPrinter()
     if printer.setup():
       filter = PrintFilter()
@@ -191,54 +175,9 @@
 
   def exportSlot(self):
     "Export analysis data to a file"
-    dialog_caption = "Export Analysis"
-    fd = QFileDialog.getSaveFileName("", "CSV (Excel compatible) (*.csv)", None,
-                                     "export as", dialog_caption)
-    filename = str(fd)
-    if (filename[-4:].lower() != ".csv"):
-      filename += ".csv"
-
-    checks = []
-    # dictionary indexed by stat name so we can lookup stats to export
-    stats = {}
-    stat_cnt = 0
-    for stat in self.m_avida_stats_interface.m_entries:
-      # Note: this relies on labeling dummy stats with None
-      if stat[0] != "None":
-        stats[stat[0]] = stat_cnt
-        checks.append(stat[0])
-      stat_cnt += 1
-
-    dialog = pyButtonListDialog(dialog_caption, "Choose stats to export",
-                                checks, True)
-    # enable checkboxes
-    for button in dialog.buttons:
-      button.setOn(True)
-
-    res = dialog.showDialog()
-    if res == []:
-      return
-
-    data = {}
     if self.m_combo_box_1.currentItem():
-      # Load stats for selected exports
-      # TODO: more efficient loading
-      for item in res:
-        idx = stats[item]
-        label1 = self.m_avida_stats_interface.m_entries[idx][0]
-        data[item] = self.load(self.m_avida_stats_interface.m_entries[idx][1],
-                               1,
-                               self.m_avida_stats_interface.m_entries[idx][2])
+      self.m_avida_stats_interface.export(str(self.m_petri_dish_dir_path))
 
-      out_file = open(filename, 'w')
-      out_file.write("Update,%s\n" % (",".join(res)))
-      # TODO: get it working with zip
-      #print zip([data[elem][1][i] for elem in res])        
-      num_updates = len(data[res[0]][0])
-      for i in range(num_updates):
-        out_file.write("%d,%s\n"
-                       % (i, ",".join([str(data[elem][1][i]) for elem in res])))
-      out_file.close()
 
   def petriDropped(self, e): 
       # a check in pyOneAnalyzeCtrl.py makes sure this is a valid path

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py	2006-06-06 18:43:10 UTC (rev 736)
@@ -31,28 +31,28 @@
       self.freezerItemDoubleClicked)
 
   def aboutToBeLowered(self):
-    """Disconnects "Print Graph..." menu item from One-Analyze Graph controller."""
+    """Disconnects menu items from One-Analyze Graph controller."""
     descr()
     self.disconnect(
       self.m_session_mdl.m_session_mdtr,
-      PYSIGNAL("printGraphSig"),
-      self.m_one_ana_graph_ctrl.printGraphSlot)
+      PYSIGNAL("printSig"),
+      self.m_one_ana_graph_ctrl.printSlot)
     # Disconnect export signal
     self.disconnect(
       self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("exportAnalyzeSig"),
       self.m_one_ana_graph_ctrl.exportSlot)
   def aboutToBeRaised(self):
-    """Connects "Print Graph..." menu item to One-Analyze Graph controller."""
+    """Connects items to One-Analyze Graph controller."""
     descr()
     self.connect(
       self.m_session_mdl.m_session_mdtr,
-      PYSIGNAL("printGraphSig"),
-      self.m_one_ana_graph_ctrl.printGraphSlot)
+      PYSIGNAL("printSig"),
+      self.m_one_ana_graph_ctrl.printSlot)
     # Connect export
     self.connect(self.m_session_mdl.m_session_mdtr,
-                 PYSIGNAL("exportAnalyzeSig"),
-                 self.m_one_ana_graph_ctrl.exportSlot)
+      PYSIGNAL("exportAnalyzeSig"),
+      self.m_one_ana_graph_ctrl.exportSlot)
 
   def dragEnterEvent( self, e ):
     descr(e)

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_GraphCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_GraphCtrl.py	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_GraphCtrl.py	2006-06-06 18:43:10 UTC (rev 736)
@@ -1,6 +1,5 @@
 # -*- coding: utf-8 -*-
 
-from AvidaCore import cInitFile, cString
 from Numeric import *
 from pyAvidaStatsInterface import pyAvidaStatsInterface
 from pyOnePop_GraphView import pyOnePop_GraphView
@@ -40,7 +39,7 @@
     self.m_combo_box.setCurrentItem(2)
     self.modeActivatedSlot(self.m_combo_box.currentItem())
 
-  def load(self, filename, colx, coly):
+  def load(self, path, filename, colx, coly):
     print "pyOnePop_GraphCtrl.load file name = " + filename
     if (self.m_avida is None) or (self.m_avida.m_population.GetStats().GetUpdate() == 0):
       print " m_avida is None, or update is zero. Not loading from file."
@@ -48,25 +47,18 @@
       self.m_y_array = zeros(1, Float)
     else:
       print " loading from file."
-      init_file = cInitFile(cString(filename))
-      init_file.Load()
-      init_file.Compress()
+      self.m_x_array, self.m_y_array = self.m_avida_stats_interface.load(
+        path,
+        filename, colx, coly)
 
-      self.m_x_array = zeros(init_file.GetNumLines(), Float)
-      self.m_y_array = zeros(init_file.GetNumLines(), Float)
-
-      for line_id in range(init_file.GetNumLines()):
-        line = init_file.GetLine(line_id)
-        self.m_x_array[line_id] = line.GetWord(colx - 1).AsDouble()
-        self.m_y_array[line_id] = line.GetWord(coly - 1).AsDouble()
-
   def modeActivatedSlot(self, index):
 #    self.m_graph_ctrl.setTitle(self.m_avida_stats_interface.m_entries[index][0])
     self.m_graph_title.setText(self.m_avida_stats_interface.m_entries[index][0])
     self.m_graph_ctrl.clear()
     if index:
       self.load(
-        os.path.join(self.m_session_mdl.m_tempdir_out, self.m_avida_stats_interface.m_entries[index][1]),
+        self.m_session_mdl.m_tempdir_out,
+        self.m_avida_stats_interface.m_entries[index][1],
         1,
         self.m_avida_stats_interface.m_entries[index][2]
       )
@@ -147,3 +139,7 @@
     self.m_combo_box.setCurrentItem(2)
     self.modeActivatedSlot(self.m_combo_box.currentItem())
 
+  def exportSlot(self):
+    "Export stats to a file"
+    if self.m_combo_box.currentItem():    
+      self.m_avida_stats_interface.export(self.m_session_mdl.m_tempdir_out)

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py	2006-06-06 18:43:10 UTC (rev 736)
@@ -39,31 +39,47 @@
     descr()
     self.disconnect(
       self.m_session_mdl.m_session_mdtr,
-      PYSIGNAL("printGraphSig"),
-      self.m_one_pop_graph_ctrl.printGraphSlot)
+      PYSIGNAL("printSig"),
+      self.printSlot)
     self.disconnect(
       self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("printPetriDishSig"),
       self.m_one_pop_petri_dish_ctrl.printPetriDishSlot)
     self.disconnect(
       self.m_session_mdl.m_session_mdtr,
+      PYSIGNAL("printGraphSig"),
+      self.m_one_pop_graph_ctrl.printGraphSlot)
+    self.disconnect(
+      self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("saveImagesSig"),
       self.saveImagesSlot)
+    self.disconnect(
+      self.m_session_mdl.m_session_mdtr,
+      PYSIGNAL("exportAnalyzeSig"),
+      self.m_one_pop_graph_ctrl.exportSlot)
   def aboutToBeRaised(self):
     """Connects menu items to One-Pop Graph controller."""
     descr()
     self.connect(
       self.m_session_mdl.m_session_mdtr,
-      PYSIGNAL("printGraphSig"),
-      self.m_one_pop_graph_ctrl.printGraphSlot)
+      PYSIGNAL("printSig"),
+      self.printSlot)
     self.connect(
       self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("printPetriDishSig"),
       self.m_one_pop_petri_dish_ctrl.printPetriDishSlot)
     self.connect(
       self.m_session_mdl.m_session_mdtr,
+      PYSIGNAL("printGraphSig"),
+      self.m_one_pop_graph_ctrl.printGraphSlot)    
+    self.connect(
+      self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("saveImagesSig"),
       self.saveImagesSlot)
+    self.connect(
+      self.m_session_mdl.m_session_mdtr,
+      PYSIGNAL("exportAnalyzeSig"),
+      self.m_one_pop_graph_ctrl.exportSlot)
 
   def dragEnterEvent( self, e ):
     descr(e)
@@ -139,3 +155,13 @@
                              self.m_one_pop_graph_ctrl.m_graph_ctrl.width(),
                              self.m_one_pop_graph_ctrl.m_graph_ctrl.height())
       p.save(filename, type, 100)
+
+  def printSlot(self):
+    "Let user choose what object to print and send signal to appropriate slot"
+    dlg = pyButtonListDialog("Print", "Choose object to print",
+                             ["Petri Dish", "Graph"])
+    res = dlg.showDialog()
+    if res[0] == "Petri Dish":
+      self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("printPetriDishSig"), ())
+    elif res[0] == "Graph":
+      self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("printGraphSig"), ())

Modified: branches/developers/avida-edward/source/python/AvidaGui2/to-do_list
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/to-do_list	2006-06-06 14:40:19 UTC (rev 735)
+++ branches/developers/avida-edward/source/python/AvidaGui2/to-do_list	2006-06-06 18:43:10 UTC (rev 736)
@@ -87,13 +87,9 @@
 
 ************Josh*******************
 
-29-Apr-06 Export Excel style (tab delimited) files
-  - Change .csv to .txt extension
-  - Allow exporting in Petri Dish view
+06-Jun-06 Change .csv to .txt extension in export dialog
 
-30-May-06 Printing of petri dish and of color scale
-  - Fill out save dialog with default filename that includes update and other
-    info
+30-May-06 Fill out save image dialog with default filename that includes update and other info
 
 ************Other*****************
 a.	Under the sliders with ranges put a few values in grey that tell you the range min and max (non)
@@ -150,3 +146,5 @@
 ************Josh*******************
 
 16-Jan-06 Get Windows version working -- Finished 21-Feb-06
+29-Apr-06 Export Excel style (comma delimited) files -- Finished 06-Jun-06
+30-May-06 Printing of petri dish and of color scale -- Finished 06-Jun-06




More information about the Avida-cvs mailing list