New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added module stopwatch #1216

Open
wants to merge 17 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@onny

onny commented Jan 6, 2018

Hey,
I modified the timer module a bit, copied it and created a simple stopwatch module.
A left click starts or pauses the timer, right click resets it.

Regards,
Jonas

@lasers

This comment has been minimized.

Show comment
Hide comment
@lasers

lasers Jan 8, 2018

Collaborator

Hey @onny. Thanks for this module. If you looked at Travis (red X right there then one more red X in build jobs), you'll find few things you need to fix.

And I wonder if it's possible / better to implement this in timer instead? Perhaps with a button to toggle between timer and stopwatch? Anyhow, I'll be happy to review this next after Travis cleared you.

Collaborator

lasers commented Jan 8, 2018

Hey @onny. Thanks for this module. If you looked at Travis (red X right there then one more red X in build jobs), you'll find few things you need to fix.

And I wonder if it's possible / better to implement this in timer instead? Perhaps with a button to toggle between timer and stopwatch? Anyhow, I'll be happy to review this next after Travis cleared you.

onny added some commits Jan 8, 2018

Update stopwatch.py
Remove unused variables
@onny

This comment has been minimized.

Show comment
Hide comment
@onny

onny Jan 8, 2018

All tests should pass now. The latest is not working because of a connection timeout of Travis ...
The idea is good but personally I prefer a seperate module so I don't have to change the behaviour of the timer/stopwatch every time. If someone is willing to change that in the future, I'll be happy to check it out 👍

onny commented Jan 8, 2018

All tests should pass now. The latest is not working because of a connection timeout of Travis ...
The idea is good but personally I prefer a seperate module so I don't have to change the behaviour of the timer/stopwatch every time. If someone is willing to change that in the future, I'll be happy to check it out 👍

Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
# Minutes
mins, t = divmod(t, 60)
# Seconds
seconds = t

This comment has been minimized.

@lasers

lasers Jan 8, 2018

Collaborator

(Nit). I'd like minutes here... and just kill the comments.

@lasers

lasers Jan 8, 2018

Collaborator

(Nit). I'd like minutes here... and just kill the comments.

This comment has been minimized.

@onny
@onny

onny Jan 20, 2018

done

Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
else:
if self.time_state:
t = self.time_state
else:

This comment has been minimized.

@lasers

lasers Jan 8, 2018

Collaborator

I think we might be able to use elif here to make it a bit more cleaner.
EDIT: Or leave this alone and put cached_until stuffs in there instead.

@lasers

lasers Jan 8, 2018

Collaborator

I think we might be able to use elif here to make it a bit more cleaner.
EDIT: Or leave this alone and put cached_until stuffs in there instead.

This comment has been minimized.

@onny
@onny

onny Jan 20, 2018

done

Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
@onny

This comment has been minimized.

Show comment
Hide comment
@onny

onny Jan 20, 2018

Thanks for all the useful and educational code support. Is everything fine so far?

onny commented Jan 20, 2018

Thanks for all the useful and educational code support. Is everything fine so far?

@lasers

Almost there...

Configuration parameters:
format: display format for this module (default 'Stopwatch {stopwatch}')

This comment has been minimized.

@lasers

lasers Jan 20, 2018

Collaborator

Missing docs...

button_reset: mouse button to reset the stopwatch (default 3)
button_toggle: mouse button to start/stop the stopwatch (default 1)
@lasers

lasers Jan 20, 2018

Collaborator

Missing docs...

button_reset: mouse button to reset the stopwatch (default 3)
button_toggle: mouse button to start/stop the stopwatch (default 1)

This comment has been minimized.

@onny
@onny

onny Jan 21, 2018

Done

Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
if button == self.button_reset:
# reset and pause stopwatch
self._reset_time()

This comment has been minimized.

@lasers

lasers Jan 20, 2018

Collaborator
        elif button == self.button_reset:
            self._reset_time()
        else:
            self.py3.prevent_refresh()

Prevent users from updating this module with clicks/scrolling if they feel like doing it. EDIT: And users have no reasons to play with this anyway.

@lasers

lasers Jan 20, 2018

Collaborator
        elif button == self.button_reset:
            self._reset_time()
        else:
            self.py3.prevent_refresh()

Prevent users from updating this module with clicks/scrolling if they feel like doing it. EDIT: And users have no reasons to play with this anyway.

This comment has been minimized.

@onny

onny Jan 21, 2018

okay done

@onny

onny Jan 21, 2018

okay done

Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
Show outdated Hide outdated py3status/modules/stopwatch.py Outdated
@onny

