Skip to content

Commit

Permalink
#49 Pythonnet code adjustments
Browse files Browse the repository at this point in the history
Converter bugfix for wrong value convert
Tree code refactoring after pythonnet upgrade
Pylint adjustments
Updated changelog
  • Loading branch information
Nepitwin committed Jan 29, 2022
1 parent 6a4be37 commit a2ac8a0
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 265 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].

## [Unreleased][]

### Added

- Python.Net 3.0 Support

### Fixxed

- Converter bugfix for wrong value convert
- Tree module refactoring

## [Release][1.6.6] [1.6.6][1.6.5-1.6.6] - 2021-09-01

### Added
Expand Down
165 changes: 16 additions & 149 deletions src/FlaUILibrary/flaui/module/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from FlaUILibrary.flaui.interface import (ModuleInterface, ValueContainer)
from FlaUILibrary.flaui.util.treeitems import TreeItems
from FlaUILibrary.flaui.util.converter import Converter
from FlaUILibrary.flaui.util.treeitemaction import TreeItemAction


class Tree(ModuleInterface):
Expand Down Expand Up @@ -107,23 +108,23 @@ def execute_action(self, action: Action, values: Container):
self.Action.GET_ROOT_ITEMS_COUNT:
lambda: values["element"].Items.Length,
self.Action.EXPAND_ALL:
lambda: self._expand_all_treetems(values["element"]),
lambda: TreeItems.expand_all_tree_nodes(values["element"].Items),
self.Action.COLLAPSE_ALL:
lambda: self._collapse_all_treetems(values["element"]),
lambda: TreeItems.collapse(values["element"].Items),
self.Action.GET_VISIBLE_ITEMS_NAMES:
lambda: self._get_every_visible_treeitems_name(values["element"]),
lambda: TreeItems.get_all_names_from_tree_nodes(values["element"].Items),
self.Action.GET_VISIBLE_ITEMS_COUNT:
lambda: self._get_every_visible_treeitems_count(values["element"]),
lambda: TreeItems.get_visible_leaf_count(values["element"].Items),
self.Action.ITEM_SHOULD_BE_VISIBLE:
lambda: self._should_be_visible(values["element"], values["item"]),
self.Action.SELECT_ITEM_BY_NAME:
lambda: self._select_by_name(values["element"], values["item"]),
lambda: TreeItems.select_visible_node_by_name(values["element"].Items, values["item"]),
self.Action.SELECT_ITEM:
lambda: self._select(values["element"], values["item"]),
lambda: TreeItems.execute_by_location(values["element"].Items, values["item"], TreeItemAction.SELECT),
self.Action.EXPAND_ITEM:
lambda: self._expand(values["element"], values["item"]),
lambda: TreeItems.execute_by_location(values["element"].Items, values["item"], TreeItemAction.EXPAND),
self.Action.COLLAPSE_ITEM:
lambda: self._collapse(values["element"], values["item"]),
lambda: TreeItems.execute_by_location(values["element"].Items, values["item"], TreeItemAction.COLLAPSE),
self.Action.SELECTED_ITEM_SHOULD_BE:
lambda: self._selected_item_should_be(values["element"], values["item"]),
self.Action.GET_SELECTED_ITEMS_NAME:
Expand All @@ -132,57 +133,10 @@ def execute_action(self, action: Action, values: Container):

return switcher.get(action, lambda: FlaUiError.raise_fla_ui_error(FlaUiError.ActionNotSupported))()

@staticmethod
def _get_every_visible_treeitems_name(control: Any):
"""
Counts every visible tree item.
Args:
control (Object): Tree control element from FlaUI.
Returns:
None.
"""
obj = TreeItems(control)
return obj.get_every_visible_treeitems_name()

@staticmethod
def _get_every_visible_treeitems_count(control: Any):
"""
Counts every visible tree item.
Args:
control (Object): Tree control element from FlaUI.
Returns:
None.
"""

obj = TreeItems(control)
obj.get_every_visible_treeitems_name()
return obj.treeitems_count

@staticmethod
def _get_selected_item(control: Any):
"""
Try to get all selected items as a list.
Args:
control (Object): Treeview control to select item from.
Returns:
The selected Tree Item object.
"""
obj = TreeItems(control)
selected = obj.selected_treeitem
if not selected:
raise FlaUiError(FlaUiError.NoItemSelected)
return selected

