atspi 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b381921221f326d93dcfc8e7f5b54bf03c562fe
4
- data.tar.gz: b98b064c005bac799a37b8aa0407255601ed01ba
3
+ metadata.gz: ead4bf4d229628674333659b98aee3247c4547bd
4
+ data.tar.gz: 6e89ecf3512272b48d05193e88db0ef0ff664583
5
5
  SHA512:
6
- metadata.gz: ecdc4dd73b12639dcb5b7c0f144949ac92734962ab6acd80c2a2095cd47e8332aa20d1c33e7707cc4adb7824aecb0d8a3275316d5a62a890c3d8b98fa076f0c5
7
- data.tar.gz: 6c3df87e1fd8b8c71dee6a8ae2c052a8614d3aeece389f9a6e52ceb8197edf1519b908b32fc3b00502290721c0566bc7bc0f757668357695ecdd85ad240ec591
6
+ metadata.gz: 76dfd023c4e90060c577f082046fc370e3b42815365ec7492112afd1001c90da363082d108c56c1fc341b1bafede670cf99cf76d90421c14a56ba7f55832e0ed
7
+ data.tar.gz: adf03361bc2c38df8d3318cc78efd7c98787bb108ac964e286d8c5f2d77f888c5ffa682923477da5b5ddbf53829f38b958f6eba77a952591cfe35e93644efaf3
@@ -149,16 +149,12 @@ module ATSPI
149
149
  Children.new(@native)
150
150
  end
151
151
 
152
- # @return [Descendants, []] its descendants. It will be an empty array if it
152
+ # @return [Descendants] its descendants. The collection will be empty if it
153
153
  # does not implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-collection collection interface}
154
154
  #
155
155
  # @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-collection atspi_accessible_get_collection
156
156
  def descendants
157
- if @native.collection_iface
158
- Descendants.new(@native)
159
- else
160
- []
161
- end
157
+ Descendants.new(@native)
162
158
  end
163
159
 
164
160
  # @return [Accessible,nil] its descendant found at the given path
@@ -1,6 +1,9 @@
1
1
  module ATSPI
2
2
  # Wraps the children part of libatspi's AtspiAccessible[https://developer.gnome.org/libatspi/stable/AtspiAccessible.html]
3
3
  # and parts of AtspiSelection[https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html].
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
4
7
  class Accessible::Children
5
8
  include SelectableCollection
6
9
 
@@ -28,5 +31,87 @@ module ATSPI
28
31
  @native.child_count
29
32
  end
30
33
  # @!endgroup
34
+
35
+ # @!group Selection
36
+ # Checks if the accessible the children belong to implements the selection
37
+ # interface.
38
+ #
39
+ # @return [true,false]
40
+ #
41
+ # @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-selection atspi_accessible_get_selection
42
+ def selectable?
43
+ not @native.selection_iface.nil?
44
+ end
45
+
46
+ # @return [Selected,[]] its selected subset. It will be an empty array if
47
+ # children are not selectable.
48
+ def selected
49
+ if selectable?
50
+ Selected.new(@native)
51
+ else
52
+ []
53
+ end
54
+ end
55
+
56
+ # Tries to select all children
57
+ #
58
+ # @return [true,false] indicates success
59
+ #
60
+ # @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html#atspi-selection-select-all atspi_selection_select_all
61
+ def select_all
62
+ selectable? and @native.select_all
63
+ end
64
+
65
+ # Tries to deselect all children
66
+ #
67
+ # @return [true,false] indicates success
68
+ #
69
+ # @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html#atspi-selection-clear-selection atspi_selection_clear_selection
70
+ def deselect_all
71
+ selectable? and @native.clear_selection
72
+ end
73
+ # @!endgroup
74
+
75
+ # @!group Filter
76
+ # @note (see Descendants#where)
77
+ # @see (see Descendants#where)
78
+ # @return [Descendants] the children collection as filtered descendants
79
+ # collection.
80
+ # @overload (see Descendants#where)
81
+ def where(*args)
82
+ Accessible::Descendants.new(@native).recursive(false).where(*args)
83
+ end
84
+ # @!endgroup
85
+
86
+ # @!group Options
87
+ # @param (see Descendants#sort_by)
88
+ # @return [Descendants] the children collection as sorted descendants
89
+ # collection.
90
+ # @example (see Descendants#sort_by)
91
+ # @see (see Descendants#sort_by)
92
+ def sort_by(order)
93
+ Accessible::Descendants.new(@native).recursive(false).sort_by(order)
94
+ end
95
+
96
+ # @param (see Descendants#limit_to)
97
+ # @return [Descendants] the children collection as limited descendants
98
+ # collection.
99
+ # @see (see Descendants#limit_to)
100
+ def limit_to(limit)
101
+ Accessible::Descendants.new(@native).recursive(false).limit_to(limit)
102
+ end
103
+
104
+ # @param (see Descendants#recursive)
105
+ # @return [Descendants,self] self if +recursive+ is set to +false+. A
106
+ # collection of all descendants if +recursive+ is set to +true+
107
+ # @see (see Descendants#recursive)
108
+ def recursive(recursive = true)
109
+ if recursive
110
+ Accessible::Descendants.new(@native)
111
+ else
112
+ self
113
+ end
114
+ end
115
+ # @!endgroup
31
116
  end
