pythonnative 0.4.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 (39) hide show
  1. pythonnative/__init__.py +45 -65
  2. pythonnative/cli/pn.py +15 -14
  3. pythonnative/components.py +241 -0
  4. pythonnative/element.py +47 -0
  5. pythonnative/native_views.py +800 -0
  6. pythonnative/page.py +319 -247
  7. pythonnative/reconciler.py +129 -0
  8. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PageFragment.kt +2 -1
  9. pythonnative/utils.py +21 -29
  10. {pythonnative-0.4.0.dist-info → pythonnative-0.5.0.dist-info}/METADATA +35 -17
  11. {pythonnative-0.4.0.dist-info → pythonnative-0.5.0.dist-info}/RECORD +15 -35
  12. pythonnative/activity_indicator_view.py +0 -71
  13. pythonnative/button.py +0 -113
  14. pythonnative/date_picker.py +0 -76
  15. pythonnative/image_view.py +0 -78
  16. pythonnative/label.py +0 -133
  17. pythonnative/list_view.py +0 -76
  18. pythonnative/material_activity_indicator_view.py +0 -71
  19. pythonnative/material_button.py +0 -69
  20. pythonnative/material_date_picker.py +0 -87
  21. pythonnative/material_progress_view.py +0 -70
  22. pythonnative/material_search_bar.py +0 -69
  23. pythonnative/material_switch.py +0 -69
  24. pythonnative/material_time_picker.py +0 -76
  25. pythonnative/picker_view.py +0 -69
  26. pythonnative/progress_view.py +0 -70
  27. pythonnative/scroll_view.py +0 -101
  28. pythonnative/search_bar.py +0 -69
  29. pythonnative/stack_view.py +0 -199
  30. pythonnative/switch.py +0 -68
  31. pythonnative/text_field.py +0 -132
  32. pythonnative/text_view.py +0 -135
  33. pythonnative/time_picker.py +0 -77
  34. pythonnative/view.py +0 -173
  35. pythonnative/web_view.py +0 -60
  36. {pythonnative-0.4.0.dist-info → pythonnative-0.5.0.dist-info}/WHEEL +0 -0
  37. {pythonnative-0.4.0.dist-info → pythonnative-0.5.0.dist-info}/entry_points.txt +0 -0
  38. {pythonnative-0.4.0.dist-info → pythonnative-0.5.0.dist-info}/licenses/LICENSE +0 -0
  39. {pythonnative-0.4.0.dist-info → pythonnative-0.5.0.dist-info}/top_level.txt +0 -0
@@ -1,78 +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 ImageViewBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_image(self, image: str) -> "ImageViewBase":
18
- pass
19
-
20
- @abstractmethod
21
- def get_image(self) -> str:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/android/widget/ImageView
29
- # ========================================
30
-
31
- from android.graphics import BitmapFactory
32
- from java import jclass
33
-
34
- class ImageView(ImageViewBase, ViewBase):
35
- def __init__(self, image: str = "") -> None:
36
- super().__init__()
37
- self.native_class = jclass("android.widget.ImageView")
38
- context = get_android_context()
39
- self.native_instance = self.native_class(context)
40
- if image:
41
- self.set_image(image)
42
-
43
- def set_image(self, image: str) -> "ImageView":
44
- bitmap = BitmapFactory.decodeFile(image)
45
- self.native_instance.setImageBitmap(bitmap)
46
- return self
47
-
48
- def get_image(self) -> str:
49
- # Please note that this is a simplistic representation, getting image from ImageView
50
- # in Android would require converting Drawable to Bitmap and then to File
51
- return "Image file path in Android"
52
-
53
- else:
54
- # ========================================
55
- # iOS class
56
- # https://developer.apple.com/documentation/uikit/uiimageview
57
- # ========================================
58
-
59
- from rubicon.objc import ObjCClass
60
- from rubicon.objc.api import NSString, UIImage
61
-
62
- class ImageView(ImageViewBase, ViewBase):
63
- def __init__(self, image: str = "") -> None:
64
- super().__init__()
65
- self.native_class = ObjCClass("UIImageView")
66
- self.native_instance = self.native_class.alloc().init()
67
- if image:
68
- self.set_image(image)
69
-
70
- def set_image(self, image: str) -> "ImageView":
71
- ns_str = NSString.alloc().initWithUTF8String_(image)
72
- ui_image = UIImage.imageNamed_(ns_str)
73
- self.native_instance.setImage_(ui_image)
74
- return self
75
-
76
- def get_image(self) -> str:
77
- # Similar to Android, getting the image from UIImageView isn't straightforward.
78
- return "Image file name in iOS"
pythonnative/label.py DELETED
@@ -1,133 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from typing import Any
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 LabelBase(ABC):
13
- @abstractmethod
14
- def __init__(self) -> None:
15
- super().__init__()
16
-
17
- @abstractmethod
18
- def set_text(self, text: str) -> "LabelBase":
19
- pass
20
-
21
- @abstractmethod
22
- def get_text(self) -> str:
23
- pass
24
-
25
- @abstractmethod
26
- def set_text_color(self, color: Any) -> "LabelBase":
27
- pass
28
-
29
- @abstractmethod
30
- def set_text_size(self, size: float) -> "LabelBase":
31
- pass
32
-
33
-
34
- if IS_ANDROID:
35
- # ========================================
36
- # Android class
37
- # https://developer.android.com/reference/android/widget/TextView
38
- # ========================================
39
-
40
- from java import jclass
41
-
42
- class Label(LabelBase, ViewBase):
43
- def __init__(self, text: str = "") -> None:
44
- super().__init__()
45
- self.native_class = jclass("android.widget.TextView")
46
- context = get_android_context()
47
- self.native_instance = self.native_class(context)
48
- self.set_text(text)
49
-
50
- def set_text(self, text: str) -> "Label":
51
- self.native_instance.setText(text)
52
- return self
53
-
54
- def get_text(self) -> str:
55
- return self.native_instance.getText().toString()
56
-
57
- def set_text_color(self, color: Any) -> "Label":
58
- # Accept int ARGB or hex string
59
- if isinstance(color, str):
60
- c = color.strip()
61
- if c.startswith("#"):
62
- c = c[1:]
63
- if len(c) == 6:
64
- c = "FF" + c
65
- color_int = int(c, 16)
66
- else:
67
- color_int = int(color)
68
- try:
69
- self.native_instance.setTextColor(color_int)
70
- except Exception:
71
- pass
72
- return self
73
-
74
- def set_text_size(self, size_sp: float) -> "Label":
75
- try:
76
- self.native_instance.setTextSize(float(size_sp))
77
- except Exception:
78
- pass
79
- return self
80
-
81
- else:
82
- # ========================================
83
- # iOS class
84
- # https://developer.apple.com/documentation/uikit/uilabel
85
- # ========================================
86
-
87
- from rubicon.objc import ObjCClass
88
-
89
- class Label(LabelBase, ViewBase):
90
- def __init__(self, text: str = "") -> None:
91
- super().__init__()
92
- self.native_class = ObjCClass("UILabel")
93
- self.native_instance = self.native_class.alloc().init()
94
- self.set_text(text)
95
-
96
- def set_text(self, text: str) -> "Label":
97
- self.native_instance.setText_(text)
98
- return self
99
-
100
- def get_text(self) -> str:
101
- return self.native_instance.text()
102
-
103
- def set_text_color(self, color: Any) -> "Label":
104
- # Accept int ARGB or hex string
105
- if isinstance(color, str):
106
- c = color.strip()
107
- if c.startswith("#"):
108
- c = c[1:]
109
- if len(c) == 6:
110
- c = "FF" + c
111
- color_int = int(c, 16)
112
- else:
113
- color_int = int(color)
114
- try:
115
- UIColor = ObjCClass("UIColor")
116
- a = ((color_int >> 24) & 0xFF) / 255.0
117
- r = ((color_int >> 16) & 0xFF) / 255.0
118
- g = ((color_int >> 8) & 0xFF) / 255.0
119
- b = (color_int & 0xFF) / 255.0
120
- color_obj = UIColor.colorWithRed_green_blue_alpha_(r, g, b, a)
121
- self.native_instance.setTextColor_(color_obj)
122
- except Exception:
123
- pass
124
- return self
125
-
126
- def set_text_size(self, size: float) -> "Label":
127
- try:
128
- UIFont = ObjCClass("UIFont")
129
- font = UIFont.systemFontOfSize_(float(size))
130
- self.native_instance.setFont_(font)
131
- except Exception:
132
- pass
133
- return self
pythonnative/list_view.py DELETED
@@ -1,76 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from typing import Any
3
-
4
- from .utils import IS_ANDROID
5
- from .view import ViewBase
6
-
7
- # ========================================
8
- # Base class
9
- # ========================================
10
-
11
-
12
- class ListViewBase(ABC):
13
- @abstractmethod
14
- def __init__(self) -> None:
15
- super().__init__()
16
-
17
- @abstractmethod
18
- def set_data(self, data: list) -> "ListViewBase":
19
- pass
20
-
21
- @abstractmethod
22
- def get_data(self) -> list:
23
- pass
24
-
25
-
26
- if IS_ANDROID:
27
- # ========================================
28
- # Android class
29
- # https://developer.android.com/reference/android/widget/ListView
30
- # ========================================
31
-
32
- from java import jclass
33
-
34
- class ListView(ListViewBase, ViewBase):
35
- def __init__(self, context: Any, data: list = []) -> None:
36
- super().__init__()
37
- self.context = context
38
- self.native_class = jclass("android.widget.ListView")
39
- self.native_instance = self.native_class(context)
40
- self.set_data(data)
41
-
42
- def set_data(self, data: list) -> "ListView":
43
- adapter = jclass("android.widget.ArrayAdapter")(
44
- self.context, jclass("android.R$layout").simple_list_item_1, data
45
- )
46
- self.native_instance.setAdapter(adapter)
47
- return self
48
-
49
- def get_data(self) -> list:
50
- adapter = self.native_instance.getAdapter()
51
- return [adapter.getItem(i) for i in range(adapter.getCount())]
52
-
53
- else:
54
- # ========================================
55
- # iOS class
56
- # https://developer.apple.com/documentation/uikit/uitableview
57
- # ========================================
58
-
59
- from rubicon.objc import ObjCClass
60
-
61
- class ListView(ListViewBase, ViewBase):
62
- def __init__(self, data: list = []) -> None:
63
- super().__init__()
64
- self.native_class = ObjCClass("UITableView")
65
- self.native_instance = self.native_class.alloc().init()
66
- self.set_data(data)
67
-
68
- def set_data(self, data: list) -> "ListView":
69
- # Note: This is a simplified representation. Normally, you would need to create a UITableViewDataSource.
70
- self.native_instance.reloadData()
71
- return self
72
-
73
- def get_data(self) -> list:
74
- # Note: This is a simplified representation.
75
- # Normally, you would need to get data from the UITableViewDataSource.
76
- return []
@@ -1,71 +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 MaterialActivityIndicatorViewBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def start_animating(self) -> None:
18
- pass
19
-
20
- @abstractmethod
21
- def stop_animating(self) -> None:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/com/google/android/material/progressindicator/CircularProgressIndicator
29
- # ========================================
30
-
31
- from typing import Any
32
-
33
- from java import jclass
34
-
35
- class MaterialActivityIndicatorView(MaterialActivityIndicatorViewBase, ViewBase):
36
- def __init__(self, context: Any) -> None:
37
- super().__init__()
38
- self.native_class = jclass("com.google.android.material.progressindicator.CircularProgressIndicator")
39
- self.native_instance = self.native_class(context)
40
- self.native_instance.setIndeterminate(True)
41
-
42
- def start_animating(self) -> None:
43
- # self.native_instance.setVisibility(android.view.View.VISIBLE)
44
- return
45
-
46
- def stop_animating(self) -> None:
47
- # self.native_instance.setVisibility(android.view.View.GONE)
48
- return
49
-
50
- else:
51
- # ========================================
52
- # iOS class
53
- # https://developer.apple.com/documentation/uikit/uiactivityindicatorview
54
- # ========================================
55
-
56
- from rubicon.objc import ObjCClass
57
-
58
- class MaterialActivityIndicatorView(MaterialActivityIndicatorViewBase, ViewBase):
59
- def __init__(self) -> None:
60
- super().__init__()
61
- self.native_class = ObjCClass("UIActivityIndicatorView")
62
- self.native_instance = self.native_class.alloc().initWithActivityIndicatorStyle_(
63
- 0
64
- ) # 0: UIActivityIndicatorViewStyleLarge
65
- self.native_instance.hidesWhenStopped = True
66
-
67
- def start_animating(self) -> None:
68
- self.native_instance.startAnimating()
69
-
70
- def stop_animating(self) -> None:
71
- self.native_instance.stopAnimating()
@@ -1,69 +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 MaterialButtonBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_title(self, title: str) -> "MaterialButtonBase":
18
- pass
19
-
20
- @abstractmethod
21
- def get_title(self) -> str:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/com/google/android/material/button/MaterialButton
29
- # ========================================
30
-
31
- from typing import Any
32
-
33
- from java import jclass
34
-
35
- class MaterialButton(MaterialButtonBase, ViewBase):
36
- def __init__(self, context: Any, title: str = "") -> None:
37
- super().__init__()
38
- self.native_class = jclass("com.google.android.material.button.MaterialButton")
39
- self.native_instance = self.native_class(context)
40
- self.set_title(title)
41
-
42
- def set_title(self, title: str) -> "MaterialButton":
43
- self.native_instance.setText(title)
44
- return self
45
-
46
- def get_title(self) -> str:
47
- return self.native_instance.getText().toString()
48
-
49
- else:
50
- # ========================================
51
- # iOS class
52
- # https://developer.apple.com/documentation/uikit/uibutton
53
- # ========================================
54
-
55
- from rubicon.objc import ObjCClass
56
-
57
- class MaterialButton(MaterialButtonBase, ViewBase):
58
- def __init__(self, title: str = "") -> None:
59
- super().__init__()
60
- self.native_class = ObjCClass("UIButton") # Apple does not have a direct equivalent for MaterialButton
61
- self.native_instance = self.native_class.alloc().init()
62
- self.set_title(title)
63
-
64
- def set_title(self, title: str) -> "MaterialButton":
65
- self.native_instance.setTitle_forState_(title, 0)
66
- return self
67
-
68
- def get_title(self) -> str:
69
- return self.native_instance.titleForState_(0)
@@ -1,87 +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 MaterialDatePickerBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_date(self, year: int, month: int, day: int) -> "MaterialDatePickerBase":
18
- pass
19
-
20
- @abstractmethod
21
- def get_date(self) -> tuple:
22
- pass
23
-
24
-
25
- if IS_ANDROID:
26
- # ========================================
27
- # Android class
28
- # https://developer.android.com/reference/com/google/android/material/datepicker/MaterialDatePicker
29
- # ========================================
30
-
31
- from java import jclass
32
-
33
- class MaterialDatePicker(MaterialDatePickerBase, ViewBase):
34
- def __init__(self, year: int = 0, month: int = 0, day: int = 0) -> None:
35
- super().__init__()
36
- self.native_class = jclass("com.google.android.material.datepicker.MaterialDatePicker")
37
- self.builder = self.native_class.Builder.datePicker()
38
- self.set_date(year, month, day)
39
- self.native_instance = self.builder.build()
40
-
41
- def set_date(self, year: int, month: int, day: int) -> "MaterialDatePicker":
42
- # MaterialDatePicker uses milliseconds since epoch to set date
43
- from java.util import Calendar
44
-
45
- cal = Calendar.getInstance()
46
- cal.set(year, month, day)
47
- milliseconds = cal.getTimeInMillis()
48
- self.builder.setSelection(milliseconds)
49
- return self
50
-
51
- def get_date(self) -> tuple:
52
- # Convert selection (milliseconds since epoch) back to a date
53
- from java.util import Calendar
54
-
55
- cal = Calendar.getInstance()
56
- cal.setTimeInMillis(self.native_instance.getSelection())
57
- return (
58
- cal.get(Calendar.YEAR),
59
- cal.get(Calendar.MONTH),
60
- cal.get(Calendar.DAY_OF_MONTH),
61
- )
62
-
63
- else:
64
- # ========================================
65
- # iOS class
66
- # https://developer.apple.com/documentation/uikit/uidatepicker
67
- # ========================================
68
-
69
- from datetime import datetime
70
-
71
- from rubicon.objc import ObjCClass
72
-
73
- class MaterialDatePicker(MaterialDatePickerBase, ViewBase):
74
- def __init__(self, year: int = 0, month: int = 0, day: int = 0) -> None:
75
- super().__init__()
76
- self.native_class = ObjCClass("UIDatePicker")
77
- self.native_instance = self.native_class.alloc().init()
78
- self.set_date(year, month, day)
79
-
80
- def set_date(self, year: int, month: int, day: int) -> "MaterialDatePicker":
81
- date = datetime(year, month, day)
82
- self.native_instance.setDate_(date)
83
- return self
84
-
85
- def get_date(self) -> tuple:
86
- date = self.native_instance.date()
87
- return date.year, date.month, date.day
@@ -1,70 +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 MaterialProgressViewBase(ABC):
12
- @abstractmethod
13
- def __init__(self) -> None:
14
- super().__init__()
15
-
16
- @abstractmethod
17
- def set_progress(self, progress: float) -> "MaterialProgressViewBase":
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/com/google/android/material/progressindicator/LinearProgressIndicator
29
- # ========================================
30
-
31
- from typing import Any
32
-
33
- from java import jclass
34
-
35
- class MaterialProgressView(MaterialProgressViewBase, ViewBase):
36
- def __init__(self, context: Any) -> None:
37
- super().__init__()
38
- self.native_class = jclass("com.google.android.material.progressindicator.LinearProgressIndicator")
39
- self.native_instance = self.native_class(context)
40
- self.native_instance.setIndeterminate(False)
41
-
42
- def set_progress(self, progress: float) -> "MaterialProgressView":
43
- self.native_instance.setProgress(int(progress * 100))
44
- return self
45
-
46
- def get_progress(self) -> float:
47
- return self.native_instance.getProgress() / 100.0
48
-
49
- else:
50
- # ========================================
51
- # iOS class
52
- # https://developer.apple.com/documentation/uikit/uiprogressview
53
- # ========================================
54
-
55
- from rubicon.objc import ObjCClass
56
-
57
- class MaterialProgressView(MaterialProgressViewBase, ViewBase):
58
- def __init__(self) -> None:
59
- super().__init__()
60
- self.native_class = ObjCClass("UIProgressView")
61
- self.native_instance = self.native_class.alloc().initWithProgressViewStyle_(
62
- 0
63
- ) # 0: UIProgressViewStyleDefault
64
-
65
- def set_progress(self, progress: float) -> "MaterialProgressView":
66
- self.native_instance.setProgress_animated_(progress, False)
67
- return self
68
-
69
- def get_progress(self) -> float:
70
- return self.native_instance.progress()
@@ -1,69 +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) -> "MaterialSearchBarBase":
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 typing import Any
32
-
33
- from java import jclass
34
-
35
- class MaterialSearchBar(MaterialSearchBarBase, ViewBase):
36
- def __init__(self, context: Any, query: str = "") -> None:
37
- super().__init__()
38
- self.native_class = jclass("com.google.android.material.search.SearchBar")
39
- self.native_instance = self.native_class(context)
40
- self.set_query(query)
41
-
42
- def set_query(self, query: str) -> "MaterialSearchBar":
43
- self.native_instance.setQuery(query, False)
44
- return self
45
-
46
- def get_query(self) -> str:
47
- return self.native_instance.getQuery().toString()
48
-
49
- else:
50
- # ========================================
51
- # iOS class
52
- # https://developer.apple.com/documentation/uikit/uisearchbar
53
- # ========================================
54
-
55
- from rubicon.objc import ObjCClass
56
-
57
- class MaterialSearchBar(MaterialSearchBarBase, ViewBase):
58
- def __init__(self, query: str = "") -> None:
59
- super().__init__()
60
- self.native_class = ObjCClass("UISearchBar")
61
- self.native_instance = self.native_class.alloc().init()
62
- self.set_query(query)
63
-
64
- def set_query(self, query: str) -> "MaterialSearchBar":
65
- self.native_instance.set_searchText_(query)
66
- return self
67
-
68
- def get_query(self) -> str:
69
- return self.native_instance.searchText()