* add or modify some widget demo scripts

* (bug fix) TkGrid failed to treat RELATIVE PLACEMENT


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2003-08-02 21:39:23 +00:00
Родитель 2c225e77e0
Коммит f820839f17
16 изменённых файлов: 1509 добавлений и 35 удалений

Просмотреть файл

@ -83,9 +83,11 @@ sample/demos-en/images/tcllogo.gif
sample/demos-en/images/teapot.ppm
sample/demos-en/items.rb
sample/demos-en/ixset
sample/demos-en/ixset2
sample/demos-en/label.rb
sample/demos-en/labelframe.rb
sample/demos-en/menu.rb
sample/demos-en/menu84.rb
sample/demos-en/menubu.rb
sample/demos-en/msgbox.rb
sample/demos-en/patch_1.1c1
@ -94,6 +96,7 @@ sample/demos-en/paned2.rb
sample/demos-en/plot.rb
sample/demos-en/puzzle.rb
sample/demos-en/radio.rb
sample/demos-en/radio2.rb
sample/demos-en/rmt
sample/demos-en/rolodex
sample/demos-en/rolodex-j
@ -156,10 +159,12 @@ sample/demos-jp/images/tcllogo.gif
sample/demos-jp/images/teapot.ppm
sample/demos-jp/items.rb
sample/demos-jp/ixset
sample/demos-jp/ixset2
sample/demos-jp/label.rb
sample/demos-jp/labelframe.rb
sample/demos-jp/menu.rb
sample/demos-jp/menu8x.rb
sample/demos-jp/menu84.rb
sample/demos-jp/menubu.rb
sample/demos-jp/msgbox.rb
sample/demos-jp/paned1.rb
@ -167,6 +172,7 @@ sample/demos-jp/paned2.rb
sample/demos-jp/plot.rb
sample/demos-jp/puzzle.rb
sample/demos-jp/radio.rb
sample/demos-jp/radio2.rb
sample/demos-jp/rmt
sample/demos-jp/rolodex
sample/demos-jp/rolodex-j

Просмотреть файл

@ -2729,9 +2729,15 @@ module TkGrid
if args[-1].kind_of?(Hash)
keys = args.pop
end
wins = [widget.epath]
wins = []
args.unshift(widget)
for i in args
wins.push i.epath
case i
when '-', 'x', '^' # RELATIVE PLACEMENT
wins.push(i)
else
wins.push(i.epath)
end
end
tk_call "grid", 'configure', *(wins+hash_kv(keys))
end

Просмотреть файл

