Processing Text in 2 wxTextCtrl

Hello,
  I've got two wxTextCtrl, in the first control I process some ASP files displaying only the quoted Text, then I want the text processing to stop and let me insert some text in the second control or press a 'skip' button.
My 'application' is a simple translator, I need to parse a file and translate the quoted text in another language, write to a temporary file then continue the parsing.
I can't understand how to generate an event from the second control to make the parsing stop and wait for input.

TIA,
  Nicholas

Nicholas Wieland wrote:

Hello,
    I've got two wxTextCtrl, in the first control I process some ASP files displaying only the quoted Text, then I want the text processing to stop and let me insert some text in the second control or press a 'skip' button.
My 'application' is a simple translator, I need to parse a file and translate the quoted text in another language, write to a temporary file then continue the parsing.
I can't understand how to generate an event from the second control to make the parsing stop and wait for input.

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.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

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 :slight_smile:

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.

Nicholas Wieland 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.

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 :slight_smile:

Don't look at the horrible design, I'm planning to refactor, redesign, improve, implement etc. when I have a *basic* working application:

It sounds like you need to focus more on the basics of an event-driven approach...

Forget the code for a minute. Instead think about and write down what events there are in the problem space, and what the program should do to respond to them. IOW, "When the user/system/etc. does this, the program should do that." type of statements. Make the "this" and "that" as fine-grained as possible. When you've done that then look at the code again and write a handler for each "that" and then hook it into the GUI with EVT_* calls or by calling the hanlder explictly from other handlers when needed.

···

On 2003.02.15 19:57 Robin Dunn wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!