pgwidgets-python 0.4.3__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.
- pgwidgets/async_/application.py +7 -0
- pgwidgets/async_/widget.py +7 -0
- pgwidgets/method_types.py +5 -0
- pgwidgets/sync/application.py +7 -0
- pgwidgets/sync/widget.py +7 -0
- pgwidgets/tab_model.py +186 -0
- {pgwidgets_python-0.4.3.dist-info → pgwidgets_python-0.5.0.dist-info}/METADATA +2 -2
- {pgwidgets_python-0.4.3.dist-info → pgwidgets_python-0.5.0.dist-info}/RECORD +11 -10
- {pgwidgets_python-0.4.3.dist-info → pgwidgets_python-0.5.0.dist-info}/WHEEL +0 -0
- {pgwidgets_python-0.4.3.dist-info → pgwidgets_python-0.5.0.dist-info}/licenses/LICENSE.md +0 -0
- {pgwidgets_python-0.4.3.dist-info → pgwidgets_python-0.5.0.dist-info}/top_level.txt +0 -0
pgwidgets/async_/application.py
CHANGED
|
@@ -27,6 +27,8 @@ import websockets
|
|
|
27
27
|
from pgwidgets_js import get_static_path, get_remote_html
|
|
28
28
|
from pgwidgets._json import JsonEncoder
|
|
29
29
|
from pgwidgets.defs import WIDGETS
|
|
30
|
+
from pgwidgets.tab_model import (TAB_MOVE_CALLBACKS,
|
|
31
|
+
apply_tab_callback)
|
|
30
32
|
from pgwidgets.method_types import (
|
|
31
33
|
SPECIAL_SETTERS, FIXED_SETTERS,
|
|
32
34
|
STATE_SYNC_CALLBACKS, STATE_SYNC_REQUIRES_OPTION,
|
|
@@ -530,6 +532,11 @@ class Session:
|
|
|
530
532
|
self._push(wid, "close_child",
|
|
531
533
|
{"__wid__": child._wid})
|
|
532
534
|
|
|
535
|
+
# Tabs dragged by the user: keep the tab order, and tell the
|
|
536
|
+
# other browsers
|
|
537
|
+
if action in TAB_MOVE_CALLBACKS:
|
|
538
|
+
apply_tab_callback(self, wid, action, args)
|
|
539
|
+
|
|
533
540
|
key = f"{wid}:{action}"
|
|
534
541
|
handlers = self._callbacks.get(key)
|
|
535
542
|
if not handlers:
|
pgwidgets/async_/widget.py
CHANGED
|
@@ -13,6 +13,7 @@ import os
|
|
|
13
13
|
|
|
14
14
|
from pgwidgets import tree_model
|
|
15
15
|
from pgwidgets.defs import WIDGETS, CALLBACK_METHODS, WIDGET_METHODS, CONTAINER_METHODS
|
|
16
|
+
from pgwidgets.tab_model import TAB_MOVE_CALLBACKS
|
|
16
17
|
from pgwidgets.method_types import (
|
|
17
18
|
classify_method, SETTER, GETTER, CHILD, ACTION, JS_ONLY,
|
|
18
19
|
FIXED_SETTERS, CLEAR_RESETS, ITEM_LIST_CONFIG,
|
|
@@ -271,6 +272,12 @@ class Widget:
|
|
|
271
272
|
await session._listen(wid, action, lambda wid, *a: None)
|
|
272
273
|
self._auto_sync_actions.add(action)
|
|
273
274
|
|
|
275
|
+
# Tabs dragged by the user (TabWidget page-move/page-reorder)
|
|
276
|
+
for action in TAB_MOVE_CALLBACKS:
|
|
277
|
+
if action in all_callbacks:
|
|
278
|
+
await session._listen(wid, action, lambda wid, *a: None)
|
|
279
|
+
self._auto_sync_actions.add(action)
|
|
280
|
+
|
|
274
281
|
# Tree/table state callbacks
|
|
275
282
|
if js_class in TREE_VIEW_WIDGETS:
|
|
276
283
|
for action in ("expanded", "collapsed", "sorted"):
|
pgwidgets/method_types.py
CHANGED
|
@@ -19,6 +19,8 @@ CHILD = "child"
|
|
|
19
19
|
ACTION = "action"
|
|
20
20
|
JS_ONLY = "js_only"
|
|
21
21
|
|
|
22
|
+
from pgwidgets.tab_model import TAB_CUSTOM_METHODS # noqa: E402
|
|
23
|
+
|
|
22
24
|
# -- Explicit overrides (take precedence over conventions) --
|
|
23
25
|
|
|
24
26
|
# Methods that manage the widget tree.
|
|
@@ -600,6 +602,9 @@ CUSTOM_METHODS = {
|
|
|
600
602
|
("Image", "set_binary_image"): _image_set_binary_image,
|
|
601
603
|
}
|
|
602
604
|
|
|
605
|
+
# tab insertion and moves keep the tab order (see pgwidgets.tab_model)
|
|
606
|
+
CUSTOM_METHODS.update(TAB_CUSTOM_METHODS)
|
|
607
|
+
|
|
603
608
|
|
|
604
609
|
def _state_key_for_setter(method_name):
|
|
605
610
|
"""Derive the state key from a set_* method name."""
|
pgwidgets/sync/application.py
CHANGED
|
@@ -29,6 +29,8 @@ from pgwidgets_js import get_static_path, get_remote_html
|
|
|
29
29
|
from pgwidgets._json import JsonEncoder
|
|
30
30
|
from pgwidgets.defs import WIDGETS
|
|
31
31
|
from pgwidgets.sync.widget import Widget, build_all_widget_classes
|
|
32
|
+
from pgwidgets.tab_model import (TAB_MOVE_CALLBACKS,
|
|
33
|
+
apply_tab_callback)
|
|
32
34
|
from pgwidgets.method_types import (
|
|
33
35
|
SPECIAL_SETTERS, FIXED_SETTERS,
|
|
34
36
|
STATE_SYNC_CALLBACKS, STATE_SYNC_REQUIRES_OPTION,
|
|
@@ -619,6 +621,11 @@ class Session:
|
|
|
619
621
|
self._push(wid, "close_child",
|
|
620
622
|
{"__wid__": child._wid})
|
|
621
623
|
|
|
624
|
+
# Tabs dragged by the user: keep the tab order, and tell the
|
|
625
|
+
# other browsers
|
|
626
|
+
if action in TAB_MOVE_CALLBACKS:
|
|
627
|
+
apply_tab_callback(self, wid, action, args)
|
|
628
|
+
|
|
622
629
|
key = f"{wid}:{action}"
|
|
623
630
|
handlers = self._callbacks.get(key)
|
|
624
631
|
if not handlers:
|
pgwidgets/sync/widget.py
CHANGED
|
@@ -13,6 +13,7 @@ import os
|
|
|
13
13
|
|
|
14
14
|
from pgwidgets import tree_model
|
|
15
15
|
from pgwidgets.defs import WIDGETS, CALLBACK_METHODS, WIDGET_METHODS, CONTAINER_METHODS
|
|
16
|
+
from pgwidgets.tab_model import TAB_MOVE_CALLBACKS
|
|
16
17
|
from pgwidgets.method_types import (
|
|
17
18
|
classify_method, SETTER, GETTER, CHILD, ACTION, JS_ONLY,
|
|
18
19
|
FIXED_SETTERS, CLEAR_RESETS, ITEM_LIST_CONFIG,
|
|
@@ -240,6 +241,12 @@ class Widget:
|
|
|
240
241
|
session._listen(wid, action, lambda wid, *a: None)
|
|
241
242
|
self._auto_sync_actions.add(action)
|
|
242
243
|
|
|
244
|
+
# Tabs dragged by the user (TabWidget page-move/page-reorder)
|
|
245
|
+
for action in TAB_MOVE_CALLBACKS:
|
|
246
|
+
if action in all_callbacks:
|
|
247
|
+
session._listen(wid, action, lambda wid, *a: None)
|
|
248
|
+
self._auto_sync_actions.add(action)
|
|
249
|
+
|
|
243
250
|
# Tree/table state callbacks
|
|
244
251
|
if js_class in TREE_VIEW_WIDGETS:
|
|
245
252
|
for action in ("expanded", "collapsed", "sorted"):
|
pgwidgets/tab_model.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Python-side model of the tabs of a TabWidget, as they are moved around.
|
|
3
|
+
|
|
4
|
+
A tab can be inserted at a position, moved to another position within its
|
|
5
|
+
TabWidget, or moved to another TabWidget -- by code, or by the user
|
|
6
|
+
dragging it in the browser. Either way the parents' ``_children`` lists
|
|
7
|
+
(which give the order the tabs are replayed in on reconstruction) and
|
|
8
|
+
their current ``index`` have to follow, and other browsers connected to
|
|
9
|
+
the session have to be told.
|
|
10
|
+
|
|
11
|
+
The functions here are shared by the sync and async widget classes.
|
|
12
|
+
``CUSTOM_METHODS`` entries return ``self._call(...)`` so that they work
|
|
13
|
+
for both: the async caller awaits the coroutine it gets back.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__all__ = ["TAB_CUSTOM_METHODS", "TAB_MOVE_CALLBACKS",
|
|
17
|
+
"apply_tab_callback", "tab_put", "tab_take"]
|
|
18
|
+
|
|
19
|
+
# Browser callbacks reporting a tab that the user has dragged; the
|
|
20
|
+
# session listens for them on every TabWidget to keep its model in step.
|
|
21
|
+
TAB_MOVE_CALLBACKS = ("page-move", "page-reorder")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _is_widget(obj):
|
|
25
|
+
return hasattr(obj, "_wid") and hasattr(obj, "_children")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def tab_take(widget, child):
|
|
29
|
+
"""Take `child` out of `widget`'s list of tabs, keeping its current
|
|
30
|
+
index on the same tab where possible. Returns the options the tab
|
|
31
|
+
was added with (a dict), or None if `child` isn't a tab of `widget`.
|
|
32
|
+
"""
|
|
33
|
+
for pos, entry in enumerate(widget._children):
|
|
34
|
+
if entry[0] is child:
|
|
35
|
+
break
|
|
36
|
+
else:
|
|
37
|
+
return None
|
|
38
|
+
del widget._children[pos]
|
|
39
|
+
child._parent = None
|
|
40
|
+
|
|
41
|
+
index = widget._state.get("index", -1)
|
|
42
|
+
if index is not None and index >= 0:
|
|
43
|
+
if pos < index:
|
|
44
|
+
index -= 1
|
|
45
|
+
elif pos == index:
|
|
46
|
+
# the browser shows a neighbour of a closed current tab
|
|
47
|
+
index = min(index, len(widget._children) - 1)
|
|
48
|
+
widget._state["index"] = index
|
|
49
|
+
|
|
50
|
+
extra = entry[1]
|
|
51
|
+
options = extra[0] if extra and isinstance(extra[0], dict) else {}
|
|
52
|
+
return options
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def tab_put(widget, child, options, index):
|
|
56
|
+
"""Put `child` in `widget`'s list of tabs at position `index`
|
|
57
|
+
(appended if None or out of range), as if it had been added there
|
|
58
|
+
with ``add_widget(child, options)``. Returns the position used.
|
|
59
|
+
"""
|
|
60
|
+
n = len(widget._children)
|
|
61
|
+
if index is None or index < 0 or index > n:
|
|
62
|
+
index = n
|
|
63
|
+
widget._children.insert(index, (child, (dict(options or {}),),
|
|
64
|
+
"add_widget", 0))
|
|
65
|
+
# reconstruction replays children in sequence order: renumber them
|
|
66
|
+
# all so that the order is the tab order
|
|
67
|
+
entries = []
|
|
68
|
+
for entry in widget._children:
|
|
69
|
+
entries.append((entry[0], entry[1], entry[2], widget._add_seq))
|
|
70
|
+
widget._add_seq += 1
|
|
71
|
+
widget._children = entries
|
|
72
|
+
|
|
73
|
+
child._parent = widget
|
|
74
|
+
roots = widget._session._root_widgets
|
|
75
|
+
if child in roots:
|
|
76
|
+
roots.remove(child)
|
|
77
|
+
return index
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _make_root(child):
|
|
81
|
+
roots = child._session._root_widgets
|
|
82
|
+
if child not in roots:
|
|
83
|
+
roots.append(child)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def apply_tab_callback(session, wid, action, args):
|
|
87
|
+
"""Update the model for a tab the user dragged in the browser, and
|
|
88
|
+
tell the session's other browsers to make the same move.
|
|
89
|
+
|
|
90
|
+
`action` is one of :data:`TAB_MOVE_CALLBACKS`; `args` are the
|
|
91
|
+
callback's arguments, still in wire form.
|
|
92
|
+
"""
|
|
93
|
+
widget = session._widget_map.get(wid)
|
|
94
|
+
if widget is None:
|
|
95
|
+
return
|
|
96
|
+
if action == "page-move" and len(args) >= 3:
|
|
97
|
+
# (src, child, index), on the destination
|
|
98
|
+
src = session._resolve_return(args[0])
|
|
99
|
+
child = session._resolve_return(args[1])
|
|
100
|
+
index = args[2]
|
|
101
|
+
if not (_is_widget(src) and _is_widget(child)):
|
|
102
|
+
return
|
|
103
|
+
options = tab_take(src, child)
|
|
104
|
+
if options is None:
|
|
105
|
+
return
|
|
106
|
+
index = tab_put(widget, child, options, index)
|
|
107
|
+
widget._state["index"] = index
|
|
108
|
+
session._push(wid, "move_tab_from", {"__wid__": src._wid},
|
|
109
|
+
{"__wid__": child._wid}, index)
|
|
110
|
+
|
|
111
|
+
elif action == "page-reorder" and len(args) >= 2:
|
|
112
|
+
# (child, index)
|
|
113
|
+
child = session._resolve_return(args[0])
|
|
114
|
+
index = args[1]
|
|
115
|
+
if not _is_widget(child):
|
|
116
|
+
return
|
|
117
|
+
options = tab_take(widget, child)
|
|
118
|
+
if options is None:
|
|
119
|
+
return
|
|
120
|
+
index = tab_put(widget, child, options, index)
|
|
121
|
+
widget._state["index"] = index
|
|
122
|
+
session._push(wid, "move_tab", {"__wid__": child._wid}, index)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# --- methods for the TabWidget classes ---
|
|
126
|
+
|
|
127
|
+
def _tab_insert_widget(self, index, child, options=None):
|
|
128
|
+
"""insert_widget(index, child, options): insert `child` as a new tab
|
|
129
|
+
at position `index` (-1 appends)."""
|
|
130
|
+
if options is None:
|
|
131
|
+
options = {}
|
|
132
|
+
if _is_widget(child):
|
|
133
|
+
old_parent = child._parent
|
|
134
|
+
if old_parent is not None and old_parent is not self:
|
|
135
|
+
old_parent._children = [entry for entry in old_parent._children
|
|
136
|
+
if entry[0] is not child]
|
|
137
|
+
index = tab_put(self, child, options,
|
|
138
|
+
None if index is None or index < 0 else index)
|
|
139
|
+
if len(self._children) == 1:
|
|
140
|
+
# the browser shows the first tab added
|
|
141
|
+
self._state["index"] = 0
|
|
142
|
+
else:
|
|
143
|
+
cur = self._state.get("index", -1)
|
|
144
|
+
if cur is not None and cur >= index:
|
|
145
|
+
self._state["index"] = cur + 1
|
|
146
|
+
return self._call("insert_widget", index, child, options)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _tab_remove(self, child, destroy=False):
|
|
150
|
+
"""remove(child, destroy=False): remove the tab holding `child`."""
|
|
151
|
+
if _is_widget(child) and tab_take(self, child) is not None:
|
|
152
|
+
_make_root(child)
|
|
153
|
+
return self._call("remove", child, destroy)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _tab_move_tab(self, child, index):
|
|
157
|
+
"""move_tab(child, index): move the tab holding `child` to position
|
|
158
|
+
`index` and make it the current tab."""
|
|
159
|
+
if _is_widget(child):
|
|
160
|
+
options = tab_take(self, child)
|
|
161
|
+
if options is not None:
|
|
162
|
+
index = tab_put(self, child, options, index)
|
|
163
|
+
self._state["index"] = index
|
|
164
|
+
return self._call("move_tab", child, index)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _tab_move_tab_from(self, src, child, index=-1):
|
|
168
|
+
"""move_tab_from(src, child, index=-1): move the tab holding `child`
|
|
169
|
+
from TabWidget `src` to position `index` here (-1 appends), and make
|
|
170
|
+
it the current tab."""
|
|
171
|
+
if _is_widget(src) and _is_widget(child):
|
|
172
|
+
options = tab_take(src, child)
|
|
173
|
+
if options is not None:
|
|
174
|
+
index = tab_put(self, child, options,
|
|
175
|
+
None if index is None or index < 0 else index)
|
|
176
|
+
self._state["index"] = index
|
|
177
|
+
return self._call("move_tab_from", src, child, index)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
TAB_CUSTOM_METHODS = {
|
|
181
|
+
("TabWidget", "insert_widget"): _tab_insert_widget,
|
|
182
|
+
("TabWidget", "remove"): _tab_remove,
|
|
183
|
+
("TabWidget", "remove_widget"): _tab_remove,
|
|
184
|
+
("TabWidget", "move_tab"): _tab_move_tab,
|
|
185
|
+
("TabWidget", "move_tab_from"): _tab_move_tab_from,
|
|
186
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pgwidgets-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Python bindings for the pgwidgets JavaScript widget library
|
|
5
5
|
Author: PGWidgets Developers
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -17,7 +17,7 @@ Classifier: Topic :: Software Development :: User Interfaces
|
|
|
17
17
|
Requires-Python: >=3.12
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE.md
|
|
20
|
-
Requires-Dist: pgwidgets-js>=0.
|
|
20
|
+
Requires-Dist: pgwidgets-js>=0.5.0
|
|
21
21
|
Requires-Dist: websockets>=12
|
|
22
22
|
Provides-Extra: dev
|
|
23
23
|
Requires-Dist: sphinx; extra == "dev"
|
|
@@ -3,23 +3,24 @@ pgwidgets/_json.py,sha256=o21qywJ6yAldbqxTq3nLwgK9O67r3a8JxhvI_WAJnMY,2184
|
|
|
3
3
|
pgwidgets/buffer.py,sha256=BYj_nb6fuyGsBqUp3_Z1YrzUm4h5VmoWPGKvpTjWrYk,4048
|
|
4
4
|
pgwidgets/callbacks.py,sha256=gA2FnX0N5BmbmOMyEV35yHySgAfVjfAZcZhZbo7j4-c,3314
|
|
5
5
|
pgwidgets/defs.py,sha256=Q8qhvTeansFU1Av6j5ncdwF2xSNHrpXuKErdHWQ3HiA,436
|
|
6
|
-
pgwidgets/method_types.py,sha256=
|
|
6
|
+
pgwidgets/method_types.py,sha256=bJBbnzcyl1KTco56rSNciqQbdBqzEl3e4TFufg_FrzE,24999
|
|
7
|
+
pgwidgets/tab_model.py,sha256=23qUZuGWVXxAdtXA_DneIo77NY_F6uroa9RLaeLZ2nI,6900
|
|
7
8
|
pgwidgets/text_model.py,sha256=xlSAoh1ikIG9ZYVwx5wHWrohkGkyu7R6Cbs36_xnbMg,29313
|
|
8
9
|
pgwidgets/tree_model.py,sha256=agif6vSeLzcGfLe1tB-O2MIkXv7Qgb53uWMoTXDSgAc,12144
|
|
9
10
|
pgwidgets/async_/Widgets.py,sha256=vld2xkvusBBEVbhbezaJsjBRRj3L7c17Up0pOVs8PGo,723
|
|
10
11
|
pgwidgets/async_/__init__.py,sha256=rXB-v9XRrYt1imYuYikhkzIyiRqaYhlTpQei2LHaQ18,564
|
|
11
|
-
pgwidgets/async_/application.py,sha256=
|
|
12
|
-
pgwidgets/async_/widget.py,sha256=
|
|
12
|
+
pgwidgets/async_/application.py,sha256=7yWjhV4S5Noi1uisbwDf0HMjjvWhQtENRWCywbaFNv8,85595
|
|
13
|
+
pgwidgets/async_/widget.py,sha256=XgbAzUCbtI91wuA-5liowPxZ7jlUIH3f0SZitUBTcII,58578
|
|
13
14
|
pgwidgets/extras/__init__.py,sha256=AXUmFtnn4RSlp6pJX6z55j-m_29VmfzpYIjQvAy7pO0,325
|
|
14
15
|
pgwidgets/extras/file_browser.py,sha256=VyGjc4zlexSBi6nWbxs-J3kBXRzEwR5ilzkLLEtEy-k,17344
|
|
15
16
|
pgwidgets/icons/pgw-python-logo.png,sha256=_Rxicp9EKy2Pzz1HtobxEnntSI-y5TtAVPlIzZIsfYs,2428840
|
|
16
17
|
pgwidgets/sync/Widgets.py,sha256=7SaocMVMzFHhi51pjuEAr47Wez90b_a61kDbiv0jOfM,706
|
|
17
18
|
pgwidgets/sync/__init__.py,sha256=SF5RTAvtu8BbYBWzpiCPipy6DJzNXf6nqk9xdvwxUhQ,542
|
|
18
|
-
pgwidgets/sync/application.py,sha256=
|
|
19
|
+
pgwidgets/sync/application.py,sha256=uTo0ny9WS6jwDmFv7RKQM6OIzHXFlz1nIeBPQizPGbg,102674
|
|
19
20
|
pgwidgets/sync/text_source.py,sha256=yeRhDbCMMqipAoMnyAk3j_1EL2YEdziCmiB3JdprGvc,10057
|
|
20
|
-
pgwidgets/sync/widget.py,sha256=
|
|
21
|
-
pgwidgets_python-0.
|
|
22
|
-
pgwidgets_python-0.
|
|
23
|
-
pgwidgets_python-0.
|
|
24
|
-
pgwidgets_python-0.
|
|
25
|
-
pgwidgets_python-0.
|
|
21
|
+
pgwidgets/sync/widget.py,sha256=wMFWCiDdlYYxaJHjbvOmueP2XnyOrv8NJhulPyVrHks,58973
|
|
22
|
+
pgwidgets_python-0.5.0.dist-info/licenses/LICENSE.md,sha256=LoM3fMTiMnQuHRCJghdjOtjnCrL8soBpu2PFk24Xvyg,1528
|
|
23
|
+
pgwidgets_python-0.5.0.dist-info/METADATA,sha256=zTOMwuyXY9Fmf1c5rdf83vaWrrqfmvGQUEF6mGHtfy0,4694
|
|
24
|
+
pgwidgets_python-0.5.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
25
|
+
pgwidgets_python-0.5.0.dist-info/top_level.txt,sha256=wwL6fBq0gU-JwzlM6TdduY1qYpu39ysqnnbQT-1bqAs,10
|
|
26
|
+
pgwidgets_python-0.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|