i am trying to get wx.DirDialog added into a bigger program. the
function seems to work.(uncomment the print line and it returns the
path ...) but after clicking the button, calling the function, the
program cannot be closed by thicking the x in top right corner. (on
windows anyway)i striped the bigger one down some to try to just show
the problem. the def folderdialog(): is new. i started with page 272
of the wxpython in action book. through testing it seems to not work
well to have the print line in the def, but ok to do in the button
click. it does not appear to hang as it goes from
self.button1.SetLabel("Doing Backup") to self.button1.SetLabel("Backup
All"). yes for this snipet gridsizer is probably overkill, but its
needed for the bigger part. and as i do not understand wx enough..
import wx,os,string,shutil,getpass
from datetime import *
def folderdialog():
app = wx.App()
dialog = wx.DirDialog(None, "Choose a directory :", style=1 )
if dialog.ShowModal() == wx.ID_OK:
chosepath = dialog.GetPath()
dialog.Destroy()
return chosepath
class MyForm(wx.Frame):
"""make a frame, inherits wx.Frame"""
def __init__(self):
# create a frame, no parent, default to wxID_ANY
wx.Frame.__init__(self, None, wx.ID_ANY, title="FacBac",
pos=(300, 150), size=(500, 200))
self.SetBackgroundColour("purple")
panel = wx.Panel(self, wx.ID_ANY)
self.title1 = wx.StaticText(panel, wx.ID_ANY, "Backup")
self.title2 = wx.StaticText(panel, wx.ID_ANY, "Restore")
self.button1 = wx.Button(panel, id=-1, label='Backup ALL')
self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
self.button1.SetToolTip(wx.ToolTip("this will backup your
whole folder"))
# ------------
gridSizer = wx.GridSizer(rows=4, cols=2, hgap=5, vgap=5)
gridSizer.Add(self.title1, 0, wx.ALL|wx.ALIGN_CENTER, 5)
gridSizer.Add(self.title2, 0, wx.ALL|wx.ALIGN_CENTER, 5)
# This is a spacer
#gridSizer.Add((20, -1), proportion=1)
gridSizer.Add(self.button1, 0, wx.ALL|wx.EXPAND, 5)
# ------------
topSizer = wx.BoxSizer(wx.VERTICAL)
topSizer.Add(gridSizer, 0, wx.ALL|wx.EXPAND, 5)
# ------------
# SetSizeHints(minW, minH, maxW, maxH)
self.SetSizeHints(500,200,500,200)
panel.SetSizer(topSizer)
topSizer.Fit(self)
···
#-----------------------------------------------------------------
#backup all button
def button1Click(self, event):
self.button1.SetLabel("Doing Backup")
chosepath = folderdialog()
#print chosepath
self.button1.SetLabel("Backup All")
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
#import wx.lib.inspection
#wx.lib.inspection.InspectionTool().Show()
app.MainLoop()