You are not logged in.

#26 2018-11-24 22:22:25

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: pyStopwatch: a gui stopwatch that can minimize to the tray

@likytau
Thanks for reporting these issues. Everything should be fixed now.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#27 2018-11-25 15:50:00

Steef435
Member
Registered: 2013-08-29
Posts: 577
Website

Re: pyStopwatch: a gui stopwatch that can minimize to the tray

(small note: state indeed represents modifier state but is a collection of flags, so if you only check for state != 0 then you would also respond to ctrl-m, ctrl-alt-m, super-m, etc.

So you'd have to check whether state equals gtk.gdk.MOD1_MASK for alt-m, and check whether state equals (gtk.gdk.MOD1_MASK | gtk.gdk.SHIFT_MASK) for alt-M

and yeah, as is already mentioned: an event is sent through all its handlers until one of them returns true, so return true in order to prevent the default handler from executing and thus executing the default tab behaviour)

Last edited by Steef435 (2018-11-25 15:50:28)

Offline

#28 2018-11-25 20:02:58

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: pyStopwatch: a gui stopwatch that can minimize to the tray

Steef435 wrote:

(small note: state indeed represents modifier state but is a collection of flags, so if you only check for state != 0 then you would also respond to ctrl-m, ctrl-alt-m, super-m, etc.

So you'd have to check whether state equals gtk.gdk.MOD1_MASK for alt-m, and check whether state equals (gtk.gdk.MOD1_MASK | gtk.gdk.SHIFT_MASK) for alt-M

Thanks for the clarification. I didn't post the details yesterday but the update does indeed check for gtk.gdk.MOD1_MASK specifically and returns false if that bit is set (none of the custom key handlers deal with <alt>). This was also necessary to keep <shift>+h/m/s working for decrements.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#29 2019-10-19 23:34:46

likytau
Member
Registered: 2012-09-02
Posts: 142

Re: pyStopwatch: a gui stopwatch that can minimize to the tray

Just exploring this program a little more, I tried 'countdown timer B' and almost reported it as bugged (before I read the info page). So I have a small suggestion: set its default value to something different, like 13:00:00, to make it more obvious that it's a 24h clock time, rather than a simple duration.

(yeah, I thought it was just for having two 'A' style timers with different durations counting down.)

Offline

#30 2019-10-22 00:54:02

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: pyStopwatch: a gui stopwatch that can minimize to the tray

The countdown target will now be set to the next 5-minute mark (rounded up) when pystopwatch is started and when the reset button is pressed.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#31 2019-11-17 03:43:13

likytau
Member
Registered: 2012-09-02
Posts: 142

Re: pyStopwatch: a gui stopwatch that can minimize to the tray

Sounds good.

Here's a small patch I made because I found I was always cycling the mode to Countdown A after starting Pystopwatch.
It adds commandline parsing via argparse.
Help text gives a good summary:

  -m {clock,stopwatch,countdown_for,countdown_to}, --mode {clock,stopwatch,countdown_for,countdown_to}
                        Start in MODE. countdown_for = Countdown A (countdown
                        for a given duration). countdown_to = Countdown B
                        (countdown to a given clock time)
  -k, --clock
  -s, --stopwatch
  -c, --countdown-for
  -t, --countdown-to

The actual patch (apply with `patch -p1`)

diff -u a/pystopwatch b/pystopwatch
--- a/pystopwatch	2019-11-17 13:57:36.712317837 +1030
+++ b/pystopwatch	2019-11-17 13:59:48.904935021 +1030
@@ -898,6 +898,38 @@
   def main(self):
     gtk.main()
 
+def parse_args(args):
+  import argparse
+  kwargs = {}
+  # This could be moved into Stopwatch static class data. It probably can't just
+  # be merged with MODE_LABEL, because these need to be easy to remember and type on the
+  # commandline
+  MODE_IDS = ['clock', 'stopwatch', 'countdown_for', 'countdown_to']
+  parser = argparse.ArgumentParser(description='PyGTK stopwatch/timer')
+  parser.add_argument('-m', '--mode',
+                      help='Start in MODE.'
+                           ' countdown_for = Countdown A (countdown for a given duration).'
+                           ' countdown_to = Countdown B (countdown to a given clock time)',
+                     choices=MODE_IDS,
+                      default='clock')
+  parser.add_argument('-k', '--clock', 
+                      dest='mode', const='clock',
+                      action='store_const')
+  parser.add_argument('-s', '--stopwatch', 
+                      dest='mode', const='stopwatch',
+                      action='store_const')
+  parser.add_argument('-c', '--countdown-for', 
+                      dest='mode', const='countdown_for',
+                      action='store_const')
+  parser.add_argument('-t', '--countdown-to', 
+                      dest='mode', const='countdown_to',
+                      action='store_const')
+  opts = parser.parse_args(args)
+  kwargs['mode'] = MODE_IDS.index(opts.mode)
+  return kwargs
+
 if __name__ == "__main__":
-  stopwatch = Stopwatch()
+  import sys
+  kwargs = parse_args(sys.argv[1:])
+  stopwatch = Stopwatch(**kwargs)
   stopwatch.main()

It could of course be a config option, but I thought that this was the kind of option that you actually might want to change per-instance.

Some options that could be useful but I haven't implemented here:

* --start (immediately start the stopwatch/countdown. N/A for 'Current Time' mode, I think.)
* positional argument for setting the initial value of the timer (as in 'pystopwatch -t --start 12:00' -- set mode to Countdown B, set target time to 12:00, and immediately start the timer)

Other issues:

* haven't tried very hard to unify the symbolic identifiers here with the labels used in the GUI.
* help text isn't particularly tidy (I don't remember what the proper way to force a line break is here)

Last edited by likytau (2019-11-17 03:50:22)

Offline

#32 2019-11-18 22:53:33

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: pyStopwatch: a gui stopwatch that can minimize to the tray

I like the idea of adding command-line options to launch an instance for a given purpose. I've added the patch to my todo list and will try to take a look at it soonish.

As for formatting argparse output, don't go down that rabbit hole. There are options to configure it but you end up having to format the text directly and it becomes a hassle to maintain. It's not as bad as arguing with LaTeX about formatting but it's just not worth it. tongue

Speaking of ugly, every time I come back to look at the code now I have a growing urge to refactor it to fix all of my noob mistakes. I'm not sure if or when I will, but the impulse is getting hard to ignore.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB