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

jclune at myxo.css.msu.edu jclune at myxo.css.msu.edu
Wed Aug 23 14:37:00 PDT 2006


Author: jclune
Date: 2006-08-23 17:37:00 -0400 (Wed, 23 Aug 2006)
New Revision: 891

Added:
   branches/developers/avida-edward/source/python/AvidaGui2/pyMapLegendCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyMapLegendView.py
Log:
more ancestor legend view files

Added: branches/developers/avida-edward/source/python/AvidaGui2/pyMapLegendCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyMapLegendCtrl.py	2006-08-23 21:12:38 UTC (rev 890)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyMapLegendCtrl.py	2006-08-23 21:37:00 UTC (rev 891)
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+from qt import *
+from pyMapLegendView import pyMapLegendView
+
+
+class pyMapLegendCtrl(pyMapLegendView):
+
+  def __init__(self,parent = None,name = None,fl = 0):
+    pyMapLegendView.__init__(self,parent,name,fl)
+    QToolTip.add(self, "<p>Dynamic scale for current variable (scale changes as maximum value in population increases or decreases)</p>")
+
+
+  def construct(self, session_mdl):
+    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 "pyMapLegendCtrl.setAvidaSlot() ..."
+    old_avida = self.m_avida
+    self.m_avida = avida
+    if(old_avida):
+      print "pyMapLegendCtrl.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 "pyMapLegendCtrl.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 pyMapLegendCtrl.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/pyMapLegendView.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyMapLegendView.py	2006-08-23 21:12:38 UTC (rev 890)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyMapLegendView.py	2006-08-23 21:37:00 UTC (rev 891)
@@ -0,0 +1,250 @@
+ # -*- coding: utf-8 -*-
+
+# Original form implementation generated from reading ui file 
+# '/Users/kaben/Projects/Software/Avida/svn/avida2/trunk/source/python/AvidaGui2/pyMapLegendView.ui'
+#
+# It has since been modified by hand
+
+from qt import *
+from math import exp
+
+class pyMapLegendView(QWidget):
+  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):
+    QWidget.__init__(self,parent,name,fl)
+    print "GOSH DARNIT, I'M ALIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIVE!"
+    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("pyMapLegendView")
+  
+  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)
+




More information about the Avida-cvs mailing list