Module: Dialog

Defined in:
lib/dialog.rb,
lib/dialog/main.rb

Defined Under Namespace

Modules: CocoaDialog, Dialog, KDialog, Yad, Zenity

Constant Summary collapse

VERSION =
'0.2.1'

Class Method Summary collapse

Class Method Details

.autosetupObject

Figure out which implementation of dialog to use, based on platform detection. This loads the methods from more specific submodules into this Dialog module, so that you can just call (for example) Dialog.messagebox("Hello, world.")



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dialog/main.rb', line 6

def self.autosetup
  case RUBY_PLATFORM
  when /linux/
    if ENV.fetch('DISPLAY', "").length > 0
      kdepid = IO.popen(["pidof", "-s", "kdeinit", "kdeinit4"], 'r') do |io|
        io.read
      end
      to_run = ["kdialog", "yad", "zenity", "dialog"].map {|name|
        name if ENV['PATH'].split(/:/).detect {|dir| File.exists?(File.join(dir, name)) }
      }.compact

      if kdepid != "" and to_run.include?("kdialog")
        extend KDialog  # Already running KDE?
      else
        if to_run.include?("yad")
          extend Yad
        elsif to_run.include?("zenity")
          extend Zenity
        elsif to_run.include?("kdialog")
          extend KDialog
        elsif (to_run.include?("dialog") and $stdout.isatty)
          extend Dialog
        end
      end
    else
      extend Dialog if ($stdout.isatty and $stdin.isatty)
    end
  when /darwin/
    extend CocoaDialog
  when /mingw/
    to_run = ["yad", "zenity", "dialog"].map {|name|
      name if ENV['PATH'].split(/;/).detect {|dir| File.exists?(File.join(dir, name)) }
    }.compact
    case to_run.first
    when 'yad'
      extend Yad
    when 'zenity'
      extend Zenity
    when 'dialog'
      extend Dialog
    else
      # Not sure here, any other way to get a dialog on windows?
    end
  else
    # The user will just have to load it themselves.
  end
end