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

jclune@myxo.css.msu.edu jclune at myxo.css.msu.edu
Fri Jul 1 11:55:25 PDT 2005


Author: jclune
Date: 2005-07-01 14:55:25 -0400 (Fri, 01 Jul 2005)
New Revision: 221

Modified:
   trunk/source/python/AvidaGui2/pyFreezerCtrl.py
   trunk/source/python/AvidaGui2/pyFreezerView.ui
   trunk/source/python/AvidaGui2/pyOnePop_StatsCtrl.py
   trunk/source/python/AvidaGui2/pyOnePopulationCtrl.py
   trunk/source/python/AvidaGui2/pyPetriCanvasView.py
   trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
   trunk/source/python/AvidaGui2/pyPopulationCellItem.py
   trunk/source/python/AvidaGui2/pyTemporaryReloads.py
   trunk/source/python/AvidaGui2/pyWriteToFreezer.py
Log:
You can now drag organisms from the petri dish into the freezer. 

Also cleaned up some of the pyWriteToFreezer code.


Modified: trunk/source/python/AvidaGui2/pyFreezerCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyFreezerCtrl.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyFreezerCtrl.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -4,6 +4,8 @@
 from qt import *
 from pyFreezerView import pyFreezerView
 from pyReadFreezer import pyReadFreezer
+from pyWriteToFreezer import pyWriteToFreezer
+from pyFreezeOrganismCtrl import pyFreezeOrganismCtrl
 import os.path
 
 class pyFreezerCtrl(pyFreezerView):
@@ -20,7 +22,6 @@
     self.connect(self.m_list_view, 
       SIGNAL("pressed(QListViewItem*, const QPoint &, int )"),
       self.pressed_itemSlot)
-    self.setAcceptDrops(1)
 
   def construct(self, session_mdl):
     self.m_session_mdl = session_mdl
@@ -121,15 +122,56 @@
   class itemDrag(QTextDrag):
     def __init__(self, item_name, parent=None, name=None):
         QStoredDrag.__init__(self, 'item name (QString)', parent, name)
+        print "setting up itemDrag, my parent is"
+        print parent
         self.setText(item_name)
 
-  def dropEvent( self, e ):
+  def dropEvent( self, e):
     freezer_item_name = QString()
     print "dropEvent in freezer"
+    if e.source() is self:
+      return
     if ( QTextDrag.decode( e, freezer_item_name ) ) : #freezer_item_name is a string...the file name 
-      if os.path.exists(str(freezer_item_name)) == False:
-        print "that was not a valid path (1)" 
-      else: 
-        self.emit(PYSIGNAL("petriDishDroppedInPopViewSig"), (e,))
+      print freezer_item_name
+      if freezer_item_name[:9] == 'organism.':
+        freezer_item_name = freezer_item_name[9:] 
+        self.FreezeOrganismSlot(freezer_item_name)
+      else:
+        print "that was not an organism"      
+    
+  def FreezeOrganismSlot(self, freezer_item_name, 
+      send_reset_signal = False, send_quit_signal = False):
+    print "freezer_item_name"
+    print freezer_item_name
+    tmp_dict = {1:freezer_item_name}
+#    tmp_dict["SETTINGS"] = self.Form2Dictio`nary()
+    m_pop_up_organism_file_name = pyFreezeOrganismCtrl()
+    file_name = m_pop_up_organism_file_name.showDialog(self.m_session_mdl.m_current_freezer)
+    print "printing file name"
+    print file_name
+    # If the user is saving a full population expand the name and insert
+    # the population dictionary into the temporary dictionary
 
+#    if (m_pop_up_freezer_file_name.isEmpty() == False):
+#      os.mkdir(file_name)
 
