pgwidgets-python 0.4.3__tar.gz → 0.5.0__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 (82) hide show
  1. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/PKG-INFO +2 -2
  2. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/WhatsNew.rst +16 -0
  3. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/callbacks.rst +9 -0
  4. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/widgets.rst +38 -3
  5. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/async_/application.py +7 -0
  6. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/async_/widget.py +7 -0
  7. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/method_types.py +5 -0
  8. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/sync/application.py +7 -0
  9. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/sync/widget.py +7 -0
  10. pgwidgets_python-0.5.0/pgwidgets/tab_model.py +186 -0
  11. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets_python.egg-info/PKG-INFO +2 -2
  12. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets_python.egg-info/SOURCES.txt +2 -0
  13. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets_python.egg-info/requires.txt +1 -1
  14. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets_python.egg-info/scm_file_list.json +2 -0
  15. pgwidgets_python-0.5.0/pgwidgets_python.egg-info/scm_version.json +8 -0
  16. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pyproject.toml +1 -15
  17. pgwidgets_python-0.5.0/tests/test_tab_moves.py +164 -0
  18. pgwidgets_python-0.4.3/pgwidgets_python.egg-info/scm_version.json +0 -8
  19. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/.flake8 +0 -0
  20. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/.github/workflows/tests.yml +0 -0
  21. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/.gitignore +0 -0
  22. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/.readthedocs.yaml +0 -0
  23. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/LICENSE.md +0 -0
  24. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/README.md +0 -0
  25. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/Makefile +0 -0
  26. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/api/async.rst +0 -0
  27. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/api/index.rst +0 -0
  28. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/api/sync.rst +0 -0
  29. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/architecture.rst +0 -0
  30. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/async.rst +0 -0
  31. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/conf.py +0 -0
  32. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/extras.rst +0 -0
  33. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/getting-started.rst +0 -0
  34. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/index.rst +0 -0
  35. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/subclassing.rst +0 -0
  36. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/sync.rst +0 -0
  37. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/utilities.rst +0 -0
  38. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/docs/web-servers.rst +0 -0
  39. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/README.md +0 -0
  40. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/all_widgets.py +0 -0
  41. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/all_widgets_async.py +0 -0
  42. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/demo_async.py +0 -0
  43. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/demo_sync.py +0 -0
  44. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/demo_treeview.py +0 -0
  45. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/flask-multi-process/README.md +0 -0
  46. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/flask-multi-process/gunicorn.conf.py +0 -0
  47. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/flask-multi-process/nginx.conf +0 -0
  48. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/flask-multi-process/server.py +0 -0
  49. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/examples/flask-multi-process/user_app.py +0 -0
  50. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/__init__.py +0 -0
  51. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/_json.py +0 -0
  52. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/async_/Widgets.py +0 -0
  53. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/async_/__init__.py +0 -0
  54. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/buffer.py +0 -0
  55. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/callbacks.py +0 -0
  56. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/defs.py +0 -0
  57. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/extras/__init__.py +0 -0
  58. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/extras/file_browser.py +0 -0
  59. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/icons/pgw-python-logo.png +0 -0
  60. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/sync/Widgets.py +0 -0
  61. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/sync/__init__.py +0 -0
  62. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/sync/text_source.py +0 -0
  63. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/text_model.py +0 -0
  64. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets/tree_model.py +0 -0
  65. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets_python.egg-info/dependency_links.txt +0 -0
  66. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/pgwidgets_python.egg-info/top_level.txt +0 -0
  67. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/setup.cfg +0 -0
  68. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/test_pg2.py +0 -0
  69. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/__init__.py +0 -0
  70. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_async_session.py +0 -0
  71. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_defs.py +0 -0
  72. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_extras.py +0 -0
  73. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_fonts.py +0 -0
  74. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_protocol.py +0 -0
  75. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_reconstruct.py +0 -0
  76. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_resolve_kwargs.py +0 -0
  77. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_session.py +0 -0
  78. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_stateful.py +0 -0
  79. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_text_source.py +0 -0
  80. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_tree_model.py +0 -0
  81. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tests/test_widget_classes.py +0 -0
  82. {pgwidgets_python-0.4.3 → pgwidgets_python-0.5.0}/tools/sync_async_tree_model.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgwidgets-python
