| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6962d38 commit 86e4ffc
25 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any | ||
| 2 | + | ||
| 1 | 3 | import pythonnative as pn | |
| 2 | 4 | ||
| 3 | 5 | try: | |
@@ -10,16 +12,16 @@ | |||
| 10 | 12 | ||
| 11 | 13 | ||
| 12 | 14 | class MainPage(pn.Page): | |
| 13 | - def __init__(self, native_instance): | ||
| 15 | + def __init__(self, native_instance: Any) -> None: | ||
| 14 | 16 | super().__init__(native_instance) | |
| 15 | 17 | ||
| 16 | - def on_create(self): | ||
| 18 | + def on_create(self) -> None: | ||
| 17 | 19 | super().on_create() | |
| 18 | 20 | stack = pn.StackView().set_axis("vertical").set_spacing(12).set_alignment("fill").set_padding(all=16) | |
| 19 | 21 | stack.add_view(pn.Label("Hello from PythonNative Demo!").set_text_size(18)) | |
| 20 | 22 | button = pn.Button("Go to Second Page").set_padding(vertical=10, horizontal=14) | |
| 21 | 23 | ||
| 22 | - def on_next(): | ||
| 24 | + def on_next() -> None: | ||
| 23 | 25 | # Visual confirmation that tap worked (iOS only) | |
| 24 | 26 | try: | |
| 25 | 27 | if UIColor is not None: | |
@@ -36,26 +38,26 @@ def on_next(): | |||
| 36 | 38 | stack.add_view(button) | |
| 37 | 39 | self.set_root_view(stack.wrap_in_scroll()) | |
| 38 | 40 | ||
| 39 | - def on_start(self): | ||
| 41 | + def on_start(self) -> None: | ||
| 40 | 42 | super().on_start() | |
| 41 | 43 | ||
| 42 | - def on_resume(self): | ||
| 44 | + def on_resume(self) -> None: | ||
| 43 | 45 | super().on_resume() | |
| 44 | 46 | ||
| 45 | - def on_pause(self): | ||
| 47 | + def on_pause(self) -> None: | ||
| 46 | 48 | super().on_pause() | |
| 47 | 49 | ||
| 48 | - def on_stop(self): | ||
| 50 | + def on_stop(self) -> None: | ||
| 49 | 51 | super().on_stop() | |
| 50 | 52 | ||
| 51 | - def on_destroy(self): | ||
| 53 | + def on_destroy(self) -> None: | ||
| 52 | 54 | super().on_destroy() | |
| 53 | 55 | ||
| 54 | - def on_restart(self): | ||
| 56 | + def on_restart(self) -> None: | ||
| 55 | 57 | super().on_restart() | |
| 56 | 58 | ||
| 57 | - def on_save_instance_state(self): | ||
| 59 | + def on_save_instance_state(self) -> None: | ||
| 58 | 60 | super().on_save_instance_state() | |
| 59 | 61 | ||
| 60 | - def on_restore_instance_state(self): | ||
| 62 | + def on_restore_instance_state(self) -> None: | ||
| 61 | 63 | super().on_restore_instance_state() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any | ||
| 2 | + | ||
| 1 | 3 | import pythonnative as pn | |
| 2 | 4 | ||
| 3 | 5 | try: | |
@@ -10,10 +12,10 @@ | |||
| 10 | 12 | ||
| 11 | 13 | ||
| 12 | 14 | class SecondPage(pn.Page): | |
| 13 | - def __init__(self, native_instance): | ||
| 15 | + def __init__(self, native_instance: Any) -> None: | ||
| 14 | 16 | super().__init__(native_instance) | |
| 15 | 17 | ||
| 16 | - def on_create(self): | ||
| 18 | + def on_create(self) -> None: | ||
| 17 | 19 | super().on_create() | |
| 18 | 20 | stack_view = pn.StackView() | |
| 19 | 21 | # Read args passed from MainPage | |
@@ -30,7 +32,7 @@ def on_create(self): | |||
| 30 | 32 | except Exception: | |
| 31 | 33 | pass | |
| 32 | 34 | ||
| 33 | - def on_next(): | ||
| 35 | + def on_next() -> None: | ||
| 34 | 36 | # Visual confirmation that tap worked (iOS only) | |
| 35 | 37 | try: | |
| 36 | 38 | if UIColor is not None: | |
@@ -47,26 +49,26 @@ def on_next(): | |||
| 47 | 49 | stack_view.add_view(back_btn) | |
| 48 | 50 | self.set_root_view(stack_view) | |
| 49 | 51 | ||
| 50 | - def on_start(self): | ||
| 52 | + def on_start(self) -> None: | ||
| 51 | 53 | super().on_start() | |
| 52 | 54 | ||
| 53 | - def on_resume(self): | ||
| 55 | + def on_resume(self) -> None: | ||
| 54 | 56 | super().on_resume() | |
| 55 | 57 | ||
| 56 | - def on_pause(self): | ||
| 58 | + def on_pause(self) -> None: | ||
| 57 | 59 | super().on_pause() | |
| 58 | 60 | ||
| 59 | - def on_stop(self): | ||
| 61 | + def on_stop(self) -> None: | ||
| 60 | 62 | super().on_stop() | |
| 61 | 63 | ||
| 62 | - def on_destroy(self): | ||
| 64 | + def on_destroy(self) -> None: | ||
| 63 | 65 | super().on_destroy() | |
| 64 | 66 | ||
| 65 | - def on_restart(self): | ||
| 67 | + def on_restart(self) -> None: | ||
| 66 | 68 | super().on_restart() | |
| 67 | 69 | ||
| 68 | - def on_save_instance_state(self): | ||
| 70 | + def on_save_instance_state(self) -> None: | ||
| 69 | 71 | super().on_save_instance_state() | |
| 70 | 72 | ||
| 71 | - def on_restore_instance_state(self): | ||
| 73 | + def on_restore_instance_state(self) -> None: | ||
| 72 | 74 | super().on_restore_instance_state() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any | ||
| 2 | + | ||
| 1 | 3 | import pythonnative as pn | |
| 2 | 4 | ||
| 3 | 5 | try: | |
@@ -10,10 +12,10 @@ | |||
| 10 | 12 | ||
| 11 | 13 | ||
| 12 | 14 | class ThirdPage(pn.Page): | |
| 13 | - def __init__(self, native_instance): | ||
| 15 | + def __init__(self, native_instance: Any) -> None: | ||
| 14 | 16 | super().__init__(native_instance) | |
| 15 | 17 | ||
| 16 | - def on_create(self): | ||
| 18 | + def on_create(self) -> None: | ||
| 17 | 19 | super().on_create() | |
| 18 | 20 | stack = pn.StackView() | |
| 19 | 21 | stack.add_view(pn.Label("This is the Third Page")) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,8 @@ strict_optional = False | |||
| 8 | 8 | pretty = True | |
| 9 | 9 | files = src, tests, examples | |
| 10 | 10 | exclude = (^build/|^examples/.*/build/) | |
| 11 | + disallow_untyped_defs = True | ||
| 12 | + disallow_incomplete_defs = True | ||
| 11 | 13 | ||
| 12 | 14 | [mypy-pythonnative.*] | |
| 13 | 15 | implicit_reexport = True | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | from abc import ABC, abstractmethod | |
| 2 | - from typing import Callable, Optional | ||
| 2 | + from typing import Any, Callable, Optional | ||
| 3 | 3 | ||
| 4 | 4 | from .utils import IS_ANDROID, get_android_context | |
| 5 | 5 | from .view import ViewBase | |
@@ -15,15 +15,15 @@ def __init__(self) -> None: | |||
| 15 | 15 | super().__init__() | |
| 16 | 16 | ||
| 17 | 17 | @abstractmethod | |
| 18 | - def set_title(self, title: str) -> None: | ||
| 18 | + def set_title(self, title: str) -> "ButtonBase": | ||
| 19 | 19 | pass | |
| 20 | 20 | ||
| 21 | 21 | @abstractmethod | |
| 22 | 22 | def get_title(self) -> str: | |
| 23 | 23 | pass | |
| 24 | 24 | ||
| 25 | 25 | @abstractmethod | |
| 26 | - def set_on_click(self, callback: Callable[[], None]) -> None: | ||
| 26 | + def set_on_click(self, callback: Callable[[], None]) -> "ButtonBase": | ||
| 27 | 27 | pass | |
| 28 | 28 | ||
| 29 | 29 | ||
@@ -43,20 +43,20 @@ def __init__(self, title: str = "") -> None: | |||
| 43 | 43 | self.native_instance = self.native_class(context) | |
| 44 | 44 | self.set_title(title) | |
| 45 | 45 | ||
| 46 | - def set_title(self, title: str): | ||
| 46 | + def set_title(self, title: str) -> "Button": | ||
| 47 | 47 | self.native_instance.setText(title) | |
| 48 | 48 | return self | |
| 49 | 49 | ||
| 50 | 50 | def get_title(self) -> str: | |
| 51 | 51 | return self.native_instance.getText().toString() | |
| 52 | 52 | ||
| 53 | - def set_on_click(self, callback: Callable[[], None]): | ||
| 53 | + def set_on_click(self, callback: Callable[[], None]) -> "Button": | ||
| 54 | 54 | class OnClickListener(dynamic_proxy(jclass("android.view.View").OnClickListener)): | |
| 55 | - def __init__(self, callback): | ||
| 55 | + def __init__(self, callback: Callable[[], None]) -> None: | ||
| 56 | 56 | super().__init__() | |
| 57 | 57 | self.callback = callback | |
| 58 | 58 | ||
| 59 | - def onClick(self, view): | ||
| 59 | + def onClick(self, view: Any) -> None: | ||
| 60 | 60 | self.callback() | |
| 61 | 61 | ||
| 62 | 62 | listener = OnClickListener(callback) | |
@@ -79,7 +79,7 @@ class _PNButtonHandler(NSObject): # type: ignore[valid-type] | |||
| 79 | 79 | _callback: Optional[Callable[[], None]] = None | |
| 80 | 80 | ||
| 81 | 81 | @objc_method | |
| 82 | - def onTap_(self, sender) -> None: | ||
| 82 | + def onTap_(self, sender: Any) -> None: | ||
| 83 | 83 | try: | |
| 84 | 84 | callback = self._callback | |
| 85 | 85 | if callback is not None: | |
@@ -95,14 +95,14 @@ def __init__(self, title: str = "") -> None: | |||
| 95 | 95 | self.native_instance = self.native_class.alloc().init() | |
| 96 | 96 | self.set_title(title) | |
| 97 | 97 | ||
| 98 | - def set_title(self, title: str): | ||
| 98 | + def set_title(self, title: str) -> "Button": | ||
| 99 | 99 | self.native_instance.setTitle_forState_(title, 0) | |
| 100 | 100 | return self | |
| 101 | 101 | ||
| 102 | 102 | def get_title(self) -> str: | |
| 103 | 103 | return self.native_instance.titleForState_(0) | |
| 104 | 104 | ||
| 105 | - def set_on_click(self, callback: Callable[[], None]): | ||
| 105 | + def set_on_click(self, callback: Callable[[], None]) -> "Button": | ||
| 106 | 106 | # Create a handler object with an Objective-C method `onTap:` and attach the Python callback | |
| 107 | 107 | handler = _PNButtonHandler.new() | |
| 108 | 108 | # Keep strong references to the handler and callback | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,10 +28,12 @@ def get_date(self) -> tuple: | |||
| 28 | 28 | # https://developer.android.com/reference/android/widget/DatePicker | |
| 29 | 29 | # ======================================== | |
| 30 | 30 | ||
| 31 | + from typing import Any | ||
| 32 | + | ||
| 31 | 33 | from java import jclass | |
| 32 | 34 | ||
| 33 | 35 | class DatePicker(DatePickerBase, ViewBase): | |
| 34 | - def __init__(self, context, year: int = 0, month: int = 0, day: int = 0) -> None: | ||
| 36 | + def __init__(self, context: Any, year: int = 0, month: int = 0, day: int = 0) -> None: | ||
| 35 | 37 | super().__init__() | |
| 36 | 38 | self.native_class = jclass("android.widget.DatePicker") | |
| 37 | 39 | self.native_instance = self.native_class(context) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,19 +15,19 @@ def __init__(self) -> None: | |||
| 15 | 15 | super().__init__() | |
| 16 | 16 | ||
| 17 | 17 | @abstractmethod | |
| 18 | - def set_text(self, text: str) -> None: | ||
| 18 | + def set_text(self, text: str) -> "LabelBase": | ||
| 19 | 19 | pass | |
| 20 | 20 | ||
| 21 | 21 | @abstractmethod | |
| 22 | 22 | def get_text(self) -> str: | |
| 23 | 23 | pass | |
| 24 | 24 | ||
| 25 | 25 | @abstractmethod | |
| 26 | - def set_text_color(self, color: Any) -> None: | ||
| 26 | + def set_text_color(self, color: Any) -> "LabelBase": | ||
| 27 | 27 | pass | |
| 28 | 28 | ||
| 29 | 29 | @abstractmethod | |
| 30 | - def set_text_size(self, size: float) -> None: | ||
| 30 | + def set_text_size(self, size: float) -> "LabelBase": | ||
| 31 | 31 | pass | |
| 32 | 32 | ||
| 33 | 33 | ||
@@ -47,14 +47,14 @@ def __init__(self, text: str = "") -> None: | |||
| 47 | 47 | self.native_instance = self.native_class(context) | |
| 48 | 48 | self.set_text(text) | |
| 49 | 49 | ||
| 50 | - def set_text(self, text: str): | ||
| 50 | + def set_text(self, text: str) -> "Label": | ||
| 51 | 51 | self.native_instance.setText(text) | |
| 52 | 52 | return self | |
| 53 | 53 | ||
| 54 | 54 | def get_text(self) -> str: | |
| 55 | 55 | return self.native_instance.getText().toString() | |
| 56 | 56 | ||
| 57 | - def set_text_color(self, color: Any): | ||
| 57 | + def set_text_color(self, color: Any) -> "Label": | ||
| 58 | 58 | # Accept int ARGB or hex string | |
| 59 | 59 | if isinstance(color, str): | |
| 60 | 60 | c = color.strip() | |
@@ -71,7 +71,7 @@ def set_text_color(self, color: Any): | |||
| 71 | 71 | pass | |
| 72 | 72 | return self | |
| 73 | 73 | ||
| 74 | - def set_text_size(self, size_sp: float): | ||
| 74 | + def set_text_size(self, size_sp: float) -> "Label": | ||
| 75 | 75 | try: | |
| 76 | 76 | self.native_instance.setTextSize(float(size_sp)) | |
| 77 | 77 | except Exception: | |
@@ -93,14 +93,14 @@ def __init__(self, text: str = "") -> None: | |||
| 93 | 93 | self.native_instance = self.native_class.alloc().init() | |
| 94 | 94 | self.set_text(text) | |
| 95 | 95 | ||
| 96 | - def set_text(self, text: str): | ||
| 96 | + def set_text(self, text: str) -> "Label": | ||
| 97 | 97 | self.native_instance.setText_(text) | |
| 98 | 98 | return self | |
| 99 | 99 | ||
| 100 | 100 | def get_text(self) -> str: | |
| 101 | 101 | return self.native_instance.text() | |
| 102 | 102 | ||
| 103 | - def set_text_color(self, color: Any): | ||
| 103 | + def set_text_color(self, color: Any) -> "Label": | ||
| 104 | 104 | # Accept int ARGB or hex string | |
| 105 | 105 | if isinstance(color, str): | |
| 106 | 106 | c = color.strip() | |
@@ -123,7 +123,7 @@ def set_text_color(self, color: Any): | |||
| 123 | 123 | pass | |
| 124 | 124 | return self | |
| 125 | 125 | ||
| 126 | - def set_text_size(self, size: float): | ||
| 126 | + def set_text_size(self, size: float) -> "Label": | ||
| 127 | 127 | try: | |
| 128 | 128 | UIFont = ObjCClass("UIFont") | |
| 129 | 129 | font = UIFont.systemFontOfSize_(float(size)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | from abc import ABC, abstractmethod | |
| 2 | + from typing import Any | ||
| 2 | 3 | ||
| 3 | 4 | from .utils import IS_ANDROID | |
| 4 | 5 | from .view import ViewBase | |
@@ -14,7 +15,7 @@ def __init__(self) -> None: | |||
| 14 | 15 | super().__init__() | |
| 15 | 16 | ||
| 16 | 17 | @abstractmethod | |
| 17 | - def set_data(self, data: list) -> None: | ||
| 18 | + def set_data(self, data: list) -> "ListViewBase": | ||
| 18 | 19 | pass | |
| 19 | 20 | ||
| 20 | 21 | @abstractmethod | |
@@ -31,14 +32,14 @@ def get_data(self) -> list: | |||
| 31 | 32 | from java import jclass | |
| 32 | 33 | ||
| 33 | 34 | class ListView(ListViewBase, ViewBase): | |
| 34 | - def __init__(self, context, data: list = []) -> None: | ||
| 35 | + def __init__(self, context: Any, data: list = []) -> None: | ||
| 35 | 36 | super().__init__() | |
| 36 | 37 | self.context = context | |
| 37 | 38 | self.native_class = jclass("android.widget.ListView") | |
| 38 | 39 | self.native_instance = self.native_class(context) | |
| 39 | 40 | self.set_data(data) | |
| 40 | 41 | ||
| 41 | - def set_data(self, data: list): | ||
| 42 | + def set_data(self, data: list) -> "ListView": | ||
| 42 | 43 | adapter = jclass("android.widget.ArrayAdapter")( | |
| 43 | 44 | self.context, jclass("android.R$layout").simple_list_item_1, data | |
| 44 | 45 | ) | |
@@ -64,7 +65,7 @@ def __init__(self, data: list = []) -> None: | |||
| 64 | 65 | self.native_instance = self.native_class.alloc().init() | |
| 65 | 66 | self.set_data(data) | |
| 66 | 67 | ||
| 67 | - def set_data(self, data: list): | ||
| 68 | + def set_data(self, data: list) -> "ListView": | ||
| 68 | 69 | # Note: This is a simplified representation. Normally, you would need to create a UITableViewDataSource. | |
| 69 | 70 | self.native_instance.reloadData() | |
| 70 | 71 | return self | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,10 +28,12 @@ def stop_animating(self) -> None: | |||
| 28 | 28 | # https://developer.android.com/reference/com/google/android/material/progressindicator/CircularProgressIndicator | |
| 29 | 29 | # ======================================== | |
| 30 | 30 | ||
| 31 | + from typing import Any | ||
| 32 | + | ||
| 31 | 33 | from java import jclass | |
| 32 | 34 | ||
| 33 | 35 | class MaterialActivityIndicatorView(MaterialActivityIndicatorViewBase, ViewBase): | |
| 34 | - def __init__(self, context) -> None: | ||
| 36 | + def __init__(self, context: Any) -> None: | ||
| 35 | 37 | super().__init__() | |
| 36 | 38 | self.native_class = jclass("com.google.android.material.progressindicator.CircularProgressIndicator") | |
| 37 | 39 | self.native_instance = self.native_class(context) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,10 +28,12 @@ def get_title(self) -> str: | |||
| 28 | 28 | # https://developer.android.com/reference/com/google/android/material/button/MaterialButton | |
| 29 | 29 | # ======================================== | |
| 30 | 30 | ||
| 31 | + from typing import Any | ||
| 32 | + | ||
| 31 | 33 | from java import jclass | |
| 32 | 34 | ||
| 33 | 35 | class MaterialButton(MaterialButtonBase, ViewBase): | |
| 34 | - def __init__(self, context, title: str = "") -> None: | ||
| 36 | + def __init__(self, context: Any, title: str = "") -> None: | ||
| 35 | 37 | super().__init__() | |
| 36 | 38 | self.native_class = jclass("com.google.android.material.button.MaterialButton") | |
| 37 | 39 | self.native_instance = self.native_class(context) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments