1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/tk/lib : bug fix

* ext/tk/lib/tkextlib/itcl : add [incr Tcl] support
* ext/tk/lib/tkextlib/itk  : add [incr Tk] support
* ext/tk/lib/tkextlib/iwidgets : midway point of [incr Widgets] support
* ext/tk/sample/tkextlib/iwidgets : very simple examples of [incr Widgets]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2004-07-08 16:50:07 +00:00
parent aa4878589c
commit afcfca607e
64 changed files with 2441 additions and 122 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

View file

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
# sample 1
p bb1 = Tk::Iwidgets::Buttonbox.new
p bb1.add('Yes', :text=>'Yes', :command=>proc{puts 'Yes'})
p bb1.add('No', :text=>'No', :command=>proc{puts 'No'})
p bb1.add('Maybe', :text=>'Maybe', :command=>proc{puts 'Maybe'})
bb1.default('Yes')
bb1.pack(:expand=>true, :fill=>:both, :pady=>5)
print "\n"
# sample 2
p bb2 = Tk::Iwidgets::Buttonbox.new
p btn1 = bb2.add(:text=>'Yes', :command=>proc{puts 'Yes'})
p btn2 = bb2.add(:text=>'No', :command=>proc{puts 'No'})
p btn3 = bb2.add(:text=>'Maybe', :command=>proc{puts 'Maybe'})
bb2.default(btn1)
bb2.pack(:expand=>true, :fill=>:both, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Calendar.new(:command=>proc{|arg| puts(arg.date)},
:weekendbackground=>'mistyrose',
:weekdaybackground=>'ghostwhite',
:outline=>'black', :startday=>'wednesday',
:days=>%w(We Th Fr Sa Su Mo Tu)).pack
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Canvasprintbox.new(:orient=>:landscape, :stretch=>1) \
.pack(:padx=>10, :pady=>10, :fill=>:both, :expand=>true)
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Canvasprintdialog.new.activate
Tk.mainloop

View file

@ -0,0 +1,12 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
cb = Tk::Iwidgets::Checkbox.new
cb.add('bold', :text=>'Bold')
cb.add('italic', :text=>'Italic')
cb.add('underline', :text=>'Underline')
cb.select('underline')
cb.pack(:expand=>true, :fill=>:both, :padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,32 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
#
# Non-editable Dropdown Combobox
#
cb1 = Tk::Iwidgets::Combobox.new(:labeltext=>'Month:',
:selectioncommand=>proc{
puts(cb1.get_curselection)
},
:editable=>false, :listheight=>185,
:popupcursor=>'hand1')
cb1.insert_list('end', *%w(Jan Feb Mar Apr May June Jul Aug Sept Oct Nov Dec))
#
# Editable Dropdown Combobox
#
cb2 = Tk::Iwidgets::Combobox.new(:labeltext=>'Operating System:',
:selectioncommand=>proc{
puts(cb2.get_curselection)
})
cb2.insert_list('end', *%w(Linux HP-UX SunOS Solaris Irix))
cb2.insert_entry('end', 'L')
cb1.pack(:padx=>10, :pady=>10, :fill=>:x)
cb2.pack(:padx=>10, :pady=>10, :fill=>:x)
Tk.mainloop

View file

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Dateentry.new.pack
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
df = Tk::Iwidgets::Datefield.new(:command=>proc{puts(df.get)})
df.pack(:fill=>:x, :expand=>true, :padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,20 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Thread.new{Tk.mainloop}
d = Tk::Iwidgets::Dialog.new(:modality=>:application)
d.buttonconfigure('OK', :command=>proc{puts 'OK'; d.deactivate true})
d.buttonconfigure('Apply', :command=>proc{puts 'Apply'})
d.buttonconfigure('Cancel', :command=>proc{puts 'Cancel'; d.deactivate false})
d.buttonconfigure('Help', :command=>proc{puts 'Help'})
TkListbox.new(d.child_site, :relief=>:sunken).pack(:expand=>true, :fill=>:both)
if TkComm.bool(d.activate)
puts "Exit via OK button"
else
puts "Exit via Cancel button"
end

View file

@ -0,0 +1,14 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
ds = Tk::Iwidgets::Dialogshell.new(:modality=>:none)
ds.add('OK', :text=>'OK', :command=>proc{puts 'OK'; ds.deactivate})
ds.add('Cancel', :text=>'Cancel', :command=>proc{puts 'Cancel'; ds.deactivate})
ds.default('OK')
TkButton.new(:text=>'ACTIVATE', :padx=>7, :pady=>7,
:command=>proc{puts ds.activate}).pack(:padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,16 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
djl = Tk::Iwidgets::Disjointlistbox.new.pack(:fill=>:both, :expand=>true,
:padx=>10, :pady=>10)
djl.set_lhs(*[0,2,4,5])
djl.set_rhs(3,6)
djl.insert_lhs(1,7,8)
djl.insert_rhs(9)
p djl.get_lhs
p djl.get_rhs
Tk.mainloop

View file

@ -0,0 +1,39 @@
#!/usr/bin/env ruby
#########################################################
#
# use Tk::UTF8_String() for a utf8 charecter
#
#########################################################
require 'tk'
require 'tkextlib/iwidgets'
TkOption.add('*textBackground', 'white')
ef = Tk::Iwidgets::Entryfield.new(:command=>proc{puts "Return Pressed"})
fef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Fixed:',
:fixed=>10, :width=>12)
nef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Numeric:',
:validate=>:numeric, :width=>12)
aef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Alphabetic:',
:validate=>:alphabetic, :width=>12,
:invalid=>proc{
puts "Alphabetic contents invalid"
})
pef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Password:', :width=>12,
:show=>Tk::UTF8_String("\267"),
## <=== utf8 character
:command=>proc{puts "Return Pressed"})
Tk::Iwidgets::Labeledwidget.alignlabels(ef, fef, nef, aef, pef)
ef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
fef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
nef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
aef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
pef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,40 @@
#!/usr/bin/env ruby
#########################################################
#
# set $KCODE to 'utf' for a utf8 charecter
#
#########################################################
$KCODE='utf'
require 'tk'
require 'tkextlib/iwidgets'
TkOption.add('*textBackground', 'white')
ef = Tk::Iwidgets::Entryfield.new(:command=>proc{puts "Return Pressed"})
fef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Fixed:',
:fixed=>10, :width=>12)
nef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Numeric:',
:validate=>:numeric, :width=>12)
aef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Alphabetic:',
:validate=>:alphabetic, :width=>12,
:invalid=>proc{
puts "Alphabetic contents invalid"
})
pef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Password:', :width=>12,
:show=>"\267", ## <=== utf8 character
:command=>proc{puts "Return Pressed"})
Tk::Iwidgets::Labeledwidget.alignlabels(ef, fef, nef, aef, pef)
ef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
fef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
nef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
aef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
pef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,40 @@
#!/usr/bin/env ruby
#########################################################
#
# set Tk.encoding = 'utf-8' for a utf8 charecter
#
#########################################################
require 'tk'
require 'tkextlib/iwidgets'
Tk.encoding = 'utf-8'
TkOption.add('*textBackground', 'white')
ef = Tk::Iwidgets::Entryfield.new(:command=>proc{puts "Return Pressed"})
fef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Fixed:',
:fixed=>10, :width=>12)
nef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Numeric:',
:validate=>:numeric, :width=>12)
aef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Alphabetic:',
:validate=>:alphabetic, :width=>12,
:invalid=>proc{
puts "Alphabetic contents invalid"
})
pef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Password:', :width=>12,
:show=>"\267", ## <=== utf8 character
:command=>proc{puts "Return Pressed"})
Tk::Iwidgets::Labeledwidget.alignlabels(ef, fef, nef, aef, pef)
ef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
fef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
nef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
aef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
pef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,20 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Extbutton.new(:text=>'Bitmap example', :bitmap=>'info',
:background=>'bisque', :activeforeground=>'red',
:bitmapforeground=>'blue', :defaultring=>true,
:command=>proc{
puts "Bisque is beautiful"
}).pack(:expand=>true)
#img = TkPhotoImage.new(:file=>File.join(File.dirname(File.expand_path(__FILE__)), '../../../images/earthris.gif'))
img = TkPhotoImage.new(:file=>File.join(File.dirname(File.expand_path(__FILE__)), '../catalog_demo/images/clear.gif'))
Tk::Iwidgets::Extbutton.new(:text=>'Image example', :relief=>:ridge,
:image=>img, :imagepos=>:e, :font=>'9x15bold',
:activebackground=>'lightyellow',
:background=>'lightgreen').pack(:expand=>true)
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Extfileselectionbox.new.pack(:padx=>10, :pady=>10,
:fill=>:both, :expand=>true)
Tk.mainloop

