Browse Source

Make first mockup of the main screen interface.

Probably need to make some part a bit more modular (TitleBar and FootBar
could be their own widget)

Separate the test main app to test new widget and the new app (start_ui.py)
Godzil 5 years ago
parent
commit
6676426897

+ 1 - 0
skin/cpi_default/config.cfg

@@ -1,6 +1,7 @@
 [Colors]
 High=#33a6ff
 White=#ffffff
+BgColor=#ffffff
 
 [Fonts]
 varela=VarelaRound-Regular.ttf

+ 1 - 1
sys.py/GdUI/label.py

@@ -5,7 +5,7 @@ from . import font_manager
 
 
 class Label(Widget):
-    def __init__(self, x, y, width=1, height=1, text="", font_obj=font_manager.get_font("default"),
+    def __init__(self, x=0, y=0, width=1, height=1, text="", font_obj=font_manager.get_font("default"),
                  color=(83, 83, 83), bg_color=None,
                  auto_resize=True):
         super().__init__(x=x, y=y, width=width, height=height, color=color, bg_color=bg_color)

+ 4 - 1
sys.py/GdUI/widget.py

@@ -42,8 +42,11 @@ class Widget:
         return self._Rect
 
     def Draw(self):
-        if self._BG_Color is not None and self.parent is not None:
+        if self._BG_Color is not None and self._Parent is not None:
             pygame.draw.rect(self._Parent.get_canvas(), self._BG_Color, self._Rect)
 
     def handle_event(self, evt):
+        pass
+
+    def reload(self):
         pass

+ 2 - 0
sys.py/config.json

@@ -12,5 +12,7 @@
     "battery",
     "wifi"
   ],
+  "screen_width": 320,
+  "screen_height": 240,
   "main_applet": "springboard"
 }

+ 1 - 0
sys.py/config_manager.py

@@ -47,6 +47,7 @@ def get(key):
     except KeyError:
         return None
 
+
 if __initialized == False:
     load_config("config.json")
     __initialized = True

+ 54 - 0
sys.py/interface/main_screen.py

@@ -0,0 +1,54 @@
+import pygame
+
+import config_manager as config
+import skin_manager as SkinManager
+import GdUI as UI
+
+
+class MainScreen(UI.Container):
+    def __init__(self, width, height):
+        super().__init__(x=0, y=0, width=width, height=height)
+
+        self._TitleBar = UI.FlowContainer(x=0, y=0, width=width, height=25)
+        self._TitleBar.set_bgcolor(SkinManager.get_color("title_bg"))
+
+        self._TitleBar_line = UI.Widget(x=0, y=24, width=width, height=1,
+                                       bg_color=SkinManager.get_color("line"))
+
+        self._FootBar = UI.FlowContainer(x=0, y=height - 20, width=width, height=20)
+        self._FootBar.set_bgcolor(SkinManager.get_color("white"))
+
+        self._FootBar_line = UI.Widget(x=0, y=0, width=width, height=1,
+                                       bg_color=SkinManager.get_color("line"))
+
+        self._AppletContainer = UI.Container(x=0, y=25, width=width, height=height-25-20,
+                                             bg_color=SkinManager.get_color("bgcolor"))
+
+        self._corner_ul = UI.Image(x=0, y=0, image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 1))
+        self._corner_ur = UI.Image(x=width - 10, y=0,
+                                   image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 2))
+        self._corner_dl = UI.Image(x=0, y=height - 10,
+                                   image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 3))
+        self._corner_dr = UI.Image(x=width - 10, y=height - 10,
+                                   image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 4))
+
+        self.add_child(self._TitleBar)
+        self.add_child(self._FootBar)
+        self._FootBar.add_child(self._FootBar_line)
+        self._TitleBar.add_child(self._TitleBar_line)
+        self.add_child(self._AppletContainer)
+        self.add_child(self._corner_ul)
+        self.add_child(self._corner_ur)
+        self.add_child(self._corner_dl)
+        self.add_child(self._corner_dr)
+
+        # Title on top
+        self._Title = "GameShell"
+        self._TitleLbl = UI.Label(color=SkinManager.get_color("text"), font_obj=UI.FontManager.get_font("varela_16"),
+                                  text=self._Title)
+        self._TitleBar.add_left_child(self._TitleLbl)
+
+    def reload(self):
+        # Do nothing for now, later reload info from skinmanager
+        pass
+

+ 70 - 0
sys.py/start_ui.py

@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+
+import pygame
+
+if not pygame.display.get_init():
+    pygame.display.init()
+if not pygame.font.get_init():
+    pygame.font.init()
+
+# from wicd import misc
+import config_manager as config
+import plugins
+import skin_manager as SkinManager
+
+import GdUI as UI
+from interface import main_screen
+
+plugins = plugins.LoadPlugins(config)
+fonts = UI.FontManager
+myscriptname = os.path.basename(os.path.realpath(__file__))
+SkinManager.load_skin("cpi_default")
+
+
+def process_event(event, ui_root: UI.Widget):
+    if event is not None:
+
+        if event.type == pygame.QUIT:
+            sys.exit()
+
+        elif event.type == pygame.KEYDOWN:
+            if event.key == pygame.K_q:
+                sys.exit()
+        else:
+            ui_root.handle_event(event)
+
+
+def main_loop():
+    global sound_patch
+    screen_width = config.get("screen_width")
+    screen_height = config.get("screen_height")
+
+    screen = UI.Screen(fps=30, width=screen_width, height=screen_height)
+    main = main_screen.MainScreen(screen_width, screen_height)
+
+    screen.add_child(main)
+
+    while True:
+        for event in pygame.event.get():
+            process_event(event, screen)
+
+        screen.Draw()
+
+
+def init():
+    os.environ['SDL_VIDEO_CENTERED'] = '1'
+    os.chdir(os.path.dirname(os.path.realpath(__file__)))
+
+    if pygame.image.get_extended() == False:
+        print("This pygame does not support PNG")
+        sys.exit()
+
+
+    main_loop()
+
+
+init()

+ 0 - 0
sys.py/startui.py → sys.py/test_ui.py