diff --git a/config.py b/config.py index 1f78785..64069c0 100644 --- a/config.py +++ b/config.py @@ -50,5 +50,10 @@ def parse_args(): type=int, default=24, help="Desired font size for the wall clock and the stop watch") + parser.add_argument( + "--color", + type=str, + default="0xff0000", + help="Desired color (e.g., 0x00ff00 for green), or 'rgb'") args = parser.parse_args() return args diff --git a/constants.py b/constants.py index 2e9af45..f6e59cf 100644 --- a/constants.py +++ b/constants.py @@ -19,7 +19,7 @@ # colors BLACK = (0, 0, 0) -GRAY = (20, 10, 10) +GRAY = (20, 20, 20) RED = (255, 0, 0) # default colors diff --git a/ticker.py b/ticker.py index 9c24bfd..cba71c4 100644 --- a/ticker.py +++ b/ticker.py @@ -29,6 +29,19 @@ def get_width_and_height(arg_width, arg_height): return (width, height) +def generate_color(option): + if option == "rgb": + rgb = pygame.Color(*RED) + while True: + hue = rgb.hsva[0] + hue = (hue + 2) % 360 + rgb.hsva = (hue, *rgb.hsva[1:]) + yield rgb + else: + fixed_color = pygame.Color(option) + while True: + yield fixed_color + def main(): args = config.parse_args() @@ -62,13 +75,16 @@ def main(): else: stopwatch = None + # multiprocessing q = Queue(maxsize=2) p = Process( target=spiceclient.spice_client, args=(q, args.host, args.port, args.password)) p.start() + # ticker stuff last_ticker_text = CONNECTING_TEXT + color_generator = generate_color(args.color) while True: # Check for pygame events for event in pygame.event.get(): @@ -103,11 +119,12 @@ def main(): # Render surface.fill(COLOR_BACKGROUND) - ticker.render(ticker_text) + color = next(color_generator) + ticker.render(ticker_text, color) if wallclock: - wallclock.render() + wallclock.render(color) if stopwatch: - stopwatch.render() + stopwatch.render(color) pygame.display.flip() clock.tick(8) pass diff --git a/widgets.py b/widgets.py index bed0b08..7c003c0 100644 --- a/widgets.py +++ b/widgets.py @@ -16,9 +16,9 @@ def on_resize(self, new_surface): self.surface = new_surface self.__update_font() - def render(self, ticker_text): + def render(self, ticker_text, color): self.__render_text(ALL_ON_CHAR * self.LENGTH, COLOR_TEXT_OFF) - self.__render_text(ticker_text, COLOR_TEXT_ON) + self.__render_text(ticker_text, color) def __render_text(self, text, color): text = self.font.render(text, True, color) @@ -64,7 +64,7 @@ def on_resize(self, new_surface): self.surface = new_surface self.__update_font() - def render(self): + def render(self, color): self.__render_text(self.DEFAULT_TEXT, COLOR_TEXT_OFF) now = datetime.now() if (now.microsecond < (500000)) == 0: @@ -72,7 +72,7 @@ def render(self): else: separator = " " ticker_text = now.strftime("%I" + separator + "%M") - self.__render_text(ticker_text, COLOR_TEXT_ON) + self.__render_text(ticker_text, color) def __render_text(self, text, color): text = self.font.render(text, True, color) @@ -101,7 +101,7 @@ def on_resize(self, new_surface): self.surface = new_surface self.__update_font() - def render(self): + def render(self, color): self.__render_text(self.DEFAULT_TEXT, COLOR_TEXT_OFF) time_diff = datetime.now() - self.start_time # time_diff += timedelta(hours=9, minutes=59, seconds=50) @@ -109,7 +109,7 @@ def render(self): minutes = (time_diff.seconds // 60) % 60 hours = (time_diff.seconds // 60 // 60) % 10 ticker_text = f"{hours:01}:{minutes:02}:{seconds:02}" - self.__render_text(ticker_text, COLOR_TEXT_ON) + self.__render_text(ticker_text, color) def __render_text(self, text, color): text = self.font.render(text, True, color)