mirror of
https://github.com/clockworkpi/launcher.git
synced 2025-12-13 18:28:50 +01:00
counter down screen
This commit is contained in:
parent
57edfccc44
commit
0f0e3563e0
111
sys.py/UI/counter_screen.py
Normal file
111
sys.py/UI/counter_screen.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
import gobject
|
||||||
|
import commands
|
||||||
|
## local package import
|
||||||
|
from constants import Width,Height
|
||||||
|
from label import Label
|
||||||
|
from fonts import fonts
|
||||||
|
from full_screen import FullScreen
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
class CounterScreen(FullScreen):
|
||||||
|
|
||||||
|
_CounterFont = fonts["varela120"]
|
||||||
|
_TextFont1 = fonts["varela15"]
|
||||||
|
_TextFont2 = fonts["varela12"]
|
||||||
|
|
||||||
|
_TopLabel = None
|
||||||
|
_BottomLabel = None
|
||||||
|
_NumberLabel = None
|
||||||
|
|
||||||
|
_BGColor = pygame.Color(0,0,0)
|
||||||
|
_FGColor = pygame.Color(255,255,255)
|
||||||
|
|
||||||
|
_Counting = False
|
||||||
|
_Number = 10
|
||||||
|
_GobjectIntervalId = -1
|
||||||
|
|
||||||
|
_inter_counter = 0
|
||||||
|
|
||||||
|
def GObjectInterval(self):
|
||||||
|
|
||||||
|
self._inter_counter+=1
|
||||||
|
if self._inter_counter >= 10:
|
||||||
|
self._Number-=1
|
||||||
|
print("sub Number %d " % self._Number)
|
||||||
|
self._inter_counter = 0
|
||||||
|
|
||||||
|
|
||||||
|
if self._inter_counter == 2:
|
||||||
|
commands.getstatusoutput("echo 0 > /proc/driver/led1")
|
||||||
|
#turn off
|
||||||
|
|
||||||
|
elif self._inter_counter == 7:
|
||||||
|
commands.getstatusoutput("echo 1 > /proc/driver/led1")
|
||||||
|
#turn on
|
||||||
|
|
||||||
|
if self._Number == 0:
|
||||||
|
self._Counting = False
|
||||||
|
|
||||||
|
print("do the real shutdown")
|
||||||
|
|
||||||
|
if config.CurKeySet != "PC":
|
||||||
|
cmdpath = "feh --bg-center gameshell/wallpaper/seeyou.png;"
|
||||||
|
cmdpath += "sleep 3;"
|
||||||
|
cmdpath += "sudo halt -p"
|
||||||
|
pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath))
|
||||||
|
|
||||||
|
self.Draw()
|
||||||
|
self.SwapAndShow()
|
||||||
|
|
||||||
|
return self._Counting
|
||||||
|
|
||||||
|
def StartCounter(self):
|
||||||
|
if self._Counting == True:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._Counting = True
|
||||||
|
|
||||||
|
self._GobjectIntervalId = gobject.timeout_add(100,self.GObjectInterval)
|
||||||
|
|
||||||
|
def StopCounter(self):
|
||||||
|
self._Counting = False
|
||||||
|
self._Number = 10
|
||||||
|
commands.getstatusoutput("echo 0 > /proc/driver/led1")
|
||||||
|
|
||||||
|
if self._GobjectIntervalId != -1:
|
||||||
|
gobject.source_remove(self._GobjectIntervalId)
|
||||||
|
self._GobjectIntervalId = -1
|
||||||
|
|
||||||
|
def Init(self):
|
||||||
|
self._CanvasHWND = pygame.Surface((self._Width,self._Height))
|
||||||
|
self._TopLabel = Label()
|
||||||
|
self._TopLabel.SetCanvasHWND(self._CanvasHWND)
|
||||||
|
self._TopLabel.Init("System shutdown in", self._TextFont1, self._FGColor)
|
||||||
|
|
||||||
|
self._BottomLabel = Label()
|
||||||
|
self._BottomLabel.SetCanvasHWND(self._CanvasHWND)
|
||||||
|
self._BottomLabel.Init("Press any key to stop countdown", self._TextFont2, self._FGColor)
|
||||||
|
|
||||||
|
self._NumberLabel = Label()
|
||||||
|
self._NumberLabel.SetCanvasHWND(self._CanvasHWND)
|
||||||
|
self._NumberLabel.Init(str(self._Number), self._CounterFont, self._FGColor)
|
||||||
|
|
||||||
|
def Draw(self):
|
||||||
|
self._CanvasHWND.fill( self._BGColor )
|
||||||
|
|
||||||
|
self._TopLabel.NewCoord(Width/2, 15)
|
||||||
|
self._TopLabel.DrawCenter()
|
||||||
|
|
||||||
|
self._BottomLabel.NewCoord(Width/2, Height-15)
|
||||||
|
self._BottomLabel.DrawCenter()
|
||||||
|
|
||||||
|
self._NumberLabel.NewCoord(Width/2,Height/2)
|
||||||
|
self._NumberLabel.SetText(str(self._Number))
|
||||||
|
self._NumberLabel.DrawCenter()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ fonts["varela27"] = pygame.font.Font(fonts_path["varela"],27)
|
|||||||
fonts["varela28"] = pygame.font.Font(fonts_path["varela"],28)
|
fonts["varela28"] = pygame.font.Font(fonts_path["varela"],28)
|
||||||
fonts["varela34"] = pygame.font.Font(fonts_path["varela"],34)
|
fonts["varela34"] = pygame.font.Font(fonts_path["varela"],34)
|
||||||
fonts["varela40"] = pygame.font.Font(fonts_path["varela"],40)
|
fonts["varela40"] = pygame.font.Font(fonts_path["varela"],40)
|
||||||
|
fonts["varela120"] = pygame.font.Font(fonts_path["varela"],120)
|
||||||
|
|
||||||
fonts["veramono25"] = pygame.font.Font(fonts_path["veramono"],25)
|
fonts["veramono25"] = pygame.font.Font(fonts_path["veramono"],25)
|
||||||
fonts["veramono24"] = pygame.font.Font(fonts_path["veramono"],24)
|
fonts["veramono24"] = pygame.font.Font(fonts_path["veramono"],24)
|
||||||
|
|||||||
38
sys.py/UI/full_screen.py
Normal file
38
sys.py/UI/full_screen.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
#from sys import exit
|
||||||
|
#import os
|
||||||
|
#import sys
|
||||||
|
|
||||||
|
#from libs import easing
|
||||||
|
#from datetime import datetime
|
||||||
|
|
||||||
|
#from beeprint import pp
|
||||||
|
|
||||||
|
## local package import
|
||||||
|
from constants import Width,Height
|
||||||
|
|
||||||
|
|
||||||
|
class FullScreen(object):
|
||||||
|
_PosX = 0
|
||||||
|
_PosY = 0
|
||||||
|
_Width = Width
|
||||||
|
_Height = Height
|
||||||
|
_CanvasHWND = None
|
||||||
|
_HWND = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def Init(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def SwapAndShow(self):
|
||||||
|
if self._HWND != None:
|
||||||
|
self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height))
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
def Draw(self):
|
||||||
|
pass
|
||||||
|
|
||||||
@ -4,6 +4,8 @@ import pygame
|
|||||||
|
|
||||||
#import base64
|
#import base64
|
||||||
#from beeprint import pp
|
#from beeprint import pp
|
||||||
|
from constants import Width,Height
|
||||||
|
from util_funcs import midRect
|
||||||
|
|
||||||
class Label:
|
class Label:
|
||||||
_PosX=0
|
_PosX=0
|
||||||
@ -50,6 +52,11 @@ class Label:
|
|||||||
def SetCanvasHWND(self,_canvashwnd):
|
def SetCanvasHWND(self,_canvashwnd):
|
||||||
self._CanvasHWND = _canvashwnd
|
self._CanvasHWND = _canvashwnd
|
||||||
|
|
||||||
|
def DrawCenter(self,bold=False):
|
||||||
|
self._FontObj.set_bold(bold) ## avoing same font tangling set_bold to others
|
||||||
|
my_text = self._FontObj.render( self._Text,True,self._Color)
|
||||||
|
self._CanvasHWND.blit(my_text,midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height))
|
||||||
|
|
||||||
def Draw(self,bold=False):
|
def Draw(self,bold=False):
|
||||||
self._FontObj.set_bold(bold) ## avoing same font tangling set_bold to others
|
self._FontObj.set_bold(bold) ## avoing same font tangling set_bold to others
|
||||||
my_text = self._FontObj.render( self._Text,True,self._Color)
|
my_text = self._FontObj.render( self._Text,True,self._Color)
|
||||||
|
|||||||
@ -26,6 +26,7 @@ from untitled_icon import UntitledIcon
|
|||||||
from Emulator import MyEmulator
|
from Emulator import MyEmulator
|
||||||
|
|
||||||
from skin_manager import SkinManager
|
from skin_manager import SkinManager
|
||||||
|
from counter_screen import CounterScreen
|
||||||
|
|
||||||
class MessageBox(Label):
|
class MessageBox(Label):
|
||||||
_Parent = None
|
_Parent = None
|
||||||
@ -135,7 +136,8 @@ class MainScreen(object):
|
|||||||
_MsgBoxFont = fonts["veramono20"]
|
_MsgBoxFont = fonts["veramono20"]
|
||||||
_IconFont = fonts["varela15"]
|
_IconFont = fonts["varela15"]
|
||||||
_SkinManager = None
|
_SkinManager = None
|
||||||
|
|
||||||
|
_CounterScreen = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._Pages = []
|
self._Pages = []
|
||||||
@ -149,6 +151,12 @@ class MainScreen(object):
|
|||||||
|
|
||||||
self._SkinManager = SkinManager()
|
self._SkinManager = SkinManager()
|
||||||
self._SkinManager.Init()
|
self._SkinManager.Init()
|
||||||
|
|
||||||
|
self._CounterScreen = CounterScreen()
|
||||||
|
self._CounterScreen._HWND = self._HWND
|
||||||
|
|
||||||
|
self._CounterScreen.Init()
|
||||||
|
|
||||||
|
|
||||||
def FartherPages(self):
|
def FartherPages(self):
|
||||||
self._PageMax = len(self._Pages)
|
self._PageMax = len(self._Pages)
|
||||||
@ -515,8 +523,9 @@ class MainScreen(object):
|
|||||||
self.SwapAndShow()
|
self.SwapAndShow()
|
||||||
|
|
||||||
if event.key == CurKeys["Space"]:
|
if event.key == CurKeys["Space"]:
|
||||||
self.Draw()
|
self._CounterScreen.Draw()
|
||||||
self.SwapAndShow()
|
self._CounterScreen.SwapAndShow()
|
||||||
|
self._CounterScreen.StartCounter()
|
||||||
|
|
||||||
## leave rest to Pages
|
## leave rest to Pages
|
||||||
current_page_key_down_cb = getattr(self._CurrentPage,"KeyDown",None)
|
current_page_key_down_cb = getattr(self._CurrentPage,"KeyDown",None)
|
||||||
|
|||||||
@ -61,12 +61,10 @@ class TitleBar:
|
|||||||
SwapAndShow()
|
SwapAndShow()
|
||||||
else:
|
else:
|
||||||
self._InLowBackLight+=1
|
self._InLowBackLight+=1
|
||||||
|
|
||||||
if self._InLowBackLight > 10:
|
if self._InLowBackLight > 10:
|
||||||
self.CheckBatteryStat()
|
self.CheckBatteryStat()
|
||||||
self.SyncSoundVolume()
|
self.SyncSoundVolume()
|
||||||
self.UpdateWifiStrength()
|
self.UpdateWifiStrength()
|
||||||
SwapAndShow()
|
|
||||||
self._InLowBackLight = 0
|
self._InLowBackLight = 0
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
CurKeySet = "GameShell" ## >>> PC or GameShell <<<
|
CurKeySet = "PC" ## >>> PC or GameShell <<<
|
||||||
|
|
||||||
DontLeave = False
|
DontLeave = False
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,12 @@ def gobject_loop():
|
|||||||
|
|
||||||
def RestoreLastBackLightBrightness(main_screen):
|
def RestoreLastBackLightBrightness(main_screen):
|
||||||
global last_brt,passout_time_stage
|
global last_brt,passout_time_stage
|
||||||
|
|
||||||
|
main_screen._CounterScreen.StopCounter()
|
||||||
|
|
||||||
|
passout_time_stage = 0
|
||||||
|
main_screen._TitleBar._InLowBackLight = -1
|
||||||
|
|
||||||
if last_brt == -1:
|
if last_brt == -1:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -96,10 +101,7 @@ def RestoreLastBackLightBrightness(main_screen):
|
|||||||
f.truncate()
|
f.truncate()
|
||||||
f.close()
|
f.close()
|
||||||
last_brt = -1
|
last_brt = -1
|
||||||
main_screen._TitleBar._InLowBackLight = -1
|
else:
|
||||||
passout_time_stage = 0
|
|
||||||
else:
|
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -159,14 +161,27 @@ def InspectionTeam(main_screen):
|
|||||||
everytime_keydown = cur_time
|
everytime_keydown = cur_time
|
||||||
|
|
||||||
elif cur_time - everytime_keydown > time_3 and passout_time_stage == 2:
|
elif cur_time - everytime_keydown > time_3 and passout_time_stage == 2:
|
||||||
print("Power Off now")
|
print("Power Off counting down")
|
||||||
|
|
||||||
if config.CurKeySet != "PC":
|
|
||||||
cmdpath = "sudo halt -p"
|
|
||||||
pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath))
|
|
||||||
|
|
||||||
passout_time_stage = 0
|
main_screen._CounterScreen.Draw()
|
||||||
everytime_keydown = cur_time
|
main_screen._CounterScreen.SwapAndShow()
|
||||||
|
main_screen._CounterScreen.StartCounter()
|
||||||
|
|
||||||
|
if main_screen._CounterScreen._Counting == True:
|
||||||
|
return True
|
||||||
|
|
||||||
|
try:
|
||||||
|
f = open(config.BackLight,"r+")
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
with f:
|
||||||
|
brt = last_brt
|
||||||
|
f.seek(0)
|
||||||
|
f.write(str(brt))
|
||||||
|
f.truncate()
|
||||||
|
f.close()
|
||||||
|
main_screen._TitleBar._InLowBackLight = 0
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -273,6 +288,7 @@ def event_process(event,main_screen):
|
|||||||
###########################################################
|
###########################################################
|
||||||
if event.key == pygame.K_ESCAPE:
|
if event.key == pygame.K_ESCAPE:
|
||||||
pygame.event.clear()
|
pygame.event.clear()
|
||||||
|
|
||||||
|
|
||||||
key_down_cb = getattr(main_screen,"KeyDown",None)
|
key_down_cb = getattr(main_screen,"KeyDown",None)
|
||||||
if key_down_cb != None:
|
if key_down_cb != None:
|
||||||
@ -368,6 +384,7 @@ def big_loop():
|
|||||||
main_screen.ReadTheDirIntoPages("../Menu",0,None)
|
main_screen.ReadTheDirIntoPages("../Menu",0,None)
|
||||||
main_screen.FartherPages()
|
main_screen.FartherPages()
|
||||||
|
|
||||||
|
|
||||||
title_bar._SkinManager = main_screen._SkinManager
|
title_bar._SkinManager = main_screen._SkinManager
|
||||||
foot_bar._SkinManager = main_screen._SkinManager
|
foot_bar._SkinManager = main_screen._SkinManager
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user