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

jclune at myxo.css.msu.edu jclune at myxo.css.msu.edu
Wed Aug 23 14:12:38 PDT 2006


Author: jclune
Date: 2006-08-23 17:12:38 -0400 (Wed, 23 Aug 2006)
New Revision: 890

Added:
   branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendObjectCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendView.py
Modified:
   branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_StatsCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyPetriDishCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyPopulationCellItem.py
   branches/developers/avida-edward/source/python/AvidaGui2/to-do_list
Log:
Added files for ancestor view

Added: branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendCtrl.py	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendCtrl.py	2006-08-23 21:12:38 UTC (rev 890)
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+
+from qt import *
+from pyAncestorLegendView import pyAncestorLegendView
+
+from descr import *
+
+class pyAncestorLegendCtrl(pyAncestorLegendView):
+
+  def __init__(self,parent = None,name = None,fl = 0):
+    pyAncestorLegendView.__init__(self,parent,name,fl)
+    QToolTip.add(self, "<p>Legend for the ancestor map mode.</p>")
+
+
+  def construct(self, session_mdl):
+    descr("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR")
+    self.m_session_mdl = session_mdl
+    self.m_avida = None
+    self.m_current_map_mode_name = None
+    self.connect(
+      self.m_session_mdl.m_session_mdtr, PYSIGNAL("setAvidaSig"),
+      self.setAvidaSlot)
+    self.connect(self.m_session_mdl.m_session_mdtr,
+       PYSIGNAL("mapModeChangedSig"), self.setMapModeSlot)
+
+
+  def setAvidaSlot(self, avida):
+    print "pyAncestorLegendCtrl.setAvidaSlot() ..."
+    old_avida = self.m_avida
+    self.m_avida = avida
+    if(old_avida):
+      print "pyAncestorLegendCtrl.setAvidaSlot() disconnecting old_avida ..."
+      self.disconnect(
+        self.m_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
+        self.avidaUpdatedSlot)
+      del old_avida
+    if(self.m_avida):
+      print "pyAncestorLegendCtrl.setAvidaSlot() connecting self.m_avida ..."
+      self.connect(
+        self.m_avida.m_avida_thread_mdtr, PYSIGNAL("AvidaUpdatedSig"),
+        self.avidaUpdatedSlot)
+
+  def setMapModeSlot(self,index):
+    self.m_current_map_mode_name = index
+
+  def avidaUpdatedSlot(self):
+    pass
+
+  def destruct(self):
+    print "*** called pyAncestorLegendCtrl.py:destruct ***"
+    self.m_avida = None
+    self.disconnect(
+      self.m_session_mdl.m_session_mdtr, PYSIGNAL("setAvidaSig"),
+      self.setAvidaSlot)
+    self.m_session_mdl = None
+  
+

