Stopwatch - pause counter

M

Morten Klim

Hello everyone!
I've started developing a little application for one of my friends,
which he will use at work to measure his hours working + the time he
has breaks. I wanna do this in python cause, I just started with this
language and wanna get more fimiliar with it. Sometimes though, it's a
bit of a struggle.

I found a nice stopwatch using tkinter, and I've modified it a bit to
my needs. The only thing I'm missing now is he wan't a pause counter,
for how long the pause button has been pushed.
An example:
I've worked for 2 hours, and wanna go for a break, I push the pause
button.
The pause counter then starts ticking, until the start button is
pressed again. So I have both a counter for working hours and pause
hours. If the pause button is pressed again, the current time he has
kept his break can't be reset, so it has to add the new time it to the
current.
I hope that made sense.

Here is my code: http://pastebin.com/T8FkMusS

The variables at __init__
self._pausestart = 0.0
self._elapsedpause = 0.0
and the method _updatepause are a attempt to make this work.

Regards,
Morten
 
T

Terry Reedy

Hello everyone!
I've started developing a little application for one of my friends,
which he will use at work to measure his hours working + the time he
has breaks. I wanna do this in python cause, I just started with this
language and wanna get more fimiliar with it. Sometimes though, it's a
bit of a struggle.

I found a nice stopwatch using tkinter, and I've modified it a bit to
my needs. The only thing I'm missing now is he wan't a pause counter,
for how long the pause button has been pushed.
An example:
I've worked for 2 hours, and wanna go for a break, I push the pause
button.
The pause counter then starts ticking, until the start button is
pressed again. So I have both a counter for working hours and pause
hours. If the pause button is pressed again,

when working or when already paused?
the current time he has kept his break can't be reset,
so it has to add the new time it to the current.
I hope that made sense.

Not really. This is basically a finite-statement machine, but I am not
sure what state-input transition matrix you intend.

Python3 code. Pastebin has a bug that is adds spaces (where line number
were) that were not pasted in when one copies the text out. So one must
dedent the entire file after pasting into an editor window (IDLE does
this pretty easily with two dedents).

The code looks pretty good and it initially ran, but when I clicked
Start (starts counting seconds), Pause (starts counting pause seconds),
Start (continued with cumulative time), and then Pause, counters goes
crazy, flashing various second readings several times a second. There
may be an tkinter bug, but if you can resume work time, you should be
able to resume pause time. Again, without a design spec, it is hard to
know what you intended.

Start, Pause, Reset (no obvious effect), Start has same effect.
 
M

Morten Klim

Well that's exactly the problem. My attempt to make this work, made
the counter go crazy and didn't care if it was paused or not. So for
this for work properly, remove following:
def _updatepause(self):
self._elapsedpause = time.time() - self._pausestart
self._setTime(self._elapsedpause)
self._timer = self.after(50, self._updatepause)

(def Stop)
self._pausestart = time.time() - self._elapsedpause
self._updatepause()


What I wanted was a counter, which ran in the background counting the
time between you have pushed the pause button and then the start
button again. Which will measure the time the guy had hold his break.
Another example:
I push the pause button, and left the counter at 01:42:11 which is the
time I've worked so far.
When I come back 30 min later, I press start. The counter in the GUI
then ticks on.
In the background though, while I were for lunch/break, a counter has
kept the time I was there.
pausetime = 30 min
 
M

Morten Klim

when working or when already paused?

 > the current time he has kept his break can't be reset,
 >  so it has to add the new time it to the current.


Not really. This is basically a finite-statement machine, but I am not
sure what state-input transition matrix you intend.


Python3 code. Pastebin has a bug that is adds spaces (where line number
were) that were not pasted in when one copies the text out. So one must
dedent the entire file after pasting into an editor window (IDLE does
this pretty easily with two dedents).

The code looks pretty good and it initially ran, but when I clicked
Start (starts counting seconds), Pause (starts counting pause seconds),
Start (continued with cumulative time), and then Pause, counters goes
crazy, flashing various second readings several times a second. There
may be an tkinter bug, but if you can resume work time, you should be
able to resume pause time. Again, without a design spec, it is hard to
know what you intended.

Start, Pause, Reset (no obvious effect), Start has same effect.


--
Terry Jan Reedy



when working or when already paused?

 > the current time he has kept his break can't be reset,
 >  so it has to add the new time it to the current.


Not really. This is basically a finite-statement machine, but I am not
sure what state-input transition matrix you intend.


Python3 code. Pastebin has a bug that is adds spaces (where line number
were) that were not pasted in when one copies the text out. So one must
dedent the entire file after pasting into an editor window (IDLE does
this pretty easily with two dedents).

The code looks pretty good and it initially ran, but when I clicked
Start (starts counting seconds), Pause (starts counting pause seconds),
Start (continued with cumulative time), and then Pause, counters goes
crazy, flashing various second readings several times a second. There
may be an tkinter bug, but if you can resume work time, you should be
able to resume pause time. Again, without a design spec, it is hard to
know what you intended.

Start, Pause, Reset (no obvious effect), Start has same effect.

Well that's exactly the problem. My attempt to make this work, made
the counter go crazy and didn't care if it was paused or not. So for
this for work properly, remove following:
def _updatepause(self):
self._elapsedpause = time.time() - self._pausestart
self._setTime(self._elapsedpause)
self._timer = self.after(50, self._updatepause)

(def Stop)
self._pausestart = time.time() - self._elapsedpause
self._updatepause()


What I wanted was a counter, which ran in the background counting the
time between you have pushed the pause button and then the start
button again. Which will measure the time the guy had hold his break.
Another example:
I push the pause button, and left the counter at 01:42:11 which is the
time I've worked so far.
When I come back 30 min later, I press start. The counter in the GUI
then ticks on.
In the background though, while I were for lunch/break, a counter has
kept the time I was there.
pausetime = 30 min
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top