add socket server thread to receive remote call,and try add skin design on it

This commit is contained in:
cuu 2018-05-31 15:38:04 +08:00
parent 81f5c56d9e
commit aea9534d4d
61 changed files with 86 additions and 91 deletions

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## local UI import ## local UI import
import pages import pages
import myvars import myvars
@ -10,11 +9,8 @@ try:
except: except:
print("No icons package") print("No icons package")
""" """
from icons import preload
def Init(main_screen): def Init(main_screen):
preload.load_icons()
pages.InitPasswordPage(main_screen) pages.InitPasswordPage(main_screen)
pages.InitScanPage(main_screen) pages.InitScanPage(main_screen)

View File

@ -1,21 +0,0 @@
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
from sys import exit
import os
import sys
from beeprint import pp
ICONS_PRELOAD={}
def load_icons():
basepath = os.path.dirname(os.path.realpath(__file__))
files = os.listdir(basepath)
for i in files:
if os.path.isfile(basepath+"/"+i) and i.endswith(".png"):
keyname = i.split(".")[0]
ICONS_PRELOAD[keyname] = pygame.image.load(basepath+"/"+i).convert_alpha()

View File

@ -12,12 +12,12 @@ from UI.fonts import fonts
from UI.util_funcs import midRect from UI.util_funcs import midRect
from UI.keys_def import CurKeys from UI.keys_def import CurKeys
from UI.icon_item import IconItem from UI.icon_item import IconItem
from UI.icon_pool import MyIconPool
from libs.roundrects import aa_round_rect from libs.roundrects import aa_round_rect
from textarea import Textarea from textarea import Textarea
from text_item import TextItem from text_item import TextItem
from icons import preload
import myvars import myvars
@ -135,7 +135,7 @@ class Keyboard(Page):
if val == "_L" or val == "_R": if val == "_L" or val == "_R":
it = KeyboardIcon() it = KeyboardIcon()
it._ImgSurf = preload.ICONS_PRELOAD[val] it._ImgSurf = MyIconPool._Icons[val]
it._Parent = self it._Parent = self
it._Str = val it._Str = val
it.Init(start_x+it._ImgSurf.get_width()/2 ,start_y,it._ImgSurf.get_width(),it._ImgSurf.get_height(),0) it.Init(start_x+it._ImgSurf.get_width()/2 ,start_y,it._ImgSurf.get_width(),it._ImgSurf.get_height(),0)

View File

@ -8,8 +8,8 @@ from UI.label import Label
from UI.fonts import fonts from UI.fonts import fonts
from UI.icon_item import IconItem from UI.icon_item import IconItem
from UI.multi_icon_item import MultiIconItem from UI.multi_icon_item import MultiIconItem
from UI.icon_pool import MyIconPool
from icons import preload
class NetItemMultiIcon(MultiIconItem): class NetItemMultiIcon(MultiIconItem):
_CanvasHWND = None _CanvasHWND = None
@ -140,13 +140,13 @@ class NetItem(object):
lock_icon = NetItemIcon() lock_icon = NetItemIcon()
lock_icon._ImgSurf = preload.ICONS_PRELOAD["lock"] lock_icon._ImgSurf = MyIconPool._Icons["lock"]
lock_icon._CanvasHWND = self._Parent._CanvasHWND lock_icon._CanvasHWND = self._Parent._CanvasHWND
lock_icon._Parent = self lock_icon._Parent = self
self._Icons["lock"] = lock_icon self._Icons["lock"] = lock_icon
done_icon = NetItemIcon() done_icon = NetItemIcon()
done_icon._ImgSurf = preload.ICONS_PRELOAD["done"] done_icon._ImgSurf = MyIconPool._Icons["done"]
done_icon._CanvasHWND = self._Parent._CanvasHWND done_icon._CanvasHWND = self._Parent._CanvasHWND
done_icon._Parent = self done_icon._Parent = self

View File

