pythonnative 0.3.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

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.
Files changed (44) hide show
  1. pythonnative/__init__.py +45 -65
  2. pythonnative/cli/pn.py +16 -10
  3. pythonnative/components.py +241 -0
  4. pythonnative/element.py +47 -0
  5. pythonnative/native_views.py +800 -0
  6. pythonnative/page.py +321 -249
  7. pythonnative/reconciler.py +129 -0
  8. pythonnative/templates/android_template/app/build.gradle +2 -2
  9. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PageFragment.kt +2 -1
  10. pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml +1 -1
  11. pythonnative/templates/android_template/build.gradle +3 -3
  12. pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +1 -1
  13. pythonnative/utils.py +21 -29
  14. pythonnative-0.5.0.dist-info/METADATA +161 -0
  15. {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/RECORD +19 -39
  16. {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/WHEEL +1 -1
  17. {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/licenses/LICENSE +1 -1
  18. pythonnative/activity_indicator_view.py +0 -71
  19. pythonnative/button.py +0 -109
  20. pythonnative/date_picker.py +0 -72
  21. pythonnative/image_view.py +0 -76
  22. pythonnative/label.py +0 -66
  23. pythonnative/list_view.py +0 -73
  24. pythonnative/material_activity_indicator_view.py +0 -69
  25. pythonnative/material_button.py +0 -65
  26. pythonnative/material_date_picker.py +0 -85
  27. pythonnative/material_progress_view.py +0 -66
  28. pythonnative/material_search_bar.py +0 -65
  29. pythonnative/material_switch.py +0 -65
  30. pythonnative/material_time_picker.py +0 -72
  31. pythonnative/picker_view.py +0 -65
  32. pythonnative/progress_view.py +0 -68
  33. pythonnative/scroll_view.py +0 -63
  34. pythonnative/search_bar.py +0 -65
  35. pythonnative/stack_view.py +0 -60
  36. pythonnative/switch.py +0 -66
  37. pythonnative/text_field.py +0 -67
  38. pythonnative/text_view.py +0 -70
  39. pythonnative/time_picker.py +0 -73
  40. pythonnative/view.py +0 -25
  41. pythonnative/web_view.py +0 -58
  42. pythonnative-0.3.0.dist-info/METADATA +0 -137
  43. {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/entry_points.txt +0 -0
  44. {pythonnative-0.3.0.dist-info → pythonnative-0.5.0.dist-info}/top_level.txt +0 -0
@@ -1,65 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class MaterialSearchBarBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_query(self, query: str) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def get_query(self) -> str:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/com/google/android/material/search/SearchBar
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class MaterialSearchBar(MaterialSearchBarBase, ViewBase):
34
- def __init__(self, context, query: str = "") -> None:
35
- super().__init__()
36
- self.native_class = jclass("com.google.android.material.search.SearchBar")
37
- self.native_instance = self.native_class(context)
38
- self.set_query(query)
39
-
40
- def set_query(self, query: str) -> None:
41
- self.native_instance.setQuery(query, False)
42
-
43
- def get_query(self) -> str:
44
- return self.native_instance.getQuery().toString()
45
-
46
- else:
47
- # ========================================
48
- # iOS class
49
- # https://developer.apple.com/documentation/uikit/uisearchbar
50
- # ========================================
51
-
52
- from rubicon.objc import ObjCClass
53
-
54
- class MaterialSearchBar(MaterialSearchBarBase, ViewBase):
55
- def __init__(self, query: str = "") -> None:
56
- super().__init__()
57
- self.native_class = ObjCClass("UISearchBar")
58
- self.native_instance = self.native_class.alloc().init()
59
- self.set_query(query)
60
-
61
- def set_query(self, query: str) -> None:
62
- self.native_instance.set_searchText_(query)
63
-
64
- def get_query(self) -> str:
65
- return self.native_instance.searchText()
@@ -1,65 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class MaterialSwitchBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_on(self, value: bool) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def is_on(self) -> bool:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class MaterialSwitch(MaterialSwitchBase, ViewBase):
34
- def __init__(self, context, value: bool = False) -> None:
35
- super().__init__()
36
- self.native_class = jclass("com.google.android.material.switch.MaterialSwitch")
37
- self.native_instance = self.native_class(context)
38
- self.set_on(value)
39
-
40
- def set_on(self, value: bool) -> None:
41
- self.native_instance.setChecked(value)
42
-
43
- def is_on(self) -> bool:
44
- return self.native_instance.isChecked()
45
-
46
- else:
47
- # ========================================
48
- # iOS class
49
- # https://developer.apple.com/documentation/uikit/uiswitch
50
- # ========================================
51
-
52
- from rubicon.objc import ObjCClass
53
-
54
- class MaterialSwitch(MaterialSwitchBase, ViewBase):
55
- def __init__(self, value: bool = False) -> None:
56
- super().__init__()
57
- self.native_class = ObjCClass("UISwitch")
58
- self.native_instance = self.native_class.alloc().init()
59
- self.set_on(value)
60
-
61
- def set_on(self, value: bool) -> None:
62
- self.native_instance.setOn_animated_(value, False)
63
-
64
- def is_on(self) -> bool:
65
- return self.native_instance.isOn()
@@ -1,72 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class MaterialTimePickerBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_time(self, hour: int, minute: int) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def get_time(self) -> tuple:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/com/google/android/material/timepicker/MaterialTimePicker
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class MaterialTimePicker(MaterialTimePickerBase, ViewBase):
34
- def __init__(self, context, hour: int = 0, minute: int = 0) -> None:
35
- super().__init__()
36
- self.native_class = jclass("com.google.android.material.timepicker.MaterialTimePicker")
37
- self.native_instance = self.native_class(context)
38
- self.set_time(hour, minute)
39
-
40
- def set_time(self, hour: int, minute: int) -> None:
41
- self.native_instance.setTime(hour, minute)
42
-
43
- def get_time(self) -> tuple:
44
- hour = self.native_instance.getHour()
45
- minute = self.native_instance.getMinute()
46
- return hour, minute
47
-
48
- else:
49
- # ========================================
50
- # iOS class
51
- # https://developer.apple.com/documentation/uikit/uidatepicker
52
- # ========================================
53
-
54
- from datetime import time
55
-
56
- from rubicon.objc import ObjCClass
57
-
58
- class MaterialTimePicker(MaterialTimePickerBase, ViewBase):
59
- def __init__(self, hour: int = 0, minute: int = 0) -> None:
60
- super().__init__()
61
- self.native_class = ObjCClass("UIDatePicker")
62
- self.native_instance = self.native_class.alloc().init()
63
- self.native_instance.setDatePickerMode_(1) # Setting mode to Time
64
- self.set_time(hour, minute)
65
-
66
- def set_time(self, hour: int, minute: int) -> None:
67
- t = time(hour, minute)
68
- self.native_instance.setTime_(t)
69
-
70
- def get_time(self) -> tuple:
71
- t = self.native_instance.time()
72
- return t.hour, t.minute
@@ -1,65 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class PickerViewBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_selected(self, index: int) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def get_selected(self) -> int:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/android/widget/Spinner
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class PickerView(PickerViewBase, ViewBase):
34
- def __init__(self, context, index: int = 0) -> None:
35
- super().__init__()
36
- self.native_class = jclass("android.widget.Spinner")
37
- self.native_instance = self.native_class(context)
38
- self.set_selected(index)
39
-
40
- def set_selected(self, index: int) -> None:
41
- self.native_instance.setSelection(index)
42
-
43
- def get_selected(self) -> int:
44
- return self.native_instance.getSelectedItemPosition()
45
-
46
- else:
47
- # ========================================
48
- # iOS class
49
- # https://developer.apple.com/documentation/uikit/uipickerview
50
- # ========================================
51
-
52
- from rubicon.objc import ObjCClass
53
-
54
- class PickerView(PickerViewBase, ViewBase):
55
- def __init__(self, index: int = 0) -> None:
56
- super().__init__()
57
- self.native_class = ObjCClass("UIPickerView")
58
- self.native_instance = self.native_class.alloc().init()
59
- self.set_selected(index)
60
-
61
- def set_selected(self, index: int) -> None:
62
- self.native_instance.selectRow_inComponent_animated_(index, 0, False)
63
-
64
- def get_selected(self) -> int:
65
- return self.native_instance.selectedRowInComponent_(0)
@@ -1,68 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID, get_android_context
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class ProgressViewBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_progress(self, progress: float) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def get_progress(self) -> float:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/android/widget/ProgressBar
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class ProgressView(ProgressViewBase, ViewBase):
34
- def __init__(self) -> None:
35
- super().__init__()
36
- self.native_class = jclass("android.widget.ProgressBar")
37
- # self.native_instance = self.native_class(context, None, android.R.attr.progressBarStyleHorizontal)
38
- context = get_android_context()
39
- self.native_instance = self.native_class(context, None, jclass("android.R$attr").progressBarStyleHorizontal)
40
- self.native_instance.setIndeterminate(False)
41
-
42
- def set_progress(self, progress: float) -> None:
43
- self.native_instance.setProgress(int(progress * 100))
44
-
45
- def get_progress(self) -> float:
46
- return self.native_instance.getProgress() / 100.0
47
-
48
- else:
49
- # ========================================
50
- # iOS class
51
- # https://developer.apple.com/documentation/uikit/uiprogressview
52
- # ========================================
53
-
54
- from rubicon.objc import ObjCClass
55
-
56
- class ProgressView(ProgressViewBase, ViewBase):
57
- def __init__(self) -> None:
58
- super().__init__()
59
- self.native_class = ObjCClass("UIProgressView")
60
- self.native_instance = self.native_class.alloc().initWithProgressViewStyle_(
61
- 0
62
- ) # 0: UIProgressViewStyleDefault
63
-
64
- def set_progress(self, progress: float) -> None:
65
- self.native_instance.setProgress_animated_(progress, False)
66
-
67
- def get_progress(self) -> float:
68
- return self.native_instance.progress()
@@ -1,63 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from typing import Any, List
3
-
4
- from .utils import IS_ANDROID
5
- from .view import ViewBase
6
-
7
- # ========================================
8
- # Base class
9
- # ========================================
10
-
11
-
12
- class ScrollViewBase(ABC):
13
- @abstractmethod
14
- def __init__(self) -> None:
15
- super().__init__()
16
- self.views: List[Any] = []
17
-
18
- @abstractmethod
19
- def add_view(self, view) -> None:
20
- pass
21
-
22
-
23
- if IS_ANDROID:
24
- # ========================================
25
- # Android class
26
- # https://developer.android.com/reference/android/widget/ScrollView
27
- # ========================================
28
-
29
- from java import jclass
30
-
31
- class ScrollView(ScrollViewBase, ViewBase):
32
- def __init__(self, context) -> None:
33
- super().__init__()
34
- self.native_class = jclass("android.widget.ScrollView")
35
- self.native_instance = self.native_class(context)
36
-
37
- def add_view(self, view):
38
- self.views.append(view)
39
- # In Android, ScrollView can host only one direct child
40
- if len(self.views) == 1:
41
- self.native_instance.addView(view.native_instance)
42
- else:
43
- raise Exception("ScrollView can host only one direct child")
44
-
45
- else:
46
- # ========================================
47
- # iOS class
48
- # https://developer.apple.com/documentation/uikit/uiscrollview
49
- # ========================================
50
-
51
- from rubicon.objc import ObjCClass
52
-
53
- class ScrollView(ScrollViewBase, ViewBase):
54
- def __init__(self) -> None:
55
- super().__init__()
56
- self.native_class = ObjCClass("UIScrollView")
57
- self.native_instance = self.native_class.alloc().initWithFrame_(((0, 0), (0, 0)))
58
-
59
- def add_view(self, view):
60
- self.views.append(view)
61
- # Ensure view is a subview of scrollview
62
- if view.native_instance not in self.native_instance.subviews:
63
- self.native_instance.addSubview_(view.native_instance)
@@ -1,65 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class SearchBarBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_query(self, query: str) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def get_query(self) -> str:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/android/widget/SearchView
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class SearchBar(SearchBarBase, ViewBase):
34
- def __init__(self, context, query: str = "") -> None:
35
- super().__init__()
36
- self.native_class = jclass("android.widget.SearchView")
37
- self.native_instance = self.native_class(context)
38
- self.set_query(query)
39
-
40
- def set_query(self, query: str) -> None:
41
- self.native_instance.setQuery(query, False)
42
-
43
- def get_query(self) -> str:
44
- return self.native_instance.getQuery().toString()
45
-
46
- else:
47
- # ========================================
48
- # iOS class
49
- # https://developer.apple.com/documentation/uikit/uisearchbar
50
- # ========================================
51
-
52
- from rubicon.objc import ObjCClass
53
-
54
- class SearchBar(SearchBarBase, ViewBase):
55
- def __init__(self, query: str = "") -> None:
56
- super().__init__()
57
- self.native_class = ObjCClass("UISearchBar")
58
- self.native_instance = self.native_class.alloc().init()
59
- self.set_query(query)
60
-
61
- def set_query(self, query: str) -> None:
62
- self.native_instance.set_text_(query)
63
-
64
- def get_query(self) -> str:
65
- return self.native_instance.text()
@@ -1,60 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from typing import Any, List
3
-
4
- from .utils import IS_ANDROID, get_android_context
5
- from .view import ViewBase
6
-
7
- # ========================================
8
- # Base class
9
- # ========================================
10
-
11
-
12
- class StackViewBase(ABC):
13
- @abstractmethod
14
- def __init__(self) -> None:
15
- super().__init__()
16
- self.views: List[Any] = []
17
-
18
- @abstractmethod
19
- def add_view(self, view) -> None:
20
- pass
21
-
22
-
23
- if IS_ANDROID:
24
- # ========================================
25
- # Android class
26
- # https://developer.android.com/reference/android/widget/LinearLayout
27
- # ========================================
28
-
29
- from java import jclass
30
-
31
- class StackView(StackViewBase, ViewBase):
32
- def __init__(self) -> None:
33
- super().__init__()
34
- self.native_class = jclass("android.widget.LinearLayout")
35
- context = get_android_context()
36
- self.native_instance = self.native_class(context)
37
- self.native_instance.setOrientation(self.native_class.VERTICAL)
38
-
39
- def add_view(self, view):
40
- self.views.append(view)
41
- self.native_instance.addView(view.native_instance)
42
-
43
- else:
44
- # ========================================
45
- # iOS class
46
- # https://developer.apple.com/documentation/uikit/uistackview
47
- # ========================================
48
-
49
- from rubicon.objc import ObjCClass
50
-
51
- class StackView(StackViewBase, ViewBase):
52
- def __init__(self) -> None:
53
- super().__init__()
54
- self.native_class = ObjCClass("UIStackView")
55
- self.native_instance = self.native_class.alloc().initWithFrame_(((0, 0), (0, 0)))
56
- self.native_instance.setAxis_(0) # Set axis to vertical
57
-
58
- def add_view(self, view):
59
- self.views.append(view)
60
- self.native_instance.addArrangedSubview_(view.native_instance)
pythonnative/switch.py DELETED
@@ -1,66 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID, get_android_context
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class SwitchBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_on(self, value: bool) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def is_on(self) -> bool:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/android/widget/Switch
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class Switch(SwitchBase, ViewBase):
34
- def __init__(self, value: bool = False) -> None:
35
- super().__init__()
36
- self.native_class = jclass("android.widget.Switch")
37
- context = get_android_context()
38
- self.native_instance = self.native_class(context)
39
- self.set_on(value)
40
-
41
- def set_on(self, value: bool) -> None:
42
- self.native_instance.setChecked(value)
43
-
44
- def is_on(self) -> bool:
45
- return self.native_instance.isChecked()
46
-
47
- else:
48
- # ========================================
49
- # iOS class
50
- # https://developer.apple.com/documentation/uikit/uiswitch
51
- # ========================================
52
-
53
- from rubicon.objc import ObjCClass
54
-
55
- class Switch(SwitchBase, ViewBase):
56
- def __init__(self, value: bool = False) -> None:
57
- super().__init__()
58
- self.native_class = ObjCClass("UISwitch")
59
- self.native_instance = self.native_class.alloc().init()
60
- self.set_on(value)
61
-
62
- def set_on(self, value: bool) -> None:
63
- self.native_instance.setOn_animated_(value, False)
64
-
65
- def is_on(self) -> bool:
66
- return self.native_instance.isOn()
@@ -1,67 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from .utils import IS_ANDROID, get_android_context
4
- from .view import ViewBase
5
-
6
- # ========================================
7
- # Base class
8
- # ========================================
9
-
10
-
11
- class TextFieldBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_text(self, text: str) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def get_text(self) -> str:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/android/widget/EditText
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class TextField(TextFieldBase, ViewBase):
34
- def __init__(self, text: str = "") -> None:
35
- super().__init__()
36
- self.native_class = jclass("android.widget.EditText")
37
- context = get_android_context()
38
- self.native_instance = self.native_class(context)
39
- self.native_instance.setSingleLine(True)
40
- self.set_text(text)
41
-
42
- def set_text(self, text: str) -> None:
43
- self.native_instance.setText(text)
44
-
45
- def get_text(self) -> str:
46
- return self.native_instance.getText().toString()
47
-
48
- else:
49
- # ========================================
50
- # iOS class
51
- # https://developer.apple.com/documentation/uikit/uitextfield
52
- # ========================================
53
-
54
- from rubicon.objc import ObjCClass
55
-
56
- class TextField(TextFieldBase, ViewBase):
57
- def __init__(self, text: str = "") -> None:
58
- super().__init__()
59
- self.native_class = ObjCClass("UITextField")
60
- self.native_instance = self.native_class.alloc().init()
61
- self.set_text(text)
62
-
63
- def set_text(self, text: str) -> None:
64
- self.native_instance.setText_(text)
65
-
66
- def get_text(self) -> str:
67
- return self.native_instance.text()