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

kaben at myxo.css.msu.edu kaben at myxo.css.msu.edu
Wed Apr 6 10:23:42 PDT 2005


Author: kaben
Date: 2005-04-06 13:23:42 -0400 (Wed, 06 Apr 2005)
New Revision: 110

Modified:
   trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
   trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
Log:

* Added map modes, gradient scale, zooming to petri dish.



Modified: trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py	2005-04-06 17:22:15 UTC (rev 109)
+++ trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py	2005-04-06 17:23:42 UTC (rev 110)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from qt import *
+from pyMapProfile import pyMapProfile
 from pyOnePop_PetriDishView import pyOnePop_PetriDishView
 
 
@@ -8,8 +9,6 @@
 
   def __init__(self,parent = None,name = None,fl = 0):
     pyOnePop_PetriDishView.__init__(self,parent,name,fl)
-    self.connect(self.m_petri_dish_toggle, SIGNAL("clicked()"), 
-      self.ToggleDishSlot)
 
   def construct(self, session_mdl):
     self.m_session_mdl = session_mdl
@@ -24,11 +23,30 @@
       self.m_petri_configure_ctrl.FreezePetriSlot)
     self.connect(self.m_session_mdl.m_session_mdtr, PYSIGNAL("setAvidaSig"),
       self.setAvidaSlot)
+    self.connect(self.m_petri_dish_toggle, SIGNAL("clicked()"), 
+      self.ToggleDishSlot)
     self.connect(self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("doDefrostDishSig"), self.RenameDishSlot)
     self.connect(self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("doDefrostDishSig"), self.MakeConfigVisiableSlot)
 
+    self.connect(self.m_zoom_spinbox, SIGNAL("valueChanged(int)"),
+      self.m_petri_dish_ctrl.zoomSlot)
+    self.connect(self.m_petri_dish_ctrl, PYSIGNAL("zoomSig"),
+      self.m_zoom_spinbox.setValue)
+
+    self.m_map_profile = pyMapProfile()
+    self.m_mode_combobox.clear()
+    self.m_mode_combobox.setInsertionPolicy(QComboBox.AtBottom)
+    for i in range(self.m_map_profile.getSize()):
+      self.m_mode_combobox.insertItem(self.m_map_profile.getModeName(i))
+    self.connect(self.m_mode_combobox, SIGNAL("activated(int)"), self.modeActivatedSlot)
+    self.m_mode_combobox.setCurrentItem(1)
+    self.m_mode_index = self.m_mode_combobox.currentItem()
+    self.modeActivatedSlot(self.m_mode_index)
+
+    self.m_petri_dish_ctrl.emit(PYSIGNAL("zoomSig"), (9,))
+
   def setAvidaSlot(self, avida):
     old_avida = self.m_avida
     self.m_avida = avida
@@ -42,6 +60,8 @@
         self.m_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
         self.avidaUpdatedSlot)
 
+    if self.m_avida:
+      self.m_map_profile.getUpdater(self.m_mode_combobox.currentItem()).resetRange(self.m_avida.m_population)
 
 
   def ToggleDishSlot (self):
@@ -58,12 +78,43 @@
     if (current_page_int == 0):
        self.m_petri_dish_widget_stack.raiseWidget(1)
 
+  def modeActivatedSlot(self, index):
+    #print "pyOnePop_PetriDishCtrl.modeActivatedSlot index", index
+    if self.m_avida:
+      self.m_avida.m_avida_threaded_driver.m_lock.acquire()
+    self.m_mode_index = index
+    updater = self.m_map_profile.getUpdater(self.m_mode_index)
+    updater and updater.reset(True)
+    #(min, max) = updater and updater.resetRange(self.m_avida and self.m_avida.m_population or None) or (0.0, 0.0)
+    #self.m_gradient_scale_ctrl.setRange(min, max)
+    #self.m_gradient_scale_ctrl.activate(True)
+    #self.m_petri_dish_ctrl.setRange(min, max)
+    self.m_petri_dish_ctrl.setIndexer(self.m_map_profile.getIndexer(self.m_mode_index))
+    #self.m_petri_dish_ctrl.updateCellItems()
+    #self.avidaUpdatedSlot()
+    if self.m_avida:
+      self.m_avida.m_avida_threaded_driver.m_lock.release()
+
   def avidaUpdatedSlot (self):
