preview game alpha

This commit is contained in:
cuu 2019-12-16 07:41:33 +00:00
parent 128e37e06a
commit 5db3db2ee3

View File

@ -9,6 +9,7 @@ import gobject
import sqlite3 import sqlite3
#from beeprint import pp #from beeprint import pp
from libs.roundrects import aa_round_rect from libs.roundrects import aa_round_rect
from shutil import copyfile
## local UI import ## local UI import
from UI.constants import Width,Height,ICON_TYPES,RESTARTUI from UI.constants import Width,Height,ICON_TYPES,RESTARTUI
@ -61,10 +62,11 @@ class ImageDownloadProcessPage(Page):
_DownloaderTimer = -1 _DownloaderTimer = -1
_Value = 0 _Value = 0
_URL = None _URL = None
_ListFontObj = MyLangManager.TrFont("varela13")
_URLColor = MySkinManager.GiveColor('URL') _URLColor = MySkinManager.GiveColor('URL')
_TextColor = MySkinManager.GiveColor('Text') _TextColor = MySkinManager.GiveColor('Text')
_img = None _img = None
_Downloader=None
def __init__(self): def __init__(self):
Page.__init__(self) Page.__init__(self)
@ -77,34 +79,68 @@ class ImageDownloadProcessPage(Page):
self._Height = self._Screen._Height self._Height = self._Screen._Height
self._CanvasHWND = self._Screen._CanvasHWND self._CanvasHWND = self._Screen._CanvasHWND
self._LoadingLabel = Label()
self._LoadingLabel.SetCanvasHWND(self._CanvasHWND)
self._LoadingLabel.Init("Loading",self._ListFontObj)
self._LoadingLabel.SetColor(self._TextColor )
def OnLoadCb(self): def OnLoadCb(self):
if self._URL is None: if self._URL is None:
return return
self._img = None
self.ClearCanvas() self.ClearCanvas()
self._Screen.Draw()
self._Screen.SwapAndShow()
print(self._URL ) filename = self._URL.split("/")[-1].strip()
local_dir = self._URL.split("raw.githubusercontent.com")
if len(local_dir) >1:
menu_file = local_dir[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
if FileExists(local_menu_file):
self._img = pygame.image.load(local_menu_file).convert_alpha()
self._Screen.Draw()
self._Screen.SwapAndShow()
else:
self._Downloader = Download(self._URL,"/tmp",None) self._Downloader = Download(self._URL,"/tmp",None)
self._Downloader.start() self._Downloader.start()
self._DownloaderTimer = gobject.timeout_add(300, self.GObjectUpdateProcessInterval) self._DownloaderTimer = gobject.timeout_add(300, self.GObjectUpdateProcessInterval)
def GObjectUpdateProcessInterval(self): def GObjectUpdateProcessInterval(self):
ret = True
if self._Screen.CurPage() == self: if self._Screen.CurPage() == self:
if self._Downloader._stop == True: if self._Downloader._stop == True:
return False ret = False
filename = self._Downloader.get_dest() dst_filename = self._Downloader.get_dest()
#print("dest ",filename) if self._Downloader.isFinished():
if FileExists(filename): if self._Downloader.isSuccessful():
filename = self._URL.split("/")[-1].strip()
local_dir = self._URL.split("raw.githubusercontent.com")
menu_file = local_dir[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
dl_file = os.path.join("/tmp",filename)
if not os.path.exists(os.path.dirname(local_menu_file)):
os.makedirs(os.path.dirname(local_menu_file))
copyfile(dl_file, local_menu_file)
ret = False
#print("dest ",dst_filename)
if FileExists(dst_filename):
try: try:
self._img = pygame.image.load(filename).convert_alpha() #print("load and draw")
self._img = pygame.image.load(dst_filename).convert_alpha()
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
except Exception as ex: except Exception as ex:
print(ex) print(ex)
return True return ret
else: else:
return False return False
@ -127,10 +163,13 @@ class ImageDownloadProcessPage(Page):
def Draw(self): def Draw(self):
self.ClearCanvas() self.ClearCanvas()
self._LoadingLabel.NewCoord( (Width-self._LoadingLabel._Width)/2,(Height-44)/2)
self._LoadingLabel.Draw()
if self._img is not None: if self._img is not None:
self._CanvasHWND.blit(self._img,midRect(160, self._CanvasHWND.blit(self._img,midRect(Width/2,
120, (Height-44)/2,
pygame.Surface.get_width(self._img),pygame.Surface.get_height(self._img),Width,Height)) pygame.Surface.get_width(self._img),pygame.Surface.get_height(self._img),Width,Height-44))
class Aria2DownloadProcessPage(Page): class Aria2DownloadProcessPage(Page):