44from FlaUILibrary .flaui .interface import (ModuleInterface , ValueContainer )
55from FlaUILibrary .flaui .util .treeitems import TreeItems
66from FlaUILibrary .flaui .util .converter import Converter
7+ from FlaUILibrary .flaui .util .treeitemaction import TreeItemAction
78
89
910class Tree (ModuleInterface ):
@@ -107,23 +108,23 @@ def execute_action(self, action: Action, values: Container):
107108 self .Action .GET_ROOT_ITEMS_COUNT :
108109 lambda : values ["element" ].Items .Length ,
109110 self .Action .EXPAND_ALL :
110- lambda : self . _expand_all_treetems (values ["element" ]),
111+ lambda : TreeItems . expand_all_tree_nodes (values ["element" ]. Items ),
111112 self .Action .COLLAPSE_ALL :
112- lambda : self . _collapse_all_treetems (values ["element" ]),
113+ lambda : TreeItems . collapse (values ["element" ]. Items ),
113114 self .Action .GET_VISIBLE_ITEMS_NAMES :
114- lambda : self . _get_every_visible_treeitems_name (values ["element" ]),
115+ lambda : TreeItems . get_all_names_from_tree_nodes (values ["element" ]. Items ),
115116 self .Action .GET_VISIBLE_ITEMS_COUNT :
116- lambda : self . _get_every_visible_treeitems_count (values ["element" ]),
117+ lambda : TreeItems . get_visible_leaf_count (values ["element" ]. Items ),
117118 self .Action .ITEM_SHOULD_BE_VISIBLE :
118119 lambda : self ._should_be_visible (values ["element" ], values ["item" ]),
119120 self .Action .SELECT_ITEM_BY_NAME :
120- lambda : self . _select_by_name (values ["element" ], values ["item" ]),
121+ lambda : TreeItems . select_visible_node_by_name (values ["element" ]. Items , values ["item" ]),
121122 self .Action .SELECT_ITEM :
122- lambda : self . _select (values ["element" ], values ["item" ]),
123+ lambda : TreeItems . execute_by_location (values ["element" ]. Items , values ["item" ], TreeItemAction . SELECT ),
123124 self .Action .EXPAND_ITEM :
124- lambda : self . _expand (values ["element" ], values ["item" ]),
125+ lambda : TreeItems . execute_by_location (values ["element" ]. Items , values ["item" ], TreeItemAction . EXPAND ),
125126 self .Action .COLLAPSE_ITEM :
126- lambda : self . _collapse (values ["element" ], values ["item" ]),
127+ lambda : TreeItems . execute_by_location (values ["element" ]. Items , values ["item" ], TreeItemAction . COLLAPSE ),
127128 self .Action .SELECTED_ITEM_SHOULD_BE :
128129 lambda : self ._selected_item_should_be (values ["element" ], values ["item" ]),
129130 self .Action .GET_SELECTED_ITEMS_NAME :
@@ -132,57 +133,10 @@ def execute_action(self, action: Action, values: Container):
132133
133134 return switcher .get (action , lambda : FlaUiError .raise_fla_ui_error (FlaUiError .ActionNotSupported ))()
134135
135- @staticmethod
136- def _get_every_visible_treeitems_name (control : Any ):
137- """
138- Counts every visible tree item.
139-
140- Args:
141- control (Object): Tree control element from FlaUI.
142-
143- Returns:
144- None.
145- """
146- obj = TreeItems (control )
147- return obj .get_every_visible_treeitems_name ()
148-
149- @staticmethod
150- def _get_every_visible_treeitems_count (control : Any ):
151- """
152- Counts every visible tree item.
153-
154- Args:
155- control (Object): Tree control element from FlaUI.
156-
157- Returns:
158- None.
159- """
160-
161- obj = TreeItems (control )
162- obj .get_every_visible_treeitems_name ()
163- return obj .treeitems_count
164-
165- @staticmethod
166- def _get_selected_item (control : Any ):
167- """
168- Try to get all selected items as a list.
169-
170- Args:
171- control (Object): Treeview control to select item from.
172-
173- Returns:
174- The selected Tree Item object.
175- """
176- obj = TreeItems (control )
177- selected = obj .selected_treeitem
178- if not selected :
179- raise FlaUiError (FlaUiError .NoItemSelected )
180- return selected
181-
182136 @staticmethod
183137 def _should_be_visible (control : Any , name : str ):
184138 """
185- Checks if Tree contains an given item by name.
139+ Checks if Tree contains a given item by name.
186140
187141 Args:
188142 control (Object): Tree control element from FlaUI.
@@ -191,99 +145,9 @@ def _should_be_visible(control: Any, name: str):
191145 Returns:
192146 True if name from combobox item exists otherwise False.
193147 """
194- names = Tree ._get_every_visible_treeitems_name (control )
195- if name not in names :
148+ if name not in TreeItems .get_all_names_from_tree_nodes (control .Items ):
196149 raise FlaUiError (FlaUiError .ElementNotVisible .format (name ))
197150
198- @staticmethod
199- def _expand_all_treetems (control : Any ):
200- """
201- Expand all tree items.
202-
203- Args:
204- control (Object): Tree control element from FlaUI.
205-
206- Returns:
207- None.
208- """
209- obj = TreeItems (control )
210- obj .expand_all_treeitems ()
211-
212- @staticmethod
213- def _collapse_all_treetems (control : Any ):
214- """
215- Collapse all tree items.
216-
217- Args:
218- control (Object): Tree control element from FlaUI.
219-
220- Returns:
221- None.
222- """
223- TreeItems (control ).collapse ()
224-
225- @staticmethod
226- def _select_by_name (control : Any , name : str ):
227- """
228- Try to select element from given name.
229-
230- Args:
231- control (Object): Tree control UI object.
232- name (String): Name from item to select
233-
234- Raises:
235- FlaUiError: If value can not be found by element.
236- """
237- obj = TreeItems (control )
238- obj .select_visible_treeitem_by_name (name )
239-
240- @staticmethod
241- def _select (control : Any , location : str ):
242- """
243- Try to select element from given parameter.
244-
245- Args:
246- control (Object): Tree control UI object.
247- location (String): series of pointers, which shows the item's location.
248- Example:
249- Location = "N:nameofitem1->N:nameofitem2->I:indexofitem2
250-
251- Raises:
252- FlaUiError: If value can not be found by control.
253- """
254- obj = TreeItems (control )
255- obj .execute_by_location (location , "Select" )
256-
257- @staticmethod
258- def _expand (control : Any , location : str ):
259- """
260- Try to expand element from given parameter.
261-
262- Args:
263- control (Object): Tree control UI object.
264- location (String): series of pointers, which shows the item's location.
265-
266- Raises:
267- FlaUiError: If value can not be found by control.
268- """
269- obj = TreeItems (control )
270- obj .execute_by_location (location , "Expand" )
271-
272- @staticmethod
273- def _collapse (control : Any , location : str ):
274- """
275- Try to collapse element from given parameter.
276-
277- Args:
278- control (Object): Tree control UI object.
279- location (String): series of pointers, which shows the item's location.
280-
281- Raises:
282- FlaUiError: If value can not be found by control.
283- """
284- obj = TreeItems (control )
285- obj .execute_by_location (location , "Collapse" )
286-
287151 @staticmethod
288152 def _get_selected_items_name (control : Any ):
289153 """
@@ -292,8 +156,11 @@ def _get_selected_items_name(control: Any):
292156 Args:
293157 control (Object): Tree control UI object.
294158 """
295- name = Tree ._get_selected_item (control ).Name
296- return name
159+ selected = control .SelectedTreeItem
160+ if not selected :
161+ raise FlaUiError (FlaUiError .NoItemSelected )
162+
163+ return selected .Name
297164
298165 @staticmethod
299166 def _selected_item_should_be (control : Any , item : str ):
0 commit comments