snakeware

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

commit c5d4fb73402ae132d5b8a476e1db47342bb64f89
parent 732f4a5fafedf7756e59da93390eae72b4e156d1
Author: Josh Moore <jxm5210@rit.edu>
Date:   Thu, 28 May 2020 14:58:10 -0400

Open apps when they are clicked in the menu

Diffstat:
Msnakewm/appmenu/appmenupanel.py | 9+++++----
Msnakewm/wm.py | 15++++++++++++++-
2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/snakewm/appmenu/appmenupanel.py b/snakewm/appmenu/appmenupanel.py @@ -28,7 +28,7 @@ class AppMenuPanel(UIPanel): # child panel created when a directory button is hovered child = None - def __init__(self, manager, pos, path, elements): + def __init__(self, manager, pos, path, elements, loadfunc): """ manager - UIManager to manage this panel pos - position indices to start drawing this panel at @@ -52,6 +52,7 @@ class AppMenuPanel(UIPanel): self.pos = pos self.path = path self.elements = elements + self.loadfunc = loadfunc # generate buttons ekeys = list(elements.keys()) @@ -77,8 +78,7 @@ class AppMenuPanel(UIPanel): uitext = event.ui_element.text if self.elements[uitext] == None: - #\TODO open app - print("opening app: " + self.path + '.' + uitext) + self.loadfunc(self.path + '.' + uitext) if event.user_type == pygame_gui.UI_BUTTON_ON_HOVERED and\ event.ui_object_id == ('panel.menu-' + self.path.replace('.', '-')): @@ -97,7 +97,8 @@ class AppMenuPanel(UIPanel): list(self.elements.keys()).index(uitext) ), self.path + '.' + uitext, - self.elements[uitext] + self.elements[uitext], + self.loadfunc ) def destroy(self): diff --git a/snakewm/wm.py b/snakewm/wm.py @@ -86,6 +86,18 @@ class SnakeWM: _app = importlib.import_module(app) _app.load(self.MANAGER, params) + def appmenu_load(self, app): + """ + This function is passed to AppMenuPanel objects to be called when + an app is selected to be opened. + The root app menu is destroyed, and the app is loaded. + """ + if self.APPMENU is not None: + self.APPMENU.destroy() + self.APPMENU = None + + self.loadapp(app) + def run(self): clock = pygame.time.Clock() running = True @@ -104,7 +116,8 @@ class SnakeWM: self.MANAGER, (0, 0), 'apps', - self.APPS + self.APPS, + self.appmenu_load ) else: # close app menu