Class: ATT::Popup
- Inherits:
-
Object
- Object
- ATT::Popup
- Defined in:
- lib/popup/popup.rb,
lib/popup/version.rb
Direct Known Subclasses
Constant Summary collapse
- VERSION =
'0.0.9'
- @@windows =
nil
Instance Attribute Summary collapse
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Class Method Summary collapse
-
.collect_windows ⇒ Object
:nodoc:.
-
.find ⇒ Object
@Return: Popup object that is found.
- .find_all ⇒ Object
-
.find_when ⇒ Object
Find a new popup when execute the block you have given.
-
.record ⇒ Object
Record all the windows availed now.
Instance Method Summary collapse
-
#assert_exist? ⇒ Boolean
(also: #exist?)
false if not.
-
#close ⇒ Object
Close the window It behave as click x button at the right postion above.
-
#initialize(window) ⇒ Popup
constructor
:nodoc:.
Constructor Details
#initialize(window) ⇒ Popup
:nodoc:
31 32 33 |
# File 'lib/popup/popup.rb', line 31 def initialize(window) # :nodoc: @window = window end |
Instance Attribute Details
#window ⇒ Object (readonly)
Returns the value of attribute window.
35 36 37 |
# File 'lib/popup/popup.rb', line 35 def window @window end |
Class Method Details
.collect_windows ⇒ Object
:nodoc:
74 75 76 |
# File 'lib/popup/popup.rb', line 74 def self.collect_windows RAutomation::Window.windows.collect { |w| w.hwnd }.find_all { |hwnd| PopupWindow.is_popup?(hwnd) } end |
.find ⇒ Object
@Return: Popup object that is found.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/popup/popup.rb', line 41 def self.find raise NotRecordError,"please call record() before use me." unless @@windows windows_new = [] begin RAutomation::WaitHelper.wait_until(Config::timeout) do sleep 0.5 windows_now = collect_windows windows_new = windows_now - @@windows windows_new.size > 0 && windows_new.reject! { |h| RAutomation::Window.new(:hwnd=>h).text.chomp == "" } windows_new.size > 0 end rescue RAutomation::WaitHelper::TimeoutError raise WindowNotFoundError,"can not found new window in time #{Config::timeout} seconds" end #~ puts "new = " + (windows_new.collect do |hwnd| RAutomation::Window.new(:hwnd=>hwnd,:adapter=>"autoit").text end).join(",") # TODO: next week we should guess one window, but not raise a big exception raise MutliWindowsMatchError,"more than one windows opened between record() and find()" if windows_new.size > 1 window = RAutomation::Window.new(:hwnd => windows_new[0] ) if windows_new.size == 1 return self.new(window) end |
.find_all ⇒ Object
62 63 64 65 66 |
# File 'lib/popup/popup.rb', line 62 def self.find_all windows_now = collect_windows windows_new = windows_now - @@windows windows_new.collect { |hwnd| self.new( RAutomation::Window.new(:hwnd => hwnd ) ) } end |
.find_when ⇒ Object
Find a new popup when execute the block you have given.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/popup/popup.rb', line 80 def self.find_when # :yields: record begin thread = Thread.new { yield } find ensure thread.kill end end |
.record ⇒ Object
Record all the windows availed now. @return: Array that contains all the hwnd of visble windows.
70 71 72 |
# File 'lib/popup/popup.rb', line 70 def self.record @@windows = collect_windows end |
Instance Method Details
#assert_exist? ⇒ Boolean Also known as: exist?
false if not
99 100 101 |
# File 'lib/popup/popup.rb', line 99 def assert_exist? @window.exist? end |
#close ⇒ Object
Close the window It behave as click x button at the right postion above.
94 95 96 |
# File 'lib/popup/popup.rb', line 94 def close @window.close end |