[Avida-SVN] r2622 - branches/developers/avida-edward/source/python/AvidaGui2
kaben at myxo.css.msu.edu
kaben at myxo.css.msu.edu
Sun Jun 8 22:13:03 PDT 2008
Author: kaben
Date: 2008-06-09 01:13:03 -0400 (Mon, 09 Jun 2008)
New Revision: 2622
Modified:
branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py
branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrganismCtrl.py
Log:
In Avida-ED, added saving and printing of image of organism viewer. Before
either saving or printing, user is presented with a list of checkboxes
corresponding to things to print: the organism, statistics about the organism,
the organism timeline. When the user saves an image of the organism, the
default file name includes the number of the organism's current execution step.
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py 2008-06-09 02:21:33 UTC (rev 2621)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrg_ScopeCtrl.py 2008-06-09 05:13:03 UTC (rev 2622)
@@ -3,7 +3,8 @@
from pyOneOrg_ScopeView import pyOneOrg_ScopeView
from pyTimeline import pyTimeline
from descr import *
-import qt
+from qt import *
+#import qt
import os
class pyOneOrg_ScopeCtrl(pyOneOrg_ScopeView):
@@ -21,50 +22,50 @@
# Use background color so timeline meter doesn't show up
self.m_timeline.setFillColor(self.m_timeline.colorGroup().background())
# self.m_timeline.setScalePosition(pyTimeline.None)
- self.m_timer = qt.QTimer()
- self.m_next = qt.QTimer()
+ self.m_timer = QTimer()
+ self.m_next = QTimer()
self.m_timer_interval = 100
self.m_organism_scope_ctrl.m_timeline = self.m_timeline
self.connect(
- self.m_execution_step_slider, qt.SIGNAL("valueChanged(int)"),
+ self.m_execution_step_slider, SIGNAL("valueChanged(int)"),
self.sliderValueChangedSlot)
self.connect(
- self.m_execution_step_slider, qt.SIGNAL("sliderMoved(int)"),
+ self.m_execution_step_slider, SIGNAL("sliderMoved(int)"),
self.sliderMovedSlot)
self.connect(
- self.m_organism_scope_ctrl, qt.PYSIGNAL("gestationTimeChangedSig"),
+ self.m_organism_scope_ctrl, PYSIGNAL("gestationTimeChangedSig"),
self.gestationTimeChangedSlot)
self.connect(
- self.m_organism_scope_ctrl, qt.PYSIGNAL("executionStepResetSig"),
+ self.m_organism_scope_ctrl, PYSIGNAL("executionStepResetSig"),
self.executionStepResetSlot)
self.connect(
- self.m_organism_scope_ctrl, qt.PYSIGNAL("frameShownSig"),
+ self.m_organism_scope_ctrl, PYSIGNAL("frameShownSig"),
self.m_organism_data_ctrl.frameShownSlot)
self.connect(
- self.m_analyze_controls_ctrl.m_rewind_btn, qt.SIGNAL("clicked()"),
+ self.m_analyze_controls_ctrl.m_rewind_btn, SIGNAL("clicked()"),
self.rewindSlot)
self.connect(
- self.m_analyze_controls_ctrl.m_cue_btn, qt.SIGNAL("clicked()"),
+ self.m_analyze_controls_ctrl.m_cue_btn, SIGNAL("clicked()"),
self.cueSlot)
self.connect(
- self.m_analyze_controls_ctrl.m_play_btn, qt.SIGNAL("clicked()"),
+ self.m_analyze_controls_ctrl.m_play_btn, SIGNAL("clicked()"),
self.playSlot)
self.connect(
- self.m_analyze_controls_ctrl.m_pause_btn, qt.SIGNAL("clicked()"),
+ self.m_analyze_controls_ctrl.m_pause_btn, SIGNAL("clicked()"),
self.pauseSlot)
self.connect(
- self.m_analyze_controls_ctrl.m_prev_btn, qt.SIGNAL("clicked()"),
+ self.m_analyze_controls_ctrl.m_prev_btn, SIGNAL("clicked()"),
self.backSlot)
self.connect(
- self.m_analyze_controls_ctrl.m_next_btn, qt.SIGNAL("clicked()"),
+ self.m_analyze_controls_ctrl.m_next_btn, SIGNAL("clicked()"),
self.advanceSlot)
- self.connect(self.m_timer, qt.SIGNAL("timeout()"), self.advanceSlot)
+ self.connect(self.m_timer, SIGNAL("timeout()"), self.advanceSlot)
def sliderValueChangedSlot(self, frame_number):
@@ -84,7 +85,7 @@
self.m_execution_step_slider.setValue(execution_step)
self.m_timeline.setValue(execution_step)
# This may be redundant (I'm not sure). @kgn
- self.m_execution_step_slider.emit(qt.SIGNAL("valueChanged(int)"),(execution_step,))
+ self.m_execution_step_slider.emit(SIGNAL("valueChanged(int)"),(execution_step,))
def sliderMovedSlot(self, frame_number):
descr("pyOneOrg_ScopeCtrl.sliderMovedSlot().")
@@ -129,3 +130,30 @@
else:
self.m_execution_step_slider.setValue(slider_value + 1)
self.m_timeline.setValue(slider_value + 1)
+
+ def getOrganismPixmap(self):
+ "Return QPixmap of organism"
+ #height = self.m_organism_scope_ctrl.height()
+ # Hide the scrollbars so they aren't painted
+ #self.m_petri_dish_ctrl.m_petri_dish_ctrl_h_scrollBar.hide()
+ #self.m_petri_dish_ctrl.m_petri_dish_ctrl_v_scrollBar.hide()
+ pix = QPixmap.grabWidget(
+ self.m_organism_scope_ctrl,
+ 0, 0,
+ self.m_organism_scope_ctrl.width(),
+ self.m_organism_scope_ctrl.height()
+ )
+ #self.m_petri_dish_ctrl.m_petri_dish_ctrl_h_scrollBar.show()
+ #self.m_petri_dish_ctrl.m_petri_dish_ctrl_v_scrollBar.show()
+ #scale_pix = QPixmap.grabWidget(self.m_gradient_scale_ctrl, 0, 0,
+ # self.m_gradient_scale_ctrl.width(),
+ # self.m_gradient_scale_ctrl.height())
+ #p = QPixmap(max(self.m_petri_dish_ctrl.m_canvas_view.width(),
+ # self.m_gradient_scale_ctrl.width()),
+ # dish_height + self.m_gradient_scale_ctrl.height())
+ #painter = QPainter(p)
+ #painter.drawPixmap(0, 0, dish_pix)
+ #painter.drawPixmap(0, dish_height, scale_pix)
+ #painter.end()
+ return pix
+
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrganismCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrganismCtrl.py 2008-06-09 02:21:33 UTC (rev 2621)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOneOrganismCtrl.py 2008-06-09 05:13:03 UTC (rev 2622)
@@ -4,6 +4,8 @@
from qt import *
from pyOneOrganismView import pyOneOrganismView
+from pyButtonListDialog import pyButtonListDialog
+from pyImageFileDialog import pyImageFileDialog
import os.path
@@ -50,14 +52,131 @@
PYSIGNAL("printSig"),
self.printOrgSlot)
+
+ def generatePixmaps(self, objects):
+ pixmap = QPixmap()
+
+ # Size the pixmap to hold the requested objects.
+ if 'Organism' in objects:
+ org_pix = QPixmap.grabWidget(
+ self.m_one_org_scope_ctrl.m_organism_scope_ctrl,
+ 0, 0,
+ self.m_one_org_scope_ctrl.m_organism_scope_ctrl.width(),
+ self.m_one_org_scope_ctrl.m_organism_scope_ctrl.height()
+ )
+ pixmap.resize(
+ pixmap.width() + org_pix.width(),
+ pixmap.height() + org_pix.height()
+ )
+ if 'Statistics' in objects:
+ data_pix = QPixmap.grabWidget(
+ self.m_one_org_scope_ctrl.m_organism_data_ctrl,
+ 0, 0,
+ self.m_one_org_scope_ctrl.m_organism_data_ctrl.width(),
+ self.m_one_org_scope_ctrl.m_organism_data_ctrl.height()
+ )
+ data_pix_x = pixmap.width()
+ pixmap.resize(
+ data_pix_x + data_pix.width(),
+ max(pixmap.height(), data_pix.height())
+ )
+ if 'Timeline' in objects:
+ timeline_pix = QPixmap.grabWidget(
+ self.m_one_org_scope_ctrl.m_timeline,
+ 0, 0,
+ self.m_one_org_scope_ctrl.m_timeline.width(),
+ self.m_one_org_scope_ctrl.m_timeline.height()
+ )
+ timeline_pix_y = pixmap.height()
+ pixmap.resize(
+ max(pixmap.width(), timeline_pix.width()),
+ timeline_pix_y + timeline_pix.height()
+ )
+ slider_pix = QPixmap.grabWidget(
+ self.m_one_org_scope_ctrl.m_execution_step_slider,
+ 0, 0,
+ self.m_one_org_scope_ctrl.m_execution_step_slider.width(),
+ self.m_one_org_scope_ctrl.m_execution_step_slider.height()
+ )
+ slider_pix_y = pixmap.height()
+ pixmap.resize(
+ max(pixmap.width(), slider_pix.width()),
+ slider_pix_y + slider_pix.height()
+ )
+
+
+ # Clear the pixmap.
+ pixmap.fill()
+
+ # Paint the pixmap.
+ painter = QPainter(pixmap)
+ if 'Organism' in objects:
+ descr('Organism in objects:', objects)
+ painter.drawPixmap(0, 0, org_pix)
+ if 'Statistics' in objects:
+ descr('Statistics in objects:', objects)
+ painter.drawPixmap(data_pix_x, 0, data_pix)
+ if 'Timeline' in objects:
+ descr('Timeline in objects:', objects)
+ painter.drawPixmap(0, timeline_pix_y, timeline_pix)
+ painter.drawPixmap(0, slider_pix_y, slider_pix)
+
+ return pixmap
+
+
def saveImagesSlot(self):
- """Place holder for code to save image of organism viewer"""
- info("You can not save an image of the organism in the current version of Avida-ED.")
+ "Save organism viewer to image file"
+ dlg = pyButtonListDialog(
+ "Save Image",
+ "Choose objects to save",
+ ["Organism", "Statistics", "Timeline"],
+ True
+ )
+ objects = dlg.showDialog()
+ if len(objects) == 0:
+ return
+ # Generate pixmap containing requested objects.
+ pixmap = self.generatePixmaps(objects)
+
+ # Ask user for name of image file to save.
+ img_dlg = pyImageFileDialog()
+ name = str(self.m_one_org_scope_ctrl.m_organism_scope_ctrl.m_organism_name)
+ execution_step = self.m_one_org_scope_ctrl.m_execution_step_slider.value()
+ filename, type = img_dlg.saveImageDialog(
+ name +
+ "-organism-step-" +
+ str(execution_step)
+ )
+
+ # Save pixmap to image file.
+ if filename:
+ pixmap.save(filename, type, 100)
+
+
def printOrgSlot(self):
- """Place holder for code to print image of organism viewer"""
- info("You can not print an image of the organism in the current version of Avida-ED.")
+ """Print image of organism viewer"""
+ dlg = pyButtonListDialog(
+ "Save Image",
+ "Choose objects to save",
+ ["Organism", "Statistics", "Timeline"],
+ True
+ )
+ objects = dlg.showDialog()
+ if len(objects) == 0:
+ return
+ # Generate pixmap containing requested objects.
+ pixmap = self.generatePixmaps(objects)
+
+ # Print pixmap.
+ printer = QPrinter()
+ if printer.setup():
+ painter = QPainter(printer)
+ painter.drawPixmap(0, 0, pixmap)
+ painter.end()
+
+
def setOneOrganismViewNameLabelTextSlot(self, name):
self.m_organism_name_label.setText(name)
More information about the Avida-cvs
mailing list