[Avida-cvs] [Avida2-svn] r126 - trunk/source/python/AvidaGui2
kaben at myxo.css.msu.edu
kaben at myxo.css.msu.edu
Thu Apr 7 13:38:09 PDT 2005
Author: kaben
Date: 2005-04-07 16:38:08 -0400 (Thu, 07 Apr 2005)
New Revision: 126
Modified:
trunk/source/python/AvidaGui2/pyGradientScaleView.py
trunk/source/python/AvidaGui2/pyMapProfile.py
trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py
trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
trunk/source/python/AvidaGui2/pyPopulationCellItem.py
Log:
* Changes to gradient scale:
- made description text use a smaller font
- used fixed width for text area
- chopped-off the last tenth of the color scale (it was
indistinguishable from empty cells)
Modified: trunk/source/python/AvidaGui2/pyGradientScaleView.py
===================================================================
--- trunk/source/python/AvidaGui2/pyGradientScaleView.py 2005-04-07 20:16:21 UTC (rev 125)
+++ trunk/source/python/AvidaGui2/pyGradientScaleView.py 2005-04-07 20:38:08 UTC (rev 126)
@@ -12,12 +12,12 @@
from math import exp
class pyGradientScaleView(QWidget):
- s_left_margin = 10
- s_top_margin = 10
- s_bottom_margin = 10
- s_right_margin = 10
- s_spacing = 10
- s_stripe_width = 40
+ s_left_margin = 6
+ s_top_margin = 6
+ s_bottom_margin = 6
+ s_right_margin = 6
+ s_spacing = 6
+ s_stripe_width = 20
s_stripes = 100
s_step = 10
@@ -27,35 +27,32 @@
self.m_min_value = 0.0
self.m_max_value = 0.0
self.m_color_vector = []
- self.m_desc_vector = []
+ self.m_descr_vector = []
self.m_continuous = False
self.m_activated = False
self.m_was_activated = False
+ self.m_color_lookup = None
self.recalcSize()
+ font = QFont(self.font())
+ font.setPointSize(10)
+ self.setFont(font)
+
if not name:
setName("pyGradientScaleView")
- def sigmoid(self, x, midpoint, steepness):
- val = steepness*(x-midpoint)
- return exp(val)/(1+exp(val))
+ def doubleToColor(self, x): return self.m_color_lookup and self.m_color_lookup(x) or QColor(Qt.black)
- def doubleToColor(self, x):
- if 1 < x: x = 1
- elif x < 0: x = 0
-
- h = (x*360 + 100) % 360
- v = self.sigmoid(x, 0.3, 10) * 255
- s = self.sigmoid(1 - x, 0.1, 30) * 255
-
- return QColor(h, s, v, QColor.Hsv)
-
def setRange(self, min, max):
self.m_min_value = min
self.m_max_value = max
self.m_continuous = True
+ def setColorLookup(self, clu):
+ self.m_color_lookup = clu
+ self.activate(True)
+
#def setColorList(self, color_vector, descr_vector):
# pass
@@ -72,7 +69,8 @@
if self.m_continuous:
self.drawContinuousScale()
else:
- self.drawColorList()
+ pass
+ #self.drawColorList()
def drawContinuousScale(self):
w = self.width()
@@ -140,12 +138,13 @@
self.s_stripe_width +
self.s_spacing +
self.s_right_margin +
- self.fontMetrics().width(self.getLabelString(self.m_max_value))
+ self.fontMetrics().width("0.0e+02")
+ #self.fontMetrics().width(self.getLabelString(self.m_max_value))
)
h = self.fontMetrics().height() * self.s_stripes / self.s_step
else:
min_label_width = 0
- for desc in m_descr_vector:
+ for desc in self.m_descr_vector:
x = self.fontMetrics().width(desc)
if min_label_width < x:
min_label_width = x
@@ -156,7 +155,7 @@
self.s_right_margin +
min_label_width
)
- h = fontMetrics().height() * len(m_color_vector)
+ h = self.fontMetrics().height() * len(self.m_color_vector)
self.setMinimumWidth(w)
self.setMaximumWidth(w)
Modified: trunk/source/python/AvidaGui2/pyMapProfile.py
===================================================================
--- trunk/source/python/AvidaGui2/pyMapProfile.py 2005-04-07 20:16:21 UTC (rev 125)
+++ trunk/source/python/AvidaGui2/pyMapProfile.py 2005-04-07 20:38:08 UTC (rev 126)
@@ -1,6 +1,10 @@
+from qt import QColor
+from math import exp
+
class pyMapProfile:
def __init__(self):
+
def continuousIndexer(idx_functor):
def continuousIndexingFunction(population_cell_item, min, range):
population_cell = population_cell_item.m_population_cell
@@ -26,48 +30,6 @@
#LineageIdx = lambda c: c.GetOrganism().GetLineageLabel()
- # class gradualLinScaleUpdater:
- # def __init__(self, rng_functor):
- # self.m_rng_functor = rng_functor
- # self.m_inf = 0.0
- # self.m_sup = 0.0
- # self.m_target_inf = 0.0
- # self.m_target_sup = 0.0
- # self.m_inf_tol_coef = 0.1
- # self.m_sup_tol_coef = 0.1
- # self.m_inf_rescale_rate = 0.0
- # self.m_sup_rescale_rate = 0.0
- # self.m_updates_to_rescale = 10
- # self.m_should_reset = True
- # def reset(self, should_reset):
- # self.m_should_reset = should_reset
- # def getRange(self):
- # return self.m_inf, self.m_sup
- # def resetRange(self, population):
- # # Abrubtly change range.
- # (inf, sup) = population and self.m_rng_functor(population) or (0.0, 0.0)
- # (self.m_target_inf, self.m_target_sup) = (self.m_inf, self.m_sup) = (inf, sup)
- # self.m_inf_rescale_rate = self.m_sup_rescale_rate = 0
- # return self.getRange()
- # def updateRange(self, population):
- # # If population is None, set range to (0,0).
- # (inf, sup) = population and self.m_rng_functor(population) or (0.0, 0.0)
- # # If self.m_should_reset flag is True, change range abruptly rather than gradually.
- # if self.m_should_reset: return self.resetRange(population)
- # # If max value in population is above range, or too low according to tolerance, gradually rescale.
- # if (sup < (1 - self.m_sup_tol_coef) * self.m_target_sup) or (self.m_target_sup < sup):
- # new_target_sup = sup * (1 + self.m_sup_tol_coef)
- # self.m_sup_rescale_rate = float(new_target_sup - self.m_target_sup) / self.m_updates_to_rescale
- # self.m_target_sup = new_target_sup
- # # Self.m_sup_rescale_rate is nonzero only when we're rescaling...
- # if self.m_sup_rescale_rate != 0:
- # self.m_sup += self.m_sup_rescale_rate
- # # Check to see whether we're done rescaling. If so, return rescaling to zero.
- # if abs(self.m_target_sup - self.m_sup) < abs(self.m_sup_rescale_rate):
- # self.m_sup = self.m_target_sup
- # self.m_sup_rescale_rate = 0
- # return self.getRange()
-
class gradualLinScaleUpdater:
def __init__(self, rng_functor):
self.m_rng_functor = rng_functor
@@ -80,102 +42,102 @@
self.m_inf_rescale_rate = 0.0
self.m_sup_rescale_rate = 0.0
self.m_updates_to_rescale = 10
-
self.m_should_reset = True
def reset(self, should_reset):
self.m_should_reset = should_reset
def shouldReset(self):
- return self.m_should_reset
+ return self.m_should_reset
def getRange(self):
return self.m_inf, self.m_sup
def resetRange(self, population):
- #print "pyMapProfile.resetRange;"
- #print " old (self.m_inf, self.m_sup)", (self.m_inf, self.m_sup)
- #print " population", population
(inf, sup) = population and self.m_rng_functor(population) or (0.0, 0.0)
- #(self.m_inf, self.m_sup) = (inf, (1 + self.m_sup_tol_coef)*sup)
- #(self.m_target_inf, self.m_target_sup) = (inf, sup)
(self.m_target_inf, self.m_target_sup) = (self.m_inf, self.m_sup) = (inf, sup)
- #print " new (self.m_inf, self.m_sup)", (self.m_inf, self.m_sup)
self.m_inf_rescale_rate = self.m_sup_rescale_rate = 0
+
return self.getRange()
def updateRange(self, population):
- if self.m_should_reset: return self.resetRange(population)
+ if self.m_should_reset:
+ return self.resetRange(population)
(inf, sup) = population and self.m_rng_functor(population) or (0.0, 0.0)
if (sup < (1 - self.m_sup_tol_coef) * self.m_target_sup) or (self.m_target_sup < sup):
- #print "pyMapProfile.updateRange changing range;"
- #if sup < (1 - self.m_sup_tol_coef) * self.m_target_sup:
- #print " narrowing range;"
- #print " sup < (1 - self.m_sup_tol_coef) * self.m_target_sup"
- #print "", sup, "<", (1 - self.m_sup_tol_coef) * self.m_target_sup
- #elif self.m_target_sup < sup:
- #print " expanding range;"
- #print " self.m_target_sup < sup"
- #print "", self.m_target_sup, "<", sup
new_target_sup = sup * (1 + self.m_sup_tol_coef)
self.m_sup_rescale_rate = float(new_target_sup - self.m_sup) / self.m_updates_to_rescale
- #print " new m_sup_rescale_rate", self.m_sup_rescale_rate
- #print " old m_target_sup", self.m_target_sup
- #print " new m_target_sup", new_target_sup
- #print " sup", sup
self.m_target_sup = new_target_sup
if self.m_sup_rescale_rate != 0:
- #print "rescaling..."
- #print " sup", sup
- #print " old m_sup", self.m_sup
self.m_sup += self.m_sup_rescale_rate
if abs(self.m_target_sup - self.m_sup) < abs(self.m_sup_rescale_rate):
- #print " done rescaling."
self.m_sup = self.m_target_sup
self.m_sup_rescale_rate = 0
- #print " new m_sup", self.m_sup
-
+
return self.getRange()
-
# Range functors
NullRng = lambda p: (0, 0)
MeritRng = lambda p: (0, p.GetStats().GetMaxMerit())
FitnessRng = lambda p: (0, p.GetStats().GetMaxFitness())
def GestationTimeRng(p):
return 0, max(
- p.GetCell(n).IsOccupied() \
- and p.GetCell(n).GetOrganism().GetPhenotype().GetGestationTime() \
- or 0 \
- for n in range(p.GetSize())
- )
+ p.GetCell(n).IsOccupied() and p.GetCell(n).GetOrganism().GetPhenotype().GetGestationTime() or 0
+ for n in range(p.GetSize()))
def SizeRng(p):
return 0, max(
- p.GetCell(n).IsOccupied() \
- and p.GetCell(n).GetOrganism().GetPhenotype().GetGenomeLength() \
- or 0 \
- for n in range(p.GetSize())
- )
-
+ p.GetCell(n).IsOccupied() and p.GetCell(n).GetOrganism().GetPhenotype().GetGenomeLength() or 0
+ for n in range(p.GetSize()))
+
+ def sigmoid(x, midpoint, steepness):
+ val = steepness * (x - midpoint)
+ return exp(val)/(1 + exp(val))
+ def sigmoidDoubleToColor(x):
+ #x = max(0, min(x, 1)) * (1 - 0.1) + 0.1
+ x = 1 < x and 1 or x
+ x = x < 0 and 0 or x
+ x = 0.1 + 0.9*x
+ h = (x * 360 + 100) % 360
+ v = sigmoid(x, 0.3, 10) * 255
+ s = sigmoid(1 - x, 0.1, 30) * 255
+ return QColor(h, s, v, QColor.Hsv)
+
self.m_entries = (
- # Mode Name, Indexer
- ('None', continuousIndexer(NullIdx), gradualLinScaleUpdater(NullRng),),
- ('Merit', continuousIndexer(MeritIdx), gradualLinScaleUpdater(MeritRng),),
- ('Fitness', continuousIndexer(FitnessIdx), gradualLinScaleUpdater(FitnessRng),),
- ('Gestation Time', continuousIndexer(GestationTimeIdx), gradualLinScaleUpdater(GestationTimeRng),),
- ('Size', continuousIndexer(SizeIdx), gradualLinScaleUpdater(SizeRng),),
- #('Genotype', GenotypeIdx,),
- #('Lineage', LineageIdx,),
+ # Mode Name, Indexer
+ ('None',
+ continuousIndexer(NullIdx),
+ gradualLinScaleUpdater(NullRng),
+ None
+ ),
+ ('Merit',
+ continuousIndexer(MeritIdx),
+ gradualLinScaleUpdater(MeritRng),
+ sigmoidDoubleToColor
+ ),
+ ('Fitness',
+ continuousIndexer(FitnessIdx),
+ gradualLinScaleUpdater(FitnessRng),
+ sigmoidDoubleToColor
+ ),
+ ('Gestation Time',
+ continuousIndexer(GestationTimeIdx),
+ gradualLinScaleUpdater(GestationTimeRng),
+ sigmoidDoubleToColor
+ ),
+ ('Size',
+ continuousIndexer(SizeIdx),
+ gradualLinScaleUpdater(SizeRng),
+ sigmoidDoubleToColor
+ ),
+ #('Genotype', GenotypeIdx,),
+ #('Lineage', LineageIdx,),
)
- def getSize(self):
- return len(self.m_entries)
- def getModeName(self, index):
- return self.m_entries[index][0]
- def getIndexer(self, index):
- return self.m_entries[index][1]
- def getUpdater(self, index):
- return self.m_entries[index][2]
+ def getSize(self): return len(self.m_entries)
+ def getModeName(self, index): return self.m_entries[index][0]
+ def getIndexer(self, index): return self.m_entries[index][1]
+ def getUpdater(self, index): return self.m_entries[index][2]
+ def getColorLookup(self, index): return self.m_entries[index][3]
Modified: trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py 2005-04-07 20:16:21 UTC (rev 125)
+++ trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py 2005-04-07 20:38:08 UTC (rev 126)
@@ -62,10 +62,13 @@
self.printGraphSlot)
def load(self, filename, colx, coly):
+ print "pyOnePop_GraphCtrl.load"
if (self.m_avida is None) or (self.m_avida.m_population.GetStats().GetUpdate() == 0):
- self.m_x_array = zeros(0, Float)
- self.m_y_array = zeros(0, Float)
+ print " m_avida is None, or update is zero. Not loading from file."
+ self.m_x_array = zeros(1, Float)
+ self.m_y_array = zeros(1, Float)
else:
+ print " loading from file."
init_file = cInitFile(cString(filename))
init_file.Load()
init_file.Compress()
@@ -90,6 +93,9 @@
self.m_graph_ctrl.m_curve = self.m_graph_ctrl.insertCurve(self.m_avida_stats_interface.m_entries[index][0])
self.m_graph_ctrl.setCurveData(self.m_graph_ctrl.m_curve, self.m_x_array, self.m_y_array)
self.m_graph_ctrl.setCurvePen(self.m_graph_ctrl.m_curve, QPen(Qt.red))
+ self.m_graph_ctrl.m_zoomer.setZoomBase(self.m_graph_ctrl.curve(self.m_graph_ctrl.m_curve).boundingRect())
+ self.m_graph_ctrl.setAxisAutoScale(QwtPlot.xBottom)
+ self.m_graph_ctrl.setAxisAutoScale(QwtPlot.yLeft)
self.m_graph_ctrl.replot()
def setAvidaSlot(self, avida):
@@ -125,11 +131,11 @@
# Quick hack: Cause the zoomer to limit zooming-out to the
# boundaries of the displayed curve.
self.m_graph_ctrl.m_zoomer.setZoomBase(self.m_graph_ctrl.curve(self.m_graph_ctrl.m_curve).boundingRect())
- # Quick hack: If the user has zoomed-in on or -out from the graph,
- # autoscaling will have been disabled. This reenables it.
- self.m_graph_ctrl.setAxisAutoScale(QwtPlot.xBottom)
- self.m_graph_ctrl.setAxisAutoScale(QwtPlot.yLeft)
- self.m_graph_ctrl.replot()
+ # Quick hack: If the user has zoomed-in on or -out from the graph,
+ # autoscaling will have been disabled. This reenables it.
+ self.m_graph_ctrl.setAxisAutoScale(QwtPlot.xBottom)
+ self.m_graph_ctrl.setAxisAutoScale(QwtPlot.yLeft)
+ self.m_graph_ctrl.replot()
def printGraphSlot(self):
printer = QPrinter()
Modified: trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py 2005-04-07 20:16:21 UTC (rev 125)
+++ trunk/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py 2005-04-07 20:38:08 UTC (rev 126)
@@ -18,32 +18,22 @@
self.m_gradient_scale_ctrl.construct(self.m_session_mdl)
self.m_live_controls_ctrl.construct(self.m_session_mdl)
self.m_petri_configure_ctrl.construct(self.m_session_mdl)
- self.connect(self.m_petri_configure_ctrl, PYSIGNAL("freezeDishPhaseISig"),
- self.m_petri_dish_ctrl.extractPopulationSlot)
- self.connect(self.m_petri_dish_ctrl, PYSIGNAL("freezeDishPhaseIISig"),
- 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_session_mdl.m_session_mdtr,
- PYSIGNAL("doDisablePetriDishSig"), self.SetDishDisabledSlot)
-
- 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.connect(self.m_petri_configure_ctrl, PYSIGNAL("freezeDishPhaseISig"), self.m_petri_dish_ctrl.extractPopulationSlot)
+ self.connect(self.m_petri_dish_ctrl, PYSIGNAL("freezeDishPhaseIISig"), 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_session_mdl.m_session_mdtr, PYSIGNAL("doDisablePetriDishSig"), self.SetDishDisabledSlot)
+ 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.connect(self.m_mode_combobox, SIGNAL("activated(int)"), self.modeActivatedSlot)
- self.m_map_profile = pyMapProfile()
self.m_mode_combobox.clear()
self.m_mode_combobox.setInsertionPolicy(QComboBox.AtBottom)
+ self.m_map_profile = pyMapProfile()
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)
@@ -87,32 +77,26 @@
self.dishDisabled = True
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_avida and 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()
+ self.m_petri_dish_ctrl.setColorLookupFunctor(self.m_map_profile.getColorLookup(self.m_mode_index))
+ self.m_gradient_scale_ctrl.setColorLookup(self.m_map_profile.getColorLookup(self.m_mode_index))
+ self.m_updater = self.m_map_profile.getUpdater(self.m_mode_index)
+ self.m_updater and self.m_updater.reset(True)
+ self.m_avida and self.m_avida.m_avida_threaded_driver.m_lock.release()
+
def avidaUpdatedSlot (self):
- 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)):
+ if self.m_updater:
+ (old_min, old_max) = self.m_updater.getRange()
+ (min, max) = self.m_avida and self.m_updater.updateRange(self.m_avida.m_population) or (0, 0)
+ if self.m_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)
+ self.m_updater.reset(False)
else:
self.m_gradient_scale_ctrl.setRange(0, 0)
self.m_gradient_scale_ctrl.activate(True)
Modified: trunk/source/python/AvidaGui2/pyPetriDishCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriDishCtrl.py 2005-04-07 20:16:21 UTC (rev 125)
+++ trunk/source/python/AvidaGui2/pyPetriDishCtrl.py 2005-04-07 20:38:08 UTC (rev 126)
@@ -1,28 +1,4 @@
-# -*- coding: utf-8 -*-
-
-# Notes:
-# - w*h population cell_info_items;
-# - cell_info_item[0] refers to population cell(0).
-# - x ord of item[n]:
-# - stores normalized_index
-#
-
-# Coordinates for grid cells in toroidal geometry:
-# x: n % w
-# y: n / w
-# xm: (x + w/2) % w
-# ym: (y + h/2) % h
-#
-# xm: (n%w + w/2) % w
-# ym: (n/w + h/2) % h
-
-# Coordinates for grid cells in bounded geometry:
-# x: n % w
-# y: n / w
-#
-# xm, ym not needed. replace w/ x & y.
-
print """
XXX fixme: in pyPetriDishCtrl.py,
pyPetriDishCtrl.setAvidaSlot(),
@@ -62,14 +38,14 @@
self.m_petri_dish_layout.addWidget(self.m_canvas_view)
self.m_changed_cell_items = []
self.m_indexer = None
+ self.m_color_lookup_functor = None
- self.connect(
- self.m_session_mdl.m_session_mdtr, PYSIGNAL("setAvidaSig"),
- self.setAvidaSlot)
- 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("setAvidaSig"), self.setAvidaSlot)
+ self.connect( self.m_canvas_view, PYSIGNAL("orgClickedOnSig"), self.m_session_mdl.m_session_mdtr, PYSIGNAL("orgClickedOnSig"))
+ def setColorLookupFunctor(self, color_lookup_functor):
+ self.m_color_lookup_functor = color_lookup_functor
+
def setAvidaSlot(self, avida):
old_avida = self.m_avida
self.m_avida = avida
@@ -102,82 +78,25 @@
self.m_cs_value_range = 0
self.m_changed_cell_items = self.m_cell_info[:]
while self.doSomeWork(self.m_avida): pass
- self.avidaUpdatedSlot()
+ self.updateCellItems()
self.m_avida.addGuiWorkFunctor(self)
- 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)
- return exp(val)/(1+exp(val))
-
- y = 1
- if self.m_cs_value_range > 0: y = (x - self.m_cs_min_value)/self.m_cs_value_range
- if y > 1: y = 1
- elif y < 0: y = 0
-
- h = (y*360 + 100) % 360
- v = sigmoid(y, 0.3, 10) * 255
- s = sigmoid(1 - y, 0.1, 30) * 255
-
- return QColor(h, s, v, QColor.Hsv)
-
- def calcCellState(self, population_cell):
- state = Qt.black
- if population_cell.IsOccupied():
- organism = population_cell.GetOrganism()
- phenotype = organism.GetPhenotype()
- dbl = phenotype.GetFitness()
- 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)
+ cell_info_item.updateColorUsingFunctor(None)
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):
- return population_cell.IsOccupied() and population_cell.GetOrganism().GetPhenotype().GetFitness() or 0.0
-
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:
@@ -193,36 +112,11 @@
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)
+ cell_info_item.updateColorUsingFunctor(self.m_color_lookup_functor)
self.m_changed_cell_items = []
if self.m_canvas: self.m_canvas.update()
- def avidaUpdatedSlot(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)
-
- self.calcColorScale()
- for cell_info_item in self.m_changed_cell_items:
- cell_info_item.updateColorUsingFunctor(temp_color_functor)
- self.m_changed_cell_items = []
- self.m_canvas.update()
-
def extractPopulationSlot(self):
population_dict = {}
world_w = cConfig.GetWorldX()
@@ -238,7 +132,6 @@
self.emit(PYSIGNAL("freezeDishPhaseIISig"), (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)
Modified: trunk/source/python/AvidaGui2/pyPopulationCellItem.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPopulationCellItem.py 2005-04-07 20:16:21 UTC (rev 125)
+++ trunk/source/python/AvidaGui2/pyPopulationCellItem.py 2005-04-07 20:38:08 UTC (rev 126)
@@ -1,8 +1,11 @@
-from qt import QBrush, QPen
+from qt import QBrush, QColor, QPen, Qt
from qtcanvas import QCanvasRectangle
class pyPopulationCellItem(QCanvasRectangle):
+
+ s_empty_color = QColor(Qt.black)
+
def rtti(self):
return 271828
@@ -25,7 +28,7 @@
return True
def updateColorUsingFunctor(self, functor):
- color = functor(self.m_index)
+ color = (self.m_population_cell.IsOccupied() and functor) and functor(self.m_index) or self.s_empty_color
self.setBrush(QBrush(color))
self.setPen(QPen(color))
More information about the Avida-cvs
mailing list