Skip to content

Commit

Permalink
Minor edits (#41)
Browse files Browse the repository at this point in the history
* doc : README.md loop section updated

* doc : CHANGELOG.md updated

* fix : sys_platform renamed to _sys_platform

* fix : loop renamed to _loop

* fix : play_process renamed to _play_process

* doc : Anaconda badge added to README.md

* doc : CHANGELOG.md updated

* doc : some indents in README.md
  • Loading branch information
sepandhaghighi authored Mar 30, 2024
1 parent ec72563 commit dc0132f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Changed
- `loop` parameter added to `play` function
- `NavaThread` class modified
- `README.md` modified
## [0.4] - 2024-02-19
### Added
- `feature_request.yml` template
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
<a href="https://badge.fury.io/py/nava">
<img src="https://badge.fury.io/py/nava.svg" alt="PyPI version" height="18">
</a>
<a href="https://codecov.io/gh/openscilab/nava">
<img src="https://codecov.io/gh/openscilab/nava/branch/main/graph/badge.svg" alt="Codecov">
</a>
<a href="https://anaconda.org/openscilab/nava">
<img src="https://anaconda.org/openscilab/nava/badges/version.svg">
</a>
<a href="https://codecov.io/gh/openscilab/nava">
<img src="https://codecov.io/gh/openscilab/nava/branch/main/graph/badge.svg" alt="Codecov">
</a>
<a href="https://discord.gg/MCbPKCFBs3">
<img src="https://img.shields.io/discord/1064533716615049236.svg" alt="Discord Channel">
</a>
Expand Down Expand Up @@ -133,7 +136,9 @@ stop(sound_id)

```python
from nava import play, stop
play("alarm.wav", async_mode=True, loop=True)
sound_id = play("alarm.wav", async_mode=True, loop=True)
time.sleep(100)
stop(sound_id)
```

### Error
Expand Down
34 changes: 17 additions & 17 deletions nava/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def __init__(self, loop, *args, **kwargs):
:type kwargs: dict
"""
super(NavaThread, self).__init__(*args, **kwargs)
self.sys_platform = sys.platform
self.play_process = None
self.loop = loop
self._sys_platform = sys.platform
self._play_process = None
self._loop = loop

def run(self):
"""
Expand All @@ -31,13 +31,13 @@ def run(self):
:return: None
"""
if self._target is not None:
if self.sys_platform == "win32":
self.play_process = self._target(*self._args, **self._kwargs)
if self._sys_platform == "win32":
self._play_process = self._target(*self._args, **self._kwargs)
else:
while True:
self.play_process = self._target(*self._args, **self._kwargs)
self.play_process.wait()
if not self.loop:
self._play_process = self._target(*self._args, **self._kwargs)
self._play_process.wait()
if not self._loop:
break

def stop(self):
Expand All @@ -46,19 +46,19 @@ def stop(self):
:return: None
"""
self.loop = False
if self.sys_platform == "win32":
self._loop = False
if self._sys_platform == "win32":
import winsound
winsound.PlaySound(None, winsound.SND_PURGE)
else:
if self.play_process is not None:
if self._play_process is not None:
try:
self.play_process.stdout.close()
self.play_process.stdin.close()
self.play_process.stderr.close()
self.play_process.kill()
self.play_process.terminate()
self._play_process.stdout.close()
self._play_process.stdin.close()
self._play_process.stderr.close()
self._play_process.kill()
self._play_process.terminate()
except ProcessLookupError:
pass
finally:
self.play_process.wait()
self._play_process.wait()

0 comments on commit dc0132f

Please sign in to comment.