mirror of
https://github.com/clockworkpi/launcher.git
synced 2025-12-12 09:48:50 +01:00
fix fds leak and remove SkinMap
This commit is contained in:
parent
6f855dc36f
commit
d3b508c3a1
@ -13,7 +13,7 @@ if not pygame.font.get_init():
|
||||
|
||||
fonts = {}
|
||||
if not fonts:
|
||||
skinpath = "../skin/"+config.SKIN+"/truetype"
|
||||
skinpath = config.SKIN+"/truetype"
|
||||
fonts_path = {}
|
||||
|
||||
fonts_path["varela"] = "%s/VarelaRound-Regular.ttf" % skinpath
|
||||
|
||||
@ -6,7 +6,7 @@ import os
|
||||
|
||||
##local import
|
||||
from constants import Width,Height,ICON_TYPES,ALIGN
|
||||
from util_funcs import FileExists,midRect,SkinMap
|
||||
from util_funcs import FileExists,midRect
|
||||
from icon_item import IconItem
|
||||
from fonts import fonts
|
||||
from multi_icon_item import MultiIconItem
|
||||
@ -14,7 +14,9 @@ from icon_pool import MyIconPool
|
||||
from libs.roundrects import aa_round_rect
|
||||
from lang_manager import MyLangManager
|
||||
from widget import Widget
|
||||
icon_base_path = SkinMap("gameshell/footbar_icons/")
|
||||
from skin_manager import MySkinManager
|
||||
|
||||
icon_base_path = MySkinManager.GiveIcon("gameshell/footbar_icons/")
|
||||
|
||||
class FootBarIcon(MultiIconItem):
|
||||
|
||||
|
||||
@ -6,12 +6,12 @@ from sys import exit
|
||||
import os
|
||||
import sys
|
||||
|
||||
from util_funcs import SkinMap
|
||||
from skin_manager import MySkinManager
|
||||
##pool only store surfaces
|
||||
|
||||
class IconPool(object):
|
||||
|
||||
_GameShellIconPath = SkinMap("gameshell/icons/")
|
||||
_GameShellIconPath = MySkinManager.GiveIcon("gameshell/icons/")
|
||||
_Icons = {}
|
||||
_Sizes = {}
|
||||
def __init__(self):
|
||||
|
||||
@ -20,7 +20,7 @@ from page import Page,PageStack
|
||||
from title_bar import TitleBar
|
||||
from foot_bar import FootBar
|
||||
from constants import Width,Height,bg_color
|
||||
from util_funcs import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable,SkinMap
|
||||
from util_funcs import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable
|
||||
from keys_def import CurKeys
|
||||
from label import Label
|
||||
from untitled_icon import UntitledIcon
|
||||
@ -469,8 +469,8 @@ class MainScreen(Widget):
|
||||
iconitem.AddLabel(MyLangManager.Tr(i2),self._IconFont)
|
||||
if FileExists( _dir+"/"+i+"/"+i2+".png"): ### 20_Prog/Prog.png , cut 20_
|
||||
iconitem._ImageName = _dir+"/"+i+"/"+i2+".png"
|
||||
elif FileExists( SkinMap(_dir+"/"+i2+".png") ):
|
||||
iconitem._ImageName = SkinMap(_dir+"/"+i2+".png")
|
||||
elif FileExists( MySkinManager.GiveIcon(_dir+"/"+i2+".png") ):
|
||||
iconitem._ImageName = MySkinManager.GiveIcon(_dir+"/"+i2+".png")
|
||||
else:
|
||||
untitled = UntitledIcon()
|
||||
untitled.Init()
|
||||
@ -577,8 +577,8 @@ class MainScreen(Widget):
|
||||
iconitem._CmdPath = os.path.realpath(_dir+"/"+i)
|
||||
MakeExecutable(iconitem._CmdPath)
|
||||
iconitem._MyType = ICON_TYPES["EXE"]
|
||||
if FileExists( SkinMap( _dir+"/"+ReplaceSuffix(i2,"png"))):
|
||||
iconitem._ImageName = SkinMap(_dir+"/"+ReplaceSuffix(i2,"png"))
|
||||
if FileExists( MySkinManager.GiveIcon( _dir+"/"+ReplaceSuffix(i2,"png"))):
|
||||
iconitem._ImageName = MySkinManager.GiveIcon(_dir+"/"+ReplaceSuffix(i2,"png"))
|
||||
else:
|
||||
untitled = UntitledIcon()
|
||||
untitled.Init()
|
||||
|
||||
@ -4,6 +4,8 @@ import pygame
|
||||
import config
|
||||
import ConfigParser
|
||||
|
||||
from util_funcs import FileExists
|
||||
|
||||
class CaseConfigParser(ConfigParser.SafeConfigParser):
|
||||
def optionxform(self, optionstr):
|
||||
return optionstr
|
||||
@ -21,6 +23,7 @@ class SkinManager(object):
|
||||
|
||||
_Colors = {}
|
||||
_Config = None
|
||||
DefaultSkin = "../skin/default"
|
||||
|
||||
def __init__(self):
|
||||
self.Init()
|
||||
@ -52,7 +55,7 @@ class SkinManager(object):
|
||||
|
||||
self._Config = CaseConfigParser()
|
||||
|
||||
fname = "../skin/"+config.SKIN+"/config.cfg"
|
||||
fname = config.SKIN+"/config.ini"
|
||||
|
||||
try:
|
||||
self._Config.read(fname)
|
||||
@ -78,6 +81,24 @@ class SkinManager(object):
|
||||
else:
|
||||
return pygame.Color(255,0,0)
|
||||
|
||||
def GiveIcon(self,orig_file_or_dir):
|
||||
#doing a wrapper for items under /home/cpi/apps/Menu/*, to be like Menu/GameShell/*
|
||||
if orig_file_or_dir.startswith("/home/cpi/apps/Menu"):
|
||||
orig_file_or_dir = orig_file_or_dir.replace("/home/cpi/apps/Menu/","../Menu/GameShell/")
|
||||
|
||||
if orig_file_or_dir.startswith(".."):
|
||||
ret = orig_file_or_dir.replace("..",config.SKIN)
|
||||
if FileExists(ret) == False:
|
||||
ret = orig_file_or_dir.replace("..",self.DefaultSkin)
|
||||
else:
|
||||
ret = config.SKIN+"/sys.py/"+orig_file_or_dir
|
||||
if FileExists(ret) == False:
|
||||
ret = self.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
|
||||
|
||||
##global MySkinManager Handler
|
||||
MySkinManager = None
|
||||
|
||||
@ -18,7 +18,8 @@ from icon_item import IconItem
|
||||
from multi_icon_item import MultiIconItem
|
||||
from icon_pool import MyIconPool
|
||||
from lang_manager import MyLangManager
|
||||
from util_funcs import midRect,SwapAndShow,SkinMap
|
||||
from util_funcs import midRect,SwapAndShow
|
||||
from skin_manager import MySkinManager
|
||||
from widget import Widget
|
||||
from config import Battery
|
||||
|
||||
@ -26,7 +27,7 @@ from libs.roundrects import aa_round_rect
|
||||
|
||||
from libs.DBUS import is_wifi_connected_now,wifi_strength
|
||||
|
||||
icon_base_path = SkinMap("gameshell/titlebar_icons/")
|
||||
icon_base_path = MySkinManager.GiveIcon("gameshell/titlebar_icons/")
|
||||
class TitleBar(Widget):
|
||||
_Width = Width
|
||||
_Height = 25
|
||||
|
||||
@ -11,12 +11,12 @@ from datetime import datetime
|
||||
import base64
|
||||
from beeprint import pp
|
||||
|
||||
from util_funcs import midRect, SkinMap
|
||||
from util_funcs import midRect
|
||||
from fonts import fonts
|
||||
|
||||
from skin_manager import MySkinManager
|
||||
|
||||
BlankPng = SkinMap("gameshell/blank.png") # 80x80
|
||||
BlankPng = MySkinManager.GiveIcon("gameshell/blank.png") # 80x80
|
||||
## use blank circle as bg, Two alpha As Icon Label
|
||||
#Upper and Lower
|
||||
|
||||
|
||||
@ -13,27 +13,6 @@ import string
|
||||
from Xlib import X,display
|
||||
import config
|
||||
|
||||
def SkinMap(orig_file_or_dir):
|
||||
DefaultSkin = "default"
|
||||
|
||||
#doing a wrapper for items under /home/cpi/apps/Menu/*, to be like Menu/GameShell/*
|
||||
if orig_file_or_dir.startswith("/home/cpi/apps/Menu"):
|
||||
orig_file_or_dir = orig_file_or_dir.replace("/home/cpi/apps/Menu/","../Menu/GameShell/")
|
||||
|
||||
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():
|
||||
return subprocess.check_output(['git', 'rev-parse', 'HEAD'])
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ UPDATE_URL="https://raw.githubusercontent.com/clockworkpi/CPI/master/launcher_ve
|
||||
|
||||
VERSION="stable 1.24"
|
||||
|
||||
SKIN="default"
|
||||
SKIN="../skin/default"
|
||||
|
||||
## three timer values in seconds: dim screen, close screen,PowerOff
|
||||
## zero means no action
|
||||
|
||||
@ -4,6 +4,9 @@ import dbus
|
||||
import dbus.service
|
||||
import sys
|
||||
import commands
|
||||
import logging
|
||||
import errno
|
||||
|
||||
from wicd import misc
|
||||
##misc.to_bool
|
||||
##misc.misc.noneToString
|
||||
@ -289,6 +292,35 @@ def RecordKeyDns(thekey,main_screen):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def release_self_fds():
|
||||
fds_flags= ["pipe","socket",".ttf"]
|
||||
"""List process currently open FDs and their target """
|
||||
if sys.platform != 'linux2':
|
||||
raise NotImplementedError('Unsupported platform: %s' % sys.platform)
|
||||
|
||||
ret = {}
|
||||
base = '/proc/self/fd'
|
||||
for num in os.listdir(base):
|
||||
path = None
|
||||
try:
|
||||
path = os.readlink(os.path.join(base, num))
|
||||
except OSError as err:
|
||||
# Last FD is always the "listdir" one (which may be closed)
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
ret[int(num)] = path
|
||||
|
||||
for key in ret:
|
||||
if ret[key] != None and isinstance(ret[key], str):
|
||||
for i in fds_flags:
|
||||
if i in ret[key]:
|
||||
os.close(key)
|
||||
break
|
||||
return ret
|
||||
|
||||
|
||||
def event_process(event,main_screen):
|
||||
global sound_patch
|
||||
global everytime_keydown
|
||||
@ -316,6 +348,7 @@ def event_process(event,main_screen):
|
||||
exec_app_cmd += event.message
|
||||
exec_app_cmd += "; sync & cd "+GetExePath()+"; exec python "+myscriptname
|
||||
print(exec_app_cmd)
|
||||
release_self_fds()
|
||||
os.execlp("/bin/sh","/bin/sh","-c", exec_app_cmd)
|
||||
os.chdir( GetExePath())
|
||||
os.exelp("python","python"," "+myscriptname)
|
||||
@ -334,6 +367,7 @@ def event_process(event,main_screen):
|
||||
exec_app_cmd += event.message
|
||||
exec_app_cmd += "; sync & cd "+GetExePath()+"; exec python "+myscriptname
|
||||
print(exec_app_cmd)
|
||||
release_self_fds()
|
||||
os.execlp("/bin/sh","/bin/sh","-c", exec_app_cmd)
|
||||
os.chdir( GetExePath())
|
||||
os.exelp("python","python"," "+myscriptname)
|
||||
@ -542,6 +576,13 @@ def PreparationInAdv():
|
||||
if "arm" not in platform.machine():
|
||||
return
|
||||
|
||||
if FileExists("%s/.gameshell_skin" % os.path.expanduser('~')) == True:
|
||||
with open("%s/.gameshell_skin" % os.path.expanduser('~'),"r") as f:
|
||||
gameshell_skin = f.read()
|
||||
|
||||
gameshell_skin = gameshell_skin.strip()
|
||||
config.SKIN= gameshell_skin
|
||||
|
||||
if FileExists(".powerlevel") == False:
|
||||
os.system("touch .powerlevel")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user