Cut, Copy and Paste shortcuts are now working in ActiveXWrapper_IE

I tried using it with wx.lib.iewin.IEHtmlWindow of wxPython 2.5.1.5
There is a problem in this function:

def sendWM_COMMAND(ie, cmdcode, command=win32con.WM_COMMAND):
    # Get the 'Shell Embedding' window.
    cwnd = ie._obj_
    # Get the 'Shell DocObject View'
    cwnd = cwnd.GetWindow(win32con.GW_CHILD)
    # Get the 'Internet Explorer_Server'
    cwnd = cwnd.GetWindow(win32con.GW_CHILD)
    cwnd.SendMessage(command, cmdcode, 0)

AttributeError: 'IEHtmlWin' object has no attribute '_obj_'

Which class has this 'SendMessage' method and how to get it from
'IEHtmlWin'?

···

-----Original Message-----
From: Michael Krause [mailto:michael@krause-software.de]
Sent: Wednesday, June 16, 2004 3:40 PM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] Cut, Copy and Paste shortcuts are now working in
ActiveXWrapper_IE

Hi,
after spending some hours searching for the solution of the shortcuts, the
answers point into something involving functions like
IOleInPlaceActiveObject::TranslateAccelerator,
PreTranslateMessage, wxApp::ProcessMessage, wxApp::ProcessMessage,
wxWindowMSW::MSWProcessMessage. None of them seem to be easily accessible
using wxPython, win32all or ctypes functions, at least not for me.

Instead I came up with a workaround in the wrong direction that covers at
least the basics which are the delete key, cut, copy, paste and undo. The
method only works for simple pages, not for frames or embedded objects like
Flash.

The WM_COMMAND numbers I got from what Winspector logged
while the respective functions were performed in the
original Internet Explorer.
There was no information to be found on the web to relate
these numbers to well known symbols or commands.

I only tested this with wxPython 2.4.2.4u on W2K and IE 6.0.

To see the results, just put the following code inside
the ActiveXWrapper_IE.py demo.

Good luck,
Michael

#----------------------------------------------------------------------

import win32con

def sendWM_COMMAND(ie, cmdcode, command=win32con.WM_COMMAND):
    # Get the 'Shell Embedding' window.
    cwnd = ie._obj_
    # Get the 'Shell DocObject View'
    cwnd = cwnd.GetWindow(win32con.GW_CHILD)
    # Get the 'Internet Explorer_Server'
    cwnd = cwnd.GetWindow(win32con.GW_CHILD)
    cwnd.SendMessage(command, cmdcode, 0)

def send_editWM_COMMAND(ie, cmdcode):
    """Check for editable field before sending the command.

    Internet Explorer happily deletes text from normal HTML elements
    which is neither standard behaviour nor what we want.
    So we only send deletion commands if an INPUT or TEXTAREA is the
    current activeElement.
    The commands do not work with frames or objects like Flash.
    """
    try:
        if ie.Document.activeElement.tagName in ['INPUT', 'TEXTAREA']:
            sendWM_COMMAND(ie, cmdcode)
    except AttributeError:
        # There might not be an activeElement, in this case we wonder
        # how we got here in the first place.
        pass

def enableStandardShortcuts(ie):

    def onDelete(event): send_editWM_COMMAND(ie, 17)
    def onCut(event): send_editWM_COMMAND(ie, 16)
    def onCopy(event): sendWM_COMMAND(ie, 15)
    def onPaste(event): send_editWM_COMMAND(ie, 26)
    def onUndo(event): send_editWM_COMMAND(ie, 43)

    #--------------------------------------------------------------------
    def funcID(func):
        newid = wxNewId()
        EVT_MENU(ie, newid, func)
        return newid

    # set additional keyboard shortcuts
    entry1 = wxAcceleratorEntry(wxACCEL_NORMAL, WXK_DELETE,
funcID(onDelete))
    entry2 = wxAcceleratorEntry(wxACCEL_CTRL, ord('X'), funcID(onCut))
    entry3 = wxAcceleratorEntry(wxACCEL_CTRL, ord('C'), funcID(onCopy))
    entry4 = wxAcceleratorEntry(wxACCEL_CTRL, ord('V'), funcID(onPaste))
    entry5 = wxAcceleratorEntry(wxACCEL_CTRL, ord('Z'), funcID(onUndo))

    acc_table = wxAcceleratorTable([entry1, entry2, entry3, entry4, entry5])
    ie.SetAcceleratorTable(acc_table)
    #--------------------------------------------------------------------

#------------------------------------------------------------------------

# Put the next line right below 'frame = TestFrame()'
    enableStandardShortcuts(frame.tp.ie)

--
- Michael Krause
- http://www.krause-software.de
- michael@krause-software.de

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org