@ -1,26 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pygame import pygame
from pygame.locals import *
from sys import exit
import os
import sys
from datetime import datetime
import base64
from beeprint import pp
## local UI import ## local UI import
import pages import pages
import myvars import myvars
from icons import preload
def Init(main_screen): def Init(main_screen):
pages.InitPoller() pages.InitPoller()
preload.load_icons()
pages.InitListPage(main_screen) pages.InitListPage(main_screen)
pages.InitMusicLibPage(main_screen) pages.InitMusicLibPage(main_screen)
pages.InitSpectrumPage(main_screen) pages.InitSpectrumPage(main_screen)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

View File

@ -1,21 +0,0 @@
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
from sys import exit
import os
import sys
from beeprint import pp
ICONS_PRELOAD={}
def load_icons():
basepath = os.path.dirname(os.path.realpath(__file__))
files = os.listdir(basepath)
for i in files:
if os.path.isfile(basepath+"/"+i) and i.endswith(".png"):
keyname = i.split(".")[0]
ICONS_PRELOAD[keyname] = pygame.image.load(basepath+"/"+i).convert_alpha()

View File

@ -17,7 +17,6 @@ from UI.util_funcs import midRect
# ------------------------ # ------------------------
import myvars # icons_path import myvars # icons_path
from icons import preload
class ListItemIcon(IconItem): class ListItemIcon(IconItem):

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 306 B

After

Width:  |  Height:  |  Size: 306 B

View File

Before

Width:  |  Height:  |  Size: 294 B

After

Width:  |  Height:  |  Size: 294 B

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

View File

Before

Width:  |  Height:  |  Size: 875 B

After

Width:  |  Height:  |  Size: 875 B

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 335 B

After

Width:  |  Height:  |  Size: 335 B

View File

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 545 B

After

Width:  |  Height:  |  Size: 545 B

View File

Before

Width:  |  Height:  |  Size: 286 B

After

Width:  |  Height:  |  Size: 286 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 427 B

After

Width:  |  Height:  |  Size: 427 B

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 316 B

After

Width:  |  Height:  |  Size: 316 B

View File

Before

Width:  |  Height:  |  Size: 601 B

After

Width:  |  Height:  |  Size: 601 B

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 673 B

After

Width:  |  Height:  |  Size: 673 B

View File

Before

Width:  |  Height:  |  Size: 627 B

After

Width:  |  Height:  |  Size: 627 B

1
sys.py/UI/.#page.py Symbolic link
View File

@ -0,0 +1 @@
guu@guu-desktop.5528:1527716105

View File

@ -6,18 +6,19 @@ from sys import exit
import os import os
import sys import sys
from datetime import datetime import config
if not pygame.font.get_init(): if not pygame.font.get_init():
pygame.font.init() pygame.font.init()
skinpath = "../skin/"+config.SKIN+"/truetype"
fonts_path = {} fonts_path = {}
fonts_path["varela"] = "../truetype/VarelaRound-Regular.ttf" fonts_path["varela"] = "%s/VarelaRound-Regular.ttf" % skinpath
fonts_path["veramono"] = "../truetype/VeraMono.ttf" fonts_path["veramono"] = "%s/VeraMono.ttf" % skinpath
fonts_path["noto"] = "../truetype/NotoSansMono-Regular.ttf" fonts_path["noto"] = "%s/NotoSansMono-Regular.ttf" % skinpath
fonts_path["notocjk"] = "../truetype/NotoSansCJK-Regular.ttf" fonts_path["notocjk"] = "%s/NotoSansCJK-Regular.ttf" % skinpath
fonts = {} fonts = {}
fonts["varela12"] = pygame.font.Font(fonts_path["varela"],12) fonts["varela12"] = pygame.font.Font(fonts_path["varela"],12)

View File

@ -6,14 +6,14 @@ import os
##local import ##local import
from constants import Width,Height,ICON_TYPES,ALIGN from constants import Width,Height,ICON_TYPES,ALIGN
from util_funcs import FileExists,midRect from util_funcs import FileExists,midRect,SkinMap
from icon_item import IconItem from icon_item import IconItem
from fonts import fonts from fonts import fonts
from multi_icon_item import MultiIconItem from multi_icon_item import MultiIconItem
from icon_pool import MyIconPool from icon_pool import MyIconPool
from libs.roundrects import aa_round_rect from libs.roundrects import aa_round_rect
icon_base_path = "gameshell/footbar_icons/" icon_base_path = SkinMap("gameshell/footbar_icons/")
class FootBarIcon(MultiIconItem): class FootBarIcon(MultiIconItem):