3
- Version: 0.4.3
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.4.3
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"
@@ -1,6 +1,22 @@
1
1
  What's New
2
2
  ==========
3
3
 
4
+ Recent changes — since ``v0.4.3``
5
+ ---------------------------------
6
+
7
+ * TabWidget: tabs can be dragged between TabWidgets and detached, with
8
+ the new pgwidgets-js ``movable``, ``detachable`` and ``group`` options
9
+ and ``page-move``, ``page-reorder`` and ``page-detach`` callbacks.
10
+ * The session follows every tab move, whether made in code
11
+ (``insert_widget()``, ``move_tab()``, ``move_tab_from()``, ``remove()``)
12
+ or by the user dragging a tab: tab order and the current tab are kept,
13
+ so a reconnecting browser gets the same layout, and the move is pushed
14
+ to the session's other browsers.
15
+ * TabWidget ``insert_widget()`` inserts at the given position (it used to
16
+ be replayed at the end on reconnect).
17
+ * These need the pgwidgets-js release after 0.4.3; the dependency floor
18
+ will be raised when it is out.
19
+
4
20
  Recent changes — since ``v0.4.2``
5
21
  ---------------------------------
6
22
 
@@ -82,6 +82,15 @@ common patterns:
82
82
  * - ``page-close``
83
83
  - TabWidget, StackWidget, MDIWidget
84
84
  - ``(child: Widget)``
85
+ * - ``page-move``
86
+ - TabWidget (destination)
87
+ - ``(src: TabWidget, child: Widget, index: int)``
88
+ * - ``page-reorder``
89
+ - TabWidget
90
+ - ``(child: Widget, index: int)``
91
+ * - ``page-detach``
92
+ - TabWidget
93
+ - ``(child: Widget, x: int, y: int)``
85
94
  * - ``child-added``
86
95
  - All containers
87
96
  - ``(child: Widget)``
@@ -190,12 +190,16 @@ TabWidget
190
190
 
191
191
  Tabbed container.
192
192
 
193
- - **Options:** ``closable``, ``reorderable``, ``tab_position``
194
- - **Methods:** ``add_widget(child, options)``, ``show_widget(child)``,
193
+ - **Options:** ``closable``, ``reorderable``, ``movable``,
194
+ ``detachable``, ``group``, ``tab_position``
195
+ - **Methods:** ``add_widget(child, options)``,
196
+ ``insert_widget(index, child, options)``, ``move_tab(child, index)``,
197
+ ``move_tab_from(src, child, index)``, ``show_widget(child)``,
195
198
  ``close_widget(child)``, ``set_index(index)``, ``get_index()``,
196
199
  ``get_tab_id(child)``, ``get_child(tab_id)``, ``index_of(child)``,
197
200
  ``highlight_tab(child, bgcolor)``, ``set_tab_position(tabpos)``
198
- - **Callbacks:** ``child-added``, ``child-removed``, ``page-switch``, ``page-close``
201
+ - **Callbacks:** ``child-added``, ``child-removed``, ``page-switch``,
202
+ ``page-close``, ``page-move``, ``page-reorder``, ``page-detach``
199
203
 
200
204
  .. code-block:: python
201
205
 
@@ -203,6 +207,37 @@ Tabbed container.
203
207
  tabs.add_widget(panel1, {"title": "Tab 1"})
204
208
  tabs.add_widget(panel2, {"title": "Tab 2"})
205
209
 
