summaryrefslogtreecommitdiff
path: root/ext/tk/sample/demos-en
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tk/sample/demos-en')
-rw-r--r--ext/tk/sample/demos-en/ixset2367
-rw-r--r--ext/tk/sample/demos-en/menu84.rb212
-rw-r--r--ext/tk/sample/demos-en/menubu.rb14
-rw-r--r--ext/tk/sample/demos-en/puzzle.rb13
-rw-r--r--ext/tk/sample/demos-en/radio2.rb106
-rw-r--r--ext/tk/sample/demos-en/text.rb36
-rw-r--r--ext/tk/sample/demos-en/widget18
7 files changed, 749 insertions, 17 deletions
diff --git a/ext/tk/sample/demos-en/ixset2 b/ext/tk/sample/demos-en/ixset2
new file mode 100644
index 0000000000..ce8472abe0
--- /dev/null
+++ b/ext/tk/sample/demos-en/ixset2
@@ -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
diff --git a/ext/tk/sample/demos-en/menu84.rb b/ext/tk/sample/demos-en/menu84.rb
new file mode 100644
index 0000000000..82e29f6475
--- /dev/null
+++ b/ext/tk/sample/demos-en/menu84.rb
@@ -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')
diff --git a/ext/tk/sample/demos-en/menubu.rb b/ext/tk/sample/demos-en/menubu.rb
index 4c19aa12a8..42a5931dd1 100644
--- a/ext/tk/sample/demos-en/menubu.rb
+++ b/ext/tk/sample/demos-en/menubu.rb
@@ -195,8 +195,18 @@ TkFrame.new(center) {|f|
'White','Brown','DarkSeaGreen','DarkViolet']
colorMenuButton = TkMenubutton.new(f)
m = optionMenu(colorMenuButton, paletteColor, *colors)
- topBorderColor = 'gray50'
- bottomBorderColor = 'gray75'
+ 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)
diff --git a/ext/tk/sample/demos-en/puzzle.rb b/ext/tk/sample/demos-en/puzzle.rb
index 91e4c8c1fb..d206efe34b 100644
--- a/ext/tk/sample/demos-en/puzzle.rb
+++ b/ext/tk/sample/demos-en/puzzle.rb
@@ -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']
diff --git a/ext/tk/sample/demos-en/radio2.rb b/ext/tk/sample/demos-en/radio2.rb
new file mode 100644
index 0000000000..aefd81bdca
--- /dev/null
+++ b/ext/tk/sample/demos-en/radio2.rb
@@ -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])
diff --git a/ext/tk/sample/demos-en/text.rb b/ext/tk/sample/demos-en/text.rb
index 1dcaad1cf9..2ed53e6938 100644
--- a/ext/tk/sample/demos-en/text.rb
+++ b/ext/tk/sample/demos-en/text.rb
@@ -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 À¸À®
+# text
TkText.new($text_demo){|t|
- # À¸À®
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')
}
-
diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget
index 9381401db2..590da01088 100644
--- a/ext/tk/sample/demos-en/widget
+++ b/ext/tk/sample/demos-en/widget
@@ -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
################################