I want to automate UI actions in my program: it can be show a menu, open another form, etc.
I'm using .py
files and .ui
files in my python app.
How can i do this?
问题:
回答1:
Almost all GUI frameworks have a notion of an event, which are typically generated by user actions (button clicking, window dragging, etc.) and send to your handlers.
But event can usually also be sent directly to the event loop. In your case, I'm assuming you're using PyQt and Qt toolkit from Digia.
The PyQt docs for QCoreApplication.sendEvent
look like a good place to start:
bool QCoreApplication.sendEvent (QObject receiver, QEvent event)
Sends event event directly to receiver receiver, using the notify() function. Returns the value that was returned from the event handler.
The event is not deleted when the event has been sent. The normal approach is to create the event on the stack, for example:
QMouseEvent event(QEvent.MouseButtonPress, pos, 0, 0, 0); QApplication.sendEvent(mainWindow, &event);
See also postEvent() and notify().
Don't ignore the see-alsos to postEvent
and notify
.
More information will also be at Digia's Qt docs for postEvent