pgwidgets-python 0.3.1__py3-none-any.whl → 0.3.2__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.
@@ -1557,6 +1557,15 @@ class Application:
1557
1557
  }
1558
1558
  self._broadcast_font_msg(self._font_default_msg())
1559
1559
 
1560
+ def open_url(self, url):
1561
+ """Ask the connected browser(s) to open *url* in a new tab/window.
1562
+
1563
+ Fire-and-forget app-level command; opens the link in the *user's*
1564
+ browser rather than on the host running Python. (Reuses the
1565
+ generic per-session broadcast helper.)
1566
+ """
1567
+ self._broadcast_font_msg({"type": "open-url", "url": str(url)})
1568
+
1560
1569
  def _font_register_msg(self, entry):
1561
1570
  return {
1562
1571
  "type": "register-font",
@@ -1788,8 +1797,14 @@ class Application:
1788
1797
  The newly created session.
1789
1798
  """
1790
1799
  if session_id is None:
1800
+ # skip ids already taken by explicitly-created sessions
1801
+ # (e.g. a pre-created default session) so we never
1802
+ # silently overwrite an existing session
1791
1803
  session_id = self._next_session_id
1792
1804
  self._next_session_id += 1
1805
+ while session_id in self._sessions:
1806
+ session_id = self._next_session_id
1807
+ self._next_session_id += 1
1793
1808
  elif session_id in self._sessions:
1794
1809
  # If the existing session was auto-created by a browser
1795
1810
  # reconnect with the same token, return it so the user's
@@ -1954,12 +1969,14 @@ class Application:
1954
1969
 
1955
1970
  In the async API, callbacks are dispatched by the asyncio event
1956
1971
  loop directly, so this simply yields control for the requested
1957
- duration.
1972
+ duration. A *timeout* of ``0`` yields once (a non-blocking drain
1973
+ of ready callbacks), matching the sync API's contract.
1958
1974
 
1959
1975
  Parameters
1960
1976
  ----------
1961
1977
  timeout : float
1962
1978
  Seconds to yield to the event loop (default 0.1).
1979
+ Use ``0`` for a single non-blocking yield.
1963
1980
  """
1964
1981
  await asyncio.sleep(timeout)
1965
1982
 
pgwidgets/method_types.py CHANGED
@@ -56,7 +56,7 @@ JS_ONLY_METHODS = {
56
56
  # ComboBox
57
57
  "get_alpha",
58
58
  # Container
59
- "num_children",
59
+ "num_children", "is_container",
60
60
  # TabWidget lookups
61
61
  "get_tab_id", "get_child", "index_of",
62
62
  # MDIWidget
@@ -1828,6 +1828,20 @@ class Application:
1828
1828
  except Exception:
1829
1829
  pass
1830
1830
 
1831
+ def open_url(self, url):
1832
+ """Ask the connected browser(s) to open *url* in a new tab/window.
1833
+
1834
+ Fire-and-forget app-level command (mirrors set_default_font's
1835
+ per-session send). This opens the link in the *user's* browser
1836
+ rather than on the host running Python.
1837
+ """
1838
+ msg = {"type": "open-url", "url": str(url)}
1839
+ for session in list(self._sessions.values()):
1840
+ try:
1841
+ session._send(msg)
1842
+ except Exception:
1843
+ pass
1844
+
1831
1845
  def _font_register_msg(self, entry):
1832
1846
  return {
1833
1847
  "type": "register-font",
@@ -2062,8 +2076,14 @@ class Application:
2062
2076
  """
2063
2077
  with self._session_lock:
2064
2078
  if session_id is None:
2079
+ # skip ids already taken by explicitly-created sessions
2080
+ # (e.g. a pre-created default session) so we never
2081
+ # silently overwrite an existing session
2065
2082
  session_id = self._next_session_id
2066
2083
  self._next_session_id += 1
2084
+ while session_id in self._sessions:
2085
+ session_id = self._next_session_id
2086
+ self._next_session_id += 1
2067
2087
  elif session_id in self._sessions:
2068
2088
  # If the existing session was auto-created by a browser
2069
2089
  # reconnect with the same token, return it so the user's
@@ -2279,22 +2299,35 @@ class Application:
2279
2299
  ``concurrent`` modes, callbacks already run on their own threads
2280
2300
  so this method simply yields control briefly.
2281
2301
 
2302
+ A *timeout* of ``0`` drains every callback currently queued and
2303
+ returns immediately without blocking -- useful when pumping from
2304
+ within another event loop (e.g. a Jupyter kernel's asyncio loop).
2305
+
2282
2306
  Parameters
2283
2307
  ----------
2284
2308
  timeout : float
2285
2309
  Maximum seconds to spend processing events (default 0.1).
2310
+ Use ``0`` for a non-blocking drain of the pending queue.
2286
2311
  """
2287
2312
  if self._concurrency == "serialized":
2313
+ non_blocking = (timeout == 0)
2288
2314
  deadline = time.monotonic() + timeout
2289
2315
  while not self._shutdown.is_set():
2290
- remaining = deadline - time.monotonic()
2291
- if remaining <= 0:
2292
- break
2293
- try:
2294
- handler, args, kwargs, result_slot = \
2295
- self._cb_queue.get(timeout=min(remaining, 0.5))
2296
- except queue.Empty:
2297
- continue
2316
+ if non_blocking:
2317
+ try:
2318
+ handler, args, kwargs, result_slot = \
2319
+ self._cb_queue.get_nowait()
2320
+ except queue.Empty:
2321
+ break
2322
+ else:
2323
+ remaining = deadline - time.monotonic()
2324
+ if remaining <= 0:
2325
+ break
2326
+ try:
2327
+ handler, args, kwargs, result_slot = \
2328
+ self._cb_queue.get(timeout=min(remaining, 0.5))
2329
+ except queue.Empty:
2330
+ continue
2298
2331
  try:
2299
2332
  rv = handler(*args, **kwargs)
2300
2333
  if result_slot is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgwidgets-python
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Python bindings for the pgwidgets JavaScript widget library
5
5
  Author: PGWidgets Developers
6
6
  License: BSD-3-Clause
@@ -3,19 +3,19 @@ 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=1gOTR8pdX_t7E_UEyUy4rnWiFoh10tJSUAINA1mE-SU,18298
6
+ pgwidgets/method_types.py,sha256=_-rdE5BOYLra8x3BMKv5-QS4Z8YB29DBhUCDsGiB-Gw,18314
7
7
  pgwidgets/async_/Widgets.py,sha256=vld2xkvusBBEVbhbezaJsjBRRj3L7c17Up0pOVs8PGo,723
8
8
  pgwidgets/async_/__init__.py,sha256=rXB-v9XRrYt1imYuYikhkzIyiRqaYhlTpQei2LHaQ18,564
9
- pgwidgets/async_/application.py,sha256=5tUlfyE9ie0aFPh2WAs2VRvgyuqQmdaGTX0d1IkSB7o,80077
9
+ pgwidgets/async_/application.py,sha256=2RJNRerXu5LXG_UcMSi9HWOCAlEOu96TrRaoIcUZ86Q,80957
10
10
  pgwidgets/async_/widget.py,sha256=gO7eJh9LV3UY7yRLdeml_0gqmHnFB5VU3NWlDURLtfc,38042
11
11
  pgwidgets/extras/__init__.py,sha256=AXUmFtnn4RSlp6pJX6z55j-m_29VmfzpYIjQvAy7pO0,325
12
12
  pgwidgets/extras/file_browser.py,sha256=CXQSfJx1VQ-fJfhKNrVyqrkKTJEQngmiP954y70Fjo0,17229
13
13
  pgwidgets/sync/Widgets.py,sha256=7SaocMVMzFHhi51pjuEAr47Wez90b_a61kDbiv0jOfM,706
14
14
  pgwidgets/sync/__init__.py,sha256=SF5RTAvtu8BbYBWzpiCPipy6DJzNXf6nqk9xdvwxUhQ,542
15
- pgwidgets/sync/application.py,sha256=Gfft77F66PfRnr_8_FBqU0v_gWe4YC9M-q5rww1N-2U,94741
15
+ pgwidgets/sync/application.py,sha256=tcAJvSVdijfT_KBP4llY1tyg2AAmQM-1qocw8Zf51nM,96240
16
16
  pgwidgets/sync/widget.py,sha256=yrScNkZB34u0JXn3-kCB-1mPLxLysVbuaPsCjC8kq0E,38343
17
- pgwidgets_python-0.3.1.dist-info/licenses/LICENSE.md,sha256=LoM3fMTiMnQuHRCJghdjOtjnCrL8soBpu2PFk24Xvyg,1528
18
- pgwidgets_python-0.3.1.dist-info/METADATA,sha256=QKWuFclVrksOLKxHPqSM-6CoNVskbt_bw_rqaUa3WpI,4568
19
- pgwidgets_python-0.3.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
20
- pgwidgets_python-0.3.1.dist-info/top_level.txt,sha256=wwL6fBq0gU-JwzlM6TdduY1qYpu39ysqnnbQT-1bqAs,10
21
- pgwidgets_python-0.3.1.dist-info/RECORD,,
17
+ pgwidgets_python-0.3.2.dist-info/licenses/LICENSE.md,sha256=LoM3fMTiMnQuHRCJghdjOtjnCrL8soBpu2PFk24Xvyg,1528
18
+ pgwidgets_python-0.3.2.dist-info/METADATA,sha256=gzz5UD--Uq8I9azawdmXRE-G4KNDrTFDtkVhiNbTSzs,4568
19
+ pgwidgets_python-0.3.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
20
+ pgwidgets_python-0.3.2.dist-info/top_level.txt,sha256=wwL6fBq0gU-JwzlM6TdduY1qYpu39ysqnnbQT-1bqAs,10
21
+ pgwidgets_python-0.3.2.dist-info/RECORD,,