Toggle AirPlane Mode

This commit is contained in:
cuu 2018-07-01 21:23:22 +08:00 committed by clockworkpi
parent 8f965b3ba5
commit 2d11df8c37
6 changed files with 81 additions and 195 deletions

View File

@ -2,7 +2,7 @@
import pygame
#import math
import subprocess
import commands
#from beeprint import pp
from libs.roundrects import aa_round_rect
@ -74,8 +74,8 @@ class InfoPageListItem(object):
class HelloWorldPage(Page):
_FootMsg = ["Nav.","","","Back",""]
class AirplanePage(Page):
_FootMsg = ["Nav.","","","Back","Toggle"]
_MyList = []
_ListFontObj = fonts["varela13"]
@ -88,53 +88,18 @@ class HelloWorldPage(Page):
_DrawOnce = False
_Scroller = None
_InAirPlaneMode = False
def __init__(self):
Page.__init__(self)
self._Icons = {}
def HelloWorld(self):
hello = {}
hello["key"] = "helloworld"
hello["label"] = "HelloWorld "
hello["value"] = "GameShell"
self._AList["hello"] = hello
def GenList(self):
self._MyList = []
start_x = 0
start_y = 10
last_height = 0
for i,u in enumerate( ["hello"] ):
if u not in self._AList:
continue
v = self._AList[u]
li = InfoPageListItem()
li._Parent = self
li._PosX = start_x
li._PosY = start_y + last_height
li._Width = Width
li._Fonts["normal"] = self._ListFontObj
li._Fonts["small"] = fonts["varela12"]
if self._AList[u]["label"] != "":
li.Init( self._AList[u]["label"] )
else:
li.Init( self._AList[u]["key"] )
li._Flag = self._AList[u]["key"]
li.SetSmallText( self._AList[u]["value"] )
last_height += li._Height
self._MyList.append(li)
def Init(self):
if self._Screen != None:
@ -155,7 +120,6 @@ class HelloWorldPage(Page):
self._Icons["bg"] = bgpng
"""
self.HelloWorld()
self.GenList()
@ -178,12 +142,35 @@ class HelloWorldPage(Page):
self._PosY += dis
self._Scrolled += dis
def ToggleMode(self):
print("ToggleMode")
out = commands.getstatusoutput('rfkill list | grep yes | cut -d " " -f3')
print out
if out[1] == "yes":
self._InAirPlaneMode = True
self._Screen._MsgBox.SetText("Turning On")
self._Screen._MsgBox.Draw()
commands.getstatusoutput("rfkill unblock all")
else:
self._InAirPlaneMode = False
self._Screen._MsgBox.SetText("Turning Off")
self._Screen._MsgBox.Draw()
commands.getstatusoutput("rfkill block all")
def OnLoadCb(self):
self._Scrolled = 0
self._PosY = 0
self._DrawOnce = False
out = commands.getstatusoutput('rfkill list | grep yes | cut -d " " -f3')
if out[1] == "yes":
self._InAirPlaneMode = True
else:
self._InAirPlaneMode = False
def OnReturnBackCb(self):
self.ReturnToUpLevelPage()
self._Screen.Draw()
@ -194,7 +181,17 @@ class HelloWorldPage(Page):
self.ReturnToUpLevelPage()
self._Screen.Draw()
self._Screen.SwapAndShow()
if event.key == CurKeys["B"]:
self.ToggleMode()
self._Screen.SwapAndShow()
pygame.time.delay(1000)
self._Screen.Draw()
self._Screen.SwapAndShow()
"""
if event.key == CurKeys["Up"]:
self.ScrollUp()
self._Screen.Draw()
@ -203,29 +200,23 @@ class HelloWorldPage(Page):
self.ScrollDown()
self._Screen.Draw()
self._Screen.SwapAndShow()
"""
def Draw(self):
if self._DrawOnce == False:
self.ClearCanvas()
#self._Ps.Draw()
if "bg" in self._Icons:
self._Icons["bg"].NewCoord(self._Width/2,self._Height/2 + (self._BGheight - Height)/2 + self._Screen._TitleBar._Height)
self._Icons["bg"].Draw()
for i in self._MyList:
i.Draw()
self._DrawOnce = True
self.ClearCanvas()
if "bg" in self._Icons:
self._Icons["bg"].NewCoord(self._Width/2,self._Height/2 + (self._BGheight - Height)/2 + self._Screen._TitleBar._Height)
self._Icons["bg"].Draw()
if self._HWND != None:
self._HWND.fill((255,255,255))
self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width, self._Height ) )
self._Scroller.UpdateSize(self._BGheight,abs(self._Scrolled)*3)
self._Scroller.Draw()
# self._Scroller.UpdateSize(self._BGheight,abs(self._Scrolled)*3)
# self._Scroller.Draw()
@ -236,9 +227,9 @@ class APIOBJ(object):
def __init__(self):
pass
def Init(self,main_screen):
self._Page = HelloWorldPage()
self._Page = AirplanePage()
self._Page._Screen = main_screen
self._Page._Name ="HelloWorld"
self._Page._Name ="Airplane Mode"
self._Page.Init()
def API(self,main_screen):

View File

@ -76,14 +76,14 @@ class ListPage(Page):
self._PsIndex = 0
# "" pkgname, label
alist = [["","Wifi","Wi-Fi"],
alist = [["","Airplane","Airplane Mode"],
["","Wifi","Wi-Fi"],
["","Sound","Sound Volume"],
["","Brightness","BackLight Brightness"],
["","Storage",""],
["","Update", ""],
["","About", "About"],
["","PowerOFF","Power off"],
["","HelloWorld","HelloWorld"],]
["","PowerOFF","Power off"],]
start_x = 0
start_y = 0

View File

@ -201,7 +201,7 @@ class MPDSpectrumPage(Page):
self._CanvasHWND = self._Screen._CanvasHWND
"""
self._BGpng = IconItem()
self._BGpng._ImgSurf = MyIconPool._Icons["sheep_bg"]
self._BGpng._MyType = ICON_TYPES["STAT"]
@ -219,7 +219,7 @@ class MPDSpectrumPage(Page):
self._SheepBody._MyType = ICON_TYPES["STAT"]
self._SheepBody._Parent = self
self._SheepBody.Adjust(0,0,self._SheepBodyW,self._SheepBodyH,0)
"""
self.Start()
self._GobjectIntervalId = gobject.timeout_add(50,self.Playing)
@ -308,123 +308,7 @@ class MPDSpectrumPage(Page):
if event.key == CurKeys["Enter"]:
pass
def Draw(self):
self.ClearCanvas()
self._BGpng.NewCoord(self._Width/2,self._Height/2)
self._BGpng.Draw()
# print(self._Neighbor._CurSongTime)
phrase1 = False
phrase2 = False
parts = self._Neighbor._CurSongTime.split(":")
if len(parts) > 1:
cur = float(parts[0])
end = float(parts[1])
pros = int((cur/end)*100.0)
if pros > 30 and pros < 55:
phrase1 = True
if pros > 55 and pros < 100:
phrase2 = True
try:
spects = self._Queue.get_nowait() ## last element is rms
#print("get_nowait: " , spects)
except Empty:
return
else: # got line
if len(spects) == 0:
return
rms = spects[-1]
ratio = float(rms)/float(self._Height)
# 139,62
dx = 0
if ratio < 0.5:
dx = 5
else:
dx = 16
self._freq_count+=1 ## like frames
sheepbody_xy = (181,92)
sheephead_xy = (139,62)
sheepeye_xy = (129,60) ## eye2 ==> 129+20
eye_dx = sheephead_xy[0] - sheepeye_xy[0]
eye_dy = sheephead_xy[1] - sheepeye_xy[1]
self._SheepBody.NewCoord(sheepbody_xy[0],sheepbody_xy[1])
leg_dx = 2
if self._freq_count % 2 == 0:
self._SheepHead.NewCoord(sheephead_xy[0]+dx, sheephead_xy[1])
elif self._freq_count % 3 == 0:
self._SheepHead.NewCoord(sheephead_xy[0]-dx, sheephead_xy[1])
elif self._freq_count % 4 == 0:
self._SheepHead.NewCoord(sheephead_xy[0],sheephead_xy[1]+dx*2)
elif self._freq_count % 5 == 0:
self._SheepBody.NewCoord(sheepbody_xy[0],sheepbody_xy[1]-dx*3)
self._SheepHead.NewCoord(sheephead_xy[0],sheephead_xy[1]-dx*3)
elif self._freq_count % 7 == 0:
leg_dx = 0
self._SheepBody.NewCoord(sheepbody_xy[0],sheepbody_xy[1])
self._SheepBody.Draw()
self._SheepHead.Draw()
## eyes
pygame.draw.circle(self._CanvasHWND,(255,255,255),(self._SheepHead._PosX-eye_dx,self._SheepHead._PosY-eye_dy),8,0)
pygame.draw.circle(self._CanvasHWND,(0,0,0),(self._SheepHead._PosX-eye_dx,self._SheepHead._PosY-eye_dy),8,2)
pygame.draw.circle(self._CanvasHWND,(0,0,0),(self._SheepHead._PosX-eye_dx,self._SheepHead._PosY-eye_dy),2,0)
pygame.draw.circle(self._CanvasHWND,(255,255,255),(self._SheepHead._PosX-eye_dx+20,self._SheepHead._PosY-eye_dy),8,0)
pygame.draw.circle(self._CanvasHWND,(0,0,0),(self._SheepHead._PosX-eye_dx+20,self._SheepHead._PosY-eye_dy),8,2)
pygame.draw.circle(self._CanvasHWND,(0,0,0),(self._SheepHead._PosX-eye_dx+20,self._SheepHead._PosY-eye_dy),2,0)
##legs
legs1_xy = (self._SheepBody._PosX+13,self._SheepBody._PosY+38)
legs1_xy_end = (legs1_xy[0],legs1_xy[1]+16)
legs1_1_xy = (legs1_xy_end[0]-leg_dx,legs1_xy_end[1])
legs1_1_xy_end = (legs1_1_xy[0],legs1_1_xy[1]+14)
legs2_xy = (self._SheepBody._PosX+23,self._SheepBody._PosY+36)
legs2_xy_end = (legs2_xy[0],legs2_xy[1]+16)
legs3_xy = (self._SheepBody._PosX-23,self._SheepBody._PosY+38)
legs3_xy_end = (legs3_xy[0],legs3_xy[1]+16)
legs4_xy = (self._SheepBody._PosX-33,self._SheepBody._PosY+26)
legs4_xy_end = (legs4_xy[0],legs4_xy[1]+22)
legs4_1_xy = (legs4_xy_end[0]-leg_dx,legs4_xy_end[1])
legs4_1_xy_end = (legs4_1_xy[0],legs4_1_xy[1]+14)
pygame.draw.line(self._CanvasHWND,(0,0,0), legs1_xy,legs1_xy_end,4)
pygame.draw.line(self._CanvasHWND,(0,0,0), legs2_xy,legs2_xy_end,4)
pygame.draw.line(self._CanvasHWND,(0,0,0), legs3_xy,legs3_xy_end,4)
pygame.draw.line(self._CanvasHWND,(0,0,0), legs4_xy,legs4_xy_end,4)
pygame.draw.line(self._CanvasHWND,(0,0,0), legs1_1_xy,legs1_1_xy_end,4)
pygame.draw.line(self._CanvasHWND,(0,0,0), legs4_1_xy,legs4_1_xy_end,4)
"""
def Draw(self):
self.ClearCanvas()
@ -443,6 +327,6 @@ class MPDSpectrumPage(Page):
for i,v in enumerate(spects[0:-1]):
pygame.draw.rect(self._CanvasHWND,self._Color,(i*w+left_margin,self._Height-v,bw,v),0)
"""

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -45,8 +45,8 @@ class MessageBox(Label):
def SetText(self,text):
self._Text = text
def Draw(self):
def PreDraw(self):
self._Width = 0
self._Height = 0
self._CanvasHWND.fill( (255,255,255))
@ -87,20 +87,31 @@ class MessageBox(Label):
self._Height = lines
padding = 5
x = (self._Parent._Width - self._Width)/2
y = (self._Parent._Height - self._Height)/2
# print("x %d y %d w %d h %d" %(x,y,self._Width,self._Height ))
def DrawWith(self, x_,y_, withborder):
pygame.draw.rect(self._HWND,(255,255,255),(x-padding,y-padding, self._Width+padding*2,self._Height+padding*2))
self.PreDraw()
x_ = x_ - self._Width/2
y_ = y_ - self._Height/2
padding = 5
pygame.draw.rect(self._HWND,(255,255,255),(x_-padding,y_-padding, self._Width+padding*2,self._Height+padding*2))
if self._HWND != None:
rect = midRect(self._Parent._Width/2,self._Parent._Height/2,self._Width,self._Height,Width,Height)
rect = pygame.Rect(x_,y_,self._Width,self._Height)
self._HWND.blit(self._CanvasHWND,rect,(0,0,self._Width,self._Height))
#self._HWND.blit(self._CanvasHWND,rect)
pygame.draw.rect(self._HWND,(0,0,0),(x-padding,y-padding, self._Width+padding*2,self._Height+padding*2),1)
if withborder == True:
pygame.draw.rect(self._HWND,(0,0,0),(x_-padding,y_-padding, self._Width+padding*2,self._Height+padding*2),1)
def Draw(self):
x = (self._Parent._Width)/2
y = (self._Parent._Height)/2
self.DrawWith(x,y,True)
python_package_flag = "__init__.py"
emulator_flag = "action.config"

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
CurKeySet = "GameShell" ## >>> PC or GameShell <<<
CurKeySet = "PC" ## >>> PC or GameShell <<<
DontLeave = False