There's an irritating UI bug in the export dialog where entering a
filename without the correct extension for the file type being exported
causes the export to needlessly fail. Attached is a patch which
automatically appends the correct extension to the file when one is not
supplied. It should deal with the case of multiple extensions per type
gracefully too (it will append the first known extension for the
selected type). Note that there are other possible solutions to this
problem (like passing a type name to the function that actually performs
the export) but I think this is consistent with the save behavior and
with user expectations for the common case (except, perhaps on the Mac
which actually has a sane way of mapping files to applications).
I've also rolled in a few improvements to the directory handling so that
when a file is opened from the command line or via drag and drop the
window it opens into picks up the working directory from the opened
file. I've kept the export directory seperate from the save/open
directory because I find that's what I need most often. Feel free to
disagree with that working pattern :)
--
"As soon as people come up with a measurable substitute for whatever
it is they care about they start treating it as more important than the
real thing" -Boris Zbarsky
? dialogs/__init__.pyc
? dialogs/aboutdialog.pyc
? dialogs/dataeditdialog.pyc
? dialogs/exceptiondialog.pyc
? dialogs/importdialog.pyc
? dialogs/reloaddata.pyc
? document/__init__.pyc
? document/commandinterface.pyc
? document/commandinterpreter.pyc
? document/doc.pyc
? document/simpleread.pyc
? setting/__init__.pyc
? setting/collections.pyc
? setting/controls.pyc
? setting/setting.pyc
? setting/settingdb.pyc
? setting/settings.pyc
? utils/__init__.pyc
? utils/fitlm.pyc
? utils/points.pyc
? utils/pref.pyc
? utils/preftypes.pyc
? utils/textrender.pyc
? utils/utilfuncs.pyc
? utils/version.pyc
? widgets/__init__.pyc
? widgets/axis.pyc
? widgets/axisticks.pyc
? widgets/containers.pyc
? widgets/fit.pyc
? widgets/graph.pyc
? widgets/key.pyc
? widgets/page.pyc
? widgets/plotters.pyc
? widgets/root.pyc
? widgets/widget.pyc
? widgets/widgetfactory.pyc
? windows/__init__.pyc
? windows/action.pyc
? windows/consolewindow.pyc
? windows/mainwindow.pyc
? windows/plotwindow.pyc
? windows/treeeditwindow.pyc
Index: windows/mainwindow.py
===================================================================
RCS file: /cvs/veusz/veusz/windows/mainwindow.py,v
retrieving revision 1.38
diff -u -r1.38 mainwindow.py
--- windows/mainwindow.py 13 Jun 2005 19:02:27 -0000 1.38
+++ windows/mainwindow.py 26 Jun 2005 20:17:30 -0000
@@ -83,7 +83,8 @@
self.statusBar().addWidget(self.pagelabel)
self.dirname = ''
-
+ self.exportDir = ''
+
self.connect( self.plot, qt.PYSIGNAL("sigUpdatePage"),
self.slotUpdatePage )
@@ -137,7 +138,7 @@
else:
CreateWindow(files[0])
for filename in files[1:]:
- CreateWindow(filename, self)
+ CreateWindow(filename)
def _getVeuszFiles(self, event):
@@ -409,7 +410,7 @@
def slotFileNew(self):
"""New file."""
- CreateWindow(opener=self)
+ CreateWindow()
def slotFileSave(self):
"""Save file."""
@@ -488,9 +489,10 @@
# show busy cursor
qt.QApplication.setOverrideCursor( qt.QCursor(qt.Qt.WaitCursor) )
-
+
try:
- # load the document in a new window
+ # load the document in the current window
+ self.dirname = os.path.dirname(filename)
self.interpreter.Load(filename)
self.document.setModified(False)
self.filename = filename
@@ -540,26 +542,57 @@
self.openFile(filename)
else:
# create a new window
- CreateWindow(filename, self)
+ CreateWindow(filename)
def slotFileExport(self):
"""Export the graph."""
+ #XXX - This should be disabled if the page count is 0
+
+ #File types we can export to in the form ([extensions], Name)
+ formats = [(["eps"], "Encapsulated Postscript"),
+ (["png"], "Portable Network Graphics")]
+
+ #Create a mapping between a format string and extensions
+ filterToExt = {}
+
fd = qt.QFileDialog(self, 'export dialog', True)
- fd.setDir( self.dirname )
+ if not self.exportDir:
+ fd.setDir( self.dirname )
+ else:
+ fd.setDir( self.exportDir )
+
fd.setMode( qt.QFileDialog.AnyFile )
- fd.setFilters( "Encapsulated Postscript (*.eps);;"
- "Portable Network Graphics (*.png)" )
+
+ filters = []
+ for format in formats:
+ extensions = " ".join(["(*." + item + ")"
+ for item in format[0]])
+ #join eveything together to make a filter string
+ filterStr = " ".join([format[1], extensions])
+ filterToExt[filterStr] = format[0]
+ filters.append(filterStr)
+
+ fd.setFilters(";;".join(filters))
+
fd.setCaption('Export')
if fd.exec_loop() == qt.QDialog.Accepted:
# save directory for next time
- self.dirname = fd.dir()
+ self.exportDir = fd.dir()
+ filterUsed = str(fd.selectedFilter())
+ validExts = filterToExt[filterUsed]
+
# show busy cursor
qt.QApplication.setOverrideCursor( qt.QCursor(qt.Qt.WaitCursor) )
filename = unicode( fd.selectedFile() )
+
+ #Add a default extension if one isn't supplied
+ if not (filename.split(".")[-1] in validExts):
+ filename = filename + "." + validExts[0]
+
try:
self.document.export(filename, self.plot.getPageNumber())
except (IOError, RuntimeError), inst:
@@ -675,12 +708,10 @@
self.actions['viewprevpage'].setEnabled( number != 0 )
self.actions['viewnextpage'].setEnabled( number < np-1 )
-def CreateWindow(filename=None, opener=None):
+def CreateWindow(filename=None):
"""Window factory function"""
win = MainWindow()
win.show()
if filename:
win.openFile(filename)
- if opener:
- win.dirname = opener.dirname
return win