|
Programmer
Join Date: Sep 2005
Location: Anchorage, Alaska
Posts: 37
Rep Power: 0 
|
help on save and save as methods
I've been working on this kind of text editor program and I can't figure out how to actually save the date entered into the editor with the save and saveas methods.
heres the two methods that I wrote using other examples from the wxPython site.
def OnSave(self, event):
""" Save a file"""
self.dirname = ''
fDialog = wx.FileDialog(self, "Choose a file", self.dirname, "*.*", wx.SAVE)
if fDialog.ShowModal() == wx.ID_OK:
self.filename = fDialog.GetFilename()
self.dirname = fDialog.GetDirectory()
f = open(os.path.join(self.dirname,self.filename),'w')
self.text2.SetValue(f.write())
f.close()
fDialog.Destroy()
def OnSaveAs(self, event):
""" Save a file"""
self.dirname = ''
fDialog = wx.FileDialog(self, "Choose a file", self.dirname, "*.*", wx.SAVE | wx.OVERWRITE_PROMPT)
if fDialog.ShowModal() == wx.ID_OK:
self.filename = fDialog.GetFilename()
self.dirname = fDialog.GetDirectory()
f = open(os.path.join(self.dirname,self.filename),'w')
#textString = self.text2.SetValue(str(self.text2))
#f.write(self.text2.SetValue(self.text2['s']))
f.write(self.text2.SetValue(str(self.text2)))
f.close()
fDialog.Destroy()
heres the frame method which creates the text editor:
class Frame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(500, 500),
style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)
self.makemenubar()
self.splitwin = wx.SplitterWindow(self)
self.text = wx.TextCtrl(self.splitwin, 1, style = wx.TE_MULTILINE)
self.text2 = wx.TextCtrl(self.splitwin, 1, "text", style = wx.TE_MULTILINE)
self.splitwin.Initialize(self.text)
self.splitwin.SetMinimumPaneSize(30)
self.splitwin.SplitVertically(self.text, self.text2, 0)
self.SetPosition((50, 50))
self.CreateStatusBar() # A StatusBar in the bottom of the window
horizon = wx.BoxSizer(wx.HORIZONTAL)
vert = wx.BoxSizer(wx.VERTICAL)
vert.Add(self.text2, 1, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT)
the entire program file can be found here:
notesprogram.txt
__________________
[ADM]art
|