Class: OverrideDlg

Inherits:
Object
  • Object
show all
Includes:
BasicLogging
Defined in:
lib/override.rb

Constant Summary collapse

XTERM =
'xterm'
@@Executables =

There used to be others, but only xterm remained.

[XTERM]
@@LIBDIR =
File::dirname(__FILE__)

Constants included from BasicLogging

BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from BasicLogging

#clear_log, is_muted?, #level, #log, #log_name, mute, #set_level, #set_target, #target

Constructor Details

#initializeOverrideDlg

Create the object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/override.rb', line 50

def initialize
  @config = Configuration::instance
  # find the supported programs 
  @executables = @@Executables.select do |ex_name|
    program?(ex_name) 
  end
  # As we are calling external programs anyway, 
  # why not continue with that ...
  @xmsg = ENV['PATH'].split(':').any? {|d| Dir.children(d).include?('xmessage')}
  # bof.
end

Class Attribute Details

.cvarsObject (readonly)

Returns the value of attribute cvars.



45
46
47
# File 'lib/override.rb', line 45

def cvars
  @cvars
end

Instance Method Details

#showObject

display a dialog and return the new options.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/override.rb', line 63

def show
  if(@executables && !@executables.empty?)
    debug('found executables ' << @executables.join(', '))
    opts = nil
    begin
      if has? XTERM
        return ruby_dlg
      end
    rescue SystemExit
      msg = 'Process is cancelled (SystemExit)'
      info msg
      exit true
    rescue Exception => ex
      msg = 'Error upon showing dialog ' << ex.message
      error(msg)
    end
  # no program to show the dialog 
  else 
    msg = "#{File.basename($0)}: No suitable executable found to display the dialog"
    warn msg
    # if xmessage is available, give the user a last chance.
    if @xmsg
      io = IO.popen('xmessage -buttons continue:0,abort:1 -default abort -print ' << msg) 
      Process.wait(io.pid)
      # ATTN! read io only once!
      exit if ('continue' != io.read.to_s.strip )
      # ... but then again, we still have a log.
      debug('continue with configured settings')
    end
  end
end