Skip to content

Commit

Permalink
Merge branch 'demo' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Jan 19, 2024
2 parents 8d3cb1c + 14d5cf3 commit f9fc89b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,14 @@ A complete demo of `tqdm_publisher` can be found in the `demo` directory, which

To run the demo, first install the dependencies:
```bash
pip install -r demo/requirements.txt
pip install tqdm_publisher[demo]
```

Then, run the Python script for the demo:
Then, run the base CLI command to start the demo server and client:
```bash
python demo/main.py
tqdm_publisher demo
```

Finally, open the demo web page in your browser:
```bash
open demo/index.html
```
> **Note:** Alternatively, you can run each part of the demo separately by running `tqdm_publisher demo --server` and `tqdm_publisher demo --client` in separate terminals.
You can then click the Create Progress Bar button to create a new `TQDMPublisher` instance, which will begin updating based on the `TQDMPublisher` instance in the Python script.
Finally, you can click the Create Progress Bar button to create a new `TQDMPublisher` instance, which will begin updating based on the `TQDMPublisher` instance in the Python script.
37 changes: 37 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import subprocess
import sys
from pathlib import Path

demo_base_path = Path(__file__).parent / "demo"

client_path = demo_base_path / "client.html"
server_path = demo_base_path/ "server.py"

def main():

command = sys.argv[1]
flags_list = sys.argv[2:]

client_flag = "--client" in flags_list
server_flag = "--server" in flags_list
both_flags = "--server" in flags_list and "--client" in flags_list

flags = dict(
client = not server_flag or both_flags,
server = not client_flag or both_flags,

)

if (command == "demo"):
if flags["client"]:
subprocess.run(["open", client_path])

if flags["server"]:
subprocess.run(["python", server_path])

else:
print(f"{command} is an invalid command.")


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions demo/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import subprocess

from pathlib import Path

client_path = Path(__file__).parent / "client.html"

def main():
subprocess.run(["open", client_path])

if __name__ == "__main__":
main()
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "vcs"

[project]
name = "tqdm_publisher"
version="0.1.0"
Expand Down Expand Up @@ -43,13 +46,9 @@ demo = [
"websockets==12.0"
]


[project.urls]
"Homepage" = "https://github.com/catalystneuro/tqdm_publisher"
"Bug Tracker" = "https://github.com/catalystneuro/tqdm_publisher/issues"

[tool.hatch.version]
source = "vcs"

[project.gui-scripts]
tqdm_publisher-demo-server = "demo.server:main"
tqdm_publisher = "cli:main"
11 changes: 6 additions & 5 deletions src/tqdm_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ def __init__(self, *args, **kwargs):

# Override the update method to call callbacks
def update(self, n=1, always_callback=False):
if super().update(n) or always_callback:
displayed = super().update(n)
for id in list(self.callbacks):
callback = self.callbacks.get(id)
if callback:
callback(self.format_dict)
return displayed

for id in list(self.callbacks):
callback = self.callbacks.get(id)
if callback:
callback(self.format_dict)


# Subscribe to updates
Expand Down

0 comments on commit f9fc89b

Please sign in to comment.