pythonnative 0.0.1__py3-none-any.whl → 0.2.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.
- pythonnative/__init__.py +74 -0
- pythonnative/activity_indicator_view.py +71 -0
- pythonnative/button.py +109 -0
- pythonnative/cli/pn.py +616 -0
- pythonnative/date_picker.py +72 -0
- pythonnative/image_view.py +76 -0
- pythonnative/label.py +66 -0
- pythonnative/list_view.py +73 -0
- pythonnative/material_activity_indicator_view.py +69 -0
- pythonnative/material_bottom_navigation_view.py +0 -0
- pythonnative/material_button.py +65 -0
- pythonnative/material_date_picker.py +85 -0
- pythonnative/material_progress_view.py +66 -0
- pythonnative/material_search_bar.py +65 -0
- pythonnative/material_switch.py +65 -0
- pythonnative/material_time_picker.py +72 -0
- pythonnative/material_toolbar.py +0 -0
- pythonnative/page.py +209 -0
- pythonnative/picker_view.py +65 -0
- pythonnative/progress_view.py +68 -0
- pythonnative/scroll_view.py +63 -0
- pythonnative/search_bar.py +65 -0
- pythonnative/stack_view.py +60 -0
- pythonnative/switch.py +66 -0
- pythonnative/templates/android_template/app/build.gradle +59 -0
- pythonnative/templates/android_template/app/proguard-rules.pro +21 -0
- pythonnative/templates/android_template/app/src/androidTest/java/com/pythonnative/android_template/ExampleInstrumentedTest.kt +24 -0
- pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +26 -0
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +32 -0
- pythonnative/templates/android_template/app/src/main/res/drawable/ic_launcher_background.xml +170 -0
- pythonnative/templates/android_template/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +30 -0
- pythonnative/templates/android_template/app/src/main/res/layout/activity_main.xml +18 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
- pythonnative/templates/android_template/app/src/main/res/values/colors.xml +5 -0
- pythonnative/templates/android_template/app/src/main/res/values/strings.xml +3 -0
- pythonnative/templates/android_template/app/src/main/res/values/themes.xml +9 -0
- pythonnative/templates/android_template/app/src/main/res/values-night/themes.xml +7 -0
- pythonnative/templates/android_template/app/src/main/res/xml/backup_rules.xml +13 -0
- pythonnative/templates/android_template/app/src/main/res/xml/data_extraction_rules.xml +19 -0
- pythonnative/templates/android_template/app/src/test/java/com/pythonnative/android_template/ExampleUnitTest.kt +17 -0
- pythonnative/templates/android_template/build.gradle +7 -0
- pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.jar +0 -0
- pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +6 -0
- pythonnative/templates/android_template/gradle.properties +23 -0
- pythonnative/templates/android_template/gradlew +185 -0
- pythonnative/templates/android_template/gradlew.bat +89 -0
- pythonnative/templates/android_template/settings.gradle +16 -0
- pythonnative/templates/ios_template/ios_template/AppDelegate.swift +36 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/AppIcon.appiconset/Contents.json +13 -0
- pythonnative/templates/ios_template/ios_template/Assets.xcassets/Contents.json +6 -0
- pythonnative/templates/ios_template/ios_template/Base.lproj/LaunchScreen.storyboard +25 -0
- pythonnative/templates/ios_template/ios_template/Base.lproj/Main.storyboard +24 -0
- pythonnative/templates/ios_template/ios_template/Info.plist +25 -0
- pythonnative/templates/ios_template/ios_template/SceneDelegate.swift +52 -0
- pythonnative/templates/ios_template/ios_template/ViewController.swift +118 -0
- pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +648 -0
- pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift +36 -0
- pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift +41 -0
- pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift +32 -0
- pythonnative/text_field.py +67 -0
- pythonnative/text_view.py +70 -0
- pythonnative/time_picker.py +73 -0
- pythonnative/utils.py +67 -0
- pythonnative/view.py +25 -0
- pythonnative/web_view.py +58 -0
- pythonnative-0.2.0.dist-info/METADATA +137 -0
- pythonnative-0.2.0.dist-info/RECORD +86 -0
- {pythonnative-0.0.1.dist-info → pythonnative-0.2.0.dist-info}/WHEEL +1 -1
- pythonnative-0.2.0.dist-info/entry_points.txt +2 -0
- {pythonnative-0.0.1.dist-info → pythonnative-0.2.0.dist-info/licenses}/LICENSE +2 -2
- {pythonnative-0.0.1.dist-info → pythonnative-0.2.0.dist-info}/top_level.txt +0 -1
- pythonnative/pythonnative.py +0 -73
- pythonnative-0.0.1.dist-info/METADATA +0 -48
- pythonnative-0.0.1.dist-info/RECORD +0 -9
- {tests → pythonnative/cli}/__init__.py +0 -0
- /tests/test_pythonnative.py → /pythonnative/collection_view.py +0 -0
pythonnative/__init__.py
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from importlib import import_module
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
4
|
+
__version__ = "0.2.0"
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"ActivityIndicatorView",
|
|
8
|
+
"Button",
|
|
9
|
+
"DatePicker",
|
|
10
|
+
"ImageView",
|
|
11
|
+
"Label",
|
|
12
|
+
"ListView",
|
|
13
|
+
"MaterialActivityIndicatorView",
|
|
14
|
+
"MaterialButton",
|
|
15
|
+
"MaterialDatePicker",
|
|
16
|
+
"MaterialProgressView",
|
|
17
|
+
"MaterialSearchBar",
|
|
18
|
+
"MaterialSwitch",
|
|
19
|
+
"MaterialTimePicker",
|
|
20
|
+
"MaterialBottomNavigationView",
|
|
21
|
+
"MaterialToolbar",
|
|
22
|
+
"Page",
|
|
23
|
+
"PickerView",
|
|
24
|
+
"ProgressView",
|
|
25
|
+
"ScrollView",
|
|
26
|
+
"SearchBar",
|
|
27
|
+
"StackView",
|
|
28
|
+
"Switch",
|
|
29
|
+
"TextField",
|
|
30
|
+
"TextView",
|
|
31
|
+
"TimePicker",
|
|
32
|
+
"WebView",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
_NAME_TO_MODULE: Dict[str, str] = {
|
|
36
|
+
"ActivityIndicatorView": ".activity_indicator_view",
|
|
37
|
+
"Button": ".button",
|
|
38
|
+
"DatePicker": ".date_picker",
|
|
39
|
+
"ImageView": ".image_view",
|
|
40
|
+
"Label": ".label",
|
|
41
|
+
"ListView": ".list_view",
|
|
42
|
+
"MaterialActivityIndicatorView": ".material_activity_indicator_view",
|
|
43
|
+
"MaterialButton": ".material_button",
|
|
44
|
+
"MaterialDatePicker": ".material_date_picker",
|
|
45
|
+
"MaterialProgressView": ".material_progress_view",
|
|
46
|
+
"MaterialSearchBar": ".material_search_bar",
|
|
47
|
+
"MaterialSwitch": ".material_switch",
|
|
48
|
+
"MaterialTimePicker": ".material_time_picker",
|
|
49
|
+
"MaterialBottomNavigationView": ".material_bottom_navigation_view",
|
|
50
|
+
"MaterialToolbar": ".material_toolbar",
|
|
51
|
+
"Page": ".page",
|
|
52
|
+
"PickerView": ".picker_view",
|
|
53
|
+
"ProgressView": ".progress_view",
|
|
54
|
+
"ScrollView": ".scroll_view",
|
|
55
|
+
"SearchBar": ".search_bar",
|
|
56
|
+
"StackView": ".stack_view",
|
|
57
|
+
"Switch": ".switch",
|
|
58
|
+
"TextField": ".text_field",
|
|
59
|
+
"TextView": ".text_view",
|
|
60
|
+
"TimePicker": ".time_picker",
|
|
61
|
+
"WebView": ".web_view",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def __getattr__(name: str) -> Any:
|
|
66
|
+
module_path = _NAME_TO_MODULE.get(name)
|
|
67
|
+
if not module_path:
|
|
68
|
+
raise AttributeError(f"module 'pythonnative' has no attribute {name!r}")
|
|
69
|
+
module = import_module(module_path, package=__name__)
|
|
70
|
+
return getattr(module, name)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def __dir__() -> Any:
|
|
74
|
+
return sorted(list(globals().keys()) + __all__)
|
|
@@ -0,0 +1,71 @@
|
|
|
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 ActivityIndicatorViewBase(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/android/widget/ProgressBar
|
|
29
|
+
# ========================================
|
|
30
|
+
|
|
31
|
+
from java import jclass
|
|
32
|
+
|
|
33
|
+
class ActivityIndicatorView(ActivityIndicatorViewBase, 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.progressBarStyleLarge)
|
|
38
|
+
context = get_android_context()
|
|
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 ActivityIndicatorView(ActivityIndicatorViewBase, 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()
|
pythonnative/button.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Callable, Optional
|
|
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 ButtonBase(ABC):
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
super().__init__()
|
|
16
|
+
|
|
17
|
+
@abstractmethod
|
|
18
|
+
def set_title(self, title: str) -> None:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def get_title(self) -> str:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def set_on_click(self, callback: Callable[[], None]) -> None:
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if IS_ANDROID:
|
|
31
|
+
# ========================================
|
|
32
|
+
# Android class
|
|
33
|
+
# https://developer.android.com/reference/android/widget/Button
|
|
34
|
+
# ========================================
|
|
35
|
+
|
|
36
|
+
from java import dynamic_proxy, jclass
|
|
37
|
+
|
|
38
|
+
class Button(ButtonBase, ViewBase):
|
|
39
|
+
def __init__(self, title: str = "") -> None:
|
|
40
|
+
super().__init__()
|
|
41
|
+
self.native_class = jclass("android.widget.Button")
|
|
42
|
+
context = get_android_context()
|
|
43
|
+
self.native_instance = self.native_class(context)
|
|
44
|
+
self.set_title(title)
|
|
45
|
+
|
|
46
|
+
def set_title(self, title: str) -> None:
|
|
47
|
+
self.native_instance.setText(title)
|
|
48
|
+
|
|
49
|
+
def get_title(self) -> str:
|
|
50
|
+
return self.native_instance.getText().toString()
|
|
51
|
+
|
|
52
|
+
def set_on_click(self, callback: Callable[[], None]) -> None:
|
|
53
|
+
class OnClickListener(dynamic_proxy(jclass("android.view.View").OnClickListener)):
|
|
54
|
+
def __init__(self, callback):
|
|
55
|
+
super().__init__()
|
|
56
|
+
self.callback = callback
|
|
57
|
+
|
|
58
|
+
def onClick(self, view):
|
|
59
|
+
self.callback()
|
|
60
|
+
|
|
61
|
+
listener = OnClickListener(callback)
|
|
62
|
+
self.native_instance.setOnClickListener(listener)
|
|
63
|
+
|
|
64
|
+
else:
|
|
65
|
+
# ========================================
|
|
66
|
+
# iOS class
|
|
67
|
+
# https://developer.apple.com/documentation/uikit/uibutton
|
|
68
|
+
# ========================================
|
|
69
|
+
|
|
70
|
+
from rubicon.objc import SEL, ObjCClass, objc_method
|
|
71
|
+
|
|
72
|
+
NSObject = ObjCClass("NSObject")
|
|
73
|
+
|
|
74
|
+
# Mypy cannot understand Rubicon's dynamic subclassing; ignore the base type here.
|
|
75
|
+
class _PNButtonHandler(NSObject): # type: ignore[valid-type]
|
|
76
|
+
# Set by the Button when wiring up the target/action callback.
|
|
77
|
+
_callback: Optional[Callable[[], None]] = None
|
|
78
|
+
|
|
79
|
+
@objc_method
|
|
80
|
+
def onTap_(self, sender) -> None:
|
|
81
|
+
try:
|
|
82
|
+
callback = self._callback
|
|
83
|
+
if callback is not None:
|
|
84
|
+
callback()
|
|
85
|
+
except Exception:
|
|
86
|
+
# Swallow exceptions to avoid crashing the app; logging is handled at higher levels
|
|
87
|
+
pass
|
|
88
|
+
|
|
89
|
+
class Button(ButtonBase, ViewBase):
|
|
90
|
+
def __init__(self, title: str = "") -> None:
|
|
91
|
+
super().__init__()
|
|
92
|
+
self.native_class = ObjCClass("UIButton")
|
|
93
|
+
self.native_instance = self.native_class.alloc().init()
|
|
94
|
+
self.set_title(title)
|
|
95
|
+
|
|
96
|
+
def set_title(self, title: str) -> None:
|
|
97
|
+
self.native_instance.setTitle_forState_(title, 0)
|
|
98
|
+
|
|
99
|
+
def get_title(self) -> str:
|
|
100
|
+
return self.native_instance.titleForState_(0)
|
|
101
|
+
|
|
102
|
+
def set_on_click(self, callback: Callable[[], None]) -> None:
|
|
103
|
+
# Create a handler object with an Objective-C method `onTap:` and attach the Python callback
|
|
104
|
+
handler = _PNButtonHandler.new()
|
|
105
|
+
# Keep strong references to the handler and callback
|
|
106
|
+
self._click_handler = handler
|
|
107
|
+
handler._callback = callback
|
|
108
|
+
# UIControlEventTouchUpInside = 1 << 6
|
|
109
|
+
self.native_instance.addTarget_action_forControlEvents_(handler, SEL("onTap:"), 1 << 6)
|