I have a wx.html2 widget in my panel. Sadly wx.html2 doesn't have many event listeners (http://wxpython.org/Phoenix/docs/html/html2.WebView.html#events-events-emitted-by-this-class).
Now I have this binding to my panel (self is the panel);
self.Bind(wx.EVT_KEY_DOWN, self.OnRightClick)
.. and it works when I type in a blanco panel/frame as intended.
I wonder if there is a way to add more event listeners to the wx.html2 manually or make a global event listener that listens, no matter the sub-widget the event happens in.
This does not work either (self.wv is the wx.html object);
self.wv.Bind(wx.EVT_KEY_DOWN, self.OnRightClick)
Update
I'm fixing the catching of keys/mouse-actions with JavaScript inside my HTML page now. It works, but I would like it more that actions can be bound to the wx.html2 object.
There are only a few events emitted by WebView, all of which can be found in WebView - wxPython (Phoenix) 2.9.5.80 documentation.
Related
Here's the situation:
I have a custom widget subclassed from QTabWidget that I've implemented to accept QDropEvents for files. When files are dropped on the TabWidget they are opened for editing. This part works fine. However, I want to implement drag and drop functionality as part of the editor (think like a LabView-esque GUI). I have properly implemented the event handlers and acceptsDrops on the EditorWidget but the TabWidget receives all the events and attempts to process them as files. I can differentiate file-related events from the editor's events by mimedata but I can't figure out how to pass the event from the TabWidgeton to the appropriate EditorWidget.
So the question:
How can I pass a QDropEvent from the widget which received it from the system to another widget which it owns? Alternatively, how do I tell the system which widget should receive the event, based on the contents of said event?
What I've tried:
I can't call the dropEvent method of the child as it's protected. I could create a series of my own methods that pass the events around but that seems redundant and fragile. I've looked into installing an EventFilter, but from what I can tell that only discards events, it doesn't say "not me try someone else."
Thanks in advance for your assistance!
Intersting! I think that accepting the event in the parent widget, and then trying to forward it to the child widget, is not the right approach architecturally. It would basically violate encapsulation (objects handling their own events).
If I were you, I would investigate why the child widget isn't seeing the event first. Children widgets are on top of their parents, so your child widget should have a first go at the event. Did you call setAcceptDrops(true)?
When you fix that, in the child widget event handler you can analyze the event and call event->ignore() if the event should be forwarded to the parent QTabWidget. If you don't call ignore(), the child will "consume" the event and it will not be propagated to the parent!
Here's an old blog post on event propagation that could help:
http://blog.qt.io/blog/2006/05/27/mouse-event-propagation/
Solving my own problem:
As Pliny stated the child should see the event first. My problem appears to have been that in EditorWidget I had not implemented dragEnterEvent and dragMoveEvent so even though I had implemented dropEvent in EditorWidget the TabWidget took control of the drag and therefore stole the drop.
I have a CDialogEx Class called Properties in which I handle the ON_COMMAND message. Now, ON_COMMAND should get called when I click the menu item ID_EDIT_PROPERTIES (as a submenu from main menu). The event handler wizard wrote that code for me, but when I start the Application the menu item remains grayed out. I've tried to manually activate it by calling EnableMenuItem when ON_UPDATE_COMMAND_UI happens, but to no avail.
Any help would be greatly appreciated.
You just need to understand how menu items enabling/disabling is handled:
If there is neither ON_COMMAND nor ON_UPDATE_COMMAND_UI handler the item is disabled.
If there exists no ON_UPDATE_COMMAND_UI handler but there is an ON_COMMAND one in the currently active document or view (or even the "mainframe"), the item is enabled.
If there exists a ON_UPDATE_COMMAND_UI handler, en-/disabling the item is determined by the handler (pCmdUI->Enable(bEnableState)).
Also keep in mind that:
You may not call EnableMenuItem() yourself, instead call pCmdUI->Enable(bEnableState) in an ON_UPDATE_COMMAND_UI handler. This affects not only the menu item, but any other "command"-type item (with the same ID), eg main menu, context menu, toolbar or rebar button.
Where to put the handler, is a matter of application design and depends on the data you are processing or representing. It can be put in the mainframe class (if it depends on some "global" data or setting), in the document class (if it depends on or changes some data or setting in the document - possibly affecting all views), or in the view class(-es) (depending on or affecting the current view only).
In your case, if I understand correctly, the item is disabled because the handler is in the CDialogEx-derived class, but no instance of this class has been created yet, ie there exists no ON_COMMAND handler for your ID_EDIT_PROPERTIES command.
Per m_bAutoMenuEnable, When this data member is enabled (which is the default), menu items that do not have ON_UPDATE_COMMAND_UI or ON_COMMAND handlers will be automatically disabled when the user pulls down a menu.
I admit that I don't know ii it is different for CDialogEx, But for CDialog I found that the UPDATE_COMMAND_UI didn't ever work unless I handled the WM_KICKIDLE event.
In your OnKickIdle event handler make a call to:
CWnd::UpdateDialogControls
There is a short tutorial on it here.
Forgive me if CDialogEx supercedes this information and I will remove the answer.
I am new in Tkinter.
And I want to know is there any way to catch some custom events for widgets,
for example catch on_packed event after widget.pack() or on_paint event for canvas widget after drawing some graphics on canvas, etc?
The events you describe don't exist. You can use the event_generate method to create your own custom events if you wish. With that you could create your own widget classes that emit any custom events you want.
Custom events must always be defined with double angle brackets. For example, the following line of code will create an event named <<OnPaint>>:
the_canvas.event_generate("<<OnPaint>>")
You can then bind to that event just like you do any other event:
the_canvas.bind("<<OnPaint>>", do_on_paint)
In the specific case of on_pack, there are events that probably do what you want at a more abstract level. For example, there are events that fire when a widget becomes visible (<Visibility>), changes size (<Configure>), and a few others.
The official tcl/tk documentation lists supported events. See the bind man page.
The list of possible event types is far more extensive than the few you typically see used in example, such as Key, Button, Motion, and Mousewheel. Here is a partial list. It appears that packing should generate a Map event.
I need to get the list of all events fired in a Qt Widget ( Qt C++) like an utility which can capture all events or some function which will be called and the event details to be passed to the function every time an event is fired.
Can somebody tell me how to do this or is there any free utility available for this purpose ?
QObject::installEventFilter is what you want. You can see all events coming into an object.
If you need to see all events for everything, you can install event filter on QApplication, see documentation to QCoreApplication::notify:
Installing an event filter on QCoreApplication::instance(). Such an
event filter is able to process all events for all widgets, so it's
just as powerful as reimplementing notify(); furthermore, it's
possible to have more than one application-global event filter. Global
event filters even see mouse events for disabled widgets. Note that
application event filters are only called for objects that live in the
main thread.
If you make a class derived from QWidget (let's call it RecordingWidget) you can reimplement it's event() function to record in whatever manner you'd like (maybe keep a log in a static member of RecordingWidget) and then continue to pass the event to QWidget's default event function:
bool RecordingWidget::event(QEvent *event)
{
// Record stuff
...
// Send the event through QWidget's default event implementation
return QWidget::event(event);
}
I have a app that has items that can contain child items and so on.
Each item has a mouseDown event that i want to be able to use to click and select an item.
The problem is that when i click a child item the parents mouseDown event is also being called.
How do i stop this so the mouseDown event only gets called once or if thats not posible i actually want the function called within the mouseDown event to only get called once.
Here is a jsfiddle to very simply show this. http://jsfiddle.net/rmossuk/W9vmW/1/
If you click no the Click here its mouse down event gets called twice.
You have to return false; in the mouseDown function.
Or you can you use event.stopPropagation(). I updated your fiddle, see http://jsfiddle.net/W9vmW/2/.
There is more informations about how event bubbling in ember works here - http://emberjs.com/guides/view_layer/#toc_event-bubbling
Events will bubble up the view hierarchy until the event reaches the root view. An event handler can stop propagation using the same techniques as normal jQuery event handlers:
return false from the method
event.stopPropagation