Module: Gutkumber

Defined in:
lib/gutkumber.rb,
lib/gutkumber/finders.rb

Constant Summary collapse

TICK_SIZE =
ENV["GUTKUMBER_TICK_SIZE"] || 0.3

Class Method Summary collapse

Class Method Details

.dialogsObject



15
16
17
18
19
# File 'lib/gutkumber/finders.rb', line 15

def self.dialogs
  Gtk::Window.toplevels.select do |window|
    window.class.ancestors.include?(Gtk::Dialog)
  end
end

.find_all_gtk_windowsObject



21
22
23
# File 'lib/gutkumber/finders.rb', line 21

def self.find_all_gtk_windows
  Gtk::Window.toplevels
end

.find_button(window, button_label) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/gutkumber/finders.rb', line 36

def self.find_button(window, button_label)
  buttons = window.child_widgets_with_class(Gtk::Button)
  buttons.each do |button|
    label = button.child_widgets_with_class(Gtk::Label).map{|la| la.text}.join(" ")
    return button if label =~ Regexp.new(Regexp.escape(button_label))
  end
  nil
end

.find_gtk_window(title) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/gutkumber/finders.rb', line 5

def self.find_gtk_window(title)
  Gtk::Window.toplevels.detect do |window| 
    if title.is_a?(Regexp)
      window.title =~ title
    else
      window.title =~ Regexp.new(Regexp.escape(title))
    end
  end
end

.in_test_process?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/gutkumber.rb', line 22

def self.in_test_process?
  true
end

.label_texts(widget) ⇒ Object



30
31
32
33
34
# File 'lib/gutkumber/finders.rb', line 30

def self.label_texts(widget)
  widget.child_widgets_with_class(Gtk::Label).map do |label|
    label.text
  end
end

.tickObject



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

def self.tick
  Gtk.main_iteration while Gtk.events_pending?
end

.wait_tickObject



49
50
51
52
# File 'lib/gutkumber/finders.rb', line 49

def self.wait_tick
  tick
  sleep TICK_SIZE
end

.window_buttons(window) ⇒ Object



25
26
27
28
# File 'lib/gutkumber/finders.rb', line 25

def self.window_buttons(window)
  buttons = window.child_widgets_with_class(Gtk::Button)
  buttons.map {|button| button.child_widgets_with_class(Gtk::Label).map{|la| la.text}.join(" ") }
end