snakeware

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

commit acc1de15ab6e83f8cc03ff52360dccdb8eecbcca
parent 2580c00db167a945e138a745ee2425dd9c450c7a
Author: Josh Moore <jxm5210@rit.edu>
Date:   Thu, 28 May 2020 17:10:28 -0400

Add background color picker

Diffstat:
Asnakewm/apps/tools/Background Color/__init__.py | 20++++++++++++++++++++
Msnakewm/wm.py | 18+++++++++++++++---
2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/snakewm/apps/tools/Background Color/__init__.py b/snakewm/apps/tools/Background Color/__init__.py @@ -0,0 +1,20 @@ +import pygame +import pygame_gui + +def load(manager, params): + """ + Launch a Colour Picker dialog to change the desktop background color. + """ + + # default position + pos = (100, 100) + + if params is not None and len(params) > 0: + pos = params[0] + + pygame_gui.windows.UIColourPickerDialog( + rect=pygame.Rect(pos, (420, 400)), + manager=manager, + window_title='Set Background Color', + object_id='#desktop_colour_picker' + ) diff --git a/snakewm/wm.py b/snakewm/wm.py @@ -10,14 +10,14 @@ import pygame, pygame_gui from appmenu.appmenupanel import AppMenuPanel -BG_COLOR = (0, 128, 128) - class SnakeWM: SCREEN = None DIMS = None BG = None MANAGER = None + BG_COLOR = (0, 128, 128) + # currently focused window FOCUS = None @@ -51,7 +51,7 @@ class SnakeWM: # init background self.BG = pygame.Surface((self.DIMS)) - self.BG.fill(BG_COLOR) + self.BG.fill(self.BG_COLOR) # init UI manager self.MANAGER = pygame_gui.UIManager(self.DIMS) @@ -101,6 +101,13 @@ class SnakeWM: self.loadapp(app) + def set_bg_color(self, color): + """ + Set the desktop background to 'color', where color is an RGB tuple. + """ + self.BG_COLOR = color + self.BG.fill(self.BG_COLOR) + def run(self): clock = pygame.time.Clock() running = True @@ -134,10 +141,15 @@ class SnakeWM: elif event.type == pygame.USEREVENT: if event.user_type == 'window_selected': + # focus selected window if self.FOCUS is not None: self.FOCUS.unfocus() self.FOCUS = event.ui_element self.FOCUS.focus() + elif event.user_type == pygame_gui.UI_COLOUR_PICKER_COLOUR_PICKED: + if event.ui_object_id == '#desktop_colour_picker': + # set desktop background color - no alpha channel + self.set_bg_color(event.colour[:-1]) self.MANAGER.process_events(event)