Class: ArcadiaDialogManager

Inherits:
Object
  • Object
show all
Defined in:
lib/a-core.rb

Defined Under Namespace

Classes: DialogParams

Instance Method Summary collapse

Constructor Details

#initialize(_arcadia) ⇒ ArcadiaDialogManager

Returns a new instance of ArcadiaDialogManager.



2423
2424
2425
2426
# File 'lib/a-core.rb', line 2423

def initialize(_arcadia)
  @arcadia = _arcadia
  Arcadia.attach_listener(self, DialogEvent)
end

Instance Method Details

#dialog_params(_event, check_type = true) ⇒ Object



2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
# File 'lib/a-core.rb', line 2428

def dialog_params(_event, check_type = true)
  ret = DialogParams.new
  if _event
    ret.type = _event.type
    if check_type && !_event.class::TYPE_PATTERNS.include?(_event.type)
      ret.type = 'ok'
    end
    ret.res_array = ret.type.split('_')
    if _event.level.nil? || _event.level.length == 0
      ret.level = 'info'
    else
      ret.level = _event.level
    end
    if _event.msg && _event.msg.length > _event.class::MSG_MAX_CHARS
      ret.msg = _event.msg[0.._event.class::MSG_MAX_CHARS]+' ...'
    else
      ret.msg = _event.msg
    end
  end
  ret
end

#do_hinner_dialog(_event) ⇒ Object



2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
# File 'lib/a-core.rb', line 2481

def do_hinner_dialog(_event)
  par = dialog_params(_event, false)
  dialog_frame = TkFrame.new(Arcadia.layout.base_frame, Arcadia.style('panel')){
    #relief 'solid'
    #borderwidth 3
    highlightbackground Arcadia.conf('hightlight.link.foreground')
    #highlightcolor 'red'
    highlightthickness 1
  }
  dialog_frame.pack('side' =>'top','after'=>Arcadia.layout.root, 'anchor'=>'nw','fill'=>'x', 'padx'=>0, 'pady'=>0)
  max_width = 0
  par.res_array.each{|v| 
    l = v.length
    max_width = l if l > max_width
  }
  res = nil
  par.res_array.reverse_each{|value|
    Tk::BWidget::Button.new(dialog_frame, Arcadia.style('button')){
      command proc{res = value}
      text value.capitalize
      helptext  value.capitalize
      width max_width*2
    }.pack('side' =>'right','padx'=>5, 'pady'=>5)
  }

  Tk::BWidget::Label.new(dialog_frame,Arcadia.style('label')){
    text  par.msg
    helptext _event.msg
#    }.pack('fill'=>'x','side' =>'left')
  }.pack('side' =>'right','padx'=>5, 'pady'=>5)

#    Tk::BWidget::Label.new(dialog_frame,Arcadia.style('label')){
#      compound 'left'
#      Tk::Anigif.image(self, "#{Dir.pwd}/ext/ae-subprocess-inspector/process.res")
#    }.pack('side' =>'right','padx'=>10)

  
  Tk.update
  dialog_frame.grab("set")
  begin
    while res == nil do 
      Tk.update
      sleep(0.1) 
    end
  ensure
    dialog_frame.grab("release")
  end
  dialog_frame.destroy
  Tk.update
  _event.add_result(self, 'value'=>res)
end

#do_system_dialog(_event) ⇒ Object



2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
# File 'lib/a-core.rb', line 2459

def do_system_dialog(_event)
  par = dialog_params(_event)
  tktype = par.type.gsub('_','').downcase
  tkdialog =  Tk::BWidget::MessageDlg.new(
    'icon' => par.level,
    'bg' => Arcadia.conf('background'),
    'fg' => Arcadia.conf('foreground'),
    'type' => tktype,
    'title' => _event.title,
  'message' => par.msg)
  tkdialog.configure('font'=>'courier 6')
  res = tkdialog.create
  if _event.level == 'error'
    if _event.exception != nil
      Arcadia.runtime_error(_event.exception, _event.title)
    else
      Arcadia.runtime_error_msg(_event.msg, _event.title)
    end
  end
  _event.add_result(self, 'value'=>par.res_array[res.to_i])
end

#on_dialog(_event) ⇒ Object



2450
2451
2452
2453
2454
2455
2456
2457
# File 'lib/a-core.rb', line 2450

def on_dialog(_event)
  case _event
    when SystemDialogEvent
      do_system_dialog(_event)
    when HinnerDialogEvent
      do_hinner_dialog(_event)
  end
end

#on_dialog_old(_event) ⇒ Object



2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
# File 'lib/a-core.rb', line 2533

def on_dialog_old(_event)
  type = _event.type
  if !DialogEvent::TYPE_PATTERNS.include?(_event.type)
    type = 'ok'
  end
  icon = _event.level
  tktype = type.gsub('_','').downcase

  res =  Tk.messageBox(
  'icon' => icon,
  'type' => tktype,
  'title' => _event.title,
  'message' => _event.msg)
  _event.add_result(self, 'value'=>res)
end