[Tutor] Writing logfile data to a user opened file

Matt D md123 at nycap.rr.com
Thu Jun 20 23:19:33 CEST 2013


Hey guys!
So now my UI panel works well with this:	

	# Open file button click event binded to openfile
	btn = wx.Button(self, -1, "Click me")
	sizer.Add(btn, pos=(7,2))
	btn.Bind(wx.EVT_BUTTON, self.openFile) 	

	#set the panel layout
	self.SetSizer(sizer)
	#makes the gui system fit all the controls onto the panel7
	self.Layout()
	self.Fit()

	EVT_DATA_EVENT(self, self.display_data)
	#self.watcher = traffic_watcher_thread(self.msgq, self)

# openfile defined to start FileDialog
def openFile(self, evt):
	with wx.FileDialog(self, "Choose a file", os.getcwd(), "",
	                "*.*", wx.OPEN) as dlg:
		if dlg.ShowModal() == wx.ID_OK:
			path = dlg.GetPath()
			mypath = os.path.basename(path)


So as you guys taught me to do I was opening 'logfile' this way:

self.logfile = open('logfile.txt', 'a')

And the logger code:

#logger code---------------
#  first new line
self.logfile.write('\n')
#  date and time
self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S", localtime()))))
#  loop through each of the TextCtrl objects
for k,v in self.fields.items():
	#  get the value of the current TextCtrl field
	f = field_values.get(k, None)
	if f:
		#  output the value with trailing comma
		self.logfile.write('%s,'%(str(f)))		
#end logger code ----------------

And that is working well.
Now I am trying to think of a way to get what is in the logfile.txt into
the file that is opened by the user via the UI.  Getting stuck trying to
come up with an idea!?  maybe something in python like 'user_opened_file
= logfile' or 'write logfile to user_opened_file'?  I am not able to
find standard way to do this.
Cheers!

-- 
Matt D
------------


More information about the Tutor mailing list