]> granicus.if.org Git - python/commitdiff
Properly deal with tuples in Open._fixresult. Fixes bug reported in
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 14 Jun 2003 21:34:32 +0000 (21:34 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 14 Jun 2003 21:34:32 +0000 (21:34 +0000)
follow-up to #621891.

Lib/lib-tk/tkFileDialog.py
Modules/_tkinter.c

index 63487d2037b472089283e0c860bbd827b8695a02..fb0014c5daea3788784a1106abcc10a923bf42f6 100644 (file)
@@ -76,6 +76,21 @@ class Open(_Dialog):
 
     command = "tk_getOpenFile"
 
+    def _fixresult(self, widget, result):
+        if isinstance(result, tuple):
+            # multiple results:
+            result = tuple([getattr(r, "string", r) for r in result])
+            if result:
+                import os
+                path, file = os.path.split(result[0])
+                self.options["initialdir"] = path
+                # don't set initialfile or filename, as we have multiple of these
+            return result
+        if not widget.tk.wantobjects() and "multiple" in self.options:
+            # Need to split result explicitly
+            return self._fixresult(widget, widget.tk.splitlist(result))
+        return _Dialog._fixresult(widget, result)
+
 class SaveAs(_Dialog):
     "Ask for a filename to save as"
 
@@ -115,9 +130,7 @@ def askopenfilenames(**options):
     cancel button selected
     """
     options["multiple"]=1
-    files=Open(**options).show()
-    return files.split()
-
+    return Open(**options).show()
 
 # FIXME: are the following  perhaps a bit too convenient?
 
index 5851372468a80903a0dc5409ee38ccb30aba0d04..5253a106032dcce1b7adc5c66c2f6033b3cf1a1f 100644 (file)
@@ -2604,9 +2604,11 @@ static PyObject *
 Tkapp_WantObjects(PyObject *self, PyObject *args)
 {
 
-       int wantobjects;
-       if (!PyArg_ParseTuple(args, "i:wantobjects", &wantobjects))
+       int wantobjects = -1;
+       if (!PyArg_ParseTuple(args, "|i:wantobjects", &wantobjects))
                return NULL;
+       if (wantobjects == -1)
+               return PyBool_FromLong(((TkappObject*)self)->wantobjects);
        ((TkappObject*)self)->wantobjects = wantobjects;
 
        Py_INCREF(Py_None);