1# -*- coding: utf-8 -*- 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 9if defined?($combo_demo) && $combo_demo 10 $combo_demo.destroy 11 $combo_demo = nil 12end 13 14$combo_demo = TkToplevel.new {|w| 15 title("Combobox Demonstration") 16 iconname("combo") 17 positionWindow(w) 18} 19 20base_frame = TkFrame.new($combo_demo).pack(:fill=>:both, :expand=>true) 21 22Ttk::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������������������������������������������������\ 312������������������������������������������������������������������������������������������������������\ 323���������������������������������������������������������������������������������������\ 33��������������������������������������������������������� 34EOL 35 36## variables 37firstValue = TkVariable.new 38secondValue = TkVariable.new 39ozCity = TkVariable.new 40 41## See Code / Dismiss buttons 42Ttk::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 68frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) 69 70australianCities = [ 71 'キャンベラ', 'シドニー', 'メルボルン', 'パース', 'アデレード', 72 'ブリスベーン', 'ホバート', 'ダーウィン', 'アリス スプリングス' 73] 74 75 76secondValue.value = '変更不可' 77ozCity.value = 'シドニー' 78 79Tk.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) 99