snakeware

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

commit cb7cdf122bf9b2a5e92a57282547224bda3b7ddb
parent 7975d82ae862e7a7d6767f15558f39de7795a5a4
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Sat, 13 Jun 2020 17:37:15 -0400

Merge pull request #118 from mdoege/tix

Add TIX
Diffstat:
Asnakewm/apps/fun/tix/README.md | 15+++++++++++++++
Asnakewm/apps/fun/tix/__init__.py | 14++++++++++++++
Asnakewm/apps/fun/tix/tix.py | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/snakewm/apps/fun/tix/README.md b/snakewm/apps/fun/tix/README.md @@ -0,0 +1,15 @@ +# TIX + +TIX is a TIX clock, based on my old PyTIX code. TIX is a novelty clock that was available from sites such as thinkgeek.com about a decade ago. + +How to read: Each colored group of squares represents one digit of the current time. So if there are (from left to right) one red, two green, three blue and four red squares, that means it's 12:34 right now. + +The display updates every four seconds by default and the window is resizable. The script also has command line options for 24 hour mode and custom update intervals. + +# Author + +Martin C. Doege + ++ github: https://github.com/mdoege + ++ date: 12 Jun 2020 diff --git a/snakewm/apps/fun/tix/__init__.py b/snakewm/apps/fun/tix/__init__.py @@ -0,0 +1,14 @@ +from .tix import TIX + + +def load(manager, params): + """ + Create and launch a new instance of TIX. + """ + # default position + pos = (100, 100) + + if params is not None and len(params) > 0: + pos = params[0] + + TIX(pos, manager) diff --git a/snakewm/apps/fun/tix/tix.py b/snakewm/apps/fun/tix/tix.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python + +# Displays the TIX clock +# 2011-01-08 / 2020-06-12 + +# Usage: tix.py [update interval] [--24] + +import pygame +import pygame_gui +from pygame_gui.elements.ui_image import UIImage + +import sys, time, random + +try: + inter = int(sys.argv[1]) +except: + inter = 4 # default update interval (secs) + +RED = 204, 0, 0 +GREEN = 78, 154, 6 +BLUE = 52, 101, 164 +BACKGROUND = 33, 41, 46 +GRAY = 76, 80, 82 +COL = (BACKGROUND, BACKGROUND, GRAY, RED, GREEN, BLUE) + +if "--24" in sys.argv: + f = "%H%M" +else: + f = "%I%M" + + +def tog(start, end, n, col=2): + "Toggle on n values randomly in the array between start and end" + global disp + + for z in random.sample(range(3 * (end - start)), n): + disp[z % 3][start + z // 3] = col + + +def mainprog(win, res): + global disp + + boxx, boxy = res[0] // 12, res[0] // 12 + + t = time.strftime(f, time.localtime()) + h1, h2, m1, m2 = [int(x) for x in t] + disp = [[2, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2] for y in range(3)] + tog(0, 1, h1, 3) + tog(2, 5, h2, 4) + tog(6, 8, m1, 5) + tog(9, 12, m2, 3) + for x in range(12): + for y in range(3): + pygame.draw.rect( + win, COL[disp[y][x]], [x * boxx + 1, y * boxy + 1, boxx - 2, boxy - 2] + ) + + +class TIX(pygame_gui.elements.UIWindow): + res = 420, 105 + + def __init__(self, pos, manager): + super().__init__( + pygame.Rect(pos, (self.res[0] + 32, self.res[1] + 60)), + manager=manager, + window_display_title="tix", + object_id="#tix", + resizable=True, + ) + + self.dsurf = UIImage( + pygame.Rect((0, 0), self.res), + pygame.Surface(self.res).convert(), + manager=manager, + container=self, + parent_element=self, + ) + self.screen = pygame.Surface(self.res) + self.screen.fill(BACKGROUND) + self.manager = manager + self.last = 0 + + def process_event(self, event): + super().process_event(event) + r = super().get_abs_rect() + if event.type == pygame.MOUSEBUTTONUP and ( + r.w != self.res[0] + 32 or r.h != self.res[1] + 60 + ): + self.res = r.w - 32, r.h - 60 + super().kill() + self.__init__((r.left, r.top), self.manager) + + def update(self, delta): + super().update(delta) + if time.time() - self.last < inter: + return + self.last = time.time() + self.screen.fill(BACKGROUND) + mainprog(self.screen, self.res) + self.dsurf.image.blit(self.screen, (0, 0))