@staticmethod
def _should_be_visible(control: Any, name: str):
"""
Checks if Tree contains an given item by name.
Checks if Tree contains a given item by name.
Args:
control (Object): Tree control element from FlaUI.
Expand All @@ -191,99 +145,9 @@ def _should_be_visible(control: Any, name: str):
Returns:
True if name from combobox item exists otherwise False.
"""
names = Tree._get_every_visible_treeitems_name(control)
if name not in names:
if name not in TreeItems.get_all_names_from_tree_nodes(control.Items):
raise FlaUiError(FlaUiError.ElementNotVisible.format(name))

@staticmethod
def _expand_all_treetems(control: Any):
"""
Expand all tree items.
Args:
control (Object): Tree control element from FlaUI.
Returns:
None.
"""
obj = TreeItems(control)
obj.expand_all_treeitems()

@staticmethod
def _collapse_all_treetems(control: Any):
"""
Collapse all tree items.
Args:
control (Object): Tree control element from FlaUI.
Returns:
None.
"""
TreeItems(control).collapse()

@staticmethod
def _select_by_name(control: Any, name: str):
"""
Try to select element from given name.
Args:
control (Object): Tree control UI object.
name (String): Name from item to select
Raises:
FlaUiError: If value can not be found by element.
"""
obj = TreeItems(control)
obj.select_visible_treeitem_by_name(name)

@staticmethod
def _select(control: Any, location: str):
"""
Try to select element from given parameter.
Args:
control (Object): Tree control UI object.
location (String): series of pointers, which shows the item's location.
Example:
Location = "N:nameofitem1->N:nameofitem2->I:indexofitem2
Raises:
FlaUiError: If value can not be found by control.
"""
obj = TreeItems(control)
obj.execute_by_location(location, "Select")

@staticmethod
def _expand(control: Any, location: str):
"""
Try to expand element from given parameter.
Args:
control (Object): Tree control UI object.
location (String): series of pointers, which shows the item's location.
Raises:
FlaUiError: If value can not be found by control.
"""
obj = TreeItems(control)
obj.execute_by_location(location, "Expand")

@staticmethod
def _collapse(control: Any, location: str):
"""
Try to collapse element from given parameter.
Args:
control (Object): Tree control UI object.
location (String): series of pointers, which shows the item's location.
Raises:
FlaUiError: If value can not be found by control.
"""
obj = TreeItems(control)
obj.execute_by_location(location, "Collapse")

@staticmethod
def _get_selected_items_name(control: Any):
"""
Expand All @@ -292,8 +156,11 @@ def _get_selected_items_name(control: Any):
Args:
control (Object): Tree control UI object.
"""
name = Tree._get_selected_item(control).Name
return name
selected = control.SelectedTreeItem
if not selected:
raise FlaUiError(FlaUiError.NoItemSelected)

return selected.Name

@staticmethod
def _selected_item_should_be(control: Any, item: str):
Expand Down
1 change: 1 addition & 0 deletions src/FlaUILibrary/flaui/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .keyboardinputconverter import KeyboardInputConverter
from .treeitems import TreeItems
from .treeitemaction import TreeItemAction
from .treeitemsparser import TreeItemsParser
17 changes: 14 additions & 3 deletions src/FlaUILibrary/flaui/util/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def cast_to_int(value: Any, error_msg=None):
error_msg (String) : Custom error message
"""
try:
return None if not value else int(value)
if value is None:
return None

return int(value)
except ValueError:
if error_msg is None:
error_msg = FlaUiError.ValueShouldBeANumber.format(value)
Expand All @@ -31,18 +34,26 @@ def cast_to_int(value: Any, error_msg=None):
def cast_to_string(value: Any):
"""
Helper to cast value as string.
If value is None empty string will be returned.
Args:
value (Object): Value to convert
"""
return "" if not value else str(value)
if value is None:
return ""

return str(value)

@staticmethod
def cast_to_bool(value: Any):
"""
Helper to cast value as bool.
If value is None False will be returned.
Args:
value (Object): Value to convert
"""
return "" if not value else bool(value)
if value is None:
return False

return bool(value)
10 changes: 10 additions & 0 deletions src/FlaUILibrary/flaui/util/treeitemaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class TreeItemAction(Enum):
"""
Enumeration class for supported tree item actions by syntax usage from tree selection.
"""
EXPAND = "Expand"
COLLAPSE = "Collapse"
SELECT = "Select"
Loading

0 comments on commit a2ac8a0

Please sign in to comment.