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.



2924
2925
2926
2927
# File 'lib/a-core.rb', line 2924

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

Instance Method Details

#dialog_params(_event, check_type = true) ⇒ Object



2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
# File 'lib/a-core.rb', line 2929

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
    if _event.title && _event.title.length > _event.class::TITLE_MAX_CHARS
      ret.title = _event.title[0.._event.class::TITLE_MAX_CHARS]+' ...'
    else
      ret.title = _event.title
    end
  end
  ret
end

#do_hinner_dialog(_event) ⇒ Object



2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
# File 'lib/a-core.rb', line 2987

def do_hinner_dialog(_event)
  par = dialog_params(_event, false)
  dialog_frame = HinnerDialog.new
  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')){
    Arcadia.wf.button(dialog_frame){
      command proc{res = value;dialog_frame.release}
      text value.capitalize
      #helptext  value.capitalize
      width max_width*2
      pack('side' =>'right','padx'=>5, 'pady'=>5)
    }.hint=value.capitalize
  }

  Tk::BWidget::Label.new(dialog_frame,Arcadia.style('label')){
    text  par.msg
    helptext _event.title
  }.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)

  dialog_frame.show_modal
  _event.add_result(self, 'value'=>res)
end

#do_system_dialog(_event) ⇒ Object



2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
# File 'lib/a-core.rb', line 2965

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



2956
2957
2958
2959
2960
2961
2962
2963
# File 'lib/a-core.rb', line 2956

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



3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
# File 'lib/a-core.rb', line 3021

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