Added: branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendObjectCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendObjectCtrl.py	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendObjectCtrl.py	2006-08-23 21:12:38 UTC (rev 890)
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'pyOrgSquareView.ui'
+#
+# Created: Wed Jul 5 10:57:42 2006
+#      by: The PyQt User Interface Compiler (pyuic) 3.15.1
+#
+# WARNING! All changes made in this file will be lost!
+
+
+from qt import *
+from pyOrgSquareCtrl import pyOrgSquareCtrl
+
+
+class pyAncestorLegendObjectCtrl(QWidget):
+    def __init__(self,parent = None,name = None,fl = 0):
+        QWidget.__init__(self,parent,name,fl)
+
+        if not name:
+            self.setName("pyAncestorLegendObjectCtrl")
+
+
+        self.pyAncestorLegendObjectCtrlLayout = QVBoxLayout(self,0,0,"pyAncestorLegendObjectCtrlLayout")
+        self.pyAncestorLegendObjectCtrlLayout.setResizeMode(QLayout.Minimum)
+#        pyAncestorLegendObjectCtrlLayout.setResizeMode(QLayout.Preferred)
+
+
+        self.m_org_square = pyOrgSquareCtrl(self,"m_org_square")
+        self.m_org_square.construct()
+        self.m_org_square.setMinimumSize(QSize(20,20))
+        self.m_org_square.setMaximumSize(QSize(20,20))
+        self.pyAncestorLegendObjectCtrlLayout.addWidget(self.m_org_square)
+        self.m_org_square.paint(Qt.green)
+
+        self.m_ancestor_name = QLabel(self,"m_ancestor_name")
+        self.m_ancestor_name.setMinimumSize(QSize(20,20))
+        self.m_ancestor_name.setMaximumHeight(20)
+        self.m_ancestor_name.setBackgroundMode(QLabel.PaletteShadow)
+        m_ancestor_name_font = QFont(self.m_ancestor_name.font())
+        m_ancestor_name_font.setPointSize(12)
+        self.m_ancestor_name.setFont(m_ancestor_name_font)
+#        self.m_ancestor_name.setScaledContents(0)
+        self.m_ancestor_name.setAlignment(QLabel.AlignTop)
+#        self.pyAncestorLegendObjectCtrlLayout.addWidget(self.m_ancestor_name)
+        self.m_ancestor_name.setPaletteBackgroundColor(Qt.darkGray)
+        self.m_ancestor_name.setText(self.__tr("mock"))
+#        self.resize(QSize(202,202).expandedTo(self.minimumSizeHint()))
+        self.clearWState(Qt.WState_Polished)
+
+    def setAncestorName(self,ancestorName):
+        self.m_ancestor_name.setText(self.__tr(ancestorName))
+        self.m_ancestor_name.setMaximumWidth(self.m_ancestor_name.minimumSizeHint().width())
+        self.m_ancestor_name.setMinimumWidth(self.m_ancestor_name.minimumSizeHint().width()+10)
+        self.pyAncestorLegendObjectCtrlLayout.addWidget(self.m_ancestor_name)
+        self.setMaximumWidth(self.m_ancestor_name.minimumSizeHint().width())
+
+    def setAncestorColor(self,color):
+        self.m_org_square.paint(color)
+
+    def languageChange(self):
+        self.setCaption(self.__tr("pyPetriDishView"))
+
+
+
+    def __tr(self,s,c = None):
+        return qApp.translate("pyAncestorLegendObjectCtrl",s,c)