This comment has been minimized.

Show comment
Hide comment
@onny

onny Jan 20, 2018

Hope it's all right now :)

onny commented Jan 20, 2018

Hope it's all right now :)

@lasers

This comment has been minimized.

Show comment
Hide comment
@lasers

lasers Jan 21, 2018

Collaborator

@onny I gave you another review in case you didn't notice. This module is cool and we still can make it more cool if we want to. 👍 EDIT: With only a little more work.

Collaborator

lasers commented Jan 21, 2018

@onny I gave you another review in case you didn't notice. This module is cool and we still can make it more cool if we want to. 👍 EDIT: With only a little more work.

@lasers

lasers approved these changes Jan 21, 2018

@tobes This is ready. However, I think it would be better if we default button_reset back to 2 and to set COLOR_DEGRADED instead of COLOR_BAD to stay in consistency with timer module...

I'm also thinking that it'd be good to reserve button_3 for maybe in the future, a button_lap = 3 to spawn new stopwatch (laps).

@onny Feel free to switch COLOR and button_reset if you agree and/or played with both stopwatch and timer. Nice job. Cheers. 👍

@onny

This comment has been minimized.

Show comment
Hide comment
@onny

onny Jan 21, 2018

I'm okay with that, we can change that 👍

onny commented Jan 21, 2018

I'm okay with that, we can change that 👍

@lasers

(Nit) If we want to colorize everything same, then this patch would be better. Otherwise, the colons should not have colors if we want it to be identical to timer.

diff --git a/py3status/modules/stopwatch.py b/py3status/modules/stopwatch.py
index 7c433a9a..e10374af 100644
--- a/py3status/modules/stopwatch.py
+++ b/py3status/modules/stopwatch.py
@@ -62,7 +62,6 @@ class Py3status:
         self.color = None
 
     def stopwatch(self):
-
         if self.running:
             cached_until = self.py3.time_in(0, offset=1)
             t = int(time() - self.time_start)
@@ -77,35 +76,14 @@ class Py3status:
         minutes, t = divmod(t, 60)
         seconds = t
 
-        composites = [
-            {
-                'full_text': str(hours),
-                'color': self.color,
-            },
-            {
-                'color': self.color,
-                'full_text': ':',
-            },
-            {
-                'full_text': '%02d' % (minutes),
-                'color': self.color,
-            },
-            {
-                'color': self.color,
-                'full_text': ':',
-            },
-            {
-                'full_text': '%02d' % (seconds),
-                'color': self.color,
-            },
-        ]
-
-        stopwatch = self.py3.composite_create(composites)
+        stopwatch = self.py3.safe_format('\?color=%s %d:%02d:%02d' % (
+            self.color, hours, minutes, seconds))
 
         return {
             'cached_until': cached_until,
             'full_text': self.py3.safe_format(
-                self.format, {'stopwatch': stopwatch})
+                self.format, {'stopwatch': stopwatch}
+            )
         }
 
     def on_click(self, event):
@onny

This comment has been minimized.

Show comment
Hide comment
@onny

onny Jan 23, 2018

Okay this looks better now 👍

onny commented Jan 23, 2018

Okay this looks better now 👍

@tobes tobes self-assigned this Jan 31, 2018

@onny

This comment has been minimized.

Show comment
Hide comment
@onny

onny Mar 23, 2018

Any updates on this?

onny commented Mar 23, 2018

Any updates on this?

@lasers

This comment has been minimized.

Show comment
Hide comment
@lasers

lasers Mar 28, 2018

Collaborator

@onny This module is up to standards. However, stopwatch contains roughly a half of timer code. If you can implement stopwatch functionality in timer instead, then that's where we can really shine here... and is likely to make more people happy by not worrying about switching between timer and stopwatch modules versus using built-in functionality.

Collaborator

lasers commented Mar 28, 2018

@onny This module is up to standards. However, stopwatch contains roughly a half of timer code. If you can implement stopwatch functionality in timer instead, then that's where we can really shine here... and is likely to make more people happy by not worrying about switching between timer and stopwatch modules versus using built-in functionality.

@tobes

This comment has been minimized.

Show comment
Hide comment
@tobes

tobes Aug 26, 2018

Collaborator

I'm with @lasers here really we should combine the two - unless we are just going for how many modules can we have - but I'm for less is more

Collaborator

tobes commented Aug 26, 2018

I'm with @lasers here really we should combine the two - unless we are just going for how many modules can we have - but I'm for less is more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment