[Avida-cvs] [Avida2-svn] r117 - trunk/source/python/AvidaGui2
kaben at myxo.css.msu.edu
kaben at myxo.css.msu.edu
Wed Apr 6 10:30:25 PDT 2005
Author: kaben
Date: 2005-04-06 13:30:25 -0400 (Wed, 06 Apr 2005)
New Revision: 117
Added:
trunk/source/python/AvidaGui2/pyGradientScaleView.py
Removed:
trunk/source/python/AvidaGui2/pyGradientScaleView.py
Log:
* This view file is now written by hand.
Deleted: trunk/source/python/AvidaGui2/pyGradientScaleView.py
===================================================================
--- trunk/source/python/AvidaGui2/pyGradientScaleView.py 2005-04-06 17:29:27 UTC (rev 116)
+++ trunk/source/python/AvidaGui2/pyGradientScaleView.py 2005-04-06 17:30:25 UTC (rev 117)
@@ -1,51 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Form implementation generated from reading ui file 'pyGradientScaleView.ui'
-#
-# Created: Thu Mar 31 04:19:19 2005
-# by: The PyQt User Interface Compiler (pyuic) 3.13
-#
-# WARNING! All changes made in this file will be lost!
-
-
-from qt import *
-
-
-class pyGradientScaleView(QWidget):
- def __init__(self,parent = None,name = None,fl = 0):
- QWidget.__init__(self,parent,name,fl)
-
- if not name:
- self.setName("pyGradientScaleView")
-
- self.setSizePolicy(QSizePolicy(5,5,0,0,self.sizePolicy().hasHeightForWidth()))
- self.setMaximumSize(QSize(32767,32767))
-
- pyGradientScaleViewLayout = QVBoxLayout(self,0,0,"pyGradientScaleViewLayout")
- pyGradientScaleViewLayout.setResizeMode(QLayout.Minimum)
-
- self.textLabel4 = QLabel(self,"textLabel4")
- self.textLabel4.setSizePolicy(QSizePolicy(1,1,0,0,self.textLabel4.sizePolicy().hasHeightForWidth()))
- self.textLabel4.setBackgroundMode(QLabel.PaletteShadow)
- self.textLabel4.setPaletteBackgroundColor(QColor(220,220,220))
- textLabel4_font = QFont(self.textLabel4.font())
- textLabel4_font.setPointSize(10)
- self.textLabel4.setFont(textLabel4_font)
- self.textLabel4.setScaledContents(0)
- self.textLabel4.setAlignment(QLabel.AlignCenter)
- pyGradientScaleViewLayout.addWidget(self.textLabel4)
-
- self.languageChange()
-
- self.resize(QSize(124,188).expandedTo(self.minimumSizeHint()))
- self.clearWState(Qt.WState_Polished)
-
-
- def languageChange(self):
- self.setCaption(self.__tr("pyGradientScaleView"))
- self.textLabel4.setText(self.__tr("mock\n"
-"gradient"))
-
-
- def __tr(self,s,c = None):
- return qApp.translate("pyGradientScaleView",s,c)
Added: trunk/source/python/AvidaGui2/pyGradientScaleView.py
===================================================================
--- trunk/source/python/AvidaGui2/pyGradientScaleView.py 2005-04-06 17:29:27 UTC (rev 116)
+++ trunk/source/python/AvidaGui2/pyGradientScaleView.py 2005-04-06 17:30:25 UTC (rev 117)
@@ -0,0 +1,167 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file '/Users/kaben/Projects/Software/Avida/svn/avida2/trunk/source/python/AvidaGui2/pyGradientScaleView.ui'
+#
+# Created: Thu Mar 31 16:57:36 2005
+# by: The PyQt User Interface Compiler (pyuic) 3.13
+#
+# WARNING! All changes made in this file will be lost!
+
+
+from qt import *
+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_stripes = 100
+ s_step = 10
+
+ def __init__(self,parent = None,name = None,fl = 0):
+ QWidget.__init__(self,parent,name,fl)
+
+ self.m_min_value = 0.0
+ self.m_max_value = 0.0
+ self.m_color_vector = []
+ self.m_desc_vector = []
+ self.m_continuous = False
+ self.m_activated = False
+ self.m_was_activated = False
+
+ self.recalcSize()
+
+ 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):
+ 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 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:
+ self.drawColorList()
+
+ def drawContinuousScale(self):
+ w = self.width()
+ h = self.height()
+ p = QPainter(self)
+
+ stripe_height = (h-self.s_top_margin-self.s_bottom_margin)/self.s_stripes + 1
+ plot_height = h-self.s_top_margin-self.s_bottom_margin-stripe_height+1
+
+ text_width = w - self.s_left_margin - self.s_stripe_width - self.s_spacing
+
+ for i in range(self.s_stripes):
+ x = float(i) / float(self.s_stripes);
+ p.fillRect(
+ self.s_left_margin,
+ (self.s_top_margin + (1-x)*plot_height),
+ self.s_stripe_width,
+ stripe_height,
+ QBrush(self.doubleToColor(x))
+ )
+ if i%self.s_step == 0:
+ p.drawText(
+ self.s_left_margin+self.s_stripe_width + self.s_spacing,
+ (self.s_top_margin + (1-x)*plot_height-(self.s_step-1)*stripe_height/2),
+ text_width,
+ self.s_step*stripe_height,
+ 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_height = (h-self.s_top_margin-self.s_bottom_margin)/len(m_color_vector)
+ # plot_height = h-self.s_top_margin-self.s_bottom_margin-stripe_height
+ #
+ # text_width = w - self.s_left_margin - self.s_stripe_width - 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_height + .1*stripe_height), m_stripe_width, (int) (.8*stripe_height), *color_it );
+ # // the label
+ # p.drawText( m_left_margin+m_stripe_width + m_spacing, (int) (m_top_margin + (1-x)*plot_height), text_width, stripe_height, 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_stripe_width +
+ self.s_spacing +
+ self.s_right_margin +
+ 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:
+ x = self.fontMetrics().width(desc)
+ if min_label_width < x:
+ min_label_width = x
+ w = (
+ self.s_left_margin +
+ self.s_stripe_width +
+ self.s_spacing +
+ self.s_right_margin +
+ min_label_width
+ )
+ h = fontMetrics().height() * len(m_color_vector)
+
+ self.setMinimumWidth(w)
+ self.setMaximumWidth(w)
+
+ self.setMinimumHeight(h)
+
+ def getLabelString(self, x):
+ return QString("%1").arg(x, 0, 'g', 2)
More information about the Avida-cvs
mailing list