Class: TKXXS_CLASSES::AskSingleLineD

Inherits:
Tk::Tile::Entry
  • Object
show all
Includes:
Tk::Tile
Defined in:
lib/tkxxs/tkxxs_classes.rb

Constant Summary collapse

CONF =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(question = nil, help = nil, hash = nil) ⇒ AskSingleLineD

See: TKXXS.ask_single_line



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/tkxxs/tkxxs_classes.rb', line 178

def initialize( question=nil, help=nil, hash=nil )
  question, help, hash = TKXXS_CLASSES.args_1(question, help, hash)

  # Must always include:  :question, :help
  hash = { # Default values
    :question => "?",
    :help => nil,
    :defaultEntry => '', 
  }.merge(hash)
  
  # Necessary, because hash[:configSection]  is deleted later on
  # with +args_2+.
  CONF.section = hash[:configSection] if CONF && hash[:configSection]

  help, hash, question, defaultEntry = 
    TKXXS_CLASSES.args_2(help,hash,question,:defaultEntry)
  
  teardownDone = false
  @ans = nil
  @goOn = goOn = TkVariable.new 
  # Because you cannot use instance-vars in procs. TODO: smarter way?

  Tk.update # Show any calling widget first to make it lower than @dialog 
  #----  Toplevel: @dialog
  @dialog=Toplevel.new() {title "Please enter your answer..."} 
  @dialog.geometry = CONF[:dialogGeom]  if CONF
  @dialog.raise
  @dialog.bind('Destroy') {
    unless teardownDone
      if CONF
        CONF[:dialogGeom] = @dialog.geometry
      end
      goOn.value = '1' # !
      teardownDone = true
    end
  }

  #----  Frame 
  @frame = Frame.new(@dialog) {padding "3 3 3 3"}.
    pack(:fill=>:both,:expand=>true)

  #----  Label 
  @lbl = Label.new(@frame, :text=>question){
    font $font if $font
    wraplength '5i'
    justify 'left'
  }
  @lbl.grid(:column=>0,:columnspan=>3,:sticky=>'ws')

  #---- self = TkEntry
  super(@frame, hash) 
  self.grid(:column=>0,:columnspan=>3,:sticky=>'ew')
  self.insert(0, defaultEntry)
  bind('Key-Return') {
    ans_( self.get )
    self.dialog.destroy
    goOn.value = '1'
  }

  #----  Button-Cancel 
  @btn = Button.new(@frame, :text=>"Cancel").
    grid(:column=>0,:row=>2)
  @btn.command { 
    self.dialog.destroy 
  }

  #----  Button-OK 
  @btn2 = Button.new(@frame, :text=>"OK").
    grid(:column=>2,:row=>2)
  @btn2.command { 
    ans_( self.get )
    self.dialog.destroy
    goOn.value = '1'
  }

  #----  Balloonhelp
  if help
    BalloonHelp.new(self, :text => help )
  end
  
  @frame.grid_columnconfigure([0,2],:weight=>0)
  @frame.grid_columnconfigure(1,:weight=>1)
  @frame.grid_rowconfigure(0,:weight=>1)
  @frame.grid_rowconfigure([1,2],:weight=>0)

  focus
  update
end

Instance Attribute Details

#dialogObject

in: “self.dialog



174
175
176
# File 'lib/tkxxs/tkxxs_classes.rb', line 174

def dialog
  @dialog
end

Instance Method Details

#answerObject

Returns: (String or nil) The answer of the dialog. ‘Cancel’ returns nil.



269
270
271
272
273
# File 'lib/tkxxs/tkxxs_classes.rb', line 269

def answer(  )
  @dialog.raise
  @goOn.wait
  @ans
end