+      # Copy the average and count files from the teporary output directory
+      # to the Freezer directory
+        
+#      shutil.copyfile(os.path.join(self.m_session_mdl.m_tempdir_out, "average.dat"), os.path.join(file_name, "average.dat"))
+#      shutil.copyfile(os.path.join(self.m_session_mdl.m_tempdir_out, "count.dat"), os.path.join(file_name, "count.dat"))
+#      file_name = os.path.join(file_name, "petri_dish")
+#      tmp_dict["POPULATION"] = population_dict
+
+    freezer_file = pyWriteToFreezer(tmp_dict, file_name)
+    
+    self.m_session_mdl.m_session_mdtr.emit(
+      PYSIGNAL("doRefreshFreezerInventorySig"), ())
+#    if send_reset_signal:
+#      print "sending reset signal from pyPetriConfigureCtrl:FreezePetriSlot" 
+#    if send_quit_signal:
+#      print "sending quit signal from pyPetriConfigureCtrl:FreezePetriSlot"
+#      self.m_session_mdl.m_session_mdtr.emit(
+#        PYSIGNAL("quitAvidaPhaseIISig"), ())
+
+

Modified: trunk/source/python/AvidaGui2/pyFreezerView.ui
===================================================================
--- trunk/source/python/AvidaGui2/pyFreezerView.ui	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyFreezerView.ui	2005-07-01 18:55:25 UTC (rev 221)
@@ -83,7 +83,7 @@
                 </font>
             </property>
             <property name="acceptDrops">
-                <bool>true</bool>
+                <bool>false</bool>
             </property>
             <property name="frameShape">
                 <enum>StyledPanel</enum>

Modified: trunk/source/python/AvidaGui2/pyOnePop_StatsCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyOnePop_StatsCtrl.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyOnePop_StatsCtrl.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -167,11 +167,8 @@
     self.m_clicked_cell_item = clicked_cell_item
     if clicked_cell_item:
       clicked_cell_num = clicked_cell_item.m_population_cell.GetID()
-#the_item.brush().color()
-#the_item.m_population_cell.GetID()
     if clicked_cell_item:
       self.m_clicked_cell_number = clicked_cell_num
-#    if clicked_cell_num is None or not self.m_avida.m_population.GetCell(int(clicked_cell_num)).IsOccupied():
     if clicked_cell_item is None or not self.m_avida.m_population.GetCell(int(clicked_cell_num)).IsOccupied():
       #PAINT the stats fields empty
       self.m_org_name.setText('empty cell')
@@ -202,6 +199,11 @@
     organism = clicked_cell.GetOrganism()
     phenotype = organism.GetPhenotype()
     genotype = organism.GetGenotype()
+ 
+    # tee up drag information
+#    dragHolder = self.itemDrag( file_name, self )
+#    dragHolder = self.itemDrag( str(genotype.GetName()), self )
+#    dragHolder.dragCopy()
 
     # print info about the org clicked on 
 
@@ -346,3 +348,7 @@
       self.loadStats(freezer_item_dir)
     else:
       return
+
+
+
+

Modified: trunk/source/python/AvidaGui2/pyOnePopulationCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyOnePopulationCtrl.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyOnePopulationCtrl.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -25,7 +25,7 @@
 
   def dropEvent( self, e ):
     freezer_item_name = QString()
-    print "dropEvent"
+    print "dropEvent in one population"
     if ( QTextDrag.decode( e, freezer_item_name ) ) : #freezer_item_name is a string...the file name 
       if os.path.exists(str(freezer_item_name)) == False:
         print "that was not a valid path (1)" 

Modified: trunk/source/python/AvidaGui2/pyPetriCanvasView.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriCanvasView.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyPetriCanvasView.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -1,4 +1,4 @@
-
+from qt import QTextDrag
 from qt import Qt, PYSIGNAL
 from qtcanvas import QCanvasView
 
@@ -18,5 +18,5 @@
           org_clicked_on__color = item.brush().color()
           org_clicked_on_item = item
       self.emit(PYSIGNAL("orgClickedOnSig"), (org_clicked_on_item,))