-    stats = self.m_avida.m_population.GetStats()
-    update = stats.GetUpdate()
-    self.m_update_label.setText(QString("%1").arg(update))
+    updater = self.m_map_profile.getUpdater(self.m_mode_index)
+    if updater:
+      (old_min, old_max) = updater.getRange()
+      (min, max) = self.m_avida and updater.updateRange(self.m_avida.m_population) or (0, 0)
+      if updater.shouldReset() or ((old_min, old_max) != (min, max)):
+        self.m_gradient_scale_ctrl.setRange(min, max)
+        self.m_gradient_scale_ctrl.activate(True)
+        self.m_petri_dish_ctrl.setRange(min, max)
+        updater.reset(False)
+    else:
+      self.m_gradient_scale_ctrl.setRange(0, 0)
+      self.m_gradient_scale_ctrl.activate(True)
+      self.m_petri_dish_ctrl.setRange(0, 0)
+    self.m_petri_dish_ctrl.updateCellItems()
+
+    stats = update = None
+    if self.m_avida: stats = self.m_avida.m_population.GetStats()
+    if stats: update = stats.GetUpdate()
+    if update: self.m_update_label.setText(QString("%1").arg(update))
     
   def RenameDishSlot(self, dishName):
     self.PopulationTextLabel.setText(dishName)
-
-

Modified: trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriDishCtrl.py	2005-04-06 17:22:15 UTC (rev 109)
+++ trunk/source/python/AvidaGui2/pyPetriDishCtrl.py	2005-04-06 17:23:42 UTC (rev 110)
@@ -81,18 +81,20 @@
     old_avida = self.m_avida
     self.m_avida = avida
     if(old_avida):
-      self.disconnect(
-        old_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
-        self.avidaUpdatedSlot)
+      #self.disconnect(
+      #  old_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
+      #  self.avidaUpdatedSlot)
       old_avida.removeGuiWorkFunctor(self)
       del old_avida
+      pass
     if(self.m_avida):
-      self.connect(
-        self.m_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
-        self.avidaUpdatedSlot)
+      #self.connect(
+      #  self.m_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
+      #  self.avidaUpdatedSlot)
+      pass
 
-    self.m_map_cell_w = 10
-    self.m_map_cell_h = 10
+    self.m_map_cell_w = 5
+    self.m_map_cell_h = 5
     world_w = cConfig.GetWorldX()
     world_h = cConfig.GetWorldY()
 
@@ -186,11 +188,17 @@
     self.m_petri_dish_layout.setResizeMode(QLayout.Minimum)
     self.m_canvas_view = QCanvasView(None, self,"m_canvas_view")
     self.m_petri_dish_layout.addWidget(self.m_canvas_view)
+    self.m_changed_cell_items = []
+    self.m_indexer = None
 
   def calcColorScale(self):
     self.m_cs_min_value = 0
     self.m_cs_value_range = self.m_avida.m_population.GetStats().GetMaxFitness()
 
+  def setRange(self, min, max):
+    self.m_cs_min_value = min
+    self.m_cs_value_range = max - min
+
   def doubleToColor(self, x):
     def sigmoid(w, midpoint, steepness):
       val = steepness*(w-midpoint)
@@ -216,28 +224,74 @@
       state = self.doubleToColor(dbl)
     return state
 
