nice-gui-utils 0.2.4__tar.gz → 0.3.1.dev1__tar.gz

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 (25) hide show
  1. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/PKG-INFO +5 -2
  2. nice_gui_utils-0.3.1.dev1/README.md +6 -0
  3. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/pyproject.toml +1 -1
  4. nice_gui_utils-0.3.1.dev1/src/nice_gui_utils/__init__.py +5 -0
  5. nice_gui_utils-0.3.1.dev1/src/nice_gui_utils/keycloak_js/__init__.py +4 -0
  6. nice_gui_utils-0.3.1.dev1/src/nice_gui_utils/keycloak_js/keycloak.py +94 -0
  7. nice_gui_utils-0.3.1.dev1/src/nice_gui_utils/router/__init__.py +4 -0
  8. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils/router/router.py +31 -3
  9. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils.egg-info/PKG-INFO +5 -2
  10. nice_gui_utils-0.2.4/README.md +0 -3
  11. nice_gui_utils-0.2.4/src/nice_gui_utils/__init__.py +0 -0
  12. nice_gui_utils-0.2.4/src/nice_gui_utils/keycloak_js/__init__.py +0 -1
  13. nice_gui_utils-0.2.4/src/nice_gui_utils/keycloak_js/keycloak.py +0 -47
  14. nice_gui_utils-0.2.4/src/nice_gui_utils/router/__init__.py +0 -1
  15. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/LICENSE +0 -0
  16. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/requirements.txt +0 -0
  17. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/setup.cfg +0 -0
  18. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils/keycloak_js/keycloak.js +0 -0
  19. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils/router/router_frame.js +0 -0
  20. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils.egg-info/SOURCES.txt +0 -0
  21. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils.egg-info/dependency_links.txt +0 -0
  22. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils.egg-info/requires.txt +0 -0
  23. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/src/nice_gui_utils.egg-info/top_level.txt +0 -0
  24. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/tests/test_login.py +0 -0
  25. {nice_gui_utils-0.2.4 → nice_gui_utils-0.3.1.dev1}/tests/test_single_page.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nice_gui_utils
3
- Version: 0.2.4
3
+ Version: 0.3.1.dev1
4
4
  Summary: Utils to use with NiceGUI.
5
5
  Author: Harter Kern
6
6
  Project-URL: Homepage, https://gitlab.com/harter-kern-public/nice-gui-utils
@@ -13,6 +13,9 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: nicegui>=1.4.0
15
15
 
16
- # Pipeline status
16
+ # nice_gui_utils - a collection of utilities for [nicegui](https://nicegui.io/)
17
17
 
