13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>wxPython</strong> griptshttp://www.zetcode.com/wxpython/gripts/self.DoOpenFile()elif val == wx.ID_CANCEL:dlg.Destroy()else:self.DoOpenFile()else:self.DoOpenFile()def DoOpenFile(self):wcd = 'All files (*)|*|Editor files (*.ef)|*.ef|'dir = os.getcwd()open_dlg = wx.FileDialog(self, message='Choose a file', defaultDir=dir, defaultFile='',wildcard=wcd, style=wx.OPEN|wx.CHANGE_DIR)if open_dlg.ShowModal() == wx.ID_OK:path = open_dlg.GetPath()try:file = open(path, 'r')text = file.read()file.close()if self.text.GetLastPosition():self.text.Clear()self.text.WriteText(text)self.last_name_saved = pathself.statusbar.SetStatusText('', 1)self.modify = Falseexcept IOError, error:dlg = wx.MessageDialog(self, 'Error opening file\n' + str(error))dlg.ShowModal()except UnicodeDecodeError, error:dlg = wx.MessageDialog(self, 'Error opening file\n' + str(error))dlg.ShowModal()open_dlg.Destroy()def OnSaveFile(self, event):if self.last_name_saved:try:file = open(self.last_name_saved, 'w')text = self.text.GetValue()file.write(text)file.close()self.statusbar.SetStatusText(os.path.basename(self.last_name_saved) + ' saved',self.modify = Falseself.statusbar.SetStatusText('', 1)except IOError, error:dlg = wx.MessageDialog(self, 'Error saving file\n' + str(error))dlg.ShowModal()else:self.OnSaveAsFile(event)def OnSaveAsFile(self, event):wcd='All files(*)|*|Editor files (*.ef)|*.ef|'dir = os.getcwd()save_dlg = wx.FileDialog(self, message='Save file as...', defaultDir=dir, defaultFile=''wildcard=wcd, style=wx.SAVE | wx.OVERWRITE_PROMPT)if save_dlg.ShowModal() == wx.ID_OK:path = save_dlg.GetPath()try:file = open(path, 'w')text = self.text.GetValue()file.write(text)6 de 12 27/04/2008 1:09

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!