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.
Files changed (89) hide show
  1. pythonnative/__init__.py +74 -0
  2. pythonnative/activity_indicator_view.py +71 -0
  3. pythonnative/button.py +109 -0
  4. pythonnative/cli/pn.py +616 -0
  5. pythonnative/date_picker.py +72 -0
  6. pythonnative/image_view.py +76 -0
  7. pythonnative/label.py +66 -0
  8. pythonnative/list_view.py +73 -0
  9. pythonnative/material_activity_indicator_view.py +69 -0
  10. pythonnative/material_bottom_navigation_view.py +0 -0
  11. pythonnative/material_button.py +65 -0
  12. pythonnative/material_date_picker.py +85 -0
  13. pythonnative/material_progress_view.py +66 -0
  14. pythonnative/material_search_bar.py +65 -0
  15. pythonnative/material_switch.py +65 -0
  16. pythonnative/material_time_picker.py +72 -0
  17. pythonnative/material_toolbar.py +0 -0
  18. pythonnative/page.py +209 -0
  19. pythonnative/picker_view.py +65 -0
  20. pythonnative/progress_view.py +68 -0
  21. pythonnative/scroll_view.py +63 -0
  22. pythonnative/search_bar.py +65 -0
  23. pythonnative/stack_view.py +60 -0
  24. pythonnative/switch.py +66 -0
  25. pythonnative/templates/android_template/app/build.gradle +59 -0
  26. pythonnative/templates/android_template/app/proguard-rules.pro +21 -0
  27. pythonnative/templates/android_template/app/src/androidTest/java/com/pythonnative/android_template/ExampleInstrumentedTest.kt +24 -0
  28. pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +26 -0
  29. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +32 -0
  30. pythonnative/templates/android_template/app/src/main/res/drawable/ic_launcher_background.xml +170 -0
  31. pythonnative/templates/android_template/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +30 -0
  32. pythonnative/templates/android_template/app/src/main/res/layout/activity_main.xml +18 -0
  33. pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
  34. pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
  35. pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
  36. pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
  37. pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
  38. pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
  39. pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
  40. pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
  41. pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
  42. pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
  43. pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
  44. pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
  45. pythonnative/templates/android_template/app/src/main/res/values/colors.xml +5 -0
  46. pythonnative/templates/android_template/app/src/main/res/values/strings.xml +3 -0
  47. pythonnative/templates/android_template/app/src/main/res/values/themes.xml +9 -0
  48. pythonnative/templates/android_template/app/src/main/res/values-night/themes.xml +7 -0
  49. pythonnative/templates/android_template/app/src/main/res/xml/backup_rules.xml +13 -0
  50. pythonnative/templates/android_template/app/src/main/res/xml/data_extraction_rules.xml +19 -0
  51. pythonnative/templates/android_template/app/src/test/java/com/pythonnative/android_template/ExampleUnitTest.kt +17 -0
  52. pythonnative/templates/android_template/build.gradle +7 -0
  53. pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.jar +0 -0
  54. pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +6 -0
  55. pythonnative/templates/android_template/gradle.properties +23 -0
  56. pythonnative/templates/android_template/gradlew +185 -0
  57. pythonnative/templates/android_template/gradlew.bat +89 -0
  58. pythonnative/templates/android_template/settings.gradle +16 -0
  59. pythonnative/templates/ios_template/ios_template/AppDelegate.swift +36 -0
  60. pythonnative/templates/ios_template/ios_template/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  61. pythonnative/templates/ios_template/ios_template/Assets.xcassets/AppIcon.appiconset/Contents.json +13 -0
  62. pythonnative/templates/ios_template/ios_template/Assets.xcassets/Contents.json +6 -0
  63. pythonnative/templates/ios_template/ios_template/Base.lproj/LaunchScreen.storyboard +25 -0
  64. pythonnative/templates/ios_template/ios_template/Base.lproj/Main.storyboard +24 -0
  65. pythonnative/templates/ios_template/ios_template/Info.plist +25 -0
  66. pythonnative/templates/ios_template/ios_template/SceneDelegate.swift +52 -0
  67. pythonnative/templates/ios_template/ios_template/ViewController.swift +118 -0
  68. pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +648 -0
  69. pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  70. pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift +36 -0
  71. pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift +41 -0
  72. pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift +32 -0
  73. pythonnative/text_field.py +67 -0
  74. pythonnative/text_view.py +70 -0
  75. pythonnative/time_picker.py +73 -0
  76. pythonnative/utils.py +67 -0
  77. pythonnative/view.py +25 -0
  78. pythonnative/web_view.py +58 -0
  79. pythonnative-0.2.0.dist-info/METADATA +137 -0
  80. pythonnative-0.2.0.dist-info/RECORD +86 -0
  81. {pythonnative-0.0.1.dist-info → pythonnative-0.2.0.dist-info}/WHEEL +1 -1
  82. pythonnative-0.2.0.dist-info/entry_points.txt +2 -0
  83. {pythonnative-0.0.1.dist-info → pythonnative-0.2.0.dist-info/licenses}/LICENSE +2 -2
  84. {pythonnative-0.0.1.dist-info → pythonnative-0.2.0.dist-info}/top_level.txt +0 -1
  85. pythonnative/pythonnative.py +0 -73
  86. pythonnative-0.0.1.dist-info/METADATA +0 -48
  87. pythonnative-0.0.1.dist-info/RECORD +0 -9
  88. {tests → pythonnative/cli}/__init__.py +0 -0
  89. /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)