18
+ ## [Documentation](https://nice-gui-utils-harter-kern-8e1d5c74ce521b132e29aa9329b109a50ad7.gitlab.io)
19
+
20
+ ## Pipeline status
18
21
  [![pipeline status](https://gitlab.com/harter-kern/nice-gui-utils/badges/main/pipeline.svg)](https://gitlab.com/harter-kern/nice-gui-utils/-/commits/main)
@@ -0,0 +1,6 @@
1
+ # nice_gui_utils - a collection of utilities for [nicegui](https://nicegui.io/)
2
+
3
+ ## [Documentation](https://nice-gui-utils-harter-kern-8e1d5c74ce521b132e29aa9329b109a50ad7.gitlab.io)
4
+
5
+ ## Pipeline status
6
+ [![pipeline status](https://gitlab.com/harter-kern/nice-gui-utils/badges/main/pipeline.svg)](https://gitlab.com/harter-kern/nice-gui-utils/-/commits/main)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nice_gui_utils"
7
- version = "0.2.4"
7
+ version = "0.3.1dev1"
8
8
  dynamic = ["dependencies"]
9
9
  authors = [
10
10
  { name = "Harter Kern" },
@@ -0,0 +1,5 @@
1
+ """
2
+ .. include:: ../../README.md
3
+ """
4
+ from .keycloak_js import KeycloakConfig, Keycloak
5
+ from .router import Router
@@ -0,0 +1,4 @@
1
+ """
2
+ .. include:: ../../../docs/keycloak_js/README.md
3
+ """
4
+ from .keycloak import KeycloakConfig, Keycloak
@@ -0,0 +1,94 @@
1
+ """
2
+ Implementation of the keycloak wrapper class.
3
+ See keycloak-js api reference for more info.
4
+ """
5
+ from dataclasses import dataclass
6
+ from typing import AnyStr, Dict, Any
7
+
8
+ from nicegui import ui
9
+ from nicegui.awaitable_response import AwaitableResponse
10
+
11
+
12
+ @dataclass
13
+ class KeycloakConfig:
14
+ """
15
+ Base Keycloak config.
16
+ """
17
+ url: AnyStr
18
+ realm: AnyStr
19
+ client_id: AnyStr
20
+
21
+
22
+ class Keycloak(ui.element, component='keycloak.js'):
23
+ """
24
+ Wrapper class. Exposes part of the api of keycloak-js.
25
+ Will automatically refresh tokens after initialization.
26
+ """
27
+
28
+ config: KeycloakConfig = None
29
+ require_login: bool = None
30
+
31
+ def __init__(self,
32
+ config: KeycloakConfig,
33
+ js_source: AnyStr = '/static/keycloak.js',
34
+ init_options: Dict = None):
35
+ """
36
+
37
+ :param config: base keycloak config
38
+ :param js_source: url of keycloak-js source
39
+ :param init_options: options used for initialization
40
+ """
41
+ super().__init__()
42
+
43
+ ui.add_head_html(f'<script src="{js_source}"></script>')
44
+
45
+ props: Dict[str, Any] = self._props
46
+ props['url'] = config.url
47
+ props['realm'] = config.realm
48
+ props['clientId'] = config.client_id
49
+
50
+ props['initOptions'] = init_options if init_options else {}
51
+
52
+ def token(self) -> AwaitableResponse:
53
+ """
54
+ Get a token that can be sent in the Authorization header in requests to services.
55
+
56
+ :return: base64 encoded token
57
+ """
58
+ return self.run_method('token')
59
+
60
+ def refresh_token(self) -> AwaitableResponse:
61
+ """
62
+ Get a refresh token that can be used to retrieve a new token.
63
+
64
+ :return: base64 encoded refresh token
65
+ """
66
+ return self.run_method('refreshToken')
67
+
68
+ def authenticated(self) -> AwaitableResponse:
69
+ """
70
+ Returns true if the user is authenticated, false otherwise.
71
+
72
+ :return: whether the used is authenticated
73
+ """
74
+ return self.run_method('authenticated')
75
+
76
+ async def login(self, options: Dict = None) -> None:
77
+ """
78
+ Redirects to login form.
79
+ See keycloak-js api reference
80
+ for more info about available options.
81
+
82
+ :param options: optional object
83
+ """
84
+ await self.run_method('login', options if options else {})
85
+
86
+ async def logout(self, options: Dict = None) -> None:
87
+ """
88
+ Redirects to logout.
89
+ See keycloak-js api reference
90
+ for more info about available options.
91
+
92
+ :param options: optional object
93
+ """
94
+ await self.run_method('logout', options if options else {})
@@ -0,0 +1,4 @@
1
+ """
2
+ .. include:: ../../../docs/router/README.md
3
+ """
4
+ from .router import Router
@@ -1,3 +1,6 @@
1
+ """
2
+ A single page router enabling navigation without page reloading.
3
+ """
1
4
  from functools import singledispatchmethod
2
5
  from typing import Callable, Dict, Optional, AnyStr, Union, Any
3
6
 
@@ -12,18 +15,33 @@ class _RouterFrame(ui.element, component='router_frame.js'):
12
15
  props: Dict[AnyStr, Any] = self._props
13
16
  props['checkInterval'] = check_interval
14
17
 
15
- def update_history(self, path):
18
+ def update_history(self, path) -> None:
19
+ """
20
+ Update browser history.
21
+ You do not need to call this directly.
22
+
23
+ :param path: path to add to the history
24
+ """
16
25
  self.run_method('updateHistory', path)
17
26
 
18
27
 
19
28
  class Router:
29
+ """
30
+ Single page router.
31
+ """
20
32
 
21
33
  def __init__(self, check_interval: int = None) -> None:
22
34
  self.routes: Dict[AnyStr, Callable] = {}
23
35
  self.content: Optional[ui.element] = None
24
36
  self.router_frame: _RouterFrame = _RouterFrame(check_interval if check_interval else 10)
25
37
 
26
- def path(self, path: str):
38
+ def path(self, path: AnyStr):
39
+ """
40
+ Decorator method. Register a path with this router.
41
+
42
+ :param path: path to register
43
+ """
44
+
27
45
  def decorator(func: Callable):
28
46
  self.routes[path] = func
29
47
  return func
@@ -31,7 +49,12 @@ class Router:
31
49
  return decorator
32
50
 
33
51
  @singledispatchmethod
34
- def go_to(self, target: Union[Callable, AnyStr]):
52
+ def go_to(self, target: Union[Callable, AnyStr]) -> None:
53
+ """
54
+ Navigate to another registered page.
55
+
56
+ :param target: page to go to
57
+ """
35
58
  path = {target: path for path, target in self.routes.items()}[target]
36
59
  self.go_to(path)
37
60
 
@@ -51,5 +74,10 @@ class Router:
51
74
  background_tasks.create(build())
52
75
 
53
76
  def frame(self) -> ui.element:
77
+ """
78
+ Add content to page.
79
+
80
+ :return: the ui element to display
81
+ """
54
82
  self.content = self.router_frame.on('open', lambda e: self.go_to(e.args))
55
83
  return self.content
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nice_gui_utils
3
- Version: 0.2.4
3
+ Version: 0.3.1.dev1
4
4
  Summary: Utils to use with NiceGUI.
5
5
  Author: Harter Kern
6
6
  Project-URL: Homepage, https://gitlab.com/harter-kern-public/nice-gui-utils
@@ -13,6 +13,9 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: nicegui>=1.4.0
15
15
 
16
- # Pipeline status
16
+ # nice_gui_utils - a collection of utilities for [nicegui](https://nicegui.io/)
17
17
 
18
+ ## [Documentation](https://nice-gui-utils-harter-kern-8e1d5c74ce521b132e29aa9329b109a50ad7.gitlab.io)
19
+
20
+ ## Pipeline status
18
21
  [![pipeline status](https://gitlab.com/harter-kern/nice-gui-utils/badges/main/pipeline.svg)](https://gitlab.com/harter-kern/nice-gui-utils/-/commits/main)
@@ -1,3 +0,0 @@
1
- # Pipeline status
2
-
3
- [![pipeline status](https://gitlab.com/harter-kern/nice-gui-utils/badges/main/pipeline.svg)](https://gitlab.com/harter-kern/nice-gui-utils/-/commits/main)
File without changes
@@ -1 +0,0 @@
1
- from .keycloak import KeycloakConfig, Keycloak
@@ -1,47 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import AnyStr, Dict, Any
3
-
4
- from nicegui import ui
5
- from nicegui.awaitable_response import AwaitableResponse
6
-
7
-
8
- @dataclass
9
- class KeycloakConfig:
10
- url: AnyStr
11
- realm: AnyStr
12
- client_id: AnyStr
13
-
14
-
15
- class Keycloak(ui.element, component='keycloak.js'):
16
- config: KeycloakConfig = None
17
- require_login: bool = None
18
-
19
- def __init__(self,
20
- config: KeycloakConfig,
21
- js_source: AnyStr = '/static/keycloak.js',
22
- init_options: Dict = None):
23
- super().__init__()
24
-
25
- ui.add_head_html(f'<script src="{js_source}"></script>')
26
-
27
- props: Dict[str, Any] = self._props
28
- props['url'] = config.url
29
- props['realm'] = config.realm
30
- props['clientId'] = config.client_id
31
-
32
- props['initOptions'] = init_options if init_options else {}
33
-
34
- def token(self) -> AwaitableResponse:
35
- return self.run_method('token')
36
-
37
- def refresh_token(self) -> AwaitableResponse:
38
- return self.run_method('refreshToken')
39
-
40
- def authenticated(self) -> AwaitableResponse:
41
- return self.run_method('authenticated')
42
-
43
- def login(self, options=None) -> AwaitableResponse:
44
- return self.run_method('login', options if options else {})
45
-
46
- def logout(self, options=None) -> AwaitableResponse:
47
- return self.run_method('logout', options if options else {})
@@ -1 +0,0 @@
1
- from .router import Router