add yes_cancel_confirm_page.py

update aria2.conf,keep and auto continue the donwloading tasks
try to show downloading status in the title_bar
This commit is contained in:
cuu 2019-12-07 00:58:40 +08:00
parent 3371393733
commit b725a86b9e
6 changed files with 172 additions and 18 deletions

View File

@ -24,7 +24,7 @@ from UI.skin_manager import MySkinManager
from UI.lang_manager import MyLangManager from UI.lang_manager import MyLangManager
from UI.info_page_list_item import InfoPageListItem from UI.info_page_list_item import InfoPageListItem
from UI.info_page_selector import InfoPageSelector from UI.info_page_selector import InfoPageSelector
from UI.yes_cancel_confirm_page import YesCancelConfirmPage
import config import config
@ -201,7 +201,7 @@ class GameStorePage(Page):
_Scroller = None _Scroller = None
_InfoPage = None _InfoPage = None
_Downloading = None _Downloading = None
_aria2_db = "aria2tasks.db"
def __init__(self): def __init__(self):
Page.__init__(self) Page.__init__(self)
self._Icons = {} self._Icons = {}
@ -214,7 +214,7 @@ class GameStorePage(Page):
def SyncSqlite(self): def SyncSqlite(self):
try: try:
conn = sqlite3.connect("aria2tasks.db") conn = sqlite3.connect(self._aria2_db)
conn.row_factory = dict_factory conn.row_factory = dict_factory
c = conn.cursor() c = conn.cursor()
ret = c.execute("SELECT * FROM tasks").fetchall() ret = c.execute("SELECT * FROM tasks").fetchall()
@ -289,8 +289,36 @@ class GameStorePage(Page):
self._Scroller._PosX = self._Width - 10 self._Scroller._PosX = self._Width - 10
self._Scroller._PosY = 2 self._Scroller._PosY = 2
self._Scroller.Init() self._Scroller.Init()
self._Scroller.SetCanvasHWND(self._HWND) self._Scroller.SetCanvasHWND(self._HWND)
self._remove_page = YesCancelConfirmPage()
self._remove_page._Screen = self._Screen
self._remove_page._StartOrA_Event = self.RemoveGame
self._remove_page._Name ="Are you sure?"
self._remove_page.Init()
def RemoveGame(self):
if self._PsIndex > len(self._MyList) -1:
return
cur_li = self._MyList[self._PsIndex]
#if cur_li._Active == True:
# return
print("Remove cur_li._Value",cur_li._Value)
if "gid" in cur_li._Value:
try:
conn = sqlite3.connect(self._aria2_db)
conn.row_factory = dict_factory
c = conn.cursor()
c.execute("DELETE FROM tasks WHERE gid = '%s'" % cur_li._Value["gid"])
conn.commit()
conn.close()
except Exception as ex:
print(ex)
def Click(self): def Click(self):
if self._PsIndex > len(self._MyList) -1: if self._PsIndex > len(self._MyList) -1:
return return
@ -372,11 +400,25 @@ class GameStorePage(Page):
self._PosY = 0 self._PosY = 0
self._DrawOnce = False self._DrawOnce = False
#sync #sync
print("OnLoadCb") print("OnLoadCb")
if self._MyStack.Length() == 1:
self._FootMsg[2] = "Remove"
else:
self._FootMsg[2] = "Up"
self.SyncList() self.SyncList()
def OnReturnBackCb(self): def OnReturnBackCb(self):
pass
if self._MyStack.Length() == 1:
self._FootMsg[2] = "Remove"
else:
self._FootMsg[2] = "Up"
self.SyncList()
self._Screen.Draw()
self._Screen.SwapAndShow()
""" """
self.ReturnToUpLevelPage() self.ReturnToUpLevelPage()
self._Screen.Draw() self._Screen.Draw()
@ -391,13 +433,35 @@ class GameStorePage(Page):
if IsKeyStartOrA(event.key): if IsKeyStartOrA(event.key):
self.Click() self.Click()
if self._MyStack.Length() == 1:
self._FootMsg[2] = "Remove"
else:
self._FootMsg[2] = "Up"
self._Screen.Draw()
self._Screen.SwapAndShow()
if event.key == CurKeys["X"]: if event.key == CurKeys["X"]:
print(self._MyStack.Length() ) #print(self._MyStack.Length() )
if self._MyStack.Length() == 1 and self._PsIndex > 0:
self._Screen.PushPage(self._remove_page)
self._remove_page._StartOrA_Event = self.RemoveGame
self._Screen.Draw()
self._Screen.SwapAndShow()
return
if self._MyStack.Length() > 1: if self._MyStack.Length() > 1:
self._MyStack.Pop() self._MyStack.Pop()
self.SyncList() if self._MyStack.Length() == 1:
self._Screen.Draw() self._FootMsg[2] = "Remove"
self._Screen.SwapAndShow() else:
self._FootMsg[2] = "Up"
self.SyncList()
self._Screen.Draw()
self._Screen.SwapAndShow()
if event.key == CurKeys["Up"]: if event.key == CurKeys["Up"]:
self.ScrollUp() self.ScrollUp()

