[Avida-cvs] [Avida2-svn] r108 - trunk/source/python/AvidaGui2
kaben at myxo.css.msu.edu
kaben at myxo.css.msu.edu
Wed Apr 6 10:17:26 PDT 2005
Author: kaben
Date: 2005-04-06 13:17:26 -0400 (Wed, 06 Apr 2005)
New Revision: 108
Modified:
trunk/source/python/AvidaGui2/pyEduWorkspaceCtrl.py
trunk/source/python/AvidaGui2/pyGraphCtrl.py
trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py
Log:
* Added zooming and printing to graphs.
Modified: trunk/source/python/AvidaGui2/pyEduWorkspaceCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyEduWorkspaceCtrl.py 2005-04-06 17:16:15 UTC (rev 107)
+++ trunk/source/python/AvidaGui2/pyEduWorkspaceCtrl.py 2005-04-06 17:17:26 UTC (rev 108)
@@ -176,7 +176,8 @@
# public slot
def filePrint(self):
- print "pyEduWorkspaceCtrl.filePrint(): Not implemented yet"
+ print "pyEduWorkspaceCtrl.filePrint() emitting printGraphSig via self.m_session_mdl.m_session_mdtr.m_workspace_mdtr"
+ self.m_session_mdl.m_session_mdtr.m_workspace_mdtr.emit(PYSIGNAL("printGraphSig"), ())
# public slot
Modified: trunk/source/python/AvidaGui2/pyGraphCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyGraphCtrl.py 2005-04-06 17:16:15 UTC (rev 107)
+++ trunk/source/python/AvidaGui2/pyGraphCtrl.py 2005-04-06 17:17:26 UTC (rev 108)
@@ -4,10 +4,21 @@
from qwt import *
from pyGraphView import pyGraphView
-
class pyGraphCtrl(QwtPlot):
def __init__(self, *args):
QwtPlot.__init__(self, *args)
def construct(self, session_mdl):
- pass
+ self.setCanvasBackground(Qt.white)
+ self.m_zoomer = QwtPlotZoomer(
+ QwtPlot.xBottom,
+ QwtPlot.yLeft,
+ QwtPicker.DragSelection,
+ QwtPicker.AlwaysOff,
+ self.canvas())
+ self.m_zoomer.setZoomBase()
+ self.m_zoomer.setRubberBandPen(QPen(Qt.black))
+ # Configure zoomer for use with one-button mouse -- for OS X.
+ # - Click and drag to create a zoom rectangle;
+ # - Option-click to zoom-out to full view.
+ self.m_zoomer.initMousePattern(1)
Modified: trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py 2005-04-06 17:16:15 UTC (rev 107)
+++ trunk/source/python/AvidaGui2/pyOnePop_GraphCtrl.py 2005-04-06 17:17:26 UTC (rev 108)
@@ -7,7 +7,28 @@
from qt import *
from qwt import *
+class PrintFilter(QwtPlotPrintFilter):
+ def __init__(self):
+ QwtPlotPrintFilter.__init__(self)
+ def color(self, c, item, i):
+ if not (self.options() & QwtPlotPrintFilter.PrintCanvasBackground):
+ if item == QwtPlotPrintFilter.MajorGrid:
+ return Qt.darkGray
+ elif item == QwtPlotPrintFilter.MinorGrid:
+ return Qt.gray
+ if item == QwtPlotPrintFilter.Title:
+ return Qt.black
+ elif item == QwtPlotPrintFilter.AxisScale:
+ return Qt.black
+ elif item == QwtPlotPrintFilter.AxisTitle:
+ return Qt.black
+ return Qt.black
+ def font(self, f, item, i):
+ result = QFont(f)
+ result.setPointSize(int(f.pointSize()*1.25))
+ return result
+
class pyOnePop_GraphCtrl(pyOnePop_GraphView):
def __init__(self,parent = None,name = None,fl = 0):
@@ -33,30 +54,43 @@
self.m_y_array = zeros(2, Float)
self.m_graph_ctrl.setAxisTitle(QwtPlot.xBottom, "Time (updates)")
+ self.m_graph_ctrl.setAxisAutoScale(QwtPlot.xBottom)
self.modeActivatedSlot(self.m_combo_box.currentItem())
+ self.connect(
+ self.m_session_mdl.m_session_mdtr.m_workspace_mdtr, PYSIGNAL("printGraphSig"),
+ self.printGraphSlot)
+
def load(self, filename, colx, coly):
- init_file = cInitFile(cString(filename))
- init_file.Load()
- init_file.Compress()
+ 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)
+ else:
+ init_file = cInitFile(cString(filename))
+ init_file.Load()
+ init_file.Compress()
- self.m_x_array = zeros(init_file.GetNumLines(), Float)
- self.m_y_array = zeros(init_file.GetNumLines(), Float)
+ self.m_x_array = zeros(init_file.GetNumLines(), Float)
+ self.m_y_array = zeros(init_file.GetNumLines(), Float)
- for line_id in range(init_file.GetNumLines()):
- line = init_file.GetLine(line_id)
- self.m_x_array[line_id] = line.GetWord(colx - 1).AsDouble()
- self.m_y_array[line_id] = line.GetWord(coly - 1).AsDouble()
+ for line_id in range(init_file.GetNumLines()):
+ line = init_file.GetLine(line_id)
+ self.m_x_array[line_id] = line.GetWord(colx - 1).AsDouble()
+ self.m_y_array[line_id] = line.GetWord(coly - 1).AsDouble()
def modeActivatedSlot(self, index):
self.m_graph_ctrl.setTitle(self.m_avida_stats_interface.m_entries[index][0])
+ self.m_graph_ctrl.clear()
if index:
- self.m_graph_ctrl.clear()
- self.load(self.m_avida_stats_interface.m_entries[index][1], 1, self.m_avida_stats_interface.m_entries[index][2])
+ self.load(
+ self.m_avida_stats_interface.m_entries[index][1],
+ 1,
+ self.m_avida_stats_interface.m_entries[index][2]
+ )
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.replot()
+ self.m_graph_ctrl.replot()
def setAvidaSlot(self, avida):
old_avida = self.m_avida
@@ -88,4 +122,20 @@
)
if hasattr(self.m_graph_ctrl, "m_curve"):
self.m_graph_ctrl.setCurveData(self.m_graph_ctrl.m_curve, self.m_x_array, self.m_y_array)
+ # 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()
+
+ def printGraphSlot(self):
+ printer = QPrinter()
+ if printer.setup():
+ filter = PrintFilter()
+ if (QPrinter.GrayScale == printer.colorMode()):
+ filter.setOptions(QwtPlotPrintFilter.PrintAll & ~QwtPlotPrintFilter.PrintCanvasBackground)
+ self.m_graph_ctrl.printPlot(printer, filter)
+
More information about the Avida-cvs
mailing list