Merge branch 'master' of github.com:Taffer/launcher into codestyle-cleanup

This commit is contained in:
Taffer 2019-12-30 15:35:54 -05:00
commit 9b5e3b411b

View File

@ -59,7 +59,6 @@ class RPCStack:
class LoadHousePage(Page): class LoadHousePage(Page):
_FootMsg = ["Nav.","","","Back","Cancel"] _FootMsg = ["Nav.","","","Back","Cancel"]
_DownloaderTimer = -1
_Value = 0 _Value = 0
_URL = None _URL = None
_ListFontObj = MyLangManager.TrFont("varela18") _ListFontObj = MyLangManager.TrFont("varela18")
@ -188,7 +187,6 @@ class LoadHousePage(Page):
class ImageDownloadProcessPage(Page): class ImageDownloadProcessPage(Page):
_FootMsg = ["Nav.","","","Back",""] _FootMsg = ["Nav.","","","Back",""]
_DownloaderTimer = -1
_Value = 0 _Value = 0
_URL = None _URL = None
_ListFontObj = MyLangManager.TrFont("varela13") _ListFontObj = MyLangManager.TrFont("varela13")
@ -344,35 +342,36 @@ class Aria2DownloadProcessPage(Page):
self._SizeLabel.Init("0/0Kb",MyLangManager.TrFont("varela12")) self._SizeLabel.Init("0/0Kb",MyLangManager.TrFont("varela12"))
self._SizeLabel.SetColor( self._URLColor ) self._SizeLabel.SetColor( self._URLColor )
@property
def GObjectUpdateProcessInterval(self): def GObjectUpdateProcessInterval(self):
downloaded = 0
if self._Screen.CurPage() == self and self._GID is not None: if self._Screen.CurPage() == self and self._GID is not None:
self._Value = config.RPC.tellStatus(self._GID) self._Value = config.RPC.tellStatus(self._GID)
downloaded = 0 downloaded = 0
total = 0 total = 0
if self._Value["status"] == "waiting": if self._Value["status"] == "waiting":
self._FileNameLabel.SetText( "waiting to download..." ) self._FileNameLabel.SetText("waiting to download...")
if self._Value["status"] == "paused": if self._Value["status"] == "paused":
self._FileNameLabel.SetText( "download paused..." ) self._FileNameLabel.SetText("download paused...")
if self._Value["status"] == "error": if self._Value["status"] == "error":
self._FileNameLabel.SetText("download errors,cancel it please") self._FileNameLabel.SetText("download errors,cancel it please")
if self._Value["status"] == "active": if self._Value["status"] == "active":
downloaded = self._Value["completedLength"] downloaded = self._Value["completedLength"]
total = self._Value["totalLength"] total = self._Value["totalLength"]
downloaded = downloaded/1000.0/1000.0 downloaded = downloaded / 1000.0 / 1000.0
total = total/1000.0/1000.0 total = total / 1000.0 / 1000.0
self._SizeLabel.SetText( "%.2f" % downloaded+"/"+ "%.2f" % total +"Mb") self._SizeLabel.SetText("%.2f" % downloaded+"/"+"%.2f" % total+"Mb")
print("Progress: %d%%" % (self._Value))
self._Screen.Draw()
self._Screen.SwapAndShow()
return True
print("Progress: %d%%" % (self._Value))
self._Screen.Draw()
self._Screen.SwapAndShow()
return True
else:
return False
def CheckDownload(self,aria2_gid): def CheckDownload(self,aria2_gid):
self._GID = aria2_gid self._GID = aria2_gid
@ -546,17 +545,19 @@ class GameStorePage(Page):
_warehouse_db = "warehouse.db" _warehouse_db = "warehouse.db"
_GobjTimer = -1 _GobjTimer = -1
_Scrolled_cnt = 0
def __init__(self): def __init__(self):
Page.__init__(self) Page.__init__(self)
self._Icons = {} self._Icons = {}
self._MyStack = RPCStack() self._MyStack = RPCStack()
#title file type #title file type
## Two level url , only github.com ## Two level url , only github.com
repos = [ repos = [
{"title":"github.com/clockworkpi/warehouse","file":"https://raw.githubusercontent.com/clockworkpi/warehouse/master/index.json","type":"source"} {"title":"github.com/clockworkpi/warehouse","file":"https://raw.githubusercontent.com/clockworkpi/warehouse/master/index.json","type":"source"}
] ]
self._MyStack.Push(repos) self._MyStack.Push(repos)
def GObjectUpdateProcessInterval(self): def GObjectUpdateProcessInterval(self):
ret = True ret = True
@ -672,10 +673,7 @@ class GameStorePage(Page):
self._MyList.append(li) self._MyList.append(li)
if self._PsIndex > len(self._MyList) - 1: self.RefreshPsIndex()
self._PsIndex = len(self._MyList) - 1
if self._PsIndex < 0:
self._PsIndex = 0
def Init(self): def Init(self):
@ -725,7 +723,7 @@ class GameStorePage(Page):
self._PreviewPage = ImageDownloadProcessPage() self._PreviewPage = ImageDownloadProcessPage()
self._PreviewPage._Screen = self._Screen self._PreviewPage._Screen = self._Screen
self._PreviewPage._Name = "preview" self._PreviewPage._Name = "Preview"
self._PreviewPage.Init() self._PreviewPage.Init()
self._LoadHousePage = LoadHousePage() self._LoadHousePage = LoadHousePage()
@ -838,47 +836,46 @@ class GameStorePage(Page):
print("cur_li._Value",cur_li._Value) print("cur_li._Value",cur_li._Value)
if cur_li._Value["type"] == "source" or cur_li._Value["type"] == "dir": if cur_li._Value["type"] == "source" or cur_li._Value["type"] == "dir":
remote_file_url = cur_li._Value["file"] remote_file_url = cur_li._Value["file"]
menu_file = remote_file_url.split("raw.githubusercontent.com")[1] #assume master branch menu_file = remote_file_url.split("raw.githubusercontent.com")[1] #assume master branch
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file ) local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
print(local_menu_file) print(local_menu_file)
if FileExists( local_menu_file ) == False: if FileExists( local_menu_file ) == False:
self.LoadHouse() self.LoadHouse()
else: else:
#read the local_menu_file, push into stack,display menu #read the local_menu_file, push into stack,display menu
self._Downloading = None self._Downloading = None
try: try:
with open(local_menu_file) as json_file: with open(local_menu_file) as json_file:
local_menu_json = json.load(json_file) local_menu_json = json.load(json_file)
print(local_menu_json) print(local_menu_json)
self._MyStack.Push(local_menu_json["list"]) self._MyStack.Push(local_menu_json["list"])
self.SyncList() self.SyncList()
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
except Exception as ex: except Exception as ex:
print(ex) print(ex)
self._Screen._MsgBox.SetText("Open house failed ") self._Screen._MsgBox.SetText("Open house failed ")
self._Screen._MsgBox.Draw() self._Screen._MsgBox.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
elif cur_li._Value["type"] == "add_house": elif cur_li._Value["type"] == "add_house":
print("show keyboard to add ware house") print("show keyboard to add ware house")
self._Screen.PushCurPage() self._Screen.PushCurPage()
self._Screen.SetCurPage( self._Keyboard ) self._Screen.SetCurPage( self._Keyboard )
else: else:
#download the game probably #download the game probably
remote_file_url = cur_li._Value["file"] remote_file_url = cur_li._Value["file"]
menu_file = remote_file_url.split("raw.githubusercontent.com")[1] menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file ) local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
if FileExists( local_menu_file ) == False: if FileExists( local_menu_file ) == False:
gid,ret = config.RPC.urlDownloading(remote_file_url) gid,ret = config.RPC.urlDownloading(remote_file_url)
if ret == False: if ret == False:
gid = config.RPC.addUri( remote_file_url, options={"out": menu_file}) gid = config.RPC.addUri( remote_file_url, options={"out": menu_file})
self._Downloading = gid self._Downloading = gid
print("stack length ",self._MyStack.Length()) print("stack length ",self._MyStack.Length())
""" """
if self._MyStack.Length() > 1:## not on the top list page if self._MyStack.Length() > 1:## not on the top list page
@ -895,13 +892,12 @@ class GameStorePage(Page):
else: else:
print(config.RPC.tellStatus(gid,["status","totalLength","completedLength"])) print(config.RPC.tellStatus(gid,["status","totalLength","completedLength"]))
self._Screen._MsgBox.SetText("Getting the game now") self._Screen._MsgBox.SetText("Getting the game now")
self._Screen._MsgBox.Draw() self._Screen._MsgBox.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
pygame.time.delay(800)
self._Screen._TitleBar.Redraw()
pygame.time.delay(800)
self._Screen._TitleBar.Redraw()
else: else:
print("file downloaded")# maybe check it if is installed,then execute it print("file downloaded")# maybe check it if is installed,then execute it
@ -1005,7 +1001,6 @@ class GameStorePage(Page):
self.SyncList() self.SyncList()
def OnReturnBackCb(self): def OnReturnBackCb(self):
if self._MyStack.Length() == 1: if self._MyStack.Length() == 1:
self._FootMsg[2] = "Remove" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "Update" self._FootMsg[1] = "Update"
@ -1014,6 +1009,8 @@ class GameStorePage(Page):
self._FootMsg[1] = "Preview" self._FootMsg[1] = "Preview"
self.SyncList() self.SyncList()
self.RestoreScrolled()
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
@ -1022,6 +1019,34 @@ class GameStorePage(Page):
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
""" """
def ScrollDown(self):
if len(self._MyList) == 0:
return
self._PsIndex += 1
if self._PsIndex >= len(self._MyList):
self._PsIndex = len(self._MyList)-1
cur_li = self._MyList[self._PsIndex]
if cur_li._PosY+cur_li._Height > self._Height:
for i in range(0, len(self._MyList)):
self._MyList[i]._PosY -= self._MyList[i]._Height
self._Scrolled_cnt -= self._MyList[i]._Height
def ScrollUp(self):
if len(self._MyList) == 0:
return
self._PsIndex -= 1
if self._PsIndex < 0:
self._PsIndex = 0
cur_li = self._MyList[self._PsIndex]
if cur_li._PosY < 0:
for i in range(0, len(self._MyList)):
self._MyList[i]._PosY += self._MyList[i]._Height
self._Scrolled_cnt += self._MyList[i]._Height
def KeyDown(self,event): def KeyDown(self,event):
if IsKeyMenuOrB(event.key): if IsKeyMenuOrB(event.key):
@ -1094,11 +1119,15 @@ class GameStorePage(Page):
self.ScrollUp() self.ScrollUp()
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
if event.key == CurKeys["Down"]: if event.key == CurKeys["Down"]:
self.ScrollDown() self.ScrollDown()
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
def RestoreScrolled(self):
for i in range(0, len(self._MyList)):
self._MyList[i]._PosY += self._Scrolled_cnt
def Draw(self): def Draw(self):