@ -0,0 +1,367 @@
#!/usr/bin/env ruby
#
# ixset --
# A nice interface to "xset" to change X server settings
#
require 'tk'
class Xsettings
#
# Button actions
#
def quit
@root.destroy
end
def ok
writesettings
quit
end
def cancel
readsettings
dispsettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
# apply is just "writesettings"
def apply
writesettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
#
# Read current settings
#
def readsettings
xfd = open("|xset q", 'r')
xfd.readlines.each{|line|
fields = line.chomp.strip.split(/\s+/)
case fields[0]
when "auto"
if fields[1] == 'repeat:'
@kbdrep = fields[2]
@w_kbdrep.set(@kbdrep)
@kbdcli = fields[6]
end
when "bell"
@bellvol = fields[2]
@bellpit = fields[5]
@belldur = fields[8]
when "acceleration:"
@mouseacc = fields[1]
@mousethr = fields[3]
when "prefer"
if fields[2] == 'yes'
@screenbla = 'blank'
else
@screenbla = 'noblank'
end
@w_screenbla.set(@screenbla)
when "timeout:"
@screentim = fields[1]
@screencyc = fields[3]
end
}
xfd.close
end
#
# Write settings into the X server
#
def writesettings
@bellvol = @w_bellvol.get
@bellpit = @w_bellpit.get
@belldur = @w_belldur.get
@kbdrep = @w_kbdrep.get
if @kbdrep == 'on'
@kbdcli = @w_kbdcli.get
else
@kbdcli = 'off'
end
@mouseacc = @w_mouseacc.get
@mousethr = @w_mousethr.get
@screentim = @w_screentim.get
@screencyc = @w_screencyc.get
@screenbla = @w_screenbla.get
system("xset \
b #{@bellvol} #{@bellpit} #{@belldur} \
c #{@kbdcli} \
r #{@kbdrep} \
m #{@mouseacc} #{@mousethr} \
s #{@screentim} #{@screencyc} \
s #{@screenbla}")
end
#
# Sends all settings to the window
#
def dispsettings
@w_bellvol.set(@bellvol)
@w_bellpit.set(@bellpit)
@w_belldur.set(@belldur)
@w_kbdonoff.set(@w_kbdrep.get)
@w_kbdcli.set(@kbdcli)
@w_mouseacc.set(@mouseacc)
@w_mousethr.set(@mousethr)
@w_screenblank.set(@w_screenbla.get)
@w_screenpat.set(@w_screenbla.get)
@w_screentim.set(@screentim)
@w_screencyc.set(@screencyc)
end
#
# Create all windows, and pack them
#
class LabelEntry
def initialize(parent, text, length, range=[])
@frame = TkFrame.new(parent)
TkLabel.new(@frame, 'text'=>text).pack('side'=>'left')
if range.size > 0
@entry = TkSpinbox.new(@frame, 'width'=>length, 'relief'=>'sunken',
'from'=>range[0], 'to'=>range[1])
else
@entry = TkEntry.new(@frame, 'width'=>length, 'relief'=>'sunken')
end
@entry.pack('side'=>'right','expand'=>'y', 'fill'=>'x')
end
def epath
@frame
end
def pack(keys)
@frame.pack(keys)
end
def get
@entry.value
end
def set(value)
@entry.delete(0,'end')
@entry.insert(0, value)
end
end
def createwindows
win = self
#
# Buttons
#
btn_frame = TkFrame.new(@root)
buttons = [
@btn_OK = TkButton.new(btn_frame, 'command'=>proc{win.ok},
'default'=>'active', 'text'=>'Ok'),
@btn_APPLY = TkButton.new(btn_frame, 'command'=>proc{win.writesettings},
'default'=>'normal', 'text'=>'Apply',
'state'=>'disabled'),
@btn_CANCEL = TkButton.new(btn_frame, 'command'=>proc{win.cancel},
'default'=>'normal', 'text'=>'Cancel',
'state'=>'disabled'),
@btn_QUIT = TkButton.new(btn_frame, 'command'=>proc{win.quit},
'default'=>'normal', 'text'=>'Quit')
]
buttons.each{|b| b.pack('side'=>'left', 'expand'=>'yes', 'pady'=>5) }
@root.bind('Return', proc{@btn_OK.flash; @btn_OK.invoke})
@root.bind('Escape', proc{@btn_QUIT.flash; @btn_QUIT.invoke})
@root.bind('1', proc{|w|
unless buttons.index(w)
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
}, '%W')
@root.bind('Key', proc{|w, k|
unless buttons.index(w)
case k
when 'Return', 'Escape', 'Tab', /.*Shift.*/
# do nothing
else
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
end
}, '%W %K')
#
# Bell settings
#
bell = TkLabelframe.new(@root, 'text'=>'Bell Settings',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_bellvol = TkScale.new(bell, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>"Volume (%)")
f = TkFrame.new(bell)
@w_bellpit = LabelEntry.new(f, "Pitch (Hz)", 6, [25, 20000])
@w_bellpit.pack('side'=>'left', 'padx'=>5)
@w_belldur = LabelEntry.new(f, "Duration (ms)", 6, [1, 10000])
@w_belldur.pack('side'=>'right', 'padx'=>5)
@w_bellvol.pack('side'=>'top', 'expand'=>'yes')
f.pack('side'=>'top', 'expand'=>'yes')
#
# Keyboard settings
#
kbdonoff = nil
kbdcli = nil
kbd = TkLabelframe.new(@root, 'text'=>'Keyboard Repeat Settings',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(kbd)
@w_kbdonoff = TkCheckButton.new(f, 'text'=>'On', 'relief'=>'flat',
'onvalue'=>'on', 'offvalue'=>'off',
'variable'=>@w_kbdrep ) {
def self.set(value)
if value == 'on'
self.select
else
self.deselect
end
end
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x', 'padx'=>[0, '1m'])
}
@w_kbdcli = TkScale.new(f, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>'Click Volume (%)')
@w_kbdcli.pack('side'=>'left', 'expand'=>'yes',
'fill'=>'x', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'fill'=>'x')
#
# Mouse settings
#
mouse = TkLabelframe.new(@root, 'text'=>'Mouse Settings',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(mouse)
@w_mouseacc = LabelEntry.new(f, 'Acceleration', 5)
@w_mouseacc.pack('side'=>'left', 'padx'=>[0, '1m'])
@w_mousethr = LabelEntry.new(f, 'Threshold (pixels)', 3, [1, 2000])
@w_mousethr.pack('side'=>'right', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes')
#
# Screen Saver settings
#
screen = TkLabelframe.new(@root, 'text'=>'Screen-saver Settings',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_screenblank = TkRadioButton.new(screen, 'text'=>'Blank',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'blank') {
def self.set(value)
if value == 'blank'
self.select
else
self.deselect
end
end
}
@w_screenpat = TkRadioButton.new(screen, 'text'=>'Pattern',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'noblank') {
def self.set(value)
if value != 'blank'
self.select
else
self.deselect
end
end
}
@w_screentim = LabelEntry.new(screen, 'Timeout (s)', 5, [1, 100000])
@w_screencyc = LabelEntry.new(screen, 'Cycle (s)', 5, [1, 100000])
Tk.grid(@w_screenblank, @w_screentim, 'sticky'=>'e')
Tk.grid(@w_screenpat, @w_screencyc, 'sticky'=>'e')
TkGrid.configure(@w_screenblank, @w_screenpat, 'sticky'=>'ew')
#
# Main window
#
param = {
'side'=>'top', 'fill'=>'both', 'expand'=>'yes',
'padx'=>'1m', 'pady'=>'1m'
}
btn_frame.pack('side'=>'top', 'fill'=>'both')
bell.pack(param)
kbd.pack(param)
mouse.pack(param)
screen.pack(param)
#
# Let the user resize our window
#
@root.minsize(10,10)
end
def initialize(title)
@root = TkRoot.new('title'=>title)
@kbdrep = 'on'
@w_kbdrep = TkVariable.new(@kbdrep)
def @w_kbdrep.get
self.value
end
def @w_kbdrep.set(val)
self.value=val
end
@kbdcli = 0
@bellvol = 100
@bellpit = 440
@belldur = 100
@mouseacc = "3/1"
@mousethr = 4
@screenbla = "blank"
@w_screenbla = TkVariable.new(@screenbla)
def @w_screenbla.get
self.value
end
def @w_screenbla.set(val)
self.value=val
end
@screentim = 600
@screencyc = 600
#
# Listen what "xset" tells us...
#
readsettings
#
# Create all windows
#
createwindows
#
# Write xset parameters
#
dispsettings
end
end
Xsettings.new(File.basename($0,'.rb'))
Tk.mainloop

Просмотреть файл

@ -0,0 +1,212 @@
#
# menus widget demo (called by 'widget')
#
# toplevel widget
if defined?($menu84_demo) && $menu84_demo
$menu84_demo.destroy
$menu84_demo = nil
end
# demo toplevel widget
$menu84_demo = TkToplevel.new {|w|
title("File Selection Dialogs")
iconname("menu84")
positionWindow(w)
}
begin
windowingsystem = Tk.windowingsystem()
rescue
windowingsystem = ""
end
# label
TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.")
else
text("This window contains a menubar with cascaded menus. You can post a menu from the keyboard by typing Alt+x, where \"x\" is the character underlined on the menu. You can then traverse among the menus using the arrow keys. When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character. If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator. The rightmost menu can be torn off into a palette by selecting the first item in the menu.")
end
}.pack('side'=>'top')
menustatus = TkVariable.new(" ")
TkFrame.new($menu84_demo) {|frame|
TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken',
'bd'=>1, 'font'=>['Helvetica', '10'],
'anchor'=>'w').pack('side'=>'left', 'padx'=>2,
'expand'=>true, 'fill'=>'both')
pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
}
# frame
TkFrame.new($menu84_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
tmppath = $menu84_demo
$menu84_demo = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'Show Code'
command proc{showCode 'menu84'}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# create menu frame
$menu84_frame = TkMenu.new($menu84_demo, 'tearoff'=>false)
# menu
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'File', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Open...', 'command'=>proc{fail 'this is just a demo: no action has been defined for the "Open..." entry'})
add('command', 'label'=>'New', 'command'=>proc{fail 'this is just a demo: no action has been defined for the "New" entry'})
add('command', 'label'=>'Save', 'command'=>proc{fail 'this is just a demo: no action has been defined for the "Save" entry'})
add('command', 'label'=>'Save As...', 'command'=>proc{fail 'this is just a demo: no action has been defined for the "Save As..." entry'})
add('separator')
add('command', 'label'=>'Print Setup...', 'command'=>proc{fail 'this is just a demo: no action has been defined for the "Print Setup..." entry'})
add('command', 'label'=>'Print...', 'command'=>proc{fail 'this is just a demo: no action has been defined for the "Print..." entry'})
add('separator')
add('command', 'label'=>'Dismiss Menus Demo', 'command'=>proc{$menu84_demo.destroy})
}
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem = "classic" || windowingsystem = "aqua"
modifier = 'Command'
elsif $tk_platform['platform'] == 'windows'
modifier = 'Control'
else
modifier = 'Meta'
end
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Basic', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Long entry that does nothing')
['A','B','C','D','E','F','G'].each{|c|
add('command', 'label'=>"Print letter \"#{c}\"",
'underline'=>14, 'accelerator'=>"Meta+#{c}",
'command'=>proc{print c,"\n"}, 'accelerator'=>"#{modifier}+#{c}")
$menu84_demo.bind("#{modifier}-#{c.downcase}", proc{print c,"\n"})
}
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Cascades', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Print hello',
'command'=>proc{print "Hello\n"},
'accelerator'=>"#{modifier}+H", 'underline'=>6)
$menu84_demo.bind("#{modifier}-h", proc{print "Hello\n"})
add('command', 'label'=>'Print goodbye',
'command'=>proc{print "Goodbye\n"},
'accelerator'=>"#{modifier}+G", 'underline'=>6)
$menu84_demo.bind("#{modifier}-g", proc{print "Goodbye\n"})
TkMenu.new(m, 'tearoff'=>false) {|cascade_check|
m.add('cascade', 'label'=>'Check buttons',
'menu'=>cascade_check, 'underline'=>0)
oil = TkVariable.new(0)
add('check', 'label'=>'Oil checked', 'variable'=>oil)
trans = TkVariable.new(0)
add('check', 'label'=>'Transmission checked', 'variable'=>trans)
brakes = TkVariable.new(0)
add('check', 'label'=>'Brakes checked', 'variable'=>brakes)
lights = TkVariable.new(0)
add('check', 'label'=>'Lights checked', 'variable'=>lights)
add('separator')
add('command', 'label'=>'Show current values',
'command'=>proc{showVars($menu84_demo,
['oil', oil],
['trans', trans],
['brakes', brakes],
['lights', lights])} )
invoke 1
invoke 3
}
TkMenu.new(m, 'tearoff'=>false) {|cascade_radio|
m.add('cascade', 'label'=>'Radio buttons',
'menu'=>cascade_radio, 'underline'=>0)
pointSize = TkVariable.new
add('radio', 'label'=>'10 point', 'variable'=>pointSize, 'value'=>10)
add('radio', 'label'=>'14 point', 'variable'=>pointSize, 'value'=>14)
add('radio', 'label'=>'18 point', 'variable'=>pointSize, 'value'=>18)
add('radio', 'label'=>'24 point', 'variable'=>pointSize, 'value'=>24)
add('radio', 'label'=>'32 point', 'variable'=>pointSize, 'value'=>32)
add('separator')
style = TkVariable.new
add('radio', 'label'=>'Roman', 'variable'=>style, 'value'=>'roman')
add('radio', 'label'=>'Bold', 'variable'=>style, 'value'=>'bold')
add('radio', 'label'=>'Italic', 'variable'=>style, 'value'=>'italic')
add('separator')
add('command', 'label'=>'Show current values',
'command'=>proc{showVars($menu84_demo,
['pointSize', pointSize],
['style', style])} )
invoke 1
invoke 7
}
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Icons', 'menu'=>m, 'underline'=>0)
add('command', 'hidemargin'=>1,
'bitmap'=>'@'+[$demo_dir,'images','pattern.xbm'].join(File::Separator),
'command'=>proc{TkDialog.new('title'=>'Bitmap Menu Entry',
'text'=>'The menu entry you invoked displays a bitmap rather than a text string. Other than this, it is just like any other menu entry.',
'bitmap'=>'', 'default'=>0,
'buttons'=>'Dismiss')} )
['info', 'questhead', 'error'].each{|icon|
add('command', 'bitmap'=>icon, 'hidemargin'=>1,
'command'=>proc{print "You invoked the #{icon} bitmap\n"})
}
entryconfigure(2, :columnbreak=>true)
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'More', 'menu'=>m, 'underline'=>0)
[ 'An entry','Another entry','Does nothing','Does almost nothing',
'Make life meaningful' ].each{|i|
add('command', 'label'=>i,
'command'=>proc{print "You invoked \"#{i}\"\n"})
}
m.entryconfigure('Does almost nothing',
'bitmap'=>'questhead', 'compound'=>'left',
'command'=>proc{
TkDialog.new('title'=>'Compound Menu Entry',
'message'=>'The menu entry you invoked'+
'displays both a bitmap and '+
'a text string. Other than '+
'this, it isjust like any '+
'other menu entry.',
'buttons'=>['OK'], 'bitmap'=>'')
})
}
TkMenu.new($menu84_frame) {|m|
$menu84_frame.add('cascade', 'label'=>'Colors', 'menu'=>m, 'underline'=>0)
['red', 'orange', 'yellow', 'green', 'blue'].each{|c|
add('command', 'label'=>c, 'background'=>c,
'command'=>proc{print "You invoked \"#{c}\"\n"})
}
}
$menu84_demo.menu($menu84_frame)
TkMenu.bind('<MenuSelect>', proc{|w|
begin
label = w.entrycget('active', 'label')
rescue
label = " "
end
menustatus.value = label
Tk.update(true)
}, '%W')

