[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Select a File...



I've got the basic file opener window, but it launches from a panel with a button on it just as in the demo.  I've tried various things to only have the filedialog, but it always crashes.  Same for the the save window.
Ian
import  os
import  wx
wildcard = ".WAV Audio (*.wav)|*.wav|"\
           ".OGG Audio (*.ogg)|*.ogg|"\
           ".MP3 Audio (*.mp3)|*.mp3|"\
           ".MP4 Audio (*.mp4)|*.mp4|"\
           "All files (*.*)|*.*"
class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        b = wx.Button(self, -1, "Create and Show an OPEN FileDialog", (50,50))
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)

    def OnButton(self, evt):
        self.log.WriteText("CWD: %s\n" % os.getcwd())

        dlg = wx.FileDialog(
            self, message="Choose a file", defaultDir=os.getcwd(), 
            defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
            )

        if dlg.ShowModal() == wx.ID_OK:
            paths = dlg.GetPaths()

            self.log.WriteText('You selected %d files:' % len(paths))

            for path in paths:
                self.log.WriteText('           %s\n' % path)
##                fp = file("Data/commlink.txt", 'w')
##                fp.write(path)
##                fp.close()

        self.log.WriteText("CWD: %s\n" % os.getcwd())

        dlg.Destroy()

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])



import  os
import  wx
wildcard = ".WAV Audio (*.wav)|*.wav|"\
           ".OGG Audio (*.ogg)|*.ogg|"\
           ".MP3 Audio (*.mp3)|*.mp3|"\
           ".MP4 Audio (*.mp4)|*.mp4|"\
           "All files (*.*)|*.*"
class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        b = wx.Button(self, -1, "Create and Show a SAVE FileDialog", (50,90))
        self.Bind(wx.EVT_BUTTON, self.OnButton2, b)

    def OnButton2(self, evt):
        self.log.WriteText("CWD: %s\n" % os.getcwd())

        dlg = wx.FileDialog(
            self, message="Save file as ...", defaultDir=os.getcwd(), 
            defaultFile="", wildcard=wildcard, style=wx.SAVE
            )

        dlg.SetFilterIndex(2)

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            self.log.WriteText('You selected "%s"' % path)

            fp = file("Data/commlink.txt", 'w')
            fp.write(path)
            fp.close()

        self.log.WriteText("CWD: %s\n" % os.getcwd())

        dlg.Destroy()

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])