mirror of
https://github.com/clockworkpi/launcher.git
synced 2025-12-12 17:58:50 +01:00
* Revert "Respond to user requests (#35)" This reverts commit dc1b7e007c24dfb7226ee02c41ab0af723229f5f. * Revert "image text" This reverts commit 968db78adb9c5404d5150f4dd467a9e58545be0d. * Revert "add restore in POWEROPT event" This reverts commit 88523224de7721f9563a5b1f8d83bf05c76e3c76. * Revert "off to OFF" This reverts commit 586aa75ae4a4c276af71c17246d202ae7dfc0eef. * Revert "text fix" This reverts commit 8e3a90589aeb2b115d6321edcfa08abad5f78d07. * Revert "ignore powerlevel" This reverts commit 164b55fb4bccf625aa378057908b7fcbac8d229f. * Revert "switch smalltext" This reverts commit 01a5f2ef9af19a7ed302c21ceb82531e087b014b. * Revert "text fix" This reverts commit e03a9da323ebd767550ed2c967f6ada1252f9e18. * Revert "text fix" This reverts commit b5603bcf7c91b3a4af8a32dbb6fbcf92122e09a9. * Revert "sudo rfkill" This reverts commit 2bbeba56654727fe634faeef99f36ba68cb3d7a5. * Revert "InspectionTeam" This reverts commit 3db3b0e8b3b8f46287eb7b9956d262b74b61b1f8. * Revert "move back CurKeySet" This reverts commit 10f7e35e2e7a75cd8b4ba0a3f463f3be805eb14c. * Revert "rm png" This reverts commit bfdb83683a1f13e469b24479a08b4ff47b7cd924. * Revert "airplane mode with animation" This reverts commit 6e19ad88a7d5797ab83567e0b79d80f849d4e194. * Revert "add detail on power mode" This reverts commit d66a0df823a05ef45485f9e0d6db0434af4e178e. * Revert "add PowerLevel options" This reverts commit 36c54a4f9d0b8c569253cde4b1003cf9532e3802. * Revert "TitleBar show airplane mode icon" This reverts commit 74e7f8ab69f1813da84f9c26ee917f0c29bf7ab0. * Revert "Toggle AirPlane Mode" This reverts commit 2d11df8c37f7ab6e30c87dd5730614126b2ef7ba. * Revert "start sheep" This reverts commit 8f965b3ba543c5a952ef65fd868721e5b1dbbe7c. * Revert "fix bug dosbox on rom_list_page and remove scalesmooth on sec level icons" This reverts commit b4e40d052a479732dab13cec0b9776c3a21c93dc. * Revert "fix fav display bug on dosbox" This reverts commit 40be34e30d1289473b06f7f54bb70611e9da51f9. * Revert "add dosbox on fav" This reverts commit 2cba2e580867dfab3065dff269a5fcca0c2f668e. * Revert "add dosbox" This reverts commit bd71c64a5c75c8fceabe6554242569807deffea6. * Revert "Move back to 10_Settings" This reverts commit 4acacaf7363def6e462d1d2ecec10d68a9208353. * Revert "change load modules checking in Settings list_page" This reverts commit 385b672eeb0afb6d80921af8ad96da1ed76d8e80. * Revert "develop branch commit" This reverts commit f604310bb2d0855ea409012f6e86c71d549d56f1.
308 lines
11 KiB
Python
308 lines
11 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import pygame
|
|
import os
|
|
import sys
|
|
|
|
from datetime import datetime
|
|
|
|
#from beeprint import pp
|
|
|
|
import alsaaudio
|
|
|
|
##local import
|
|
from constants import ICON_TYPES,Width,Height
|
|
from fonts import fonts
|
|
from icon_item import IconItem
|
|
from multi_icon_item import MultiIconItem
|
|
from icon_pool import MyIconPool
|
|
|
|
from util_funcs import midRect,SwapAndShow,SkinMap
|
|
|
|
from config import Battery
|
|
|
|
from libs.roundrects import aa_round_rect
|
|
|
|
from libs.DBUS import is_wifi_connected_now,wifi_strength
|
|
|
|
icon_base_path = SkinMap("gameshell/titlebar_icons/")
|
|
class TitleBar:
|
|
_PosX = 0
|
|
_PosY = 0
|
|
_Width = Width
|
|
_Height = 25
|
|
_BarHeight = 24.5
|
|
_LOffset = 3
|
|
_ROffset = 3
|
|
_Icons = {}
|
|
_icon_width = 18
|
|
_icon_height = 18
|
|
_BorderWidth = 1
|
|
_CanvasHWND = None
|
|
_HWND = None
|
|
_Title = ""
|
|
|
|
_InLowBackLight = -1
|
|
|
|
_SkinManager = None
|
|
|
|
|
|
def __init__(self):
|
|
self._Icons = {}
|
|
|
|
|
|
def GObjectRoundRobin(self):
|
|
if self._InLowBackLight < 0:
|
|
self.CheckBatteryStat()
|
|
self.SyncSoundVolume()
|
|
self.UpdateWifiStrength()
|
|
SwapAndShow()
|
|
else:
|
|
self._InLowBackLight+=1
|
|
|
|
if self._InLowBackLight > 10:
|
|
self.CheckBatteryStat()
|
|
self.SyncSoundVolume()
|
|
self.UpdateWifiStrength()
|
|
SwapAndShow()
|
|
self._InLowBackLight = 0
|
|
|
|
return True
|
|
|
|
def UpdateWifiStrength(self):
|
|
self.Draw(self._Title)
|
|
|
|
def GetWifiStrength(self,stren): ##invoke anytime to change title bar icon status
|
|
#0-25
|
|
#25-50
|
|
#50-75
|
|
#75-100
|
|
|
|
segs = [[-2,-1], [0,25],[25,50],[50,75],[75,100] ]
|
|
|
|
stren = int(stren)
|
|
ge = 0
|
|
|
|
if stren == 0:
|
|
return ge
|
|
|
|
for i,v in enumerate(segs):
|
|
if stren >= v[0] and stren <= v[1]:
|
|
ge = i
|
|
break
|
|
|
|
return ge
|
|
|
|
def SyncSoundVolume(self):
|
|
m = alsaaudio.Mixer()
|
|
vol = m.getvolume()[0]
|
|
|
|
snd_segs = [ [0,10],[10,30],[30,70],[70,100] ]
|
|
|
|
ge = 0
|
|
for i,v in enumerate(snd_segs):
|
|
if vol >= v[0] and vol <= v[1]:
|
|
ge = i
|
|
break
|
|
|
|
self._Icons["soundvolume"]._IconIndex = ge
|
|
self._Icons["sound"] = self._Icons["soundvolume"]
|
|
|
|
|
|
def SetSoundVolume(self,vol):
|
|
pass
|
|
|
|
def CheckBatteryStat(self): ## 100ms check interval
|
|
content = ""
|
|
bat_uevent = {}
|
|
bat_segs=[ [0,6],[7,15],[16,20], [21,30],[31,50],[51,60], [61,80],[81,90],[91,100] ]
|
|
|
|
try:
|
|
f = open(Battery)
|
|
except IOError:
|
|
self._Icons["battery"] = self._Icons["battery_unknown"]
|
|
print("CheckBatteryStat open failed")
|
|
return False
|
|
else:
|
|
with f:
|
|
content = f.readlines()
|
|
content = [x.strip() for x in content]
|
|
f.close()
|
|
|
|
for i in content:
|
|
pis = i.split("=")
|
|
if len(pis) > 1:
|
|
bat_uevent[pis[0]] = pis[1]
|
|
|
|
# print(bat_uevent["POWER_SUPPLY_CAPACITY"])
|
|
|
|
"""
|
|
power_current = int(bat_uevent["POWER_SUPPLY_CURRENT_NOW"])
|
|
if power_current < 270000:
|
|
self._Icons["battery"] = self._Icons["battery_unknown"]
|
|
return False
|
|
"""
|
|
|
|
if "POWER_SUPPLY_CAPACITY" in bat_uevent:
|
|
cur_cap = int(bat_uevent["POWER_SUPPLY_CAPACITY"])
|
|
else:
|
|
cur_cap = 0
|
|
|
|
cap_ge = 0
|
|
|
|
for i,v in enumerate(bat_segs):
|
|
if cur_cap >= v[0] and cur_cap <= v[1]:
|
|
cap_ge = i
|
|
break
|
|
|
|
if bat_uevent["POWER_SUPPLY_STATUS"] == "Charging":
|
|
self._Icons["battery_charging"]._IconIndex = cap_ge
|
|
self._Icons["battery"] = self._Icons["battery_charging"]
|
|
|
|
print("Charging %d" % cap_ge)
|
|
else:
|
|
self._Icons["battery_discharging"]._IconIndex = cap_ge
|
|
self._Icons["battery"] = self._Icons["battery_discharging"]
|
|
print("Discharging %d" % cap_ge)
|
|
|
|
|
|
return True
|
|
|
|
def SetBatteryStat(self,bat):
|
|
pass
|
|
|
|
def Init(self,screen):
|
|
|
|
|
|
start_x = 0
|
|
self._CanvasHWND = pygame.Surface((self._Width,self._Height))
|
|
self._HWND = screen
|
|
|
|
|
|
icon_wifi_status = MultiIconItem()
|
|
icon_wifi_status._MyType = ICON_TYPES["STAT"]
|
|
icon_wifi_status._ImageName = icon_base_path+"wifi.png"
|
|
icon_wifi_status._Parent = self
|
|
icon_wifi_status.Adjust(start_x+self._icon_width+5,self._icon_height/2+(self._BarHeight-self._icon_height)/2,self._icon_width,self._icon_height,0)
|
|
self._Icons["wifistatus"] = icon_wifi_status
|
|
|
|
battery_charging = MultiIconItem()
|
|
battery_charging._MyType = ICON_TYPES["STAT"]
|
|
battery_charging._Parent = self
|
|
battery_charging._ImageName = icon_base_path+"withcharging.png"
|
|
battery_charging.Adjust(start_x+self._icon_width+self._icon_width+8,self._icon_height/2+(self._BarHeight-self._icon_height)/2,self._icon_width,self._icon_height,0)
|
|
|
|
self._Icons["battery_charging"] = battery_charging
|
|
|
|
battery_discharging = MultiIconItem()
|
|
battery_discharging._MyType = ICON_TYPES["STAT"]
|
|
battery_discharging._Parent = self
|
|
battery_discharging._ImageName = icon_base_path+"without_charging.png"
|
|
battery_discharging.Adjust(start_x+self._icon_width+self._icon_width+8,self._icon_height/2+(self._BarHeight-self._icon_height)/2,self._icon_width,self._icon_height,0)
|
|
|
|
self._Icons["battery_discharging"] = battery_discharging
|
|
|
|
battery_unknown = IconItem()
|
|
battery_unknown._MyType = ICON_TYPES["STAT"]
|
|
battery_unknown._Parent = self
|
|
battery_unknown._ImageName = icon_base_path+"battery_unknown.png"
|
|
battery_unknown.Adjust(start_x+self._icon_width+self._icon_width+8,self._icon_height/2+(self._BarHeight-self._icon_height)/2,self._icon_width,self._icon_height,0)
|
|
|
|
self._Icons["battery_unknown"] = battery_unknown
|
|
|
|
self.CheckBatteryStat()
|
|
|
|
sound_volume = MultiIconItem()
|
|
sound_volume._MyType = ICON_TYPES["STAT"]
|
|
sound_volume._Parent = self
|
|
sound_volume._ImageName = icon_base_path+"soundvolume.png"
|
|
sound_volume.Adjust(start_x+self._icon_width+self._icon_width+8,self._icon_height/2+(self._BarHeight-self._icon_height)/2,self._icon_width,self._icon_height,0)
|
|
|
|
self._Icons["soundvolume"] = sound_volume
|
|
|
|
self.SyncSoundVolume()
|
|
|
|
|
|
round_corners = MultiIconItem()
|
|
round_corners._IconWidth = 10
|
|
round_corners._IconHeight = 10
|
|
|
|
round_corners._MyType = ICON_TYPES["STAT"]
|
|
round_corners._Parent = self
|
|
round_corners._ImgSurf = MyIconPool._Icons["roundcorners"]
|
|
round_corners.Adjust(0,0,10,10,0)
|
|
|
|
self._Icons["round_corners"] = round_corners
|
|
|
|
if is_wifi_connected_now():
|
|
print("wifi is connected")
|
|
print( wifi_strength())
|
|
|
|
def ClearCanvas(self):
|
|
self._CanvasHWND.fill( self._SkinManager.GiveColor("TitleBg") )
|
|
|
|
self._Icons["round_corners"].NewCoord(5,5)
|
|
self._Icons["round_corners"]._IconIndex = 0
|
|
self._Icons["round_corners"].Draw()
|
|
|
|
self._Icons["round_corners"].NewCoord(self._Width-5,5)
|
|
self._Icons["round_corners"]._IconIndex = 1
|
|
self._Icons["round_corners"].Draw()
|
|
|
|
|
|
"""
|
|
aa_round_rect(self._CanvasHWND,
|
|
(0,0,self._Width,self._Height),self._BgColor,8,0, self._BgColor)
|
|
|
|
pygame.draw.rect(self._CanvasHWND,self._BgColor,(0,self._Height/2,Width,self._BarHeight), 0 )
|
|
"""
|
|
|
|
def Draw(self,title):
|
|
self.ClearCanvas()
|
|
|
|
self._Title = title
|
|
|
|
cur_time = datetime.now().strftime("%H:%M")
|
|
time_text_size = fonts["varela12"].size(cur_time)
|
|
title_text_size = fonts["varela16"].size(title)
|
|
|
|
self._CanvasHWND.blit(fonts["varela16"].render(title,True,self._SkinManager.GiveColor("Text")),midRect(title_text_size[0]/2+self._LOffset,
|
|
title_text_size[1]/2+(self._BarHeight-title_text_size[1])/2,
|
|
title_text_size[0],title_text_size[1],Width,Height))
|
|
self._CanvasHWND.blit(fonts["varela12"].render(cur_time,True,self._SkinManager.GiveColor("Text")),midRect(Width-time_text_size[0]/2-self._ROffset,
|
|
time_text_size[1]/2+(self._BarHeight-time_text_size[1])/2,
|
|
time_text_size[0],time_text_size[1],Width,Height))
|
|
|
|
start_x = Width-time_text_size[0]-self._ROffset-self._icon_width*3 # near by the time_text
|
|
|
|
self._Icons["sound"].NewCoord(start_x, self._icon_height/2+(self._BarHeight-self._icon_height)/2)
|
|
|
|
#self._Icons["wifi"].NewCoord(start_x+self._icon_width+5, self._icon_height/2+(self._BarHeight-self._icon_height)/2)
|
|
|
|
self._Icons["battery"].NewCoord(start_x+self._icon_width+self._icon_width+8,self._icon_height/2+(self._BarHeight-self._icon_height)/2)
|
|
|
|
|
|
if is_wifi_connected_now():
|
|
ge = self.GetWifiStrength(wifi_strength())
|
|
if ge > 0:
|
|
self._Icons["wifistatus"]._IconIndex = ge
|
|
self._Icons["wifistatus"].NewCoord(start_x+self._icon_width+5,self._icon_height/2+(self._BarHeight-self._icon_height)/2)
|
|
self._Icons["wifistatus"].Draw()
|
|
else:
|
|
self._Icons["wifistatus"]._IconIndex = 0
|
|
self._Icons["wifistatus"].Draw()
|
|
print("strength error")
|
|
else:
|
|
self._Icons["wifistatus"]._IconIndex = 0
|
|
self._Icons["wifistatus"].NewCoord(start_x+self._icon_width+5,self._icon_height/2+(self._BarHeight-self._icon_height)/2)
|
|
self._Icons["wifistatus"].Draw()
|
|
|
|
self._Icons["sound"].Draw()
|
|
|
|
self._Icons["battery"].Draw()
|
|
|
|
pygame.draw.line(self._CanvasHWND,self._SkinManager.GiveColor("Line"),(0,self._BarHeight),(self._Width,self._BarHeight),self._BorderWidth)
|
|
|
|
if self._HWND != None:
|
|
self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height))
|