Added: branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendView.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendView.py	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyAncestorLegendView.py	2006-08-23 21:12:38 UTC (rev 890)
@@ -0,0 +1,249 @@
+ # -*- coding: utf-8 -*-
+
+# Original form implementation generated from reading ui file 
+# '/Users/kaben/Projects/Software/Avida/svn/avida2/trunk/source/python/AvidaGui2/pyAncestorLegendView.ui'
+#
+# It has since been modified by hand
+
+from qt import *
+from math import exp
+
+
+class pyAncestorLegendView(QScrollView):
+  s_left_margin = 6
+  s_top_margin = 6
+  s_bottom_margin = 6
+  s_right_margin = 6
+  s_spacing = 6
+  s_stripe_height = 20
+  s_stripes = 100
+  s_step = 10
+  s_empty_text = "(empty)"
+  s_off_scale_text = "(off scale)"
+  s_empty_text_width = 0
+  s_off_scale_text_width = 0
+  s_label_text_width = 0
+  s_map_mode_name_label_width = 100
+  s_text_height = 0
+
+  def __init__(self,parent = None,name = None,fl = 0):
+    QScrollView.__init__(self,parent,name,fl)
+
+    self.m_min_value = 0.0
+    self.m_max_value = 0.0
+    self.m_color_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(9)
+    self.setFont(font)
+
+    self.s_empty_text_width = self.fontMetrics().width(self.s_empty_text)
+    self.s_off_scale_text_width = self.fontMetrics().width(self.s_off_scale_text)
+    self.s_label_text_width = self.fontMetrics().width("0.00000")
+    self.s_text_height = self.fontMetrics().height()
+
+    if not name:
+      setName("pyAncestorLegendView")
+  
+  def construct(self, session_mdl):
+    self.m_session_mdl = session_mdl
+    self.m_avida = None
+
+
+  def doubleToColor(self, x): return self.m_color_lookup and self.m_color_lookup(x) or QColor(Qt.black)
+
+  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
+
+  def activate(self, should_activate):
+    self.m_activated = should_activate
+    if should_activate:
+      self.recalcSize()
+      self.repaint()
+
+  def paintEvent(self, QPaintEvent):
+    if not self.m_activated:
+      return
+
+    if self.m_continuous:
+      self.drawContinuousScale()
+    else:
+      pass
+      #self.drawColorList()
+
+  def drawContinuousScale(self):
+    w = self.width()
+    h = self.height()
+    p = QPainter(self)
+  
+    stripe_width = (w-self.s_left_margin-self.s_right_margin)/self.s_stripes + 1
+    plot_width = w-self.s_left_margin-self.s_right_margin+1
+    #plot_width = w-self.s_left_margin-self.s_right_margin-stripe_width+1
+  
+    #text_height = self.fontMetrics().height()
+    #label_width = self.fontMetrics().width("0.00000")
+  
+    for i in xrange(self.s_stripes):
+      x = float(i) / float(self.s_stripes);
+      p.fillRect(
+        (self.s_left_margin + x*plot_width),
+        #self.s_top_margin + text_height + self.s_spacing,
+        self.s_top_margin + self.s_text_height + self.s_spacing,
+        stripe_width,
+        self.s_stripe_height,
+        QBrush(self.doubleToColor(x))
+        )
+
+    p.drawText(
+      self.s_left_margin,
+      self.s_top_margin,
+      self.s_label_text_width,
+      self.s_text_height,
+      #label_width,
+      #text_height,
+      Qt.AlignBottom | Qt.AlignLeft,
+      self.getLabelString(self.m_min_value)
+    )
+    p.drawText(
+      #w - self.s_right_margin - label_width,
+      w - self.s_right_margin - self.s_label_text_width,
+      self.s_top_margin,
+      self.s_label_text_width,
+      self.s_text_height,
+      #label_width,
+      #text_height,
+      Qt.AlignBottom | Qt.AlignRight,
+      self.getLabelString(self.m_max_value)
+    )
+
+# draw the number label for the midpoint
+    p.drawText(
+      #w - self.s_right_margin - label_width,
+#      w/2 - self.s_right_margin - self.s_label_text_width,
+      w/2 - self.s_label_text_width/2,
+      self.s_top_margin,
+      self.s_label_text_width,
+      self.s_text_height,
+      #label_width,
+      #text_height,
+      Qt.AlignBottom | Qt.AlignCenter,
+      self.getLabelString((self.m_max_value-self.m_min_value)/2.0)
+    )
+
+
+#  make a word label for the scale 
+    p.drawText(
+      w/2 - self.s_map_mode_name_label_width/2,
+      h - self.s_top_margin*4,            #the multiple is a hack
+      self.s_map_mode_name_label_width,
+      self.s_text_height,
+      #label_width,
+      #text_height,
+      Qt.AlignBottom | Qt.AlignCenter,
+      self.m_current_map_mode_name
+    )
+
+
+      #self.s_spacing + 2 * self.fontMetrics().width("0.0e+02")
+
+      #if i%self.s_step == 0:
+      #  p.drawText(
+      #    self.s_left_margin+self.s_stripe_height + self.s_spacing,
+      #    (self.s_top_margin + (1-x)*plot_width-(self.s_step-1)*stripe_width/2),
+      #    text_width,
+      #    self.s_step*stripe_width,
+      #    Qt.AlignVCenter | Qt.AlignLeft,
+      #    self.getLabelString( self.m_min_value+x*(self.m_max_value - self.m_min_value))
+      #    )
+
+  #def drawColorList(self):
+  #  QValueVector<QString>::const_iterator str_it = m_descr_vector.begin();
+  #  QValueVector<QColor>::const_iterator color_it = m_color_vector.begin();
+  #
+  #  w = self.width()
+  #  h = self.height()
+  #  p = QPainter(self)
+  #
+  #  stripe_width = (h-self.s_top_margin-self.s_bottom_margin)/len(m_color_vector)
+  #  plot_width = h-self.s_top_margin-self.s_bottom_margin-stripe_width
+  #
+  #  text_width = w - self.s_left_margin - self.s_stripe_height - self.s_spacing;
+  #
+  #  int i,j;
+  #  i = j = m_color_list_length-1;
+  #  for ( ; i>=0; i--, str_it++, color_it++ ){
+  #    if ( !(*str_it).isNull() ){ // draw only if description exists
+  #      double x = (double) j / (double)(m_color_list_length-1);
+  #      // the colored stripe
+  #      p.fillRect( m_left_margin, (int) (m_top_margin + (1-x)*plot_width + .1*stripe_width), m_stripe_width, (int) (.8*stripe_width), *color_it );
+  #      // the label
+  #      p.drawText( m_left_margin+m_stripe_width + m_spacing, (int) (m_top_margin + (1-x)*plot_width), text_width, stripe_width, Qt::AlignVCenter | Qt::AlignLeft, *str_it );
+  #      j--;
+  #    } 
+  #  } 
+  
+
+  def recalcSize(self):
+    w = 1
+    h = 1
+    if self.m_activated:
+      if self.m_continuous:
+        #w = self.s_left_margin + self.s_right_margin + self.s_spacing + 2 * self.fontMetrics().width("0.0e+02")
+        w = self.s_left_margin + self.s_right_margin + self.s_spacing + 2 * self.s_label_text_width
+        h = (
+          self.s_top_margin +
+          #self.fontMetrics().height() +
+          self.s_label_text_width +
+          self.s_spacing +
+          self.s_stripe_height +
+          self.s_bottom_margin
+        )
+      else:
+        min_label_width = 0
+        for desc in self.m_descr_vector: 
+          x = self.fontMetrics().width(desc)
+          if min_label_width < x:
+            min_label_width = x
+        w = (
+          self.s_left_margin +
+          self.s_stripe_height +
+          self.s_spacing +
+          self.s_right_margin +
+          min_label_width
+          )
+        h = self.fontMetrics().height() * len(self.m_color_vector)
+
+    self.setMinimumWidth(w)
+    #self.setMaximumWidth(w)
+
+    self.setMinimumHeight(h)
+    self.setMaximumHeight(h)
+
+
+  def getLabelString(self, x):
+
+    # To show numbers < 10,000 without going to sci. notation had to
+    # set precision in the .arg method to 5 this produces a lot of digits
+    # after the decimal point so the follow lines partially correct for this
+
+    if x >= 100:
+      ix = int(x)
+      x = float(ix)
+    return QString("%1").arg(x, 0, 'g', 2)
+

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_PetriDishCtrl.py	2006-08-23 21:12:38 UTC (rev 890)
@@ -151,14 +151,25 @@
         num_ancestor_object_counter = num_ancestor_object_counter+1
         continue
 