View File

@ -6,12 +6,12 @@ from sys import exit
import os import os
import sys import sys
from util_funcs import SkinMap
##pool only store surfaces ##pool only store surfaces
class IconPool(object): class IconPool(object):
_GameShellIconPath = "gameshell/icons/" _GameShellIconPath = SkinMap("gameshell/icons/")
_Icons = {} _Icons = {}
def __init__(self): def __init__(self):
self._Icons= {} self._Icons= {}

View File

@ -19,7 +19,7 @@ from page import Page,PageStack
from title_bar import TitleBar from title_bar import TitleBar
from foot_bar import FootBar from foot_bar import FootBar
from constants import Width,Height,bg_color from constants import Width,Height,bg_color
from util_funcs import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable from util_funcs import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable,SkinMap
from fonts import fonts from fonts import fonts
from keys_def import CurKeys from keys_def import CurKeys
from label import Label from label import Label
@ -371,8 +371,8 @@ class MainScreen(object):
iconitem = IconItem() iconitem = IconItem()
iconitem._CmdPath = "" iconitem._CmdPath = ""
iconitem.AddLabel(i2,self._IconFont) iconitem.AddLabel(i2,self._IconFont)
if FileExists(_dir+"/"+i2+".png"): if FileExists( SkinMap(_dir+"/"+i2+".png") ):
iconitem._ImageName = _dir+"/"+i2+".png" iconitem._ImageName = SkinMap(_dir+"/"+i2+".png")
else: else:
untitled = UntitledIcon() untitled = UntitledIcon()
untitled.Init() untitled.Init()
@ -446,8 +446,8 @@ class MainScreen(object):
iconitem._CmdPath = _dir+"/"+i iconitem._CmdPath = _dir+"/"+i
MakeExecutable(iconitem._CmdPath) MakeExecutable(iconitem._CmdPath)
iconitem._MyType = ICON_TYPES["EXE"] iconitem._MyType = ICON_TYPES["EXE"]
if FileExists(_dir+"/"+ReplaceSuffix(i2,"png")): if FileExists( SkinMap( _dir+"/"+ReplaceSuffix(i2,"png"))):
iconitem._ImageName = _dir+"/"+ReplaceSuffix(i2,"png") iconitem._ImageName = SkinMap(_dir+"/"+ReplaceSuffix(i2,"png"))
else: else:
untitled = UntitledIcon() untitled = UntitledIcon()
untitled.Init() untitled.Init()

View File

@ -17,7 +17,7 @@ from icon_item import IconItem
from multi_icon_item import MultiIconItem from multi_icon_item import MultiIconItem
from icon_pool import MyIconPool from icon_pool import MyIconPool
from util_funcs import midRect,SwapAndShow from util_funcs import midRect,SwapAndShow,SkinMap
from config import Battery from config import Battery
@ -25,7 +25,7 @@ from libs.roundrects import aa_round_rect
from libs.DBUS import is_wifi_connected_now,wifi_strength from libs.DBUS import is_wifi_connected_now,wifi_strength
icon_base_path = "gameshell/titlebar_icons/" icon_base_path = SkinMap("gameshell/titlebar_icons/")
class TitleBar: class TitleBar:
_PosX = 0 _PosX = 0
_PosY = 0 _PosY = 0
@ -179,13 +179,6 @@ class TitleBar:
self._CanvasHWND = pygame.Surface((self._Width,self._Height)) self._CanvasHWND = pygame.Surface((self._Width,self._Height))
self._HWND = screen self._HWND = screen
icon_snd = IconItem()
icon_snd._MyType = ICON_TYPES["STAT"]
icon_snd._Parent = self
icon_snd._ImageName = icon_base_path+"ic_volume_up_black.png"
icon_snd.Adjust(start_x,self._icon_height/2+(self._BarHeight-self._icon_height)/2,self._icon_width,self._icon_height,0)
icon_snd.ChangeImgSurfColor(self._IconColor)
icon_wifi_status = MultiIconItem() icon_wifi_status = MultiIconItem()
icon_wifi_status._MyType = ICON_TYPES["STAT"] icon_wifi_status._MyType = ICON_TYPES["STAT"]