View File

@ -9,3 +9,10 @@ daemon=true
allow-overwrite=true allow-overwrite=true
split=1 split=1
max-concurrent-downloads=100 max-concurrent-downloads=100
disk-cache=15M
timeout=600
retry-wait=30
max-tries=50
save-session-interval=10
disable-ipv6=true
save-session=/home/cpi/aria2download/aria.session.txt

View File

@ -62,13 +62,13 @@ class ConfirmPage(Page):
_BGWidth = 0 _BGWidth = 0
_BGHeight = 0 _BGHeight = 0
_Parent = None _Parent = None
def __init__(self): def __init__(self):
Page.__init__(self) Page.__init__(self)
self._Icons = {} self._Icons = {}
self._CanvasHWND = None self._CanvasHWND = None
self._MyList = [] self._MyList = []
def Reset(self): def Reset(self):
self._MyList[0].SetText(self._ConfirmText) self._MyList[0].SetText(self._ConfirmText)
self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width)/2 self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width)/2

View File

@ -20,7 +20,7 @@ from lang_manager import MyLangManager
from util_funcs import midRect,SwapAndShow from util_funcs import midRect,SwapAndShow
from skin_manager import MySkinManager from skin_manager import MySkinManager
from widget import Widget from widget import Widget
from config import Battery from config import Battery,RPC
from libs.roundrects import aa_round_rect from libs.roundrects import aa_round_rect

View File

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
import pygame
#UI lib
from UI.constants import RUNSYS
from UI.keys_def import CurKeys, IsKeyStartOrA, IsKeyMenuOrB
from UI.confirm_page import ConfirmPage
from UI.lang_manager import MyLangManager
from UI.skin_manager import MySkinManager
class YesCancelConfirmPage(ConfirmPage):
_ConfirmText = MyLangManager.Tr("Awaiting Input")
_FootMsg = ["Nav","","","Cancel","Yes"]
_StartOrA_Event = None
_Key_X_Event = None
_Key_Y_Event = None
def KeyDown(self,event):
if IsKeyMenuOrB(event.key):
self.ReturnToUpLevelPage()
self._Screen.Draw()
self._Screen.SwapAndShow()
if IsKeyStartOrA(event.key):
if self._StartOrA_Event != None:
if callable( self._StartOrA_Event):
self._StartOrA_Event()
self.ReturnToUpLevelPage()
if event.key == CurKeys["X"]:
if self._Key_X_Event != None:
if callable( self._Key_X_Event):
self._Key_X_Event()
self.ReturnToUpLevelPage()
if event.key == CurKeys["Y"]:
if self._Key_Y_Event != None:
if callable( self._Key_Y_Event):
self._Key_Y_Event()
self.ReturnToUpLevelPage()

View File

@ -1,3 +1,5 @@
import os
import platform
import sqlite3 import sqlite3
import json import json
@ -11,14 +13,51 @@ aria2_db = "aria2tasks.db"
rpc = Wsrpc('localhost',6800) rpc = Wsrpc('localhost',6800)
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
@misc.threaded @misc.threaded
def game_install_thread(): def game_install_thread(gid):
pass try:
conn = sqlite3.connect(aria2_db)
conn.row_factory = dict_factory
c = conn.cursor()
ret = c.execute("SELECT * FROM tasks WHERE gid='%s'" % gid ).fetchone()
print(ret)
remote_file_url = ret["file"]
menu_file = remote_file_url.split("master")[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
if os.path.exists(local_menu_file) == True and "arm" not in platform.machine():
gametype = ret["type"]
if gametype == "launcher":
#tar zxvf
_cmd = "tar zxvf '%s' -C %s" % (local_menu_file, "~/apps/Menu/21_Indie\ Games/")
print(_cmd)
os.system(_cmd)
if gametype == "pico8":
_cmd="cp -rf '%s' ~/.lexaloffle/pico-8/carts/" % local_menu_file
print(_cmd)
os.system(_cmd)
if gametype == "tic80":
_cmd = "cp -rf '%s' ~/games/TIC-80/" % local_menu_file
print(_cmd)
os.system(_cmd)
conn.close()
except Exception as ex:
print("Sqlite3 error: ",ex)
def on_message(ws, message): def on_message(ws, message):
global rpc global rpc
print("got message") print("got message ",message)
print(message)
#decode json #decode json
#lookup in the sqlite db ,update the status[error,complete], #lookup in the sqlite db ,update the status[error,complete],
#uncompress the game into destnation folder in the game_install_thread #uncompress the game into destnation folder in the game_install_thread
@ -32,7 +71,7 @@ def on_message(ws, message):
gid = aria2_noti["params"][0]["gid"] gid = aria2_noti["params"][0]["gid"]
msg = rpc.tellStatus(gid) msg = rpc.tellStatus(gid)
ws.send(msg) ws.send(msg)
game_install_thread(gid)
def on_error(ws, error): def on_error(ws, error):
print(error) print(error)