Просмотреть файл

@ -195,8 +195,18 @@ TkFrame.new(center) {|f|
'White','Brown','DarkSeaGreen','DarkViolet']
colorMenuButton = TkMenubutton.new(f)
m = optionMenu(colorMenuButton, paletteColor, *colors)
begin
windowingsystem = Tk.windowingsystem()
rescue
windowingsystem = ""
end
if windowingsystem == "classic" || windowingsystem == "aqua"
topBorderColor = 'Black'
bottomBorderColor = 'Black'
else
topBorderColor = 'gray50'
bottomBorderColor = 'gray75'
end
for i in 0..15
image = TkPhotoImage.new('height'=>16, 'width'=>16)
image.put(topBorderColor, 0, 0, 16, 1)

Просмотреть файл

@ -50,11 +50,20 @@ TkFrame.new($puzzle_demo) {|frame|
# Special trick: select a darker color for the space by creating a
# scrollbar widget and using its trough color.
begin
if Tk.windowingsystem() == 'aqua'
frameSize = 160
else
frameSize = 120
end
rescue
frameSize = 120
end
s = TkScrollbar.new($puzzle_demo)
base = TkFrame.new($puzzle_demo) {
width 120
height 120
width frameSize
height frameSize
borderwidth 2
relief 'sunken'
bg s['troughcolor']

Просмотреть файл

@ -0,0 +1,106 @@
# radio.rb
#
# This demonstration script creates a toplevel window containing
# several radiobutton widgets.
#
# radiobutton widget demo (called by 'widget')
#
# toplevel widget
if defined?($radio2_demo) && $radio2_demo
$radio2_demo.destroy
$radio2_demo = nil
end
# demo toplevel widget
$radio2_demo = TkToplevel.new {|w|
title("Radiobutton Demonstration")
iconname("radio")
positionWindow(w)
}
# label
msg = TkLabel.new($radio2_demo) {
font $font
wraplength '5i'
justify 'left'
text "Three groups of radiobuttons are displayed below. If you click on a button then the button will become selected exclusively among all the buttons in its group. A Tcl variable is associated with each group to indicate which of the group's buttons is selected. Click the \"See Variables\" button to see the current values of the variables."
}
msg.pack('side'=>'top')
#
size = TkVariable.new
color = TkVariable.new
align = TkVariable.new
# frame
TkFrame.new($radio2_demo) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
tmppath = $radio2_demo
$radio2_demo = nil
$showVarsWin[tmppath.path] = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'Show Code'
command proc{showCode 'radio'}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'See Variables'
command proc{
showVars($radio2_demo,
['size', size], ['color', color], ['compound', align])
}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
f_left = TkLabelFrame.new($radio2_demo, 'text'=>'Point Size',
'pady'=>2, 'padx'=>2)
f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'Color',
'pady'=>2, 'padx'=>2)
f_right = TkLabelFrame.new($radio2_demo, 'text'=>'Alignment',
'pady'=>2, 'padx'=>2)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
# radiobutton
[10, 12, 18, 24].each {|sz|
TkRadioButton.new(f_left) {
text "Point Size #{sz}"
variable size
relief 'flat'
value sz
}.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w', 'fill'=>'x')
}
['Red', 'Green', 'Blue', 'Yellow', 'Orange', 'Purple'].each {|col|
TkRadioButton.new(f_mid) {
text col
variable color
relief 'flat'
value col.downcase
anchor 'w'
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
}
label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label))
abtn = ['Top', 'Left', 'Right', 'Bottom'].collect{|a|
lower = a.downcase
TkRadioButton.new(f_right, 'text'=>a, 'variable'=>align, 'relief'=>'flat',
'value'=>lower, 'indicatoron'=>0, 'width'=>7,
'command'=>proc{label.compound(align.value)})
}
Tk.grid('x', abtn[0])
Tk.grid(abtn[1], label, abtn[2])
Tk.grid('x', abtn[3])

