More ActiveX stuff. Can now automatically catch callbacks (events) from the
COM object. I actually create a new class on the fly that derives from wxWindow, the COM CoClass and others needed to make it all work. The resulting class can be instantiated just like wxWindow, used in sizers, etc. It also responds to all COM method calls, properties, etc. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7148 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,40 +1,15 @@
|
||||
"""
|
||||
ActiveXControl sample usage.
|
||||
|
||||
Based on original code by Willy Heineman, wheineman@uconect.net, 14 February 2000
|
||||
|
||||
ActiveXControl provides a simplified wrapper for creating activeX
|
||||
controls within wxPython GUIs. It allows you to include the activeX
|
||||
control in a sizer, and includes a flag to prevent redrawing the
|
||||
background behind the control (reduces the annoying flicker on
|
||||
Win32 systems).
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.activexwrapper import ActiveXWrapper
|
||||
from wxPython.lib.activexwrapper import MakeActiveXClass
|
||||
|
||||
import pythoncom
|
||||
import pywin.mfc.activex
|
||||
import win32com.client.gencache
|
||||
import win32con
|
||||
import win32ui
|
||||
|
||||
acrobatOCX = win32com.client.gencache.EnsureModule('{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3)
|
||||
if acrobatOCX is None:
|
||||
win32ui.MessageBox("Can't load PDF.OCX, install Acrobat 4.0",
|
||||
'ActiveX Demo',
|
||||
win32con.MB_OK | win32con.MB_ICONSTOP)
|
||||
raise ImportError
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# NOTE:
|
||||
# Your ActiveX control _must_ be an instance of pywin.mfc.activex.Control,
|
||||
# as we use the CreateControl method to bind the GUI systems.
|
||||
|
||||
class PDFControl(pywin.mfc.activex.Control, acrobatOCX.Pdf):
|
||||
def __init__(self):
|
||||
pywin.mfc.activex.Control.__init__(self)
|
||||
acrobatOCX.Pdf.__init__(self)
|
||||
try:
|
||||
acrobat = win32com.client.gencache.EnsureModule('{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3)
|
||||
except:
|
||||
raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@@ -47,12 +22,14 @@ class TestPanel(wxPanel):
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
btnSizer = wxBoxSizer(wxHORIZONTAL)
|
||||
|
||||
# Build the wxPython wrapper window and put the Acrobat
|
||||
# control in it
|
||||
self.axw = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER, eraseBackground=0)
|
||||
self.axw.SetControl( PDFControl() )
|
||||
# this function creates a new class that can be used as
|
||||
# a wxWindow, but contains the given ActiveX control.
|
||||
ActiveXWrapper = MakeActiveXClass(acrobat.Pdf)
|
||||
|
||||
sizer.Add(self.axw, 1, wxEXPAND)
|
||||
# create an instance of the new class
|
||||
self.pdf = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER)
|
||||
|
||||
sizer.Add(self.pdf, 1, wxEXPAND)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Open PDF File")
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
|
||||
@@ -74,24 +51,26 @@ class TestPanel(wxPanel):
|
||||
self.SetAutoLayout(true)
|
||||
|
||||
def __del__(self):
|
||||
self.axw.Cleanup()
|
||||
self.axw = None
|
||||
self.pdf.Cleanup()
|
||||
self.pdf = None
|
||||
|
||||
|
||||
def OnOpenButton(self, event):
|
||||
dlg = wxFileDialog(self, wildcard="*.pdf")
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
self.axw.control.LoadFile(dlg.GetPath())
|
||||
wxBeginBusyCursor()
|
||||
self.pdf.LoadFile(dlg.GetPath())
|
||||
wxEndBusyCursor()
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def OnPrevPageButton(self, event):
|
||||
self.axw.control.gotoPreviousPage()
|
||||
self.pdf.gotoPreviousPage()
|
||||
|
||||
|
||||
def OnNextPageButton(self, event):
|
||||
self.axw.control.gotoNextPage()
|
||||
self.pdf.gotoNextPage()
|
||||
|
||||
|
||||
|
||||
@@ -110,11 +89,12 @@ overview = __doc__
|
||||
if __name__ == '__main__':
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self, None, -1, "ActiveX test -- Acrobat", size=(640, 480))
|
||||
wxFrame.__init__(self, None, -1, "ActiveX test -- Acrobat", size=(640, 480),
|
||||
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
self.tp = TestPanel(self, sys.stdout)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.tp.axw.Cleanup()
|
||||
self.tp.pdf.Cleanup()
|
||||
self.Destroy()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user