Hello,
A help please:
In the code below, how do I run the event self.OnClick when self.oBtnlog receive focus and the user presses the enter key?
Thank you.
class Enterfocus( wx.Frame ):
def init(self):
wx.Frame.init(self, None, wx.ID_ANY, “Text Validation Tutorial” )
panel = wx.Panel(self)
self.first = wx.TextCtrl(panel )
self.second = wx.TextCtrl(panel )
self.oBtnlog = GB.GradientButton( panel, -1, None, “Entrar”, size=(90,34) )
self.oBtnlog.Bind( wx.EVT_BUTTON, self.OnClick, self.oBtnlog )
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.first, 0, wx.ALL, 5)
sizer.Add(self.second, 0, wx.ALL, 5)
sizer.Add(self.oBtnlog, 0, wx.ALL, 5)
panel.SetSizer(sizer)
def OnClick( self , evt ):
print ‘Click GradientButton’
if name == “main”:
app = wx.App(False)
frame = Enterfocus()
frame.Show()
app.MainLoop()
EdsonSil Sil wrote:
Hello,
A help please:
In the code below, how do I run the event self.OnClick when
self.oBtnlog receive focus and the user presses the enter key?
You should be able to call self.oBtnlog.SetDefault() to make it the
"default" button for the dialog,
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
For focus related stuff, you can use
SetFocus() or SetDefault() programmatically for frames, miniframes, dialogs.
As far as handling key, mouse events…
you can use
ms = wx.GetMouseState(),
wx.MouseState,
wx.KeyboardState,
or try to handle wx.EVT_KEY_DOWN, wx.EVT_KEY_UP, wx.EVT_LEFT_DOWN, wx.EVT_LEFT_UP, etc… events.
the keycode you are looking for is
wx.WXK_RETURN
Depending on what type of functionality you want for a widget, there are many routes for the developer to go here.
I’ve tried but I can not capture the wx.WXK_RETURN key.
You could use my code as an example?
Thank you.
···
Em segunda-feira, 13 de janeiro de 2014 23h06min51s UTC-2, Metallicow escreveu:
For focus related stuff, you can use
SetFocus() or SetDefault() programmatically for frames, miniframes, dialogs.
As far as handling key, mouse events…
you can use
ms = wx.GetMouseState(),
wx.MouseState,
wx.KeyboardState,
or try to handle wx.EVT_KEY_DOWN, wx.EVT_KEY_UP, wx.EVT_LEFT_DOWN, wx.EVT_LEFT_UP, etc… events.
the keycode you are looking for is
wx.WXK_RETURN
Depending on what type of functionality you want for a widget, there are many routes for the developer to go here.
Se attached sample.
FocusDefaultKeyUp.py (1.14 KB)
···
On Tuesday, January 14, 2014 3:13:04 AM UTC-6, EdsonSil Sil wrote:
I’ve tried but I can not capture the wx.WXK_RETURN key.
You could use my code as an example?
Hello Metallicow.
Thanks for the help.
It would be possible to simulate the pressing of the button?
···
Em terça-feira, 14 de janeiro de 2014 08h48min27s UTC-2, Metallicow escreveu:
On Tuesday, January 14, 2014 3:13:04 AM UTC-6, EdsonSil Sil wrote:
I’ve tried but I can not capture the wx.WXK_RETURN key.
You could use my code as an example?
Se attached sample.
Would it be possible manually(programatically)?.. maybe you ask?
Under windows, use can use the pywin32bindings,
or ctypes(plain python)
or if using another OS, then look into a different lib or whatever.
PressKey and other libs is a simple example on Windows.
Right off hand, I’m not sure how to do it manually from other OS’s.
Ex: Linux(various flavors) or Mac(don’t own one, just test occasionally)
···
On Wednesday, January 15, 2014 2:34:49 AM UTC-6, EdsonSil Sil wrote:
It would be possible to simulate the pressing of the button?
I mean simulate pressed when the button onclick event occurs.
Would be something like: self.oBtnlog.lower ()
···
Em quarta-feira, 15 de janeiro de 2014 08h17min53s UTC-2, Metallicow escreveu:
On Wednesday, January 15, 2014 2:34:49 AM UTC-6, EdsonSil Sil wrote:
It would be possible to simulate the pressing of the button?
Would it be possible manually(programatically)?.. maybe you ask?
Under windows, use can use the pywin32bindings,
or ctypes(plain python)
or if using another OS, then look into a different lib or whatever.
PressKey and other libs is a simple example on Windows.
Right off hand, I’m not sure how to do it manually from other OS’s.
Ex: Linux(various flavors) or Mac(don’t own one, just test occasionally)
I mean simulate pressed when the button onclick event occurs.
Would be something like: self.oBtnlog.lower ()
Depending on what “widget” you want to bind a particular event too, then the possibilies are endless almost.
self.oBtnlog could be bound like so…
self.oBtnlog.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
def OnLeftUp(self, event):
event.GetEventObject().SetLabel(event.GetEventObject().GetLabel().lower())
This would chane the label to lowercase upon clicking…
or something similar…
Other events that simulate similar “clicking” effects with wx.Button are:
wx.EVT_BUTTON, wx.EVT_LEFT_DOWN, wx.EVT_LEFT_UP.
These can all be Bound
to “that” widget specifically.
LOTR: my precious…
···
On Wednesday, January 15, 2014 5:25:37 AM UTC-6, EdsonSil Sil wrote:
Sorry, I have difficult with the English language.
I would like to try to simulate the effect on the button pressed.
There is a method of GB.GradientButton for this?
···
Em quarta-feira, 15 de janeiro de 2014 09h41min50s UTC-2, Metallicow escreveu:
On Wednesday, January 15, 2014 5:25:37 AM UTC-6, EdsonSil Sil wrote:
I mean simulate pressed when the button onclick event occurs.
Would be something like: self.oBtnlog.lower ()
Depending on what “widget” you want to bind a particular event too, then the possibilies are endless almost.
self.oBtnlog could be bound like so…
self.oBtnlog.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
def OnLeftUp(self, event):
event.GetEventObject().SetLabel(event.GetEventObject().GetLabel().lower())
This would chane the label to lowercase upon clicking…
or something similar…
Other events that simulate similar “clicking” effects with wx.Button are:
wx.EVT_BUTTON, wx.EVT_LEFT_DOWN, wx.EVT_LEFT_UP.
These can all be Bound
to “that” widget specifically.
LOTR: my precious…
see attached sample2.
FocusDefaultKeyUp2.py (1.4 KB)
···
On Wednesday, January 15, 2014 5:59:19 AM UTC-6, EdsonSil Sil wrote:
Sorry, I have difficult with the English language.
I would like to try to simulate the effect on the button pressed.
There is a method of GB.GradientButton for this?
Hello my friend.
When the User clicks the button, he lowers and raises then.
This effect I would like to accomplish when the enter key was pressed on the button.
···
Em quarta-feira, 15 de janeiro de 2014 10h11min24s UTC-2, Metallicow escreveu:
On Wednesday, January 15, 2014 5:59:19 AM UTC-6, EdsonSil Sil wrote:
Sorry, I have difficult with the English language.
I would like to try to simulate the effect on the button pressed.
There is a method of GB.GradientButton for this?
see attached sample2.
Sorry, the translation was a bit off.
I believe what you want is in the attachment. See 2 attached files.
I am assuming you want to show the pressed button state (mouse), when pressing the Return key down(wx.EVT_KEY_DOWN), then the unpressed state of the button when the wx.EVT_KEY_UP.
Hope this helps.
gradientbutton_mod.py (20.6 KB)
FocusDefaultKeyUp3.py (2.64 KB)
···
On Wednesday, January 15, 2014 6:27:49 AM UTC-6, EdsonSil Sil wrote:
Hello my friend.
When the User clicks the button, he lowers and raises then.
This effect I would like to accomplish when the enter key was pressed on the button.
It extamente it! Very good.
This implementation can be part of the official distribution?
Thank you very much.
big hug
···
Em quinta-feira, 16 de janeiro de 2014 09h41min16s UTC-2, Metallicow escreveu:
On Wednesday, January 15, 2014 6:27:49 AM UTC-6, EdsonSil Sil wrote:
Hello my friend.
When the User clicks the button, he lowers and raises then.
This effect I would like to accomplish when the enter key was pressed on the button.
Sorry, the translation was a bit off.
I believe what you want is in the attachment. See 2 attached files.
I am assuming you want to show the pressed button state (mouse), when pressing the Return key down(wx.EVT_KEY_DOWN), then the unpressed state of the button when the wx.EVT_KEY_UP.
Hope this helps.
Your welcome. Glad that gives you a start anyway. I made a few small changes to it(gradientbutton_mod.py) since.
I noticed the space event firing twice in the 3rd demo I attached.
But yes, I can stick it on my TODO list for patches to pass on to Andrea/Robin.
Return/Enter/Space should actually fire the pressed state if using wx.WANTS_CHARS flag.
Thanks for noticing.
···
On Thursday, January 16, 2014 8:07:37 AM UTC-6, EdsonSil Sil wrote:
It extamente it! Very good.
This implementation can be part of the official distribution?
Thank you very much.
big hug
Is there any change in the forecast issue of lost focus?
The fact that they run the focus of another control priate to the previous control loses focus? Exists in C # an event called PreviewLostKeyboardFocus. Is there any plans to have this wxpython?
···
Em sábado, 18 de janeiro de 2014 09h53min46s UTC-2, Metallicow escreveu:
On Thursday, January 16, 2014 8:07:37 AM UTC-6, EdsonSil Sil wrote:
It extamente it! Very good.
This implementation can be part of the official distribution?
Thank you very much.
big hug
Your welcome. Glad that gives you a start anyway. I made a few small changes to it(gradientbutton_mod.py) since.
I noticed the space event firing twice in the 3rd demo I attached.
But yes, I can stick it on my TODO list for patches to pass on to Andrea/Robin.
Return/Enter/Space should actually fire the pressed state if using wx.WANTS_CHARS flag.
Thanks for noticing.
Not exactly sure what you are asking? Is there an issue that you have notticed with the focus of the GradientButton?
The GradientButton is written in python, so if you are asking for wxWidgets related C++ code, then you will have to port it yourself.
···
On Saturday, January 18, 2014 9:14:17 AM UTC-6, EdsonSil Sil wrote:
Is there any change in the forecast issue of lost focus?
The fact that they run the focus of another control priate to the previous control loses focus? Exists in C # an event called PreviewLostKeyboardFocus. Is there any plans to have this wxpython?