1# -*- coding: utf-8 -*- 2# 3# spin.rb -- 4# 5# This demonstration script creates several spinbox widgets. 6# 7# based on Tcl/Tk8.4.4 widget demos 8 9if defined?($spin_demo) && $spin_demo 10 $spin_demo.destroy 11 $spin_demo = nil 12end 13 14$spin_demo = TkToplevel.new {|w| 15 title("Spinbox Demonstration") 16 iconname("spin") 17 positionWindow(w) 18} 19 20base_frame = TkFrame.new($spin_demo).pack(:fill=>:both, :expand=>true) 21 22TkLabel.new(base_frame, 23 :font=>$font, :wraplength=>'5i', :justify=>:left, 24 :text=><<EOL).pack(:side=>:top) 25������������������������������������������������������������������������ 26������������������������������������������������������������������������������������ 27���������������������������Emacs ������������������������������������������ 28Motif ������������������������������������������������������������������������ 29Backspace ��� Control-h ��������������������������������������������� 30������������Delete ��� Control-d ������������������������������������������ 31������������������������������������������������������������������������������������ 32��������������������������������������������������������������������������������� 33��������������������������������������������� 34��������������������������������������������������������������������������������� 35������������������������������������������������������������������������������������ 36��������������������������������������������������������������������������������� 37������������������������������������������������������ 38��������������������������������� Ruby ��������������������������� Tk ������ 39������������ spinbox ��������������������������������������������������������� 40��������������������������������������������������������������� spinbox ������ 41������������������������������������������������������������������������������ Tk 42��������������������������������������������������������� 43EOL 44 45TkFrame.new(base_frame){|f| 46 pack(:side=>:bottom, :fill=>:x, :pady=>'2m') 47 48 TkButton.new(f, :text=>'閉じる', :width=>15, :command=>proc{ 49 $spin_demo.destroy 50 $spin_demo = nil 51 }).pack(:side=>:left, :expand=>true) 52 53 TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ 54 showCode 'spin' 55 }).pack(:side=>:left, :expand=>true) 56} 57 58australianCities = [ 59 'Canberra', 'Sydney', 'Melbourne', 'Perth', 'Adelaide', 60 'Brisbane', 'Hobart', 'Darwin', 'Alice Springs' 61] 62 63[ 64 TkSpinbox.new(base_frame, :from=>1, :to=>10, :width=>10, :validate=>:key, 65 :validatecommand=>[ 66 proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P' 67 ]), 68 TkSpinbox.new(base_frame, :from=>0, :to=>3, :increment=>0.5, 69 :format=>'%05.2f', :width=>10), 70 TkSpinbox.new(base_frame, :values=>australianCities, :width=>10) 71].each{|sbox| sbox.pack(:side=>:top, :pady=>5, :padx=>10)} 72