snakeware

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

commit 9c49c9e3315e9835cf94103cd1d3d3cf675e4090
parent 5e0c7fe42b8cb2dafa6261566bede67a3a2cf630
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Mon, 15 Jun 2020 17:38:12 -0400

Merge pull request #123 from mdoege/help

Add help browser
Diffstat:
Asnakewm/apps/system/help/README.md | 20++++++++++++++++++++
Asnakewm/apps/system/help/__init__.py | 14++++++++++++++
Asnakewm/apps/system/help/help.py | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+), 0 deletions(-)

diff --git a/snakewm/apps/system/help/README.md b/snakewm/apps/system/help/README.md @@ -0,0 +1,20 @@ +# Help + +A simple help browser + +# Authors + +Martin C. Doege + ++ github: https://github.com/mdoege + ++ date: 14 Jun 2020 + +Based on Clock by Abdur-Rahmaan Janhangeer + ++ github: https://github.com/Abdur-rahmaanJ + ++ mail: arj.python@gmail.com + ++ date: 30 May 2020 + diff --git a/snakewm/apps/system/help/__init__.py b/snakewm/apps/system/help/__init__.py @@ -0,0 +1,14 @@ +from .help import Help + + +def load(manager, params): + """ + Create and launch a new instance of Help. + """ + # default position + pos = (100, 100) + + if params is not None and len(params) > 0: + pos = params[0] + + Help(pos, manager) diff --git a/snakewm/apps/system/help/help.py b/snakewm/apps/system/help/help.py @@ -0,0 +1,89 @@ +# Help browser for Snakeware + +import pygame +import pygame_gui +from pygame_gui.elements.ui_drop_down_menu import UIDropDownMenu + +import os, time + + +path = os.path.dirname(os.path.abspath(__file__)) + + +def appname(x): + l = x.split("/") + return l[-2] + + +def gethelp(): + d = path + "/../.." + h = [] + for root, dirs, files in os.walk(d, topdown=False): + for name in files: + if "README" in name: + h.append((appname(os.path.join(root, name)), os.path.join(root, name))) + h.sort(key=lambda r: r[0]) + return h + + +class Help(pygame_gui.elements.UIWindow): + def __init__(self, pos, manager): + super().__init__( + pygame.Rect(pos, (630, 490)), + manager=manager, + window_display_title="help", + object_id="#help", + resizable=False, + ) + + self.files = gethelp() + self.last = self.files[0][0] + + self.menu = UIDropDownMenu( + options_list=[p for p, q in self.files], + starting_option=self.last, + relative_rect=pygame.Rect(100, 0, 400, 30), + manager=manager, + container=self, + ) + + self.menu.current_state.should_transition = True + + self.textbox = pygame_gui.elements.UITextBox( + "", + relative_rect=pygame.Rect(0, 31, 600, 400), + manager=manager, + container=self, + anchors={ + "left": "left", + "right": "right", + "top": "top", + "bottom": "bottom", + }, + ) + self.last = 0 + + def process_event(self, event): + super().process_event(event) + + def update(self, time_delta): + super().update(time_delta) + + n = self.menu.selected_option + if n == self.last: + return + self.last = n + s = "" + for i in range(len(self.files)): + if self.files[i][0] == n: + for l in open(self.files[i][1]): + x = l.strip() + if len(x) > 1 and x[0] == "#": + x = "<b><u>" + x[1:] + " </u></b>" + s += x + "<br>" + + self.set_text(s) + + def set_text(self, text): + self.textbox.html_text = text + self.textbox.rebuild()