210
+ **Dragging tabs.** With ``reorderable`` the user can drag a tab to
211
+ another position in its tab bar. With ``movable`` a tab can be dragged
212
+ to another movable TabWidget of the same ``group`` (default ``0``). With
213
+ ``detachable`` a tab can be dropped on the page background, outside of
214
+ any window -- but only if a ``page-detach`` handler is registered, since
215
+ the handler decides where the tab goes; the tab is not removed for it.
216
+ A drop anywhere else cancels the drag. See the pgwidgets-js
217
+ documentation for the details.
218
+
219
+ The session keeps its record of the tabs in step with every move, made
220
+ in code or by the user, so a reconnecting browser gets the same tab order
221
+ and current tab, and the other browsers of the session are shown the
222
+ move.
223
+
224
+ .. code-block:: python
225
+
226
+ left = Widgets.TabWidget(movable=True, detachable=True, group=1)
227
+ right = Widgets.TabWidget(movable=True, detachable=True, group=1)
228
+
229
+ def detach(child, x, y):
230
+ # give the detached tab a window of its own, where it was dropped
231
+ tabs = Widgets.TabWidget(movable=True, detachable=True, group=1)
232
+ top = Widgets.TopLevel(title="Detached", resizable=True)
233
+ top.set_widget(tabs)
234
+ left.remove(child)
235
+ tabs.add_widget(child, {"title": "Detached"})
236
+ top.set_position(x, y)
237
+ top.show()
238
+
239
+ left.on("page-detach", detach)
240
+
206
241
  StackWidget
207
242
  ~~~~~~~~~~~
208
243
 
