An abstract command target class. Encapsulates an MFC CCmdTarget
class
-
Displays the cursor as an hourglass.
-
End a wait cursor.
-
Hook a command handler.
-
Hook a windows command update handler.
-
Hooks an OLE event.
-
Hook a control notification handler.
-
Restores the appropriate hourglass cursor after the system cursor has changed.
PyCCmdTarget.BeginWaitCursor
BeginWaitCursor() Displays the cursor as an hourglass. This can be used when you expect a
command to take a noticeable time to execute (eg, when a document
loads or saves itself to a file.).
The actions of BeginWaitCursor are not always effective outside of a single
message handler as other actions, such as OnSetCursor handling, could change
the cursor.
Call EndWaitCursor to restore the previous cursor.
- CWnd::BeginWaitCursor
PyCCmdTarget.EndWaitCursor
EndWaitCursor() Ends a wait cursor. Should only be called after PyCWnd::BeginWaitCursor
.
PyCCmdTarget.HookCommand
object = HookCommand(obHandler, id
) Hook a windows command handler.
-
obHandler : object
The handler for the command message. This must be a callable object.
-
id : int
The ID of the command to be handled, or zero to handle all command messages.
obHandler will be called as the application receives command notification messages with the specified ID.
Command notification messages are usually sent in response to menu or toolbar commands.
When updating a user interface element, Pythonwin will first check if a
handler has been installed via PyCCmdTarget::HookCommandUpdate. If so, this alone
determines the state of the interface object. If no Update handler exists,
PythonWin will automatically enable a menu/toolbar item if a command handler exists
The handler will be called with 2 arguments
* The command id being handled.
* The command notification code.
If the handler returns TRUE, then the command will be passed on to the
default handler, otherwise the message will be consumed.
This method is best suited to handling messages from user interface
elements, such as menus, toolbars, etc. To handle notification messages from a control,
you should use PyCCmdTarget::HookNotify
The return value is the previous handler, or None.
PyCCmdTarget.HookCommandUpdate
object = HookCommandUpdate(obHandler, id
) Hook a windows command update handler.
-
obHandler : object
The handler for the command message. This must be a callable object.
-
id : int
The ID of the command to be handled.
The handler object passed will be called as
the application updates user interface elements
with the specified ID.
See PyCCmdTarget::HookCommand for a description
of the rules used to determine command routing and updating.
The return value is the previous handler, or None.
PyCCmdTarget.HookNotify
object = HookNotify(obHandler, id
) Hook a windows command handler.
-
obHandler : object
The handler for the command message. This must be a callable object.
-
id : int
The ID of the command to be handled, or zero to handle all command messages.
obHandler will be called as the application receives control notification messages.
These may also be handled via PyCCmdTarget::HookCommand, but this method is specific
to control notifications, and therefore provides more information.
The handler will be called with 2 arguments
A tuple describing standard notification information.
A tuple describing extra notification params, or an integer containing the address of the first byte of the extended information.
If the handler returns TRUE, then the command will be passed on to the
default handler, otherwise the message will be consumed.
Certain notification codes are recognised internally, and these are converted to a Python tuple.
If the extra information is not recognised, the address is passed. These addresses could be
extracted using win32ui::GetBytes and the struct module, or using
Sam Rushing's calldll/dynwin module. (It would be possible to extend Pythonwin so a program
can install certain knowledge about handlers, but this has not been implemented.)
The return value is the previous handler, or None.
PyCCmdTarget.HookOleEvent
object = HookOleEvent() Hook an OLE Event.
The return value is the previous handler, or None.
PyCCmdTarget.RestoreWaitCursor
RestoreWaitCursor() Restores the appropriate hourglass cursor after the system cursor has changed.
Call this function to restore the appropriate hourglass cursor after
the system cursor has changed (for example, after a message box has opened
and then closed while in the middle of a lengthy operation).