View file

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
mainloop = Thread.new{Tk.mainloop}
#
# Non-modal example
#
nmfsd = Tk::Iwidgets::Extfileselectiondialog.new(:title=>'Non-Modal')
nmfsd.buttonconfigure('OK', :command=>proc{
puts "You selected #{nmfsd.get}"
nmfsd.deactivate
})
nmfsd.activate
#
# Modal example
#
mfsd = Tk::Iwidgets::Extfileselectiondialog.new(:modality=>:application)
mfsd.center
if TkComm.bool(mfsd.activate)
puts "You selected #{mfsd.get}"
else
puts "You cancelled the dialog"
end
mainloop.join

View file

@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Feedback.new(:labeltext=>'Status', :steps=>20){|fb|
pack(:padx=>10, :pady=>10, :fill=>:both, :expand=>true)
TkTimer.new(500, 20, proc{fb.step}).start(5000)
}
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Fileselectionbox.new.pack(:padx=>10, :pady=>10,
:fill=>:both, :expand=>true)
Tk.mainloop

View file

@ -0,0 +1,28 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
mainloop = Thread.new{Tk.mainloop}
#
# Non-modal example
#
nmfsd = Tk::Iwidgets::Fileselectiondialog.new(:title=>'Non-Modal')
nmfsd.buttonconfigure('OK', :command=>proc{
puts "You selected #{nmfsd.get}"
nmfsd.deactivate
})
nmfsd.activate
#
# Modal example
#
mfsd = Tk::Iwidgets::Fileselectiondialog.new(:modality=>:application)
mfsd.center
if TkComm.bool(mfsd.activate)
puts "You selected #{mfsd.get}"
else
puts "You cancelled the dialog"
end
mainloop.join

View file

@ -0,0 +1,13 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
lw = Tk::Iwidgets::Labeledwidget.new(:labeltext=>'Canvas Widget',
:labelpos=>:s)
lw.pack(:fill=>:both, :expand=>true, :padx=>10, :pady=>10)
cw = TkCanvas.new(lw.child_site, :relief=>:raised, :width=>200, :height=>200,
:borderwidth=>3, :background=>:white)
cw.pack(:padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,17 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
sh = Tk::Iwidgets::Shell.new(:modality=>:application,
:padx=>20, :pady=>20, :title=>'Shell')
TkButton.new(:text=>'ACTIVATE', :padx=>7, :pady=>7,
:command=>proc{puts sh.activate}).pack(:padx=>10, :pady=>10)
TkLabel.new(sh.child_site, :text=>'SHELL').pack
TkButton.new(sh.child_site, :text=>'YES',
:command=>proc{sh.deactivate 'press YES'}).pack(:fill=>:x)
TkButton.new(sh.child_site, :text=>'NO',
:command=>proc{sh.deactivate 'press NO'}).pack(:fill=>:x)
Tk.mainloop