2003-07-31 16:52:40 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
# widget --
|
|
|
|
# This script demonstrates the various widgets provided by Tk,
|
|
|
|
# along with many of the features of the Tk toolkit. This file
|
|
|
|
# only contains code to generate the main window for the
|
|
|
|
# application, which invokes individual demonstrations. The
|
|
|
|
# code for the actual demonstrations is contained in separate
|
|
|
|
# ".rb" files is this directory, which are sourced by this script
|
|
|
|
# as needed.
|
|
|
|
|
|
|
|
require 'tk'
|
2004-05-01 12:09:54 -04:00
|
|
|
# require 'tkafter'
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
### $DEBUG=1 ##########
|
|
|
|
|
|
|
|
#----------------------------------------------------------------
|
|
|
|
# The code below create the main window, consisting of a menu bar
|
|
|
|
# and a text widget that explains how to use the program, plus lists
|
|
|
|
# all of the demos as hypertext items.
|
|
|
|
#----------------------------------------------------------------
|
|
|
|
|
|
|
|
# widget demo directory
|
|
|
|
$demo_dir = File.dirname($0)
|
|
|
|
|
|
|
|
# root
|
|
|
|
$root = TkRoot.new{title "Ruby/Tk Widget Demonstration"}
|
|
|
|
|
|
|
|
# tk
|
|
|
|
$tk_version = Tk::TK_VERSION
|
2004-05-01 12:09:54 -04:00
|
|
|
$tk_major_ver, $tk_minor_ver = $tk_version.split('.').map{|n| n.to_i}
|
|
|
|
$tk_patchlevel = Tk::TK_PATCHLEVEL
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
# tcl_platform
|
|
|
|
$tk_platform = TkVarAccess.new('tcl_platform')
|
|
|
|
|
|
|
|
#
|
2004-05-01 12:09:54 -04:00
|
|
|
case($tk_version)
|
|
|
|
when /^4.*/
|
|
|
|
$font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil)
|
|
|
|
else
|
|
|
|
$font = TkFont.new('Helvetica -12')
|
|
|
|
end
|
|
|
|
|
|
|
|
# images
|
|
|
|
$image = {}
|
|
|
|
|
|
|
|
if $tk_major_ver >= 8
|
|
|
|
$image['refresh'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
|
|
|
|
R0lGODlhEAAQAPMAAMz/zCpnKdb/1z9mPypbKBtLGy9NMPL/9Or+6+P+4j1Y
|
|
|
|
PwQKBP7//xMLFAYBCAEBASH5BAEAAAAALAAAAAAQABAAAwR0EAD3Gn0Vyw0e
|
|
|
|
++CncU7IIAezMA/nhUqSLJizvSdCEEjy2ZIV46AwDAoDHwPYGSoEiUJAAGJ6
|
|
|
|
EDHBNCFINW5OqABKSFk/B9lUa94IDwIFgewFMwQDQwCZQCztTgM9Sl8SOEMG
|
|
|
|
KSAthiaOjBMPDhQONBiXABEAOw==
|
|
|
|
EOD
|
|
|
|
end
|
|
|
|
|
|
|
|
if $tk_major_ver >= 8
|
|
|
|
$image['view'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
|
|
|
|
R0lGODlhEAAQAPMAAMz/zP///8DAwICAgH9/fwAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAwRIcMhJB7h3hM33
|
|
|
|
KFjWdQQYap1QrCaGBmrRrS4nj5b53jOgbwXBKGACoYLDIuAoHCmZyYvR1rT5
|
|
|
|
RMAq8LqcIYGsrjPsW1XOmFUEADs=
|
|
|
|
EOD
|
|
|
|
end
|
|
|
|
|
|
|
|
if $tk_major_ver >= 8
|
|
|
|
$image['delete'] = TkPhotoImage.new(:height=>16, :format=>'GIF', :data=><<EOD)
|
|
|
|
R0lGODlhEAAOAKEAAIQAAO/n3v///////yH5BAEKAAIALAAAAAAQAA4AAAIm
|
|
|
|
lI9pAKHbIHNoVhYhTdjlJ2AWKG2g+CldmB6rxo2uybYhbS80eRQAOw==
|
|
|
|
EOD
|
|
|
|
end
|
|
|
|
|
|
|
|
if $tk_major_ver >= 8
|
2004-12-02 11:59:02 -05:00
|
|
|
$image['print'] = TkPhotoImage.new(:height=>19, :format=>'GIF', :data=><<EOD)
|
2004-05-01 12:09:54 -04:00
|
|
|
R0lGODlhGgATAPcAACEQOTEpQjEpUkIpc0IxY0I5c0oxjEo5SlJCY1JCe1JK
|
|
|
|
UlpChFpCjFpGkFpSc1paa2NKc2NKnGNja2tapWtjc29KnHNanHNjc3NjrXNr
|
|
|
|
jHNrnHNzc3tjpXtrtXtzhICAgIRzvYSEjIZzqox7tYyEnIyMjJSEtZSEvZSM
|
|
|
|
lJyMtZyMvZyUlJyUrZyUvZycnKWctaWlpa2czq2lzrWtvbWtzrW1tb21xr21
|
|
|
|
1sa9zs693s7OztbO3tbO597W1t7W7+fe7+fn5////+/n7+/v7+/v9////wAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
|
AAAAAAAAAAAAAAAAAAAAACH5BAEAAEEALAAAAAAaABMAQAj/AIMIHBhkg0GC
|
|
|
|
CBMGIQEiQgseQT4oeCBBAokgRYYQ0JBixg8hRIiUUEBBYYmTByBwiCBCRYwH
|
|
|
|
CxY8cKFw4AogRXLqLAJkQ80gCBBg3BkxZswTNGh4MGqgQQUMJRHCwMkTSE+D
|
|
|
|
Pn8eCKBhxIMhO3ei2OHDBw6sWSlMMMoWgwwfMDZI8GBjx44NARZwEGGi5MkS
|
|
|
|
PcIWKRGz5YgLbAco+KkQBQoJIRgjdGEVq+SaJajqtNrzMgsPCmoIzqmDgmWE
|
|
|
|
KOBuUKAAwYabYTfs4OHjY0giGyhk4MAWRI4eKyRQqPgggYUXPH4A+XBAgwoK
|
|
|
|
DiIsCFxjA9sFEVQQCRJCAYAFDJxiKhAxvMTonEFimrhhYinTBgWiCvxLNX3M
|
|
|
|
DkkpsKV5OYhjBxCMYAICAigUEAA7
|
|
|
|
EOD
|
|
|
|
end
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
TkMenubar.new($root,
|
2004-10-11 00:51:21 -04:00
|
|
|
[[['File', 0],
|
|
|
|
['About ... ', proc{aboutBox}, 0, '<F1>'],
|
|
|
|
'---',
|
|
|
|
['Quit', proc{exit}, 0, 'Meta-Q']
|
|
|
|
]]).pack('side'=>'top', 'fill'=>'x')
|
2003-07-31 16:52:40 -04:00
|
|
|
$root.bind('F1', proc{aboutBox})
|
2004-05-01 12:09:54 -04:00
|
|
|
$root.bind('Meta-q', proc{exit})
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
=begin
|
|
|
|
TkFrame.new($root){|frame|
|
|
|
|
TkMenubutton.new(frame){|button|
|
|
|
|
m = TkMenu.new(button) {
|
|
|
|
add 'command', 'label'=>'Quit', 'command'=>proc{exit}, 'underline'=>0
|
|
|
|
}
|
|
|
|
menu m
|
|
|
|
text 'File'
|
|
|
|
underline 0
|
|
|
|
}.pack('side'=>'left')
|
|
|
|
}.pack('side'=>'top', 'fill'=>'x')
|
|
|
|
=end
|
|
|
|
|
|
|
|
#
|
|
|
|
if $tk_version =~ /^4\.[01]/
|
|
|
|
scr = TkScrollbar.new($root, 'orient'=>'vertical')
|
|
|
|
txt = TkText.new($root) {
|
|
|
|
wrap 'word'
|
2004-05-01 12:09:54 -04:00
|
|
|
width 70
|
2003-07-31 16:52:40 -04:00
|
|
|
height 30
|
|
|
|
font $font
|
|
|
|
setgrid 'yes'
|
|
|
|
yscrollcommand proc{|first,last| scr.set first,last}
|
|
|
|
}
|
|
|
|
scr.command(proc{|*args| txt.yview(*args)})
|
|
|
|
scr.pack('side'=>'right', 'fill'=>'y')
|
|
|
|
txt.pack('expand'=>'yes', 'fill'=>'both')
|
|
|
|
else
|
|
|
|
textFrame = TkFrame.new($root)
|
|
|
|
scr = TkScrollbar.new($root, 'orient'=>'vertical',
|
2004-10-11 00:51:21 -04:00
|
|
|
'highlightthickness'=>0, 'takefocus'=>1) {
|
2003-07-31 16:52:40 -04:00
|
|
|
pack('in'=>textFrame, 'side'=>'right', 'fill'=>'y', 'padx'=>1)
|
|
|
|
}
|
|
|
|
txt = TkText.new($root) {
|
|
|
|
wrap 'word'
|
2004-05-01 12:09:54 -04:00
|
|
|
width 70
|
2003-07-31 16:52:40 -04:00
|
|
|
height 30
|
|
|
|
font $font
|
|
|
|
setgrid 'yes'
|
|
|
|
highlightthickness 0
|
|
|
|
padx 4
|
|
|
|
pady 2
|
|
|
|
takefocus 0
|
2004-05-01 12:09:54 -04:00
|
|
|
bd 1
|
2003-07-31 16:52:40 -04:00
|
|
|
yscrollcommand proc{|first,last| scr.set first,last}
|
|
|
|
}
|
|
|
|
scr.command(proc{|*args| txt.yview(*args)})
|
|
|
|
# txt.pack('in'=>textFrame, 'expand'=>'yes', 'fill'=>'both', 'padx'=>1)
|
|
|
|
txt.pack('in'=>textFrame, 'expand'=>'yes', 'fill'=>'both')
|
|
|
|
# textFrame.pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>2)
|
|
|
|
textFrame.pack('expand'=>'yes', 'fill'=>'both')
|
|
|
|
|
|
|
|
statusBar = TkFrame.new($root) {|f|
|
|
|
|
$statusBarLabel = \
|
|
|
|
TkLabel.new(f, 'text'=>" ", 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
|
2004-10-11 00:51:21 -04:00
|
|
|
'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
|
|
|
|
.pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both')
|
2003-07-31 16:52:40 -04:00
|
|
|
TkLabel.new(f, 'width'=>8, 'relief'=>'sunken', 'bd'=>1, 'anchor'=>'w',
|
2004-10-11 00:51:21 -04:00
|
|
|
'font'=>'-*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') \
|
|
|
|
.pack('side'=>'left', 'padx'=>2)
|
2003-07-31 16:52:40 -04:00
|
|
|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create a bunch of tags to use in the text widget, such as those for
|
|
|
|
# section titles and demo descriptions. Also define the bindings for
|
|
|
|
# tags.
|
|
|
|
|
|
|
|
tag_title = TkTextTag.new(txt, 'font'=>'-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*')
|
|
|
|
|
|
|
|
# We put some "space" characters to the left and right of each demo description
|
|
|
|
# so that the descriptions are highlighted only when the mouse cursor
|
|
|
|
# is right over them (but not when the cursor is to their left or right)
|
|
|
|
|
|
|
|
tag_demospace = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c')
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
if TkWinfo.depth($root) == 1
|
2003-07-31 16:52:40 -04:00
|
|
|
tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
|
2004-10-11 00:51:21 -04:00
|
|
|
'underline'=>1)
|
2003-07-31 16:52:40 -04:00
|
|
|
$tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
|
2004-10-11 00:51:21 -04:00
|
|
|
'underline'=>1)
|
2003-07-31 16:52:40 -04:00
|
|
|
tag_hot = TkTextTag.new(txt, 'background'=>'black', 'foreground'=>'white')
|
|
|
|
else
|
|
|
|
tag_demo = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
|
2004-10-11 00:51:21 -04:00
|
|
|
'foreground'=>'blue', 'underline'=>1)
|
2003-07-31 16:52:40 -04:00
|
|
|
$tag_visited = TkTextTag.new(txt, 'lmargin1'=>'1c', 'lmargin2'=>'1c',
|
2004-10-11 00:51:21 -04:00
|
|
|
'foreground'=>'#303080', 'underline'=>1)
|
2003-07-31 16:52:40 -04:00
|
|
|
# tag_hot = TkTextTag.new(txt, 'relief'=>'raised', 'borderwidth'=>1,
|
2004-10-11 00:51:21 -04:00
|
|
|
# 'background'=>'SeaGreen3')
|
2003-07-31 16:52:40 -04:00
|
|
|
tag_hot = TkTextTag.new(txt, 'borderwidth'=>1, 'foreground'=>'red')
|
|
|
|
end
|
|
|
|
|
|
|
|
#tag_demo.bind('Button-1', proc{invoke txt, txt.index('current')})
|
|
|
|
tag_demo.bind('ButtonRelease-1',
|
2004-10-11 00:51:21 -04:00
|
|
|
proc{|x,y|invoke txt, txt.index("@#{x},#{y}")}, '%x %y')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
lastLine = TkVariable.new("")
|
|
|
|
newLine = TkVariable.new("")
|
|
|
|
tag_demo.bind('Enter', proc{|x,y|
|
2004-10-11 00:51:21 -04:00
|
|
|
lastLine.value = txt.index("@#{x},#{y} linestart")
|
|
|
|
tag_hot.add(lastLine.value, "#{lastLine.value} lineend")
|
|
|
|
showStatus txt, txt.index("@#{x},#{y}")
|
|
|
|
},
|
|
|
|
'%x %y')
|
2003-07-31 16:52:40 -04:00
|
|
|
tag_demo.bind('Leave',
|
2004-10-11 00:51:21 -04:00
|
|
|
proc{
|
|
|
|
tag_hot.remove('1.0','end')
|
|
|
|
txt.configure('cursor','xterm')
|
|
|
|
$statusBarLabel.configure('text'=>"")
|
|
|
|
})
|
2003-07-31 16:52:40 -04:00
|
|
|
tag_demo.bind('Motion', proc{|x, y|
|
2004-10-11 00:51:21 -04:00
|
|
|
newLine.value = txt.index("@#{x},#{y} linestart")
|
|
|
|
if newLine.value != lastLine.value
|
|
|
|
tag_hot.remove('1.0','end')
|
|
|
|
lastLine.value = newLine.value
|
|
|
|
if ( txt.tag_names("@#{x},#{y}").find{|t|
|
|
|
|
t.kind_of?(String) && t =~ /^demo-/
|
|
|
|
} )
|
|
|
|
tag_hot.add(lastLine.value,
|
|
|
|
"#{lastLine.value} lineend -1 chars")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
showStatus txt, txt.index("@#{x},#{y}")
|
|
|
|
},
|
|
|
|
'%x %y')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
# Create the text for the text widget.
|
|
|
|
|
|
|
|
txt.insert('end', "Ruby/Tk Widget Demonstrations\n\n", tag_title)
|
|
|
|
txt.insert('end', <<EOT)
|
|
|
|
This application provides a front end for several short scripts that \
|
|
|
|
demonstrate what you can do with Tk widgets. Each of the numbered \
|
|
|
|
lines below describes a demonstration; you can click on it to invoke \
|
|
|
|
the demonstration. Once the demonstration window appears, you can \
|
|
|
|
click the "See Code" button to see the Ruby/Tk code that created the \
|
|
|
|
demonstration. If you wish, you can edit the code and click the \
|
|
|
|
"Rerun Demo" button in the code window to reinvoke the demonstration \
|
|
|
|
with the modified code.
|
|
|
|
|
2003-08-03 05:18:22 -04:00
|
|
|
Some demo scripts require the recent version of Tk library \
|
|
|
|
(e.g. Tk8.4 or later) \
|
|
|
|
If your Tk library linked to Ruby doesn't support the functions \
|
|
|
|
required by the demo script, the demo doesn't work. \
|
|
|
|
In such a case, please re-compile tcltklib with the later Tk library \
|
|
|
|
which supports the required functions.
|
|
|
|
|
|
|
|
|
2003-07-31 16:52:40 -04:00
|
|
|
EOT
|
|
|
|
|
|
|
|
txt.insert('end', "Labels, buttons, checkbuttons, and radiobuttons.\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. Labels (text and bitmaps).\n", tag_demo, "demo-label")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2003-10-16 03:45:51 -04:00
|
|
|
txt.insert('end', "2. Labels and UNICODE text. (if supported)\n", tag_demo, "demo-unicodeout")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2003-10-16 03:45:51 -04:00
|
|
|
txt.insert('end', "3. Buttons.\n", tag_demo, "demo-button")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2003-10-16 03:45:51 -04:00
|
|
|
txt.insert('end', "4. Checkbuttons (select any of a group).\n", tag_demo, "demo-check")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "5. Checkbuttons (if supported).\n", tag_demo, "demo-check2")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "6. Radiobuttons (select one of a group).\n", tag_demo, "demo-radio")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "7. Radiobuttons (if supported 'compound' option).\n", tag_demo, "demo-radio2")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "8. Radiobuttons (if supported).\n", tag_demo, "demo-radio3")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "9. A 15-puzzle game made out of buttons.\n", tag_demo, "demo-puzzle")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "10. Iconic buttons that use bitmaps.\n", tag_demo, "demo-icon")
|
2003-08-02 17:39:23 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "11. Two labels displaying images.\n", tag_demo, "demo-image1")
|
2003-08-03 04:17:41 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "12. A simple user interface for viewing images.\n", tag_demo, "demo-image2")
|
2003-10-16 03:45:51 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "13. A simple user interface for viewing images. (if supported)\n", tag_demo, "demo-image3")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "14. Labelled frames (if supported)\n", tag_demo, "demo-labelframe")
|
2003-08-02 05:58:13 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Listboxes\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. 50 states.\n", tag_demo, "demo-states")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. Colors: change the color scheme for the application.\n", "#{tag_demo.id} demo-colors")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "3. A collection of famous sayings.\n", tag_demo, "demo-sayings")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
|
|
|
txt.insert('end', "\n")
|
2003-08-02 05:58:13 -04:00
|
|
|
txt.insert('end', "Entries and Spin-boxes\n", tag_title)
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. Without scrollbars.\n", tag_demo, "demo-entry1")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. With scrollbars.\n", tag_demo, "demo-entry2")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2003-10-14 15:36:09 -04:00
|
|
|
txt.insert('end',
|
2004-10-11 00:51:21 -04:00
|
|
|
"3. Validated entries and password fields. (if supported)\n",
|
|
|
|
tag_demo, "demo-entry3")
|
2003-08-02 05:58:13 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2003-10-14 15:36:09 -04:00
|
|
|
txt.insert('end', "4. Spin-boxes. (if supported)\n", tag_demo, "demo-spin")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "5. Simple Rolodex-like form.\n", tag_demo, "demo-form")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Text\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. Basic editable text.\n", tag_demo, "demo-text")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. Text display styles.\n", tag_demo, "demo-style")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "3. Hypertext (tag bindings).\n", tag_demo, "demo-bind")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "4. A text widget with embedded windows.\n", tag_demo, "demo-twind")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "5. A text widget with embedded windows. (if supported)\n", tag_demo, "demo-twind2")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "6. A search tool built with a text widget.\n", tag_demo, "demo-search")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Canvases\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. The canvas item types.\n", tag_demo, "demo-items")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. A simple 2-D plot.\n", tag_demo, "demo-plot")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "3. Text items in canvases.\n", tag_demo, "demo-ctext")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "4. An editor for arrowheads on canvas lines.\n", tag_demo, "demo-arrow")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "5. A ruler with adjustable tab stops.\n", tag_demo, "demo-ruler")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "6. A building floor plan.\n", tag_demo, "demo-floor")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2004-05-01 12:09:54 -04:00
|
|
|
txt.insert('end', "7. A building floor plan. (another way to create canvas items)\n", tag_demo, "demo-floor2")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "8. A simple scrollable canvas.\n", tag_demo, "demo-cscroll")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Scales\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. Vertical scale.\n", tag_demo.id, "demo-vscale")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. Horizontal scale.\n", tag_demo.id, "demo-hscale")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
2003-08-02 05:58:13 -04:00
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Paned Windows\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. Horizontal paned window. (if supported)\n", tag_demo.id, "demo-paned1")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. Vertical paned window. (if supported)\n", tag_demo.id, "demo-paned2")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Menus\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. Menus and cascades.\n", tag_demo, "demo-menu")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
2003-08-02 17:39:23 -04:00
|
|
|
txt.insert('end', "2. Menus and cascades. (if supported)\n", tag_demo, "demo-menu84")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "3. Menubuttons\n", tag_demo, "demo-menubu")
|
2003-07-31 16:52:40 -04:00
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Common Dialogs\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. Message boxes.\n", tag_demo, "demo-msgbox")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. File selection dialog.\n", tag_demo, "demo-filebox")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "3. Color picker.\n", tag_demo, "demo-clrpick")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
|
|
|
txt.insert('end', "\n")
|
|
|
|
txt.insert('end', "Miscellaneous\n", tag_title)
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "1. The built-in bitmaps.\n", tag_demo, "demo-bitmap")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "2. A dialog box with a local grab.\n", tag_demo, "demo-dialog1")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
txt.insert('end', "3. A dialog box with a global grab.\n", tag_demo, "demo-dialog2")
|
|
|
|
txt.insert('end', " \n ", tag_demospace)
|
|
|
|
|
|
|
|
txt.state('disabled')
|
|
|
|
scr.focus
|
|
|
|
|
|
|
|
# positionWindow --
|
|
|
|
# This procedure is invoked by most of the demos to position a
|
|
|
|
# new demo window.
|
|
|
|
#
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
# w - The name of the window to position.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
def positionWindow(w)
|
|
|
|
w.geometry('+300+300')
|
|
|
|
end
|
|
|
|
|
|
|
|
# showVars --
|
|
|
|
# Displays the values of one or more variables in a window, and
|
|
|
|
# updates the display whenever any of the variables changes.
|
|
|
|
#
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
# w - Name of new window to create for display.
|
|
|
|
# args - Any number of names of variables.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
$showVarsWin = {}
|
2004-05-01 12:09:54 -04:00
|
|
|
def showVars1(parent, *args)
|
2003-07-31 16:52:40 -04:00
|
|
|
if $showVarsWin[parent.path]
|
|
|
|
begin
|
|
|
|
$showVarsWin[parent.path].destroy
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
w = TkToplevel.new(parent) {|w|
|
|
|
|
title "Variable values"
|
|
|
|
TkLabel.new(w) {
|
|
|
|
text "Variable values:"
|
|
|
|
width 20
|
|
|
|
anchor 'center'
|
|
|
|
font '-Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*'
|
|
|
|
}.pack('side'=>'top', 'fill'=>'x')
|
|
|
|
len = 1
|
|
|
|
args.each{|vnam,vbody|
|
|
|
|
len = vnam.to_s.length if vnam.to_s.length > len
|
|
|
|
}
|
|
|
|
args.each{|vnam,vbody|
|
|
|
|
TkFrame.new(w){|f|
|
2004-10-11 00:51:21 -04:00
|
|
|
#TkLabel.new(f, 'text'=>"#{vnam}: ").pack('side'=>'left')
|
|
|
|
TkLabel.new(f, 'text'=>"#{vnam}: ",'width'=>len+2).pack('side'=>'left')
|
|
|
|
TkLabel.new(f, 'textvariable'=>vbody, 'anchor'=>'w')\
|
|
|
|
.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
|
2003-07-31 16:52:40 -04:00
|
|
|
}.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x')
|
|
|
|
}
|
|
|
|
TkButton.new(w) {
|
|
|
|
text "OK"
|
|
|
|
command proc{w.destroy}
|
|
|
|
}.pack('side'=>'bottom', 'pady'=>2)
|
|
|
|
}
|
|
|
|
$showVarsWin[parent.path] = w
|
|
|
|
end
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def showVars2(parent, *args)
|
|
|
|
if $showVarsWin[parent.path]
|
|
|
|
begin
|
|
|
|
$showVarsWin[parent.path].destroy
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$showVarsWin[parent.path] = TkToplevel.new(parent) {|w|
|
|
|
|
title "Variable values"
|
|
|
|
|
|
|
|
TkLabelFrame.new(w, :text=>"Variable values:",
|
2004-10-11 00:51:21 -04:00
|
|
|
:font=>{:family=>'Helvetica', :size=>14}){|f|
|
2004-05-01 12:09:54 -04:00
|
|
|
args.each{|vnam,vbody|
|
2004-10-11 00:51:21 -04:00
|
|
|
TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'),
|
|
|
|
TkLabel.new(f, :textvariable=>vbody, :anchor=>'w'),
|
|
|
|
:padx=>2, :pady=>2, :sticky=>'w')
|
2004-05-01 12:09:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
f.grid(:sticky=>'news', :padx=>4)
|
|
|
|
f.grid_columnconfig(1, :weight=>1)
|
|
|
|
f.grid_rowconfig(100, :weight=>1)
|
|
|
|
}
|
|
|
|
TkButton.new(w, :text=>"OK", :width=>8, :default=>:active,
|
2004-10-11 00:51:21 -04:00
|
|
|
:command=>proc{w.destroy}){|b|
|
2004-05-01 12:09:54 -04:00
|
|
|
w.bind('Return', proc{b.invoke})
|
|
|
|
w.bind('Escape', proc{b.invoke})
|
|
|
|
|
|
|
|
b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4])
|
|
|
|
}
|
|
|
|
w.grid_columnconfig(0, :weight=>1)
|
|
|
|
w.grid_rowconfig(0, :weight=>1)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if $tk_major_ver < 8
|
|
|
|
alias showVars showVars1
|
2004-12-16 02:32:01 -05:00
|
|
|
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
|
2004-05-01 12:09:54 -04:00
|
|
|
alias showVars showVars1
|
2004-12-16 02:32:01 -05:00
|
|
|
else # ver >= 8.4
|
2004-05-01 12:09:54 -04:00
|
|
|
alias showVars showVars2
|
|
|
|
end
|
|
|
|
|
2003-07-31 16:52:40 -04:00
|
|
|
# invoke --
|
|
|
|
# This procedure is called when the user clicks on a demo description.
|
|
|
|
# It is responsible for invoking the demonstration.
|
|
|
|
#
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
# txt - Name of text widget
|
|
|
|
# index - The index of the character that the user clicked on.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
def invoke (txt, index)
|
|
|
|
tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
|
|
|
|
return unless tag
|
|
|
|
cursor = txt.cget('cursor')
|
|
|
|
txt.cursor('watch')
|
|
|
|
Tk.update
|
|
|
|
# eval `cat #{tag[5..-1]}.rb`
|
2004-05-01 12:09:54 -04:00
|
|
|
# eval `cat #{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb`
|
|
|
|
eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
|
2003-07-31 16:52:40 -04:00
|
|
|
Tk.update
|
|
|
|
# txt.cursor('xterm')
|
|
|
|
txt.cursor(cursor)
|
|
|
|
|
|
|
|
$tag_visited.add("#{index} linestart +1 chars", "#{index} lineend +1 chars")
|
|
|
|
end
|
|
|
|
|
|
|
|
# showStatus --
|
|
|
|
#
|
2004-10-11 00:51:21 -04:00
|
|
|
# Show the name of the demo program in the status bar. This procedure
|
|
|
|
# is called when the user moves the cursor over a demo description.
|
2003-07-31 16:52:40 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
def showStatus (txt, index)
|
|
|
|
tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
|
|
|
|
cursor = txt.cget('cursor')
|
|
|
|
unless tag
|
|
|
|
$statusBarLabel.configure('text', " ")
|
|
|
|
newcursor = 'xterm'
|
|
|
|
else
|
|
|
|
demoname = tag[5..-1]
|
|
|
|
$statusBarLabel.configure('text',
|
2004-10-11 00:51:21 -04:00
|
|
|
"Run the \"#{demoname}\" sample program")
|
2003-07-31 16:52:40 -04:00
|
|
|
newcursor = 'hand2'
|
|
|
|
end
|
|
|
|
txt.configure('cursor'=>newcursor) if cursor != newcursor
|
|
|
|
end
|
|
|
|
|
|
|
|
# showCode --
|
|
|
|
# This procedure creates a toplevel window that displays the code for
|
|
|
|
# a demonstration and allows it to be edited and reinvoked.
|
|
|
|
#
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
# demo - The name of the demonstration's window, which can be
|
|
|
|
# used to derive the name of the file containing its code.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def showCode1(demo)
|
2003-07-31 16:52:40 -04:00
|
|
|
file = "#{demo}.rb"
|
|
|
|
$code_window = nil unless defined? $code_window
|
2004-05-01 12:09:54 -04:00
|
|
|
if $code_window == nil || TkWinfo.exist?($code_window) == false
|
2003-07-31 16:52:40 -04:00
|
|
|
$code_window = TkToplevel.new(nil)
|
|
|
|
f = TkFrame.new($code_window)
|
|
|
|
TkButton.new(f) {
|
|
|
|
text "Dismiss"
|
|
|
|
command proc{
|
2004-10-11 00:51:21 -04:00
|
|
|
$code_window.destroy
|
|
|
|
$code_window = nil
|
2003-07-31 16:52:40 -04:00
|
|
|
}
|
|
|
|
}.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
|
|
|
|
TkButton.new(f) {
|
|
|
|
text "Rerun Demo"
|
|
|
|
command proc{eval($code_text.get('1.0','end'))}
|
|
|
|
}.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2)
|
|
|
|
# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x')
|
|
|
|
f.pack('side'=>'bottom', 'fill'=>'x')
|
|
|
|
|
|
|
|
if $tk_version =~ /^4\.[01]/
|
|
|
|
s = TkScrollbar.new($code_window, 'orient'=>'vertical')
|
|
|
|
$code_text = TkText.new($code_window) {
|
2004-10-11 00:51:21 -04:00
|
|
|
height 40
|
|
|
|
setgrid 'yes'
|
|
|
|
yscrollcommand proc{|first,last| s.set first,last}
|
2003-07-31 16:52:40 -04:00
|
|
|
}
|
|
|
|
s.command(proc{|*args| $code_text.yview(*args)})
|
|
|
|
s.pack('side'=>'right', 'fill'=>'y')
|
|
|
|
$code_text.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'both')
|
|
|
|
else
|
|
|
|
TkFrame.new($code_window) {|f|
|
2004-10-11 00:51:21 -04:00
|
|
|
pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)
|
|
|
|
|
|
|
|
hs = TkScrollbar.new($code_window, 'highlightthickness'=>0,
|
|
|
|
'orient'=>'horizontal')
|
|
|
|
vs = TkScrollbar.new($code_window, 'highlightthickness'=>0,
|
|
|
|
'orient'=>'vertical')
|
|
|
|
$code_text = TkText.new($code_window) {|t|
|
|
|
|
height 40
|
|
|
|
wrap 'word'
|
|
|
|
xscrollcommand proc{|first,last| hs.set first,last}
|
|
|
|
yscrollcommand proc{|first,last| vs.set first,last}
|
|
|
|
setgrid 'yes'
|
|
|
|
highlightthickness 0
|
|
|
|
pady 2
|
|
|
|
padx 3
|
|
|
|
hs.command(proc{|*args| $code_text.xview(*args)})
|
|
|
|
vs.command(proc{|*args| $code_text.yview(*args)})
|
|
|
|
}
|
|
|
|
|
|
|
|
$code_text.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>0,
|
|
|
|
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
|
|
|
|
vs.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>1,
|
|
|
|
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
|
|
|
|
# xs.grid('in'=>f, 'padx'=>1, 'pady'=>1, 'row'=>1, 'column'=>0,
|
|
|
|
# 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
# JKC 2001-07-26: segfaults under 1.7.1 (2001-06-19) [i686-linux]
|
2004-10-11 00:51:21 -04:00
|
|
|
TkGrid.rowconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
|
|
|
|
TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0)
|
2003-07-31 16:52:40 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
$code_window.deiconify
|
|
|
|
$code_window.raise
|
|
|
|
end
|
|
|
|
$code_window.title("Demo code: #{file}")
|
|
|
|
$code_window.iconname(file)
|
|
|
|
# fid = open(file, 'r')
|
|
|
|
fid = open([$demo_dir, file].join(File::Separator), 'r')
|
|
|
|
$code_text.delete('1.0', 'end')
|
|
|
|
#$code_text.insert('1.0', `cat #{file}`)
|
|
|
|
$code_text.insert('1.0', fid.read)
|
|
|
|
#$code_mark = TkTextMark.new($code_text, '1.0')
|
|
|
|
#$code_text.set_insert('1.0')
|
|
|
|
TkTextMarkInsert.new($code_text,'1.0')
|
|
|
|
fid.close
|
|
|
|
end
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
def showCode2(demo)
|
|
|
|
file = "#{demo}.rb"
|
|
|
|
$code_window = nil unless defined? $code_window
|
|
|
|
if $code_window == nil || TkWinfo.exist?($code_window) == false
|
|
|
|
$code_window = TkToplevel.new(nil)
|
|
|
|
tf = TkFrame.new($code_window)
|
|
|
|
$code_text = TkText.new(tf, :font=>'Courier 10', :height=>30,
|
2004-10-11 00:51:21 -04:00
|
|
|
:wrap=>'word', :bd=>1, :setgrid=>true,
|
|
|
|
:highlightthickness=>0, :pady=>2, :padx=>3)
|
2004-05-01 12:09:54 -04:00
|
|
|
xscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
|
|
|
|
yscr = TkScrollbar.new(tf, :bd=>1){assign($code_text)}
|
|
|
|
TkGrid($code_text, yscr, :sticky=>'news')
|
|
|
|
#TkGrid(xscr)
|
|
|
|
tf.grid_rowconfigure(0, :weight=>1)
|
|
|
|
tf.grid_columnconfigure(0, :weight=>1)
|
|
|
|
|
|
|
|
bf = TkFrame.new($code_window)
|
|
|
|
|
|
|
|
b_dis = TkButton.new(bf, :text=>'Dismiss', :default=>:active,
|
2004-10-11 00:51:21 -04:00
|
|
|
:command=>proc{
|
|
|
|
$code_window.destroy
|
|
|
|
$code_window = nil
|
|
|
|
},
|
|
|
|
:image=>$image['delete'], :compound=>:left)
|
2004-05-01 12:09:54 -04:00
|
|
|
b_prn = TkButton.new(bf, :text=>'Print Code',
|
2004-10-11 00:51:21 -04:00
|
|
|
:command=>proc{printCode($code_text, file)},
|
|
|
|
:image=>$image['print'], :compound=>:left)
|
2004-05-01 12:09:54 -04:00
|
|
|
b_run = TkButton.new(bf, :text=>'Rerun Demo',
|
2004-10-11 00:51:21 -04:00
|
|
|
:command=>proc{eval($code_text.get('1.0','end'))},
|
|
|
|
:image=>$image['refresh'], :compound=>:left)
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4])
|
|
|
|
bf.grid_columnconfigure(0, :weight=>1)
|
|
|
|
|
|
|
|
TkGrid(tf, :sticky=>'news')
|
|
|
|
TkGrid(bf, :sticky=>'ew')
|
|
|
|
$code_window.grid_columnconfigure(0, :weight=>1)
|
|
|
|
$code_window.grid_rowconfigure(0, :weight=>1)
|
|
|
|
|
|
|
|
$code_window.bind('Return', proc{|win|
|
2004-10-11 00:51:21 -04:00
|
|
|
b_dis.invoke unless win.kind_of?(TkText)
|
|
|
|
}, '%W')
|
2004-05-01 12:09:54 -04:00
|
|
|
$code_window.bindinfo('Return').each{|cmd, arg|
|
|
|
|
$code_window.bind_append('Escape', cmd, arg)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$code_window.deiconify
|
|
|
|
$code_window.raise
|
|
|
|
end
|
|
|
|
|
|
|
|
$code_window.title("Demo code: #{file}")
|
|
|
|
$code_window.iconname(file)
|
|
|
|
fid = open([$demo_dir, file].join(File::Separator), 'r')
|
|
|
|
$code_text.delete('1.0', 'end')
|
|
|
|
$code_text.insert('1.0', fid.read)
|
|
|
|
TkTextMarkInsert.new($code_text,'1.0')
|
|
|
|
fid.close
|
|
|
|
end
|
|
|
|
|
|
|
|
if $tk_major_ver < 8
|
|
|
|
alias showCode showCode1
|
2004-12-16 02:32:01 -05:00
|
|
|
elsif $tk_major_ver == 8 && $tk_minor_ver < 4
|
2004-05-01 12:09:54 -04:00
|
|
|
alias showCode showCode1
|
2004-12-16 02:32:01 -05:00
|
|
|
else # ver >= 8.4
|
2004-05-01 12:09:54 -04:00
|
|
|
alias showCode showCode2
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# printCode --
|
|
|
|
# Prints the source code currently displayed in the See Code dialog.
|
|
|
|
# Much thanks to Arjen Markus for this.
|
|
|
|
#
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
# txt - Name of text widget containing code to print
|
|
|
|
# file - Name of the original file (implicitly for title)
|
2004-05-01 12:09:54 -04:00
|
|
|
|
|
|
|
def printCode(txt, file)
|
|
|
|
code = txt.get('1.0', 'end - 1c')
|
|
|
|
dir = '.'
|
|
|
|
dir = ENV['HOME'] if ENV['HOME']
|
|
|
|
dir = ENV['TMP'] if ENV['TMP']
|
|
|
|
dir = ENV['TEMP'] if ENV['TEMP']
|
|
|
|
|
|
|
|
fname = [dir, 'tkdemo-' + file].join(File::Separator)
|
|
|
|
open(fname, 'w'){|fid| fid.print(code)}
|
|
|
|
begin
|
|
|
|
case Tk::TCL_PLATFORM('platform')
|
|
|
|
when 'unix'
|
|
|
|
msg = `lp -c #{fname}`
|
|
|
|
unless $?.exitstatus == 0
|
2004-10-11 00:51:21 -04:00
|
|
|
Tk.messageBox(:title=>'Print spooling failure',
|
|
|
|
:message=>'Print spooling probably failed: ' + msg)
|
2004-05-01 12:09:54 -04:00
|
|
|
end
|
|
|
|
when 'windows'
|
|
|
|
begin
|
2004-10-11 00:51:21 -04:00
|
|
|
printTextWin32(fname)
|
2004-05-01 12:09:54 -04:00
|
|
|
rescue => e
|
2004-10-11 00:51:21 -04:00
|
|
|
Tk.messageBox(:title=>'Print spooling failure',
|
|
|
|
:message=>'Print spooling probably failed: ' +
|
|
|
|
e.message)
|
2004-05-01 12:09:54 -04:00
|
|
|
end
|
|
|
|
when 'macintosh'
|
|
|
|
Tk.messageBox(:title=>'Operation not Implemented',
|
2004-10-11 00:51:21 -04:00
|
|
|
:message=>'Oops, sorry: not implemented yet!')
|
2004-05-01 12:09:54 -04:00
|
|
|
else
|
|
|
|
Tk.messageBox(:title=>'Operation not Implemented',
|
2004-10-11 00:51:21 -04:00
|
|
|
:message=>'Wow! Unknown platform: ' +
|
|
|
|
Tk::TCL_PLATFORM('platform'))
|
2004-05-01 12:09:54 -04:00
|
|
|
end
|
|
|
|
ensure
|
|
|
|
File.delete(fname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# printTextWin32 --
|
|
|
|
# Print a file under Windows
|
|
|
|
#
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
# filename - Name of the file
|
2004-05-01 12:09:54 -04:00
|
|
|
#
|
|
|
|
def printTextWin32(fname)
|
|
|
|
require 'win32/registry'
|
|
|
|
begin
|
|
|
|
app = Win32::Registry::HKEY_CLASSES_ROOT['.txt']
|
|
|
|
pcmd = nil
|
|
|
|
Win32::Registry::HKEY_CLASSES_ROOT.open("#{app}\\shell\\print"){|reg|
|
|
|
|
pcmd = reg['command']
|
|
|
|
}
|
|
|
|
rescue
|
|
|
|
app = Tk.tk_call('auto_execok', 'notepad.exe')
|
|
|
|
pcmd = "#{app} /p %1"
|
|
|
|
end
|
|
|
|
|
|
|
|
pcmd.gsub!('%1', fname)
|
|
|
|
puts pcmd
|
|
|
|
cmd = Tk.tk_call('auto_execok', 'start') + ' /min ' + pcmd
|
|
|
|
|
|
|
|
msg = `#{cmd}`
|
|
|
|
unless $?.exitstatus == 0
|
|
|
|
fail RuntimeError, msg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-07-31 16:52:40 -04:00
|
|
|
# aboutBox
|
|
|
|
#
|
|
|
|
# Pops up a message box with an "about" message
|
|
|
|
#
|
|
|
|
def aboutBox
|
|
|
|
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
|
2004-12-02 11:59:02 -05:00
|
|
|
'message'=>"Ruby/Tk widget demonstration Ver.1.4.4-en\n\n" +
|
2004-05-01 12:09:54 -04:00
|
|
|
"based on demos of Tk8.1 -- 8.5 " +
|
2004-10-11 00:51:21 -04:00
|
|
|
"( Copyright:: " +
|
|
|
|
"(c) 1996-1997 Sun Microsystems, Inc. / " +
|
2004-05-01 12:09:54 -04:00
|
|
|
"(c) 1997-2000 Ajuba Solutions, Inc. / " +
|
2004-10-11 00:51:21 -04:00
|
|
|
"(c) 2001-2003 Donal K. Fellows )\n\n" +
|
2004-05-01 12:09:54 -04:00
|
|
|
"Your Ruby & Tk Version ::\n" +
|
|
|
|
"Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}")
|
2003-07-31 16:52:40 -04:00
|
|
|
end
|
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
#########################################
|
|
|
|
# start demos if given at command line
|
|
|
|
no_launcher = false
|
|
|
|
if ARGV[0] == '-n'
|
|
|
|
ARGV.shift
|
|
|
|
no_launcher = true if ARGV.size > 0
|
|
|
|
end
|
|
|
|
ARGV.each{|cmd|
|
|
|
|
if cmd =~ /(.*).rb/
|
|
|
|
cmd = $1
|
|
|
|
end
|
|
|
|
eval IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join
|
|
|
|
}
|
|
|
|
if no_launcher
|
|
|
|
$root.withdraw # hide root window
|
|
|
|
Thread.start{
|
|
|
|
loop do
|
|
|
|
count = 0
|
|
|
|
$root.winfo_children.each{|w|
|
2004-10-11 00:51:21 -04:00
|
|
|
count += 1 if w.kind_of?(TkToplevel)
|
2004-05-01 12:09:54 -04:00
|
|
|
}
|
|
|
|
$root.destroy if count == 0
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2003-07-31 16:52:40 -04:00
|
|
|
|
2004-05-01 12:09:54 -04:00
|
|
|
#########################################
|
|
|
|
# start eventloop
|
2003-07-31 16:52:40 -04:00
|
|
|
Tk.mainloop
|
|
|
|
|