Class: SubProcessWidget

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-subprocess-inspector/ae-subprocess-inspector.rb

Overview

class SubProcessWidget < Tk::BWidget::Button

attr_reader :event
def initialize(_parent=nil, _event=nil, *args)
  super(Arcadia['toolbar'].frame, Arcadia.style('button').update("compound"=>'left', "background"=>Arcadia.conf("background"),"activebackground"=>'black', 'relief'=>'groove'))
  @parent = _parent
  @event = _event
  b_command = proc{
    message = Arcadia.text('ext.spi.d.kill.msg', [_event.pid, _event.name])
    r=Arcadia.hinner_dialog(self,
        'type'=>'yes_no', 
        'level'=>'warning',
        'title'=> Arcadia.text('ext.spi.d.kill.title'), 
        'msg'=>message)
    if r=="yes"
      _event.abort_action.call
    end
  }
  command b_command
  begin
    text File.basename(_event.name)
  rescue
    text _event.name
  end  
  helptext "#{_event.name} [pid #{_event.pid}]"
  pack('side' =>'left', :padx=>2, :pady=>0)
  Tk::Anigif.image(self, "#{Dir.pwd}/ext/ae-subprocess-inspector/process.res")
  start_check  
end

def start_check
  if @event.timecheck
    timecheck = @event.timecheck
  else
    timecheck = 1000
  end
  @timer = TkAfter.new
  proc_check = proc{
    alive = @event.alive_check.call
    #p "ALIVE=#{alive}"
    if !alive
      @timer.stop
      @parent.do_delete_process(self)
      self.destroy
    end
  }
  @timer.set_procs(timecheck,-1,proc_check)
  @timer.start
end

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_parent = nil, _event = nil, *args) ⇒ SubProcessWidget

Returns a new instance of SubProcessWidget.



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
# File 'ext/ae-subprocess-inspector/ae-subprocess-inspector.rb', line 106

def initialize(_parent=nil, _event=nil, *args)
  @parent = _parent
  @event = _event
  @anigif = _event.anigif.nil? ? "process.res" : _event.anigif
  abort_dialog_yes = _event.abort_dialog_yes.nil? || _event.abort_dialog_yes == true
  b_command = proc{
    if abort_dialog_yes
      message = Arcadia.text('ext.spi.d.kill.msg', [_event.pid, _event.name])
      r=Arcadia.hinner_dialog(self,
          'type'=>'yes_no', 
          'level'=>'warning',
          'title'=> Arcadia.text('ext.spi.d.kill.title'), 
          'msg'=>message)
    else
      r="yes"
    end
    if r=="yes"
      _event.abort_action.call
    end
  }
  #command b_command
  begin
    l_text = File.basename(_event.name)
  rescue
    l_text = _event.name
  end  
  helptext = "#{_event.name} [pid #{_event.pid}]"
  

  @label = TkLabel.new(Arcadia['toolbar'].frame, Arcadia.style('label')){
    compound 'left'
    text l_text
    pack('side' =>'left', :padx=>2, :pady=>0)
  }
  Tk::Anigif.image(@label, "#{Dir.pwd}/ext/ae-subprocess-inspector/#{@anigif}")

  @button = Arcadia.wf.toolbutton(Arcadia['toolbar'].frame){
    command b_command
    image Arcadia.image_res(CLOSE_FRAME_GIF)      
    pack('side' =>'left', :padx=>2, :pady=>0)
  }
  @button.hint=helptext

  start_check  
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



105
106
107
# File 'ext/ae-subprocess-inspector/ae-subprocess-inspector.rb', line 105

def event
  @event
end

Instance Method Details

#destroyObject



152
153
154
155
156
# File 'ext/ae-subprocess-inspector/ae-subprocess-inspector.rb', line 152

def destroy
 # @img.destroy
  @label.destroy
  @button.destroy
end

#start_checkObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'ext/ae-subprocess-inspector/ae-subprocess-inspector.rb', line 158

def start_check
  if @event.timecheck
    timecheck = @event.timecheck
  else
    timecheck = 1000
  end
  @timer = TkAfter.new
  proc_check = proc{
    alive = @event.alive_check.call
    #p "ALIVE=#{alive}"
    if !alive
      @timer.stop
      @parent.do_delete_process(self)
      self.destroy
    end
  }
  @timer.set_procs(timecheck,-1,proc_check)
  @timer.start
end