Skip to content

Collections

flaui.lib.collections

This module contains collections which can effective handle data transition between C# and Python.

TypeCast

A class that provides methods to convert C# objects to Python objects

cs_datetime(date) staticmethod

Parses Python date as C# Datetime object

Parameters:

Name Type Description Default
date date

Python date

required
Source code in flaui/lib/collections.py
@staticmethod
def cs_datetime(date: date):
    """Parses Python date as C# Datetime object

    :param date: Python date
    """
    return CSDateTime.Parse(arrow.get(date).strftime("%Y-%m-%d"))

cs_timespan(value) staticmethod

Converts a Python time milliseconds value to C# TimeSpan object

Parameters:

Name Type Description Default
value int

Time in milliseconds

required

Returns:

Type Description
Any

TimeSpan object from C# System

Source code in flaui/lib/collections.py
@staticmethod
def cs_timespan(value: int) -> Any:
    """Converts a Python time milliseconds value to C# TimeSpan object

    :param value: Time in milliseconds
    :return: TimeSpan object from C# System
    """
    if value is None:
        return None

    return TimeSpan.FromMilliseconds(value)

py_dict(raw) staticmethod

Converts C# Dict to Python Dict

Parameters:

Name Type Description Default
raw Any

Raw C# Dict object

required

Returns:

Type Description
Dict[Any, Any]

Converted Python Dict object

Source code in flaui/lib/collections.py
@staticmethod
def py_dict(raw: Any) -> Dict[Any, Any]:
    """Converts C# Dict to Python Dict

    :param raw: Raw C# Dict object
    :return: Converted Python Dict object
    """
    return raw if isinstance(raw, dict) else {_.Key: _.Value for _ in raw.GetEnumerator()}

py_list(raw) staticmethod

Converts C# Lists to Python lists

Parameters:

Name Type Description Default
raw Any

Raw C# list object

required

Returns:

Type Description
List[Any]

Converted Python List object

Source code in flaui/lib/collections.py
@staticmethod
def py_list(raw: Any) -> List[Any]:
    """Converts C# Lists to Python lists

    :param raw: Raw C# list object
    :return: Converted Python List object
    """
    return raw if isinstance(raw, list) else list(map(lambda x: x, raw))