snakeware

Python-based Linux distro for x86-64 and RPi
git clone git://squid-tech.com/snakeware.git
Log | Files | Refs | README

commit b5b1f66ce43a755bd8221a2e43dd3fa34d29606e
parent 0d9356e0b2369c1d966b8b85272f86829a90146f
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Wed, 17 Jun 2020 17:09:24 -0400

Merge pull request #125 from callmepavo/stopwatch

Added stopwatch app
Diffstat:
Asnakewm/apps/clocks/stopwatch/README.md | 24++++++++++++++++++++++++
Asnakewm/apps/clocks/stopwatch/__init__.py | 14++++++++++++++
Asnakewm/apps/clocks/stopwatch/stopwatch.py | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/snakewm/apps/clocks/stopwatch/README.md b/snakewm/apps/clocks/stopwatch/README.md @@ -0,0 +1,23 @@ +# Stopwatch +A basic stopwatch that counts up in seconds. `start/pause` button stops and starts counting, `reset` button returns count to 0. + +# Authors +Stopwatch by pavo. + ++ github: https://github.com/callmepavo/ + ++ date: 16 Jun 2020 + +Based on SnakeClock by Abdur-Rahmaan Janhangeer. + ++ github: https://github.com/Abdur-rahmaanJ + ++ mail: arj.python@gmail.com + ++ date: 30 May 2020 + +Slight edits to SnakeClock made by pavo. + ++ github: https://github.com/callmepavo + ++ date: 10 May 2020+ \ No newline at end of file diff --git a/snakewm/apps/clocks/stopwatch/__init__.py b/snakewm/apps/clocks/stopwatch/__init__.py @@ -0,0 +1,14 @@ +from .stopwatch import Stopwatch + + +def load(manager, params): + """ + Create and launch a new instance of Stopwatch. + """ + # default position + pos = (100, 100) + + if params is not None and len(params) > 0: + pos = params[0] + + Stopwatch(pos, manager) diff --git a/snakewm/apps/clocks/stopwatch/stopwatch.py b/snakewm/apps/clocks/stopwatch/stopwatch.py @@ -0,0 +1,72 @@ +import pygame +import pygame_gui + +import time + + +class Stopwatch(pygame_gui.elements.UIWindow): + def __init__(self, pos, manager): + super().__init__( + pygame.Rect(pos, (362, 75)), + manager=manager, + window_display_title="stopwatch", + object_id="#stopwatch", + resizable=False, + ) + + self.textbox = pygame_gui.elements.UITextBox( + "0 : 0 : 0", + relative_rect=pygame.Rect(0, 3, 130, 35), + manager=manager, + container=self, + ) + + button_layout_rect = pygame.Rect(130, 3, 100, 35) + self.start_button = pygame_gui.elements.UIButton( + relative_rect=button_layout_rect, + text="start/pause", + container=self, + manager=manager, + object_id="#start_button", + ) + + button2_layout_rect = pygame.Rect(230, 3, 100, 35) + self.reset_button = pygame_gui.elements.UIButton( + relative_rect=button2_layout_rect, + text="reset", + container=self, + manager=manager, + object_id="#reset_button", + ) + + self.time_counter = 0 + self.currently_counting = False + + def process_event(self, event): + super().process_event(event) + if event.type == pygame.USEREVENT: + if event.user_type == pygame_gui.UI_BUTTON_PRESSED: + if event.ui_element == self.start_button: + self.currently_counting = not self.currently_counting + elif event.ui_element == self.reset_button: + self.reset_time() + + def update(self, time_delta): + super().update(time_delta) + if self.currently_counting: + self.time_counter += time_delta + secs = int(self.time_counter % 60) + mins = int( (self.time_counter % (60**2)) // 60 ) + hours = int(self.time_counter // (60**2)) + + counter_str = f"{str(hours)} : {str(mins)} : {str(secs)}" + self.set_text(counter_str) + + def set_text(self, text): + self.textbox.html_text = text + self.textbox.rebuild() + + def reset_time(self): + self.time_counter = 0 + self.currently_counting = False + self.update(0)+ \ No newline at end of file