mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-07-02 22:30:48 +00:00
first commit
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
# Utilities for the demos
|
||||
|
||||
import sys, win32api, win32con, win32ui
|
||||
|
||||
NotScriptMsg = """\
|
||||
This demo program is not designed to be run as a Script, but is
|
||||
probably used by some other test program. Please try another demo.
|
||||
"""
|
||||
|
||||
NeedGUIMsg = """\
|
||||
This demo program can only be run from inside of Pythonwin
|
||||
|
||||
You must start Pythonwin, and select 'Run' from the toolbar or File menu
|
||||
"""
|
||||
|
||||
|
||||
NeedAppMsg = """\
|
||||
This demo program is a 'Pythonwin Application'.
|
||||
|
||||
It is more demo code than an example of Pythonwin's capabilities.
|
||||
|
||||
To run it, you must execute the command:
|
||||
pythonwin.exe /app "%s"
|
||||
|
||||
Would you like to execute it now?
|
||||
"""
|
||||
|
||||
|
||||
def NotAScript():
|
||||
import win32ui
|
||||
|
||||
win32ui.MessageBox(NotScriptMsg, "Demos")
|
||||
|
||||
|
||||
def NeedGoodGUI():
|
||||
from pywin.framework.app import HaveGoodGUI
|
||||
|
||||
rc = HaveGoodGUI()
|
||||
if not rc:
|
||||
win32ui.MessageBox(NeedGUIMsg, "Demos")
|
||||
return rc
|
||||
|
||||
|
||||
def NeedApp():
|
||||
import win32ui
|
||||
|
||||
rc = win32ui.MessageBox(NeedAppMsg % sys.argv[0], "Demos", win32con.MB_YESNO)
|
||||
if rc == win32con.IDYES:
|
||||
try:
|
||||
parent = win32ui.GetMainFrame().GetSafeHwnd()
|
||||
win32api.ShellExecute(
|
||||
parent, None, "pythonwin.exe", '/app "%s"' % sys.argv[0], None, 1
|
||||
)
|
||||
except win32api.error as details:
|
||||
win32ui.MessageBox("Error executing command - %s" % (details), "Demos")
|
||||
|
||||
|
||||
from pywin.framework.app import HaveGoodGUI
|
||||
|
||||
if __name__ == "__main__":
|
||||
from . import demoutils
|
||||
|
||||
demoutils.NotAScript()
|
91
.venv/Lib/site-packages/pythonwin/pywin/Demos/ocx/flash.py
Normal file
91
.venv/Lib/site-packages/pythonwin/pywin/Demos/ocx/flash.py
Normal file
@ -0,0 +1,91 @@
|
||||
# By Bradley Schatz
|
||||
# simple flash/python application demonstrating bidirectional
|
||||
# communicaion between flash and python. Click the sphere to see
|
||||
# behavior. Uses Bounce.swf from FlashBounce.zip, available from
|
||||
# http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial12/
|
||||
|
||||
# Update to the path of the .swf file (note it could be a true URL)
|
||||
flash_url = "c:\\bounce.swf"
|
||||
|
||||
import win32ui, win32con, win32api, regutil
|
||||
from pywin.mfc import window, activex
|
||||
from win32com.client import gencache
|
||||
import sys
|
||||
|
||||
FlashModule = gencache.EnsureModule("{D27CDB6B-AE6D-11CF-96B8-444553540000}", 0, 1, 0)
|
||||
|
||||
if FlashModule is None:
|
||||
raise ImportError("Flash does not appear to be installed.")
|
||||
|
||||
|
||||
class MyFlashComponent(activex.Control, FlashModule.ShockwaveFlash):
|
||||
def __init__(self):
|
||||
activex.Control.__init__(self)
|
||||
FlashModule.ShockwaveFlash.__init__(self)
|
||||
self.x = 50
|
||||
self.y = 50
|
||||
self.angle = 30
|
||||
self.started = 0
|
||||
|
||||
def OnFSCommand(self, command, args):
|
||||
print("FSCommend", command, args)
|
||||
self.x = self.x + 20
|
||||
self.y = self.y + 20
|
||||
self.angle = self.angle + 20
|
||||
if self.x > 200 or self.y > 200:
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
if self.angle > 360:
|
||||
self.angle = 0
|
||||
self.SetVariable("xVal", self.x)
|
||||
self.SetVariable("yVal", self.y)
|
||||
self.SetVariable("angle", self.angle)
|
||||
self.TPlay("_root.mikeBall")
|
||||
|
||||
def OnProgress(self, percentDone):
|
||||
print("PercentDone", percentDone)
|
||||
|
||||
def OnReadyStateChange(self, newState):
|
||||
# 0=Loading, 1=Uninitialized, 2=Loaded, 3=Interactive, 4=Complete
|
||||
print("State", newState)
|
||||
|
||||
|
||||
class BrowserFrame(window.MDIChildWnd):
|
||||
def __init__(self, url=None):
|
||||
if url is None:
|
||||
self.url = regutil.GetRegisteredHelpFile("Main Python Documentation")
|
||||
else:
|
||||
self.url = url
|
||||
pass # Dont call base class doc/view version...
|
||||
|
||||
def Create(self, title, rect=None, parent=None):
|
||||
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW
|
||||
self._obj_ = win32ui.CreateMDIChild()
|
||||
self._obj_.AttachObject(self)
|
||||
self._obj_.CreateWindow(None, title, style, rect, parent)
|
||||
rect = self.GetClientRect()
|
||||
rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])
|
||||
self.ocx = MyFlashComponent()
|
||||
self.ocx.CreateControl(
|
||||
"Flash Player", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 1000
|
||||
)
|
||||
self.ocx.LoadMovie(0, flash_url)
|
||||
self.ocx.Play()
|
||||
self.HookMessage(self.OnSize, win32con.WM_SIZE)
|
||||
|
||||
def OnSize(self, params):
|
||||
rect = self.GetClientRect()
|
||||
rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])
|
||||
self.ocx.SetWindowPos(0, rect, 0)
|
||||
|
||||
|
||||
def Demo():
|
||||
url = None
|
||||
if len(sys.argv) > 1:
|
||||
url = win32api.GetFullPathName(sys.argv[1])
|
||||
f = BrowserFrame(url)
|
||||
f.Create("Flash Player")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Demo()
|
147
.venv/Lib/site-packages/pythonwin/pywin/Demos/ocx/msoffice.py
Normal file
147
.venv/Lib/site-packages/pythonwin/pywin/Demos/ocx/msoffice.py
Normal file
@ -0,0 +1,147 @@
|
||||
# This demo uses some of the Microsoft Office components.
|
||||
#
|
||||
# It was taken from an MSDN article showing how to embed excel.
|
||||
# It is not comlpete yet, but it _does_ show an Excel spreadsheet in a frame!
|
||||
#
|
||||
|
||||
import win32ui, win32uiole, win32con, regutil
|
||||
from pywin.mfc import window, activex, object, docview
|
||||
from win32com.client import gencache
|
||||
|
||||
# WordModule = gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 1033, 8, 0)
|
||||
# if WordModule is None:
|
||||
# raise ImportError, "Microsoft Word version 8 does not appear to be installed."
|
||||
|
||||
|
||||
class OleClientItem(object.CmdTarget):
|
||||
def __init__(self, doc):
|
||||
object.CmdTarget.__init__(self, win32uiole.CreateOleClientItem(doc))
|
||||
|
||||
def OnGetItemPosition(self):
|
||||
# For now return a hard-coded rect.
|
||||
return (10, 10, 210, 210)
|
||||
|
||||
def OnActivate(self):
|
||||
# Allow only one inplace activate item per frame
|
||||
view = self.GetActiveView()
|
||||
item = self.GetDocument().GetInPlaceActiveItem(view)
|
||||
if item is not None and item._obj_ != self._obj_:
|
||||
item.Close()
|
||||
self._obj_.OnActivate()
|
||||
|
||||
def OnChange(self, oleNotification, dwParam):
|
||||
self._obj_.OnChange(oleNotification, dwParam)
|
||||
self.GetDocument().UpdateAllViews(None)
|
||||
|
||||
def OnChangeItemPosition(self, rect):
|
||||
# During in-place activation CEmbed_ExcelCntrItem::OnChangeItemPosition
|
||||
# is called by the server to change the position of the in-place
|
||||
# window. Usually, this is a result of the data in the server
|
||||
# document changing such that the extent has changed or as a result
|
||||
# of in-place resizing.
|
||||
#
|
||||
# The default here is to call the base class, which will call
|
||||
# COleClientItem::SetItemRects to move the item
|
||||
# to the new position.
|
||||
if not self._obj_.OnChangeItemPosition(self, rect):
|
||||
return 0
|
||||
|
||||
# TODO: update any cache you may have of the item's rectangle/extent
|
||||
return 1
|
||||
|
||||
|
||||
class OleDocument(object.CmdTarget):
|
||||
def __init__(self, template):
|
||||
object.CmdTarget.__init__(self, win32uiole.CreateOleDocument(template))
|
||||
self.EnableCompoundFile()
|
||||
|
||||
|
||||
class ExcelView(docview.ScrollView):
|
||||
def OnInitialUpdate(self):
|
||||
self.HookMessage(self.OnSetFocus, win32con.WM_SETFOCUS)
|
||||
self.HookMessage(self.OnSize, win32con.WM_SIZE)
|
||||
|
||||
self.SetScrollSizes(win32con.MM_TEXT, (100, 100))
|
||||
rc = self._obj_.OnInitialUpdate()
|
||||
self.EmbedExcel()
|
||||
return rc
|
||||
|
||||
def EmbedExcel(self):
|
||||
doc = self.GetDocument()
|
||||
self.clientItem = OleClientItem(doc)
|
||||
self.clientItem.CreateNewItem("Excel.Sheet")
|
||||
self.clientItem.DoVerb(-1, self)
|
||||
doc.UpdateAllViews(None)
|
||||
|
||||
def OnDraw(self, dc):
|
||||
doc = self.GetDocument()
|
||||
pos = doc.GetStartPosition()
|
||||
clientItem, pos = doc.GetNextItem(pos)
|
||||
clientItem.Draw(dc, (10, 10, 210, 210))
|
||||
|
||||
# Special handling of OnSetFocus and OnSize are required for a container
|
||||
# when an object is being edited in-place.
|
||||
def OnSetFocus(self, msg):
|
||||
item = self.GetDocument().GetInPlaceActiveItem(self)
|
||||
if (
|
||||
item is not None
|
||||
and item.GetItemState() == win32uiole.COleClientItem_activeUIState
|
||||
):
|
||||
wnd = item.GetInPlaceWindow()
|
||||
if wnd is not None:
|
||||
wnd.SetFocus()
|
||||
return 0 # Dont get the base version called.
|
||||
return 1 # Call the base version.
|
||||
|
||||
def OnSize(self, params):
|
||||
item = self.GetDocument().GetInPlaceActiveItem(self)
|
||||
if item is not None:
|
||||
item.SetItemRects()
|
||||
return 1 # do call the base!
|
||||
|
||||
|
||||
class OleTemplate(docview.DocTemplate):
|
||||
def __init__(
|
||||
self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None
|
||||
):
|
||||
if MakeDocument is None:
|
||||
MakeDocument = OleDocument
|
||||
if MakeView is None:
|
||||
MakeView = ExcelView
|
||||
docview.DocTemplate.__init__(
|
||||
self, resourceId, MakeDocument, MakeFrame, MakeView
|
||||
)
|
||||
|
||||
|
||||
class WordFrame(window.MDIChildWnd):
|
||||
def __init__(self, doc=None):
|
||||
self._obj_ = win32ui.CreateMDIChild()
|
||||
self._obj_.AttachObject(self)
|
||||
# Dont call base class doc/view version...
|
||||
|
||||
def Create(self, title, rect=None, parent=None):
|
||||
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW
|
||||
self._obj_.CreateWindow(None, title, style, rect, parent)
|
||||
|
||||
rect = self.GetClientRect()
|
||||
rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])
|
||||
self.ocx = MyWordControl()
|
||||
self.ocx.CreateControl(
|
||||
"Microsoft Word", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 20000
|
||||
)
|
||||
|
||||
|
||||
def Demo():
|
||||
import sys, win32api
|
||||
|
||||
docName = None
|
||||
if len(sys.argv) > 1:
|
||||
docName = win32api.GetFullPathName(sys.argv[1])
|
||||
OleTemplate().OpenDocumentFile(None)
|
||||
|
||||
|
||||
# f = WordFrame(docName)
|
||||
# f.Create("Microsoft Office")
|
||||
|
||||
if __name__ == "__main__":
|
||||
Demo()
|
@ -0,0 +1,132 @@
|
||||
# ocxserialtest.py
|
||||
#
|
||||
# Sample that uses the mscomm OCX to talk to a serial
|
||||
# device.
|
||||
|
||||
# Very simple - queries a modem for ATI responses
|
||||
|
||||
import win32ui, win32uiole
|
||||
import win32con
|
||||
from pywin.mfc import dialog, activex
|
||||
from win32com.client import gencache
|
||||
import pythoncom
|
||||
|
||||
SERIAL_SETTINGS = "19200,n,8,1"
|
||||
SERIAL_PORT = 2
|
||||
|
||||
win32ui.DoWaitCursor(1)
|
||||
serialModule = gencache.EnsureModule("{648A5603-2C6E-101B-82B6-000000000014}", 0, 1, 1)
|
||||
win32ui.DoWaitCursor(0)
|
||||
if serialModule is None:
|
||||
raise ImportError("MS COMM Control does not appear to be installed on the PC")
|
||||
|
||||
|
||||
def MakeDlgTemplate():
|
||||
style = (
|
||||
win32con.DS_MODALFRAME
|
||||
| win32con.WS_POPUP
|
||||
| win32con.WS_VISIBLE
|
||||
| win32con.WS_CAPTION
|
||||
| win32con.WS_SYSMENU
|
||||
| win32con.DS_SETFONT
|
||||
)
|
||||
cs = win32con.WS_CHILD | win32con.WS_VISIBLE
|
||||
dlg = [
|
||||
["Very Basic Terminal", (0, 0, 350, 180), style, None, (8, "MS Sans Serif")],
|
||||
]
|
||||
s = win32con.WS_TABSTOP | cs
|
||||
dlg.append(
|
||||
[
|
||||
"RICHEDIT",
|
||||
None,
|
||||
132,
|
||||
(5, 5, 340, 170),
|
||||
s
|
||||
| win32con.ES_WANTRETURN
|
||||
| win32con.ES_MULTILINE
|
||||
| win32con.ES_AUTOVSCROLL
|
||||
| win32con.WS_VSCROLL,
|
||||
]
|
||||
)
|
||||
return dlg
|
||||
|
||||
|
||||
####################################
|
||||
#
|
||||
# Serial Control
|
||||
#
|
||||
class MySerialControl(activex.Control, serialModule.MSComm):
|
||||
def __init__(self, parent):
|
||||
activex.Control.__init__(self)
|
||||
serialModule.MSComm.__init__(self)
|
||||
self.parent = parent
|
||||
|
||||
def OnComm(self):
|
||||
self.parent.OnComm()
|
||||
|
||||
|
||||
class TestSerDialog(dialog.Dialog):
|
||||
def __init__(self, *args):
|
||||
dialog.Dialog.__init__(*(self,) + args)
|
||||
self.olectl = None
|
||||
|
||||
def OnComm(self):
|
||||
event = self.olectl.CommEvent
|
||||
if event == serialModule.OnCommConstants.comEvReceive:
|
||||
self.editwindow.ReplaceSel(self.olectl.Input)
|
||||
|
||||
def OnKey(self, key):
|
||||
if self.olectl:
|
||||
self.olectl.Output = chr(key)
|
||||
|
||||
def OnInitDialog(self):
|
||||
rc = dialog.Dialog.OnInitDialog(self)
|
||||
self.editwindow = self.GetDlgItem(132)
|
||||
self.editwindow.HookAllKeyStrokes(self.OnKey)
|
||||
|
||||
self.olectl = MySerialControl(self)
|
||||
try:
|
||||
self.olectl.CreateControl(
|
||||
"OCX",
|
||||
win32con.WS_TABSTOP | win32con.WS_VISIBLE,
|
||||
(7, 43, 500, 300),
|
||||
self._obj_,
|
||||
131,
|
||||
)
|
||||
except win32ui.error:
|
||||
self.MessageBox("The Serial Control could not be created")
|
||||
self.olectl = None
|
||||
self.EndDialog(win32con.IDCANCEL)
|
||||
if self.olectl:
|
||||
self.olectl.Settings = SERIAL_SETTINGS
|
||||
self.olectl.CommPort = SERIAL_PORT
|
||||
self.olectl.RThreshold = 1
|
||||
try:
|
||||
self.olectl.PortOpen = 1
|
||||
except pythoncom.com_error as details:
|
||||
print(
|
||||
"Could not open the specified serial port - %s"
|
||||
% (details.excepinfo[2])
|
||||
)
|
||||
self.EndDialog(win32con.IDCANCEL)
|
||||
return rc
|
||||
|
||||
def OnDestroy(self, msg):
|
||||
if self.olectl:
|
||||
try:
|
||||
self.olectl.PortOpen = 0
|
||||
except pythoncom.com_error as details:
|
||||
print("Error closing port - %s" % (details.excepinfo[2]))
|
||||
return dialog.Dialog.OnDestroy(self, msg)
|
||||
|
||||
|
||||
def test():
|
||||
d = TestSerDialog(MakeDlgTemplate())
|
||||
d.DoModal()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from . import demoutils
|
||||
|
||||
if demoutils.NeedGoodGUI():
|
||||
test()
|
246
.venv/Lib/site-packages/pythonwin/pywin/Demos/ocx/ocxtest.py
Normal file
246
.venv/Lib/site-packages/pythonwin/pywin/Demos/ocx/ocxtest.py
Normal file
@ -0,0 +1,246 @@
|
||||
# OCX Tester for Pythonwin
|
||||
#
|
||||
# This file _is_ ready to run. All that is required is that the OCXs being tested
|
||||
# are installed on your machine.
|
||||
#
|
||||
# The .py files behind the OCXs will be automatically generated and imported.
|
||||
|
||||
from pywin.mfc import dialog, window, activex
|
||||
import win32ui, win32uiole
|
||||
import win32con
|
||||
import os, sys, win32api, glob
|
||||
from win32com.client import gencache
|
||||
|
||||
|
||||
def MakeDlgTemplate():
|
||||
style = (
|
||||
win32con.DS_MODALFRAME
|
||||
| win32con.WS_POPUP
|
||||
| win32con.WS_VISIBLE
|
||||
| win32con.WS_CAPTION
|
||||
| win32con.WS_SYSMENU
|
||||
| win32con.DS_SETFONT
|
||||
)
|
||||
cs = win32con.WS_CHILD | win32con.WS_VISIBLE
|
||||
dlg = [
|
||||
["OCX Demos", (0, 0, 350, 350), style, None, (8, "MS Sans Serif")],
|
||||
]
|
||||
s = win32con.WS_TABSTOP | cs
|
||||
# dlg.append([131, None, 130, (5, 40, 110, 48),
|
||||
# s | win32con.LBS_NOTIFY | win32con.LBS_SORT | win32con.LBS_NOINTEGRALHEIGHT | win32con.WS_VSCROLL | win32con.WS_BORDER])
|
||||
# dlg.append(["{8E27C92B-1264-101C-8A2F-040224009C02}", None, 131, (5, 40, 110, 48),win32con.WS_TABSTOP])
|
||||
|
||||
dlg.append(
|
||||
[128, "About", win32con.IDOK, (124, 5, 50, 14), s | win32con.BS_DEFPUSHBUTTON]
|
||||
)
|
||||
s = win32con.BS_PUSHBUTTON | s
|
||||
dlg.append([128, "Close", win32con.IDCANCEL, (124, 22, 50, 14), s])
|
||||
|
||||
return dlg
|
||||
|
||||
|
||||
####################################
|
||||
#
|
||||
# Calendar test code
|
||||
#
|
||||
|
||||
|
||||
def GetTestCalendarClass():
|
||||
global calendarParentModule
|
||||
win32ui.DoWaitCursor(1)
|
||||
calendarParentModule = gencache.EnsureModule(
|
||||
"{8E27C92E-1264-101C-8A2F-040224009C02}", 0, 7, 0
|
||||
)
|
||||
win32ui.DoWaitCursor(0)
|
||||
if calendarParentModule is None:
|
||||
return None
|
||||
|
||||
class TestCalDialog(dialog.Dialog):
|
||||
def OnInitDialog(self):
|
||||
class MyCal(activex.Control, calendarParentModule.Calendar):
|
||||
def OnAfterUpdate(self):
|
||||
print("OnAfterUpdate")
|
||||
|
||||
def OnClick(self):
|
||||
print("OnClick")
|
||||
|
||||
def OnDblClick(self):
|
||||
print("OnDblClick")
|
||||
|
||||
def OnKeyDown(self, KeyCode, Shift):
|
||||
print("OnKeyDown", KeyCode, Shift)
|
||||
|
||||
def OnKeyPress(self, KeyAscii):
|
||||
print("OnKeyPress", KeyAscii)
|
||||
|
||||
def OnKeyUp(self, KeyCode, Shift):
|
||||
print("OnKeyUp", KeyCode, Shift)
|
||||
|
||||
def OnBeforeUpdate(self, Cancel):
|
||||
print("OnBeforeUpdate", Cancel)
|
||||
|
||||
def OnNewMonth(self):
|
||||
print("OnNewMonth")
|
||||
|
||||
def OnNewYear(self):
|
||||
print("OnNewYear")
|
||||
|
||||
rc = dialog.Dialog.OnInitDialog(self)
|
||||
self.olectl = MyCal()
|
||||
try:
|
||||
self.olectl.CreateControl(
|
||||
"OCX",
|
||||
win32con.WS_TABSTOP | win32con.WS_VISIBLE,
|
||||
(7, 43, 500, 300),
|
||||
self._obj_,
|
||||
131,
|
||||
)
|
||||
except win32ui.error:
|
||||
self.MessageBox("The Calendar Control could not be created")
|
||||
self.olectl = None
|
||||
self.EndDialog(win32con.IDCANCEL)
|
||||
|
||||
return rc
|
||||
|
||||
def OnOK(self):
|
||||
self.olectl.AboutBox()
|
||||
|
||||
return TestCalDialog
|
||||
|
||||
|
||||
####################################
|
||||
#
|
||||
# Video Control
|
||||
#
|
||||
def GetTestVideoModule():
|
||||
global videoControlModule, videoControlFileName
|
||||
win32ui.DoWaitCursor(1)
|
||||
videoControlModule = gencache.EnsureModule(
|
||||
"{05589FA0-C356-11CE-BF01-00AA0055595A}", 0, 2, 0
|
||||
)
|
||||
win32ui.DoWaitCursor(0)
|
||||
if videoControlModule is None:
|
||||
return None
|
||||
fnames = glob.glob(os.path.join(win32api.GetWindowsDirectory(), "*.avi"))
|
||||
if not fnames:
|
||||
print("No AVI files available in system directory")
|
||||
return None
|
||||
videoControlFileName = fnames[0]
|
||||
return videoControlModule
|
||||
|
||||
|
||||
def GetTestVideoDialogClass():
|
||||
if GetTestVideoModule() is None:
|
||||
return None
|
||||
|
||||
class TestVideoDialog(dialog.Dialog):
|
||||
def OnInitDialog(self):
|
||||
rc = dialog.Dialog.OnInitDialog(self)
|
||||
try:
|
||||
self.olectl = activex.MakeControlInstance(
|
||||
videoControlModule.ActiveMovie
|
||||
)
|
||||
self.olectl.CreateControl(
|
||||
"",
|
||||
win32con.WS_TABSTOP | win32con.WS_VISIBLE,
|
||||
(7, 43, 500, 300),
|
||||
self._obj_,
|
||||
131,
|
||||
)
|
||||
except win32ui.error:
|
||||
self.MessageBox("The Video Control could not be created")
|
||||
self.olectl = None
|
||||
self.EndDialog(win32con.IDCANCEL)
|
||||
return
|
||||
|
||||
self.olectl.FileName = videoControlFileName
|
||||
# self.olectl.Run()
|
||||
return rc
|
||||
|
||||
def OnOK(self):
|
||||
self.olectl.AboutBox()
|
||||
|
||||
return TestVideoDialog
|
||||
|
||||
|
||||
###############
|
||||
#
|
||||
# An OCX in an MDI Frame
|
||||
#
|
||||
class OCXFrame(window.MDIChildWnd):
|
||||
def __init__(self):
|
||||
pass # Dont call base class doc/view version...
|
||||
|
||||
def Create(self, controlClass, title, rect=None, parent=None):
|
||||
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW
|
||||
self._obj_ = win32ui.CreateMDIChild()
|
||||
self._obj_.AttachObject(self)
|
||||
self._obj_.CreateWindow(None, title, style, rect, parent)
|
||||
|
||||
rect = self.GetClientRect()
|
||||
rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])
|
||||
self.ocx = controlClass()
|
||||
self.ocx.CreateControl(
|
||||
"", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 1000
|
||||
)
|
||||
|
||||
|
||||
def MDITest():
|
||||
calendarParentModule = gencache.EnsureModule(
|
||||
"{8E27C92E-1264-101C-8A2F-040224009C02}", 0, 7, 0
|
||||
)
|
||||
|
||||
class MyCal(activex.Control, calendarParentModule.Calendar):
|
||||
def OnAfterUpdate(self):
|
||||
print("OnAfterUpdate")
|
||||
|
||||
def OnClick(self):
|
||||
print("OnClick")
|
||||
|
||||
f = OCXFrame()
|
||||
f.Create(MyCal, "Calendar Test")
|
||||
|
||||
|
||||
def test1():
|
||||
klass = GetTestCalendarClass()
|
||||
if klass is None:
|
||||
print(
|
||||
"Can not test the MSAccess Calendar control - it does not appear to be installed"
|
||||
)
|
||||
return
|
||||
|
||||
d = klass(MakeDlgTemplate())
|
||||
d.DoModal()
|
||||
|
||||
|
||||
def test2():
|
||||
klass = GetTestVideoDialogClass()
|
||||
if klass is None:
|
||||
print("Can not test the Video OCX - it does not appear to be installed,")
|
||||
print("or no AVI files can be found.")
|
||||
return
|
||||
d = klass(MakeDlgTemplate())
|
||||
d.DoModal()
|
||||
d = None
|
||||
|
||||
|
||||
def test3():
|
||||
d = TestCOMMDialog(MakeDlgTemplate())
|
||||
d.DoModal()
|
||||
d = None
|
||||
|
||||
|
||||
def testall():
|
||||
test1()
|
||||
test2()
|
||||
|
||||
|
||||
def demo():
|
||||
testall()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from . import demoutils
|
||||
|
||||
if demoutils.NeedGoodGUI():
|
||||
testall()
|
@ -0,0 +1,68 @@
|
||||
# This demo uses the IE4 Web Browser control.
|
||||
|
||||
# It catches an "OnNavigate" event, and updates the frame title.
|
||||
# (event stuff by Neil Hodgson)
|
||||
|
||||
import win32ui, win32con, win32api, regutil
|
||||
from pywin.mfc import window, activex
|
||||
from win32com.client import gencache
|
||||
import sys
|
||||
|
||||
WebBrowserModule = gencache.EnsureModule(
|
||||
"{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1
|
||||
)
|
||||
if WebBrowserModule is None:
|
||||
raise ImportError("IE4 does not appear to be installed.")
|
||||
|
||||
|
||||
class MyWebBrowser(activex.Control, WebBrowserModule.WebBrowser):
|
||||
def OnBeforeNavigate2(
|
||||
self, pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel
|
||||
):
|
||||
self.GetParent().OnNavigate(URL)
|
||||
# print "BeforeNavigate2", pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel
|
||||
|
||||
|
||||
class BrowserFrame(window.MDIChildWnd):
|
||||
def __init__(self, url=None):
|
||||
if url is None:
|
||||
self.url = regutil.GetRegisteredHelpFile("Main Python Documentation")
|
||||
if self.url is None:
|
||||
self.url = "http://www.python.org"
|
||||
else:
|
||||
self.url = url
|
||||
pass # Dont call base class doc/view version...
|
||||
|
||||
def Create(self, title, rect=None, parent=None):
|
||||
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW
|
||||
self._obj_ = win32ui.CreateMDIChild()
|
||||
self._obj_.AttachObject(self)
|
||||
self._obj_.CreateWindow(None, title, style, rect, parent)
|
||||
rect = self.GetClientRect()
|
||||
rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])
|
||||
self.ocx = MyWebBrowser()
|
||||
self.ocx.CreateControl(
|
||||
"Web Browser", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 1000
|
||||
)
|
||||
self.ocx.Navigate(self.url)
|
||||
self.HookMessage(self.OnSize, win32con.WM_SIZE)
|
||||
|
||||
def OnSize(self, params):
|
||||
rect = self.GetClientRect()
|
||||
rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])
|
||||
self.ocx.SetWindowPos(0, rect, 0)
|
||||
|
||||
def OnNavigate(self, url):
|
||||
title = "Web Browser - %s" % (url,)
|
||||
self.SetWindowText(title)
|
||||
|
||||
|
||||
def Demo(url=None):
|
||||
if url is None and len(sys.argv) > 1:
|
||||
url = win32api.GetFullPathName(sys.argv[1])
|
||||
f = BrowserFrame(url)
|
||||
f.Create("Web Browser")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Demo()
|
Reference in New Issue
Block a user