snakeware

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

commit f50c6854e3ba7a2852252ed67f87f76c4dfdf218
parent 7064efa04cf6dd9fe6c6958f92a283a6e4713ac9
Author: Josh Moore <jxm5210@rit.edu>
Date:   Thu, 28 May 2020 12:22:10 -0400

Add very basic appmenupanel component - WIP

Diffstat:
A.gitignore | 1+
Asnakewm/appmenu/__init__.py | 0
Asnakewm/appmenu/appmenupanel.py | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msnakewm/wm.py | 17+++++++++++++++++
4 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/snakewm/appmenu/__init__.py b/snakewm/appmenu/__init__.py diff --git a/snakewm/appmenu/appmenupanel.py b/snakewm/appmenu/appmenupanel.py @@ -0,0 +1,65 @@ +""" +App menu panel containing a list of all apps or subdirectories in the +current directory. +""" + +import pygame + +from pygame_gui.elements import UIPanel +from pygame_gui.elements import UIButton + +# panel draw layer +PANEL_LAYER = 10 + +# button dimensions +BUTTON_DIMS = (200, 25) + +class AppMenuPanel(UIPanel): + manager = None + pos = None + path = None + + # the elements field contains a list of tuples, where each tuple + # represents a single element the current directory: + # (text, next) + # where text is the text to display, and next is the directory this + # element represents, or None if the element represents an app. + elements = None + + def __init__(self, manager, pos, path, elements): + """ + manager - UIManager to manage this panel + pos - position indices to start drawing this panel at + path - the directory this panel represents + elements - list of elements in this directory + \TODO replace elements with a dict structure representing the + current directory + """ + super().__init__( + pygame.Rect( + ( + pos[0] * BUTTON_DIMS[0], + pos[1] * BUTTON_DIMS[1] + ), + ( + BUTTON_DIMS[0] + 5, + BUTTON_DIMS[1] * len(elements) + 5 + ) + ), + starting_layer_height=PANEL_LAYER, + manager=manager + ) + self.path = path + self.elements = elements + + # generate buttons + for i in range(len(elements)): + UIButton( + pygame.Rect( + (0, i * BUTTON_DIMS[1]), + BUTTON_DIMS + ), + text=elements[i][0], + manager=manager, + container=self + ) diff --git a/snakewm/wm.py b/snakewm/wm.py @@ -8,6 +8,8 @@ import importlib import pygame, pygame_gui +from appmenu.appmenupanel import AppMenuPanel + BG_COLOR = (0, 128, 128) class SnakeWM: @@ -42,6 +44,21 @@ class SnakeWM: # init UI manager self.MANAGER = pygame_gui.UIManager(self.DIMS) + ## REMOVE ME + AppMenuPanel( + self.MANAGER, + (0, 0), + 'apps', + [('test', None), ('games', None), ('aaa', None)] + ) + AppMenuPanel( + self.MANAGER, + (1, 2), + 'apps.games', + [('HelloWorld', None), ('asdf', None)] + ) + ## + pygame.mouse.set_visible(True) pygame.display.update()