Re: Is "process enter" possible with textfields in PythonCard?

Neil Hughes <[email protected]> Sat, 16 Aug 2008 21:43:57 +0100
Newsgroups gmane.comp.python.pythoncard
Message-ID <[email protected]>
On 05/06/2008 19:54, Neil Hughes wrote:
> On 05/06/2008 15:19, Alec Bennett wrote:
>> I'm working on a PythonCard project and can't figure out if it's 
>> possible to set a wx.TE_PROCESS_ENTER style on a textfield. In other 
>> words, I'd like to be able to trigger an event (for example a submit 
>> button type event) when the user presses the enter key while they're in 
>> a text field.
>>
>> Is this possible with PythonCard?
> 
> On some of my windows I have a username text field and password text 
> field, but I want the return/enter key to act the same as the login 
> button next to them, so I use this:
> 
>      def on_keyDown(self, event):
>          if(event.keyCode == wx.WXK_RETURN):
>              if(self.components.LoginButton.enabled == True):
>                  self.on_LoginButton_mouseClick(event)
> 
> on_keyDown() is catching keyboard events not trapped by any specific 
> widget, but you should be able to use
> 
> on_<text field name>_keyDown()
> 
> to only listen to the specific text field widget you want.

I've just had to do something similar with a password field, i.e. I 
needed the operator to type in the password and then when he/she hits 
return the login button needs to activate. My solution above didn't work 
straight away with text/password fields because, as initially pointed 
out, the return key is not trapped and you have to use the special flag.

Question....I ended up setting the flag in on_initialize() with a line 
at the end that just does:

self.components.PasswordField.WindowStyle |= wx.TE_PROCESS_ENTER

meanwhile I have this method activating the login button when the 
password field gets a return key and there's something typed in:

def on_PasswordField_keyDown(self, event):

    if((event.keyCode == wx.WXK_RETURN) and 
(self.components.PasswordField.text <> '')):
       self.on_LoginButton_mouseClick(event)
    else:
       event.skip()

Is this the best/safest way...or is there something a bit tidier that 
avoids delving into using the underlying wx stuff? It's almost like I 
need a 'special flags' field in the resource editor, but with some 
smarts as to which flags apply to which widget types.

-- 
Neil Hughes

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/