32
117
  end
@@ -0,0 +1,35 @@
1
+ module ATSPI
2
+ # Wraps libatspi's AtspiSelection[https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html]
3
+ # together with parts of {Selectable} and {Children}
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
7
+ class Accessible::Children::Selected
8
+ include SelectableCollection::Selected
9
+
10
+ # @api private
11
+ def initialize(native)
12
+ @native = native
13
+ end
14
+
15
+ # @!group Enumerable interface
16
+ # @param idx [Integer]
17
+ #
18
+ # @return [Accessible] its child at index +idx+
19
+ #
20
+ # @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html#atspi-selection-get-selected-child atspi_selection_get_selected_child
21
+ def at(idx)
22
+ super do |mapped_idx|
23
+ Accessible.new(@native.selected_child(mapped_idx))
24
+ end
25
+ end
26
+
27
+ # @return [Integer] its number of children
28
+ #
29
+ # @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html#atspi-selection-get-n-selected-children atspi_selection_get_n_selected_children
30
+ def count
31
+ @native.n_selected_children
32
+ end
33
+ # @!endgroup
34
+ end
35
+ end
@@ -22,6 +22,14 @@ module ATSPI
22
22
  # In essence, it wraps libatspi's AtspiCollection[https://developer.gnome.org/libatspi/stable/libatspi-atspi-collection.html] and
23
23
  # AtspiMatchRule[https://developer.gnome.org/libatspi/stable/AtspiMatchRule.html]
24
24
  class Accessible::Descendants
25
+ extend Forwardable
26
+ # Delegate all methods of arrays directly to the array representation so
27
+ # methods available otherwise (like #select through Kernel) do not
28
+ # interfere
29
+ Array.instance_methods(false).each do |method|
30
+ delegate method => :to_a
31
+ end
32
+
25
33
  # @api private
26
34
  def initialize(native)
27
35
  @native = native
@@ -240,8 +248,10 @@ module ATSPI
240
248
 
241
249
  # @!group Access
242
250
  # @return [Array<Accessible>] the descendants according to the configured
243
- # filters and options.
251
+ # filters and options. The collection will be empty if the accessible
252
+ # does not implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-collection collection interface}
244
253
  def to_a
254
+ return [] unless @native.collection_iface
245
255
  match_rule = Libatspi::MatchRule.new(*@filters[:state], *@filters[:attributes],
246
256
  *@filters[:role], *@filters[:interface], @options.inverted?)
247
257
  matches = @native.matches(match_rule, *@options).to_a
@@ -256,6 +266,27 @@ module ATSPI
256
266
  end
257
267
  # @!endgroup
258
268
 
269
+ # @!group Selection
270
+ # @return [Array<Accessible>] its selected subset.
271
+ def selected
272
+ select(&:selected?)
273
+ end
274
+
275
+ # Tries to select all descendants in the collection
276
+ #
277
+ # @return [true,false] indicates if *all* are now selected
278
+ def select_all
279
+ map(&:select).all?
280
+ end
281
+
282
+ # Tries to deselect all descendants in the collection
283
+ #
284
+ # @return [true,false] indicates if *all* are now deselected
285
+ def deselect_all
286
+ map(&:deselect).all?
287
+ end
288
+ # @!endgroup
289
+
259
290
  # @!group Representations
260
291
  # @return [String] itself as an inspectable string
261
292
  def inspect
@@ -1,6 +1,6 @@
1
1
  class ATSPI::Accessible
2
2
  # Wraps libatspi's AtspiSelection[https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html]
3
- # together with parts of {Children}
3
+ # together with parts of {Children} and {Children::Selected}
4
4
  module Selectable
5
5
  # @!group Attributes & States
6
6
  # Checks if it can be selected. Accessibles which parent's native
@@ -9,7 +9,7 @@ class ATSPI::Accessible
9
9
  #
10
10
  # @return [true, false]
11
11
  def selectable?
12
- not parent.__send__(:native).selection_iface.nil?
12
+ parent.children.selectable?
13
13
  end
14
14
  # @!endgroup
15
15
 
@@ -24,12 +24,12 @@ class ATSPI::Accessible
24
24
  end
25
25
 
26
26
  # Deselects it
27
- # @return [true, false] indicating success of the operation. +true+ if its
27
+ # @return [true, false] indicating success of the operation. +false+ if its
28
28
  # parent does not implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-selection selection interface}.
