2005-04-09 05:27:54 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
#
|
|
|
|
# Demo for 'tile' package.
|
|
|
|
#
|
|
|
|
require 'tk'
|
|
|
|
|
|
|
|
demodir = File.dirname($0)
|
|
|
|
Tk::AUTO_PATH.lappend('.', demodir, File.join(demodir, 'themes'))
|
|
|
|
|
|
|
|
require 'tkextlib/tile'
|
|
|
|
|
2005-08-04 00:16:27 -04:00
|
|
|
def version?(ver)
|
|
|
|
TkPackage.vcompare(Tk::Tile.package_version, ver) >= 0
|
|
|
|
end
|
|
|
|
|
2005-04-09 05:27:54 -04:00
|
|
|
Tk.load_tclscript(File.join(demodir, 'toolbutton.tcl'))
|
2005-08-02 02:51:26 -04:00
|
|
|
Tk.load_tclscript(File.join(demodir, 'repeater.tcl'))
|
2005-04-09 05:27:54 -04:00
|
|
|
|
|
|
|
# This forces an update of the available packages list. It's required
|
|
|
|
# for package names to find the themes in demos/themes/*.tcl
|
2005-08-02 17:05:17 -04:00
|
|
|
## Tk.tk_call(TkPackage.unknown_proc, 'Tcl', TkPackage.provide('Tcl'))
|
|
|
|
## --> This doesn't work.
|
|
|
|
## Because, unknown_proc may be "command + some arguments".
|
|
|
|
Tk.ip_eval("#{TkPackage.unknown_proc} Tcl #{TkPackage.provide('Tcl')}")
|
2005-04-09 05:27:54 -04:00
|
|
|
|
|
|
|
TkRoot.new{
|
|
|
|
title 'Tile demo'
|
|
|
|
iconname 'Tile demo'
|
|
|
|
}
|
|
|
|
|
|
|
|
# The descriptive names of the builtin themes.
|
|
|
|
$THEMELIST = [
|
|
|
|
['default', 'Classic'],
|
|
|
|
['alt', 'Revitalized'],
|
|
|
|
['winnative', 'Windows native'],
|
|
|
|
['xpnative', 'XP Native'],
|
|
|
|
['aqua', 'Aqua'],
|
|
|
|
]
|
|
|
|
|
|
|
|
$V = TkVariable.new_hash(:THEME => 'default',
|
|
|
|
:COMPOUND => 'top',
|
|
|
|
:CONSOLE => false,
|
|
|
|
:MENURADIO1 => 'One',
|
2005-08-04 00:16:27 -04:00
|
|
|
:MENUCHECK1 => true,
|
|
|
|
:PBMODE => 'determinate',
|
|
|
|
:SELECTED => true,
|
|
|
|
:CHOICE => 2)
|
2005-04-09 05:27:54 -04:00
|
|
|
|
|
|
|
# Add in any available loadable themes.
|
|
|
|
TkPackage.names.find_all{|n| n =~ /^tile::theme::/}.each{|pkg|
|
|
|
|
name = pkg.split('::')[-1]
|
|
|
|
unless $THEMELIST.assoc(name)
|
|
|
|
$THEMELIST << [name, Tk.tk_call('string', 'totitle', name)]
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add theme definition written by ruby
|
|
|
|
$RUBY_THEMELIST = []
|
|
|
|
begin
|
|
|
|
load(File.join(demodir, 'themes', 'kroc.rb'), true)
|
|
|
|
rescue
|
|
|
|
$RUBY_THEMELIST << ['kroc-rb', 'Kroc (by Ruby)', false]
|
|
|
|
else
|
|
|
|
$RUBY_THEMELIST << ['kroc-rb', 'Kroc (by Ruby)', true]
|
|
|
|
end
|
|
|
|
|
|
|
|
def makeThemeControl(parent)
|
2005-08-04 00:48:13 -04:00
|
|
|
c = Tk::Tile::Labelframe.new(parent, :text=>'Theme')
|
2005-04-09 05:27:54 -04:00
|
|
|
$THEMELIST.each{|theme, name|
|
2005-08-04 00:48:13 -04:00
|
|
|
b = Tk::Tile::Radiobutton.new(c, :text=>name, :value=>theme,
|
2005-04-09 05:27:54 -04:00
|
|
|
:variable=>$V.ref(:THEME),
|
|
|
|
:command=>proc{setTheme(theme)})
|
|
|
|
b.grid(:sticky=>:ew)
|
|
|
|
unless (TkPackage.names.find{|n| n == "tile::theme::#{theme}"})
|
|
|
|
b.state(:disabled)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
$RUBY_THEMELIST.each{|theme, name, available|
|
2005-08-04 00:48:13 -04:00
|
|
|
b = Tk::Tile::Radiobutton.new(c, :text=>name, :value=>theme,
|
2005-04-09 05:27:54 -04:00
|
|
|
:variable=>$V.ref(:THEME),
|
|
|
|
:command=>proc{setTheme(theme)})
|
|
|
|
b.grid(:sticky=>:ew)
|
|
|
|
b.state(:disabled) unless available
|
|
|
|
}
|
|
|
|
c
|
|
|
|
end
|
|
|
|
|
|
|
|
def makeThemeMenu(parent)
|
|
|
|
m = TkMenu.new(parent)
|
|
|
|
$THEMELIST.each{|theme, name|
|
|
|
|
m.add(:radiobutton, :label=>name, :variable=>$V.ref(:THEME),
|
|
|
|
:value=>theme, :command=>proc{setTheme(theme)})
|
|
|
|
unless (TkPackage.names.find{|n| n == "tile::theme::#{theme}"})
|
|
|
|
m.entryconfigure(:end, :state=>:disabled)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
$RUBY_THEMELIST.each{|theme, name, available|
|
|
|
|
m.add(:radiobutton, :label=>name, :variable=>$V.ref(:THEME),
|
|
|
|
:value=>theme, :command=>proc{setTheme(theme)})
|
|
|
|
m.entryconfigure(:end, :state=>:disabled) unless available
|
|
|
|
}
|
|
|
|
m
|
|
|
|
end
|
|
|
|
|
|
|
|
def setTheme(theme)
|
|
|
|
if (TkPackage.names.find{|n| n == "tile::theme::#{theme}"})
|
|
|
|
TkPackage.require("tile::theme::#{theme}")
|
|
|
|
end
|
|
|
|
Tk::Tile::Style.theme_use(theme)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Load icons...
|
|
|
|
#
|
|
|
|
$BUTTONS = ['open', 'new', 'save']
|
|
|
|
$CHECKBOXES = ['bold', 'italic']
|
|
|
|
$ICON = {}
|
|
|
|
|
|
|
|
def loadIcons(file)
|
|
|
|
Tk.load_tclscript(file)
|
|
|
|
img_data = TkVarAccess.new('ImgData')
|
|
|
|
img_data.keys.each{|icon|
|
|
|
|
$ICON[icon] = TkPhotoImage.new(:data=>img_data[icon])
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
loadIcons(File.join(demodir, 'iconlib.tcl'))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Utilities:
|
|
|
|
#
|
|
|
|
def foreachWidget(wins, cmd)
|
|
|
|
wins.each{|w|
|
|
|
|
cmd.call(w)
|
|
|
|
foreachWidget(w.winfo_children, cmd)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# sbstub
|
|
|
|
# Used as the :command option for a scrollbar,
|
|
|
|
# updates the scrollbar's position.
|
|
|
|
#
|
|
|
|
def sbstub(sb, cmd, num, units = 'units')
|
2005-06-05 10:03:41 -04:00
|
|
|
num = TkComm.number(num)
|
2005-04-09 05:27:54 -04:00
|
|
|
case cmd.to_s
|
|
|
|
when 'moveto'
|
|
|
|
sb.set(num, num+0.5)
|
|
|
|
|
|
|
|
when 'scroll'
|
|
|
|
if units.to_s == 'pages'
|
|
|
|
delta = 0.2
|
|
|
|
else
|
|
|
|
delta = 0.05
|
|
|
|
end
|
|
|
|
current = sb.get
|
|
|
|
sb.set(current[0] + delta * num, current[1] + delta * num)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# ... for debugging:
|
|
|
|
TkBindTag::ALL.bind('ButtonPress-3', proc{|w| $W = w}, '%W')
|
|
|
|
TkBindTag::ALL.bind('Control-ButtonPress-3', proc{|w| w.set_focus}, '%W')
|
|
|
|
|
|
|
|
def showHelp()
|
|
|
|
Tk.messageBox(:message=>'No help yet...')
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# See toolbutton.tcl.
|
|
|
|
TkOption.add('*Toolbar.relief', :groove)
|
|
|
|
TkOption.add('*Toolbar.borderWidth', 2)
|
|
|
|
|
|
|
|
TkOption.add('*Toolbar.Button.Pad', 2)
|
|
|
|
|
|
|
|
$ROOT = Tk.root
|
|
|
|
$BASE = $ROOT
|
|
|
|
Tk.destroy(*($ROOT.winfo_children))
|
|
|
|
|
|
|
|
$TOOLBARS = []
|
|
|
|
|
|
|
|
#
|
|
|
|
# Toolbar button standard vs. tile comparison:
|
|
|
|
#
|
|
|
|
def makeToolbars
|
|
|
|
#
|
|
|
|
# Tile toolbar:
|
|
|
|
#
|
2005-08-04 00:48:13 -04:00
|
|
|
tb = Tk::Tile::Frame.new($BASE, :class=>'Toolbar')
|
2005-04-09 05:27:54 -04:00
|
|
|
$TOOLBARS << tb
|
|
|
|
i = 0
|
|
|
|
$BUTTONS.each{|icon|
|
|
|
|
i += 1
|
2005-08-04 00:48:13 -04:00
|
|
|
Tk::Tile::Button.new(tb, :text=>icon, :image=>$ICON[icon],
|
2005-04-09 05:27:54 -04:00
|
|
|
:compound=>$V[:COMPOUND],
|
|
|
|
:style=>:Toolbutton).grid(:row=>0, :column=>i,
|
|
|
|
:sticky=>:news)
|
|
|
|
}
|
|
|
|
$CHECKBOXES.each{|icon|
|
|
|
|
i += 1
|
2005-08-04 00:48:13 -04:00
|
|
|
Tk::Tile::Checkbutton.new(tb, :text=>icon, :image=>$ICON[icon],
|
2005-04-09 05:27:54 -04:00
|
|
|
:variable=>$V.ref(icon),
|
|
|
|
:compound=>$V[:COMPOUND],
|
|
|
|
:style=>:Toolbutton).grid(:row=>0, :column=>i,
|
|
|
|
:sticky=>:news)
|
|
|
|
}
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
mb = Tk::Tile::Menubutton.new(tb, :text=>'toolbar', :image=>$ICON['file'],
|
2005-04-09 05:27:54 -04:00
|
|
|
:compound=>$V[:COMPOUND])
|
|
|
|
mb.configure(:menu=>makeCompoundMenu(mb))
|
|
|
|
i += 1
|
|
|
|
mb.grid(:row=>0, :column=>i, :sticky=>:news)
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
tb.grid_columnconfigure(i, :weight=>1)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Standard toolbar:
|
|
|
|
#
|
|
|
|
tb = TkFrame.new($BASE, :class=>'Toolbar')
|
|
|
|
$TOOLBARS << tb
|
|
|
|
i = 0
|
|
|
|
$BUTTONS.each{|icon|
|
|
|
|
i += 1
|
|
|
|
TkButton.new(tb, :text=>icon, :image=>$ICON[icon],
|
|
|
|
:compound=>$V[:COMPOUND], :relief=>:flat,
|
|
|
|
:overrelief=>:raised).grid(:row=>0, :column=>i,
|
|
|
|
:sticky=>:news)
|
|
|
|
}
|
|
|
|
$CHECKBOXES.each{|icon|
|
|
|
|
i += 1
|
|
|
|
TkCheckbutton.new(tb, :text=>icon, :image=>$ICON[icon],
|
|
|
|
:variable=>$V.ref(icon), :compound=>$V[:COMPOUND],
|
|
|
|
:indicatoron=>false, :selectcolor=>'', :relief=>:flat,
|
|
|
|
:overrelief=>:raised).grid(:row=>0, :column=>i,
|
|
|
|
:sticky=>:news)
|
|
|
|
}
|
|
|
|
|
|
|
|
mb = TkMenubutton.new(tb, :text=>'toolbar', :image=>$ICON['file'],
|
|
|
|
:compound=>$V[:COMPOUND])
|
|
|
|
mb.configure(:menu=>makeCompoundMenu(mb))
|
|
|
|
i += 1
|
|
|
|
mb.grid(:row=>0, :column=>i, :sticky=>:news)
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
tb.grid_columnconfigure(i, :weight=>1)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Toolbar :compound control:
|
|
|
|
#
|
|
|
|
def makeCompoundMenu(mb)
|
|
|
|
menu = TkMenu.new(mb)
|
|
|
|
%w(text image none top bottom left right center).each{|str|
|
|
|
|
menu.add(:radiobutton, :label=>Tk.tk_call('string', 'totitle', str),
|
|
|
|
:variable=>$V.ref(:COMPOUND), :value=>str,
|
|
|
|
:command=>proc{ changeToolbars() })
|
|
|
|
}
|
|
|
|
menu
|
|
|
|
end
|
|
|
|
|
|
|
|
makeToolbars()
|
|
|
|
|
|
|
|
## CONTROLS
|
2005-08-04 00:48:13 -04:00
|
|
|
control = Tk::Tile::Frame.new($BASE)
|
2005-04-09 05:27:54 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Overall theme control:
|
|
|
|
#
|
|
|
|
makeThemeControl(control).grid(:sticky=>:news, :padx=>6, :ipadx=>6)
|
|
|
|
control.grid_rowconfigure(99, :weight=>1)
|
|
|
|
|
|
|
|
def changeToolbars
|
|
|
|
foreachWidget($TOOLBARS,
|
|
|
|
proc{|w|
|
|
|
|
begin
|
|
|
|
w.compound($V[:COMPOUND])
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def scrolledWidget(parent, klass, themed, *args)
|
|
|
|
if themed
|
2005-08-04 00:48:13 -04:00
|
|
|
f = Tk::Tile::Frame.new(parent)
|
2005-04-09 05:27:54 -04:00
|
|
|
t = klass.new(f, *args)
|
2005-08-04 00:48:13 -04:00
|
|
|
vs = Tk::Tile::Scrollbar.new(f)
|
|
|
|
hs = Tk::Tile::Scrollbar.new(f)
|
2005-04-09 05:27:54 -04:00
|
|
|
else
|
|
|
|
f = TkFrame.new(parent)
|
|
|
|
t = klass.new(f, *args)
|
|
|
|
vs = TkScrollbar.new(f)
|
|
|
|
hs = TkScrollbar.new(f)
|
|
|
|
end
|
|
|
|
t.yscrollbar(vs)
|
|
|
|
t.xscrollbar(hs)
|
|
|
|
|
|
|
|
TkGrid.configure(t, vs, :sticky=>:news)
|
|
|
|
TkGrid.configure(hs, 'x', :sticky=>:news)
|
|
|
|
TkGrid.rowconfigure(f, 0, :weight=>1)
|
|
|
|
TkGrid.columnconfigure(f, 0, :weight=>1)
|
|
|
|
|
|
|
|
[f, t]
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Notebook demonstration:
|
|
|
|
#
|
|
|
|
def makeNotebook
|
2005-08-04 00:48:13 -04:00
|
|
|
nb = Tk::Tile::Notebook.new($BASE, :padding=>6)
|
2005-04-09 05:27:54 -04:00
|
|
|
nb.enable_traversal
|
2005-08-04 00:48:13 -04:00
|
|
|
client = Tk::Tile::Frame.new(nb)
|
2005-04-09 05:27:54 -04:00
|
|
|
nb.add(client, :text=>'Demo', :underline=>0)
|
|
|
|
nb.select(client)
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
scales = Tk::Tile::Frame.new(nb)
|
2005-08-04 00:16:27 -04:00
|
|
|
nb.add(scales, :text=>'Scales')
|
2005-08-04 00:48:13 -04:00
|
|
|
combo = Tk::Tile::Frame.new(nb)
|
2005-08-01 02:35:15 -04:00
|
|
|
nb.add(combo, :text=>'Combobox', :underline=>7)
|
2005-08-04 00:48:13 -04:00
|
|
|
tree = Tk::Tile::Frame.new(nb)
|
2005-08-01 06:25:51 -04:00
|
|
|
nb.add(tree, :text=>'Tree')
|
2005-08-04 00:48:13 -04:00
|
|
|
others = Tk::Tile::Frame.new(nb)
|
2005-04-09 05:27:54 -04:00
|
|
|
nb.add(others, :text=>'Others', :underline=>4)
|
|
|
|
|
2005-08-04 00:16:27 -04:00
|
|
|
[nb, client, scales, combo, tree, others]
|
2005-04-09 05:27:54 -04:00
|
|
|
end
|
|
|
|
|
2005-08-04 00:16:27 -04:00
|
|
|
nb, client, scales, combo, tree, others = makeNotebook()
|
2005-04-09 05:27:54 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Side-by side check, radio, and menu button comparison:
|
|
|
|
#
|
|
|
|
def fillMenu(menu)
|
|
|
|
%w(above below left right flush).each{|dir|
|
|
|
|
menu.add(:command, :label=>Tk.tk_call('string', 'totitle', dir),
|
|
|
|
:command=>proc{ menu.winfo_parent.direction(dir) })
|
|
|
|
}
|
|
|
|
menu.add(:cascade, :label=>'Submenu', :menu=>(submenu = TkMenu.new(menu)))
|
|
|
|
submenu.add(:command, :label=>'Subcommand 1')
|
|
|
|
submenu.add(:command, :label=>'Subcommand 2')
|
|
|
|
submenu.add(:command, :label=>'Subcommand 3')
|
|
|
|
|
|
|
|
menu.add(:separator)
|
|
|
|
menu.add(:command, :label=>'Quit', :command=>proc{Tk.root.destroy})
|
|
|
|
end
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
l = Tk::Tile::Labelframe.new(client, :text=>'Themed', :padding=>6)
|
2005-04-09 05:27:54 -04:00
|
|
|
r = TkLabelframe.new(client, :text=>'Standard', :padx=>6, :pady=>6)
|
|
|
|
|
|
|
|
## Styled frame
|
2005-08-04 00:48:13 -04:00
|
|
|
cb = Tk::Tile::Checkbutton.new(l, :text=>'Checkbutton',
|
2005-04-09 05:27:54 -04:00
|
|
|
:variable=>$V.ref(:SELECTED), :underline=>2)
|
2005-08-04 00:48:13 -04:00
|
|
|
rb1 = Tk::Tile::Radiobutton.new(l, :text=>'One', :variable=>$V.ref(:CHOICE),
|
2005-04-09 05:27:54 -04:00
|
|
|
:value=>1, :underline=>0)
|
2005-08-04 00:48:13 -04:00
|
|
|
rb2 = Tk::Tile::Radiobutton.new(l, :text=>'Two', :variable=>$V.ref(:CHOICE),
|
2005-04-09 05:27:54 -04:00
|
|
|
:value=>2)
|
2005-08-04 00:48:13 -04:00
|
|
|
rb3 = Tk::Tile::Radiobutton.new(l, :text=>'Three',
|
2005-04-09 05:27:54 -04:00
|
|
|
:variable=>$V.ref(:CHOICE),
|
|
|
|
:value=>3, :underline=>0)
|
2005-08-04 00:48:13 -04:00
|
|
|
btn = Tk::Tile::Button.new(l, :text=>'Button', :underline=>0)
|
2005-04-09 05:27:54 -04:00
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
mb = Tk::Tile::Menubutton.new(l, :text=>'Menubutton', :underline=>2)
|
2005-04-09 05:27:54 -04:00
|
|
|
#m = TkMenu.new(mb)
|
|
|
|
#mb.menu(m)
|
|
|
|
#fillMenu(m)
|
|
|
|
|
|
|
|
$entryText = TkVariable.new('Entry widget')
|
2005-08-04 00:48:13 -04:00
|
|
|
e = Tk::Tile::Entry.new(l, :textvariable=>$entryText)
|
2005-04-09 05:27:54 -04:00
|
|
|
e.selection_range(6, :end)
|
|
|
|
|
|
|
|
ltext_f, ltext = scrolledWidget(l, TkText, true,
|
|
|
|
:width=>12, :height=>5, :wrap=>:none)
|
|
|
|
# NOTE TO MAINTAINERS:
|
|
|
|
# The checkbuttons are -sticky ew / -expand x on purpose:
|
|
|
|
# it demonstrates one of the differences between TCheckbuttons
|
|
|
|
# and standard checkbuttons.
|
|
|
|
#
|
|
|
|
Tk.grid(cb, :sticky=>:ew)
|
|
|
|
Tk.grid(rb1, :sticky=>:ew)
|
|
|
|
Tk.grid(rb2, :sticky=>:ew)
|
|
|
|
Tk.grid(rb3, :sticky=>:ew)
|
|
|
|
Tk.grid(btn, :sticky=>:ew, :padx=>2, :pady=>2)
|
|
|
|
Tk.grid(mb, :sticky=>:ew, :padx=>2, :pady=>2)
|
|
|
|
Tk.grid(e, :sticky=>:ew, :padx=>2, :pady=>2)
|
|
|
|
Tk.grid(ltext_f, :sticky=>:news)
|
|
|
|
|
|
|
|
TkGrid.columnconfigure(l, 0, :weight=>1)
|
|
|
|
TkGrid.rowconfigure(l, 7, :weight=>1) # text widget (grid is a PITA)
|
|
|
|
|
|
|
|
## Orig frame
|
|
|
|
cb = TkCheckbutton.new(r, :text=>'Checkbutton', :variable=>$V.ref(:SELECTED))
|
|
|
|
rb1 = TkRadiobutton.new(r, :text=>'One',
|
|
|
|
:variable=>$V.ref(:CHOICE), :value=>1)
|
|
|
|
rb2 = TkRadiobutton.new(r, :text=>'Two', :variable=>$V.ref(:CHOICE),
|
|
|
|
:value=>2, :underline=>1)
|
|
|
|
rb3 = TkRadiobutton.new(r, :text=>'Three',
|
|
|
|
:variable=>$V.ref(:CHOICE), :value=>3)
|
|
|
|
btn = TkButton.new(r, :text=>'Button')
|
|
|
|
|
|
|
|
mb = TkMenubutton.new(r, :text=>'Menubutton', :underline=>3, :takefocus=>true)
|
|
|
|
m = TkMenu.new(mb)
|
|
|
|
mb.menu(m)
|
|
|
|
$V[:rmbIndicatoron] = mb.indicatoron
|
|
|
|
m.add(:checkbutton, :label=>'Indicator?', #'
|
|
|
|
:variable=>$V.ref(:rmbIndicatoron),
|
2005-07-26 21:57:14 -04:00
|
|
|
:command=>proc{mb.indicatoron($V[:rmbIndicatoron])})
|
2005-04-09 05:27:54 -04:00
|
|
|
m.add(:separator)
|
|
|
|
fillMenu(m)
|
|
|
|
|
|
|
|
e = TkEntry.new(r, :textvariable=>$entryText)
|
|
|
|
|
|
|
|
rtext_f, rtext = scrolledWidget(r, TkText, false,
|
|
|
|
:width=>12, :height=>5, :wrap=>:none)
|
|
|
|
|
|
|
|
Tk.grid(cb, :sticky=>:ew)
|
|
|
|
Tk.grid(rb1, :sticky=>:ew)
|
|
|
|
Tk.grid(rb2, :sticky=>:ew)
|
|
|
|
Tk.grid(rb3, :sticky=>:ew)
|
|
|
|
Tk.grid(btn, :sticky=>:ew, :padx=>2, :pady=>2)
|
|
|
|
Tk.grid(mb, :sticky=>:ew, :padx=>2, :pady=>2)
|
|
|
|
Tk.grid(e, :sticky=>:ew, :padx=>2, :pady=>2)
|
|
|
|
Tk.grid(rtext_f, :sticky=>:news)
|
|
|
|
|
|
|
|
TkGrid.columnconfigure(l, 0, :weight=>1)
|
|
|
|
TkGrid.rowconfigure(l, 7, :weight=>1) # text widget (grid is a PITA)
|
|
|
|
|
|
|
|
Tk.grid(l, r, :sticky=>:news, :padx=>6, :pady=>6)
|
|
|
|
TkGrid.rowconfigure(client, 0, :weight=>1)
|
|
|
|
TkGrid.columnconfigure(client, [0, 1], :weight=>1)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Add some text to the text boxes:
|
|
|
|
#
|
|
|
|
msgs = [
|
|
|
|
"The cat crept into the crypt, crapped and crept out again",
|
|
|
|
"Peter Piper picked a peck of pickled peppers",
|
|
|
|
"How much wood would a woodchuck chuck if a woodchuck could chuck wood",
|
|
|
|
"He thrusts his fists against the posts and still insists he sees the ghosts",
|
|
|
|
"Who put the bomb in the bom-b-bom-b-bom,",
|
|
|
|
"Is this your sister's sixth zither, sir?",
|
|
|
|
"Who put the ram in the ramalamadingdong?",
|
|
|
|
"I am not the pheasant plucker, I'm the pheasant plucker's mate."
|
|
|
|
]
|
|
|
|
|
|
|
|
nmsgs = msgs.size
|
|
|
|
(0...50).each{|n|
|
|
|
|
msg = msgs[n % nmsgs]
|
|
|
|
ltext.insert(:end, "#{n}: #{msg}\n")
|
|
|
|
rtext.insert(:end, "#{n}: #{msg}\n")
|
|
|
|
}
|
2005-08-04 00:16:27 -04:00
|
|
|
#
|
|
|
|
# Scales and sliders pane:
|
|
|
|
#
|
2005-08-04 00:48:13 -04:00
|
|
|
l = Tk::Tile::Labelframe.new(scales, :text=>'Themed', :padding=>6)
|
2005-08-04 00:16:27 -04:00
|
|
|
r = TkLabelframe.new(scales, :text=>'Standard', :padx=>6, :pady=>6)
|
|
|
|
|
|
|
|
if version?('0.6')
|
|
|
|
|
|
|
|
# thremed frame
|
2005-08-04 00:48:13 -04:00
|
|
|
scale = Tk::Tile::Scale.new(l, :orient=>:horizontal, :from=>0, :to=>100,
|
2005-08-04 00:16:27 -04:00
|
|
|
:variable=>$V.ref(:SCALE))
|
2005-08-04 00:48:13 -04:00
|
|
|
vscale = Tk::Tile::Scale.new(l, :orient=>:vertical, :from=>0, :to=>100,
|
2005-08-04 00:16:27 -04:00
|
|
|
:variable=>$V.ref(:VSCALE))
|
2005-08-04 00:48:13 -04:00
|
|
|
progress = Tk::Tile::Progressbar.new(l, :orient=>:horizontal, :maximum=>100)
|
|
|
|
vprogress = Tk::Tile::Progressbar.new(l, :orient=>:vertical, :maximum=>100)
|
2005-08-04 00:16:27 -04:00
|
|
|
|
|
|
|
if true
|
|
|
|
def progress.inverted(w, value)
|
|
|
|
w.value(w.maximum - value)
|
|
|
|
end
|
|
|
|
scale.command {|value| progress.value(value)}
|
|
|
|
vscale.command {|value| progress.inverted(vprogress, value) }
|
|
|
|
else
|
|
|
|
# This would also work, but the Tk scale widgets
|
|
|
|
# in the right hand pane cause some interference when
|
|
|
|
# in autoincrement/indeterminate mode.
|
|
|
|
#
|
|
|
|
progress.variable $V.ref(:SCALE)
|
|
|
|
vprogress.variable $V.ref(:VSCALE)
|
|
|
|
end
|
|
|
|
|
|
|
|
scale.set(50)
|
|
|
|
vscale.set(50)
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
lmode = Tk::Tile::Label.new(l, :text=>'Progress bar mode')
|
|
|
|
pbmode0 = Tk::Tile::Radiobutton.new(l, :variable=>$V.ref(:PBMODE),
|
2005-08-04 00:16:27 -04:00
|
|
|
:text=>'determinate', :value=>'determinate',
|
|
|
|
:command=>proc{pbMode(progress, vprogress)})
|
2005-08-04 00:48:13 -04:00
|
|
|
pbmode1 = Tk::Tile::Radiobutton.new(l, :variable=>$V.ref(:PBMODE),
|
2005-08-04 00:16:27 -04:00
|
|
|
:text=>'indeterminate', :value=>'indeterminate',
|
|
|
|
:command=>proc{pbMode(progress, vprogress)})
|
|
|
|
def pbMode(progress, vprogress)
|
|
|
|
progress.mode $V[:PBMODE]
|
|
|
|
vprogress.mode $V[:PBMODE]
|
|
|
|
end
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
start = Tk::Tile::Button.new(l, :text=>"Start",
|
2005-08-04 00:16:27 -04:00
|
|
|
:command=>proc{pbStart(progress, vprogress)})
|
|
|
|
def pbStart(progress, vprogress)
|
|
|
|
$V[:PBMODE] = 'indeterminate'; pbMode(progress, vprogress)
|
|
|
|
progress.start 10
|
|
|
|
vprogress.start
|
|
|
|
end
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
stop = Tk::Tile::Button.new(l, :text=>'Stop',
|
2005-08-04 00:16:27 -04:00
|
|
|
:command=>proc{pbStop(progress, vprogress)})
|
|
|
|
def pbStop(progress, vprogress)
|
|
|
|
progress.stop
|
|
|
|
vprogress.stop
|
|
|
|
end
|
|
|
|
|
|
|
|
Tk.grid(scale, :columnspan=>2, :sticky=>'ew')
|
|
|
|
Tk.grid(progress, :columnspan=>2, :sticky=>'ew')
|
|
|
|
Tk.grid(vscale, vprogress, :sticky=>'nws')
|
|
|
|
|
|
|
|
Tk.grid(lmode, :sticky=>'we', :columnspan=>2)
|
|
|
|
Tk.grid(pbmode0, :sticky=>'we', :columnspan=>2)
|
|
|
|
Tk.grid(pbmode1, :sticky=>'we', :columnspan=>2)
|
|
|
|
Tk.grid(start, :sticky=>'we', :columnspan=>2)
|
|
|
|
Tk.grid(stop, :sticky=>'we', :columnspan=>2)
|
|
|
|
|
|
|
|
l.grid_columnconfigure(0, :weight=>1)
|
|
|
|
l.grid_columnconfigure(1, :weight=>1)
|
|
|
|
l.grid_rowconfigure(99, :weight=>1)
|
|
|
|
|
|
|
|
# standard frame
|
|
|
|
TkScale.new(r, :orient=>:horizontal, :from=>0, :to=>100,
|
|
|
|
:variable=>$V.ref(:SCALE)).grid(:sticky=>'news')
|
|
|
|
TkScale.new(r, :orient=>:vertical, :from=>0, :to=>100,
|
|
|
|
:variable=>$V.ref(:VSCALE)).grid(:sticky=>'nws')
|
|
|
|
|
|
|
|
r.grid_columnconfigure(0, :weight=>1)
|
|
|
|
r.grid_columnconfigure(1, :weight=>1)
|
|
|
|
r.grid_rowconfigure(99, :weight=>1)
|
|
|
|
|
|
|
|
else # tile 0.5 or earlier
|
|
|
|
|
|
|
|
# themed frame
|
2005-08-04 00:48:13 -04:00
|
|
|
scale = Tk::Tile::Scale.new(l, :variable=>$V.ref(:SCALE),
|
2005-08-04 00:16:27 -04:00
|
|
|
:orient=>:horizontal, :from=>0, :to=>100)
|
2005-08-04 00:48:13 -04:00
|
|
|
vscale = Tk::Tile::Scale.new(l, :variable=>$V.ref(:VSCALE),
|
2005-08-04 00:16:27 -04:00
|
|
|
:orient=>:vertical, :from=>-25, :to=>25)
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
progress = Tk::Tile::Progress.new(l,
|
2005-08-04 00:16:27 -04:00
|
|
|
:orient=>:horizontal, :from=>0, :to=>100)
|
2005-08-04 00:48:13 -04:00
|
|
|
vprogress = Tk::Tile::Progress.new(l,
|
2005-08-04 00:16:27 -04:00
|
|
|
:orient=>:vertical, :from=>-25, :to=>25)
|
|
|
|
|
|
|
|
if true
|
|
|
|
scale.command{|value| progress.set(value)}
|
|
|
|
vscale.command{|value| vprogress.set(value)}
|
|
|
|
else # this would also work. (via TkVariable#trace)
|
|
|
|
v1 = $V.ref(:SCALE)
|
|
|
|
v2 = $V.ref(:VSCALE)
|
|
|
|
v1.trace('w', proc{ progress.set(v1.value) })
|
|
|
|
v2.trace('w', proc{ vprogress.set(v2.value) })
|
|
|
|
end
|
|
|
|
|
|
|
|
Tk.grid(scale, :columnspan=>2, :sticky=>:ew)
|
|
|
|
Tk.grid(progress, :columnspan=>2, :sticky=>:ew)
|
|
|
|
Tk.grid(vscale, vprogress, :sticky=>:nws)
|
|
|
|
TkGrid.columnconfigure(l, 0, :weight=>1)
|
|
|
|
TkGrid.columnconfigure(l, 1, :weight=>1)
|
|
|
|
|
|
|
|
# standard frame
|
|
|
|
TkScale.new(r, :variable=>$V.ref(:SCALE),
|
|
|
|
:orient=>:horizontal, :from=>0, :to=>100).grid(:sticky=>'news')
|
|
|
|
TkScale.new(r, :variable=>$V.ref(:VSCALE),
|
|
|
|
:orient=>:vertical, :from=>-25, :to=>25).grid(:sticky=>'nws')
|
|
|
|
|
|
|
|
TkGrid.columnconfigure(r, 0, :weight=>1)
|
|
|
|
TkGrid.columnconfigure(r, 1, :weight=>1)
|
|
|
|
end
|
|
|
|
|
|
|
|
# layout frames
|
|
|
|
Tk.grid(l, r, :sticky=>'nwes', :padx=>6, :pady=>6)
|
|
|
|
scales.grid_columnconfigure(0, :weight=>1)
|
|
|
|
scales.grid_columnconfigure(1, :weight=>1)
|
|
|
|
scales.grid_rowconfigure(0, :weight=>1)
|
2005-04-09 05:27:54 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Command box:
|
|
|
|
#
|
2005-08-04 00:48:13 -04:00
|
|
|
cmd = Tk::Tile::Frame.new($BASE)
|
|
|
|
b_close = Tk::Tile::Button.new(cmd, :text=>'Close',
|
2005-04-09 05:27:54 -04:00
|
|
|
:underline=>0, :default=>:normal,
|
|
|
|
:command=>proc{Tk.root.destroy})
|
2005-08-04 00:48:13 -04:00
|
|
|
b_help = Tk::Tile::Button.new(cmd, :text=>'Help', :underline=>0,
|
2005-04-09 05:27:54 -04:00
|
|
|
:default=>:normal, :command=>proc{showHelp()})
|
|
|
|
Tk.grid('x', b_close, b_help, :pady=>[6, 4], :padx=>4)
|
|
|
|
TkGrid.columnconfigure(cmd, 0, :weight=>1)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Set up accelerators:
|
|
|
|
#
|
|
|
|
$ROOT.bind('KeyPress-Escape', proc{Tk.event_generate(b_close, '<Invoke>')})
|
|
|
|
$ROOT.bind('<Help>', proc{Tk.event_generate(b_help, '<Invoke>')})
|
|
|
|
Tk::Tile::KeyNav.enableMnemonics($ROOT)
|
|
|
|
Tk::Tile::KeyNav.defaultButton(b_help)
|
|
|
|
|
|
|
|
Tk.grid($TOOLBARS[0], '-', :sticky=>:ew)
|
|
|
|
Tk.grid($TOOLBARS[1], '-', :sticky=>:ew)
|
|
|
|
Tk.grid(control, nb, :sticky=>:news)
|
|
|
|
Tk.grid(cmd, '-', :sticky=>:ew)
|
|
|
|
TkGrid.columnconfigure($ROOT, 1, :weight=>1)
|
|
|
|
TkGrid.rowconfigure($ROOT, 2, :weight=>1)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Add a menu
|
|
|
|
#
|
|
|
|
menu = TkMenu.new($BASE)
|
|
|
|
$ROOT.menu(menu)
|
|
|
|
m_file = TkMenu.new(menu, :tearoff=>0)
|
|
|
|
menu.add(:cascade, :label=>'File', :underline=>0, :menu=>m_file)
|
|
|
|
m_file.add(:command, :label=>'Open', :underline=>0,
|
|
|
|
:compound=>:left, :image=>$ICON['open'])
|
|
|
|
m_file.add(:command, :label=>'Save', :underline=>0,
|
|
|
|
:compound=>:left, :image=>$ICON['save'])
|
|
|
|
m_file.add(:separator)
|
|
|
|
m_f_test = TkMenu.new(menu, :tearoff=>0)
|
|
|
|
m_file.add(:cascade, :label=>'Test submenu', :underline=>0, :menu=>m_f_test)
|
|
|
|
m_file.add(:checkbutton, :label=>'Text check', :underline=>5,
|
|
|
|
:variable=>$V.ref(:MENUCHECK1))
|
|
|
|
m_file.insert(:end, :separator)
|
|
|
|
|
|
|
|
if Tk.windowingsystem != 'x11'
|
2005-06-06 00:47:43 -04:00
|
|
|
TkConsole.create
|
2005-04-09 05:27:54 -04:00
|
|
|
m_file.insert(:end, :checkbutton, :label=>'Console', :underline=>5,
|
|
|
|
:variable=>$V.ref(:CONSOLE), :command=>proc{toggle_console()})
|
|
|
|
def toggle_console
|
|
|
|
if TkComm.bool($V[:CONSOLE])
|
|
|
|
TkConsole.show
|
|
|
|
else
|
|
|
|
TkConsole.hide
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
m_file.add(:command, :label=>'Exit', :underline=>1,
|
|
|
|
:command=>proc{Tk.event_generate(b_close, '<Invoke>')})
|
|
|
|
|
|
|
|
%w(One Two Three Four).each{|lbl|
|
|
|
|
m_f_test.add(:radiobutton, :label=>lbl, :variable=>$V.ref(:MENURADIO1))
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add Theme menu.
|
|
|
|
#
|
|
|
|
menu.add(:cascade, :label=>'Theme', :underline=>3,
|
|
|
|
:menu=>makeThemeMenu(menu))
|
|
|
|
|
|
|
|
setTheme($V[:THEME])
|
|
|
|
|
2005-08-01 02:35:15 -04:00
|
|
|
#
|
|
|
|
# Combobox demo pane:
|
|
|
|
#
|
|
|
|
values = %w(list abc def ghi jkl mno pqr stu vwx yz)
|
|
|
|
2.times {|i|
|
2005-08-04 00:48:13 -04:00
|
|
|
cb = Tk::Tile::Combobox.new(
|
2005-08-01 02:35:15 -04:00
|
|
|
combo, :values=>values, :textvariable=>$V.ref(:COMBO))
|
|
|
|
cb.pack(:side=>:top, :padx=>2, :pady=>2, :expand=>false, :fill=>:x)
|
|
|
|
if i == 1
|
|
|
|
cb.state :readonly
|
|
|
|
begin
|
|
|
|
cb.current = 3 # ignore if unsupported (tile0.4)
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2005-08-01 06:25:51 -04:00
|
|
|
#
|
|
|
|
# Treeview widget demo pane:
|
|
|
|
#
|
2005-08-04 00:16:27 -04:00
|
|
|
if version?('0.5')
|
2005-08-01 06:25:51 -04:00
|
|
|
|
|
|
|
treeview = nil # avoid 'undefined' error
|
2005-08-04 00:48:13 -04:00
|
|
|
scrollbar = Tk::Tile::Scrollbar.new(tree,
|
2005-08-01 06:25:51 -04:00
|
|
|
:command=>proc{|*args| treeview.yview(*args)})
|
|
|
|
treeview = Tk::Tile::Treeview.new(tree, :columns=>%w(Class), :padding=>4,
|
|
|
|
:yscrollcommand=>proc{|*args| scrollbar.set(*args)})
|
|
|
|
|
|
|
|
Tk.grid(treeview, scrollbar, :sticky=>'news')
|
|
|
|
tree.grid_columnconfigure(0, :weight=>1)
|
|
|
|
tree.grid_rowconfigure(0, :weight=>1)
|
|
|
|
tree.grid_propagate(0)
|
|
|
|
|
|
|
|
# Add initial tree node:
|
|
|
|
# Later nodes will be added in <<TreeviewOpen>> binding.
|
|
|
|
treeview.insert('', 0, :id=>'.', :text=>'Main Window', :open=>false,
|
|
|
|
:values=>[TkWinfo.classname('.')])
|
2005-08-02 17:05:17 -04:00
|
|
|
treeview.headingconfigure('#0', :text=>'Widget')
|
|
|
|
treeview.headingconfigure('Class', :text=>'Class')
|
2005-08-01 06:25:51 -04:00
|
|
|
treeview.bind('<TreeviewOpen>', proc{fillTree(treeview)})
|
|
|
|
|
|
|
|
def fillTree(treeview)
|
|
|
|
id = treeview.focus_item
|
|
|
|
unless TkWinfo.exist?(id)
|
|
|
|
treeview.delete(id)
|
|
|
|
end
|
|
|
|
# Replace tree item children with current list of child windows.
|
|
|
|
treeview.delete(treeview.children(id))
|
|
|
|
for child in TkWinfo.children(id)
|
|
|
|
treeview.insert(id, :end, :id=>child, :text=>TkWinfo.appname(child),
|
|
|
|
:open=>false, :values=>[TkWinfo.classname(child)])
|
|
|
|
unless TkWinfo.children(child).empty?
|
|
|
|
# insert dummy child to show [+] indicator
|
|
|
|
treeview.insert(child, :end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
2005-08-04 00:48:13 -04:00
|
|
|
Tk::Tile::Label.new(tree,
|
2005-08-01 06:25:51 -04:00
|
|
|
:text=>'Treeview is supported on tile 0.5 or later...').pack
|
|
|
|
end
|
|
|
|
|
2005-04-09 05:27:54 -04:00
|
|
|
#
|
|
|
|
# Other demos:
|
|
|
|
#
|
|
|
|
$Timers = {:StateMonitor=>nil, :FocusMonitor=>nil}
|
|
|
|
|
|
|
|
msg = TkMessage.new(others, :aspect=>200)
|
|
|
|
|
|
|
|
$Desc = {}
|
|
|
|
|
|
|
|
showDescription = TkBindTag.new
|
|
|
|
showDescription.bind('Enter', proc{|w| msg.text($Desc[w.path])}, '%W')
|
|
|
|
showDescription.bind('Leave', proc{|w| msg.text('')}, '%W')
|
|
|
|
|
|
|
|
[
|
|
|
|
[ :trackStates, "Widget states...",
|
|
|
|
"Display/modify widget state bits" ],
|
|
|
|
|
|
|
|
[ :scrollbarResizeDemo, "Scrollbar resize behavior...",
|
|
|
|
"Shows how Tile and standard scrollbars differ when they're sized too large" ],
|
|
|
|
|
|
|
|
[ :trackFocus, "Track keyboard focus..." ,
|
2005-08-02 02:51:26 -04:00
|
|
|
"Display the name of the widget that currently has focus" ],
|
|
|
|
|
|
|
|
[ :repeatDemo, "Repeating buttons...",
|
|
|
|
"Demonstrates custom classes (see demos/repeater.tcl)" ]
|
|
|
|
|
2005-04-09 05:27:54 -04:00
|
|
|
].each{|demo_cmd, label, description|
|
2005-08-04 00:48:13 -04:00
|
|
|
b = Tk::Tile::Button.new(others, :text=>label,
|
2005-04-09 05:27:54 -04:00
|
|
|
:command=>proc{ self.__send__(demo_cmd) })
|
|
|
|
$Desc[b.path] = description
|
|
|
|
b.bindtags <<= showDescription
|
|
|
|
|
|
|
|
b.pack(:side=>:top, :expand=>false, :fill=>:x, :padx=>6, :pady=>6)
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.pack(:side=>:bottom, :expand=>true, :fill=>:both)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Scrollbar resize demo:
|
|
|
|
#
|
|
|
|
$scrollbars = nil
|
|
|
|
|
|
|
|
def scrollbarResizeDemo
|
|
|
|
if $scrollbars
|
|
|
|
begin
|
|
|
|
$scrollbars.destroy
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$scrollbars = TkToplevel.new(:title=>'Scrollbars', :geometry=>'200x200')
|
|
|
|
f = TkFrame.new($scrollbars, :height=>200)
|
2005-08-04 00:48:13 -04:00
|
|
|
tsb = Tk::Tile::Scrollbar.new(f, :command=>proc{|*args| sbstub(tsb, *args)})
|
2005-04-09 05:27:54 -04:00
|
|
|
sb = TkScrollbar.new(f, :command=>proc{|*args| sbstub(sb, *args)})
|
|
|
|
Tk.grid(tsb, sb, :sticky=>:news)
|
|
|
|
|
|
|
|
sb.set(0, 0.5) # prevent backwards-compatibility mode for old SB
|
|
|
|
|
|
|
|
f.grid_columnconfigure(0, :weight=>1)
|
|
|
|
f.grid_columnconfigure(1, :weight=>1)
|
|
|
|
f.grid_rowconfigure(0, :weight=>1)
|
|
|
|
|
|
|
|
f.pack(:expand=>true, :fill=>:both)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Track focus demo:
|
|
|
|
#
|
|
|
|
$FocusInf = TkVariable.new_hash
|
|
|
|
$focus = nil
|
|
|
|
|
|
|
|
def trackFocus
|
|
|
|
if $focus
|
|
|
|
begin
|
|
|
|
$focus.destroy
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$focus = TkToplevel.new(:title=>'Keyboard focus')
|
|
|
|
i = 0
|
|
|
|
[
|
|
|
|
["Focus widget:", :Widget],
|
|
|
|
["Class:", :WidgetClass],
|
|
|
|
["Next:", :WidgetNext],
|
|
|
|
["Grab:", :Grab],
|
|
|
|
["Status:", :GrabStatus]
|
|
|
|
].each{|label, var_index|
|
2005-08-04 00:48:13 -04:00
|
|
|
Tk.grid(Tk::Tile::Label.new($focus, :text=>label, :anchor=>:e),
|
|
|
|
Tk::Tile::Label.new($focus,
|
2005-04-09 05:27:54 -04:00
|
|
|
:textvariable=>$FocusInf.ref(var_index),
|
|
|
|
:width=>40, :anchor=>:w, :relief=>:groove),
|
|
|
|
:sticky=>:ew)
|
|
|
|
i += 1
|
|
|
|
}
|
|
|
|
$focus.grid_columnconfigure(1, :weight=>1)
|
|
|
|
$focus.grid_rowconfigure(i, :weight=>1)
|
|
|
|
|
|
|
|
$focus.bind('Destroy', proc{Tk.after_cancel($Timers[:FocusMonitor])})
|
|
|
|
focusMonitor
|
|
|
|
end
|
|
|
|
|
|
|
|
def focusMonitor
|
|
|
|
$FocusInf[:Widget] = focus_win = Tk.focus
|
|
|
|
if focus_win
|
|
|
|
$FocusInf[:WidgetClass] = focus_win.winfo_classname
|
|
|
|
$FocusInf[:WidgetNext] = Tk.focus_next(focus_win)
|
|
|
|
else
|
|
|
|
$FocusInf[:WidgetClass] = $FocusInf[:WidgetNext] = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
$FocusInf[:Grab] = grab_wins = Tk.current_grabs
|
|
|
|
unless grab_wins.empty?
|
|
|
|
$FocusInf[:GrabStatus] = grab_wins[0].grab_status
|
|
|
|
else
|
|
|
|
$FocusInf[:GrabStatus] = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
$Timers[:FocusMonitor] = Tk.after(200, proc{ focusMonitor() })
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Widget state demo:
|
|
|
|
#
|
|
|
|
$Widget = TkVariable.new
|
|
|
|
|
|
|
|
TkBindTag::ALL.bind('Control-Shift-ButtonPress-1',
|
|
|
|
proc{|w|
|
|
|
|
$Widget.value = w
|
|
|
|
updateStates()
|
|
|
|
Tk.callback_break
|
|
|
|
}, '%W')
|
|
|
|
$states_list = %w(active disabled focus pressed selected
|
|
|
|
background indeterminate invalid default)
|
|
|
|
$states_btns = {}
|
|
|
|
$states = nil
|
|
|
|
|
|
|
|
$State = TkVariable.new_hash
|
|
|
|
|
|
|
|
def trackStates
|
|
|
|
if $states
|
|
|
|
begin
|
|
|
|
$state.destroy
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$states = TkToplevel.new(:title=>'Widget states')
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
l_inf = Tk::Tile::Label.new($states, :text=>"Press Control-Shift-Button-1 on any widget")
|
2005-04-09 05:27:54 -04:00
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
l_lw = Tk::Tile::Label.new($states, :text=>'Widget:',
|
2005-04-09 05:27:54 -04:00
|
|
|
:anchor=>:e, :relief=>:groove)
|
2005-08-04 00:48:13 -04:00
|
|
|
l_w = Tk::Tile::Label.new($states, :textvariable=>$Widget,
|
2005-04-09 05:27:54 -04:00
|
|
|
:anchor=>:w, :relief=>:groove)
|
|
|
|
|
|
|
|
Tk.grid(l_inf, '-', :sticky=>:ew, :padx=>6, :pady=>6)
|
|
|
|
Tk.grid(l_lw, l_w, :sticky=>:ew)
|
|
|
|
|
|
|
|
$states_list.each{|st|
|
2005-08-04 00:48:13 -04:00
|
|
|
cb = Tk::Tile::Checkbutton.new($states, :text=>st,
|
2005-04-09 05:27:54 -04:00
|
|
|
:variable=>$State.ref(st),
|
|
|
|
:command=>proc{ changeState(st) })
|
|
|
|
$states_btns[st] = cb
|
|
|
|
Tk.grid('x', cb, :sticky=>:nsew)
|
|
|
|
}
|
|
|
|
|
|
|
|
$states.grid_columnconfigure(1, :weight=>1)
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
f_cmd = Tk::Tile::Frame.new($states)
|
2005-04-09 05:27:54 -04:00
|
|
|
Tk.grid('x', f_cmd, :sticky=>:nse)
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
b_close = Tk::Tile::Button.new(f_cmd, :text=>'Close',
|
2005-04-09 05:27:54 -04:00
|
|
|
:command=>proc{ $states.destroy })
|
|
|
|
Tk.grid('x', b_close, :padx=>4, :pady=>[6,4])
|
|
|
|
f_cmd.grid_columnconfigure(0, :weight=>1)
|
|
|
|
|
|
|
|
$states.bind('KeyPress-Escape', proc{Tk.event_generate(b_close, '<Invoke>')})
|
|
|
|
|
|
|
|
$states.bind('Destroy', proc{Tk.after_cancel($Timers[:StateMonitor])})
|
|
|
|
stateMonitor()
|
|
|
|
end
|
|
|
|
|
|
|
|
def stateMonitor
|
|
|
|
updateStates() if $Widget.value != ''
|
|
|
|
$Timers[:StateMonitor] = Tk.after(200, proc{ stateMonitor() })
|
|
|
|
end
|
|
|
|
|
|
|
|
def updateStates
|
|
|
|
$states_list.each{|st|
|
|
|
|
begin
|
|
|
|
$State[st] = $Widget.window.instate(st)
|
|
|
|
rescue
|
|
|
|
$states_btns[st].state('disabled')
|
|
|
|
else
|
|
|
|
$states_btns[st].state('!disabled')
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def changeState(st)
|
|
|
|
if $Widget.value != ''
|
|
|
|
if $State.bool_element(st)
|
|
|
|
$Widget.window.state(st)
|
|
|
|
else
|
|
|
|
$Widget.window.state("!#{st}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-08-02 02:51:26 -04:00
|
|
|
#
|
|
|
|
# Repeating buttons demo:
|
|
|
|
#
|
|
|
|
def repeatDemo
|
|
|
|
if defined?($repeatDemo) && $repeatDemo.exist?
|
|
|
|
$repeatDemo.deiconify; return
|
|
|
|
end
|
|
|
|
$repeatDemo = TkToplevel.new(:title=>'Repeating button')
|
|
|
|
|
2005-08-04 00:48:13 -04:00
|
|
|
f = Tk::Tile::Frame.new($repeatDemo)
|
|
|
|
b = Tk::Tile::Button.new(f, :class=>'Repeater', :text=>'Press and hold')
|
2005-08-04 00:16:27 -04:00
|
|
|
if version?('0.6')
|
2005-08-04 00:48:13 -04:00
|
|
|
p = Tk::Tile::Progressbar.new(f, :orient=>:horizontal, :maximum=>10)
|
2005-08-04 00:16:27 -04:00
|
|
|
else # progressbar is not supported
|
2005-08-04 00:48:13 -04:00
|
|
|
p = Tk::Tile::Progress.new(f, :orient=>:horizontal, :from=>0, :to=>10)
|
2005-08-02 02:51:26 -04:00
|
|
|
def p.step
|
2005-08-02 07:49:46 -04:00
|
|
|
i = self.get + 1
|
|
|
|
i = self.from if i > self.to
|
|
|
|
self.set(i)
|
2005-08-02 02:51:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
b.command {p.step}
|
|
|
|
|
|
|
|
b.pack(:side=>:left, :expand=>false, :fill=>:none, :padx=>6, :pady=>6)
|
|
|
|
p.pack(:side=>:right, :expand=>true, :fill=>:x, :padx=>6, :pady=>6)
|
|
|
|
f.pack(:expand=>true, :fill=>:both)
|
|
|
|
end
|
|
|
|
|
2005-04-09 05:27:54 -04:00
|
|
|
Tk.mainloop
|