Class: TKXXS_CLASSES::AskMultiLineD

Inherits:
TkText
  • 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) ⇒ AskMultiLineD

TODO: implement in TKXXS.



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/tkxxs/tkxxs_classes.rb', line 297

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

  # Must always include:  :question, :help
  hash = {
    :question => "?",
    :help => nil,
    :title => "Please enter your answer..."
  }.merge(hash)
  
  # Necessary, because hash[:configSection]  is deleted later on
  # in args_2.
  CONF.section = hash[:configSection] if CONF && hash[:configSection]

  # help, hash, question, title = 
  #   TKXXS_CLASSES.args_2( help, hash, question, :title)
  help, hash, question, title = 
    TKXXS_CLASSES.args_2( help, hash, question, :title)
  
  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('title')} 
  @dialog=Toplevel.new() {title(title)} 
  @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(:sticky=>'news')

  #---- self = TextW
  super(@frame, hash) 
  self.grid(:column=>0,:row=>1,:sticky=>'news')
  @tagSel = TkTextTagSel.new(self)
  bind('Control-Key-a') {
    # From:
    # "Using Control-a to select all text in a text widget : TCL",
    # http://objectmix.com/tcl/35276-using-control-select-all-text-text-widget.html
    @tagSel.add('0.0', :end)
    Kernel.raise TkCallbackBreak
  }
  ##/ bind('Key-Return') {
  ##/   ans_( self.get )
  ##/   self.dialog.destroy
  ##/   goOn.value = '1'
  ##/ }

  #----  Scrollbars
  sy = Scrollbar.new(@frame)
  sy.grid(:column=>1,:row=>1,:sticky=>'ns')
  self.yscrollbar(sy)
  
  sx = Scrollbar.new(@frame)
  sx.grid(:column=>0,:row=>2,:sticky=>'ew')
  self.xscrollbar(sx)
  
  #----  Button-Cancel 
  @btn = Button.new(@frame, :text=>"Cancel").
    grid(:row=>3,:column=>0,:sticky=>'w')
  @btn.command { 
    self.dialog.destroy 
  }
  
  #----  Button-OK 
  @btn2 = Button.new(@frame, :text=>"OK").
    grid(:row=>3,:column=>0,:sticky=>'e')
    ## grid(:row=>3,:column=>0,:sticky=>'e',:columnspan=>2)
  @btn2.command { 
    got = self.get('0.0', 'end -1c')
    ans_( got )
    self.dialog.destroy
    goOn.value = '1'
  }

  @frame.grid_columnconfigure(0, :weight=>1)
  @frame.grid_columnconfigure(1, :weight=>0)
  @frame.grid_rowconfigure([0,2,3], :weight=>0)
  @frame.grid_rowconfigure(1, :weight=>1)
  @lbl.bind('Configure'){ 
    @lbl.wraplength =  TkWinfo.width(@frame) - 40
  }

  #----  Balloonhelp
  BalloonHelp.new(self,:text => help) if help

  self.focus
  ##Tk.update
end

Instance Attribute Details

#dialogObject

in: “self.dialog



293
294
295
# File 'lib/tkxxs/tkxxs_classes.rb', line 293

def dialog
  @dialog
end

Instance Method Details

#answerObject

initialize



408
409
410
411
412
# File 'lib/tkxxs/tkxxs_classes.rb', line 408

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