syd 1.2.5__py3-none-any.whl → 1.2.6__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.
syd/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.2.5"
1
+ __version__ = "1.2.6"
2
2
 
3
3
  from .viewer import make_viewer, Viewer
4
4
  from .support import show_open_servers, close_servers
@@ -396,49 +396,14 @@ class FlaskDeployer:
396
396
  "Flask app not built. Call build_layout() before display()."
397
397
  )
398
398
 
399
+ print(self.port, self.host)
400
+
399
401
  # Find an available port if none is specified
400
- self.port = port or _find_available_port()
401
402
  self.host = host or socket.gethostbyname(socket.gethostname())
403
+ self.port = port or _find_available_port(address=self.host)
402
404
  self.url = f"http://{self.host}:{self.port}"
403
405
  print(f" * Syd Flask server running on {self.url}")
404
406
 
405
- # if open_browser:
406
-
407
- # def wait_until_responsive(url, timeout=self.timeout_threshold):
408
- # start_time = time.time()
409
- # while time.time() - start_time < timeout:
410
- # try:
411
- # r = requests.get(url, timeout=0.5)
412
- # if r.status_code == 200:
413
- # return True
414
- # except requests.exceptions.RequestException:
415
- # pass
416
- # time.sleep(0.1)
417
- # return False
418
-
419
- # def open_browser_tab_when_ready():
420
- # if wait_until_responsive(self.url):
421
- # out = webbrowser.open(self.url, new=1, autoraise=True)
422
- # else:
423
- # print(
424
- # f"Could not open browser: server at {self.url} not responding."
425
- # f"Increase the timeout_threshold to fix this! It's set to {self.timeout_threshold} seconds."
426
- # "You can do this from viewer.show(timeout_threshold=...) or in the FlaskDeployer constructor."
427
- # "Also, this is unexpected so please report this issue on GitHub."
428
- # )
429
-
430
- # threading.Thread(target=open_browser_tab_when_ready, daemon=True).start()
431
-
432
- # # Run the Flask server using Werkzeug's run_simple
433
- # # Pass debug status to run_simple for auto-reloading
434
- # run_simple(
435
- # self.host,
436
- # self.port,
437
- # self.app,
438
- # use_reloader=False,
439
- # use_debugger=self.debug,
440
- # )
441
-
442
407
  # 1) Spin up the server thread
443
408
  srv_thread = ServerThread(self.host, self.port, self.app, debug=self.debug)
444
409
  srv_thread.start()
@@ -460,7 +425,7 @@ class FlaskDeployer:
460
425
  """
461
426
  Deploy the viewer using Flask.
462
427
 
463
- Builds components (no-op), layout (Flask app/routes),
428
+ Builds components, layout (Flask app/routes),
464
429
  and then starts the server.
465
430
  """
466
431
  # build_layout creates the Flask app and routes
@@ -704,14 +669,15 @@ class FlaskDeployer:
704
669
  )
705
670
 
706
671
 
707
- def _find_available_port(start_port=5000, max_attempts=1000):
672
+ def _find_available_port(
673
+ start_port=5000,
674
+ max_attempts=1000,
675
+ address: str = "127.0.0.1",
676
+ ):
708
677
  """
709
678
  Find an available port starting from start_port.
710
- (Identical to original)
711
679
  """
712
680
  for port in range(start_port, start_port + max_attempts):
713
- # Use localhost address explicitly
714
- address = "127.0.0.1"
715
681
  try:
716
682
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
717
683
  # Check if the port is usable
syd/viewer.py CHANGED
@@ -209,7 +209,7 @@ class Viewer:
209
209
  def plot(self, state: Dict[str, Any]) -> Figure:
210
210
  """Create and return a matplotlib figure.
211
211
 
212
- This is a placeholder. You must either:
212
+ Hello user! This is a placeholder that raises a NotImplementedError. You must either:
213
213
 
214
214
  1. Call set_plot() with your plotting function
215
215
  This will look like this:
@@ -249,7 +249,19 @@ class Viewer:
249
249
  )
250
250
 
251
251
  def set_plot(self, func: Callable) -> None:
252
- """Set the plot method for the viewer"""
252
+ """Set the plot method for the viewer.
253
+
254
+ For viewers created with make_viewer(), this function is used to set the plot method.
255
+ The input must be a callable function that takes a state dictionary and returns a matplotlib figure.
256
+
257
+ Examples
258
+ --------
259
+ >>> def plot(state):
260
+ >>> ... generate figure, plot stuff ...
261
+ >>> return fig
262
+ >>> viewer = make_viewer()
263
+ >>> viewer.set_plot(plot)
264
+ """
253
265
  self.plot = self._prepare_function(func, context="Setting plot:")
254
266
 
255
267
  def show(
@@ -259,9 +271,25 @@ class Viewer:
259
271
  suppress_warnings: bool = True,
260
272
  update_threshold: float = 1.0,
261
273
  ):
262
- """Show the viewer in a notebook
274
+ """
275
+ Show the viewer locally in a notebook.
263
276
 
264
- Same as deploy(env="notebook") except it doesn't return the viewer object.
277
+ This method displays the viewer in a Jupyter notebook environment with interactive controls.
278
+
279
+ Parameters
280
+ ----------
281
+ controls_position : {'left', 'top', 'right', 'bottom'}, optional
282
+ Position of the controls relative to the plot (default is 'left').
283
+ controls_width_percent : int, optional
284
+ Width of the controls as a percentage of the total viewer width (default is 20).
285
+ suppress_warnings : bool, optional
286
+ If True, suppress warnings during deployment (default is True).
287
+ update_threshold : float, optional
288
+ Minimum time in seconds between updates to the viewer (default is 1.0).
289
+
290
+ Notes
291
+ -----
292
+ This method is equivalent to calling `deploy(env="notebook")` but does not return the viewer object.
265
293
  """
