Hi
Using a template from the tutorial Fuse offered i made this program:
import wx
import os
WINDOW_WIDTH = 700
WINDOW_HEIGHT = 600
class MainFrame(wx.Frame,object):
def __init__(self):
wx.Frame.__init__(self,None,
title = "Paul's Text Editor",
pos = (200,75),
size = (WINDOW_WIDTH,WINDOW_HEIGHT))
self.menubar = wx.MenuBar()
self.menufile = wx.Menu()
self.menuinfo = wx.Menu()
self.SetMenuBar(self.menubar)
self.menubar.Append(self.menufile,'&File')
self.loadItem = self.menufile.Append(-1,'&Load')
self.Bind(wx.EVT_MENU,self.loadEvent,self.loadItem)
self.save = self.menufile.Append(-1,'&Save')
self.Bind(wx.EVT_MENU,self.saveevent,self.save)
self.exititem = self.menufile.Append(-1,'E&xit')
self.Bind(wx.EVT_MENU,self.exitevent,self.exititem)
self.menubar.Append(self.menuinfo,'&Info')
self.aboutitem = self.menuinfo.Append(-1,'&About')
self.Bind(wx.EVT_MENU,self.aboutevent,self.aboutitem)
self.helpitem = self.menuinfo.Append(-1,'&Help')
self.Bind(wx.EVT_MENU,self.helpevent,self.helpitem)
self.background = wx.Panel(self)
self.tbut = wx.Button(self.background,label = 'transfer')
self.tbut.Bind(wx.EVT_BUTTON,self.transferEvent)
self.first = 1
self.inarea = wx.TextCtrl(self.background,style=wx.PROCESS_ENTER)
self.inarea.Bind(wx.EVT_TEXT_ENTER,self.transferEvent)
self.inarea.SetValue("Enter Data Line by Line")
self.inarea.Bind(wx.EVT_LEFT_UP,self.clearin)
self.transarea = wx.TextCtrl(self.background,
style = wx.TE_MULTILINE)
self.transarea.SetValue("Or go for it in here!")
self.transarea.Bind(wx.EVT_LEFT_UP,self.cleartransarea)
self.horbox = wx.BoxSizer()
self.horbox.Add(self.inarea,proportion = 1,border=0)
self.horbox.Add(self.tbut,proportion=0,border = 0)
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.horbox,proportion=0,flag=wx.EXPAND,
border=0)
self.vbox.Add(self.transarea,proportion=1,flag=wx.EXPAND,
border=0)
self.background.SetSizer(self.vbox)
self.Show()
self.loaded=0
self.Bind(wx.EVT_CLOSE,self.OnExit)
def cleartransarea(self,event):
self.transarea.SetValue('')
def clearin(self,event):
print event
self.inarea.SetValue('')
def loadEvent(self,event):
loadbox = wx.FileDialog(self,message='open',
defaultDir=os.getcwd(),
defaultFile='',
style = wx.OPEN)
if loadbox.ShowModal() == wx.ID_OK:
self.filename=loadbox.GetPath()
target = open(self.filename,'rb')
self.transarea.SetValue(target.read())
target.close
self.loaded = 1
loadbox.Destroy()
def OnExit(self,event):
self.exitevent(wx.EVT_CLOSE)
self.Destroy()
def exitevent(self,event):
if self.loaded:
checksave = wx.MessageDialog(self,message = 'do you want to save?',
style = wx.YES_NO)
if checksave.ShowModal() == wx.ID_YES:
f = open(self.filename,'w')
f.write(self.transarea.GetValue())
f.close()
else:
if len(self.transarea.GetValue()) >0:
checksave = wx.MessageDialog(self,message = 'do you want to save?',
style = wx.YES_NO)
if checksave.ShowModal() == wx.ID_YES:
self.saveevent(None)
self.Destroy()
def saveevent(self,event):
if self.loaded:
overwrite = wx.MessageDialog(self,message="Would you like to overwrite the file?"
,style = wx.YES_NO)
if overwrite.ShowModal()==wx.ID_YES:
g = wx.MessageDialog(self,message='Saved!',style=wx.OK)
g.ShowModal()
f = open(self.filename,'w')
f.write(self.transarea.GetValue())
f.close()
else:
savebox = wx.FileDialog(self,message = 'Where will you save the file?',
defaultDir="C:\\",
defaultFile = '',
style = wx.OPEN)
if savebox.ShowModal() == wx.ID_OK:
self.filename = savebox.GetPath()
target = open(self.filename,'w')
target.write(self.transarea.GetValue())
target.close()
savebox.Destroy()
def helpevent(self,event):
self.transarea.SetValue('''To load a file go to FILE and
press load and navigate to the
file you want and press OK.
To exit press the cross or
FILE --> EXIT''')
def aboutevent(self,event):
aboutinfo = 'Made by Paul Thompson.\nMade with a tutorial by Fuse'
aboutbox = wx.MessageDialog(self,
message=aboutinfo,
caption='About',
style=wx.ICON_INFORMATION|wx.STAY_ON_TOP|wx.OK)
if aboutbox.ShowModal() == wx.ID_OK:
aboutbox.Destroy()
def transferEvent(self,event):
self.transarea.SetValue(self.transarea.GetValue()+'\n'+self.inarea.GetValue())
app=wx.App(redirect=False)
window=MainFrame()
app.MainLoop()
print 'ending'
app.Destroy()
What it is meant to do it be a text editing program. I have it so it saves and loads files and this works fine but i have also got a part which makes the two text input bits start with text inside them to tell the user how they are meant to be used. Then i tried to make an event that when you clicked on them the text that was there disappeared. This is where i get my problem, the text clears as soon as you click in it but then it kinda freezes up and you can't do anything. There are no errors coming up in the console so i was wondering if anyone could help me to fix this.
Thanks :)