1# 2# manager demo --- called from demo.rb 3# 4unless Object.const_defined?('DemoVar') 5 fail RuntimeError, "This is NOT a stand alone script. This script is called from 'demo.rb'. " 6end 7 8module DemoManager 9 @@progress = TkVariable.new(false) 10 @@status = TkVariable.new('Compute in progress...') 11 @@homogeneous = TkVariable.new(false) 12 @@constw = TkVariable.new 13 @@afterobj = nil 14 15 def self.create(nb) 16 frame = nb.insert('end', 'demoManager', :text=>'Manager') 17 18 topf = TkFrame.new(frame) 19 titf1 = Tk::BWidget::TitleFrame.new(topf, :text=>"MainFrame") 20 titf2 = Tk::BWidget::TitleFrame.new(topf, :text=>"NoteBook") 21 titf3 = Tk::BWidget::TitleFrame.new(frame, :text=>"Paned & ScrolledWindow") 22 23 _mainframe(titf1.get_frame) 24 _notebook(titf2.get_frame) 25 _paned(titf3.get_frame) 26 27 Tk.pack(titf1, titf2, :padx=>4, :side=>:left, :fill=>:both, :expand=>true) 28 Tk.pack(topf, :fill=>:x, :pady=>2) 29 Tk.pack(titf3, :pady=>2, :padx=>4, :fill=>:both, :expand=>true) 30 31 frame 32 end 33 34 def self._mainframe(parent) 35 labf1 = Tk::BWidget::LabelFrame.new(parent, :text=>'Toolbar', 36 :side=>:top, :anchor=>:w, 37 :relief=>:sunken, :borderwidth=>2) 38 subf = labf1.get_frame 39 chk1 = TkCheckbutton.new(subf, :text=>'View toolbar 1', 40 :variable=>DemoVar.toolbar1, 41 :command=>proc{ 42 DemoVar.mainframe.show_toolbar( 43 0, DemoVar.toolbar1.value 44 ) 45 }) 46 chk2 = TkCheckbutton.new(subf, :text=>'View toolbar 2', 47 :variable=>DemoVar.toolbar2, 48 :command=>proc{ 49 DemoVar.mainframe.show_toolbar( 50 1, DemoVar.toolbar2.value 51 ) 52 }) 53 54 Tk.pack(chk1, chk2, :anchor=>:w, :fill=>:x) 55 labf1.pack(:fill=>:both) 56 57 labf2 = Tk::BWidget::LabelFrame.new(parent, :text=>'Status bar', 58 :side=>:top, :anchor=>:w, 59 :relief=>:sunken, :borderwidth=>2) 60 subf = labf2.get_frame 61 chk1 = TkCheckbutton.new(subf, :text=>"Show Progress\nindicator", 62 :justify=>:left, :variable=>@@progress, 63 :command=>proc{ _show_progress }) 64 chk1.pack(:anchor=>:w, :fill=>:x) 65 66 Tk.pack(labf1, labf2, :side=>:left, :padx=>4, :fill=>:both) 67 end 68 69 def self._notebook(parent) 70 TkCheckbutton.new(parent, :text=>'Homogeneous label', 71 :variable=>@@homogeneous, 72 :command=>proc{ 73 DemoVar.notebook[:homogeneous] = @@homogeneous.value 74 }).pack(:side=>:left, :anchor=>:n, :fill=>:x) 75 end 76 77 def self._paned(parent) 78 pw1 = Tk::BWidget::PanedWindow.new(parent, :side=>:top) 79 pane = pw1.add(:minsize=>100) 80 81 pw2 = Tk::BWidget::PanedWindow.new(pane, :side=>:left) 82 pane1 = pw2.add(:minsize=>100) 83 pane2 = pw2.add(:minsize=>100) 84 85 pane3 = pw1.add(:minsize=>100) 86 87 [pane1, pane2].each{|pane| 88 sw = Tk::BWidget::ScrolledWindow.new(pane) 89 lb = TkListbox.new(sw, :height=>8, :width=>20, :highlightthickness=>0) 90 (1..8).each{|i| lb.insert('end', "Valur #{i}") } 91 sw.set_widget(lb) 92 sw.pack(:fill=>:both, :expand=>true) 93 } 94 95 sw = Tk::BWidget::ScrolledWindow.new(pane3, :relief=>:sunken, 96 :borderwidth=>2) 97 sf = Tk::BWidget::ScrollableFrame.new(sw) 98 sw.set_widget(sf) 99 subf = sf.get_frame 100 lab = TkLabel.new(subf, :text=>'This is a ScrollableFrame') 101 chk = TkCheckbutton.new(subf, :text=>'Constrained with', 102 :variable=>@@constw, :command=>proc{ 103 sf['constrainedwidth'] = @@constw.value 104 }) 105 lab.pack 106 chk.pack(:anchor=>:w) 107 chk.bind('FocusIn', proc{sf.see(chk)}) 108 (0..20).each{|i| 109 ent = TkEntry.new(subf, :width=>50).pack(:fill=>:x, :pady=>4) 110 ent.bind('FocusIn', proc{sf.see(ent)}) 111 ent.insert('end', "Text field #{i}") 112 } 113 114 Tk.pack(sw, pw2, pw1, :fill=>:both, :expand=>true) 115 end 116 117 def self._show_progress 118 unless @@afterobj 119 @@afterobj = TkTimer.new(30, -1, proc{_update_progress}) 120 end 121 if @@progress.bool 122 DemoVar.status.value = 'Compute in progress...' 123 DemoVar.prgindic.value = 0 124 DemoVar.mainframe.show_statusbar(:progression) 125 @@afterobj.start unless @@afterobj.running? 126 else 127 DemoVar.status.value = '' 128 DemoVar.mainframe.show_statusbar(:status) 129 @@afterobj.stop 130 end 131 end 132 133 def self._update_progress 134 if @@progress.bool 135 if DemoVar.prgindic.numeric < 100 136 DemoVar.prgindic.numeric += 5 137 else 138 @@progress.value = false 139 DemoVar.mainframe.show_statusbar(:status) 140 DemoVar.status.value = 'Done' 141 @@afterobj.stop 142 Tk.after(500, proc{ DemoVar.status.value = '' }) 143 end 144 else 145 @@afterobj.stop 146 end 147 end 148 149end 150 151