Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

fix(board): two-digit minutes, no tenths on the clock

public

fix(board): two-digit minutes, no tenths on the clock

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changeset8990a946f8e24bdef4ce5e1d2d10d6fc2efd2185
Author (claimed)Timo Stolz <timo.stolz@nullachtvierzehn.de>,
Parentsb1251054cd58
Children2194dab24eb5
Pushlog
by timo via ssh
by timo via ssh

modified schach/board.py +5 −9

@@ -510,8 +510,7 @@ class BoardView(Gtk.DrawingArea):
510510
         pad = h * 0.22
511511
         # feste Mindestbreiten, damit die Uhr beim Ticken nicht springt
512512
         left_w = max(cr.text_extents("00").x_advance, cr.text_extents(minutes).x_advance) + 2 * pad
513
-        right_w = max(cr.text_extents("00.0" if low else "00").x_advance,
514
-                      cr.text_extents(seconds).x_advance) + 2 * pad
513
+        right_w = max(cr.text_extents("00").x_advance, cr.text_extents(seconds).x_advance) + 2 * pad
515514
         bh = h * 0.78
516515
         by = y + (h - bh) / 2
517516
         bx = right - left_w - right_w
@@ -558,20 +557,17 @@ class BoardView(Gtk.DrawingArea):
558557
         cr.show_text(text)
559558
 
560559
 
561
-LOW_TIME_MS = 20000  # darunter: rot und mit Zehntelsekunden
560
+LOW_TIME_MS = 20000  # darunter wird die laufende Uhr rot
562561
 CLOCK_RUNNING = (0.18, 0.55, 0.34)
563562
 CLOCK_LOW = (0.80, 0.20, 0.18)
564563
 
565564
 
566565
 def clock_parts(ms):
567
-    """Minuten- und Sekundenfeld: ("4", "37"), ab einer Stunde ("1:02", "37"), knapp ("0", "19.4")."""
568
-    ms = max(0, int(ms))
569
-    secs = ms // 1000
566
+    """Minuten- und Sekundenfeld, beide zweistellig: ("04", "37"); ab einer Stunde ("1:02", "37")."""
567
+    secs = max(0, int(ms)) // 1000
570568
     if secs >= 3600:
571569
         return f"{secs // 3600}:{secs // 60 % 60:02d}", f"{secs % 60:02d}"
572
-    if ms < LOW_TIME_MS:
573
-        return f"{secs // 60}", f"{secs % 60:02d}.{ms % 1000 // 100}"
574
-    return f"{secs // 60}", f"{secs % 60:02d}"
570
+    return f"{secs // 60:02d}", f"{secs % 60:02d}"
575571
 
576572
 
577573
 def _rounded(cr, x, y, w, h, r):

modified tests/test_notation.py +5 −4

@@ -37,11 +37,12 @@ class ClockPartsTest(unittest.TestCase):
3737
     def test_parts(self):
3838
         from schach.board import clock_parts
3939
 
40
-        self.assertEqual(clock_parts(300000), ("5", "00"))
41
-        self.assertEqual(clock_parts(61000), ("1", "01"))
42
-        self.assertEqual(clock_parts(19450), ("0", "19.4"))
40
+        self.assertEqual(clock_parts(300000), ("05", "00"))
41
+        self.assertEqual(clock_parts(61000), ("01", "01"))
42
+        self.assertEqual(clock_parts(19450), ("00", "19"))
43
+        self.assertEqual(clock_parts(1800000), ("30", "00"))
4344
         self.assertEqual(clock_parts(3723000), ("1:02", "03"))
44
-        self.assertEqual(clock_parts(-5), ("0", "00.0"))
45
+        self.assertEqual(clock_parts(-5), ("00", "00"))
4546
 
4647
 
4748
 if __name__ == "__main__":