Skip to content

Commit a2ac8a0

Browse files
committed
#49 Pythonnet code adjustments
Converter bugfix for wrong value convert Tree code refactoring after pythonnet upgrade Pylint adjustments Updated changelog
1 parent 6a4be37 commit a2ac8a0

File tree

7 files changed

+181
-265
lines changed

7 files changed

+181
-265
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
77

88
## [Unreleased][]
99

10+
### Added
11+
12+
- Python.Net 3.0 Support
13+
14+
### Fixxed
15+
16+
- Converter bugfix for wrong value convert
17+
- Tree module refactoring
18+
1019
## [Release][1.6.6] [1.6.6][1.6.5-1.6.6] - 2021-09-01
1120

1221
### Added

src/FlaUILibrary/flaui/module/tree.py

Lines changed: 16 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from FlaUILibrary.flaui.interface import (ModuleInterface, ValueContainer)
55
from FlaUILibrary.flaui.util.treeitems import TreeItems
66
from FlaUILibrary.flaui.util.converter import Converter
7+
from FlaUILibrary.flaui.util.treeitemaction import TreeItemAction
78

89

910
class 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):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .keyboardinputconverter import KeyboardInputConverter
22
from .treeitems import TreeItems
3+
from .treeitemaction import TreeItemAction
34
from .treeitemsparser import TreeItemsParser

src/FlaUILibrary/flaui/util/converter.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def cast_to_int(value: Any, error_msg=None):
2020
error_msg (String) : Custom error message
2121
"""
2222
try:
23-
return None if not value else int(value)
23+
if value is None:
24+
return None
25+
26+
return int(value)
2427
except ValueError:
2528
if error_msg is None:
2629
error_msg = FlaUiError.ValueShouldBeANumber.format(value)
@@ -31,18 +34,26 @@ def cast_to_int(value: Any, error_msg=None):
3134
def cast_to_string(value: Any):
3235
"""
3336
Helper to cast value as string.
37+
If value is None empty string will be returned.
3438
3539
Args:
3640
value (Object): Value to convert
3741
"""
38-
return "" if not value else str(value)
42+
if value is None:
43+
return ""
44+
45+
return str(value)
3946

4047
@staticmethod
4148
def cast_to_bool(value: Any):
4249
"""
4350
Helper to cast value as bool.
51+
If value is None False will be returned.
4452
4553
Args:
4654
value (Object): Value to convert
4755
"""
48-
return "" if not value else bool(value)
56+
if value is None:
57+
return False
58+
59+
return bool(value)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from enum import Enum
2+
3+
4+
class TreeItemAction(Enum):
5+
"""
6+
Enumeration class for supported tree item actions by syntax usage from tree selection.
7+
"""
8+
EXPAND = "Expand"
9+
COLLAPSE = "Collapse"
10+
SELECT = "Select"

0 commit comments

Comments
 (0)