question: EVT_TEXT_ENTER in wx.lib.masked

Dear All.

I Have this script, it's combined from wxGlade generated code and some part of MaskedEditControls.py (wxPython demo)

Here it is :
------------START-----------
#!/usr/bin/env python
import wx
#This one is copied from MaskedEditControls.py
import wx.lib.masked as masked
#The masks is taken from MaskedEditControls.py around line 118-125
maskFloat = ["Float (signed)", "#{6}.#{9}", "", 'F-_R', "", '','', '000000.000000000']
maskText = ["Full Name", "C{14}", "", 'F_', '^[A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+', '', '', '']
class MyFrame(wx.Frame):
     """
     The Class For creating Base Frame
     inherit the Frame class from wx
     """
     def __init__(self, *args, **kwds):
         kwds["style"] = wx.DEFAULT_FRAME_STYLE
         wx.Frame.__init__(self, *args, **kwds)
         #Frame is defined, let's defined the panel inside
         self.panel_1 = wx.Panel(self, -1)
         #Panel is defined, lets try to define 2 masked.TextControl,
         #1. masked with MaskText
         #2. masked with MaskFloat
         self.ctrl_maskText = masked.TextCtrl( self.panel_1, -1, "", style=masked.TE_PROCESS_ENTER,
                                                 mask = maskText[1],
                                                 excludeChars = maskText[2],
                                                 formatcodes = maskText[3],
                                                 includeChars = "",
                                                 validRegex = maskText[4],
                                                 validRange = maskText[5],
                                                 choices = maskText[6],
                                                 choiceRequired = False,
                                                 defaultValue = maskText[7])
         self.ctrl_maskFloat = masked.TextCtrl( self.panel_1, -1, "", style=masked.TE_PROCESS_ENTER,
                                                 mask = maskFloat[1],
                                                 excludeChars = maskFloat[2],
                                                 formatcodes = maskFloat[3],
                                                 includeChars = "",
                                                 validRegex = maskFloat[4],
                                                 validRange = maskFloat[5],
                                                 choices = maskFloat[6],
                                                 choiceRequired = False,
                                                 defaultValue = maskFloat[7])

         self.__set_properties()
         self.__do_layout()

         self.Bind(wx.EVT_TEXT_ENTER, self.f_EVT_TEXT_ENTER, self.maskText)
         self.Bind(wx.EVT_TEXT_ENTER, self.f_EVT_TEXT_ENTER, self.maskFloat)

     def __set_properties(self):
         self.SetTitle("frame_1")

     def __do_layout(self):
         sizer_1 = wx.BoxSizer(wx.VERTICAL)
         sizer_2 = wx.BoxSizer(wx.VERTICAL)
         sizer_2.Add(self.ctrl_maskText, 0, , 0)
         sizer_2.Add(self.ctrl_maskFloat, 0, , 0)
         self.panel_1.SetSizer(sizer_2)
         sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
         self.SetSizer(sizer_1)
         sizer_1.Fit(self)
         self.Layout()

     def f_EVT_TEXT_ENTER(self, event):
         print "MASKED TextCTRL --> EVT_TEXT_ENTER"

if __name__ == "__main__":
     app = wx.PySimpleApp(0)
     wx.InitAllImageHandlers()
     frame_1 = MyFrame(None, -1, "")
     app.SetTopWindow(frame_1)
     frame_1.Show()
     app.MainLoop()
------------END--------------

What I got :
1. When typing at maskText control and press ENTER, the cursor move to next control (maskFloat) .. just like what I want.
2. When typing at maskFloat :
2.a Can not enter any alphabet chars .. only numeric
2.b when keypress ENTER .. cursor move back to maskText control
Exactly like what I want

My problem is at how to catch the EVT_TEXT_ENTER event ?
I want it to do some procedure(s) before move to another control

Kindly please give me your enlightment

BTW : Which one is prefered by this mailing-list, post the code inline or pastebin it and just post the url ?

Sincerely
-bino-

