具有可选到期的计数计时器,可以暂停、恢复和重置。
项目描述
计时器
实现向上/向下计数计时器的类
安装
$ pip install count-timer
演示
这是 CountTimer 类的倒计时版本的基于文本的基本演示。您可以直接启动它:
$ demo
...或来自 Python:
$ python count_timer/demo_async.py
启动后,演示将提示您输入持续时间(倒计时计时器到期值)。计时器将在终端上开始倒计时。到期前 <10 秒时,时间将变为黄色,当到期前 <5 秒时,时间将变为红色。
按“q”将导致计时器退出。
按“r”将导致计时器以原始持续时间重新启动。
按空格键可以暂停/恢复计时器。
API
CountTimer(持续时间:浮动)
创建一个计数计时器,具有可配置的持续时间(秒)。计时器在 time 开始t=0,并使用系统时钟进行计数,直到它命中t=duration。此时,该expired属性设置为True。请注意,计数器会在到期时间之后继续递增。
如果duration设置为零(这是默认值),则计时器永不过期并继续计数。
可以使用该pause()方法暂停计时器。暂停时,计时器停止递增。当时钟再次恢复时(使用resume()方法),它会从停止的地方继续。
该计数器/定时器可用作“向上”定时器或“向下”定时器。默认的解释模式是“向上”,但如果您更喜欢倒计时时间,只需查看remaining属性而不是elapsed.
┌─────────────────────────────────────────────────────────────────────────────────────┐
│ count_timer.count_timer.CountTimer │
└─────────────────────────────────────────────────────────────────────────────────────┘
class CountTimer(duration=0):
A counting timer (w/ optional expiry that can be started, paused, resumed and reset
Configuration:
duration: Number of seconds to elapse before expiration
(optional; default: 0 - indicates time never expires)
Methods:
start(): start the timer
pause(): pause the timer
resume(): resume the timer
reset(): reset the timer to default (duration 0/paused/not started)
Properties:
paused: True if timer is paused
running: True if timer is running
duration: value of the 'duration' config param
elapsed: time (sec) since timer was started
remaining: time (sec) until timer expires
Inspiration from https://stackoverflow.com/a/60027719/4402572
def start(self):
Start the timer.
def pause(self):
Pause the timer.
def resume(self):
Resume the timer.
def reset(self, duration=0):
elapsed: float 自定时器启动以来的时间(秒)
paused: bool 定时器的计数是否已经暂停
running: bool 定时器当前是否正在运行(即内部递增)
expired: bool 是否超过定时器配置的过期值
start(): start() -> None 启动计时器,无限计数
pause(): pause() -> None 暂停计时器;计数停止,直到恢复
resume(): resume() -> None 恢复/取消暂停计时器 - 当计时器恢复时,倒计时从暂停时的位置开始
reset(): reset() -> None 将计时器恢复到第一次创建时的原始状态(暂停/尚未启动)
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
内置分布
count_timer -0.3.8-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 9818a0f41f1adb5db99bbfa6ab346a1f73acdea9f0e95474081ec0032afd28a0 |
|
| MD5 | 8445fa5aa58d77b3c1cf81a5c77365a1 |
|
| 布莱克2-256 | 947f6d28dee72cef3c98cc4034f22c4828a5637d0b467aaf249d244e9384eaf2 |