-      if org_clicked_on_item:
-        self.emit(PYSIGNAL("orgClickedOnSig"), (org_clicked_on_item,))
+
+   

Modified: trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriDishCtrl.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyPetriDishCtrl.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -8,9 +8,10 @@
 """
 
 from AvidaCore import cConfig
+from AvidaCore import cInitFile, cString
 
 from math import exp
-from qt import PYSIGNAL, QBrush, QColor, QLayout, QPen, QSize, Qt, QVBoxLayout, QWidget, QWMatrix
+from qt import PYSIGNAL, QBrush, QColor, QLayout, QPen, QSize, Qt, QVBoxLayout, QWidget, QWMatrix, QTextDrag, QStoredDrag
 from qtcanvas import QCanvas, QCanvasRectangle
 from pyPetriCanvasView import pyPetriCanvasView
 from pyPopulationCellItem import pyPopulationCellItem
@@ -51,7 +52,6 @@
     self.m_org_clicked_on_item = None
     self.m_occupied_cells_ids = []
 
-#    self.m_target_dish_width = 270
     self.m_target_dish_width = 350
     self.m_target_dish_scaling = 5.
     self.m_map_cell_width = 5
@@ -60,9 +60,10 @@
     self.connect( self.m_canvas_view, PYSIGNAL("orgClickedOnSig"), self.m_session_mdl.m_session_mdtr, PYSIGNAL("orgClickedOnSig"))
     self.connect( self.m_session_mdl.m_session_mdtr, PYSIGNAL("orgClickedOnSig"),
       self.updateOrgClickedOutlineCellNumberSlot)
+    self.connect( self.m_session_mdl.m_session_mdtr, PYSIGNAL("orgClickedOnSig"),
+      self.setDragSlot)
 
 
-
   def setColorLookupFunctor(self, color_lookup_functor):
     self.m_color_lookup_functor = color_lookup_functor
 
@@ -121,6 +122,20 @@
     self.m_changed_cell_items = self.m_cell_info[:]
     self.updateCellItems(True)
 
+  def setDragSlot(self, org_clicked_on_item):
+    print "here"
+    if org_clicked_on_item:
+      clicked_cell_num = org_clicked_on_item.m_population_cell.GetID()
+      clicked_cell = self.m_avida.m_population.GetCell(int(clicked_cell_num))
+      organism = clicked_cell.GetOrganism()
+
+      # tee up drag information
+      dragHolder = self.itemDrag( ('organism.' + str(organism.GetGenome().AsString())), self )
+      dragHolder.dragCopy()
+
+
+
+
   def setRange(self, min, max):
     self.m_cs_min_value = min
     self.m_cs_value_range = max - min
@@ -143,11 +158,9 @@
     self.m_indexer(cell_info_item, self.m_cs_min_value, self.m_cs_value_range)
     cell_info_item.updateColorUsingFunctor(self.m_color_lookup_functor)
 
-#JMC
     if self.m_org_clicked_on_item:
       if cell_info_item.m_population_cell.GetID == self.m_org_clicked_on_item.m_population_cell.GetID:
         cell_info_item.setPen(QPen(QColor(0,255,0)))      
-#JMC
 
   def updateCellItems(self, should_update_all = False):
     if self.m_cell_info:
@@ -197,3 +210,7 @@
         m.translate(trans_h/(zoom_factor/self.m_target_dish_scaling),trans_h/(zoom_factor/self.m_target_dish_scaling))    
       self.m_canvas_view.setWorldMatrix(m)
  
+  class itemDrag(QTextDrag):
+    def __init__(self, item_name, parent=None, name=None):
+        QStoredDrag.__init__(self, 'item name (QString)', parent, name)
+        self.setText(item_name)

Modified: trunk/source/python/AvidaGui2/pyPopulationCellItem.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPopulationCellItem.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyPopulationCellItem.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -11,8 +11,6 @@
     return 271828
 
   def __init__(self, population_cell, x, y, w, h, canvas):
- #   x = x + 5
- #   y = y + 5
     QCanvasRectangle.__init__(self, x, y, w, h, canvas)
     self.m_population_cell = population_cell
     self.m_index = 0

Modified: trunk/source/python/AvidaGui2/pyTemporaryReloads.py
===================================================================
--- trunk/source/python/AvidaGui2/pyTemporaryReloads.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyTemporaryReloads.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -46,6 +46,8 @@
   "AvidaGui2.pyAvidaStatsInterface",
   "AvidaGui2.pyFreezeDialogView",
   "AvidaGui2.pyFreezeDialogCtrl",
+  "AvidaGui2.pyFreezeOrganismView",
+  "AvidaGui2.pyFreezeOrganismCtrl",
   "AvidaGui2.pyFreezerView",
   "AvidaGui2.pyFreezerCtrl",
   "AvidaGui2.pyGradientScaleView",

Modified: trunk/source/python/AvidaGui2/pyWriteToFreezer.py
===================================================================
--- trunk/source/python/AvidaGui2/pyWriteToFreezer.py	2005-06-23 19:25:18 UTC (rev 220)
+++ trunk/source/python/AvidaGui2/pyWriteToFreezer.py	2005-07-01 18:55:25 UTC (rev 221)
@@ -1,25 +1,60 @@
 # -*- coding: utf-8 -*-
 
 import string
-import qt
+from qt import *
+import os
 
 class pyWriteToFreezer:
 
-  def __init__(self, in_dict = None, empty_dish = True, out_file_name = None):
+  def __init__(self, in_dict = None, out_file_name = None):
+
+    is_org = False
+    is_dish = False
+    is_empty_dish = False
+
+    if out_file_name.endswith("petri_dish"):
+      out_file_name = (os.path.split(out_file_name)[0])
+
+    if out_file_name.endswith(".organism"):
+      print "that was an org"
+      is_org = True
+
+    elif out_file_name.endswith(".full"):
+      print "that was a full dish man"
+      is_dish = True
+      self.simplifyPopulation(in_dict)
+      out_file_name = (out_file_name + '/petri_dish')
+
+    elif out_file_name.endswith(".empty"):
+      print "that was an empty dish man"
+      is_dish = True
+      is_empty_dish = True
+
+    else:
+      print "that was junk man"
+
+    out_freezer_file = open((out_file_name), "w")
+
   
-    if empty_dish == False:
-      self.simplifyPopulation(in_dict)
-    out_freezer_file = open(out_file_name, "w")
-    for section in in_dict.keys():
+    if is_org == True:
+      print "writing org"
+      genome = str(in_dict[1])
+      out_freezer_file.write(genome + "\n")
+    elif is_dish == True:
+
+      for section in in_dict.keys():
     
-      # Always print out the petri dishes settings and if it is a full dish
-      # print out the cell and organism information
+        # Always print out the petri dishes settings and if it is a full dish
+        # print out the cell and organism information
       
-      if ((section == "SETTINGS") or (empty_dish == False)):
-        out_freezer_file.write("*" + section + "\n")
-        info_dict = in_dict[section]
-        for info_key in info_dict.keys():
-          out_freezer_file.write(str(info_key) + " " + str(info_dict[info_key]) + "\n")
+        if ((section == "SETTINGS") or (is_empty_dish == False)):
+          out_freezer_file.write("*" + section + "\n")
+          info_dict = in_dict[section]
+          for info_key in info_dict.keys():
+            out_freezer_file.write(str(info_key) + " " + str(info_dict[info_key]) + "\n")
+    else: 
+      print "something is wrong, that was not an org or a dish"
+
     out_freezer_file.close()
     
   def simplifyPopulation(self, in_dict = None):




More information about the Avida-cvs mailing list