mirror of
https://github.com/clockworkpi/launcher.git
synced 2025-12-15 11:18:51 +01:00
Corrected broken Time binary file
This commit is contained in:
parent
5dd47f599b
commit
7e585ccfe4
19
Menu/GameShell/10_Settings/Time/__init__.py
Normal file
19
Menu/GameShell/10_Settings/Time/__init__.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
## local UI import
|
||||||
|
import pages
|
||||||
|
import myvars
|
||||||
|
|
||||||
|
def Init(main_screen):
|
||||||
|
pages.InitTimezoneListPage(main_screen)
|
||||||
|
|
||||||
|
def API(main_screen):
|
||||||
|
if main_screen !=None:
|
||||||
|
main_screen.PushCurPage()
|
||||||
|
main_screen.SetCurPage(myvars.TimezoneListPage)
|
||||||
|
main_screen.Draw()
|
||||||
|
main_screen.SwapAndShow()
|
||||||
|
|
||||||
|
|
||||||
112
Menu/GameShell/10_Settings/Time/list_item.py
Normal file
112
Menu/GameShell/10_Settings/Time/list_item.py
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
from libs.roundrects import aa_round_rect
|
||||||
|
|
||||||
|
## local UI import
|
||||||
|
from UI.constants import ICON_TYPES
|
||||||
|
from UI.page import Page
|
||||||
|
from UI.label import Label
|
||||||
|
from UI.fonts import fonts
|
||||||
|
from UI.icon_item import IconItem
|
||||||
|
from UI.util_funcs import midRect
|
||||||
|
|
||||||
|
# a item for List
|
||||||
|
# - - - - - - - - - - - --
|
||||||
|
# | Icon Text..... > |
|
||||||
|
# ------------------------
|
||||||
|
|
||||||
|
import myvars # icons_path
|
||||||
|
|
||||||
|
class ListItemIcon(IconItem):
|
||||||
|
|
||||||
|
_CanvasHWND = None
|
||||||
|
_Parent = None
|
||||||
|
_Width = 18
|
||||||
|
_Height = 18
|
||||||
|
|
||||||
|
def Draw(self):
|
||||||
|
self._CanvasHWND.blit(self._ImgSurf,(self._PosX,self._PosY+(self._Parent._Height-self._Height)/2,self._Width,self._Height))
|
||||||
|
|
||||||
|
|
||||||
|
class ListItemLabel(Label):
|
||||||
|
|
||||||
|
_ActiveColor = pygame.Color(175,90,0)
|
||||||
|
_Active = False
|
||||||
|
def Draw(self):
|
||||||
|
|
||||||
|
self._FontObj.set_bold(self._Active)
|
||||||
|
|
||||||
|
my_text = self._FontObj.render( self._Text,True,self._Color)
|
||||||
|
self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))
|
||||||
|
|
||||||
|
|
||||||
|
class ListItem(object):
|
||||||
|
_PosX = 0
|
||||||
|
_PosY = 0
|
||||||
|
_Width = 0
|
||||||
|
_Height = 30
|
||||||
|
|
||||||
|
_Labels = {}
|
||||||
|
_Icons = {}
|
||||||
|
_Fonts = {}
|
||||||
|
_MyType = ICON_TYPES["EXE"]
|
||||||
|
_LinkObj = None
|
||||||
|
_Path = ""
|
||||||
|
_Active = False
|
||||||
|
_Parent = None
|
||||||
|
|
||||||
|
_Text = ""
|
||||||
|
def __init__(self):
|
||||||
|
self._Labels = {}
|
||||||
|
self._Icons = {}
|
||||||
|
self._Fonts = {}
|
||||||
|
|
||||||
|
|
||||||
|
def Init(self,text):
|
||||||
|
|
||||||
|
self._Text = text
|
||||||
|
|
||||||
|
l = ListItemLabel()
|
||||||
|
l._PosX = 22
|
||||||
|
l.SetCanvasHWND(self._Parent._CanvasHWND)
|
||||||
|
|
||||||
|
if self._MyType == ICON_TYPES["DIR"]:
|
||||||
|
l.Init(text,self._Fonts["normal"])
|
||||||
|
self._Path = text
|
||||||
|
else:
|
||||||
|
l.Init(text,self._Fonts["normal"])
|
||||||
|
self._Path = text
|
||||||
|
|
||||||
|
|
||||||
|
self._Labels["Text"] = l
|
||||||
|
|
||||||
|
|
||||||
|
def NewCoord(self,x,y):
|
||||||
|
self._PosX = x
|
||||||
|
self._PosY = y
|
||||||
|
|
||||||
|
def Draw(self):
|
||||||
|
|
||||||
|
if self._MyType == ICON_TYPES["DIR"] and self._Path != "[..]":
|
||||||
|
self._Parent._Icons["sys"]._IconIndex = 0
|
||||||
|
self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
|
||||||
|
self._Parent._Icons["sys"].Draw()
|
||||||
|
|
||||||
|
if self._MyType == ICON_TYPES["FILE"]:
|
||||||
|
self._Parent._Icons["sys"]._IconIndex = 1
|
||||||
|
self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
|
||||||
|
self._Parent._Icons["sys"].Draw()
|
||||||
|
|
||||||
|
if self._Active == True:
|
||||||
|
self._Labels["Text"]._Active = True
|
||||||
|
else:
|
||||||
|
self._Labels["Text"]._Active = False
|
||||||
|
|
||||||
|
|
||||||
|
self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
|
||||||
|
|
||||||
|
pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
|
||||||
|
|
||||||
|
self._Labels["Text"].Draw()
|
||||||
|
|
||||||
16
Menu/GameShell/10_Settings/Time/logger.py
Normal file
16
Menu/GameShell/10_Settings/Time/logger.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import logzero
|
||||||
|
|
||||||
|
def get_logger():
|
||||||
|
# Set a custom formatter
|
||||||
|
log_format = '%(color)s[%(levelname)1.1s ' \
|
||||||
|
'%(asctime)s.%(msecs)03d %(module)s:%(lineno)d]' \
|
||||||
|
'%(end_color)s %(message)s'
|
||||||
|
formatter = logzero.LogFormatter(fmt=log_format)
|
||||||
|
logzero.setup_default_logger(formatter=formatter)
|
||||||
|
|
||||||
|
logzero.logfile(
|
||||||
|
'logzero.log',
|
||||||
|
maxBytes=1e6,
|
||||||
|
backupCount=3
|
||||||
|
)
|
||||||
|
return logzero.logger
|
||||||
5
Menu/GameShell/10_Settings/Time/myvars.py
Normal file
5
Menu/GameShell/10_Settings/Time/myvars.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
TimePage = None
|
||||||
|
TimezoneListPage = None
|
||||||
|
|
||||||
13
Menu/GameShell/10_Settings/Time/pages.py
Normal file
13
Menu/GameShell/10_Settings/Time/pages.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from timezone_lib_list_page import TimezoneListPage
|
||||||
|
import myvars
|
||||||
|
|
||||||
|
def InitTimePage(main_screen):
|
||||||
|
myvars.TimePage = None
|
||||||
|
|
||||||
|
def InitTimezoneListPage(main_screen):
|
||||||
|
myvars.TimezoneListPage = TimezoneListPage()
|
||||||
|
myvars.TimezoneListPage._Screen = main_screen
|
||||||
|
myvars.TimezoneListPage._Name = "Timezone Selection"
|
||||||
|
myvars.TimezoneListPage.Init()
|
||||||
333
Menu/GameShell/10_Settings/Time/timezone_lib_list_page.py
Normal file
333
Menu/GameShell/10_Settings/Time/timezone_lib_list_page.py
Normal file
@ -0,0 +1,333 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
from libs.roundrects import aa_round_rect
|
||||||
|
|
||||||
|
## local UI import
|
||||||
|
from UI.constants import Width,Height,ICON_TYPES
|
||||||
|
from UI.page import Page,PageSelector
|
||||||
|
from UI.label import Label
|
||||||
|
from UI.fonts import fonts
|
||||||
|
from UI.icon_item import IconItem
|
||||||
|
from UI.util_funcs import midRect
|
||||||
|
from UI.keys_def import CurKeys
|
||||||
|
from UI.multi_icon_item import MultiIconItem
|
||||||
|
from UI.icon_pool import MyIconPool
|
||||||
|
from UI.scroller import ListScroller
|
||||||
|
|
||||||
|
from list_item import ListItem
|
||||||
|
|
||||||
|
|
||||||
|
import myvars
|
||||||
|
|
||||||
|
|
||||||
|
class TimeLibStack:
|
||||||
|
def __init__(self):
|
||||||
|
self.stack = list()
|
||||||
|
|
||||||
|
def Push(self,data):
|
||||||
|
if data not in self.stack:
|
||||||
|
self.stack.append(data)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def Pop(self):
|
||||||
|
if len(self.stack)<=0:
|
||||||
|
return None,False
|
||||||
|
return self.stack.pop(),True
|
||||||
|
|
||||||
|
def Last(self):
|
||||||
|
idx = len(self.stack) -1
|
||||||
|
if idx < 0:
|
||||||
|
return "/usr/share/zoneinfo/posix"
|
||||||
|
else:
|
||||||
|
return self.stack[ idx ]
|
||||||
|
|
||||||
|
def Length(self):
|
||||||
|
return len(self.stack)
|
||||||
|
|
||||||
|
class ListPageSelector(PageSelector):
|
||||||
|
_BackgroundColor = pygame.Color(131,199,219)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._PosX = 0
|
||||||
|
self._PosY = 0
|
||||||
|
self._Height = 0
|
||||||
|
self._Width = Width
|
||||||
|
|
||||||
|
def AnimateDraw(self,x2,y2):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def Draw(self):
|
||||||
|
idx = self._Parent._PsIndex
|
||||||
|
|
||||||
|
if idx < len(self._Parent._MyList):
|
||||||
|
x = self._Parent._MyList[idx]._PosX+2
|
||||||
|
y = self._Parent._MyList[idx]._PosY+1
|
||||||
|
h = self._Parent._MyList[idx]._Height -3
|
||||||
|
|
||||||
|
self._PosX = x
|
||||||
|
self._PosY = y
|
||||||
|
self._Height = h
|
||||||
|
|
||||||
|
aa_round_rect(self._Parent._CanvasHWND,
|
||||||
|
(x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TimezoneListPage(Page):
|
||||||
|
|
||||||
|
_Icons = {}
|
||||||
|
_Selector=None
|
||||||
|
_FootMsg = ["Nav","","","Back","Select"]
|
||||||
|
_MyList = []
|
||||||
|
_SwapMyList = []
|
||||||
|
_ListFont = fonts["notosanscjk15"]
|
||||||
|
_MyStack = None
|
||||||
|
|
||||||
|
_Scroller = None
|
||||||
|
|
||||||
|
_BGpng = None
|
||||||
|
_BGwidth = 56
|
||||||
|
_BGheight = 70
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
Page.__init__(self)
|
||||||
|
self._Icons = {}
|
||||||
|
self._CanvasHWND = None
|
||||||
|
self._MyList = []
|
||||||
|
self._SwapMyList = []
|
||||||
|
self._MyStack = TimeLibStack()
|
||||||
|
|
||||||
|
def buildDirectoryList(self, path):
|
||||||
|
elements = [
|
||||||
|
{
|
||||||
|
'name': f,
|
||||||
|
'file_path': os.path.join(path, f),
|
||||||
|
'is_file': os.path.isfile(os.path.join(path, f))
|
||||||
|
}
|
||||||
|
for f in os.listdir(path)
|
||||||
|
]
|
||||||
|
return elements
|
||||||
|
|
||||||
|
def SyncList(self,path):
|
||||||
|
|
||||||
|
alist = self.buildDirectoryList(path)
|
||||||
|
if not alist:
|
||||||
|
print("buildDirectoryList empty")
|
||||||
|
return
|
||||||
|
|
||||||
|
self._MyList = []
|
||||||
|
self._SwapMyList = []
|
||||||
|
|
||||||
|
start_x = 0
|
||||||
|
start_y = 0
|
||||||
|
hasparent = 0
|
||||||
|
if self._MyStack.Length() > 0:
|
||||||
|
hasparent = 1
|
||||||
|
li = ListItem()
|
||||||
|
li._Parent = self
|
||||||
|
li._PosX = start_x
|
||||||
|
li._PosY = start_y
|
||||||
|
li._Width = Width
|
||||||
|
li._Fonts["normal"] = self._ListFont
|
||||||
|
li._MyType = ICON_TYPES["DIR"]
|
||||||
|
li.Init("[..]")
|
||||||
|
self._MyList.append(li)
|
||||||
|
|
||||||
|
for i,v in enumerate(sorted(alist)):
|
||||||
|
li = ListItem()
|
||||||
|
li._Parent = self
|
||||||
|
li._PosX = start_x
|
||||||
|
li._PosY = start_y + (i+hasparent)*ListItem._Height
|
||||||
|
li._Width = Width
|
||||||
|
li._Fonts["normal"] = self._ListFont
|
||||||
|
li._MyType = ICON_TYPES["FILE"]
|
||||||
|
|
||||||
|
if not v['is_file']:
|
||||||
|
li._MyType = ICON_TYPES["DIR"]
|
||||||
|
else:
|
||||||
|
li._MyType = ICON_TYPES["FILE"]
|
||||||
|
|
||||||
|
li.Init( v['name'] )
|
||||||
|
li._Path = v["file_path"]
|
||||||
|
|
||||||
|
|
||||||
|
self._MyList.append(li)
|
||||||
|
|
||||||
|
for i in self._MyList:
|
||||||
|
self._SwapMyList.append(i)
|
||||||
|
|
||||||
|
def Init(self):
|
||||||
|
self._PosX = self._Index * self._Screen._Width
|
||||||
|
self._Width = self._Screen._Width
|
||||||
|
self._Height = self._Screen._Height
|
||||||
|
|
||||||
|
self._CanvasHWND = self._Screen._CanvasHWND
|
||||||
|
|
||||||
|
ps = ListPageSelector()
|
||||||
|
ps._Parent = self
|
||||||
|
self._Ps = ps
|
||||||
|
self._PsIndex = 0
|
||||||
|
|
||||||
|
self.SyncList("/usr/share/zoneinfo/posix")
|
||||||
|
|
||||||
|
icon_for_list = MultiIconItem()
|
||||||
|
icon_for_list._ImgSurf = MyIconPool._Icons["sys"]
|
||||||
|
icon_for_list._MyType = ICON_TYPES["STAT"]
|
||||||
|
icon_for_list._Parent = self
|
||||||
|
|
||||||
|
icon_for_list.Adjust(0,0,18,18,0)
|
||||||
|
self._Icons["sys"] = icon_for_list
|
||||||
|
|
||||||
|
|
||||||
|
self._BGpng = IconItem()
|
||||||
|
self._BGpng._ImgSurf = MyIconPool._Icons["empty"]
|
||||||
|
self._BGpng._MyType = ICON_TYPES["STAT"]
|
||||||
|
self._BGpng._Parent = self
|
||||||
|
self._BGpng.AddLabel("No timezones found on system!", fonts["varela22"])
|
||||||
|
self._BGpng.SetLableColor(pygame.Color(204,204,204))
|
||||||
|
self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
|
||||||
|
|
||||||
|
|
||||||
|
self._Scroller = ListScroller()
|
||||||
|
self._Scroller._Parent = self
|
||||||
|
self._Scroller._PosX = self._Width - 10
|
||||||
|
self._Scroller._PosY = 2
|
||||||
|
self._Scroller.Init()
|
||||||
|
|
||||||
|
|
||||||
|
def ScrollUp(self,Step=1):
|
||||||
|
if len(self._MyList) == 0:
|
||||||
|
return
|
||||||
|
tmp = self._PsIndex
|
||||||
|
self._PsIndex -= Step
|
||||||
|
|
||||||
|
if self._PsIndex < 0:
|
||||||
|
self._PsIndex = 0
|
||||||
|
dy = tmp-self._PsIndex
|
||||||
|
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*dy
|
||||||
|
|
||||||
|
|
||||||
|
def ScrollDown(self,Step=1):
|
||||||
|
if len(self._MyList) == 0:
|
||||||
|
return
|
||||||
|
tmp = self._PsIndex
|
||||||
|
self._PsIndex +=Step
|
||||||
|
if self._PsIndex >= len(self._MyList):
|
||||||
|
self._PsIndex = len(self._MyList) -1
|
||||||
|
dy = self._PsIndex - tmp
|
||||||
|
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*dy
|
||||||
|
|
||||||
|
def Click(self):
|
||||||
|
if len(self._MyList) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
cur_li = self._MyList[self._PsIndex]
|
||||||
|
|
||||||
|
if cur_li._MyType == ICON_TYPES["DIR"]:
|
||||||
|
if cur_li._Path == "[..]":
|
||||||
|
self._MyStack.Pop()
|
||||||
|
self.SyncList( self._MyStack.Last() )
|
||||||
|
self._PsIndex = 0
|
||||||
|
else:
|
||||||
|
self._MyStack.Push( self._MyList[self._PsIndex]._Path )
|
||||||
|
self.SyncList( self._MyStack.Last() )
|
||||||
|
self._PsIndex = 0
|
||||||
|
|
||||||
|
if cur_li._MyType == ICON_TYPES["FILE"]: ## set the current timezone
|
||||||
|
subprocess.call(['sudo', 'cp', cur_li._Path, '/etc/localtime'])
|
||||||
|
#copyfile(cur_li._Path, '/etc/localtime')
|
||||||
|
print("add" , cur_li._Path)
|
||||||
|
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
|
||||||
|
def Rescan(self):
|
||||||
|
self.SyncList("/usr/share/zoneinfo/posix")
|
||||||
|
self._PsIndex = 0
|
||||||
|
|
||||||
|
def KeyDown(self,event):
|
||||||
|
|
||||||
|
if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
|
||||||
|
|
||||||
|
self.ReturnToUpLevelPage()
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
|
||||||
|
if event.key == CurKeys["Up"]:
|
||||||
|
self.ScrollUp()
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
if event.key == CurKeys["Down"]:
|
||||||
|
self.ScrollDown()
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
|
||||||
|
if event.key == CurKeys["Right"]:
|
||||||
|
self.ScrollDown(Step=5)
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
|
||||||
|
if event.key == CurKeys["Left"]:
|
||||||
|
self.ScrollUp(Step=5)
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
|
||||||
|
if event.key == CurKeys["Enter"]:
|
||||||
|
self.Click()
|
||||||
|
|
||||||
|
def Draw(self):
|
||||||
|
self.ClearCanvas()
|
||||||
|
|
||||||
|
if len(self._MyList) == 0:
|
||||||
|
self._BGpng.NewCoord(self._Width/2,self._Height/2)
|
||||||
|
self._BGpng.Draw()
|
||||||
|
return
|
||||||
|
|
||||||
|
else:
|
||||||
|
if len(self._MyList) * ListItem._Height > self._Height:
|
||||||
|
self._Ps._Width = self._Width - 11
|
||||||
|
|
||||||
|
self._Ps.Draw()
|
||||||
|
for i in self._MyList:
|
||||||
|
if False:
|
||||||
|
i._Active = True
|
||||||
|
else:
|
||||||
|
i._Active = False
|
||||||
|
|
||||||
|
if i._PosY > self._Height + self._Height/2:
|
||||||
|
break
|
||||||
|
|
||||||
|
if i._PosY < 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
i.Draw()
|
||||||
|
|
||||||
|
self._Scroller.UpdateSize( len(self._MyList)*ListItem._Height, self._PsIndex*ListItem._Height)
|
||||||
|
self._Scroller.Draw()
|
||||||
|
else:
|
||||||
|
self._Ps._Width = self._Width
|
||||||
|
self._Ps.Draw()
|
||||||
|
for i in self._MyList:
|
||||||
|
if False:
|
||||||
|
i._Active = True
|
||||||
|
else:
|
||||||
|
i._Active = False
|
||||||
|
|
||||||
|
if i._PosY > self._Height + self._Height/2:
|
||||||
|
break
|
||||||
|
|
||||||
|
if i._PosY < 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
i.Draw()
|
||||||
Loading…
x
Reference in New Issue
Block a user