Class: AutoItX3::TreeView

Inherits:
Control
  • Object
show all
Defined in:
lib/AutoItX3/control.rb

Overview

A TreeView is a control that shows a kind of expandable list, like the one displayed ont the left side in .chm files.

The item parameter of many methods in this class is a string of form

"#index_0|#index_1|#index_2..."

that describes where to find the item. See the #selected method for an example.

Instance Method Summary collapse

Methods inherited from Control

#click, #disable, #enable, #enabled?, #focus, from_control, functions, functions=, #handle, #hide, #initialize, #move, #rect, #send_command_to_control, #send_keys, #show, #text, #text=, #visible?

Constructor Details

This class inherits a constructor from AutoItX3::Control

Instance Method Details

#check(item) ⇒ Object

Checks item, if it supports that operation.

Parameters

item

The path of the item to check.

Return value

Unknown.

Raises

Au3Error

Control or window not found.

Example

ctrl.check("#0|#3|#7")


869
870
871
# File 'lib/AutoItX3/control.rb', line 869

def check(item)
  send_command_to_tree_view("Check", item)
end

#checked?(item) ⇒ Boolean

Returns wheather or not item is checked.

Parameters

item

The item to check.

Return value

true or false.

Raises

Au3Error

Control or window not found.

Example

p ctrl.checked?("#1|#2|#3") #=> true

Remarks

This method always returns false for non-checkable items.

Returns:

  • (Boolean)


982
983
984
# File 'lib/AutoItX3/control.rb', line 982

def checked?(item)
  send_command_to_tree_view("IsChecked", item).to_i == 1
end

#collapse(item) ⇒ Object

Collapses item to hide its children.

Parameters

item

The path of the item to collapse.

Return value

Unknown.

Raises

Au3Error

Control or window not found.

Example

ctrl.collapse("#0")


882
883
884
# File 'lib/AutoItX3/control.rb', line 882

def collapse(item)
  send_command_to_tree_view("Collapse", item)
end

#exists?(item) ⇒ Boolean

Return wheather or not item exists.

Parameters

item

The path of the item to check.

Return value

true or false.

Raises

Au3Error

Control or window not found.

Example

p ctrl.exists?("#0|#3") #=> true
p ctrl.exists?("#1|#4") #=> false

Returns:

  • (Boolean)


896
897
898
# File 'lib/AutoItX3/control.rb', line 896

def exists?(item)
  send_command_to_tree_view("Exists", item).to_i == 1
end

#expand(item) ⇒ Object

Expands item to show its children.

Parameters

item

The path of the item to expand.

Return value

Unknown.

Raises

Au3Error

Control or window not found.

Example

ctrl.expand("#0|#3")


909
910
911
# File 'lib/AutoItX3/control.rb', line 909

def expand(item)
  send_command_to_tree_view("Expand", item)
end

#num_subitems(item) ⇒ Object

Returns the number of children of item.

Parameters

item

The path of the item to check.

Return value

The number of subitems of that node.

Raises

Au3Error

Control or window not found.

Example

p ctrl.num_subitems("#0") #=> 8

Remarks

This method returns 0 if the item doesn’t exist.



924
925
926
# File 'lib/AutoItX3/control.rb', line 924

def num_subitems(item)
  send_command_to_tree_view("GetItemCount", item).to_i
end

#select(item) ⇒ Object

Selects item.

Parameters

item

The item to select.

Return value

Unknown.

Raises

Au3Error

Control or window not found.

Example

ctrl.select("#1|#2")


995
996
997
# File 'lib/AutoItX3/control.rb', line 995

def select(item)
  send_command_to_tree_view("Select", item)
end

#selected(use_index = false) ⇒ Object

Returns where to find the selected item.

Parameters

use_index

(false) If this is true, you only get the last index.

Return value

If use_index is false, which is the default, you get a string back that describes where you find the currently selected item. The string is of form

"#index_0|#index_1|#index_3..."

for example

"#0|#3|#0|#10|#1|#0"

for the “ControlClick” item in the AutoItX help. Otherwise, if use_index is false, you only get the last index of that chain, as an integer.

Raises

Au3Error

Control or window not found.

Example

See Return value.

Remarks

You can pass the result of this method directly to many methods of this class.



945
946
947
948
949
# File 'lib/AutoItX3/control.rb', line 945

def selected(use_index = false)
  result = send_command_to_tree_view("GetSelected", use_index ? 1 : 0)
  return result.to_i if use_index
  result
end

#send_command_to_tree_view(command, arg1 = "", arg2 = "") ⇒ Object

Sends cmd to self. This method is only used internally.

Raises:



851
852
853
854
855
856
857
858
# File 'lib/AutoItX3/control.rb', line 851

def send_command_to_tree_view(command, arg1 = "", arg2 = "")
  Control.functions[__method__] ||= AU3_Function.new("ControlTreeView", 'SSSSSSPI')
  buffer = " " * BUFFER_SIZE
  buffer.wide!
  Control.functions[__method__].call(@title.wide, @text.wide, @c_id.to_s.wide, command.to_s.wide, arg1.to_s.wide, arg2.to_s.wide, buffer, BUFFER_SIZE - 1)
  raise(Au3Error, "Unknown error occured when sending '#{command}' to '#{@c_id}' in '#{@title}'! Maybe an invalid window?") if AutoItX3.last_error == 1
  buffer.normal.strip
end

#text_at(item) ⇒ Object Also known as: []

call-seq:

text_at( item ) ==> aString
[ item ] ==> aString

Returns the text of item.

Parameters

item

The item to retrieve the text from.

Return value

The text at the specified position.

Raises

Au3Error

Control or window not found.

Example

p ctrl.text_at("#0|#3|#0|#10|#1|#0") #=> "ControlClick"

Remarks

See #selected for an easy way of how to get the text of the currently selected item.



966
967
968
# File 'lib/AutoItX3/control.rb', line 966

def text_at(item)
  send_command_to_tree_view("GetText", item)
end

#uncheck(item) ⇒ Object

Unchecks item if it suports that operation (i.e. it’s a checkbox).

Parameters

item

The item to uncheck.

Return value

Unknown.

Raises

Au3Error

Control or Window not found.

Example

ctrl.uncheck("#0|#3")


1008
1009
1010
# File 'lib/AutoItX3/control.rb', line 1008

def uncheck(item)
  send_command_to_tree_view("Uncheck", item)
end