summaryrefslogtreecommitdiffstats
path: root/barchart
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2009-03-31 14:35:10 +0200
committerDavid Boddie <dboddie@trolltech.com>2009-03-31 14:35:10 +0200
commit3a5db68af19b5646bafc70d81b9724943084befc (patch)
tree8a3c36440de4104dbf2afcdf026cc321e4653b15 /barchart
parentdf831ef41ecef945b3fbda8b1106240417bc3300 (diff)
Updated the example using feedback from Thulio Costa.
Diffstat (limited to 'barchart')
-rw-r--r--barchart/barchart.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/barchart/barchart.py b/barchart/barchart.py
index 67a2e86..a8b7735 100644
--- a/barchart/barchart.py
+++ b/barchart/barchart.py
@@ -22,7 +22,7 @@
#############################################################################
import sys
-from PyQt4.QtCore import QPointF, QSize, Qt
+from PyQt4.QtCore import QFile, QPointF, QSize, Qt
from PyQt4.QtGui import *
class BarChart(QWidget):
@@ -31,6 +31,7 @@ class BarChart(QWidget):
QWidget.__init__(self, parent)
self.suffix = ""
+ self.path = ""
def showEvent(self, event):
@@ -109,11 +110,16 @@ class BarChart(QWidget):
event.ignore()
def mousePressEvent(self, event):
- fname = QFileDialog.getSaveFileName(self, "Save", ".", "*.png", 0, 0)
- if fname.length > 0:
+ fname = QFileDialog.getSaveFileName(self, self.tr("Save"), self.path,
+ self.tr("PNG files (*.png)"))
+ if not fname.isEmpty():
img = QImage(self.size(), QImage.Format_ARGB32_Premultiplied)
self.render(img)
- img.save(QFile(fname))
+ if img.save(QFile(fname)):
+ self.path = fname
+ else:
+ QMessageBox.warning(self, self.tr("Failed to save image"),
+ self.tr("The specified image could not be saved."))
if __name__ == "__main__":