-      #another test
-      #alo = pyAncestorLegendObjectCtrl(self.m_ancestor_legend_ctrl.viewport())
       alo = pyAncestorLegendObjectCtrl(self.m_big_hbox)
  #     a.append(alo)
 #      self.pyAncestorLegendCtrlLayout.addWidget(alo)
 #      self.m_ancestor_legend_ctrl.addChild(alo)
 #      alo.setMaximumSize(QSize(100,100))
+
+#     in the psuedo working version
       alo.setAncestorName(name)
+#     end in the pseudo
+
+#      alo.setAncestorName(name)
+#      lineage_range = len(self.m_session_mdl.m_ancestors_dict)
+#      non_normalized_index = label + 1
+#      normalized_index = float(non_normalized_index) / float(lineage_range)
+#      a_sensible_color = self.m_petri_dish_ctrl.m_color_lookup_functor(normalized_index)
+#      alo.setAncestorColor(a_sensible_color)
+
+
+
 #      a.append(pyAncestorLegendObjectCtrl(self.m_ancestor_legend_ctrl.viewport()))
 #      self.pyAncestorLegendCtrlLayout.addWidget(a[len(a)-1])
 #      a[len(a)-1].setMaximumSize(QSize(100,100))
@@ -173,6 +184,19 @@
       self.m_num_ancestor_objects_added = len(self.a)
       
     print "len(a) is ", len(self.a)
