pgwidgets-python 0.4.2__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 +11 -3
- pgwidgets/async_/widget.py +37 -3
- pgwidgets/extras/file_browser.py +3 -3
- pgwidgets/method_types.py +13 -0
- pgwidgets/sync/application.py +11 -3
- pgwidgets/sync/widget.py +37 -2
- pgwidgets/tab_model.py +186 -0
- {pgwidgets_python-0.4.2.dist-info → pgwidgets_python-0.5.0.dist-info}/METADATA +2 -2
- {pgwidgets_python-0.4.2.dist-info → pgwidgets_python-0.5.0.dist-info}/RECORD +12 -11
- {pgwidgets_python-0.4.2.dist-info → pgwidgets_python-0.5.0.dist-info}/WHEEL +1 -1
- {pgwidgets_python-0.4.2.dist-info → pgwidgets_python-0.5.0.dist-info}/licenses/LICENSE.md +0 -0
- {pgwidgets_python-0.4.2.dist-info → pgwidgets_python-0.5.0.dist-info}/top_level.txt +0 -0
pgwidgets/async_/application.py
CHANGED
|
@@ -27,11 +27,13 @@ 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
|
-
SPECIAL_SETTERS, FIXED_SETTERS,
|
|
33
|
+
SPECIAL_SETTERS, FIXED_SETTERS,
|
|
32
34
|
STATE_SYNC_CALLBACKS, STATE_SYNC_REQUIRES_OPTION,
|
|
33
35
|
WIDGET_CALLBACK_SYNC, POST_CHILDREN_STATE_KEYS, ITEM_LIST_CONFIG,
|
|
34
|
-
CHILD_CLOSE_CALLBACKS,
|
|
36
|
+
CHILD_CLOSE_CALLBACKS,
|
|
35
37
|
TREE_OVERRIDE_REPLAY, colour_batches, JS_ONLY_METHODS,
|
|
36
38
|
coalesce_colour_calls,
|
|
37
39
|
BINARY_STATE_KEYS, _send_binary_auto,
|
|
@@ -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:
|
|
@@ -622,7 +629,6 @@ class Session:
|
|
|
622
629
|
self._next_wid = js_next
|
|
623
630
|
return result
|
|
624
631
|
|
|
625
|
-
|
|
626
632
|
def _push(self, wid, method, *args):
|
|
627
633
|
"""Push a silent call to all browsers except the callback source.
|
|
628
634
|
Fire-and-forget: no result is awaited."""
|
|
@@ -795,6 +801,7 @@ class Session:
|
|
|
795
801
|
"method": method,
|
|
796
802
|
"args": list(args),
|
|
797
803
|
}, cls=JsonEncoder)
|
|
804
|
+
|
|
798
805
|
async def _pair(ws):
|
|
799
806
|
await ws.send(header)
|
|
800
807
|
await ws.send(data)
|
|
@@ -1842,6 +1849,7 @@ class Application:
|
|
|
1842
1849
|
asyncio.ensure_future(do_reconstruct())
|
|
1843
1850
|
else:
|
|
1844
1851
|
self._logger.info(f"Session {session.id} connected.")
|
|
1852
|
+
|
|
1845
1853
|
async def do_connect():
|
|
1846
1854
|
# Replay fonts before the user callback so any
|
|
1847
1855
|
# widget the user builds with ``set_font(family,
|
pgwidgets/async_/widget.py
CHANGED
|
@@ -13,9 +13,9 @@ 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
|
-
CHILD_METHODS as CHILD_METHOD_TYPES,
|
|
19
19
|
FIXED_SETTERS, CLEAR_RESETS, ITEM_LIST_CONFIG,
|
|
20
20
|
REPLAY_METHODS, CHILD_SELECT_METHODS, TREE_VIEW_WIDGETS,
|
|
21
21
|
STATE_SYNC_CALLBACKS, STATE_SYNC_REQUIRES_OPTION,
|
|
@@ -146,6 +146,10 @@ class Widget:
|
|
|
146
146
|
# Store constructor info for reconstruction
|
|
147
147
|
self._constructor_args = tuple(args[:len(pos_names)])
|
|
148
148
|
self._constructor_options = dict(options)
|
|
149
|
+
if self._constructor_options.get("columns") is not None:
|
|
150
|
+
# the replay record, so keep it safe from the caller's edits
|
|
151
|
+
self._constructor_options["columns"] = tree_model.copy_tree(
|
|
152
|
+
self._constructor_options["columns"])
|
|
149
153
|
|
|
150
154
|
# Store constructor args as initial state (None means "not
|
|
151
155
|
# provided" since generated __init__ defaults all args to None)
|
|
@@ -154,6 +158,10 @@ class Widget:
|
|
|
154
158
|
self._state[name] = args[i]
|
|
155
159
|
for k, v in options.items():
|
|
156
160
|
if v is not None:
|
|
161
|
+
# the column list is edited in place later (see
|
|
162
|
+
# _add_tree_model_methods), so keep a copy of the caller's
|
|
163
|
+
if k == "columns":
|
|
164
|
+
v = tree_model.copy_tree(v)
|
|
157
165
|
self._state[k] = v
|
|
158
166
|
|
|
159
167
|
# Apply default state for keys not set by constructor
|
|
@@ -264,6 +272,12 @@ class Widget:
|
|
|
264
272
|
await session._listen(wid, action, lambda wid, *a: None)
|
|
265
273
|
self._auto_sync_actions.add(action)
|
|
266
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
|
+
|
|
267
281
|
# Tree/table state callbacks
|
|
268
282
|
if js_class in TREE_VIEW_WIDGETS:
|
|
269
283
|
for action in ("expanded", "collapsed", "sorted"):
|
|
@@ -665,7 +679,7 @@ def _make_clear(method_name, widget_name):
|
|
|
665
679
|
self._state.pop(key, None)
|
|
666
680
|
return await self._call("clear")
|
|
667
681
|
method.__name__ = "clear"
|
|
668
|
-
method.__qualname__ =
|
|
682
|
+
method.__qualname__ = "Widget.clear"
|
|
669
683
|
method.__doc__ = "clear()"
|
|
670
684
|
return method
|
|
671
685
|
|
|
@@ -703,6 +717,7 @@ def _add_item_list_methods(attrs, item_cfg, all_methods):
|
|
|
703
717
|
|
|
704
718
|
if append_name and append_name in all_methods:
|
|
705
719
|
param_names = all_methods[append_name]
|
|
720
|
+
|
|
706
721
|
def make_append(mn, pn):
|
|
707
722
|
async def method(self, *args, **kwargs):
|
|
708
723
|
args = _resolve_kwargs(mn, pn, args, kwargs)
|
|
@@ -718,6 +733,7 @@ def _add_item_list_methods(attrs, item_cfg, all_methods):
|
|
|
718
733
|
if insert_name and insert_name in all_methods:
|
|
719
734
|
param_names = all_methods[insert_name]
|
|
720
735
|
alpha_sort = param_names == ["text"]
|
|
736
|
+
|
|
721
737
|
def make_insert(mn, pn, alpha):
|
|
722
738
|
async def method(self, *args, **kwargs):
|
|
723
739
|
args = _resolve_kwargs(mn, pn, args, kwargs)
|
|
@@ -741,6 +757,7 @@ def _add_item_list_methods(attrs, item_cfg, all_methods):
|
|
|
741
757
|
|
|
742
758
|
if delete_name and delete_name in all_methods:
|
|
743
759
|
param_names = all_methods[delete_name]
|
|
760
|
+
|
|
744
761
|
def make_delete(mn, pn):
|
|
745
762
|
async def method(self, *args, **kwargs):
|
|
746
763
|
args = _resolve_kwargs(mn, pn, args, kwargs)
|
|
@@ -766,6 +783,7 @@ def _add_tree_view_methods(attrs, all_methods):
|
|
|
766
783
|
|
|
767
784
|
if "sort_by_column" in all_methods:
|
|
768
785
|
param_names = all_methods["sort_by_column"]
|
|
786
|
+
|
|
769
787
|
async def sort_method(self, *args, **kwargs):
|
|
770
788
|
args = _resolve_kwargs("sort_by_column", param_names, args, kwargs)
|
|
771
789
|
col = args[0] if args else 0
|
|
@@ -777,6 +795,7 @@ def _add_tree_view_methods(attrs, all_methods):
|
|
|
777
795
|
|
|
778
796
|
if "expand_item" in all_methods:
|
|
779
797
|
param_names = all_methods["expand_item"]
|
|
798
|
+
|
|
780
799
|
async def expand_item_method(self, *args, **kwargs):
|
|
781
800
|
args = _resolve_kwargs("expand_item", param_names, args, kwargs)
|
|
782
801
|
path = args[0] if args else None
|
|
@@ -794,6 +813,7 @@ def _add_tree_view_methods(attrs, all_methods):
|
|
|
794
813
|
|
|
795
814
|
if "collapse_item" in all_methods:
|
|
796
815
|
param_names = all_methods["collapse_item"]
|
|
816
|
+
|
|
797
817
|
async def collapse_item_method(self, *args, **kwargs):
|
|
798
818
|
args = _resolve_kwargs("collapse_item", param_names, args, kwargs)
|
|
799
819
|
path = args[0] if args else None
|
|
@@ -886,6 +906,21 @@ def _add_tree_model_methods(attrs, all_methods):
|
|
|
886
906
|
return method
|
|
887
907
|
attrs[name] = make_bulk(name, state_key, all_methods[name])
|
|
888
908
|
|
|
909
|
+
# --- columns: also a private copy, since insert/append/delete_column
|
|
910
|
+
# edit the stored list in place -- without the copy they would edit
|
|
911
|
+
# the caller's list too. Unlike the row setters it keeps the styles.
|
|
912
|
+
if "set_columns" in all_methods:
|
|
913
|
+
param_names = all_methods["set_columns"]
|
|
914
|
+
|
|
915
|
+
async def set_columns_method(self, *args, **kwargs):
|
|
916
|
+
args = _resolve_kwargs("set_columns", param_names, args, kwargs)
|
|
917
|
+
self._state["columns"] = tree_model.copy_tree(
|
|
918
|
+
args[0] if args else None)
|
|
919
|
+
self._user_set_state.add("columns")
|
|
920
|
+
return await self._call("set_columns", *args)
|
|
921
|
+
set_columns_method.__name__ = "set_columns"
|
|
922
|
+
attrs["set_columns"] = set_columns_method
|
|
923
|
+
|
|
889
924
|
# --- per-cell writes fold into the model ---
|
|
890
925
|
if "set_cell" in all_methods:
|
|
891
926
|
param_names = all_methods["set_cell"]
|
|
@@ -1248,7 +1283,6 @@ def _add_colour_override_methods(attrs, all_methods):
|
|
|
1248
1283
|
attrs["clear_all_colors"] = clear_all_colors_method
|
|
1249
1284
|
|
|
1250
1285
|
|
|
1251
|
-
|
|
1252
1286
|
def _init_params(pos_names, opt_names):
|
|
1253
1287
|
"""Build the parameter string for the generated __init__.
|
|
1254
1288
|
|
pgwidgets/extras/file_browser.py
CHANGED
|
@@ -140,7 +140,7 @@ class FileBrowser(Callbacks):
|
|
|
140
140
|
|
|
141
141
|
# Build the dialog (autoclose=False; we manage closing ourselves)
|
|
142
142
|
self._dialog = W.Dialog(title, [["Cancel", "cancel"],
|
|
143
|
-
|
|
143
|
+
[ok_label, "ok"]],
|
|
144
144
|
autoclose=False, modal=modal,
|
|
145
145
|
moveable=True, resizable=True)
|
|
146
146
|
self._dialog.resize(550, 420)
|
|
@@ -448,8 +448,8 @@ class FileBrowser(Callbacks):
|
|
|
448
448
|
"""Show a confirmation dialog for overwriting an existing file."""
|
|
449
449
|
W = self._W
|
|
450
450
|
dlg = W.Dialog("Confirm Overwrite",
|
|
451
|
-
|
|
452
|
-
|
|
451
|
+
[["Cancel", "cancel"], ["Overwrite", "ok"]],
|
|
452
|
+
autoclose=True, modal=True)
|
|
453
453
|
dlg.resize(350, 140)
|
|
454
454
|
dlg.set_spacing(8)
|
|
455
455
|
name = os.path.basename(path)
|
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.
|
|
@@ -360,6 +362,7 @@ def colour_batches(widget, chunk=COLOUR_BATCH_SIZE):
|
|
|
360
362
|
batches.append({"cells": cells[i:i + chunk]})
|
|
361
363
|
return batches
|
|
362
364
|
|
|
365
|
+
|
|
363
366
|
# Default state values applied when a widget is created without
|
|
364
367
|
# explicitly setting the key (e.g. TextEntry() with no text arg).
|
|
365
368
|
STATE_DEFAULTS = {
|
|
@@ -452,32 +455,38 @@ def _index_to_widget(self, index):
|
|
|
452
455
|
return None
|
|
453
456
|
return self._children[index][0]
|
|
454
457
|
|
|
458
|
+
|
|
455
459
|
def _index_of(self, child):
|
|
456
460
|
for i, entry in enumerate(self._children):
|
|
457
461
|
if entry[0] is child:
|
|
458
462
|
return i
|
|
459
463
|
return -1
|
|
460
464
|
|
|
465
|
+
|
|
461
466
|
def _dialog_popup(self, x=None, y=None):
|
|
462
467
|
self._state["visible"] = True
|
|
463
468
|
if x is not None and y is not None:
|
|
464
469
|
self._state["position"] = (x, y)
|
|
465
470
|
return self._call("popup", x, y)
|
|
466
471
|
|
|
472
|
+
|
|
467
473
|
def _get_menu(self, name):
|
|
468
474
|
for entry in self._replay_calls:
|
|
469
475
|
if entry[0] == "add_menu" and entry[1] and entry[1][0] == name:
|
|
470
476
|
return entry[2]
|
|
471
477
|
return None
|
|
472
478
|
|
|
479
|
+
|
|
473
480
|
def _menuaction_set_state(self, tf):
|
|
474
481
|
"""Alias for MenuAction.set_checked — keeps a single state key."""
|
|
475
482
|
return self.set_checked(tf)
|
|
476
483
|
|
|
484
|
+
|
|
477
485
|
def _menuaction_get_state(self):
|
|
478
486
|
"""Alias for MenuAction.get_checked — keeps a single state key."""
|
|
479
487
|
return self.get_checked()
|
|
480
488
|
|
|
489
|
+
|
|
481
490
|
# Above this size (bytes), set_binary_image switches from the single-
|
|
482
491
|
# frame _send_binary transport to the chunked _send_binary_chunked
|
|
483
492
|
# transport. Keeps small frames cheap and lets multi-megabyte frames
|
|
@@ -540,6 +549,7 @@ def _image_set_binary_image(self, data, format="jpeg"):
|
|
|
540
549
|
_send_binary_auto(self._session, self._wid,
|
|
541
550
|
"set_binary_image", [format], data)
|
|
542
551
|
|
|
552
|
+
|
|
543
553
|
# State keys whose value is a (format, bytes) tuple that must be
|
|
544
554
|
# replayed via _send_binary instead of _call during reconstruction.
|
|
545
555
|
# Maps state_key -> JS-side method name to invoke. The replay packs
|
|
@@ -592,6 +602,9 @@ CUSTOM_METHODS = {
|
|
|
592
602
|
("Image", "set_binary_image"): _image_set_binary_image,
|
|
593
603
|
}
|
|
594
604
|
|
|
605
|
+
# tab insertion and moves keep the tab order (see pgwidgets.tab_model)
|
|
606
|
+
CUSTOM_METHODS.update(TAB_CUSTOM_METHODS)
|
|
607
|
+
|
|
595
608
|
|
|
596
609
|
def _state_key_for_setter(method_name):
|
|
597
610
|
"""Derive the state key from a set_* method name."""
|
pgwidgets/sync/application.py
CHANGED
|
@@ -29,11 +29,13 @@ 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
|
-
SPECIAL_SETTERS, FIXED_SETTERS,
|
|
35
|
+
SPECIAL_SETTERS, FIXED_SETTERS,
|
|
34
36
|
STATE_SYNC_CALLBACKS, STATE_SYNC_REQUIRES_OPTION,
|
|
35
37
|
WIDGET_CALLBACK_SYNC, POST_CHILDREN_STATE_KEYS, ITEM_LIST_CONFIG,
|
|
36
|
-
CHILD_CLOSE_CALLBACKS,
|
|
38
|
+
CHILD_CLOSE_CALLBACKS,
|
|
37
39
|
TREE_OVERRIDE_REPLAY, colour_batches, JS_ONLY_METHODS,
|
|
38
40
|
coalesce_colour_calls,
|
|
39
41
|
BINARY_STATE_KEYS, _send_binary_auto,
|
|
@@ -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:
|
|
@@ -876,6 +883,7 @@ class Session:
|
|
|
876
883
|
"method": method,
|
|
877
884
|
"args": list(args),
|
|
878
885
|
}, cls=JsonEncoder)
|
|
886
|
+
|
|
879
887
|
# Send header + binary as an atomic pair on each connection so
|
|
880
888
|
# they can't be interleaved with other sends from another
|
|
881
889
|
# thread. The pair is wrapped in a single coroutine.
|
|
@@ -1571,7 +1579,6 @@ class Session:
|
|
|
1571
1579
|
"""Determine which child method a container uses."""
|
|
1572
1580
|
# Check the widget's definition for which child methods it has
|
|
1573
1581
|
defn = WIDGETS[parent._js_class]
|
|
1574
|
-
base = defn.get("base")
|
|
1575
1582
|
methods = defn.get("methods", {})
|
|
1576
1583
|
if "set_widget" in methods:
|
|
1577
1584
|
return "set_widget"
|
|
@@ -2159,6 +2166,7 @@ class Application:
|
|
|
2159
2166
|
self._dispatch(session, do_reconstruct, ())
|
|
2160
2167
|
else:
|
|
2161
2168
|
self._logger.info(f"Session {session.id} connected.")
|
|
2169
|
+
|
|
2162
2170
|
def do_connect():
|
|
2163
2171
|
# Replay fonts before the user callback so any widget
|
|
2164
2172
|
# the user builds with ``set_font(family, ...)`` sees
|
pgwidgets/sync/widget.py
CHANGED
|
@@ -13,9 +13,9 @@ 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
|
-
CHILD_METHODS as CHILD_METHOD_TYPES,
|
|
19
19
|
FIXED_SETTERS, CLEAR_RESETS, ITEM_LIST_CONFIG,
|
|
20
20
|
REPLAY_METHODS, CHILD_SELECT_METHODS, TREE_VIEW_WIDGETS,
|
|
21
21
|
STATE_SYNC_CALLBACKS, STATE_SYNC_REQUIRES_OPTION,
|
|
@@ -122,6 +122,10 @@ class Widget:
|
|
|
122
122
|
# Store constructor info for reconstruction
|
|
123
123
|
self._constructor_args = tuple(args[:len(pos_names)])
|
|
124
124
|
self._constructor_options = dict(options)
|
|
125
|
+
if self._constructor_options.get("columns") is not None:
|
|
126
|
+
# the replay record, so keep it safe from the caller's edits
|
|
127
|
+
self._constructor_options["columns"] = tree_model.copy_tree(
|
|
128
|
+
self._constructor_options["columns"])
|
|
125
129
|
|
|
126
130
|
# Store constructor args as initial state (None means "not
|
|
127
131
|
# provided" since generated __init__ defaults all args to None)
|
|
@@ -130,6 +134,10 @@ class Widget:
|
|
|
130
134
|
self._state[name] = args[i]
|
|
131
135
|
for k, v in options.items():
|
|
132
136
|
if v is not None:
|
|
137
|
+
# the column list is edited in place later (see
|
|
138
|
+
# _add_tree_model_methods), so keep a copy of the caller's
|
|
139
|
+
if k == "columns":
|
|
140
|
+
v = tree_model.copy_tree(v)
|
|
133
141
|
self._state[k] = v
|
|
134
142
|
|
|
135
143
|
# Apply default state for keys not set by constructor
|
|
@@ -233,6 +241,12 @@ class Widget:
|
|
|
233
241
|
session._listen(wid, action, lambda wid, *a: None)
|
|
234
242
|
self._auto_sync_actions.add(action)
|
|
235
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
|
+
|
|
236
250
|
# Tree/table state callbacks
|
|
237
251
|
if js_class in TREE_VIEW_WIDGETS:
|
|
238
252
|
for action in ("expanded", "collapsed", "sorted"):
|
|
@@ -655,7 +669,7 @@ def _make_clear(method_name, widget_name):
|
|
|
655
669
|
self._state.pop(key, None)
|
|
656
670
|
return self._call("clear")
|
|
657
671
|
method.__name__ = "clear"
|
|
658
|
-
method.__qualname__ =
|
|
672
|
+
method.__qualname__ = "Widget.clear"
|
|
659
673
|
method.__doc__ = "clear()"
|
|
660
674
|
return method
|
|
661
675
|
|
|
@@ -700,6 +714,7 @@ def _add_item_list_methods(attrs, item_cfg, all_methods):
|
|
|
700
714
|
|
|
701
715
|
if append_name and append_name in all_methods:
|
|
702
716
|
param_names = all_methods[append_name]
|
|
717
|
+
|
|
703
718
|
def make_append(mn, pn):
|
|
704
719
|
def method(self, *args, **kwargs):
|
|
705
720
|
args = _resolve_kwargs(mn, pn, args, kwargs)
|
|
@@ -719,6 +734,7 @@ def _add_item_list_methods(attrs, item_cfg, all_methods):
|
|
|
719
734
|
# local list matches the browser's order. Otherwise treat the
|
|
720
735
|
# second arg as an explicit insert index.
|
|
721
736
|
alpha_sort = param_names == ["text"]
|
|
737
|
+
|
|
722
738
|
def make_insert(mn, pn, alpha):
|
|
723
739
|
def method(self, *args, **kwargs):
|
|
724
740
|
args = _resolve_kwargs(mn, pn, args, kwargs)
|
|
@@ -742,6 +758,7 @@ def _add_item_list_methods(attrs, item_cfg, all_methods):
|
|
|
742
758
|
|
|
743
759
|
if delete_name and delete_name in all_methods:
|
|
744
760
|
param_names = all_methods[delete_name]
|
|
761
|
+
|
|
745
762
|
def make_delete(mn, pn):
|
|
746
763
|
def method(self, *args, **kwargs):
|
|
747
764
|
args = _resolve_kwargs(mn, pn, args, kwargs)
|
|
@@ -767,6 +784,7 @@ def _add_tree_view_methods(attrs, all_methods):
|
|
|
767
784
|
|
|
768
785
|
if "sort_by_column" in all_methods:
|
|
769
786
|
param_names = all_methods["sort_by_column"]
|
|
787
|
+
|
|
770
788
|
def sort_method(self, *args, **kwargs):
|
|
771
789
|
args = _resolve_kwargs("sort_by_column", param_names, args, kwargs)
|
|
772
790
|
col = args[0] if args else 0
|
|
@@ -778,6 +796,7 @@ def _add_tree_view_methods(attrs, all_methods):
|
|
|
778
796
|
|
|
779
797
|
if "expand_item" in all_methods:
|
|
780
798
|
param_names = all_methods["expand_item"]
|
|
799
|
+
|
|
781
800
|
def expand_item_method(self, *args, **kwargs):
|
|
782
801
|
args = _resolve_kwargs("expand_item", param_names, args, kwargs)
|
|
783
802
|
path = args[0] if args else None
|
|
@@ -795,6 +814,7 @@ def _add_tree_view_methods(attrs, all_methods):
|
|
|
795
814
|
|
|
796
815
|
if "collapse_item" in all_methods:
|
|
797
816
|
param_names = all_methods["collapse_item"]
|
|
817
|
+
|
|
798
818
|
def collapse_item_method(self, *args, **kwargs):
|
|
799
819
|
args = _resolve_kwargs("collapse_item", param_names, args, kwargs)
|
|
800
820
|
path = args[0] if args else None
|
|
@@ -886,6 +906,21 @@ def _add_tree_model_methods(attrs, all_methods):
|
|
|
886
906
|
return method
|
|
887
907
|
attrs[name] = make_bulk(name, state_key, all_methods[name])
|
|
888
908
|
|
|
909
|
+
# --- columns: also a private copy, since insert/append/delete_column
|
|
910
|
+
# edit the stored list in place -- without the copy they would edit
|
|
911
|
+
# the caller's list too. Unlike the row setters it keeps the styles.
|
|
912
|
+
if "set_columns" in all_methods:
|
|
913
|
+
param_names = all_methods["set_columns"]
|
|
914
|
+
|
|
915
|
+
def set_columns_method(self, *args, **kwargs):
|
|
916
|
+
args = _resolve_kwargs("set_columns", param_names, args, kwargs)
|
|
917
|
+
self._state["columns"] = tree_model.copy_tree(
|
|
918
|
+
args[0] if args else None)
|
|
919
|
+
self._user_set_state.add("columns")
|
|
920
|
+
return self._call("set_columns", *args)
|
|
921
|
+
set_columns_method.__name__ = "set_columns"
|
|
922
|
+
attrs["set_columns"] = set_columns_method
|
|
923
|
+
|
|
889
924
|
# --- per-cell writes fold into the model ---
|
|
890
925
|
if "set_cell" in all_methods:
|
|
891
926
|
param_names = all_methods["set_cell"]
|
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
|
-
pgwidgets/extras/file_browser.py,sha256=
|
|
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
|