Ooopps wrong code pasted
here is the one
------START---------
#!/usr/bin/env python
import wx
#This one is copied from MaskedEditControls.py
import wx.lib.masked as masked
#The masks is taken from MaskedEditControls.py around line 118-125
maskFloat = ["Float (signed)", "#{6}.#{9}", "", 'F-_R', "", '','', '000000.000000000']
maskText = ["Full Name", "C{14}", "", 'F_', '^[A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+', '', '', '']
class MyFrame(wx.Frame):
     """
     The Class For creating Base Frame
     inherit the Frame class from wx
     """
     def __init__(self, *args, **kwds):
         kwds["style"] = wx.DEFAULT_FRAME_STYLE
         wx.Frame.__init__(self, *args, **kwds)
         #Frame is defined, let's defined the panel inside
         self.panel_1 = wx.Panel(self, -1)
         #Panel is defined, lets try to define 2 masked.TextControl,
         #1. masked with MaskText
         #2. masked with MaskFloat
         self.ctrl_maskText = masked.TextCtrl( self.panel_1, -1, "",
                                                 mask = maskText[1],
                                                 excludeChars = maskText[2],
                                                 formatcodes = maskText[3],
                                                 includeChars = "",
                                                 validRegex = maskText[4],
                                                 validRange = maskText[5],
                                                 choices = maskText[6],
                                                 choiceRequired = False,
                                                 defaultValue = maskText[7])
         self.ctrl_maskFloat = masked.TextCtrl( self.panel_1, -1, "",
                                                 mask = maskFloat[1],
                                                 excludeChars = maskFloat[2],
                                                 formatcodes = maskFloat[3],
                                                 includeChars = "",
                                                 validRegex = maskFloat[4],
                                                 validRange = maskFloat[5],
                                                 choices = maskFloat[6],
                                                 choiceRequired = False,
                                                 defaultValue = maskFloat[7])

         self.__set_properties()
         self.__do_layout()
         #self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=ipaddr1.GetId())
         self.Bind(wx.EVT_TEXT_ENTER, self.f_EVT_TEXT_ENTER, id=self.ctrl_maskText.GetId())
         self.Bind(wx.EVT_TEXT_ENTER, self.f_EVT_TEXT_ENTER, id=self.ctrl_maskFloat.GetId())

     def __set_properties(self):
         self.SetTitle("frame_1")

     def __do_layout(self):
         sizer_1 = wx.BoxSizer(wx.VERTICAL)
         sizer_2 = wx.BoxSizer(wx.VERTICAL)
         sizer_2.Add(self.ctrl_maskText, 0, 0 , 0)
         sizer_2.Add(self.ctrl_maskFloat, 0, 0 , 0)
         self.panel_1.SetSizer(sizer_2)
         sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
         self.SetSizer(sizer_1)
         sizer_1.Fit(self)
         self.Layout()

     def f_EVT_TEXT_ENTER(self, event):
         print "MASKED TextCTRL --> EVT_TEXT_ENTER"

if __name__ == "__main__":
     app = wx.PySimpleApp(0)
     wx.InitAllImageHandlers()
     frame_1 = MyFrame(None, -1, "")
     app.SetTopWindow(frame_1)
     frame_1.Show()
     app.MainLoop()
------END-----------

What I got :
1. When typing at maskText control and press ENTER, the cursor move to next control (maskFloat) .. just like what I want.
2. When typing at maskFloat :
2.a Can not enter any alphabet chars .. only numeric
2.b when keypress ENTER .. cursor move back to maskText control
Exactly like what I want

My problem is at how to catch the EVT_TEXT_ENTER event ?
I want it to do some procedure(s) before move to another control

Kindly please give me your enlightment

Sincerely
-bino-

...

Attaching the code is probably preferably or pastebin if it is really large.

The code should also be self contained, so one can easily run it - which it was in your case.

What I got :
1. When typing at maskText control and press ENTER, the cursor move to next control (maskFloat) .. just like what I want.
2. When typing at maskFloat :
2.a Can not enter any alphabet chars .. only numeric
2.b when keypress ENTER .. cursor move back to maskText control
Exactly like what I want

My problem is at how to catch the EVT_TEXT_ENTER event ?

You need to set the style wx.TE_PROCESS_ENTER, but I am not sure that is possible with masked.TextCtrl.

I added "style=wx.TE_PROCESS_ENTER," and also tried with this bind "self.ctrl_maskText.Bind(wx.EVT_TEXT_ENTER, self.f_EVT_TEXT_ENTER)"

Hopefully Robin or someone else can enlighten us on this.

I want it to do some procedure(s) before move to another control

What kind of procedure do you want to do, maybe there is an alternative - e.g. a validator?

Werner

···

On 09/15/2011 04:49 AM, bino oetomo wrote:

