From 5180b74a91adb82a52555e847e88c069c3710198 Mon Sep 17 00:00:00 2001 From: Parallels Date: Sun, 12 Jan 2020 01:33:33 +0800 Subject: [PATCH] add GlobalScale --- sys.py/UI/main_screen.py | 4 ++-- sys.py/UI/util_funcs.py | 8 ++++++++ sys.py/config.py | 19 ++++++++++++++++--- sys.py/run.py | 9 +++++---- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/sys.py/UI/main_screen.py b/sys.py/UI/main_screen.py index 27891ee..fa454d1 100644 --- a/sys.py/UI/main_screen.py +++ b/sys.py/UI/main_screen.py @@ -20,7 +20,7 @@ from page import Page,PageStack from title_bar import TitleBar from foot_bar import FootBar from constants import Width,Height -from util_funcs import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable +from util_funcs import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable,SwapAndShow from keys_def import CurKeys from label import Label from untitled_icon import UntitledIcon @@ -361,7 +361,7 @@ class MainScreen(Widget): return if self._HWND != None: self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height)) - pygame.display.update() + SwapAndShow() def ExtraName(self,name): ## extra name like 1_xxx to be => xxx, diff --git a/sys.py/UI/util_funcs.py b/sys.py/UI/util_funcs.py index f913516..c271cde 100644 --- a/sys.py/UI/util_funcs.py +++ b/sys.py/UI/util_funcs.py @@ -12,6 +12,7 @@ import subprocess import string from Xlib import X,display import config +from constants import Width,Height def get_git_revision_hash(): return subprocess.check_output(['git', 'rev-parse', 'HEAD']) @@ -109,6 +110,13 @@ def DrawText(canvas,text, x,y,width,height,canWidth,canHeight,fontObj):# text fo def SwapAndShow(): + screen = pygame.display.get_surface() + if config.GlobalScale > 1: + tmp = pygame.transform.scale(config.GlobalCanvas,(Width*config.GlobalScale,Height*config.GlobalScale)) + screen.blit(tmp,(0,0,Width*config.GlobalScale,Height*config.GlobalScale)) + elif config.GlobalScale == 1: + screen.blit(config.GlobalCanvas,(0,0,Width,Height)) + pygame.display.update() def ArmSystem(cmd): diff --git a/sys.py/config.py b/sys.py/config.py index 8a64a36..dc59288 100644 --- a/sys.py/config.py +++ b/sys.py/config.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import os import platform -from UI.util_funcs import FileExists,ArmSystem +from UI.util_funcs import FileExists,ArmSystem,ReadTheFileContent from pyaria2_rpc.pyaria2 import Xmlrpc CurKeySet = "GameShell" ## >>> PC or GameShell <<< @@ -10,6 +10,7 @@ DontLeave = False BackLight = "/proc/driver/backlight" Battery = "/sys/class/power_supply/axp20x-battery/uevent" +FB_Modes = "/sys/class/graphics/fb0/modes" MPD_socket = "/tmp/mpd.socket" @@ -32,8 +33,11 @@ PowerLevels["balance_saving"] = [40,0,0] PowerLevel = "balance_saving" +GlobalCanvas=None +GlobalScale = 1 + def PreparationInAdv(): - global SKIN,ButtonsLayout + global SKIN,ButtonsLayout,FB_Modes,GlobalScale global PowerLevel global RPC if SKIN != None: @@ -73,7 +77,16 @@ def PreparationInAdv(): else: ArmSystem("sudo iw wlan0 set power_save off >/dev/null") - RPC = Xmlrpc('localhost', 6800) + if FileExists(FB_Modes): + modes = ReadTheFileContent(FB_Modes) + if "320x240" in modes: + GlobalScale = 1 + if "640x480" in modes: + GlobalScale = 2 + if "480x640" in modes: + GlobalScale = 2 + + RPC = Xmlrpc('localhost', 6800) PreparationInAdv() ##sys.py/.powerlevel diff --git a/sys.py/run.py b/sys.py/run.py index c1470e5..cccbd11 100644 --- a/sys.py/run.py +++ b/sys.py/run.py @@ -585,7 +585,7 @@ def socket_thread(main_screen): main_screen._TitleBar.Redraw() -def big_loop(): +def big_loop(screen): global sound_patch,gobject_flash_led1 title_bar = TitleBar() @@ -639,7 +639,7 @@ if __name__ == '__main__': os.chdir( os.path.dirname(os.path.realpath(__file__)) ) - SCREEN_SIZE = (Width,Height) + SCREEN_SIZE = (Width*config.GlobalScale,Height*config.GlobalScale) screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32) pygame.event.set_allowed(None) @@ -662,10 +662,11 @@ if __name__ == '__main__': print("This pygame does not support PNG") exit() + config.GlobalCanvas = pygame.Surface((Width,Height),0,32) crt_screen = CreateByScreen() crt_screen.Init() - crt_screen._HWND = screen + crt_screen._HWND = config.GlobalCanvas - big_loop() + big_loop(config.GlobalCanvas)