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

gerrishj@myxo.css.msu.edu gerrishj at myxo.css.msu.edu
Thu Jun 8 14:09:26 PDT 2006


Author: gerrishj
Date: 2006-06-08 17:09:26 -0400 (Thu, 08 Jun 2006)
New Revision: 740

Added:
   branches/developers/avida-edward/source/python/AvidaGui2/pyImageFileDialog.py
Modified:
   branches/developers/avida-edward/source/python/AvidaGui2/pyGraphCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py
   branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py
Log:
Moved image saving file save dialog into pyImageFileDialog.
Added image saving to analyze view.


Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyGraphCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyGraphCtrl.py	2006-06-07 15:45:15 UTC (rev 739)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyGraphCtrl.py	2006-06-08 21:09:26 UTC (rev 740)
@@ -2,7 +2,6 @@
 
 from qt import *
 from qwt import *
-from pyGraphView import pyGraphView
 
 class pyGraphCtrl(QwtPlot):
 
@@ -25,6 +24,12 @@
     # - Option-click to zoom-out to full view.
     self.m_zoomer.initMousePattern(1)
 
+  def saveImage(self, filename, type):
+    "Save image of graph to file"
+    p = QPixmap.grabWidget(self, 0, 0, self.width(), self.height())
+    p.save(filename, type, 100)
+
+
 class PrintFilter(QwtPlotPrintFilter):
   def __init__(self):
     QwtPlotPrintFilter.__init__(self)

Added: branches/developers/avida-edward/source/python/AvidaGui2/pyImageFileDialog.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyImageFileDialog.py	2006-06-07 15:45:15 UTC (rev 739)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyImageFileDialog.py	2006-06-08 21:09:26 UTC (rev 740)
@@ -0,0 +1,24 @@
+from qt import QFileDialog
+
+class pyImageFileDialog(QFileDialog):
+
+  def saveImageDialog(self):
+    """Dialog that lets user select where to save images.
+    Returns filename and filetype."""
+    # Let user select file format
+    dialog_caption = "Export Image"
+    fd = self.getSaveFileName("", "JPEG (*.jpg);;PNG (*.png)", None,
+                              "Save As", dialog_caption)
+    filename = str(fd)
+    if filename == "":
+      return
+
+    if filename[-4:].lower() == ".jpg":
+      type = "JPEG"
+    elif filename[-4:].lower() == ".png":
+      type = "PNG"
+    else:
+      filename += ".jpg"
+      type = "JPEG"
+
+    return filename, type

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py	2006-06-07 15:45:15 UTC (rev 739)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOneAnalyzeCtrl.py	2006-06-08 21:09:26 UTC (rev 740)
@@ -4,6 +4,7 @@
 
 from qt import *
 from pyOneAnalyzeView import pyOneAnalyzeView
+from pyImageFileDialog import pyImageFileDialog
 import os.path
 
 class pyOneAnalyzeCtrl(pyOneAnalyzeView):
@@ -35,6 +36,10 @@
     descr()
     self.disconnect(
       self.m_session_mdl.m_session_mdtr,
+      PYSIGNAL("saveImagesSig"),
+      self.saveImagesSlot)
+    self.disconnect(
+      self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("printSig"),
       self.m_one_ana_graph_ctrl.printSlot)
     # Disconnect export signal
@@ -47,6 +52,10 @@
     descr()
     self.connect(
       self.m_session_mdl.m_session_mdtr,
+      PYSIGNAL("saveImagesSig"),
+      self.saveImagesSlot)
+    self.connect(
+      self.m_session_mdl.m_session_mdtr,
       PYSIGNAL("printSig"),
       self.m_one_ana_graph_ctrl.printSlot)
     # Connect export
@@ -66,7 +75,6 @@
         e.acceptAction(True)
         descr("accepted.")
 
-
   def dropEvent( self, e ):
     freezer_item_name = QString()
     if ( QTextDrag.decode( e, freezer_item_name ) ) :
@@ -83,6 +91,9 @@
       if self.isVisible():
         self.emit(PYSIGNAL("freezerItemDoubleClickedOnInOneAnaSig"), 
           (freezer_item_name,))
-      
 
-
+  def saveImagesSlot(self):
+    "Save image of graph"
+    dlg = pyImageFileDialog()
+    filename, type = dlg.saveImageDialog()
+    self.m_one_ana_graph_ctrl.m_graph_ctrl.saveImage(filename, type)

Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py	2006-06-07 15:45:15 UTC (rev 739)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOnePopulationCtrl.py	2006-06-08 21:09:26 UTC (rev 740)
@@ -7,6 +7,7 @@
 from pyOnePopulationView import pyOnePopulationView
 from pyButtonListDialog import pyButtonListDialog
 from pyGraphCtrl import PrintFilter
+from pyImageFileDialog import pyImageFileDialog
 import os.path
 
 class pyOnePopulationCtrl(pyOnePopulationView):
@@ -125,36 +126,19 @@
 
   def saveImagesSlot(self):
     "Save petri dish or graph to image file"
-    # Let user select which image to save
     dlg = pyButtonListDialog("Save Image", "Choose object to save",
                              ["Petri Dish", "Graph"])
     res = dlg.showDialog()
 
-    # Let user select file format
-    dialog_caption = "Export Image"
-    fd = QFileDialog.getSaveFileName("", "JPEG (*.jpg);;PNG (*.png)", None,
-                                     "Save As", dialog_caption)
-    filename = str(fd)
-    if filename == "":
-      return
+    img_dlg = pyImageFileDialog()
+    filename, type = img_dlg.saveImageDialog()
 
-    if filename[-4:].lower() == ".jpg":
-      type = "JPEG"
-    elif filename[-4:].lower() == ".png":
-      type = "PNG"
-    else:
-      filename += ".jpg"
-      type = "JPEG"
-
     # Save the image
     if res[0] == "Petri Dish":
       p = self.m_one_pop_petri_dish_ctrl.getPetriDishPixmap()
       p.save(filename, type, 100)
     else:
-      p = QPixmap.grabWidget(self.m_one_pop_graph_ctrl.m_graph_ctrl, 0, 0,
-                             self.m_one_pop_graph_ctrl.m_graph_ctrl.width(),
-                             self.m_one_pop_graph_ctrl.m_graph_ctrl.height())
-      p.save(filename, type, 100)
+      self.m_one_pop_graph_ctrl.m_graph_ctrl.saveImage(filename, type)
 
   def printSlot(self):
     "Let user choose what object to print and send signal to appropriate slot"




More information about the Avida-cvs mailing list