I want a kitchen timer. But with apps, I can't always see it by opening the browser. Then I thought that the iPhone would be fine, but I couldn't touch my cellphone! !!
I want a kitchen timer that doesn't take up space where I can always see it! that? The status bar at the top of the Mac is good! Let's make it!
I tried to make it like this.
I referred to this article. https://qiita.com/hartmann16325/items/8667611fcaf68b9a948b
Since I use python, I checked and found that it is possible to operate in the status bar by using a library called rumps.
I've posted it on GitHub, so if you'd like, please! https://github.com/tokky08/Kitchen_timer
@rumps.clicked(u'Half an hour')
def selectTimer(sender):
global minute
minute = 30
global start
start = time.time()
Here is the creation of the menu bar.
@rumps.timer(1)
def dispTimer(sender):
timer_minute = str(minute-1)
timer_second = str(second - int(time.time() - start) % 60)
remaining_minute = int(time.time() - start) // 60
timer_minute = str(int(timer_minute) - remaining_minute)
if int(timer_minute) < 0:
app.title = "TIME UP"
if int(timer_minute) == -1 and int(timer_second) == 58:
rumps.notification(message="Please stop working! !! !!", title="TIME UP!", subtitle="")
else:
if int(timer_second) < 10:
timer_second = "0" + timer_second
app.title = "remaining time:" + timer_minute + ":" + timer_second
Here this function is executed every second. I think it is divided into minutes and seconds.
For minutes, time.time ()-start
is calculated as the number of seconds from the beginning of the countdown minus the time this function was executed.
And second
is 59 here.
second-int (time.time ()-start)
indicates that it decreases by 1 second.
The reason why it is% 60 is that it does not become negative.
Seconds represent the minutes elapsed in remaining_minute
.
You can represent the remaining minutes by subtracting it from the selected time.
I thought about it and researched it, and it took 6 hours to complete. Even if it looks easy, there are some challenges when it comes to making it. Still, the idea can be realized and programming is interesting! I think.
Please point out any mistakes.
Recommended Posts