Просмотреть файл

@ -19,6 +19,13 @@ $text_demo = TkToplevel.new {|w|
positionWindow(w)
}
# version check
if ((Tk::TK_VERSION.split('.').collect{|n| n.to_i} <=> [8,4]) < 0)
undo_support = false
else
undo_support = true
end
# frame
TkFrame.new($text_demo) {|frame|
TkButton.new(frame) {
@ -36,13 +43,16 @@ TkFrame.new($text_demo) {|frame|
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# text <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
# text
TkText.new($text_demo){|t|
# <20><><EFBFBD><EFBFBD>
relief 'sunken'
bd 2
setgrid 1
height 30
if undo_support
undo true
autoseparators true
end
TkScrollbar.new($text_demo) {|s|
pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)}
@ -51,7 +61,8 @@ TkText.new($text_demo){|t|
pack('expand'=>'yes', 'fill'=>'both')
#
insert('0.0', %q|This window is a text widget. It displays one or more lines of text
insert('0.0', <<EOT)
This window is a text widget. It displays one or more lines of text
and allows you to edit the text. Here is a summary of the things you
can do to a text widget:
@ -89,14 +100,27 @@ the insertion cursor to the end of the line, or it deletes the newline
character if that is the only thing left on the line. Control-o opens
a new line by inserting a newline character to the right of the insertion
cursor. Control-t transposes the two characters on either side of the
insertion cursor.
insertion cursor. #{
if undo_support
undo_text = "Control-z undoes the last editing action performed,\nand "
case $tk_platform['platform']
when "unix", "macintosh"
undo_text << "Control-Shift-z"
else # 'windows'
undo_text << "Control-y"
end
undo_text << "redoes undone edits."
else
""
end
}
7. Resize the window. This widget has been configured with the "setGrid"
option on, so that if you resize the window it will always resize to an
even number of characters high and wide. Also, if you make the window
narrow you can see that long lines automatically wrap around onto
additional lines so that all the information is always visible.|)
additional lines so that all the information is always visible.
EOT
set_insert('0.0')
}

Просмотреть файл

@ -198,15 +198,17 @@ txt.insert('end', "3. Checkbuttons (select any of a group).\n", tag_demo, "demo-
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. Radiobuttons (select one of a group).\n", tag_demo, "demo-radio")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "5. A 15-puzzle game made out of buttons.\n", tag_demo, "demo-puzzle")
txt.insert('end', "5. Radiobuttons (if supported 'compound' option).\n", tag_demo, "demo-radio2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. Iconic buttons that use bitmaps.\n", tag_demo, "demo-icon")
txt.insert('end', "6. A 15-puzzle game made out of buttons.\n", tag_demo, "demo-puzzle")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "7. Two labels displaying images.\n", tag_demo, "demo-image1")
txt.insert('end', "7. Iconic buttons that use bitmaps.\n", tag_demo, "demo-icon")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "8. A simple user interface for viewing images.\n", tag_demo, "demo-image2")
txt.insert('end', "8. Two labels displaying images.\n", tag_demo, "demo-image1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "9. Labelled frames (if supported)\n", tag_demo, "demo-labelframe")
txt.insert('end', "9. A simple user interface for viewing images.\n", tag_demo, "demo-image2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "10. Labelled frames (if supported)\n", tag_demo, "demo-labelframe")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@ -284,7 +286,9 @@ 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)
txt.insert('end', "2. Menubuttons\n", tag_demo, "demo-menubu")
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")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
@ -502,7 +506,7 @@ end
#
def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
'message'=>"Ruby/Tk widget demonstration Ver.1.3.0-en\n\n( based on Tk 8.1 Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}")
'message'=>"Ruby/Tk widget demonstration Ver.1.3.1-en\n\n( based on Tk 8.1 Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}")
end
################################

Просмотреть файл

@ -0,0 +1,368 @@
#!/usr/bin/env ruby
#
# ixset --
# A nice interface to "xset" to change X server settings
#
require 'tk'
class Xsettings
#
# Button actions
#
def quit
@root.destroy
end
def ok
writesettings
quit
end
def cancel
readsettings
dispsettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
# apply is just "writesettings"
def apply
writesettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
#
# Read current settings
#
def readsettings
xfd = open("|xset q", 'r')
xfd.readlines.each{|line|
fields = line.chomp.strip.split(/\s+/)
case fields[0]
when "auto"
if fields[1] == 'repeat:'
@kbdrep = fields[2]
@w_kbdrep.set(@kbdrep)
@kbdcli = fields[6]
end
when "bell"
@bellvol = fields[2]
@bellpit = fields[5]
@belldur = fields[8]
when "acceleration:"
@mouseacc = fields[1]
@mousethr = fields[3]
when "prefer"
if fields[2] == 'yes'
@screenbla = 'blank'
else
@screenbla = 'noblank'
end
@w_screenbla.set(@screenbla)
when "timeout:"
@screentim = fields[1]
@screencyc = fields[3]
end
}
xfd.close
end
#
# Write settings into the X server
#
def writesettings
@bellvol = @w_bellvol.get
@bellpit = @w_bellpit.get
@belldur = @w_belldur.get
@kbdrep = @w_kbdrep.get
if @kbdrep == 'on'
@kbdcli = @w_kbdcli.get
else
@kbdcli = 'off'
end
@mouseacc = @w_mouseacc.get
@mousethr = @w_mousethr.get
@screentim = @w_screentim.get
@screencyc = @w_screencyc.get
@screenbla = @w_screenbla.get
system("xset \
b #{@bellvol} #{@bellpit} #{@belldur} \
c #{@kbdcli} \
r #{@kbdrep} \
m #{@mouseacc} #{@mousethr} \
s #{@screentim} #{@screencyc} \
s #{@screenbla}")
end
#
# Sends all settings to the window
#
def dispsettings
@w_bellvol.set(@bellvol)
@w_bellpit.set(@bellpit)
@w_belldur.set(@belldur)
@w_kbdonoff.set(@w_kbdrep.get)
@w_kbdcli.set(@kbdcli)
@w_mouseacc.set(@mouseacc)
@w_mousethr.set(@mousethr)
@w_screenblank.set(@w_screenbla.get)
@w_screenpat.set(@w_screenbla.get)
@w_screentim.set(@screentim)
@w_screencyc.set(@screencyc)
end
#
# Create all windows, and pack them
#
class LabelEntry
def initialize(parent, text, length, range=[])
@frame = TkFrame.new(parent)
TkLabel.new(@frame, 'text'=>text).pack('side'=>'left')
if range.size > 0
@entry = TkSpinbox.new(@frame, 'width'=>length, 'relief'=>'sunken',
'from'=>range[0], 'to'=>range[1])
else
@entry = TkEntry.new(@frame, 'width'=>length, 'relief'=>'sunken')
end
@entry.pack('side'=>'right','expand'=>'y', 'fill'=>'x')
end
def epath
@frame
end
def pack(keys)
@frame.pack(keys)
end
def get
@entry.value
end
def set(value)
@entry.delete(0,'end')
@entry.insert(0, value)
end
end
def createwindows
win = self
#
# Buttons
#
btn_frame = TkFrame.new(@root)
buttons = [
@btn_OK = TkButton.new(btn_frame, 'command'=>proc{win.ok},
'default'=>'active', 'text'=>'了解'),
@btn_APPLY = TkButton.new(btn_frame, 'command'=>proc{win.writesettings},
'default'=>'normal', 'text'=>'適用',
'state'=>'disabled'),
@btn_CANCEL = TkButton.new(btn_frame, 'command'=>proc{win.cancel},
'default'=>'normal', 'text'=>'取消',
'state'=>'disabled'),
@btn_QUIT = TkButton.new(btn_frame, 'command'=>proc{win.quit},
'default'=>'normal', 'text'=>'中止')
]
buttons.each{|b| b.pack('side'=>'left', 'expand'=>'yes', 'pady'=>5) }
@root.bind('Return', proc{@btn_OK.flash; @btn_OK.invoke})
@root.bind('Escape', proc{@btn_QUIT.flash; @btn_QUIT.invoke})
@root.bind('1', proc{|w|
unless buttons.index(w)
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
}, '%W')
@root.bind('Key', proc{|w, k|
unless buttons.index(w)
case k
when 'Return', 'Escape', 'Tab', /.*Shift.*/
# do nothing
else
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
end
}, '%W %K')
#
# Bell settings
#
bell = TkLabelframe.new(@root, 'text'=>'ベル設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_bellvol = TkScale.new(bell, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>"音量 (%)")
f = TkFrame.new(bell)
@w_bellpit = LabelEntry.new(f, "音程 (Hz)", 6, [25, 20000])
@w_bellpit.pack('side'=>'left', 'padx'=>5)
@w_belldur = LabelEntry.new(f, "持続時間 (ms)", 6, [1, 10000])
@w_belldur.pack('side'=>'right', 'padx'=>5)
@w_bellvol.pack('side'=>'top', 'expand'=>'yes')
f.pack('side'=>'top', 'expand'=>'yes')
#
# Keyboard settings
#
kbdonoff = nil
kbdcli = nil
kbd = TkLabelframe.new(@root, 'text'=>'キーボードリピート設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(kbd)
@w_kbdonoff = TkCheckButton.new(f, 'text'=>'クリック音あり',
'relief'=>'flat',
'onvalue'=>'on', 'offvalue'=>'off',
'variable'=>@w_kbdrep ) {
def self.set(value)
if value == 'on'
self.select
else
self.deselect
end
end
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x', 'padx'=>[0, '1m'])
}
@w_kbdcli = TkScale.new(f, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>'クリック音量 (%)')
@w_kbdcli.pack('side'=>'left', 'expand'=>'yes',
'fill'=>'x', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'fill'=>'x')
#
# Mouse settings
#
mouse = TkLabelframe.new(@root, 'text'=>'マウス設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(mouse)
@w_mouseacc = LabelEntry.new(f, '加速量', 5)
@w_mouseacc.pack('side'=>'left', 'padx'=>[0, '1m'])
@w_mousethr = LabelEntry.new(f, '閾値 (pixels)', 3, [1, 2000])
@w_mousethr.pack('side'=>'right', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes')
#
# Screen Saver settings
#
screen = TkLabelframe.new(@root, 'text'=>'スクリーンセーバ設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_screenblank = TkRadioButton.new(screen, 'text'=>'ブランク表示',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'blank') {
def self.set(value)
if value == 'blank'
self.select
else
self.deselect
end
end
}
@w_screenpat = TkRadioButton.new(screen, 'text'=>'パターン表示',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'noblank') {
def self.set(value)
if value != 'blank'
self.select
else
self.deselect
end
end
}
@w_screentim = LabelEntry.new(screen, 'タイムアウト (s)', 5, [1, 100000])
@w_screencyc = LabelEntry.new(screen, '周期 (s)', 5, [1, 100000])
Tk.grid(@w_screenblank, @w_screentim, 'sticky'=>'e')
Tk.grid(@w_screenpat, @w_screencyc, 'sticky'=>'e')
TkGrid.configure(@w_screenblank, @w_screenpat, 'sticky'=>'ew')
#
# Main window
#
param = {
'side'=>'top', 'fill'=>'both', 'expand'=>'yes',
'padx'=>'1m', 'pady'=>'1m'
}
btn_frame.pack('side'=>'top', 'fill'=>'both')
bell.pack(param)
kbd.pack(param)
mouse.pack(param)
screen.pack(param)
#
# Let the user resize our window
#
@root.minsize(10,10)
end
def initialize(title)
@root = TkRoot.new('title'=>title)
@kbdrep = 'on'
@w_kbdrep = TkVariable.new(@kbdrep)
def @w_kbdrep.get
self.value
end
def @w_kbdrep.set(val)
self.value=val
end
@kbdcli = 0
@bellvol = 100
@bellpit = 440
@belldur = 100
@mouseacc = "3/1"
@mousethr = 4
@screenbla = "blank"
@w_screenbla = TkVariable.new(@screenbla)
def @w_screenbla.get
self.value
end
def @w_screenbla.set(val)
self.value=val
end
@screentim = 600
@screencyc = 600
#
# Listen what "xset" tells us...
#
readsettings
#
# Create all windows
#
createwindows
#
# Write xset parameters
#
dispsettings
end
end
Xsettings.new(File.basename($0,'.rb'))
Tk.mainloop

Просмотреть файл

@ -0,0 +1,208 @@
#
# menus widget demo (called by 'widget')
#
# toplevel widget
if defined?($menu84_demo) && $menu84_demo
$menu84_demo.destroy
$menu84_demo = nil
end
# demo toplevel widget
$menu84_demo = TkToplevel.new {|w|
title("File Selection Dialogs")
iconname("menu84")
positionWindow(w)
}
begin
windowingsystem = Tk.windowingsystem()
rescue
windowingsystem = ""
end
# label
TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("このウィンドウにはカスケードメニューを持つメニューバーが付けられています。Command+x ('x'はコマンドキーシンボルに続けて表示されている文字です) とタイプすることによっても項目の機能を呼び出すことができます。最後のメニューは、マウスでウィンドウの外にドラッグすることによって、独立したパレットとなるように切り放すことが可能です。")
else
text("このウィンドウにはカスケードメニューを持つメニューバーが付けられています。Alt+x ('x'はメニュー上で下線が引かれた文字です) とタイプすることによってもメニューを呼び出すことができます。矢印キーを使って、メニュー間を移動することも可能です。メニューが表示されている時には、現在位置の項目をスペースキーで選択したり、下線が引かれた文字を入力することでその項目を選択したりすることができます。もし項目にアクセラレータの指定がなされていたならば、その指定されたキー入力を行うことで、メニューを表示させることなく直接その項目の機能を呼び出せます。最後のメニューは、メニューの最初の項目を選択することによって、独立したパレットとなるように切り放すことが可能です。")
end
}.pack('side'=>'top')
menustatus = TkVariable.new(" ")
TkFrame.new($menu84_demo) {|frame|
TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken',
'bd'=>1, 'font'=>['Helvetica', '10'],
'anchor'=>'w').pack('side'=>'left', 'padx'=>2,
'expand'=>true, 'fill'=>'both')
pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
}
# frame
TkFrame.new($menu84_demo) {|frame|
TkButton.new(frame) {
text '了解'
command proc{
tmppath = $menu84_demo
$menu84_demo = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'コード参照'
command proc{showCode 'menu84'}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# create menu frame
$menu84_frame = TkMenu.new($menu84_demo, 'tearoff'=>false)
# menu
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'File', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Open...', 'command'=>proc{fail 'これは単なるデモですから、"Open..." 項目の機能は特に定義されてはいません。'})
add('command', 'label'=>'New', 'command'=>proc{fail 'これは単なるデモですから、"New" 項目の機能は特に定義されてはいません。'})
add('command', 'label'=>'Save', 'command'=>proc{fail 'これは単なるでもですから、"Save" 項目の機能は特に定義されてはいません。'})
add('command', 'label'=>'Save As...', 'command'=>proc{fail 'これは単なるでもですから、"Save As..." 項目の機能は特に定義されてはいません。'})
add('separator')
add('command', 'label'=>'Print Setup...', 'command'=>proc{fail 'これは単なるデモですから、"Print Setup..." 項目の機能は特に定義されてはいません。'})
add('command', 'label'=>'Print...', 'command'=>proc{fail 'これは単なるデモですから、"Print..." 項目の機能は特に定義されてはいません。'})
add('separator')
add('command', 'label'=>'Dismiss Menus Demo', 'command'=>proc{$menu84_demo.destroy})
}
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem = "classic" || windowingsystem = "aqua"
modifier = 'Command'
elsif $tk_platform['platform'] == 'windows'
modifier = 'Control'
else
modifier = 'Meta'
end
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Basic', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Long entry that does nothing')
['A','B','C','D','E','F','G'].each{|c|
add('command', 'label'=>"Print letter \"#{c}\"",
'underline'=>14, 'accelerator'=>"Meta+#{c}",
'command'=>proc{print c,"\n"}, 'accelerator'=>"#{modifier}+#{c}")
$menu84_demo.bind("#{modifier}-#{c.downcase}", proc{print c,"\n"})
}
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Cascades', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Print hello',
'command'=>proc{print "Hello\n"},
'accelerator'=>"#{modifier}+H", 'underline'=>6)
$menu84_demo.bind("#{modifier}-h", proc{print "Hello\n"})
add('command', 'label'=>'Print goodbye',
'command'=>proc{print "Goodbye\n"},
'accelerator'=>"#{modifier}+G", 'underline'=>6)
$menu84_demo.bind("#{modifier}-g", proc{print "Goodbye\n"})
TkMenu.new(m, 'tearoff'=>false) {|cascade_check|
m.add('cascade', 'label'=>'Check button',
'menu'=>cascade_check, 'underline'=>0)
oil = TkVariable.new(0)
add('check', 'label'=>'オイル検査', 'variable'=>oil)
trans = TkVariable.new(0)
add('check', 'label'=>'トランスミッション検査', 'variable'=>trans)
brakes = TkVariable.new(0)
add('check', 'label'=>'ブレーキ検査', 'variable'=>brakes)
lights = TkVariable.new(0)
add('check', 'label'=>'ライト検査', 'variable'=>lights)
add('separator')
add('command', 'label'=>'Show current values',
'command'=>proc{showVars($menu84_demo,
['オイル', oil],
['トランスミッション', trans],
['ブレーキ', brakes],
['ライト', lights])} )
invoke 1
invoke 3
}
TkMenu.new(m, 'tearoff'=>false) {|cascade_radio|
m.add('cascade', 'label'=>'Radio buttons',
'menu'=>cascade_radio, 'underline'=>0)
pointSize = TkVariable.new
add('radio', 'label'=>'10 point', 'variable'=>pointSize, 'value'=>10)
add('radio', 'label'=>'14 point', 'variable'=>pointSize, 'value'=>14)
add('radio', 'label'=>'18 point', 'variable'=>pointSize, 'value'=>18)
add('radio', 'label'=>'24 point', 'variable'=>pointSize, 'value'=>24)
add('radio', 'label'=>'32 point', 'variable'=>pointSize, 'value'=>32)
add('separator')
style = TkVariable.new
add('radio', 'label'=>'Roman', 'variable'=>style, 'value'=>'roman')
add('radio', 'label'=>'Bold', 'variable'=>style, 'value'=>'bold')
add('radio', 'label'=>'Italic', 'variable'=>style, 'value'=>'italic')
add('separator')
add('command', 'label'=>'現在値の表示',
'command'=>proc{showVars($menu84_demo,
['pointSize', pointSize],
['style', style])} )
invoke 1
invoke 7
}
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Icons', 'menu'=>m, 'underline'=>0)
add('command', 'hidemargin'=>1,
'bitmap'=>'@'+[$demo_dir,'images','pattern.bmp'].join(File::Separator),
'command'=>proc{TkDialog.new('title'=>'Bitmap Menu Entry',
'text'=>'あなたが選択したメニュー項目は、文字列の代わりにビットマップイメージで項目を表示したものです。それ以外の点では、ほかのメニュー項目との間で特に違いがあるわけではありません。',
'bitmap'=>'', 'default'=>0,
'buttons'=>'閉じる')} )
['info', 'questhead', 'error'].each{|icon|
add('command', 'bitmap'=>icon, 'hidemargin'=>1,
'command'=>proc{print "You invoked the #{icon} bitmap\n"})
}
entryconfigure(2, :columnbreak=>true)
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'More', 'menu'=>m, 'underline'=>0)
[ 'An entry','Another entry','Does nothing','Does almost nothing',
'Make life meaningful' ].each{|i|
add('command', 'label'=>i,
'command'=>proc{print "You invoked \"#{i}\"\n"})
}
m.entryconfigure('Does almost nothing',
'bitmap'=>'questhead', 'compound'=>'left',
'command'=>proc{
TkDialog.new('title'=>'Compound Menu Entry',
'message'=>'あなたが選択したメニュー項目は、ビットマップイメージと文字列とを同時に一つの項目に表示するようにしたものです。それ以外の点では、ほかのメニュー項目との間で特に違いがあるわけではありません。',
'buttons'=>['了解'], 'bitmap'=>'')
})
}
TkMenu.new($menu84_frame) {|m|
$menu84_frame.add('cascade', 'label'=>'Colors', 'menu'=>m, 'underline'=>0)
['red', 'orange', 'yellow', 'green', 'blue'].each{|c|
add('command', 'label'=>c, 'background'=>c,
'command'=>proc{print "You invoked \"#{c}\"\n"})
}
}
$menu84_demo.menu($menu84_frame)
TkMenu.bind('<MenuSelect>', proc{|w|
begin
label = w.entrycget('active', 'label')
rescue
label = " "
end
menustatus.value = label
Tk.update(true)
}, '%W')

Просмотреть файл

@ -193,8 +193,18 @@ TkFrame.new(center) {|f|
'White','Brown','DarkSeaGreen','DarkViolet']
colorMenuButton = TkMenubutton.new(f)
m = optionMenu(colorMenuButton, paletteColor, *colors)
begin
windowingsystem = Tk.windowingsystem()
rescue
windowingsystem = ""
end
if windowingsystem == "classic" || windowingsystem == "aqua"
topBorderColor = 'Black'
bottomBorderColor = 'Black'
else
topBorderColor = 'gray50'
bottomBorderColor = 'gray75'
end
for i in 0..15
image = TkPhotoImage.new('height'=>16, 'width'=>16)
image.put(topBorderColor, 0, 0, 16, 1)

Просмотреть файл

@ -47,10 +47,20 @@ TkFrame.new($puzzle_demo) {|frame|
# Special trick: scrollbar widget を生成してその trough color を用いることで
# 空白部分のための暗色を選択し,設定する
#
begin
if Tk.windowingsystem() == 'aqua'
frameSize = 160
else
frameSize = 120
end
rescue
frameSize = 120
end
s = TkScrollbar.new($puzzle_demo)
base = TkFrame.new($puzzle_demo) {
width 120
height 120
width frameSize
height frameSize
borderwidth 2
relief 'sunken'
bg s['troughcolor']

Просмотреть файл

@ -0,0 +1,106 @@
# radio.rb
#
# This demonstration script creates a toplevel window containing
# several radiobutton widgets.
#
# radiobutton widget demo (called by 'widget')
#
# toplevel widget
if defined?($radio2_demo) && $radio2_demo
$radio2_demo.destroy
$radio2_demo = nil
end
# demo toplevel widget
$radio2_demo = TkToplevel.new {|w|
title("Radiobutton Demonstration")
iconname("radio")
positionWindow(w)
}
# label
msg = TkLabel.new($radio2_demo) {
font $font
wraplength '5i'
justify 'left'
text "下には2つのラジオボタングループが表示されています。ボタンをクリックすると、そのボタンだけがそのグループの中で選択されます。各グループに対してそのグループの中のどのボタンが選択されているかを示す変数が割り当てられています。現在の変数の値を見るには「変数参照」ボタンをクリックしてください。"
}
msg.pack('side'=>'top')
#
size = TkVariable.new
color = TkVariable.new
align = TkVariable.new
# frame
TkFrame.new($radio2_demo) {|frame|
TkButton.new(frame) {
text '了解'
command proc{
tmppath = $radio2_demo
$radio2_demo = nil
$showVarsWin[tmppath.path] = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'コード参照'
command proc{showCode 'radio'}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text '変数参照'
command proc{
showVars($radio2_demo,
['size', size], ['color', color], ['compound', align])
}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
f_left = TkLabelFrame.new($radio2_demo, 'text'=>'文字サイズ',
'pady'=>2, 'padx'=>2)
f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'色',
'pady'=>2, 'padx'=>2)
f_right = TkLabelFrame.new($radio2_demo, 'text'=>'ビットマップ配置',
'pady'=>2, 'padx'=>2)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
# radiobutton
[10, 12, 18, 24].each {|sz|
TkRadioButton.new(f_left) {
text "ポイントサイズ #{sz}"
variable size
relief 'flat'
value sz
}.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w', 'fill'=>'x')
}
['赤', '緑', '青', '黄', '橙', '紫'].each {|col|
TkRadioButton.new(f_mid) {
text col
variable color
relief 'flat'
value col.downcase
anchor 'w'
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
}
label = TkLabel.new(f_right, 'text'=>'ラベル', 'bitmap'=>'questhead',
'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label))
abtn = ['Top', 'Left', 'Right', 'Bottom'].collect{|a|
lower = a.downcase
TkRadioButton.new(f_right, 'text'=>a, 'variable'=>align, 'relief'=>'flat',
'value'=>lower, 'indicatoron'=>0, 'width'=>7,
'command'=>proc{label.compound(align.value)})
}
Tk.grid('x', abtn[0])
Tk.grid(abtn[1], label, abtn[2])
Tk.grid('x', abtn[3])

Просмотреть файл

@ -15,6 +15,13 @@ $text_demo = TkToplevel.new {|w|
positionWindow(w)
}
# version check
if ((Tk::TK_VERSION.split('.').collect{|n| n.to_i} <=> [8,4]) < 0)
undo_support = false
else
undo_support = true
end
# frame 生成
TkFrame.new($text_demo) {|frame|
TkButton.new(frame) {
@ -47,7 +54,7 @@ TkText.new($text_demo){|t|
pack('expand'=>'yes', 'fill'=>'both')
# テキスト挿入
insert('0.0', %q|
insert('0.0', <<EOT)
widget 1
widget
@ -82,12 +89,27 @@ TkText.new($text_demo){|t|
Meta-
Meta-D
-K
#{
if undo_support
undo_text = "Control-z は最後に行った変更の取り消し(undo)を行い、"
case $tk_platform['platform']
when "unix", "macintosh"
undo_text << "Control-Shift-z"
else # 'windows'
undo_text << "Control-y"
end
undo_text << "はundoした変更の再適用(redo)を行います。"
else
""
end
}
8. widget "setGrid"
|)
EOT
set_insert('0.0')
}

Просмотреть файл

@ -211,19 +211,22 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. ラジオボタン (任意の一つを選択可能)\n",
tag_demo, "demo-radio")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "5. ボタンで作られた15-パズルゲーム\n",
txt.insert('end', "5. ラジオボタン (機能に対応したバージョンのTkが必要)\n",
tag_demo, "demo-radio2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. ボタンで作られた15-パズルゲーム\n",
tag_demo, "demo-puzzle")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "6. ビットマップを使用したアイコンボタン\n",
txt.insert('end', "7. ビットマップを使用したアイコンボタン\n",
tag_demo, "demo-icon")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "7. 画像を表示する二つのラベル\n",
txt.insert('end', "8. 画像を表示する二つのラベル\n",
tag_demo, "demo-image1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "8. 画像を見るための簡単なユーザインターフェース\n",
txt.insert('end', "9. 画像を見るための簡単なユーザインターフェース\n",
tag_demo, "demo-image2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "9. ラベル付きフレーム (Tkに実装されている場合に限る)\n",
txt.insert('end', "10. ラベル付きフレーム (機能に対応したバージョンのTkが必要)\n",
tag_demo, "demo-labelframe")
txt.insert('end', " \n ", tag_demospace)
@ -247,7 +250,7 @@ txt.insert('end', "1.
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. スクロールバーあり\n", tag_demo, "demo-entry2")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. スピンボックス (Tkに実装されている場合に限る)\n",
txt.insert('end', "3. スピンボックス (機能に対応したバージョンのTkが必要)\n",
tag_demo, "demo-spin")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. 簡単なフォーム\n", tag_demo, "demo-form")
@ -302,10 +305,10 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "\n")
txt.insert('end', "ペインドウィンドウ\n", tag_kanji_title)
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "1. 水平方向 (Tkに実装されている場合に限る)\n",
txt.insert('end', "1. 水平方向 (機能に対応したバージョンのTkが必要)\n",
tag_demo.id, "demo-paned1")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. 垂直方向 (Tkに実装されている場合に限る)\n",
txt.insert('end', "2. 垂直方向 (機能に対応したバージョンのTkが必要)\n",
tag_demo.id, "demo-paned2")
txt.insert('end', " \n ", tag_demospace)
@ -319,7 +322,10 @@ txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "2. メニューとカスケードを含んだウィンドウ (Tk8.x 専用)\n",
tag_demo, "demo-menu8x")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "3. メニューボタン (Tk8.x 専用)\n",
txt.insert('end', "3. 〃 (機能に対応したバージョンのTkが必要)\n",
tag_demo, "demo-menu84")
txt.insert('end', " \n ", tag_demospace)
txt.insert('end', "4. メニューボタン (Tk8.x 専用)\n",
tag_demo, "demo-menubu")
txt.insert('end', " \n ", tag_demospace)