"Open Tcl is a Tcl extension to provide connectivity to the resident host's component model." http://www.sys.uea.ac.uk/~fuzz/optcl/default.html Farzad Pezeshkpour wrote and maintains it.
[Recommend Leslie Brooks' nice example [L1 ] and commentary ...]
An example:
# # Open Word and read the template for the report. (The template # contains Header and Footer macros that we will use.) # set word [optcl::new word.application] set filename [file join [pwd] "Chapter 5 template.doc"] set doc [$word -with documents open $filename] # # Set the header by running a Word Macro recorded in the # template file and passing it the parameters it needs # (System Release, RTP version, and Test Step). # $word run header "$test_step" "$SR" "$RTP_Version" $word run footer "$Operator"
The template for the header macro is
Sub Header(TestStep As String, SR As String, RTP As String) ' ' Header Macro ' Macro recorded 7/24/01 by Leslie Brooks ' Set the Test Step number, the System Release number, and the ' RTP version number in the report header. . . . End Sub
Michael Jacobson: Here is some code to display a Microsoft's Internet Explorer ActiveX component in a Tk frame with the IE's scroll bar.
MPJ (5/02) Changed to use ProgId from the registry instead of the CLSID. The CLSID is a string representation of a COM Globally Unique IDentifer (GUID for short). This should make it a little easier to understand instead of the ProgId numbers.
package require optcl wm title . {WebBrowers in Tk with scroll} set htm [optcl::new -window .htm Shell.Explorer.2] ;# for MSIE ActiveX Control # set htm [optcl::new -window .htm Mozilla.Browser.1] ;# for Mozilla ActiveX Control .htm config -width 800 -height 600 pack .htm -fill both -expand 1 $htm navigate www.scriptics.com # to view the type information for the control pack [button .b -text "View TypeLibrary for IE container" -command { tlview::viewtype [ optcl::class $htm ] } ] -side bottom
Here is the code to do it without the IE's scroll bar. Notice the difference???
package require optcl wm title . {MSIE in Tk without scroll} set htm [optcl::new -window .htm {http://www.scriptics.com}] .htm config -width 800 -height 600 pack .htm -fill both -expand 1 # to view the type information for the control pack [button .b -text "View TypeLibrary for IE container" -command { tlview::viewtype [ optcl::class $htm ] } ] -side bottom
MPJ A little bigger example is how to play a VCD with Microsoft's MediaPlayer using optcl.
package require optcl wm title . {VCD Document in Tk} set vcd [optcl::new -start -window .vcd MediaPlayer.MediaPlayer.1] .vcd config -width 640 -height 480 pack .vcd -fill both -expand 1 # put location of VCD file here ... need to make much smarter $vcd : filename "E:/mpegav/music01.dat" $vcd Play # view the loaded activex component ## tlview::loadedlibs .tmp2 #how long the file is ## clock format [expr int([clock scan 0]+ [$vcd : duration])] -format %T # current position in time ## clock format [expr int([clock scan 0]+ [$vcd : CurrentPosition])] -format %T
MPJ Display of the Wiki in a Tk frame is yet another example Michael provides:
package require optcl optcl::new -window .htm {http://wiki.tcl.tk} .htm config -width 800 -height 600 pack .htm
MPJ Display the Calendar control being integrated within a Tk widget. Also see the examples files that come with OpTcl to bind events.
package require optcl optcl::new -window .cal MSCAL.Calendar.7 .cal config -width 300 -height 300 pack .cal
See also COM on! - a tiny web browser & WippleWobble - A Mini Web Browser (for Windows)
etdxc I put together some of the commands from other peoples postings (sorry for the duplication) and a bunch of stuff I managed to work out by using the Type Library utility.
Hope it helps someone.
*****************************************************************************
ALL
package require optcl
to view the type information for the control
pack [button .b -text "View TypeLibrary for IE container" -command { tlview::viewtype [ optcl::class $htm ] } ] -side bottom
view the loaded libraries
tlview::loadedlibs .tmp2
view the type hierarchy
tlview::viewtype [optcl::class $doc] tlview::viewtype [optcl::class $htm] tlview::viewtype [optcl::class $cal] tlview::viewtype [optcl::class $vcd]
*****************************************************************************
Word Start word
set word [optcl::new word.application]
New Document
set doc [$word -with documents add]
Opens a document
set doc [$word -with documents open $filename]
Make Word visible
$word : visible 1
Make Word invisible
$word : visible 0
Insert text with formatting
$word -with selection.font : name "Courier New" $word -with selection.font : size 10.0 $doc -with content : text "Text in Courier 10 point \r" ;# \r Return ???
Change colour of selected text
$word -with selection : start 0 $word -with selection : end 5 $word -with selection.font : color wdcolorblue $word -with selection.font : bold 1 $word -with selection : end 50000 ;# Move to end of doc set end [$word -with selection : end] ;# Get the size of the doc $word -with selection : start $end ;# Move to end of doc $word -with selection.font : name "Courier New" $word -with selection.font : size 10.0 $word -with selection.range : text "Text is 14 point Courier" $doc select ;# Select the text start to end I think
Exit Word
$word quit
Minmise, Maximise, Restore
$word : Windowstate wdWindowStateMaximize $word : Windowstate wdWindowStateMinimize $word : Windowstate wdWindowStateNormal
Page Setup
set pSetUp [$doc PageSetup] $pSetUp : LeftMargin 1.0 ;# sets left margin
Printing
$doc PrintOut ;# Prints strainght away''
Print Preview
$word : PrintPreview 1
Print Options
set pOtions [$word : options] ;# print options $p : PrintProperties 1 $p : PrintBackground 1 $p : PrintDraft 1
dialogs
set d [$word : Dialogs] set dia [$d Item wdDialogFilePrintSetup] $dia Execute $dia Show
Display the document in powerpoint
$doc PresentIt
Embed/Display word in IE
$doc WebPagePreview
Turn on form design toolbar
$doc ToggleFormsDesign
Email document
$doc SendMail # $doc SendMailer FileFormat Priority ;# not implemented error
Fax document
# $doc SendFax Address Subject ;# Needs Microsoft Lacal Fax
Letter Wizard
# $doc RunLetterWizard ;# untested
Repaginate the document
# $doc Repaginate ;# untested
Remove the documents theme
# $doc RemoveTheme ;# untested
Remove Numbers >?????
# $doc RemoveNumbers ;# untested
Reload as
# $doc ReloadAs Office.MsoEncoding ;# untested
Reload
# $doc Reload ;# untested
''Send to exchange folder'
$doc Post
Merge
# $doc Merge filename ;# untested
Data Form ?? Header Record Delimiters
$doc DataForm
Check Spelling
$doc CheckSpelling
Check Grammar
$doc CheckGrammar
Summarise
$doc AutoSummarize
Activate
$word Activate
Change the open file path
$word ChangeFileOpenDirectory "C:/"
?????
# $word CheckGrammar string ;# untested # $word CheckSpelling lots of args # $word CleanString string string # $word DDE''cmds''
Activate the helptool (?)
$word HelpTool
Get the CLSID code
$word ProductCode
Resize window
$word Resize $x $y ;# state needs to be normal or maximised
Fax
$word SendFax ;# runs registered fax software
Set Default theme
# $word SetDefaultTheme args ;# untested
'' ShowMe ?????'
$word ShowMe ;# Didn't seem to do anything
Run Word macro with parm
$word run header "arg" "arg" "arg" $word run footer "arg"
SaveAs
$doc saveas "filename" 6 # where 6 = format # 0 (zero) Word document # 1 Document template # 2 Text only # 3 Text only with line breaks # 4 MS-DOS text # 5 MS-DOS text with line breaks # 6 Rich Text Format (RTF)
*****************************************************************************
IE
for MSIE ActiveX Control
set htm [optcl::new -window .htm Shell.Explorer.2] .htm config -width 800 -height 600 pack .htm
for Mozilla ActiveX Control
set htm [optcl::new -window .htm Mozilla.Browser.1] .htm config -width 800 -height 600 pack .htm
Open a web page with scroll bars
$htm navigate www.scriptics.com
Without the IE's scroll bar.
set htm [optcl::new -window .htm {http://www.scriptics.com}]
Get the URL of current webpage using IE
set current_site [$htm : LocationURL]
*****************************************************************************
Play a VCD with Microsoft's MediaPlayer
set vcd [optcl::new -start -window .vcd MediaPlayer.MediaPlayer.1] .vcd config -width 640 -height 480 pack .vcd -fill both -expand 1
put location of VCD file here ... need to make much smarter
$vcd : filename "E:/mpegav/music01.dat" $vcd Play
how long the file is
clock format [expr int([clock scan 0]+ [$vcd : duration])] -format %T
current position in time
clock format [expr int([clock scan 0]+ [$vcd : CurrentPosition])] -format %T
***************************************************************************** Calendar Control
optcl::new -window .cal MSCAL.Calendar.7 .cal config -width 300 -height 300 pack .cal