Is it possible to set the default directory for wx.FileDialog under Windows
8?
I tried "defaultDir=path" in the constructor and both
"dlg.SetDirectory(path)" and "dlg.SetPath(path+'/')" immediately after
creating the dialog but before "dlg.ShowModal()". In those three instances,
whatever I chose as "path" was overridden by the most recently used folder.
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-Directory-in-Windows-8-FileDialog-tp5719983.html
Sent from the wxPython-users mailing list archive at Nabble.com.
Does the dialog style exclude the wx.FD_CHANGE_DIR bit? If so, try removing that and send the path.
wx.FD_CHANGE_DIR seems to always change the cwd when using a FileDialog.
···
On Monday, January 27, 2014 8:27:15 PM UTC-6, Wilson Omesiete wrote:
Is it possible to set the default directory for wx.FileDialog under Windows
8?
I tried “defaultDir=path” in the constructor and both
“dlg.SetDirectory(path)” and “dlg.SetPath(path+‘/’)” immediately after
creating the dialog but before “dlg.ShowModal()”. In those three instances,
whatever I chose as “path” was overridden by the most recently used folder.
–
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-Directory-in-Windows-8-FileDialog-tp5719983.html
Sent from the wxPython-users mailing list archive at Nabble.com.
I did not specify the dialog style. I can't test this on a Windows 8 system
until tomorrow, but on 7, with no style specified, the default dialog did
not change the output from "print os.getcwd()".
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-Directory-in-Windows-8-FileDialog-tp5719983p5720003.html
Sent from the wxPython-users mailing list archive at Nabble.com.
I did not specify the dialog style. I can’t test this on a Windows 8 system
until tomorrow, but on 7, with no style specified, the default dialog did
not change the output from “print os.getcwd()”.
–
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-Directory-in-Windows-8-FileDialog-tp5719983p5720003.html
Sent from the wxPython-users mailing list archive at Nabble.com.
Something like this should work
···
On Thursday, January 30, 2014 6:14:57 PM UTC-6, Wilson Omesiete wrote:
tmpChangeDir = os.getcwd()
myPath = ‘some/path/I/want/to/set’
os.chdir(myPath)
Do dialog stuff. Don’t add wx.FD_CHANGE_DIR | to the style
dlg = wx.FileDialog(
self, message=“Choose a file”,
defaultDir=myPath,
defaultFile=“”,
wildcard=‘’,
style=wx.FD_OPEN | wx.FD_MULTIPLE |
wx.FD_FILE_MUST_EXIST |
wx.FD_PREVIEW
)
if dlg.ShowModal() == wx.ID_OK:
# Do something…
dlg.Destroy()
os.chdir(tmpChangeDir) # Change cwd back to what it was
Thank you for the suggestion, but unfortunately that did not work.
I am guessing this has something to do with how the file dialog class
interfaces with windows... I am guessing that deriving a child class and
simply setting a timer to forcibly change the directory after creation might
work, and I'm going to try that...
class customFileDialog(wx.FileDialog):
def __init__(self, parent, message=wx.FileSelectorPromptStr,
defaultDir="", defaultFile="", wildcard=wx.FileSelectorDefaultWildcardStr,
style=wx.FD_DEFAULT_STYLE, pos=wx.DefaultPosition):
wx.FileDialog.__init__(self, parent, message, defaultDir,
defaultFile, wildcard, style, pos)
onWindows8 = True
DIRECTORY_CHANGE_DELAY = 2000
self.defaultDirectory = defaultDir
self.timeChangeDirectory = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onChangeToDefaultDirectory,
self.timeChangeDirectory)
if onWindows8:
self.timeChangeDirectory.Start(DIRECTORY_CHANGE_DELAY, True)
def onChangeToDefaultDirectory(self, e):
print self.defaultDirectory
self.SetDirectory(self.defaultDirectory)
... That did not work. The directory prints but no change happens. I need to
find the method to actually change the directory in the dialog while it's
displayed if one exists.
Or find a better solution, this one seems unfavorable even if it ends up
working.
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-Directory-in-Windows-8-FileDialog-tp5719983p5720027.html
Sent from the wxPython-users mailing list archive at Nabble.com.
This works on either system...
class customFileDialog(wx.FileDialog):
def __init__(self, parent, message=wx.FileSelectorPromptStr,
defaultDir="", defaultFile="", wildcard=wx.FileSelectorDefaultWildcardStr,
style=wx.FD_DEFAULT_STYLE, pos=wx.DefaultPosition):
wx.FileDialog.__init__(self, parent, message, defaultDir,
defaultFile, wildcard, style, pos)
onWindows8 = True
DIRECTORY_CHANGE_DELAY = 1
self.defaultDirectory = defaultDir
self.timeChangeDirectory = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onChangeToDefaultDirectory,
self.timeChangeDirectory)
if onWindows8:
self.timeChangeDirectory.Start(DIRECTORY_CHANGE_DELAY, True)
def onChangeToDefaultDirectory(self, e):
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys(self.defaultDirectory.replace("/", "\\")+"~" )
...but it relies on sending keypresses to the dialog with PyWin32. It
happens after a single millisecond, so the user probably won't interfere,
but they might. The 'onWindows8' tag should of course be set somewhere else
before this.
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-Directory-in-Windows-8-FileDialog-tp5719983p5720029.html
Sent from the wxPython-users mailing list archive at Nabble.com.