From 8e04b841e70fd3a2e61d543f41313e0ac0bdda39 Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Tue, 15 Oct 2019 18:17:29 +0200 Subject: [PATCH] WIP dev env --- .../10_Settings/Airplane/__init__.py | 16 +- .../10_Settings/Bluetooth/__init__.py | 348 +++++++++--------- Menu/GameShell/10_Settings/Wifi/wifi_list.py | 6 +- Menu/GameShell/10_Settings/__init__.py | 1 - .../97_Music Player/mpd_spectrum_page.py | 116 +++--- sys.py/UI/main_screen.py | 2 - sys.py/UI/title_bar.py | 4 +- sys.py/UI/untitled_icon.py | 6 +- sys.py/run.py | 180 ++++----- 9 files changed, 339 insertions(+), 340 deletions(-) diff --git a/Menu/GameShell/10_Settings/Airplane/__init__.py b/Menu/GameShell/10_Settings/Airplane/__init__.py index 3338d90d..2fff687b 100644 --- a/Menu/GameShell/10_Settings/Airplane/__init__.py +++ b/Menu/GameShell/10_Settings/Airplane/__init__.py @@ -122,7 +122,7 @@ def ScrollUp(self): self._Scrolled += dis def ToggleModeAni(self): ## with animation - out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + out = commands.getstatusoutput('rfkill list | grep yes | cut -d " " -f3') if "yes" in out[1]: data = self.EasingData(0,43) for _,v in enumerate(data): @@ -133,7 +133,7 @@ def ToggleModeAni(self): ## with animation self._Screen.Draw() self._Screen.SwapAndShow() - commands.getstatusoutput("sudo rfkill unblock all") + commands.getstatusoutput("rfkill unblock all") self._Screen._TitleBar._InAirPlaneMode = False else: @@ -146,29 +146,29 @@ def ToggleModeAni(self): ## with animation self._Screen.Draw() self._Screen.SwapAndShow() - commands.getstatusoutput("sudo rfkill block all") + commands.getstatusoutput("rfkill block all") self._Screen._TitleBar._InAirPlaneMode = True def ToggleMode(self): - out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + out = commands.getstatusoutput('rfkill list | grep yes | cut -d " " -f3') print out if "yes" in out[1]: self._Screen._MsgBox.SetText("TurningOn") self._Screen._MsgBox.Draw() - commands.getstatusoutput("sudo rfkill unblock all") + commands.getstatusoutput("rfkill unblock all") self._Screen._TitleBar._InAirPlaneMode = False else: self._Screen._MsgBox.SetText("TurningOff") self._Screen._MsgBox.Draw() - commands.getstatusoutput("sudo rfkill block all") + commands.getstatusoutput("rfkill block all") self._Screen._TitleBar._InAirPlaneMode = True def UnBlockAll(self): self._Screen._MsgBox.SetText("TurningOn") self._Screen._MsgBox.Draw() - commands.getstatusoutput("sudo rfkill unblock all") + commands.getstatusoutput("rfkill unblock all") self._Screen._TitleBar._InAirPlaneMode = False @@ -176,7 +176,7 @@ def OnLoadCb(self): self._Scrolled = 0 self._PosY = 0 self._DrawOnce = False - out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + out = commands.getstatusoutput('rfkill list | grep yes | cut -d " " -f3') if "yes" in out[1]: self._Screen._TitleBar._InAirPlaneMode = True self._airwire_y = 50+43 diff --git a/Menu/GameShell/10_Settings/Bluetooth/__init__.py b/Menu/GameShell/10_Settings/Bluetooth/__init__.py index 4a943ab8..2bf796e3 100644 --- a/Menu/GameShell/10_Settings/Bluetooth/__init__.py +++ b/Menu/GameShell/10_Settings/Bluetooth/__init__.py @@ -1,16 +1,15 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import re import pygame #import math import commands import dbus -from beeprint import pp from libs.roundrects import aa_round_rect from libs.DBUS import bus, adapter,devices #import gobject -#from wicd import misc +#from wicd import misc ## local UI import from UI.constants import Width,Height,ICON_TYPES from UI.page import Page,PageSelector @@ -36,37 +35,37 @@ class BleForgetConfirmPage(ConfirmPage): _ConfirmText = MyLangManager.Tr("ConfirmForgetQ") - + def KeyDown(self,event): if IsKeyMenuOrB(event.key): self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() - + if IsKeyStartOrA(event.key): self.SnapMsg(MyLangManager.Tr("Deleting")) self._Screen.Draw() self._Screen.SwapAndShow() - + try: #self._Parent._Adapter.RemoveDevice() print("try to RemoveDevice") except Exception,e: print(str(e)) - + pygame.time.delay(400) - + self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() - - + + def Draw(self): #self.ClearCanvas() self.DrawBG() for i in self._MyList: i.Draw() - + self.Reset() @@ -77,9 +76,9 @@ def __init__(self): self._PosX = 0 self._PosY = 0 self._Height = 0 - + def AnimateDraw(self,x2,y2): - pass + pass def Draw(self): idx = self._Parent._PsIndex @@ -87,12 +86,12 @@ def Draw(self): x = self._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, + aa_round_rect(self._Parent._CanvasHWND, (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor) class BleInfoPage(Page): @@ -101,7 +100,7 @@ class BleInfoPage(Page): _ListFontObj = MyLangManager.TrFont("varela15") _ListSmFontObj = MySkinManager.GiveFont("varela12") # small font _ListSm2FontObj= MySkinManager.GiveFont("varela11") - + _AList = {} _Path = "" def Init(self): @@ -109,16 +108,16 @@ def Init(self): if self._Screen._CanvasHWND != None and self._CanvasHWND == None: self._CanvasHWND = self._Screen._CanvasHWND - self._PosX = self._Index*self._Screen._Width + self._PosX = self._Index*self._Screen._Width self._Width = self._Screen._Width ## equal to screen width self._Height = self._Screen._Height - + ps = BleInfoPageSelector() ps._Parent = self self._Ps = ps self._PsIndex = 0 - - #_AList is an object + + #_AList is an object self.GenList() self._Scroller = ListScroller() @@ -126,13 +125,13 @@ def Init(self): self._Scroller._PosX = 2 self._Scroller._PosY = 2 self._Scroller.Init() - + self._ConfirmPage1 = BleForgetConfirmPage() self._ConfirmPage1._Screen = self._Screen self._ConfirmPage1._Name = "ConfirmForget" self._ConfirmPage1._Parent = self - self._ConfirmPage1.Init() - + self._ConfirmPage1.Init() + def GenList(self): if self._AList== None: return @@ -140,25 +139,25 @@ def GenList(self): self._PsIndex = 0 start_x = 0 start_y = 0 - + for i,v in enumerate( self._AList): #print(i,v) # (0, dbus.String(u'AddressType')) - + li = InfoPageListItem() li._Parent = self li._PosX = start_x li._PosY = start_y + i*InfoPageListItem._Height li._Width = Width li._Fonts["normal"] = self._ListFontObj - + if v == "UUIDs": li._Fonts["small"] = self._ListSm2FontObj else: li._Fonts["small"] = self._ListSmFontObj - + li.Init( str(v) ) li._Flag = v - + if v =="UUIDs": if len(self._AList[v]) > 1: pp(self._AList[v][0]) @@ -166,28 +165,28 @@ def GenList(self): else: sm_text = "" else: - sm_text = str(self._AList[v]) - + sm_text = str(self._AList[v]) + if sm_text == "0": sm_text="No" elif sm_text == "1": sm_text="Yes" - + sm_text = sm_text[:20] li.SetSmallText(sm_text) - + li._PosX = 2 - self._MyList.append(li) + self._MyList.append(li) def TryToForget(self): global adapter proxy_obj = bus.get_object("org.bluez", self._Path) dev = dbus.Interface(proxy_obj, "org.bluez.Device1") - + self._Screen._MsgBox.SetText("Forgeting") self._Screen._MsgBox.Draw() - self._Screen.SwapAndShow() - + self._Screen.SwapAndShow() + try: adapter.RemoveDevice(dev) except Exception,e: @@ -196,31 +195,31 @@ def TryToForget(self): self._Screen._MsgBox.SetText("DBus noreply") else: self._Screen._MsgBox.SetText("Forget failed") - + self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() - + pygame.time.delay(500) - + self.ReturnToUpLevelPage() self._Screen.Draw() - self._Screen.SwapAndShow() - + self._Screen.SwapAndShow() + def TryToDisconnect(self): global bus - + if "Connected" in self._AList: if self._AList["Connected"] == 0: return - + proxy_obj = bus.get_object("org.bluez", self._Path) dev = dbus.Interface(proxy_obj, "org.bluez.Device1") - + self._Screen._FootBar.UpdateNavText("Disconnecting") self._Screen._MsgBox.SetText("Disconnecting") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() - + try: dev.Disconnect() except Exception,e: @@ -231,24 +230,24 @@ def TryToDisconnect(self): self._Screen._MsgBox.SetText("Disconnect failed") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() - + pygame.time.delay(500) self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() - - self._Screen._FootBar.ResetNavText() - - + + self._Screen._FootBar.ResetNavText() + + def Click(self): if self._PsIndex >= len(self._MyList): return - + cur_li = self._MyList[self._PsIndex] print(cur_li._Flag) if cur_li._Flag in self._AList: print(self._AList[ cur_li._Flag ]) - + def OnLoadCb(self): if self._AList != None: if "Connected" in self._AList: @@ -256,7 +255,7 @@ def OnLoadCb(self): self._FootMsg[1] = "Disconnect" else: self._FootMsg[1] = "" - + self.GenList() def OnReturnBackCb(self): @@ -269,7 +268,7 @@ def KeyDown(self,event): self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() - + if event.key == CurKeys["Up"]: self.ScrollUp() self._Screen.Draw() @@ -278,41 +277,41 @@ def KeyDown(self,event): self.ScrollDown() self._Screen.Draw() self._Screen.SwapAndShow() - + if IsKeyStartOrA(event.key): self.Click() - + if event.key == CurKeys["X"]: self.TryToDisconnect() - + if event.key == CurKeys["Y"]: self.TryToForget() - - + + def Draw(self): if len(self._MyList) == 0: return - + self.ClearCanvas() if len(self._MyList) * InfoPageListItem._Height > self._Height: self._Ps._Width = self._Width - 10 self._Ps._PosX = 9 - self._Ps.Draw() + self._Ps.Draw() for i in self._MyList: i.Draw() - + self._Scroller.UpdateSize(len(self._MyList)*InfoPageListItem._Height, self._PsIndex*InfoPageListItem._Height) self._Scroller.Draw() - + else: self._Ps._Width = self._Width self._Ps.Draw() for i in self._MyList: - i.Draw() - + i.Draw() + + - class BleListSelector(PageSelector): _BackgroundColor = MySkinManager.GiveColor('Front') @@ -323,7 +322,7 @@ def __init__(self): self._Height = 0 def AnimateDraw(self,x2,y2): - pass + pass def Draw(self): idx = self._Parent._PsIndex @@ -331,12 +330,12 @@ def Draw(self): 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, + aa_round_rect(self._Parent._CanvasHWND, (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor) class BleListMessageBox(Label): @@ -348,7 +347,7 @@ def Draw(self): h = my_text.get_height() x = (self._Parent._Width - w)/2 y = (self._Parent._Height - h)/2 - padding = 10 + padding = 10 pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('White'),(x-padding,y-padding, w+padding*2,h+padding*2)) pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('Black'),(x-padding,y-padding, w+padding*2,h+padding*2),1) @@ -363,85 +362,85 @@ class BluetoothPage(Page): _Adapter = None _Dbus = None _Devices = None - + _BlePassword = "" _Connecting = False - _Scanning = False - + _Scanning = False + _PrevState = None _Selector = None - - _ShowingMessageBox = False + + _ShowingMessageBox = False _MsgBox = None _ConnectTry = 0 _BlockCb = None - + _LastStatusMsg = "" _FootMsg = ["Nav","Info","Scan","Back","TryConnect"] _Scroller = None _ListFontObj = MyLangManager.TrFont("notosanscjk15") _InfoPage = None - + _ADAPTER_DEV = "hci0" - + _Offline = False - + _Leader = None - + def __init__(self): Page.__init__(self) self._MyList = [] self._CanvasHWND = None - + def ShowBox(self,msg): - + self._MsgBox._Text = msg self._ShowingMessageBox = True self._Screen.Draw() self._MsgBox.Draw() self._Screen.SwapAndShow() - + def HideBox(self): self.Draw() self._ShowingMessageBox = False - self._Screen.SwapAndShow() - + self._Screen.SwapAndShow() + def Init(self): - + self._PosX = self._Index * self._Screen._Width self._Width = self._Screen._Width - self._Height = self._Screen._Height - + self._Height = self._Screen._Height + #self._CanvasHWND = pygame.Surface((self._Width,self._Height)) self._CanvasHWND = self._Screen._CanvasHWND ps = BleListSelector() ps._Parent = self ps._Width = Width - 12 - + self._Ps = ps self._PsIndex = 0 - + msgbox = BleListMessageBox() msgbox._CanvasHWND = self._CanvasHWND msgbox.Init(" ",MyLangManager.TrFont("veramono12")) msgbox._Parent = self - - self._MsgBox = msgbox + + self._MsgBox = msgbox self._Scroller = ListScroller() self._Scroller._Parent = self self._Scroller._PosX = 2 self._Scroller._PosY = 2 self._Scroller.Init() - + self.GenNetworkList() - + self._InfoPage = BleInfoPage() self._InfoPage._Screen = self._Screen self._InfoPage._Name = "BluetoothInfo" - self._InfoPage.Init() + self._InfoPage.Init() def print_normal(self,address, properties): print("[ " + address + " ]") @@ -487,61 +486,61 @@ def DbusPropertiesChanged(self, interface, changed, invalidated, path): address = devices[path]["Address"] else: address = "" - + self._Devices = devices self.print_normal(address, devices[path]) - + self.RefreshDevices() self.GenNetworkList() self._Screen.Draw() self._Screen.SwapAndShow() - + def ShutDownConnecting(self): print("Bluetooth Shutdown connecting...") - + def AbortedAndReturnToUpLevel(self): self.HideBox() self._Screen._FootBar.ResetNavText() self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() - - + + def CheckIfBluetoothConnecting(self): return True def TryConnect(self): global bus - + if self._PsIndex >= len(self._MyList): return - + cur_li = self._MyList[self._PsIndex] print(cur_li._Path) - + if "Connected" in cur_li._Atts: if cur_li._Atts["Connected"] == 1: return - + proxy_obj = bus.get_object("org.bluez", cur_li._Path) dev = dbus.Interface(proxy_obj, "org.bluez.Device1") - + self._Screen._FootBar.UpdateNavText("Connecting") self.ShowBox(MyLangManager.Tr("Connecting")) - + self._Leader._MyAgent.device_obj = dev self._Leader._MyAgent.dev_path = cur_li._Path - + try: - dev.Pair(reply_handler=self._Leader._MyAgent.pair_reply, + dev.Pair(reply_handler=self._Leader._MyAgent.pair_reply, error_handler=self._Leader._MyAgent.pair_error,timeout=60000) except Exception,e: - print(str(e)) - - + print(str(e)) + + #self.HideBox() #self._Screen._FootBar.ResetNavText() - + def RefreshDevices(self): global devices devices = {} @@ -555,15 +554,15 @@ def RefreshDevices(self): except Exception,e: print(str(e)) devices={} - + self._Devices = devices - - + + def GenNetworkList(self): self._MyList = [] start_x = 0 start_y = 0 - + counter = 0 for i,v in enumerate(self._Devices): if "Name" in self._Devices[v]: @@ -573,41 +572,41 @@ def GenNetworkList(self): continue else: continue - + ni = NetItem() ni._Parent = self ni._PosX = start_x ni._PosY = start_y + counter* NetItem._Height ni._Width = Width ni._FontObj = self._ListFontObj - + ni.Init(v,self._Devices[v]) - + counter += 1 self._MyList.append(ni) - self._PsIndex = 0 - + self._PsIndex = 0 + def Rescan(self): if self._Screen._CurrentPage != self: return - + self._Scanning = True self.ShowBox(MyLangManager.Tr("BluetoothScanning")) self._Screen._FootBar.UpdateNavText("Scanning") - + proxy_obj = self._Dbus.get_object("org.bluez", "/org/bluez/" + self._ADAPTER_DEV) adapter_props = dbus.Interface(proxy_obj,"org.freedesktop.DBus.Properties") - discoverying = adapter_props.Get("org.bluez.Adapter1", "Discovering") + discoverying = adapter_props.Get("org.bluez.Adapter1", "Discovering") print("discoverying", discoverying) - - + + if self._Adapter!= None: try: self._Adapter.StopDiscovery() except Exception,e: print(str(e)) - + try: self._Adapter.StartDiscovery() except Exception,e: @@ -616,11 +615,11 @@ def Rescan(self): print("start discovery timeout") else: print("start discovery unknown err: ", str(e)) - + def OnReturnBackCb(self): self.RefreshDevices() self.GenNetworkList() - + def OnLoadCb(self): self._Offline = False if self._Screen._TitleBar._InAirPlaneMode == False: @@ -633,20 +632,20 @@ def OnLoadCb(self): self.GenNetworkList() else: self._Offline = True - + def KeyDown(self,event): - + if IsKeyMenuOrB(event.key): if self._Offline == True: self.AbortedAndReturnToUpLevel() return - + if self._Adapter != None: try: self._Adapter.StopDiscovery() except Exception,e: print(str(e)) - + _connecting = self.CheckIfBluetoothConnecting() if _connecting: self.ShutDownConnecting() @@ -659,9 +658,9 @@ def KeyDown(self,event): self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() - + self._Screen._FootBar.ResetNavText() - + if event.key == CurKeys["Up"]: self.ScrollUp() self._Screen.Draw() @@ -669,24 +668,24 @@ def KeyDown(self,event): if event.key == CurKeys["Down"]: self.ScrollDown() self._Screen.Draw() - self._Screen.SwapAndShow() - + self._Screen.SwapAndShow() + if event.key == CurKeys["X"]: if self._Offline == False: - self.Rescan() + self.Rescan() if event.key == CurKeys["Y"]: if len(self._MyList) == 0: return if self._Offline == True: return - + self._InfoPage._AList = self._MyList[self._PsIndex]._Atts self._InfoPage._Path = self._MyList[self._PsIndex]._Path self._Screen.PushPage(self._InfoPage) self._Screen.Draw() self._Screen.SwapAndShow() - + if IsKeyStartOrA(event.key): if self._Offline == False: self.TryConnect() @@ -695,14 +694,14 @@ def Draw(self): self.ClearCanvas() if len(self._MyList) == 0: return - + if len(self._MyList) * NetItem._Height > self._Height: self._Ps._Width = self._Width - 11 self._Ps.Draw() - + for i in self._MyList: - i.Draw() - + i.Draw() + self._Scroller.UpdateSize( len(self._MyList)*NetItem._Height, self._PsIndex*NetItem._Height) self._Scroller.Draw() else: @@ -726,7 +725,7 @@ class APIOBJ(object): _Prompts = {} # string key,string value _PromptType = None _MyAgent = None - + def __init__(self): self._Prompts["PIN"]="" self._Prompts["PASS"]="" @@ -738,68 +737,71 @@ def OnKbdReturnBackCb(self): if self._PromptType in self._Prompts: inputed = "".join(self._Page3._Textarea._MyWords) self._Prompts[self._PromptType] = inputed - - self._PromptType = None ##clear - - + + self._PromptType = None ##clear + + def Ask(self,prompt,prompt_type=None): - + self._Screen.PushPage(self._Page3) self._Page3.SetPassword("") self._Page3._Name = prompt self._Page3._Caller = self - + self._Screen.Draw() self._Screen.SwapAndShow() - + if prompt_type != None: self._PromptType = prompt_type - + def RegisterMyAgent(self): global AGENT_PATH, bus,devices,adapter - + capability = "KeyboardDisplay" self._MyAgent = BleAgent(bus, AGENT_PATH) self._MyAgent._Leader = self - + obj = bus.get_object(BUS_NAME, "/org/bluez"); manager = dbus.Interface(obj, "org.bluez.AgentManager1") manager.RegisterAgent(AGENT_PATH, capability) print("BleAgent %s registered" % AGENT_PATH) - + def Init(self,main_screen): global bus,devices,adapter - + self._Page = BluetoothPage() self._Page._Dbus = bus self._Page._Devices = devices self._Page._Adapter = adapter - + self._Page._Screen = main_screen self._Page._Name ="Bluetooth" - + self._Page._Leader = self - + self._Page.Init() - + self._PairPage = BleAgentPairPage() self._PairPage._Screen = main_screen self._PairPage._Name = "Bluetooth" self._PairPage.Init() - + self._Page3= Keyboard() self._Page3._Name = "Enter" self._Page3._Screen = main_screen self._Page3.Init() - - bus.add_signal_receiver(self._Page.DbusPropertiesChanged, - dbus_interface = "org.freedesktop.DBus.Properties", - signal_name = "PropertiesChanged", - arg0 = "org.bluez.Device1", - path_keyword = "path") - - self.RegisterMyAgent() - + + try: + bus.add_signal_receiver(self._Page.DbusPropertiesChanged, + dbus_interface = "org.freedesktop.DBus.Properties", + signal_name = "PropertiesChanged", + arg0 = "org.bluez.Device1", + path_keyword = "path") + self.RegisterMyAgent() + except AttributeError: + pass + + def API(self,main_screen): if main_screen !=None: main_screen.PushPage(self._Page) @@ -807,7 +809,7 @@ def API(self,main_screen): main_screen.SwapAndShow() OBJ = APIOBJ() -def Init(main_screen): +def Init(main_screen): OBJ.Init(main_screen) def API(main_screen): OBJ.API(main_screen) diff --git a/Menu/GameShell/10_Settings/Wifi/wifi_list.py b/Menu/GameShell/10_Settings/Wifi/wifi_list.py index c5882d7f..09363858 100644 --- a/Menu/GameShell/10_Settings/Wifi/wifi_list.py +++ b/Menu/GameShell/10_Settings/Wifi/wifi_list.py @@ -2,7 +2,6 @@ import pygame -from beeprint import pp from libs.roundrects import aa_round_rect import gobject from wicd import misc @@ -692,7 +691,10 @@ def Init(self): self._MsgBox = msgbox - self._EncMethods = misc.LoadEncryptionMethods() # load predefined templates from /etc/wicd/... + try: + self._EncMethods = misc.LoadEncryptionMethods() # load predefined templates from /etc/wicd/... + except IOError: + pass """ { diff --git a/Menu/GameShell/10_Settings/__init__.py b/Menu/GameShell/10_Settings/__init__.py index 76b04b0e..60143a9d 100644 --- a/Menu/GameShell/10_Settings/__init__.py +++ b/Menu/GameShell/10_Settings/__init__.py @@ -9,7 +9,6 @@ from datetime import datetime import base64 -from beeprint import pp ## local UI import diff --git a/Menu/GameShell/97_Music Player/mpd_spectrum_page.py b/Menu/GameShell/97_Music Player/mpd_spectrum_page.py index 92bf8995..481ace6e 100644 --- a/Menu/GameShell/97_Music Player/mpd_spectrum_page.py +++ b/Menu/GameShell/97_Music Player/mpd_spectrum_page.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import os import time @@ -9,8 +9,6 @@ import gobject -from beeprint import pp - ## local UI import from UI.constants import Width,Height,ICON_TYPES from UI.page import Page,PageSelector @@ -36,11 +34,11 @@ class PIFI(object): _NUMBER_OF_SELECTED_BINS = 1024 _samples_buffer = None - + def __init__(self): self.sampleSize = self._SAMPLE_SIZE self.samplingRate = self._SAMPLING_RATE - + def GetSpectrum(self,fifoFile,trim_by=4,log_scale=False,div_by=100): try: rawSamples = os.read(fifoFile,self.sampleSize) # will return empty lines (non-blocking) @@ -54,7 +52,7 @@ def GetSpectrum(self,fifoFile,trim_by=4,log_scale=False,div_by=100): if self._samples_buffer == None: return "" - + data = numpy.fromstring(self._samples_buffer, dtype=numpy.int16) data = data * numpy.hanning(len(data)) @@ -69,10 +67,10 @@ def GetSpectrum(self,fifoFile,trim_by=4,log_scale=False,div_by=100): spec_y=spec_y[:i] if div_by: spec_y=spec_y/float(div_by) - + return spec_y - - + + class MPDSpectrumPage(Page): _Icons = {} @@ -88,7 +86,7 @@ class MPDSpectrumPage(Page): _Queue = None _KeepReading = True _ReadingThread = None - + _BGpng = None _BGwidth = 320 _BGheight = 200 @@ -104,7 +102,7 @@ class MPDSpectrumPage(Page): _RollCanvas = None _RollW = 180 _RollH = 18 - + _freq_count = 0 _head_dir = 0 @@ -118,14 +116,14 @@ class MPDSpectrumPage(Page): read_retry = 0 _queue_data = [] _vis_values = [] - + def __init__(self): Page.__init__(self) self._Icons = {} self._CanvasHWND = None self._MyList = [] self._PIFI = PIFI() - + def Init(self): self._PosX = self._Index * self._Screen._Width self._Width = self._Screen._Width @@ -133,14 +131,14 @@ def Init(self): self._CanvasHWND = self._Screen._CanvasHWND self._RollCanvas = pygame.Surface(( self._RollW,self._RollH)) - + """ self._BGpng = IconItem() self._BGpng._ImgSurf = MyIconPool.GiveIconSurface("sheep_bg") self._BGpng._MyType = ICON_TYPES["STAT"] self._BGpng._Parent = self self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0) - + self._SheepHead = IconItem() self._SheepHead._ImgSurf = MyIconPool.GiveIconSurface("sheep_head") self._SheepHead._MyType = ICON_TYPES["STAT"] @@ -153,7 +151,7 @@ def Init(self): self._SheepBody._Parent = self self._SheepBody.Adjust(0,0,self._SheepBodyW,self._SheepBodyH,0) """ - + self._cwp_png = IconItem() self._cwp_png._ImgSurf = MyIconPool.GiveIconSurface("tape") self._cwp_png._MyType = ICON_TYPES["STAT"] @@ -172,7 +170,7 @@ def Init(self): self._time = Label() self._time.SetCanvasHWND(self._CanvasHWND) - self._time.Init("Time:",self._ListFont,MySkinManager.GiveColor('White')) + self._time.Init("Time:",self._ListFont,MySkinManager.GiveColor('White')) self._time2 = Label() @@ -180,22 +178,22 @@ def Init(self): self._time2.Init("00:00-00:00", self._ListFont, MySkinManager.GiveColor('White')) - + self.Start() - + def Start(self): if self._Screen.CurPage() != self: return - + try: self._FIFO = os.open(self._PIFI._MPD_FIFO, os.O_RDONLY | os.O_NONBLOCK) - + t = Thread(target=self.GetSpectrum) t.daemon = True # thread dies with the program t.start() self._ReadingThread = t - + except IOError: print("open %s failed"%self._PIFI._MPD_FIFO) self._FIFO = None @@ -213,17 +211,17 @@ def GetSpectrum(self): os.close(self._FIFO) self._FIFO = os.open(self._PIFI._MPD_FIFO, os.O_RDONLY | os.O_NONBLOCK) self.read_retry = 0 - + self.Playing() - + else: self.read_retry = 0 self._queue_data = raw_samples - self.Playing() - + self.Playing() + def Playing(self): - + self._Screen.Draw() self._Screen.SwapAndShow() @@ -237,7 +235,7 @@ def SgsSmooth(self): origs = self._bby[:] for p in range(0,passes): pivot = int(points/2.0) - + for i in range(0,pivot): self._bby[i] = origs[i] self._bby[ len(origs) -i -1 ] = origs[ len(origs) -i -1 ] @@ -252,40 +250,40 @@ def SgsSmooth(self): if p < (passes - 1): origs = self._bby[:] - + def OnLoadCb(self): if self._Neighbor != None: pass - + if self._KeepReading == False: self._KeepReading = True - + if self._FIFO == None: self.Start() - - + + def KeyDown(self,event): if IsKeyMenuOrB(event.key): try: os.close(self._FIFO) self._FIFO = None - + except Exception, e: print(e) - + self._KeepReading = False self._ReadingThread.join() self._ReadingThread = None - + self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() - + def Draw(self): self.ClearCanvas() self._frames+=1 - + bw = 10 gap = 2 margin_bottom = 72 @@ -296,7 +294,7 @@ def Draw(self): meter_left = meter_left*int(bw+gap) margin_left = meter_left / 2 + gap meterNum = int(meterNum) - + self._cwp_png.NewCoord(43,159) self._cwp_png.Draw() @@ -321,10 +319,10 @@ def Draw(self): else: cur_text = "" end_text = times - + self._time2.SetText(cur_text+"-"+end_text) - - + + self._title.NewCoord(90,167) self._title.Draw() @@ -333,7 +331,7 @@ def Draw(self): self._time2.NewCoord(135,140) self._time2.Draw() - + if self._RollCanvas != None: # self._RollCanvas.fill((111,22,33)) self._RollCanvas.fill(MySkinManager.GiveColor('Black')) @@ -344,38 +342,38 @@ def Draw(self): self._song_title._PosX = 0 else: self._song_title._PosX = 0 - + self._song_title.Draw() - + self._CanvasHWND.blit(self._RollCanvas,(135,165,self._RollW,self._RollH)) - - + + try: spects = self._queue_data if len(spects) == 0: return # print("spects:",spects) - + step = int( round( len( spects ) / meterNum) ) # print(len(spects)) self._bbs = [] a = numpy.logspace(0, 1, num=meterNum,endpoint=True) - + for i in range(0,meterNum): index = int(a[i] * step) total = 0 - + value = spects[index] self._bbs.append(value) - + if len(self._bby) < len(self._bbs): self._bby = self._bbs elif len(self._bby) == len(self._bbs): for i in range(0,len(self._bbs)): self._bby[i] = (self._bby[i]+self._bbs[i])/2 - + self.SgsSmooth() - + for i in range(0,meterNum): value = self._bby[ i ] if math.isnan(value) or math.isinf(value): @@ -384,7 +382,7 @@ def Draw(self): value = value/32768.0 value = value * 123 value = value % (self._Height-gap-margin_bottom) - + if len(self._vis_values) < len(self._bby): self._vis_values.append(value) elif len(self._vis_values) == len(self._bby): @@ -401,7 +399,7 @@ def Draw(self): for i in range(0,meterNum): value = self._vis_values[i] - + if len(self._capYPositionArray) < round(meterNum): self._capYPositionArray.append(value) @@ -411,10 +409,10 @@ def Draw(self): self._capYPositionArray[i] = value pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('White'),(i*(bw+gap)+margin_left,self._Height-gap-self._capYPositionArray[i]-margin_bottom,bw,gap),0) - + pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('White'),(i*(bw+gap)+margin_left,self._Height-value-gap-margin_bottom,bw,value+gap),0) - - self._vis_values[i] -= 2 + + self._vis_values[i] -= 2 + - diff --git a/sys.py/UI/main_screen.py b/sys.py/UI/main_screen.py index 3348c63c..b41c05b1 100644 --- a/sys.py/UI/main_screen.py +++ b/sys.py/UI/main_screen.py @@ -11,8 +11,6 @@ from libs import easing from datetime import datetime -from beeprint import pp - ## local package import from constants import ICON_TYPES,icon_ext,icon_width,icon_height,RUNEVT from icon_item import IconItem diff --git a/sys.py/UI/title_bar.py b/sys.py/UI/title_bar.py index f87e859c..2febafe5 100644 --- a/sys.py/UI/title_bar.py +++ b/sys.py/UI/title_bar.py @@ -185,7 +185,7 @@ def CheckBluetooth(self): self._Icons["bluetooth"]._IconIndex = 2 return else: - out = commands.getstatusoutput("sudo rfkill list | grep hci0 -A 2 | grep yes") + out = commands.getstatusoutput("rfkill list | grep hci0 -A 2 | grep yes") if len(out[1]) > 10: self._Icons["bluetooth"]._IconIndex = 1 return @@ -268,7 +268,7 @@ def Init(self,screen): print("wifi is connected") print( wifi_strength()) else: - out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + out = commands.getstatusoutput('rfkill list | grep yes | cut -d " " -f3') if out[1] == "yes": self._InAirPlaneMode = True else: diff --git a/sys.py/UI/untitled_icon.py b/sys.py/UI/untitled_icon.py index 978edaf8..50d51b5c 100644 --- a/sys.py/UI/untitled_icon.py +++ b/sys.py/UI/untitled_icon.py @@ -48,12 +48,12 @@ def SetWords(self, TwoWords): self._Words[1] = TwoWords[1].lower() self._Text = self._FontObj.render("".join(self._Words),True,self._Color) - + def Draw(self): if self._BG != None: w_ = self._Text.get_width() h_ = self._Text.get_height() - + self._BG.blit(self._Text,midRect(self._Width/2,self._Height/2,w_,h_,self._Width,self._Height)) def Surface(self): @@ -61,4 +61,4 @@ def Surface(self): return self._BG - + diff --git a/sys.py/run.py b/sys.py/run.py index 33e5995e..3de7cd05 100644 --- a/sys.py/run.py +++ b/sys.py/run.py @@ -1,13 +1,13 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import dbus import dbus.service import sys -import commands +import subprocess import logging import errno -from wicd import misc +from wicd import misc ##misc.to_bool ##misc.misc.noneToString ##misc.to_unicode @@ -75,8 +75,8 @@ def gobject_loop(): """ - here to receive dbus signal - """ + here to receive dbus signal + """ try: gobject_main_loop.run() except KeyboardInterrupt: @@ -85,7 +85,7 @@ def gobject_loop(): def GobjectFlashLed1(main_screen): global gobject_flash_led1_counter - + if main_screen._Closed == False: if gobject_flash_led1_counter > 0: try: @@ -102,7 +102,7 @@ def GobjectFlashLed1(main_screen): gobject_flash_led1_counter = 0 return True - + gobject_flash_led1_counter+=1 if gobject_flash_led1_counter == 3: @@ -117,7 +117,7 @@ def GobjectFlashLed1(main_screen): f.write("1") f.truncate() f.close() - + elif gobject_flash_led1_counter == 5: try: @@ -131,21 +131,21 @@ def GobjectFlashLed1(main_screen): f.write("0") f.truncate() f.close() - + if gobject_flash_led1_counter == 11: gobject_flash_led1_counter = 1 - + return True - + def RestoreLastBackLightBrightness(main_screen): global last_brt,passout_time_stage,gobject_flash_led1 passout_time_stage = 0 main_screen._TitleBar._InLowBackLight = -1 main_screen._Closed = False - - + + if last_brt == -1: return True @@ -158,14 +158,14 @@ def RestoreLastBackLightBrightness(main_screen): with f: content = f.readlines() content = [x.strip() for x in content] - brt=int(content[0]) + brt=int(content[0]) if brt < last_brt: f.seek(0) f.write(str( last_brt )) f.truncate() f.close() last_brt = -1 - else: + else: f.close() try: @@ -179,23 +179,23 @@ def RestoreLastBackLightBrightness(main_screen): f.write("0") f.truncate() f.close() - + if main_screen._CounterScreen._Counting==True: main_screen._CounterScreen.StopCounter() main_screen.Draw() main_screen.SwapAndShow() return False - + return True def InspectionTeam(main_screen): global everytime_keydown,last_brt,passout_time_stage,gobject_flash_led1 - + cur_time = time.time() time_1 = config.PowerLevels[config.PowerLevel][0] time_2 = config.PowerLevels[config.PowerLevel][1] time_3 = config.PowerLevels[config.PowerLevel][2] - + if cur_time - everytime_keydown > time_1 and passout_time_stage == 0: print("timeout, dim screen %d" % int(cur_time - everytime_keydown)) @@ -221,12 +221,12 @@ def InspectionTeam(main_screen): main_screen._TitleBar._InLowBackLight = 0 if time_2 != 0: - passout_time_stage = 1 # next + passout_time_stage = 1 # next everytime_keydown = cur_time - + elif cur_time - everytime_keydown > time_2 and passout_time_stage == 1: print("timeout, close screen %d" % int(cur_time - everytime_keydown)) - + try: f = open(config.BackLight,"r+") except IOError: @@ -239,17 +239,17 @@ def InspectionTeam(main_screen): f.truncate() f.close() - + main_screen._TitleBar._InLowBackLight = 0 main_screen._Closed = True if time_3 != 0: passout_time_stage = 2 # next - + everytime_keydown = cur_time - + elif cur_time - everytime_keydown > time_3 and passout_time_stage == 2: print("Power Off counting down") - + try: f = open(config.BackLight,"r+") except IOError: @@ -261,26 +261,26 @@ def InspectionTeam(main_screen): f.write(str(brt)) f.truncate() f.close() - + main_screen._CounterScreen.Draw() main_screen._CounterScreen.SwapAndShow() main_screen._CounterScreen.StartCounter() - + main_screen._TitleBar._InLowBackLight = 0 passout_time_stage = 4 - + return True def RecordKeyDns(thekey,main_screen): global Keys,crt_screen - + if len(Keys) < 10: Keys.append(thekey) else: Keys = [] Keys.append(thekey) - + keys = ''.join(map(str,Keys)) #print(keys) if keys == "273273274274276276275275106107":##uuddllrrab @@ -288,7 +288,7 @@ def RecordKeyDns(thekey,main_screen): crt_screen.SwapAndShow() main_screen._TitleBar._InLowBackLight = 0 ##pause titlebar drawing return True - + return False @@ -310,19 +310,19 @@ def release_self_fds(): if err.errno != errno.ENOENT: raise ret[int(num)] = path - + for key in ret: if ret[key] != None and isinstance(ret[key], str): for i in fds_flags: if i in ret[key]: os.close(key) break - return ret + return ret + - def event_process(event,main_screen): global sound_patch - global everytime_keydown + global everytime_keydown if event != None: pygame.event.clear() if event.type == pygame.ACTIVEEVENT: @@ -330,7 +330,7 @@ def event_process(event,main_screen): return if event.type == pygame.QUIT: exit() - if event.type == RUNEVT: + if event.type == RUNEVT: if config.DontLeave==True: os.chdir(GetExePath()) os.system( "/bin/sh -c "+event.message) @@ -339,18 +339,18 @@ def event_process(event,main_screen): if on_exit_cb != None: if callable( on_exit_cb ): main_screen.OnExitCb(event) - + pygame.quit() gobject_main_loop.quit() os.chdir( GetExePath()) - + endpos = len(event.message) space_break_pos = endpos for i in range(0,endpos): if event.message[i] == "/" and event.message[i-1] == " " and i > 6: space_break_pos = i-1 break - + exec_app_cmd = "cd "+os.path.dirname(event.message[:space_break_pos])+";" exec_app_cmd += event.message exec_app_cmd += "; sync & cd "+GetExePath()+"; exec python "+myscriptname @@ -376,8 +376,8 @@ def event_process(event,main_screen): if event.message[i] == "/" and event.message[i-1] == " " and i > 6: space_break_pos = i-1 break - - exec_app_cmd = "cd "+os.path.dirname(event.message[:space_break_pos])+";" + + exec_app_cmd = "cd "+os.path.dirname(event.message[:space_break_pos])+";" exec_app_cmd += event.message exec_app_cmd += "; sync & cd "+GetExePath()+"; exec python "+myscriptname print(exec_app_cmd) @@ -407,10 +407,10 @@ def event_process(event,main_screen): return if event.type == POWEROPT: everytime_keydown = time.time() - + return if event.type == pygame.KEYUP: - + pygame.event.clear(pygame.KEYDOWN) return if event.type == pygame.KEYDOWN: @@ -423,7 +423,7 @@ def event_process(event,main_screen): if on_exit_cb != None: if callable( on_exit_cb ): main_screen.OnExitCb(event) - + gobject_main_loop.quit() exit() @@ -432,25 +432,25 @@ def event_process(event,main_screen): main_screen.Draw() sound_patch.VolumeUp() sound_patch.Draw() - + main_screen.SwapAndShow() #pygame.time.delay(200) #main_screen.Draw() #main_screen.SwapAndShow() - + if event.key == pygame.K_KP_MINUS: if main_screen._CurrentPage._Name != "Sound volume": main_screen.Draw() - + sound_patch.VolumeDown() sound_patch.Draw() - + main_screen.SwapAndShow() #pygame.time.delay(200) #main_screen.Draw() #main_screen.SwapAndShow() - - + + ########################################################### if event.key == pygame.K_ESCAPE: pygame.event.clear() @@ -460,27 +460,27 @@ def event_process(event,main_screen): if key_down_cb != None: if callable( key_down_cb ): main_screen.KeyDown(event) - + main_screen._LastKeyDown = everytime_keydown return - + def gobject_pygame_event_poll_timer(main_screen): - + event = pygame.event.poll() event_process(event,main_screen) InspectionTeam(main_screen) - - return True + + return True def gobject_pygame_event_timer(main_screen): global sound_patch - + for event in pygame.event.get(): event_process(event,main_screen) - - return True + + return True @misc.threaded @@ -506,17 +506,17 @@ def socket_thread(main_screen): if current_page_key_down_cb != None: if callable( current_page_key_down_cb ): main_screen._CurrentPage.KeyDown(escevent) - + if tokens[0].lower() == "quit": #eg: echo "quit" | socat - UNIX-CONNECT:/tmp/gameshell conn.close() on_exit_cb = getattr(main_screen,"OnExitCb",None) if on_exit_cb != None: if callable( on_exit_cb ): main_screen.OnExitCb(None) - + gobject_main_loop.quit() exit() - + if tokens[0].lower() == "keydown": ## simulate keydown event everytime_keydown = time.time() if RestoreLastBackLightBrightness(main_screen) == False: @@ -529,10 +529,10 @@ def socket_thread(main_screen): if current_page_key_down_cb != None: if callable( current_page_key_down_cb ): main_screen._CurrentPage.KeyDown(escevent) - - if main_screen._MyPageStack.Length() == 0: ## on Top Level + + if main_screen._MyPageStack.Length() == 0: ## on Top Level break - + if main_screen._CurrentPage._Name == "GameShell": for i in main_screen._CurrentPage._Icons: if i._MyType == ICON_TYPES["FUNC"]: @@ -540,11 +540,11 @@ def socket_thread(main_screen): api_cb = getattr(i._CmdPath,"API",None) if api_cb != None: if callable(api_cb): - i._CmdPath.API(main_screen) - + i._CmdPath.API(main_screen) + def big_loop(): global sound_patch,gobject_flash_led1 - + title_bar = TitleBar() title_bar.Init(screen) foot_bar = FootBar() @@ -552,20 +552,20 @@ def big_loop(): main_screen = MainScreen() main_screen._HWND = screen - main_screen._TitleBar = title_bar + main_screen._TitleBar = title_bar main_screen._FootBar = foot_bar main_screen.Init() - + main_screen.ReadTheDirIntoPages("../Menu",0,None) - main_screen.ReadTheDirIntoPages("/home/cpi/apps/Menu",1,main_screen._Pages[ len(main_screen._Pages) -1]) + main_screen.ReadTheDirIntoPages("/home/arthur/local/clockworkpi/Menu",1,main_screen._Pages[ len(main_screen._Pages) -1]) main_screen.ReunionPagesIcons() - + main_screen.FartherPages() - + title_bar._SkinManager = main_screen._SkinManager foot_bar._SkinManager = main_screen._SkinManager - + sound_patch = SoundPatch() sound_patch._Parent = main_screen sound_patch.Init() @@ -577,51 +577,51 @@ def big_loop(): #gobject.timeout_add(DT,gobject_pygame_event_timer,main_screen) gobject_flash_led1 = gobject.timeout_add(200,GobjectFlashLed1,main_screen) - + gobject.timeout_add(DT,gobject_pygame_event_poll_timer,main_screen) gobject.timeout_add(3000,title_bar.GObjectRoundRobin) socket_thread(main_screen) - + gobject_loop() - + ###MAIN()### if __name__ == '__main__': - + os.environ['SDL_VIDEO_CENTERED'] = '1' X_center_mouse() - + os.chdir( os.path.dirname(os.path.realpath(__file__)) ) - + SCREEN_SIZE = (Width,Height) screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32) - pygame.event.set_allowed(None) + pygame.event.set_allowed(None) pygame.event.set_allowed([pygame.KEYDOWN,pygame.KEYUP,RUNEVT,RUNSYS,POWEROPT,RESTARTUI,RUNSH]) - + pygame.key.set_repeat(DT+DT*6+DT/2, DT+DT*3+DT/2) - + MyIconPool.Init() - + setup_dbus() gobject.threads_init() - + gobject_main_loop = gobject.MainLoop() # if pygame.display.get_active() == True: # print("I am actived") - + if pygame.image.get_extended() == False: print("This pygame does not support PNG") exit() - + crt_screen = CreateByScreen() crt_screen.Init() - crt_screen._HWND = screen - + crt_screen._HWND = screen + big_loop() - +