snakeware

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

commit ee97803b4346fbfc31bd32243defea86c36efefd
parent ee5992120a683d74b09e694265abc27425fee8a4
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Sun, 31 May 2020 14:06:22 -0400

Merge pull request #28 from Sam-Hildebrand/master

Background Images and Background Picker
Diffstat:
Asnakewm/apps/tools/Background Image/Big Flower.jpg | 0
Asnakewm/apps/tools/Background Image/Fallen Log.jpg | 0
Asnakewm/apps/tools/Background Image/Flower Field.jpg | 0
Asnakewm/apps/tools/Background Image/The Moon.jpg | 0
Asnakewm/apps/tools/Background Image/__init__.py | 22++++++++++++++++++++++
Msnakewm/wm.py | 14+++++++++++++-
6 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/snakewm/apps/tools/Background Image/Big Flower.jpg b/snakewm/apps/tools/Background Image/Big Flower.jpg Binary files differ. diff --git a/snakewm/apps/tools/Background Image/Fallen Log.jpg b/snakewm/apps/tools/Background Image/Fallen Log.jpg Binary files differ. diff --git a/snakewm/apps/tools/Background Image/Flower Field.jpg b/snakewm/apps/tools/Background Image/Flower Field.jpg Binary files differ. diff --git a/snakewm/apps/tools/Background Image/The Moon.jpg b/snakewm/apps/tools/Background Image/The Moon.jpg Binary files differ. diff --git a/snakewm/apps/tools/Background Image/__init__.py b/snakewm/apps/tools/Background Image/__init__.py @@ -0,0 +1,22 @@ +import pygame +import pygame_gui +import os + +def load(manager, params): + """ + Launch a file dialog to change the desktop background. + """ + + # default position + pos = (30, 30) + + if params is not None and len(params) > 0: + pos = params[0] + + pygame_gui.windows.UIFileDialog( + rect=pygame.Rect(pos, (600, 400)), + manager=manager, + window_title='Set Background Image', + initial_file_path=os.path.dirname(os.path.realpath(__file__)), + object_id='#background_picker' + ) diff --git a/snakewm/wm.py b/snakewm/wm.py @@ -85,7 +85,7 @@ class SnakeWM: parameter and a params list parameter. The load() function should create an instance of the app to load and - add the app UI to the passed UIManager object. See existing apps for + add the app UI to the passed UIManager object. See existing apps for examples. """ if not TESTMODE: @@ -110,9 +110,18 @@ class SnakeWM: """ Set the desktop background to 'color', where color is an RGB tuple. """ + self.BG = pygame.Surface((self.DIMS)) self.BG_COLOR = color self.BG.fill(self.BG_COLOR) + def set_bg_image(self, file): + """ + Sets the desktop background to an image. + """ + filename, file_extension = os.path.splitext(file) + if file_extension == ".jpg" or file_extension == ".png": + self.BG = pygame.transform.scale(pygame.image.load(file), self.DIMS) + def run(self): clock = pygame.time.Clock() running = True @@ -155,6 +164,9 @@ class SnakeWM: if event.ui_object_id == '#desktop_colour_picker': # set desktop background color - no alpha channel self.set_bg_color(event.colour[:-1]) + elif event.user_type == pygame_gui.UI_FILE_DIALOG_PATH_PICKED: + if event.ui_object_id == '#background_picker': + self.set_bg_image(event.text) self.MANAGER.process_events(event)