Stopwatch - pause counter

Morten Klim klim8d at gmail.com
Tue Jul 19 16:03:47 EDT 2011


On Jul 19, 8:55 pm, Terry Reedy <tjre... at udel.edu> wrote:
> On 7/19/2011 6:41 AM, Morten Klim wrote:
>
>
>
>
>
>
>
>
>
> > 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.
>
> > Here is my code:http://pastebin.com/T8FkMusS
>
> 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.
>
> > The variables at __init__
> > self._pausestart = 0.0
> > self._elapsedpause = 0.0
> > and the method _updatepause are a attempt to make this work.
>
> --
> Terry Jan Reedy

On Jul 19, 8:55 pm, Terry Reedy <tjre... at udel.edu> wrote:
> On 7/19/2011 6:41 AM, Morten Klim wrote:
>
>
>
>
>
>
>
>
>
> > 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.
>
> > Here is my code:http://pastebin.com/T8FkMusS
>
> 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.
>
> > The variables at __init__
> > self._pausestart = 0.0
> > self._elapsedpause = 0.0
> > and the method _updatepause are a attempt to make this work.
>
> --
> Terry Jan Reedy

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



More information about the Python-list mailing list