Class: BWidget_Demo

Inherits:
Object show all
Defined in:
sample/tkextlib/bwidget/demo.rb

Constant Summary collapse

DEMODIR =
File.dirname(File.expand_path(__FILE__))

Instance Method Summary collapse

Constructor Details

#initializeBWidget_Demo

Returns a new instance of BWidget_Demo.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'sample/tkextlib/bwidget/demo.rb', line 30

def initialize
  TkOption.add('*TitleFrame.l.font', 'helvetica 11 bold italic')

  root = TkRoot.new(:title=>'BWidget demo')
  root.withdraw

  _create

  Tk::BWidget.place(root, 0, 0, :center)
  root.deiconify
  root.raise
  root.focus(true)

  root.geometry(root.geometry)
end

Instance Method Details

#_createObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'sample/tkextlib/bwidget/demo.rb', line 46

def _create
  DemoVar.prgtext.value = 'Please wait while loading font...'
  DemoVar.prgindic.value = -1

  intro = _create_intro

  Tk.update

  Tk::BWidget::SelectFont.load_font

  descmenu = [
    '&File', 'all', 'file', 0, [
      ['command', 'E&xit', [], 'Exit BWidget demo', [],
        {:command=>proc{exit}}]
    ],
    '&Options', 'all', 'options', 0, [
      ['checkbutton', 'Toolbar &1', ['all', 'option'],
        'Show/hide toolbar 1', [],
        { :variable=>DemoVar.toolbar1,
          :command=>proc{
            DemoVar.mainframe.show_toolbar(0, DemoVar.toolbar1.value)
          }
        }
      ],
      ['checkbutton', 'Toolbar &2', ['all', 'option'],
        'Show/hide toolbar 2', [],
        { :variable=>DemoVar.toolbar2,
          :command=>proc{
            DemoVar.mainframe.show_toolbar(1, DemoVar.toolbar2.value)
          }
        }
      ]
    ]
  ]

  DemoVar.prgtext.value = 'Creating MainFrame...'
  DemoVar.prgindic.value = 0

  DemoVar.mainframe = Tk::BWidget::MainFrame.new(
                              :menu=>descmenu,
                              :textvariable=>DemoVar.status,
                              :progressvar=>DemoVar.prgindic
                      )

  # toobar 1 creation
  DemoVar.prgindic.numeric += 1

  DemoVar.mainframe.add_toolbar{|tb1|
    Tk::BWidget::ButtonBox.new(tb1, :spacing=>0, :padx=>1, :pady=>1){|bbox|
      add(:image=>Tk::BWidget::Bitmap.new('new'),
          :highlightthickness=>0, :takefocus=>0, :relief=>:link,
          :borderwidth=>1, :padx=>1, :pady=>1,
          :command=>proc{puts 'select "Create a new file" icon'},
          :helptext=>"Create a new file")

      add(:image=>Tk::BWidget::Bitmap.new('open'),
          :highlightthickness=>0, :takefocus=>0, :relief=>:link,
          :borderwidth=>1, :padx=>1, :pady=>1,
          :command=>proc{puts 'select "Open an existing file" icon'},
          :helptext=>"Open an existing file")

      add(:image=>Tk::BWidget::Bitmap.new('save'),
          :highlightthickness=>0, :takefocus=>0, :relief=>:link,
          :borderwidth=>1, :padx=>1, :pady=>1,
          :command=>proc{puts 'select "Save file" icon'},
          :helptext=>"Save file")

      pack(:side=>:left, :anchor=>:w)
    }

    Tk::BWidget::Separator.new(tb1, :orient=>:vertical){
      pack(:side=>:left, :fill=>:y, :padx=>4, :anchor=>:w)
    }

    DemoVar.prgindic.numeric += 1

    Tk::BWidget::ButtonBox.new(tb1, :spacing=>0, :padx=>1, :pady=>1){|bbox|
      add(:image=>Tk::BWidget::Bitmap.new('cut'),
          :highlightthickness=>0, :takefocus=>0, :relief=>:link,
          :borderwidth=>1, :padx=>1, :pady=>1,
          :command=>proc{puts 'select "Cut selection" icon'},
          :helptext=>"Cut selection")

      add(:image=>Tk::BWidget::Bitmap.new('copy'),
          :highlightthickness=>0, :takefocus=>0, :relief=>:link,
          :borderwidth=>1, :padx=>1, :pady=>1,
          :command=>proc{puts 'select "Copy selection" icon'},
          :helptext=>"Copy selection")

      add(:image=>Tk::BWidget::Bitmap.new('paste'),
          :highlightthickness=>0, :takefocus=>0, :relief=>:link,
          :borderwidth=>1, :padx=>1, :pady=>1,
          :command=>proc{puts 'select "Paste selection" icon'},
          :helptext=>"Paste selection")

      pack(:side=>:left, :anchor=>:w)
    }
  }

  # toolbar 2 creation
  DemoVar.prgindic.numeric += 1

  tb2 = DemoVar.mainframe.add_toolbar
  DemoVar._wfont = Tk::BWidget::SelectFont::Toolbar.new(tb2,
                     :command=>proc{update_font(DemoVar._wfont[:font])}
                   )
  DemoVar.font = DemoVar._wfont[:font]
  DemoVar._wfont.pack(:side=>:left, :anchor=>:w)

  DemoVar.mainframe.add_indicator(
    :text=>"BWidget #{Tk::BWidget.package_version}"
  )
  DemoVar.mainframe.add_indicator(:textvariable=>'tk_patchLevel')

  # NoteBook creation
  DemoVar.notebook = Tk::BWidget::NoteBook.new(DemoVar.mainframe.get_frame)

  DemoVar.prgtext.value = "Creating Manager..."
  DemoVar.prgindic.numeric += 1
  DemoManager.create(DemoVar.notebook)

  DemoVar.prgtext.value = "Creating Basic..."
  DemoVar.prgindic.numeric += 1
  DemoBasic.create(DemoVar.notebook)

  DemoVar.prgtext.value = "Creating Select..."
  DemoVar.prgindic.numeric += 1
  DemoSelect.create(DemoVar.notebook)

  DemoVar.prgtext.value = "Creating Dialog..."
  DemoVar.prgindic.numeric += 1
  DemoDialog.create(DemoVar.notebook)

  DemoVar.prgtext.value = "Creating Drag and Drop..."
  DemoVar.prgindic.numeric += 1
  DemoDnD.create(DemoVar.notebook)

  DemoVar.prgtext.value = "Creating Tree..."
  DemoVar.prgindic.numeric += 1
  DemoTree.create(DemoVar.notebook)

  DemoVar.prgtext.value = "Done"
  DemoVar.prgindic.numeric += 1

  DemoVar.notebook.compute_size
  DemoVar.notebook.pack(:fill=>:both, :expand=>true, :padx=>4, :pady=>4)
  DemoVar.notebook.raise(DemoVar.notebook.get_page(0))

  DemoVar.mainframe.pack(:fill=>:both, :expand=>true)

  Tk.update_idletasks

  intro.destroy
