Ok, thanks for the advice, my first approach was clearly wrong...
I'm already stuck, I know what I have to do but I don't know *how* to do it...
I've read documentation and Wiki but I'm already having problems, my lack is that I know how a single widget works but not how widgets work together
Don't look at the horrible design, I'm planning to refactor, redesign, improve, implement etc. when I have a *basic* working application:
##########code###########
from wxPython.wx import *
import string
class Translator( wxFrame ):
def __init__( self ):
wxFrame.__init__( self, NULL, -1, "Translator",
wxDefaultPosition, wxDefaultSize )
self.DrawChildWidgets()
def DrawChildWidgets( self ):
self.DrawMenu()
box = wxBoxSizer( wxVERTICAL )
self.source = wxTextCtrl( self, -1, style = wxTE_READONLY )
EVT_TEXT( self, self.source.GetId(), self.OnText )
box.Add( self.source, 2, wxGROW )
self.dest = wxTextCtrl( self, -1, style = wxTE_PROCESS_ENTER )
EVT_ENTER( self, self.dest.GetId(), self.OnEnter )
box.Add( self.dest, 2, wxGROW )
self.SetSizer( box )
def DrawMenu( self ):
OPEN_ID = wxNewId()
file_menu = wxMenu()
file_menu.Append( OPEN_ID, "Open..." )
EVT_MENU( self, OPEN_ID, self.OnOpen )
menubar = wxMenuBar()
menubar.Append( file_menu, "&File" )
self.SetMenuBar( menubar )
def OnOpen( self, event ):
WildCard = "ASP source (*.asp)|*.asp"
file_dlg = wxFileDialog( self, "Choose a file", "",
"", WildCard, wxOPEN )
if( file_dlg.ShowModal() == wxID_OK ):
self.src_file = open( file_dlg.GetPath(), "r" )
self.dst_file = open( "_buffer", "w" )
self.Parse()
file_dlg.Destroy()
def Parse( self ):
while( 1 ):
line = self.src_file.readline()
a = string.find( line, "\"" )
b = string.rfind( line, "\"" )
self.dst_file.write( line[ : a ] )
self.source.WriteText( line[ a + 1 : b - 1 ] )
self.dst_file.write( line[ b : ] )
if( line == "" ):
break
def OnText( self, event ):
def OnEnter( self, event ):
class App( wxApp ):
def OnInit( self ):
frame = Translator()
frame.Show( true )
return true
translator = App( 0 )
translator.MainLoop()
########code#########
As you can see I'm stuck with event handling...
Every suggestion is really appreciated.
TIA,
Nicholas
···
On 2003.02.15 19:57 Robin Dunn wrote:
Turn the problem inside out. Organize your parser to work on small chunks at a time, when your parser senses something that needs translated, it should cause the app to fill the text controls and stop. When you do the translation and click the button you process the translation and then tell the parser to do the next chunk.