diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-09 19:29:29 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-09 19:29:29 +0000 |
commit | e55330c9c415f673ca5565a9dbd0b84775d53419 (patch) | |
tree | ab1c6145288ce3d209e605fe3dbc10c66f487f2f /ext/tk/sample | |
parent | 29c3cb6d2061d2d476ef50066b44a5596dd51d99 (diff) | |
download | ruby-e55330c9c415f673ca5565a9dbd0b84775d53419.tar.gz |
* ext/tk/lib/tk.rb: better operation for SIGINT when processing callbacks.
* ext/tk/lib/tk/msgcat.rb: ditto.
* ext/tk/lib/tk/variable.rb: ditto.
* ext/tk/lib/tk/timer.rb: ditto.
* ext/tk/lib/tk/validation.rb: add Tk::ValidateConfigure.__def_validcmd()
to define validatecommand methods easier
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
9 files changed, 167 insertions, 0 deletions
diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/hierarchy.rb b/ext/tk/sample/tkextlib/iwidgets/sample/hierarchy.rb new file mode 100644 index 0000000000..594158294e --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/hierarchy.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +def get_files(file) + dir = (file.empty?)? ENV['HOME'] : file + Dir.chdir(dir) rescue return '' + rlist = [] + Dir['*'].sort.each{|f| rlist << File.join(dir, f) } + rlist +end + +Tk::Iwidgets::Hierarchy.new(:querycommand=>proc{|arg| get_files(arg.node)}, + :visibleitems=>'30x15', + :labeltext=>ENV['HOME']).pack(:side=>:left, + :expand=>true, + :fill=>:both) + +# Tk::Iwidgets::Hierarchy.new(:querycommand=>[proc{|n| get_files(n)}, '%n'], +# :visibleitems=>'30x15', +# :labeltext=>ENV['HOME']).pack(:side=>:left, +# :expand=>true, +# :fill=>:both) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/hyperhelp.rb b/ext/tk/sample/tkextlib/iwidgets/sample/hyperhelp.rb new file mode 100644 index 0000000000..f9c92bf6dc --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/hyperhelp.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mainloop = Thread.new{Tk.mainloop} + +dir = '/usr/local/ActiveTcl/demos/IWidgets/html/' +href = [ 'hyperhelp.n', 'buttonbox.n', 'calendar.n' ] + +hh = Tk::Iwidgets::Hyperhelp.new(:topics=>href, :helpdir=>dir) +hh.show_topic('hyperhelp.n') +hh.activate + +mainloop.join diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/messagebox1.rb b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox1.rb new file mode 100644 index 0000000000..3f7b137b19 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox1.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mb = Tk::Iwidgets::Messagebox.new(:hscrollmode=>:dynamic, + :labeltext=>'Messages', :labelpos=>:n, + :height=>120, :width=>550, + :savedir=>'/tmp', :textbackground=>'#d9d9d9') +mb.pack(:padx=>5, :pady=>5, :fill=>:both, :expand=>true) + +mb.type_add('ERROR', :background=>'red', :foreground=>'white', :bell=>true) +mb.type_add('WARNING', :background=>'yellow', :foreground=>'black') +mb.type_add('INFO', :background=>'white', :foreground=>'black') + +mb.issue('This is an error message in red with a beep', 'ERROR') +mb.issue('This warning message in yellow', 'WARNING') +mb.issue('This is an informational message', 'INFO') + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/messagebox2.rb b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox2.rb new file mode 100644 index 0000000000..1aae7587e4 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox2.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mb = Tk::Iwidgets::Messagebox.new(:hscrollmode=>:dynamic, + :labeltext=>'Messages', :labelpos=>:n, + :height=>120, :width=>550, + :savedir=>'/tmp', :textbackground=>'#d9d9d9') +mb.pack(:padx=>5, :pady=>5, :fill=>:both, :expand=>true) + +error = mb.type_add(:background=>'red', :foreground=>'white', :bell=>true) +warning = mb.type_add(:background=>'yellow', :foreground=>'black') +info = mb.type_add(:background=>'white', :foreground=>'black') + +mb.issue('This is an error message in red with a beep', error) +mb.issue('This warning message in yellow', warning) +mb.issue('This is an informational message', info) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/messagedialog.rb b/ext/tk/sample/tkextlib/iwidgets/sample/messagedialog.rb new file mode 100644 index 0000000000..8cf373f964 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/messagedialog.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mainloop = Thread.new{Tk.mainloop} + +# +# Standard question message dialog used for confirmation. +# +md = Tk::Iwidgets::Messagedialog.new(:title=>'Message Dialog', + :text=>'Are you sure ? ', + :bitmap=>'questhead', :modality=>:global) + +md.buttonconfigure('OK', :text=>'Yes') +md.buttonconfigure('Cancel', :text=>'No') + +if TkComm.bool(md.activate) + md.text('Are you really sure ? ') + if TkComm.bool(md.activate) + puts 'Yes' + else + puts 'No' + end +else + puts 'No' +end + +md.destroy + +# +# Copyright notice with automatic deactivation. +# +bmp = '@' + File.join(File.dirname(File.expand_path(__FILE__)), '../catalog_demo/images/text.xbm') + +cr = Tk::Iwidgets::Messagedialog.new(:title=>'Copyright', + :bitmap=>bmp, :imagepos=>:n, + :text=>"Copyright 200x XXX Corporation\nAll rights reserved") + +cr.hide('Cancel') + +cr.activate +Tk.after(7000, proc{cr.deactivate; Tk.root.destroy}) + +mainloop.join diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb b/ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb new file mode 100644 index 0000000000..9cd6a002b0 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +rb = Tk::Iwidgets::Radiobox.new(:labeltext=>'Fonts') +rb.add('times', :text=>'Times') +rb.add('helvetica', :text=>'Helvetica') +rb.add('courier', :text=>'Courier') +rb.add('symbol', :text=>'Symbol') +rb.select('courier') +rb.pack(:expand=>true, :fill=>:both, :padx=>10, :pady=>10) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/timeentry.rb b/ext/tk/sample/tkextlib/iwidgets/sample/timeentry.rb new file mode 100644 index 0000000000..465939947b --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/timeentry.rb @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +Tk::Iwidgets::Timeentry.new.pack + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/timefield.rb b/ext/tk/sample/tkextlib/iwidgets/sample/timefield.rb new file mode 100644 index 0000000000..bb5945048d --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/timefield.rb @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +tf = Tk::Iwidgets::Timefield.new(:command=>proc{puts(tf.get)}) +tf.pack(:fill=>:x, :expand=>true, :padx=>10, :pady=>10) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/watch.rb b/ext/tk/sample/tkextlib/iwidgets/sample/watch.rb new file mode 100644 index 0000000000..d2b6246bf3 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/watch.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +Thread.new{ + trap('INT') {puts 'catch SIGINT'} + sleep 5 + trap('INT', 'DEFAULT') +} + +Tk::Iwidgets::Watch.new(:state=>:disabled, :showampm=>:no, + :width=>155, :height=>155){|w| + w.pack(:padx=>10, :pady=>10, :fill=>:both, :expand=>true) + # TkTimer.new(1000, -1, proc{w.show; Tk.update}).start + TkTimer.new(25, -1, proc{w.show; Tk.update}).start +} + +Tk.mainloop |