Well ... since this is for my try on write a POS, the procedures will things like :
- Check if the Product_id is already in sale list,
- Check if the product id is in database
- count the sub total
- count the total
- etc etc

I just read the "validator" and I think it have some promise .. i'll give it a try

I realy appreciate your enlightment

-bino-

···

On 09/15/2011 03:12 PM, werner wrote:

You need to set the style wx.TE_PROCESS_ENTER, but I am not sure that is possible with masked.TextCtrl.

I added "style=wx.TE_PROCESS_ENTER," and also tried with this bind "self.ctrl_maskText.Bind(wx.EVT_TEXT_ENTER, self.f_EVT_TEXT_ENTER)"

Hopefully Robin or someone else can enlighten us on this.

I want it to do some procedure(s) before move to another control

What kind of procedure do you want to do, maybe there is an alternative - e.g. a validator?

Hi Bino,

You need to set the style wx.TE_PROCESS_ENTER, but I am not sure that is possible with masked.TextCtrl.

I added "style=wx.TE_PROCESS_ENTER," and also tried with this bind "self.ctrl_maskText.Bind(wx.EVT_TEXT_ENTER, self.f_EVT_TEXT_ENTER)"

Hopefully Robin or someone else can enlighten us on this.

I want it to do some procedure(s) before move to another control

What kind of procedure do you want to do, maybe there is an alternative - e.g. a validator?

Well ... since this is for my try on write a POS, the procedures will things like :
- Check if the Product_id is already in sale list,
- Check if the product id is in database
- count the sub total
- count the total
- etc etc

I just read the "validator" and I think it have some promise .. i'll give it a try

I use validator (see InitDialog, TransferDataFromWindow, TransferDataToWindow) to read/write from/to database via SQLAlchemy which works very well for me, including with the masked controls which I use quit extensively.

Beside SQLAlchemy you might also want to look at Dabo - http://www.dabodev.com/

Do you really want to do all this on control enter/exit shouldn't most of this be done on save?

Just remember that I had a need on exit of a field to do a db lookup and I used with a masked.numctrl

self.bottleID.Bind(wx.EVT_KILL_FOCUS, self.OnBottleIDKillFocus)

that should work in your case too and probably is even better then on enter key as that would not catch a mouse or touch screen move to another field.

Werner

···

On 09/16/2011 04:00 AM, bino oetomo wrote:

On 09/15/2011 03:12 PM, werner wrote:

Hi Werner

Hi Bino,

I use validator (see InitDialog, TransferDataFromWindow, TransferDataToWindow) to read/write from/to database via SQLAlchemy which works very well for me, including with the masked controls which I use quit extensively.

Beside SQLAlchemy you might also want to look at Dabo - http://www.dabodev.com/

Do you really want to do all this on control enter/exit shouldn't most of this be done on save?

Just remember that I had a need on exit of a field to do a db lookup and I used with a masked.numctrl

self.bottleID.Bind(wx.EVT_KILL_FOCUS, self.OnBottleIDKillFocus)

that should work in your case too and probably is even better then on enter key as that would not catch a mouse or touch screen move to another field.

I really appreciate your enlightment
Yes , I tried to use "validator" but in general I think it need some other button to do the trick

Hmmm .... EVT_KILL_FOCUS .. looks great .. I'll try it tomorrow

again ... i really appreciate your enlightment

sincerely
-bino-

···

On 09/16/2011 05:33 PM, werner wrote:

I see that Werner has done a good job dealing with your main question so I'll just address this:

BTW : Which one is prefered by this mailing-list, post the code inline
or pastebin it and just post the url ?

Attachments are best. If your google groups settings are delivering the messages to you as emails then you only need to attach the file(s) to your mail message like you would with any other mail. If you are reading the group on the web using Google's browser interface, then you can still attach files if you are using the new (beta) Google Groups user interface. There should be a link that will let you switch to the new UI when you go the the main groups.google.com page.

As a last resort you can use a pastebin, but I discourage it for groups like this that will have a permanent archive, because the paste may expire, or the pastebin service may change their links, or the text may have been altered by someone else, or... So if someone has the same question a year from now and finds your message in the archive, or even a reply to your message that has pastebinned the solution, then there is a good chance that they will not be able to fetch the code, or at least the original version of it, and so it will be of no help for them.

···

On 9/14/11 7:32 PM, bino oetomo wrote:

--
Robin Dunn
Software Craftsman