View File

@ -11,7 +11,24 @@ import subprocess
#from beeprint import pp #from beeprint import pp
import string import string
from Xlib import X,display from Xlib import X,display
import config
def SkinMap(orig_file_or_dir):
DefaultSkin = "default"
if orig_file_or_dir.startswith(".."):
ret = orig_file_or_dir.replace("..","../skin/"+config.SKIN)
if FileExists(ret) == False:
ret = orig_file_or_dir.replace("..","../skin/"+DefaultSkin)
else:
ret = "../skin/"+config.SKIN+"/sys.py/"+orig_file_or_dir
if FileExists(ret) == False:
ret = "../skin/"+DefaultSkin+"/sys.py/"+orig_file_or_dir
if FileExists( ret ):
return ret
else: ## if not existed both in default or custom skin ,return where it is
return orig_file_or_dir
def get_git_revision_hash(): def get_git_revision_hash():
return subprocess.check_output(['git', 'rev-parse', 'HEAD']) return subprocess.check_output(['git', 'rev-parse', 'HEAD'])

View File

@ -12,4 +12,6 @@ MPD_socket = "/tmp/mpd.socket"
UPDATE_URL="https://raw.githubusercontent.com/clockworkpi/CPI/master/launcher_ver.json" UPDATE_URL="https://raw.githubusercontent.com/clockworkpi/CPI/master/launcher_ver.json"
VERSION="1.0" VERSION="stable 1.0"
SKIN="default"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 B

View File

@ -15,6 +15,7 @@ import time
import gobject import gobject
import socket
import pygame import pygame
from sys import exit from sys import exit
import os import os
@ -29,7 +30,7 @@ else:
#local UI import #local UI import
from UI.constants import Width,Height,bg_color,icon_width,icon_height,DT,GMEVT,RUNEVT,RUNSYS from UI.constants import Width,Height,bg_color,icon_width,icon_height,DT,GMEVT,RUNEVT,RUNSYS,ICON_TYPES
from UI.util_funcs import ReplaceSuffix,FileExists, ReadTheFileContent,midRect,color_surface,SwapAndShow,GetExePath,X_center_mouse from UI.util_funcs import ReplaceSuffix,FileExists, ReadTheFileContent,midRect,color_surface,SwapAndShow,GetExePath,X_center_mouse
from UI.page import PageStack,PageSelector,Page from UI.page import PageStack,PageSelector,Page
from UI.label import Label from UI.label import Label
@ -254,6 +255,42 @@ def gobject_pygame_event_timer(main_screen):
return True return True
@misc.threaded
def socket_thread(main_screen):
socket_path = "/tmp/gameshell"
if os.path.exists(socket_path):
os.remove(socket_path)
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind(socket_path)
while True:
server.listen(1)
conn, addr = server.accept()
datagram = conn.recv(1024)
if datagram:
tokens = datagram.strip().split()
if tokens[0].lower() == "quit":
conn.close()
on_exit_cb = getattr(main_screen,"OnExitCb",None)
if on_exit_cb != None:
if callable( on_exit_cb ):
main_screen.OnExitCb(None)
gobject_main_loop.quit()
exit()
if tokens[0].lower() == "poweroff":
if main_screen._CurrentPage._Name == "GameShell":
for i in main_screen._CurrentPage._Icons:
if i._MyType == ICON_TYPES["FUNC"]:
if i._Label.GetText() == "PowerOFF":
api_cb = getattr(i._CmdPath,"API",None)
if api_cb != None:
if callable(api_cb):
i._CmdPath.API(main_screen)
def big_loop(): def big_loop():
global sound_patch global sound_patch
@ -285,6 +322,8 @@ def big_loop():
gobject.timeout_add(3000,title_bar.GObjectRoundRobin) gobject.timeout_add(3000,title_bar.GObjectRoundRobin)
socket_thread(main_screen)
gobject_loop() gobject_loop()
@ -320,5 +359,6 @@ if __name__ == '__main__':
print("This pygame does not support PNG") print("This pygame does not support PNG")
exit() exit()
big_loop() big_loop()