+
+    k = 0
+    for label, name in self.m_session_mdl.m_ancestors_dict.iteritems():
+
+      lineage_range = len(self.m_session_mdl.m_ancestors_dict)
+      non_normalized_index = label + 1
+      normalized_index = float(non_normalized_index) / float(lineage_range)
+      a_sensible_color = self.m_petri_dish_ctrl.m_color_lookup_functor(normalized_index)
+      self.a[k].setAncestorColor(a_sensible_color)
+      k = k+1
+                                    
+
+
 #      alo = pyAncestorLegendObjectCtrl(self.m_kgn_hbox)
 #      alo.setMaximumSize(QSize(100,100))
 #      alo.setAncestorName(name)

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_StatsCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_StatsCtrl.py	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOnePop_StatsCtrl.py	2006-08-23 21:12:38 UTC (rev 890)
@@ -281,7 +281,7 @@
     #   print the tasks the clicked on organism is doing 
  
     # get the Tarray of tasks
-    m_clickedOrg_task_count = phenotype.GetCurTaskCount()
+    m_clickedOrg_task_count = phenotype.GetLastTaskCount()
 
     num_not_clickedOrg = m_clickedOrg_task_count[0]
     self.m_num_not_clickedOrg.setText(str(num_not_clickedOrg))

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyPetriDishCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyPetriDishCtrl.py	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyPetriDishCtrl.py	2006-08-23 21:12:38 UTC (rev 890)
@@ -268,14 +268,17 @@
       if (passedATest and not failedATest):  
         cell_info_item.setPen(QPen(QColor(0,255,255))) 
 
-    cell_info_item.updateColorUsingFunctor(self.m_color_lookup_functor)
+    brush_color = cell_info_item.updateColorUsingFunctor(self.m_color_lookup_functor)
 
     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),2))
       else:
 #        cell_info_item.setPen(QPen(Qt.NoPen))
-        self.m_last_cell_outlined = cell_info_item      
+        self.m_last_cell_outlined = cell_info_item
+
+
+
     return cell_info_item
 
   def updateCellItems(self, should_update_all = False):

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyPopulationCellItem.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyPopulationCellItem.py	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyPopulationCellItem.py	2006-08-23 21:12:38 UTC (rev 890)
@@ -33,6 +33,7 @@
   def updateColorUsingFunctor(self, functor):
     color = (self.m_population_cell.IsOccupied() and functor) and functor(self.m_index) or self.s_empty_color
     self.setBrush(QBrush(color))
+    return color
 
  
 

Modified: branches/developers/avida-edward/source/python/AvidaGui2/to-do_list
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/to-do_list	2006-08-23 18:54:29 UTC (rev 889)
+++ branches/developers/avida-edward/source/python/AvidaGui2/to-do_list	2006-08-23 21:12:38 UTC (rev 890)
@@ -63,13 +63,10 @@
 
 Priority High
 -make the org report give the name of the ancestor when they are clicked on
--make tasks reflect parent tasks (not real time) in org report (pending group decision) (1/26/06)
 
 
-
-
 Priority Medium
--make the getting rid of the outline of the cells something that doesn't slow down the code at every step
+
 -Use warning system
    -make a warning that says you can't drag orgs into this view (1/26/06)
    -the "that was a bad path" or "file does not exist" warnings for dragging and dropping should use this (10/01/05)
@@ -80,9 +77,9 @@
 
 Priority Low
 -color the scales (1/10/05)
+-make the getting rid of the outline of the cells something that doesn't slow down the code at every step
 
 
-
 ************Kaben******************
 
 
@@ -276,4 +273,6 @@
 -work continues on the ancestor map mode=======
 -fix the prerun crashes for clicking around petri dish ancestors
 -fix the problem that the gray outline of ancestors is going away if they are clicked on then off again pre-run
-
+-made the highlight of the clicked on cell twice as thick
+-ancestor map mode now loads the names of the organisms and has the size of the name label correctly, scrolling also works, but the color of the ancestor is not being painted correctly (and the layout needs to be improved)
+--make tasks reflect parent tasks (not real time) in org report (pending group decision) (1/26/06)
\ No newline at end of file




More information about the Avida-cvs mailing list