Programming Forums
User Name Password Register
 

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

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Nov 9th, 2006, 6:15 PM   #1
Yarvin
Programmer
 
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
 

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 12:20 AM
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 8:55 AM
Read,regexp,rename,and save karamelos Perl 3 May 3rd, 2006 7:37 AM
Save print screen to file OMG GAH Sane Coder's Corner Lounge 37 Jan 5th, 2006 3:16 PM
system commands/ save results ktsirig PHP 1 Oct 27th, 2005 2:10 PM




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

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