mirror of
https://github.com/clockworkpi/launcher.git
synced 2025-12-13 02:08:50 +01:00
commit
a700ed7236
262
Menu/GameShell/10_Settings/Notification/__init__.py
Normal file
262
Menu/GameShell/10_Settings/Notification/__init__.py
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import ConfigParser
|
||||||
|
import socket
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
#import math
|
||||||
|
import commands
|
||||||
|
|
||||||
|
#from beeprint import pp
|
||||||
|
from libs.roundrects import aa_round_rect
|
||||||
|
#import gobject
|
||||||
|
#from wicd import misc
|
||||||
|
## 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.util_funcs import midRect,FileExists
|
||||||
|
from UI.keys_def import CurKeys
|
||||||
|
from UI.scroller import ListScroller
|
||||||
|
from UI.icon_pool import MyIconPool
|
||||||
|
from UI.icon_item import IconItem
|
||||||
|
from UI.multi_icon_item import MultiIconItem
|
||||||
|
|
||||||
|
from UI.multilabel import MultiLabel
|
||||||
|
from UI.info_page_list_item import InfoPageListItem
|
||||||
|
from UI.info_page_selector import InfoPageSelector
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationPage(Page):
|
||||||
|
_FootMsg = ["Nav.","","","Back","Toggle"]
|
||||||
|
_MyList = []
|
||||||
|
_ListFontObj = fonts["varela13"]
|
||||||
|
|
||||||
|
_AList = {}
|
||||||
|
|
||||||
|
_Scrolled = 0
|
||||||
|
|
||||||
|
_BGwidth = 320
|
||||||
|
_BGheight = 240-24-20
|
||||||
|
|
||||||
|
_DrawOnce = False
|
||||||
|
_Scroller = None
|
||||||
|
|
||||||
|
_EasingDur = 30
|
||||||
|
|
||||||
|
_GSNOTIFY_CFG="gsnotify/gsnotify.cfg"
|
||||||
|
_GSNOTIFY_SOCKET="/tmp/gsnotify.sock"
|
||||||
|
_Config =None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
Page.__init__(self)
|
||||||
|
self._Icons = {}
|
||||||
|
|
||||||
|
def ReadConfig(self,fname):
|
||||||
|
if FileExists(fname):
|
||||||
|
if self._Config == None:
|
||||||
|
self._Config = ConfigParser.ConfigParser()
|
||||||
|
self._Config.optionxform = str
|
||||||
|
|
||||||
|
self._Config.read(fname)
|
||||||
|
else:
|
||||||
|
print(fname, "not found")
|
||||||
|
|
||||||
|
def GenList(self):
|
||||||
|
if self._Config == None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._AList = {}
|
||||||
|
self._MyList = []
|
||||||
|
## map ini to self._AList
|
||||||
|
for i,v in enumerate(self._Config.items("Settings")):
|
||||||
|
self._AList[v[0]] = v[1] ## {'BGCOLOR': '#eab934', 'Enabled': 'False',...}
|
||||||
|
|
||||||
|
|
||||||
|
start_x = 10
|
||||||
|
start_y = 0
|
||||||
|
|
||||||
|
for i,v in enumerate( self._AList):
|
||||||
|
li = InfoPageListItem()
|
||||||
|
li._Parent = self
|
||||||
|
li._PosX = start_x
|
||||||
|
li._PosY = start_y + i*InfoPageListItem._Height
|
||||||
|
li._Width = Width-10
|
||||||
|
li._Fonts["normal"] = self._ListFontObj
|
||||||
|
li._Fonts["small"] = fonts["varela12"]
|
||||||
|
|
||||||
|
li.Init( v )
|
||||||
|
li._Flag = v
|
||||||
|
li.SetSmallText( self._AList[v] )
|
||||||
|
if v != "Enabled":
|
||||||
|
li._ReadOnly=True
|
||||||
|
|
||||||
|
self._MyList.append(li)
|
||||||
|
|
||||||
|
def Init(self):
|
||||||
|
if self._Screen != None:
|
||||||
|
if self._Screen._CanvasHWND != None and self._CanvasHWND == None:
|
||||||
|
self._CanvasHWND = self._Screen._CanvasHWND
|
||||||
|
|
||||||
|
self._PosX = self._Index*self._Screen._Width
|
||||||
|
self._Width = self._Screen._Width ## equal to screen width
|
||||||
|
self._Height = self._Screen._Height
|
||||||
|
|
||||||
|
ps = InfoPageSelector()
|
||||||
|
ps._PosX = 11
|
||||||
|
ps._Parent = self
|
||||||
|
ps._Width = self._Width-10
|
||||||
|
self._Ps = ps
|
||||||
|
self._PsIndex = 0
|
||||||
|
|
||||||
|
self.ReadConfig(self._GSNOTIFY_CFG)
|
||||||
|
|
||||||
|
self._Scroller = ListScroller()
|
||||||
|
self._Scroller._Parent = self
|
||||||
|
self._Scroller._PosX = 2
|
||||||
|
self._Scroller._PosY = 2
|
||||||
|
self._Scroller.Init()
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def Click(self):
|
||||||
|
if len(self._MyList) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
cur_li = self._MyList[self._PsIndex]
|
||||||
|
print("Click ",cur_li._Flag)
|
||||||
|
|
||||||
|
def SendMsgToUnixSocket(self,msg):
|
||||||
|
if FileExists(self._GSNOTIFY_SOCKET) == False:
|
||||||
|
print(self._GSNOTIFY_SOCKET," not existed")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = socket.socket(socket.AF_UNIX)
|
||||||
|
s.settimeout(1) # 1 second timeout
|
||||||
|
s.connect(self._GSNOTIFY_SOCKET)
|
||||||
|
s.send(msg)
|
||||||
|
data = s.recv(1024)
|
||||||
|
print("received: {}".format(data))
|
||||||
|
s.close()
|
||||||
|
except Exception as err:
|
||||||
|
print(err) ## print error ,but ignore it
|
||||||
|
|
||||||
|
|
||||||
|
def ToggleEnable(self):
|
||||||
|
print("ToggleEnable")
|
||||||
|
if self._Config == None:
|
||||||
|
return
|
||||||
|
|
||||||
|
e = self._Config.get("Settings","Enabled")
|
||||||
|
|
||||||
|
if e == "False":
|
||||||
|
self.SendMsgToUnixSocket("Enable")
|
||||||
|
else:
|
||||||
|
self.SendMsgToUnixSocket("Disable")
|
||||||
|
|
||||||
|
|
||||||
|
def OnLoadCb(self):
|
||||||
|
self._Scrolled = 0
|
||||||
|
self._PosY = 0
|
||||||
|
self._DrawOnce = False
|
||||||
|
self.GenList()
|
||||||
|
|
||||||
|
def OnReturnBackCb(self):
|
||||||
|
self.ReturnToUpLevelPage()
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
|
||||||
|
def KeyDown(self,event):
|
||||||
|
if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
|
||||||
|
self.ReturnToUpLevelPage()
|
||||||
|
self._Screen.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
|
||||||
|
if event.key == CurKeys["B"]:
|
||||||
|
self.ToggleEnable()
|
||||||
|
self._Screen._MsgBox.SetText("Applying...")
|
||||||
|
self._Screen._MsgBox.Draw()
|
||||||
|
self._Screen.SwapAndShow()
|
||||||
|
pygame.time.delay(1000)
|
||||||
|
self.ReadConfig(self._GSNOTIFY_CFG)
|
||||||
|
self.GenList()
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def Draw(self):
|
||||||
|
self.ClearCanvas()
|
||||||
|
self._Ps.Draw()
|
||||||
|
|
||||||
|
if len(self._MyList) > 0:
|
||||||
|
for i in self._MyList:
|
||||||
|
i.Draw()
|
||||||
|
|
||||||
|
self._Scroller.UpdateSize( len(self._MyList)*InfoPageListItem._Height,
|
||||||
|
self._PsIndex*InfoPageListItem._Height)
|
||||||
|
self._Scroller.Draw()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class APIOBJ(object):
|
||||||
|
|
||||||
|
_Page = None
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
def Init(self,main_screen):
|
||||||
|
self._Page = NotificationPage()
|
||||||
|
self._Page._Screen = main_screen
|
||||||
|
self._Page._Name ="Notify"
|
||||||
|
self._Page.Init()
|
||||||
|
|
||||||
|
def API(self,main_screen):
|
||||||
|
if main_screen !=None:
|
||||||
|
main_screen.PushPage(self._Page)
|
||||||
|
main_screen.Draw()
|
||||||
|
main_screen.SwapAndShow()
|
||||||
|
|
||||||
|
OBJ = APIOBJ()
|
||||||
|
def Init(main_screen):
|
||||||
|
OBJ.Init(main_screen)
|
||||||
|
def API(main_screen):
|
||||||
|
OBJ.API(main_screen)
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ from UI.confirm_page import ConfirmPage
|
|||||||
from UI.skin_manager import SkinManager
|
from UI.skin_manager import SkinManager
|
||||||
|
|
||||||
from UI.info_page_list_item import InfoPageListItem
|
from UI.info_page_list_item import InfoPageListItem
|
||||||
|
from UI.info_page_selector import InfoPageSelector
|
||||||
|
|
||||||
from net_item import NetItem
|
from net_item import NetItem
|
||||||
|
|
||||||
@ -55,32 +56,6 @@ class WifiDisconnectConfirmPage(ConfirmPage):
|
|||||||
|
|
||||||
self.Reset()
|
self.Reset()
|
||||||
|
|
||||||
class WifiInfoPageSelector(PageSelector):
|
|
||||||
_BackgroundColor = SkinManager().GiveColor('Front')
|
|
||||||
|
|
||||||
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 = 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 WifiInfoPage(Page):
|
class WifiInfoPage(Page):
|
||||||
_FootMsg = ["Nav.","Disconnect","","Back",""]
|
_FootMsg = ["Nav.","Disconnect","","Back",""]
|
||||||
_MyList = []
|
_MyList = []
|
||||||
@ -138,8 +113,9 @@ class WifiInfoPage(Page):
|
|||||||
self._Width = self._Screen._Width ## equal to screen width
|
self._Width = self._Screen._Width ## equal to screen width
|
||||||
self._Height = self._Screen._Height
|
self._Height = self._Screen._Height
|
||||||
|
|
||||||
ps = WifiInfoPageSelector()
|
ps = InfoPageSelector()
|
||||||
ps._Parent = self
|
ps._Parent = self
|
||||||
|
ps._PosX = 2
|
||||||
self._Ps = ps
|
self._Ps = ps
|
||||||
self._PsIndex = 0
|
self._PsIndex = 0
|
||||||
|
|
||||||
|
|||||||
@ -85,6 +85,7 @@ class ListPage(Page):
|
|||||||
["","Brightness","BackLight Brightness"],
|
["","Brightness","BackLight Brightness"],
|
||||||
["","Storage",""],
|
["","Storage",""],
|
||||||
["","Time","Timezone"],
|
["","Time","Timezone"],
|
||||||
|
["","Notification","Notification"],
|
||||||
["","Update", ""],
|
["","Update", ""],
|
||||||
["","About", "About"],
|
["","About", "About"],
|
||||||
["","PowerOFF","Power off"],
|
["","PowerOFF","Power off"],
|
||||||
|
|||||||
@ -15,6 +15,7 @@ class InfoPageListItem(object):
|
|||||||
_Fonts = {}
|
_Fonts = {}
|
||||||
|
|
||||||
_LinkObj = None
|
_LinkObj = None
|
||||||
|
_ReadOnly = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._Labels = {}
|
self._Labels = {}
|
||||||
@ -41,6 +42,12 @@ class InfoPageListItem(object):
|
|||||||
self._Labels["Text"] = l
|
self._Labels["Text"] = l
|
||||||
|
|
||||||
def Draw(self):
|
def Draw(self):
|
||||||
|
if self._ReadOnly == True:
|
||||||
|
self._Labels["Text"].SetColor(SkinManager().GiveColor("ReadOnlyText"))
|
||||||
|
else:
|
||||||
|
self._Labels["Text"].SetColor(SkinManager().GiveColor("Text"))
|
||||||
|
|
||||||
|
|
||||||
self._Labels["Text"]._PosX = self._Labels["Text"]._PosX + self._PosX
|
self._Labels["Text"]._PosX = self._Labels["Text"]._PosX + self._PosX
|
||||||
self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
|
self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
|
||||||
self._Labels["Text"].Draw()
|
self._Labels["Text"].Draw()
|
||||||
|
|||||||
32
sys.py/UI/info_page_selector.py
Normal file
32
sys.py/UI/info_page_selector.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
from libs.roundrects import aa_round_rect
|
||||||
|
## local UI import
|
||||||
|
from UI.constants import Width,Height
|
||||||
|
from UI.page import Page,PageSelector
|
||||||
|
from UI.skin_manager import SkinManager
|
||||||
|
|
||||||
|
class InfoPageSelector(PageSelector):
|
||||||
|
_BackgroundColor = SkinManager().GiveColor('Front')
|
||||||
|
|
||||||
|
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):
|
||||||
|
y = self._Parent._MyList[idx]._PosY+1
|
||||||
|
h = self._Parent._MyList[idx]._Height -3
|
||||||
|
|
||||||
|
self._PosY = y
|
||||||
|
self._Height = h
|
||||||
|
|
||||||
|
aa_round_rect(self._Parent._CanvasHWND,
|
||||||
|
(self._PosX,self._PosY,self._Width-4,self._Height),self._BackgroundColor,4,0,self._BackgroundColor)
|
||||||
@ -38,6 +38,7 @@ class SkinManager(object):
|
|||||||
Colors = {}
|
Colors = {}
|
||||||
Colors["High"] = pygame.Color(51, 166, 255)
|
Colors["High"] = pygame.Color(51, 166, 255)
|
||||||
Colors["Text"] = pygame.Color(83, 83, 83)
|
Colors["Text"] = pygame.Color(83, 83, 83)
|
||||||
|
Colors["ReadOnlyText"] = pygame.Color(130,130,130)
|
||||||
Colors["Front"] = pygame.Color(131, 199, 219)
|
Colors["Front"] = pygame.Color(131, 199, 219)
|
||||||
Colors["URL"] = pygame.Color(51, 166, 255)
|
Colors["URL"] = pygame.Color(51, 166, 255)
|
||||||
Colors["Line"] = pygame.Color(169, 169, 169)
|
Colors["Line"] = pygame.Color(169, 169, 169)
|
||||||
|
|||||||
Binary file not shown.
@ -402,6 +402,8 @@ def gobject_pygame_event_timer(main_screen):
|
|||||||
|
|
||||||
@misc.threaded
|
@misc.threaded
|
||||||
def socket_thread(main_screen):
|
def socket_thread(main_screen):
|
||||||
|
global everytime_keydown
|
||||||
|
|
||||||
socket_path = "/tmp/gameshell"
|
socket_path = "/tmp/gameshell"
|
||||||
if os.path.exists(socket_path):
|
if os.path.exists(socket_path):
|
||||||
os.remove(socket_path)
|
os.remove(socket_path)
|
||||||
@ -431,7 +433,12 @@ def socket_thread(main_screen):
|
|||||||
|
|
||||||
gobject_main_loop.quit()
|
gobject_main_loop.quit()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
if tokens[0].lower() == "keydown": ## simulate keydown event
|
||||||
|
everytime_keydown = time.time()
|
||||||
|
if RestoreLastBackLightBrightness(main_screen) == False:
|
||||||
|
print("RestoreLastBackLightBrightness unix socket false")
|
||||||
|
|
||||||
if tokens[0].lower() == "poweroff":
|
if tokens[0].lower() == "poweroff":
|
||||||
escevent = pygame.event.Event(pygame.KEYDOWN,{'scancode':9,'key': 27, 'unicode': u'\x1b', 'mod': 0})
|
escevent = pygame.event.Event(pygame.KEYDOWN,{'scancode':9,'key': 27, 'unicode': u'\x1b', 'mod': 0})
|
||||||
for i in range(0,5):
|
for i in range(0,5):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user