OSDN Git Service

da00d712bacb67a437ccca05b0e1a39ecec4da07
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / ext / tk / sample / demos-jp / combo.rb
1 # -*- coding: euc-jp -*-
2 #
3 # combo.rb --
4 #
5 # This demonstration script creates several combobox widgets.
6 #
7 # based on "Id: combo.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
8
9 if defined?($combo_demo) && $combo_demo
10   $combo_demo.destroy 
11   $combo_demo = nil
12 end
13
14 $combo_demo = TkToplevel.new {|w|
15   title("Combobox Demonstration")
16   iconname("combo")
17   positionWindow(w)
18 }
19
20 base_frame = TkFrame.new($combo_demo).pack(:fill=>:both, :expand=>true)
21
22 Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left, 
23                :text=><<EOL).pack(:side=>:top, :fill=>:x)
24 °Ê²¼¤Ç¤Ï3¼ïÎà¤Î¥³¥ó¥Ü¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥\
25 ºÇ½é¤Î¤â¤Î¤Ï¡¤¥¨¥ó¥È¥ê¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸Íͤˡ¤\
26 ¥Ý¥¤¥ó¥È¤·¤¿¤ê¡¤¥¯¥ê¥Ã¥¯¤·¤¿¤ê¡¤¥¿¥¤¥×¤·¤¿¤ê¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥\
27 ¤Þ¤¿¡¤Return¥­¡¼¤òÆþÎϤ¹¤ì¤Ð¸½ºß¤ÎÃͤ¬¥ê¥¹¥È¤ËÄɲ䵤졤\
28 ¥É¥í¥Ã¥×¥À¥¦¥ó¥ê¥¹¥È¤«¤éÁªÂò¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥\
29 ¢­(²¼¸þ¤­Ìð°õ)¥­¡¼¤ò²¡¤·¤Æɽ¼¨¤µ¤ì¤¿¥ê¥¹¥È¤«¤é\
30 Ìð°õ¥­¡¼¤Ç¾¤Î¸õÊä¤òÁª¤ó¤ÇReturn¥­¡¼¤ò²¡¤»¤Ð¡¤ÃͤòÁªÂò¤Ç¤­¤Þ¤¹¡¥\
31 2ÈÖÌܤΥ³¥ó¥Ü¥Ü¥Ã¥¯¥¹¤ÏÆÃÄê¤ÎÃͤ˸ÇÄꤵ¤ì¤Æ¤ª¤ê¡¤°ìÀÚÊѹ¹¤Ç¤­¤Þ¤»¤ó¡¥\
32 3ÈÖÌܤΤâ¤Î¤Ï¥ª¡¼¥¹¥È¥é¥ê¥¢¤ÎÅԻԤΥɥí¥Ã¥×¥À¥¦¥ó¥ê¥¹¥È¤«¤é\
33 ÁªÂò¤¹¤ë¤³¤È¤À¤±¤¬²Äǽ¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥
34 EOL
35
36 ## variables
37 firstValue  = TkVariable.new
38 secondValue = TkVariable.new
39 ozCity      = TkVariable.new
40
41 ## See Code / Dismiss buttons
42 Ttk::Frame.new(base_frame) {|frame|
43   sep = Ttk::Separator.new(frame)
44   Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
45   TkGrid('x', 
46          Ttk::Button.new(frame, :text=>'ÊÑ¿ô»²¾È', 
47                          :image=>$image['view'], :compound=>:left, 
48                          :command=>proc{
49                            showVars(base_frame, 
50                                     ['firstVariable', firstValue], 
51                                     ['secondVariable', secondValue], 
52                                     ['ozCity', ozCity])
53                          }), 
54          Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', 
55                          :image=>$image['view'], :compound=>:left, 
56                          :command=>proc{showCode 'combo'}), 
57          Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', 
58                          :image=>$image['delete'], :compound=>:left, 
59                          :command=>proc{
60                            $combo_demo.destroy
61                            $combo_demo = nil
62                          }), 
63          :padx=>4, :pady=>4)
64   grid_columnconfigure(0, :weight=>1)
65   pack(:side=>:bottom, :fill=>:x)
66 }
67
68 frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
69
70 australianCities = [
71   '¥­¥ã¥ó¥Ù¥é', '¥·¥É¥Ë¡¼', '¥á¥ë¥Ü¥ë¥ó', '¥Ñ¡¼¥¹', '¥¢¥Ç¥ì¡¼¥É', 
72   '¥Ö¥ê¥¹¥Ù¡¼¥ó', '¥Û¥Ð¡¼¥È', '¥À¡¼¥¦¥£¥ó', '¥¢¥ê¥¹ ¥¹¥×¥ê¥ó¥°¥¹'
73 ]
74
75
76 secondValue.value = 'Êѹ¹ÉÔ²Ä'
77 ozCity.value = '¥·¥É¥Ë¡¼'
78
79 Tk.pack(Ttk::Labelframe.new(frame, :text=>'Fully Editable'){|f|
80           Ttk::Combobox.new(f, :textvariable=>firstValue){|b|
81             b.bind('Return', '%W'){|w|
82               w.values <<= w.value unless w.values.include?(w.value)
83             }
84           }.pack(:pady=>5, :padx=>10)
85         }, 
86
87         Ttk::LabelFrame.new(frame, :text=>'Disabled'){|f|
88           Ttk::Combobox.new(f, :textvariable=>secondValue, :state=>:disabled) .
89             pack(:pady=>5, :padx=>10)
90         }, 
91
92         Ttk::LabelFrame.new(frame, :text=>'Defined List Only'){|f|
93           Ttk::Combobox.new(f, :textvariable=>ozCity, :state=>:readonly, 
94                             :values=>australianCities) .
95             pack(:pady=>5, :padx=>10)
96         }, 
97
98         :side=>:top, :pady=>5, :padx=>10)