end

#_create_introObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'sample/tkextlib/bwidget/demo.rb', line 212

def _create_intro
  top = TkToplevel.new(:relief=>:raised, :borderwidth=>2)
  top.withdraw
  top.overrideredirect(true)

  ximg  = TkLabel.new(top, :bitmap=>"@#{File.join(DEMODIR,'x1.xbm')}",
                      :foreground=>'grey90', :background=>'white')
  bwimg = TkLabel.new(ximg, :bitmap=>"@#{File.join(DEMODIR,'bwidget.xbm')}",
                      :foreground=>'grey90', :background=>'white')
  frame = TkFrame.new(ximg, :background=>'white')
  TkLabel.new(frame, :text=>'Loading demo',
              :background=>'white', :font=>'times 8').pack
  TkLabel.new(frame, :textvariable=>DemoVar.prgtext,
              :background=>'white', :font=>'times 8', :width=>35).pack
  Tk::BWidget::ProgressBar.new(frame, :width=>50, :height=>10,
                               :background=>'white',
                               :variable=>DemoVar.prgindic,
                               :maximum=>10).pack
  frame.place(:x=>0, :y=>0, :anchor=>:nw)
  bwimg.place(:relx=>1, :rely=>1, :anchor=>:se)
  ximg.pack
  Tk::BWidget.place(top, 0, 0, :center)
  top.deiconify

  top
end

#update_font(newfont) ⇒ Object



201
202
203
204
205
206
207
208
209
210
# File 'sample/tkextlib/bwidget/demo.rb', line 201

def update_font(newfont)
  root = Tk.root
  root[:cursor] = 'watch'
  if newfont != '' && DemoVar.font != newfont
    DemoVar._wfont[:font] = newfont
    DemoVar.notebook[:font] = newfont
    DemoVar.font = newfont
  end
  root[:cursor] = ''
end