Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 9th, 2006, 7:15 PM   #1
Yarvin
College Student
 
Join Date: Sep 2005
Location: Anchorage, Alaska
Posts: 37
Rep Power: 0 Yarvin is on a distinguished road
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
Yarvin is offline   Reply With Quote
Old Nov 9th, 2006, 8:12 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,192
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
                        f = open(os.path.join(self.dirname,self.filename),'w')
                        self.text2.SetValue(f.write())
                        f.close()

What are you trying to do here? You write nothing to the file you just opened, then set self.text2 to the return value of f.write().

                        f = open(os.path.join(self.dirname,self.filename),'w')
			f.write(self.text2.SetValue(str(self.text2)))
                        f.close()

Similarily, what are you trying to do here? You're writing to the data file the return from the method "SetValue", which is NULL. That makes no sense to me.

Presumably... you would want this instead:

                        f = open(os.path.join(self.dirname,self.filename),'w')
			f.write(self.text2.GetValue())
                        f.close()

Why were you trying to set self.text2 to the value of itself anyways?
Sane is offline   Reply With Quote
Old Nov 9th, 2006, 9:01 PM   #3
Yarvin
College Student
 
Join Date: Sep 2005
Location: Anchorage, Alaska
Posts: 37
Rep Power: 0 Yarvin is on a distinguished road
okay! that does it thanks
__________________
[ADM]art
Yarvin is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save the array vars in a class? cCj PHP 2 Aug 6th, 2006 1:20 AM
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 9:55 AM
Read,regexp,rename,and save karamelos Perl 3 May 3rd, 2006 8:37 AM
Save print screen to file OMG GAH Sane Coder's Corner Lounge 37 Jan 5th, 2006 4:16 PM
system commands/ save results ktsirig PHP 1 Oct 27th, 2005 3:10 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC