I have a wxPython grid (wx.grid) class with rows/columns and such. I'm trying to detect when the user performs a "Control + Click" on a particular cell. Right now I have:
def __init__(self, parent, size):
grd.Grid.__init__(self, parent, -1, size=size)
self.control_button_pressed = False
self.Bind(grd.EVT_GRID_CELL_LEFT_CLICK, self._OnSelectedCell)
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyPress)
self.Bind(wx.EVT_KEY_UP, self._OnKeyUp)
def _OnKeyPress(self, event):
self.control_button_pressed = True
event.Skip()
def _OnKeyLift(self, event):
self.control_button_pressed = False
def _OnSelectedCell(self, event):
print "Cell Selected"
This works fine when just clicking on the cell, but when I perform a Control + Click, this event doesn't even fire.
How can I bind this event?
The Grid class is already handling Ctrl-Click events to implement adding cells to the collection of selected cells. Since the grid is already consuming that event for that purpose then the event is not propagated or converted into grid events (other than selection events.) However you can intercept the lower level mouse events before the grid gets them, and do your checks there. Try binding handlers directly to the grid window component of the Grid, like this:
self.GetGridWindow().Bind(wx.EVT_LEFT_UP, self.onLeftUp)
Be sure to call event.Skip() in your mouse event handler so the Grid can still get and process the event.
You do not have to worry about catching the key events for this because the event object passed to the mouse event handlers includes methods for getting the state of the modifier keys at the time that the mouse event happened.
I think you'll need to bind to EVT_KEY_DOWN and EVT_KEY_UP. In the key down event, set some variable like "self.ctrl" to True. In the up event, set it to False. You should probably initially set it to False as well. Then when it's held down, it becomes True and as long as you call event.Skip(), your grid event should fire when you click. Something along those lines should work anyway.
This might help you understand key events better: http://www.blog.pythonlibrary.org/2009/08/29/wxpython-catching-key-and-char-events/
Never mind this answer --> see Robin Dunn's
Related
For example: a uwp pivot automatically handles Ctrl+Tab. I want to create a custom app-wide keyboard shortcut that uses Ctrl+Tab. However, if my app is currently focused on a pivot control, then the pivot steals the shortcut keydown event.
What I have tried:
For testing purposes, I created a singleton class that handles CoreWindow.KeyDown events. I register some handlers. When I press Ctrl+Tab without focusing on any element, then the singleton class handles the event. But if I focus on a pivot control in my app and press Ctrl+Tab, then the pivot steals the event and the singleton class does not. How do I make it so the singleton class picks up the event and not the focused element?
I tried to register the KeyDown event on CoreWindow. After testing, Pivot receives keyboard events earlier than CoreWindow.KeyDown events, so you can try to disable the corresponding keyboard accelerator in Pivot:
private void Pivot_ProcessKeyboardAccelerators(UIElement sender, ProcessKeyboardAcceleratorEventArgs args)
{
if(args.Key==Windows.System.VirtualKey.Tab && args.Modifiers == Windows.System.VirtualKeyModifiers.Control)
{
args.Handled = true;
}
}
By listening to the Pivot.ProcessKeyboardAccelerators event, we can prevent the default behavior when Ctrl+Tab is triggered (args.Handled = True).
However, it should be noted that because the event is prevented from further bubbling, the CoreWindow.KeyDown event will still not be triggered at this time.
You mentioned in the question description that you used a singleton to handle the event triggered by the shortcut. Then you need to directly call your processing method in the singleton in the code.
...
args.Handled = true;
CtrlAndTabHandle();
Thanks.
I'm working with VB6.
I have several forms and i need open a form. This form have a UserControl.
My problem is setfocus in a element of UserControl inside this form.
Sub Form_Activate()
Ctrl_User.MyTextbox.SetFocus
End Sub
but don't run
How i can do it??
Thanks
Have you tried this:
Sub Form_Activate()
Ctrl_User.Enabled = True
Ctrl_User.MyTextbox.SetFocus
End Sub
Also maybe you may need to review this here as well it may help you more:
If you're authoring a user-drawn control, there won't be any
constituent controls on your UserControl. If you don't want your
control to be able to receive the focus, set the CanGetFocus property
of the UserControl object to False. CanGetFocus is True by default.
If your user-drawn control can receive the focus, the UserControl
object will receive GotFocus and LostFocus events when your control
receives and loses the focus. A user-drawn control is responsible for
drawing its own focus rectangle when it has the focus, as described in
"User-Drawn Controls," in this chapter.
This is the only function your UserControl's GotFocus and LostFocus
events need to fulfill for a user-drawn control. You don't need to
raise GotFocus or LostFocus events for the user of your control,
because the container's extender provides these events if the
CanGetFocus property is True.
https://msdn.microsoft.com/en-us/library/aa241743(v=vs.60).aspx
I want to make some changes to a text field once it loses the focus but I cant figure out the event I need. This is my code:
Event.observe('my_text_field', '????', function(event) {
do something here
}
So, what do I have to put in instead of the ???? ?
Thanks!
You are looking for the blur event:
The blur event is fired when an element has lost focus.
And from the DOM2 Events spec:
The blur event occurs when an element loses focus either via the pointing device or by tabbing navigation. This event is valid for the following elements: LABEL, INPUT, SELECT, TEXTAREA, and BUTTON.
I have a checkbox with a custom image for the button. I used the click delegate to perform an action whenever the button is clicked:
box.Click += { //do some stuff... }
This is working great.
However, now I have been given the requirement to add swipe detection to this checkbox (Sounds crazy but it does actually make sense for this app).
I added the swipe detection using the standard methods I am used to with normal Android in Java: I subclassed GestureDetector.SimpleOnGestureListener and also implemented View.IOnTouchListener.
I added the swipe detection to the checkbox as follows:
/*
SwipeListener implements View.IOnTouchListener
SwipeDetector is a subclass of GestureDetector.SimpleOnGestureListener
*/
SwipeListener listener = new SwipeListener(new GestureDetector(new SwipeDetector(this)));
box.SetOnTouchListener(listener);
When I do this, the swipe works great. But the click delegate no longer gets activated. I tried moving my code for the click to my SwipeDetector class, and that seemed to work.
But then I noticed that my checkbox was no longer getting its checked/unchecked state and so my custom image for it never changed.
I know this has got to be something simple, but I'm not seeing it... What is the proper way to have a click and a swipe on a view (checkbox) in Android/MonoDroid?
My guess without seeing your code is that you are returning true from OnTouch, meaning you have consumed the event and do not wish any further processing to occur using the event. Try returning false if you want the rest of the event to fire.
http://developer.android.com/reference/android/view/View.OnTouchListener.html
Im using Ext JS 4. I have a button inside a container. I want the container to receive mouseover, mouseout, and click events, but the button is causing the mouseover and mouseout event handlers to be called twice on the container. How can i disable the events on the child button?
I believe you are running to 4.0's new bubbleEvents behavior. Components now propagate some events to their parent containers. This happens in code, independent of DOM event bubbling, up the component hierarchy.
http://dev.sencha.com/deploy/ext-4.0.0/docs/api/Ext.container.Container.html
The best fix is to simply stop the event once you've handled it. That should prevent all bubbling, component or DOM. It is generally a good idea to do this for click events to make sure one and only one thing happens in response to a click, but I'm less certain it's appropriate for mouseover and mouseout.
panel.on('click', function(e) {
e.stopEvent();
// do your stuff
});
another fix you could try (I haven't) is to wipe bubbleEvents on the button.
Another, possibly less robust fix is to turn on event buffering:
el.on('click', this.onClick, this, {buffer: 10});
Buffering collapses duplicate events in a configurable time window into one and it's useful for smoothing out rapid fire or duplicate UI events, but I'm not sure how it plays with bubbling.
{
...
preventDefault: true,
...
}