266
294
  _ = self.deploy(
267
295
  env="notebook",
@@ -285,9 +313,37 @@ class Viewer:
285
313
  update_threshold: float = 1.0,
286
314
  timeout_threshold: float = 10.0,
287
315
  ):
288
- """Share the viewer on a web browser using Flask
316
+ """
317
+ Share the viewer on a web browser using Flask.
289
318
 
290
- Same as deploy(env="browser") except it doesn't return the viewer object.
319
+ Parameters
320
+ ----------
321
+ controls_position : str, optional
322
+ Position of the controls relative to the plot (default is 'left').
323
+ fig_dpi : int, optional
324
+ Dots per inch for the figure resolution (default is 300).
325
+ controls_width_percent : int, optional
326
+ Width of the controls as a percentage of the total viewer width (default is 20).
327
+ plot_margin_percent : float, optional
328
+ Margin around the plot as a percentage of the plot size (default is 2.5).
329
+ suppress_warnings : bool, optional
330
+ If True, suppress warnings during deployment (default is True).
331
+ debug : bool, optional
332
+ If True, run the server in debug mode (default is False).
333
+ host : str, optional
334
+ Hostname to use for the server (default is None, which uses 'localhost').
335
+ port : int, optional
336
+ Port number to use for the server (default is None, which selects the first available port).
337
+ open_browser : bool, optional
338
+ If True, automatically open the web browser to the viewer (default is True).
339
+ update_threshold : float, optional
340
+ Minimum time in seconds between updates to the viewer (default is 1.0).
341
+ timeout_threshold : float, optional
342
+ Maximum time in seconds to wait for a response before timing out (default is 10.0).
343
+
344
+ Notes
345
+ -----
346
+ This method is equivalent to calling `deploy(env="browser")` but does not return the viewer object.
291
347
  """
292
348
  _ = self.deploy(
293
349
  env="browser",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syd
3
- Version: 1.2.5
3
+ Version: 1.2.6
4
4
  Summary: A Python package for making GUIs for data science easy.
5
5
  Project-URL: Homepage, https://github.com/landoskape/syd
6
6
  Author-email: Andrew Landau <andrew+tyler+landau+getridofthisanddtheplusses@gmail.com>
@@ -60,7 +60,7 @@ pip install syd
60
60
  The full documentation is available [here](https://shareyourdata.readthedocs.io/). It includes a quick start guide, a comprehensive tutorial, and an API reference for the different elements of Syd. If you have any questions or want to suggest improvements to the docs, please let us know on the [github issues page](https://github.com/landoskape/syd/issues)!
61
61
 
62
62
  ## Quick Start
63
- This is an example of a sine wave viewer which is about as simple as it gets. You can choose which env to use - if you use ``env="notebook"`` then the GUI will deploy as the output of a jupyter cell (this only works in jupyter!). If you use ``env="browser"`` then the GUI will open a page in your default web browser and you can interact with the data there (works in jupyter notebooks and also from python scripts!).
63
+ This is an example of a sine wave viewer which is about as simple as it gets. You can choose where you want to display the viewer. If you use ``viewer.show()`` then the GUI will deploy as the output of a jupyter cell (this only works in jupyter or colab!). If you use ``viewer.share()`` then the GUI will open a page in your default web browser and you can interact with the data there (works in jupyter notebooks and also from python scripts!).
64
64
 
65
65
  ```python
66
66
  import numpy as np
@@ -95,7 +95,9 @@ We have several examples of more complex viewers with detailed explanations in t
95
95
  | [Making a Viewer Class](examples/2b-subclass_example.ipynb) | Rewrites the comprehensive example as a class, which is useful when you have complex data processing or callbacks. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/landoskape/syd/blob/main/examples/2b-subclass_example.ipynb) |
96
96
  | [Data Loading](examples/3-data_loading.ipynb) | Showcases different ways to get your data into a Syd viewer. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/landoskape/syd/blob/main/examples/3-data_loading.ipynb) |
97
97
  | [Hierarchical Callbacks](examples/4-hierarchical_callbacks.ipynb) | Demonstrates how to handle complicated callback situations. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/landoskape/syd/blob/main/examples/4-hierarchical_callbacks.ipynb) |
98
-
98
+ | [Interactive plots with Seaborn](examples/5-interactive-with-seaborn.ipynb) | Showcases how to use Syd with Seaborn. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/landoskape/syd/blob/main/examples/5-interactive-with-seaborn.ipynb) |
99
+ | [Histology Viewer](examples/6-histology-viewer.ipynb) | Showcases how to use Syd to create a histology viewer for viewing histology slides on the fly. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/landoskape/syd/blob/main/examples/6-histology-viewer.ipynb) |
100
+ | [Image Labeler](examples/7-image-labeler.ipynb) | Showcases how to use Syd to create an image labeler for annotating images (like ROIs). | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/landoskape/syd/blob/main/examples/7-image-labeler.ipynb) |
99
101
 
100
102
  ### Data loading
101
103
  Thinking about how to get data into a Syd viewer can be non-intuitive. For some examples that showcase different ways to get your data into a Syd viewer, check out the [data loading example](examples/3-data_loading.ipynb). Or, if you just want a quick and fast example, check this one out:
@@ -1,9 +1,9 @@
1
- syd/__init__.py,sha256=vegsqm4zQ_sfa0BFitwk_n8yT_Fka5mN7gs_0yrMNPs,117
1
+ syd/__init__.py,sha256=Yt5zZh7xZGBEthWRjdA1_BKGx0v12I5uwmbtltY6WXs,117
2
2
  syd/parameters.py,sha256=lzCHSMGYEdQ_FMbcXnntdPF1XvCm7fybB6CNy3TFn04,43543
3
3
  syd/support.py,sha256=LoHOsTN0byyDxk9uibjM0BKnI-vAJ4aU-tWILMCXz1Y,6783
4
- syd/viewer.py,sha256=yKycDAFfyKu8WEp-VUtHVG1Ad4flQtQ3bHqPaQ4JWVM,52699
4
+ syd/viewer.py,sha256=U0TzAKDyORZ3KkNIq5HTCJqLJkD1hP7ua3Cr8KYZUOg,55383
5
5
  syd/flask_deployment/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
6
- syd/flask_deployment/deployer.py,sha256=TKlf4jtRN4t67cuHypcVZe2c8-P3zkXovO5EpXKW2LQ,29827
6
+ syd/flask_deployment/deployer.py,sha256=bRfR0YDScCWn5-1OQZVlDs_xWfL-6Ck_8a5dRs3zsow,28182
7
7
  syd/flask_deployment/testing_principles.md,sha256=GyULM97sDeie8h3tSPoduOckdMNGyWuwm1RdHo5jzK0,10130
8
8
  syd/flask_deployment/static/__init__.py,sha256=ieWE8NKR-APw7h4Ge0ooZGk6wZrneSSs_1cMyTPbQSA,65
9
9
  syd/flask_deployment/static/css/styles.css,sha256=GQgIPbWMdfTgU-HN80FCObA8bd1FPiwa1Dq0yRANsPc,5944
@@ -22,7 +22,7 @@ syd/flask_deployment/templates/index.html,sha256=KDMR-KTMpdQa1PS8py71-NSoGMAWE3q
22
22
  syd/notebook_deployment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  syd/notebook_deployment/deployer.py,sha256=ovuFvj5_qXB5WToNhCxrEHmPuKYypIeLqrUg0KjovQs,12706
24
24
  syd/notebook_deployment/widgets.py,sha256=ptys7exVA6NCF4eCRZMTPJblT0ZbtPdN4o2A0Yh5Cfc,20781
25
- syd-1.2.5.dist-info/METADATA,sha256=U4bMgpT10LCsQyI476ZO0l8PciUnOiOfdq2UEDzFyYo,15340
26
- syd-1.2.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- syd-1.2.5.dist-info/licenses/LICENSE,sha256=YF6QR6Vjxcg5b_sYIyqkME7FZYau5TfEUGTG-0JeRK0,35129
28
- syd-1.2.5.dist-info/RECORD,,
25
+ syd-1.2.6.dist-info/METADATA,sha256=lpnEeFJAEkn-mhdHmSXYLEUuQX9liGydartk_bqpwJw,16329
26
+ syd-1.2.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ syd-1.2.6.dist-info/licenses/LICENSE,sha256=YF6QR6Vjxcg5b_sYIyqkME7FZYau5TfEUGTG-0JeRK0,35129
28
+ syd-1.2.6.dist-info/RECORD,,
File without changes