+  def setIndexer(self, indexer):
+    print "pyPetriDishCtrl.setIndexer"
+    self.m_indexer = indexer
+
+    if self.m_cell_info:
+      def temp_color_functor(index):
+        return QColor(0, 0, 0)
+      for cell_info_item in self.m_cell_info:
+        cell_info_item.updateColorUsingFunctor(temp_color_functor)
+      self.m_canvas.update()
+      self.m_changed_cell_items = self.m_cell_info[:]
+
+
+  #def doSomeWork(self, avida):
+  #  def temp_normalized_index_functor(population_cell):
+  #    #dbl = 0.0
+  #    #if population_cell.IsOccupied():
+  #    #  dbl = population_cell.GetOrganism().GetPhenotype().GetFitness()
+  #    #return dbl
+  #    return population_cell.IsOccupied() and population_cell.GetOrganism().GetPhenotype().GetFitness() or 0.0
+
+  #  for x in range(3600):
+  #    if len(self.m_cell_info) <= self.m_thread_work_cell_item_index:
+  #      self.m_thread_work_cell_item_index = 0
+  #      return False
+  #    else:
+  #      cell_info_item = self.m_cell_info[self.m_thread_work_cell_item_index]
+  #      if cell_info_item.checkNormalizedIndexUsingFunctor(
+  #        temp_normalized_index_functor,
+  #        self.m_cs_min_value,
+  #        self.m_cs_value_range
+  #      ):
+  #        self.m_changed_cell_items.append(cell_info_item)
+  #      self.m_thread_work_cell_item_index += 1
+  #  return True
+
   def doSomeWork(self, avida):
     def temp_normalized_index_functor(population_cell):
-      dbl = 0.0
-      if population_cell.IsOccupied():
-        dbl = population_cell.GetOrganism().GetPhenotype().GetFitness()
-      return dbl
+      return population_cell.IsOccupied() and population_cell.GetOrganism().GetPhenotype().GetFitness() or 0.0
 
-    for x in range(3600):
-      if len(self.m_cell_info) <= self.m_thread_work_cell_item_index:
-        self.m_thread_work_cell_item_index = 0
-        return False
-      else:
-        cell_info_item = self.m_cell_info[self.m_thread_work_cell_item_index]
-        if cell_info_item.checkNormalizedIndexUsingFunctor(
-          temp_normalized_index_functor,
-          self.m_cs_min_value,
-          self.m_cs_value_range
-        ):
-          self.m_changed_cell_items.append(cell_info_item)
-        self.m_thread_work_cell_item_index += 1
-    return True
+    if self.m_indexer:
+      for x in range(len(self.m_cell_info)):
+        if len(self.m_cell_info) <= self.m_thread_work_cell_item_index:
+          self.m_thread_work_cell_item_index = 0
+          return False
+        else:
+          cell_info_item = self.m_cell_info[self.m_thread_work_cell_item_index]
+          if self.m_indexer(cell_info_item, self.m_cs_min_value, self.m_cs_value_range):
+            self.m_changed_cell_items.append(cell_info_item)
+          self.m_thread_work_cell_item_index += 1
+      return True
+    else:
+      return False
 
+  def updateCellItems(self):
+    def temp_color_functor(index):
+      def sigmoid(w, midpoint, steepness):
+        val = steepness*(w-midpoint)
+        return exp(val)/(1+exp(val))     
+      h = (index*360.0 + 100.0) % 360.0
+      v = sigmoid(index, 0.3, 10.0) * 255.0
+      s = sigmoid(1.0 - index, 0.1, 30.0) * 255.0
+      return QColor(h, s, v, QColor.Hsv)
+      
+    for cell_info_item in self.m_changed_cell_items:
+      cell_info_item.updateColorUsingFunctor(temp_color_functor)
+    self.m_changed_cell_items = []
+    if self.m_canvas: self.m_canvas.update()
 
   def avidaUpdatedSlot(self):
     def temp_color_functor(index):
@@ -268,3 +322,11 @@
             genome = organism.GetGenome()
             population_dict[cell.GetID()] = str(genome.AsString())
     self.emit(PYSIGNAL("freezeDishPhaseIISig"), ("/freezer", population_dict, ))
+
+  def zoomSlot(self, zoom_factor):
+    #print "pyPetriDishCtrl.zoomSlot zoom_factor", zoom_factor
+    if self.m_canvas_view:
+      m = QWMatrix()
+      m.scale(zoom_factor/5.0, zoom_factor/5.0)
+      self.m_canvas_view.setWorldMatrix(m)
+




More information about the Avida-cvs mailing list