@@ -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:
@@ -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"):
@@ -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."""
@@ -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:
@@ -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"):
@@ -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.4.3
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.4.3
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"
@@ -40,6 +40,7 @@ pgwidgets/buffer.py
40
40
  pgwidgets/callbacks.py
41
41
  pgwidgets/defs.py
42
42
  pgwidgets/method_types.py
43
+ pgwidgets/tab_model.py
43
44
  pgwidgets/text_model.py
44
45
  pgwidgets/tree_model.py
45
46
  pgwidgets/async_/Widgets.py
@@ -71,6 +72,7 @@ tests/test_reconstruct.py
71
72
  tests/test_resolve_kwargs.py
72
73
  tests/test_session.py
73
74
  tests/test_stateful.py
75
+ tests/test_tab_moves.py
74
76
  tests/test_text_source.py
75
77
  tests/test_tree_model.py
76
78
  tests/test_widget_classes.py
@@ -1,4 +1,4 @@
1
- pgwidgets-js>=0.4.3
1
+ pgwidgets-js>=0.5.0
2
2
  websockets>=12
3
3
 
4
4
  [dev]
@@ -52,6 +52,7 @@
52
52
  "pgwidgets/sync/application.py",
53
53
  "pgwidgets/sync/text_source.py",
54
54
  "pgwidgets/sync/widget.py",
55
+ "pgwidgets/tab_model.py",
55
56
  "pgwidgets/text_model.py",
56
57
  "pgwidgets/tree_model.py",
57
58
  "pyproject.toml",
@@ -66,6 +67,7 @@
66
67
  "tests/test_resolve_kwargs.py",
67
68
  "tests/test_session.py",
68
69
  "tests/test_stateful.py",
70
+ "tests/test_tab_moves.py",
69
71
  "tests/test_text_source.py",
70
72
  "tests/test_tree_model.py",
71
73
  "tests/test_widget_classes.py",
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.5.0",
3
+ "distance": 0,
4
+ "node": "gf173c6278ef90f5cc0cb56cc258c81ad6631a691",
5
+ "dirty": false,
6
+ "branch": "main",
7
+ "node_date": "2026-12-02"
8
+ }
@@ -14,21 +14,7 @@ authors = [
14
14
  {name = "PGWidgets Developers"},
15
15
  ]
16
16
  dependencies = [
17
- # A TreeView/TableView column descriptor's `sortable: False`, which
18
- # takes that column out of the header-click sort, is honoured by the
19
- # browser side from pgwidgets-js 0.4.3.
20
- # (TreeView.select_path()/select_paths()/select_all() rely on the
21
- # browser side defaulting their `state` argument, since the proxy
22
- # forwards only the arguments it was given -- 0.4.2; TextSource's
23
- # scroll alignment and set_cursor_style() need the matching
24
- # browser-side methods, introduced in pgwidgets-js 0.4.1;
25
- # earlier requirements — the incremental TreeView/TableView updates
26
- # and the "batch" / set_colors protocol messages date to 0.4.0; the
27
- # TextSource selection/tag-region and tooltip/scroll APIs, Separator,
28
- # Button.set_hover, ButtonBox.min_button_width, Dialog.set_title to
29
- # 0.3.4; set_min_size/set_max_size, the dict-tree TreeView, the
30
- # binary Image protocol, TopLevel window-control options to 0.2.0.)
31
- "pgwidgets-js>=0.4.3",
17
+ "pgwidgets-js>=0.5.0",
32
18
  "websockets>=12",
33
19
  ]
34
20
  keywords = ["widgets", "ui", "gui", "websocket", "browser"]
@@ -0,0 +1,164 @@
1
+ """
2
+ Tests for tabs moved between and within TabWidgets: the tab order and
3
+ current index that the session keeps (and replays on reconstruction),
4
+ whether the move is made by code or by the user dragging a tab in the
5
+ browser, and the calls pushed to the session's other browsers.
6
+ """
7
+
8
+ from tests.test_reconstruct import _make_session
9
+
10
+
11
+ def _tabs(W, prefix, n=3, **kwargs):
12
+ tw = W.TabWidget(**kwargs)
13
+ kids = []
14
+ for i in range(n):
15
+ child = W.Label(f"{prefix}{i}")
16
+ tw.add_widget(child, {"title": f"{prefix}{i}"})
17
+ kids.append(child)
18
+ return tw, kids
19
+
20
+
21
+ def _titles(tw):
22
+ return [entry[1][0]["title"] for entry in tw._children]
23
+
24
+
25
+ def _ref(w):
26
+ return {"__wid__": w.wid}
27
+
28
+
29
+ def _session_with_pushes():
30
+ s = _make_session()
31
+ pushed = []
32
+ s._push = lambda wid, method, *args: pushed.append((wid, method, args))
33
+ return s, pushed
34
+
35
+
36
+ def _replayed_titles(s, tw):
37
+ """The titles of the tabs of `tw`, in the order reconstruction adds
38
+ them to it."""
39
+ s.start_recording()
40
+ s.reconstruct()
41
+ s.stop_recording()
42
+ titles = []
43
+ for m in s._recorded:
44
+ if (m.get("type") == "call" and m.get("wid") == tw.wid
45
+ and m.get("method") == "add_widget"):
46
+ titles.append(m["args"][1]["title"])
47
+ return titles
48
+
49
+
50
+ class TestFromCode:
51
+
52
+ def test_insert_widget(self):
53
+ s = _make_session()
54
+ W = s.get_widgets()
55
+ tw, _kids = _tabs(W, "a")
56
+ x = W.Label("x")
57
+ tw.insert_widget(1, x, {"title": "x"})
58
+ assert _titles(tw) == ["a0", "x", "a1", "a2"]
59
+ assert tw.index_of(x) == 1
60
+ assert x._parent is tw
61
+ assert x not in s._root_widgets
62
+ assert _replayed_titles(s, tw) == ["a0", "x", "a1", "a2"]
63
+
64
+ def test_insert_keeps_current_tab(self):
65
+ s = _make_session()
66
+ W = s.get_widgets()
67
+ tw, _kids = _tabs(W, "a")
68
+ tw.set_index(1)
69
+ tw.insert_widget(0, W.Label("x"), {"title": "x"})
70
+ assert tw.get_index() == 2
71
+
72
+ def test_remove_keeps_current_tab(self):
73
+ s = _make_session()
74
+ W = s.get_widgets()
75
+ tw, kids = _tabs(W, "a")
76
+ tw.set_index(2)
77
+ tw.remove(kids[0])
78
+ assert tw.get_index() == 1
79
+ assert kids[0] in s._root_widgets
80
+ assert kids[0]._parent is None
81
+
82
+ def test_move_tab(self):
83
+ s = _make_session()
84
+ W = s.get_widgets()
85
+ tw, kids = _tabs(W, "a")
86
+ tw.move_tab(kids[0], 2)
87
+ assert _titles(tw) == ["a1", "a2", "a0"]
88
+ assert tw.get_index() == 2
89
+ assert _replayed_titles(s, tw) == ["a1", "a2", "a0"]
90
+
91
+ def test_move_tab_from(self):
92
+ s = _make_session()
93
+ W = s.get_widgets()
94
+ a, akids = _tabs(W, "a")
95
+ b, _bkids = _tabs(W, "b")
96
+ b.move_tab_from(a, akids[1], 1)
97
+ assert _titles(a) == ["a0", "a2"]
98
+ assert _titles(b) == ["b0", "a1", "b1", "b2"]
99
+ assert akids[1]._parent is b
100
+ assert b.get_index() == 1
101
+ assert _replayed_titles(s, b) == ["b0", "a1", "b1", "b2"]
102
+
103
+
104
+ class TestFromBrowser:
105
+
106
+ def test_page_move(self):
107
+ s, pushed = _session_with_pushes()
108
+ W = s.get_widgets()
109
+ a, akids = _tabs(W, "a", movable=True, group=1)
110
+ b, _bkids = _tabs(W, "b", movable=True, group=1)
111
+ a.set_index(2)
112
+ child = akids[0]
113
+
114
+ s._dispatch_callback(b.wid, "page-move", _ref(a), _ref(child), 1)
115
+
116
+ assert _titles(a) == ["a1", "a2"]
117
+ assert _titles(b) == ["b0", "a0", "b1", "b2"]
118
+ assert child._parent is b
119
+ # the current tab of the source stays the same tab
120
+ assert a.get_index() == 1
121
+ assert b.get_index() == 1
122
+ assert pushed == [(b.wid, "move_tab_from",
123
+ (_ref(a), _ref(child), 1))]
124
+ assert _replayed_titles(s, b) == ["b0", "a0", "b1", "b2"]
125
+ assert _replayed_titles(s, a) == ["a1", "a2"]
126
+
127
+ def test_page_move_of_current_tab(self):
128
+ s, _pushed = _session_with_pushes()
129
+ W = s.get_widgets()
130
+ a, akids = _tabs(W, "a", movable=True)
131
+ b, _bkids = _tabs(W, "b", movable=True)
132
+ a.set_index(1)
133
+ # the browser shows a neighbour of the tab that went, and says so
134
+ # before it reports the move
135
+ s._dispatch_callback(a.wid, "page-switch", _ref(akids[2]), 1)
136
+ s._dispatch_callback(b.wid, "page-move", _ref(a), _ref(akids[1]), 3)
137
+ assert a.get_index() == 1
138
+ assert a.index_to_widget(1) is akids[2]
139
+ assert _titles(b) == ["b0", "b1", "b2", "a1"]
140
+
141
+ def test_page_reorder(self):
142
+ s, pushed = _session_with_pushes()
143
+ W = s.get_widgets()
144
+ tw, kids = _tabs(W, "a", reorderable=True)
145
+ s._dispatch_callback(tw.wid, "page-reorder", _ref(kids[0]), 2)
146
+ assert _titles(tw) == ["a1", "a2", "a0"]
147
+ assert tw.get_index() == 2
148
+ assert pushed == [(tw.wid, "move_tab", (_ref(kids[0]), 2))]
149
+
150
+ def test_unknown_child_is_ignored(self):
151
+ s, pushed = _session_with_pushes()
152
+ W = s.get_widgets()
153
+ a, _akids = _tabs(W, "a")
154
+ b, bkids = _tabs(W, "b")
155
+ s._dispatch_callback(b.wid, "page-move", _ref(a), _ref(bkids[0]), 0)
156
+ assert _titles(a) == ["a0", "a1", "a2"]
157
+ assert _titles(b) == ["b0", "b1", "b2"]
158
+ assert pushed == []
159
+
160
+ def test_listened_for(self):
161
+ s = _make_session()
162
+ W = s.get_widgets()
163
+ tw, _kids = _tabs(W, "a")
164
+ assert {"page-move", "page-reorder"} <= tw._auto_sync_actions
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "0.4.3",
3
- "distance": 0,
4
- "node": "gc355a17b4d5de8d8307e1e5ee3a64a10b3dd1eab",
5
- "dirty": false,
6
- "branch": "main",
7
- "node_date": "2026-10-28"
8
- }