def GiveWallpaper(self, png_name): #first SKIN/wallpapers/xxxx.png #second ../skin/default/wallpapers/xxxx.png #finnal gameshell/wallpaper/xxxx.png #loading.png,seeyou.png,updating.png,gameover.png,desktopbg.png wlp = "/wallpaper/" if FileExists(config.SKIN + wlp + png_name): return config.SKIN + wlp + png_name elif FileExists(self.DefaultSkin + wlp + png_name): return self.DefaultSkin + wlp + png_name else: return "gameshell/wallpaper/" + png_name
def SetLangs(self): self._Config = CaseConfigParser() #print("SetLangs") fname = ".lang" try: with open(fname, "r") as f: self._ConfigFileName = f.read() self._ConfigFileName = self._ConfigFileName.strip("\r\n ") #print(self._ConfigFileName) except: os.system("touch .lang") print("read lang failed") None if self._ConfigFileName == "" or FileExists("langs/"+self._ConfigFileName) == False: #print("miss file") self._ConfigFileName = "00_English.ini" else: pass #print("has file",self._ConfigFileName) try: self._Config.read("langs/"+self._ConfigFileName) except Exception, e: print("read lang ini error %s" % str(e)) return
def __init__(self): self._Icons = [] ## so every theme can have a background.png for displaying as the background of the launcher,except the topbar and footbar ## https://forum.clockworkpi.com/t/give-your-gs-a-custom-wallpaper/3724 bg_img_path = config.SKIN+"/background.png" if FileExists(bg_img_path): self._Wallpaper = pygame.transform.scale(pygame.image.load(bg_img_path).convert(), (320,240))
def configExists(self): if FileExists(config.SKIN + "/config.ini"): self._Config = CaseConfigParser() fname = config.SKIN + "/config.ini" try: return self._Config.read(fname) except Exception, e: print("skin config.ini read error %s" % str(e)) return
def GiveIcon(self,orig_file_or_dir): ## return is string,not Surface #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
def ReadFootBarIcons(self,icondir): if FileExists(icondir) == False and os.path.isdir(icondir) == False: return keynames = ["nav","x","y","a","b","select"] share_surf = pygame.image.load(icon_base_path+"footbar.png").convert_alpha() files = os.listdir(icondir) for _i,i in enumerate( keynames): it = FootBarIcon() it._MyType = ICON_TYPES["NAV"] it._Parent = self it._ImgSurf= share_surf it._Align = ALIGN["HLeft"] # (x)text <= it.AddLabel("game",self._LabelFont) it.Adjust(self._IconWidth/2+_i*self._IconWidth, self._IconHeight/2+2, self._IconWidth, self._IconHeight,0) it._IconIndex = _i self._Icons[i] = it
def Init(self, screen): start_x = 0 self._CanvasHWND = pygame.Surface((self._Width, self._Height)) self._HWND = screen icon_wifi_status = MultiIconItem() icon_wifi_status._MyType = ICON_TYPES["STAT"] icon_wifi_status._ImageName = icon_base_path + "wifi.png" icon_wifi_status._Parent = self icon_wifi_status.Adjust( start_x + self._icon_width + 5, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2, self._icon_width, self._icon_height, 0) self._Icons["wifistatus"] = icon_wifi_status battery_charging = MultiIconItem() battery_charging._MyType = ICON_TYPES["STAT"] battery_charging._Parent = self battery_charging._ImageName = icon_base_path + "withcharging.png" battery_charging.Adjust( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2, self._icon_width, self._icon_height, 0) self._Icons["battery_charging"] = battery_charging battery_discharging = MultiIconItem() battery_discharging._MyType = ICON_TYPES["STAT"] battery_discharging._Parent = self battery_discharging._ImageName = icon_base_path + "without_charging.png" battery_discharging.Adjust( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2, self._icon_width, self._icon_height, 0) self._Icons["battery_discharging"] = battery_discharging battery_unknown = IconItem() battery_unknown._MyType = ICON_TYPES["STAT"] battery_unknown._Parent = self battery_unknown._ImageName = icon_base_path + "battery_unknown.png" battery_unknown.Adjust( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2, self._icon_width, self._icon_height, 0) self._Icons["battery_unknown"] = battery_unknown self.CheckBatteryStat() sound_volume = MultiIconItem() sound_volume._MyType = ICON_TYPES["STAT"] sound_volume._Parent = self sound_volume._ImageName = icon_base_path + "soundvolume.png" sound_volume.Adjust( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2, self._icon_width, self._icon_height, 0) self._Icons["soundvolume"] = sound_volume self.SyncSoundVolume() bluetooth = MultiIconItem() bluetooth._MyType = ICON_TYPES["STAT"] bluetooth._Parent = self bluetooth._ImageName = icon_base_path + "bluetooth.png" bluetooth.Adjust( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2, self._icon_width, self._icon_height, 0) self._Icons["bluetooth"] = bluetooth self.CheckBluetooth() round_corners = MultiIconItem() round_corners._IconWidth = 10 round_corners._IconHeight = 10 round_corners._MyType = ICON_TYPES["STAT"] round_corners._Parent = self round_corners._ImgSurf = MyIconPool.GiveIconSurface("roundcorners") round_corners.Adjust(0, 0, 10, 10, 0) self._Icons["round_corners"] = round_corners dlstatus = MultiIconItem() dlstatus._MyType = ICON_TYPES["STAT"] dlstatus._Parent = self if FileExists(icon_base_path + "dlstatus18.png"): dlstatus._ImageName = icon_base_path + "dlstatus18.png" dlstatus.Adjust( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2, self._icon_width, self._icon_height, 0) self._Icons["dlstatus"] = dlstatus self.UpdateDownloadStatus() if is_wifi_connected_now(): print("wifi is connected") print(wifi_strength()) else: out = commands.getstatusoutput( 'sudo rfkill list | grep yes | cut -d " " -f3') if out[1] == "yes": self._InAirPlaneMode = True else: self._InAirPlaneMode = False
def ReadTheDirIntoPages(self, _dir, pglevel, cur_page): global commercialsoftware_flag if FileExists(_dir) == False and os.path.isdir(_dir) == False: return files = os.listdir(_dir) for i in sorted(files): if os.path.isdir(_dir + "/" + i) and i.startswith( ".") == False: # TOPLEVEL only is dir if pglevel == 0: page = Page() page._Name = self.ExtraName(i) page._Icons = [] self._Pages.append(page) self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1, self._Pages[len(self._Pages) - 1]) else: ## On CurPage now i2 = self.ExtraName(i) iconitem = IconItem() iconitem._FileName = i iconitem._CmdPath = "" 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( MySkinManager.GiveIcon(_dir + "/" + i2 + ".png")): iconitem._ImageName = MySkinManager.GiveIcon(_dir + "/" + i2 + ".png") else: untitled = UntitledIcon() untitled.Init() if len(i2) > 1: untitled.SetWords(i2[:2]) elif len(i2) == 1: untitled.SetWords([i2[0], i2[0]]) else: untitled.SetWords(["G", "s"]) iconitem._ImgSurf = untitled.Surface() iconitem._ImageName = "" if self.IsPythonPackage(_dir + "/" + i): iconitem._MyType = ICON_TYPES["FUNC"] sys.path.append(_dir) iconitem._CmdPath = __import__(i) init_cb = getattr(iconitem._CmdPath, "Init", None) if init_cb != None: if callable(init_cb): iconitem._CmdPath.Init(self) cur_page._Icons.append(iconitem) elif self.IsEmulatorPackage(_dir + "/" + i): obj = {} obj["ROM"] = "" obj["ROM_SO"] = "" obj["EXT"] = [] obj["EXCLUDE"] = [] obj["FILETYPE"] = "file" obj["LAUNCHER"] = "" obj["TITLE"] = "Game" obj["SO_URL"] = "" obj["RETRO_CONFIG"] = "" ## try: f = open(_dir + "/" + i + "/" + emulator_flag) except IOError: print("action config open failed") return else: with f: content = f.readlines() content = [x.strip() for x in content] for c in content: pis = c.split("=") if len(pis) > 1: if "EXT" in pis[0]: obj[pis[0]] = pis[1].split(",") elif "EXCLUDE" in pis[0]: obj[pis[0]] = pis[1].split(",") else: obj[pis[0]] = pis[1] if FileExists(_dir + "/" + i + "/retroarch-local.cfg"): obj["RETRO_CONFIG"] = CmdClean( os.path.abspath(_dir + "/" + i + "/retroarch-local.cfg")) print("a local retroarch cfg:", obj["RETRO_CONFIG"]) em = MyEmulator() em._Emulator = obj em.Init(self) iconitem._CmdPath = em iconitem._MyType = ICON_TYPES["Emulator"] cur_page._Icons.append(iconitem) elif self.IsCommercialPackage(os.path.join(_dir, i)): data = None em = MyCommercialSoftwarePackage() if FileExists(_dir + "/" + i + "/.done"): print(_dir + "/" + i + "/.done") em._Done = os.path.realpath(_dir + "/" + i + "/" + i2 + ".sh") else: with open( os.path.join(_dir, i) + "/" + commercialsoftware_flag) as f: data = json.load(f) em._ComPkgInfo = data em._Done = "" em._InvokeDir = os.path.realpath(os.path.join(_dir, i)) em.Init(self) iconitem._CmdPath = em iconitem._MyType = ICON_TYPES["Commercial"] cur_page._Icons.append(iconitem) elif self.IsExecPackage( _dir + "/" + i): ## ExecPackage is the last one to check iconitem._MyType = ICON_TYPES["EXE"] iconitem._CmdPath = os.path.realpath(_dir + "/" + i + "/" + i2 + ".sh") MakeExecutable(iconitem._CmdPath) cur_page._Icons.append(iconitem) else: iconitem._MyType = ICON_TYPES["DIR"] iconitem._LinkPage = Page() iconitem._LinkPage._Name = i2 cur_page._Icons.append(iconitem) self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1, iconitem._LinkPage) elif os.path.isfile(_dir + "/" + i) and i.startswith( ".") == False and pglevel > 0: if i.lower().endswith(icon_ext): i2 = self.ExtraName(i) #cmd = ReadTheFileContent(_dir+"/"+i) iconitem = IconItem() iconitem._FileName = i iconitem._CmdPath = os.path.realpath(_dir + "/" + i) MakeExecutable(iconitem._CmdPath) iconitem._MyType = ICON_TYPES["EXE"] if FileExists( MySkinManager.GiveIcon(_dir + "/" + ReplaceSuffix(i2, "png"))): iconitem._ImageName = MySkinManager.GiveIcon( _dir + "/" + ReplaceSuffix(i2, "png")) else: untitled = UntitledIcon() untitled.Init() if len(i2) > 1: untitled.SetWords(i2[:2]) elif len(i2) == 1: untitled.SetWords([i2[0], i2[0]]) else: untitled.SetWords(["G", "s"]) iconitem._ImgSurf = untitled.Surface() iconitem._ImageName = "" iconitem.AddLabel(MyLangManager.Tr(i2.split(".")[0]), self._IconFont) iconitem._LinkPage = None cur_page._Icons.append(iconitem)
def ReadTheDirIntoPages(self,_dir,pglevel,cur_page): if FileExists(_dir) == False and os.path.isdir(_dir) == False: return files = os.listdir(_dir) for i in sorted(files): if os.path.isdir(_dir+"/"+i): # TOPLEVEL only is dir if pglevel == 0: page = Page() page._Name = self.ExtraName(i) page._Icons = [] self._Pages.append(page) self.ReadTheDirIntoPages(_dir+"/"+i, pglevel+1 ,self._Pages[ len(self._Pages) -1]) else: ## On CurPage now i2 = self.ExtraName(i) iconitem = IconItem() iconitem._CmdPath = "" iconitem.AddLabel(i2,self._IconFont) if FileExists(_dir+"/"+i2+".png"): iconitem._ImageName = _dir+"/"+i2+".png" else: untitled = UntitledIcon() untitled.Init() if len(i2) > 1: untitled.SetWords(i2[:2]) elif len(i2) == 1: untitled.SetWords([i2[0],i2[0]]) else: untitled.SetWords(["G","s"]) iconitem._ImgSurf = untitled.Surface() iconitem._ImageName = "" if self.IsPythonPackage(_dir+"/"+i): iconitem._MyType = ICON_TYPES["FUNC"] sys.path.append(_dir) iconitem._CmdPath = __import__(i) init_cb = getattr(iconitem._CmdPath,"Init",None) if init_cb != None: if callable(init_cb): iconitem._CmdPath.Init(self) cur_page._Icons.append(iconitem) elif self.IsEmulatorPackage(_dir+"/"+i): obj = {} obj["ROM"] = "" obj["ROM_SO"] ="" obj["EXT"] = [] obj["LAUNCHER"] = "" obj["TITLE"] = "Game" obj["SO_URL"] = "" try: f = open(_dir+"/"+i+"/"+emulator_flag) except IOError: print("action config open failed") return else: with f: content = f.readlines() content = [x.strip() for x in content] for i in content: pis = i.split("=") if len(pis) > 1: if "EXT" in pis[0]: obj[pis[0]] = pis[1].split(",") else: obj[pis[0]] = pis[1] em = MyEmulator() em._Emulator = obj em.Init(self) iconitem._CmdPath = em iconitem._MyType = ICON_TYPES["Emulator"] cur_page._Icons.append(iconitem) else: iconitem._MyType = ICON_TYPES["DIR"] iconitem._LinkPage = Page() iconitem._LinkPage._Name = i2 cur_page._Icons.append(iconitem) self.ReadTheDirIntoPages(_dir+"/"+i,pglevel+1,iconitem._LinkPage) elif os.path.isfile(_dir+"/"+i) and pglevel > 0: if i.lower().endswith(icon_ext): i2 = self.ExtraName(i) #cmd = ReadTheFileContent(_dir+"/"+i) iconitem = IconItem() iconitem._CmdPath = _dir+"/"+i MakeExecutable(iconitem._CmdPath) iconitem._MyType = ICON_TYPES["EXE"] if FileExists(_dir+"/"+ReplaceSuffix(i2,"png")): iconitem._ImageName = _dir+"/"+ReplaceSuffix(i2,"png") else: untitled = UntitledIcon() untitled.Init() if len(i2) > 1: untitled.SetWords(i2[:2]) elif len(i2) == 1: untitled.SetWords([i2[0],i2[0]]) else: untitled.SetWords(["G","s"]) iconitem._ImgSurf = untitled.Surface() iconitem._ImageName = "" iconitem.AddLabel(i2.split(".")[0],self._IconFont) iconitem._LinkPage = None cur_page._Icons.append(iconitem)