29
29
  #
30
30
  # @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-selection.html#atspi-selection-deselect-child atspi_selection_deselect_child
31
31
  def deselect
32
- not selectable? or parent.__send__(:native).deselect_child(index_in_parent)
32
+ selectable? and parent.__send__(:native).deselect_child(index_in_parent)
33
33
  end
34
34
  # @!endgroup
35
35
 
@@ -1,6 +1,9 @@
1
1
  module ATSPI
2
2
  class Accessible::Table
3
3
  # Represents the columns a table {Cell} spans.
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
4
7
  class Cell::Columns
5
8
  include SelectableCollection::Selected
6
9
 
@@ -1,6 +1,9 @@
1
1
  module ATSPI
2
2
  class Accessible::Table
3
3
  # Represents the rows a table {Cell} spans.
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
4
7
  class Cell::Rows
5
8
  include SelectableCollection::Selected
6
9
 
@@ -1,6 +1,9 @@
1
1
  module ATSPI
2
2
  class Accessible::Table
3
- # Represents all columns in a {Table}
3
+ # Represents all columns in a {Table}.
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
4
7
  class Columns
5
8
  include SelectableCollection
6
9
 
@@ -1,6 +1,9 @@
1
1
  module ATSPI
2
2
  class Accessible::Table
3
- # Represents all selected columns of a {Table}
3
+ # Represents all selected columns of a {Table}.
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
4
7
  class Columns::Selected
5
8
  include SelectableCollection::Selected
6
9
 
@@ -1,6 +1,9 @@
1
1
  module ATSPI
2
2
  class Accessible::Table
3
- # Represents all rows in a {Table}
3
+ # Represents all rows in a {Table}.
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
4
7
  class Rows
5
8
  include SelectableCollection
6
9
 
@@ -1,6 +1,9 @@
1
1
  module ATSPI
2
2
  class Accessible::Table
3
- # Represents all selected rows of a {Table}
3
+ # Represents all selected rows of a {Table}.
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
4
7
  class Rows::Selected
5
8
  include SelectableCollection::Selected
6
9
 
@@ -2,7 +2,7 @@ module ATSPI
2
2
  # Included in classes representing a collection that can be iterated over.
3
3
  # A Collection is an Enumerable adjusted to the what we can efficiently get
4
4
  # from libatspi. In particular, it provides access to items by index and
5
- # from the end of the collection.
5
+ # from the end of the collection and can be treated like an array.
6
6
  module Collection
7
7
  include Enumerable
8
8
  # @!group Enumerable interface
@@ -22,6 +22,7 @@ require 'atspi/accessible/action'
22
22
 
23
23
  # Children
24
24
  require 'atspi/accessible/children'
25
+ require 'atspi/accessible/children/selected'
25
26
 
26
27
  # Descendants
27
28
  require 'atspi/accessible/descendants'
@@ -1,5 +1,8 @@
1
1
  module ATSPI
2
- # Included in classes representing a collection having selectable items
2
+ # Included in classes representing a collection having selectable items.
3
+ #
4
+ # Instance are enumerables supporting item access and can be treated more or
5
+ # less like an array.
3
6
  module SelectableCollection
4
7
  include Collection
5
8
 
@@ -1,5 +1,9 @@
1
1
  module ATSPI
2
- # Included in classes representing the selected subset of a selectable collection
2
+ # Included in classes representing the selected subset of a selectable
3
+ # collection.
4
+ #
5
+ # Instance are enumerables supporting item access and can be treated more or
6
+ # less like an array.
3
7
  module SelectableCollection::Selected
4
8
  include Collection
5
9
 
@@ -14,7 +18,7 @@ module ATSPI
14
18
  # @!group Representation
15
19
  # @return [String] instance as inspectable string
16
20
  def inspect
17
- indices = self.indices(limit: 5).inspect
21
+ indices = self.__send__(:indices, limit: 5).inspect
18
22
  indices[-1] = ", …]" if count > 5
19
23
  "#<#{self.class.name}:0x#{'%x14' % __id__} @count=#{count} @indices=#{indices}>"
20
24
  end
@@ -1,4 +1,4 @@
1
1
  module ATSPI
2
2
  # this library's version
3
- VERSION = "0.9.0"
3
+ VERSION = "0.9.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atspi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Aue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-02 00:00:00.000000000 Z
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gir_ffi
@@ -86,6 +86,7 @@ files:
86
86
  - lib/atspi/accessible.rb
87
87
  - lib/atspi/accessible/action.rb
88
88
  - lib/atspi/accessible/children.rb
89
+ - lib/atspi/accessible/children/selected.rb
89
90
  - lib/atspi/accessible/descendants.rb
90
91
  - lib/atspi/accessible/descendants/attribute_filter.rb
91
92
  - lib/atspi/accessible/descendants/interface_filter.rb