add widget.py

This commit is contained in:
cuu
2019-01-15 16:37:15 +08:00
parent c641c8d84a
commit 7e75d4856b
25 changed files with 213 additions and 356 deletions

View File

@@ -177,30 +177,6 @@ class BleInfoPage(Page):
li._PosX = 2
self._MyList.append(li)
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 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 TryToForget(self):
global adapter
proxy_obj = bus.get_object("org.bluez", self._Path)
@@ -336,10 +312,10 @@ class BleListSelector(PageSelector):
def Draw(self):
idx = self._Parent._PsIndex
if idx < len( self._Parent._WirelessList):
x = self._Parent._WirelessList[idx]._PosX+2
y = self._Parent._WirelessList[idx]._PosY+1
h = self._Parent._WirelessList[idx]._Height -3
if idx < len( self._Parent._MyList):
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
@@ -367,7 +343,7 @@ class BleListMessageBox(Label):
class BluetoothPage(Page):
_WirelessList = []
_MyList = []
#Wicd dbus part
_Adapter = None
_Dbus = None
@@ -398,7 +374,7 @@ class BluetoothPage(Page):
def __init__(self):
Page.__init__(self)
self._WirelessList = []
self._MyList = []
self._CanvasHWND = None
def ShowBox(self,msg):
@@ -520,10 +496,10 @@ class BluetoothPage(Page):
def TryConnect(self):
global bus
if self._PsIndex >= len(self._WirelessList):
if self._PsIndex >= len(self._MyList):
return
cur_li = self._WirelessList[self._PsIndex]
cur_li = self._MyList[self._PsIndex]
print(cur_li._Path)
if "Connected" in cur_li._Atts:
@@ -562,7 +538,7 @@ class BluetoothPage(Page):
def GenNetworkList(self):
self._WirelessList = []
self._MyList = []
start_x = 0
start_y = 0
@@ -586,7 +562,7 @@ class BluetoothPage(Page):
ni.Init(v,self._Devices[v])
counter += 1
self._WirelessList.append(ni)
self._MyList.append(ni)
self._PsIndex = 0
@@ -631,31 +607,7 @@ class BluetoothPage(Page):
self.GenNetworkList()
else:
self._Offline = True
def ScrollUp(self):
if len(self._WirelessList) == 0:
return
self._PsIndex-=1
if self._PsIndex < 0:
self._PsIndex = 0
cur_ni = self._WirelessList[self._PsIndex]
if cur_ni._PosY < 0:
for i in range(0,len(self._WirelessList)):
self._WirelessList[i]._PosY += self._WirelessList[i]._Height
def ScrollDown(self):
if len(self._WirelessList) == 0:
return
self._PsIndex+=1
if self._PsIndex >= len(self._WirelessList):
self._PsIndex = len(self._WirelessList) -1
cur_ni = self._WirelessList[self._PsIndex]
if cur_ni._PosY + cur_ni._Height > self._Height:
for i in range(0,len(self._WirelessList)):
self._WirelessList[i]._PosY -= self._WirelessList[i]._Height
def KeyDown(self,event):
if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
@@ -698,13 +650,13 @@ class BluetoothPage(Page):
self.Rescan()
if event.key == CurKeys["Y"]:
if len(self._WirelessList) == 0:
if len(self._MyList) == 0:
return
if self._Offline == True:
return
self._InfoPage._AList = self._WirelessList[self._PsIndex]._Atts
self._InfoPage._Path = self._WirelessList[self._PsIndex]._Path
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()
@@ -715,23 +667,23 @@ class BluetoothPage(Page):
def Draw(self):
self.ClearCanvas()
if len(self._WirelessList) == 0:
if len(self._MyList) == 0:
return
if len(self._WirelessList) * NetItem._Height > self._Height:
if len(self._MyList) * NetItem._Height > self._Height:
self._Ps._Width = self._Width - 11
self._Ps.Draw()
for i in self._WirelessList:
for i in self._MyList:
i.Draw()
self._Scroller.UpdateSize( len(self._WirelessList)*NetItem._Height, self._PsIndex*NetItem._Height)
self._Scroller.UpdateSize( len(self._MyList)*NetItem._Height, self._PsIndex*NetItem._Height)
self._Scroller.Draw()
else:
self._Ps._Width = self._Width
self._Ps.Draw()
for i in self._WirelessList:
for i in self._MyList:
i.Draw()

View File

@@ -3,7 +3,7 @@ import os
import pygame
#import math
#mport subprocess
import glob
import platform
#from beeprint import pp
from libs.roundrects import aa_round_rect
@@ -24,8 +24,9 @@ class APIOBJ(object):
main_screen._MsgBox.Draw()
main_screen.SwapAndShow()
pygame.time.delay(300)
os.system("sed -i s/launcher/launchergo/g ~/.bashrc" )
os.system("sudo reboot")
if "arm" in platform.machine():
os.system("sed -i s/launcher/launchergo/g ~/.bashrc" )
os.system("sudo reboot")
OBJ = APIOBJ()
def Init(main_screen):

View File

@@ -168,29 +168,6 @@ class NotificationPage(Page):
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

View File

@@ -402,30 +402,6 @@ class PowerOptionsPage(Page):
self._InfoPage._Screen = self._Screen
self._InfoPage._Name = "Power option detail"
self._InfoPage.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:

View File

@@ -200,35 +200,6 @@ class TimezoneListPage(Page):
self._Scroller._PosY = 2
self._Scroller.Init()
def ScrollUp(self,Step=1):
if len(self._MyList) == 0:
return
tmp = self._PsIndex
self._PsIndex -= Step
if self._PsIndex < 0:
self._PsIndex = 0
dy = tmp-self._PsIndex
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*dy
def ScrollDown(self,Step=1):
if len(self._MyList) == 0:
return
tmp = self._PsIndex
self._PsIndex +=Step
if self._PsIndex >= len(self._MyList):
self._PsIndex = len(self._MyList) -1
dy = self._PsIndex - tmp
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*dy
def Click(self):
if len(self._MyList) == 0:
return
@@ -275,12 +246,12 @@ class TimezoneListPage(Page):
self._Screen.SwapAndShow()
if event.key == CurKeys["Right"]:
self.ScrollDown(Step=5)
self.FScrollDown(Step=5)
self._Screen.Draw()
self._Screen.SwapAndShow()
if event.key == CurKeys["Left"]:
self.ScrollUp(Step=5)
self.FScrollUp(Step=5)
self._Screen.Draw()
self._Screen.SwapAndShow()

View File

@@ -10,7 +10,7 @@ from UI.icon_item import IconItem
from UI.multi_icon_item import MultiIconItem
from UI.icon_pool import MyIconPool
from UI.skin_manager import MySkinManager
from UI.widget import Widget
class NetItemMultiIcon(MultiIconItem):
_CanvasHWND = None
@@ -33,10 +33,7 @@ class NetItemIcon(IconItem):
self._CanvasHWND.blit(self._ImgSurf,(self._PosX,self._PosY+(self._Parent._Height-self._Height)/2,self._Width,self._Height))
class NetItem(object):
_PosX = 0
_PosY = 0
_Width = 0
class NetItem(Widget):
_Height = 30
_Bssid="" # 50:3A:A0:51:18:3C

View File

@@ -142,30 +142,6 @@ class WifiInfoPage(Page):
self._DisconnectConfirmPage._Name = "Confirm Disconnect"
self._DisconnectConfirmPage._Parent = self
self._DisconnectConfirmPage.Init()
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 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 Click(self):
cur_li = self._MyList[self._PsIndex]
@@ -230,9 +206,7 @@ class WifiListSelector(PageSelector):
_BackgroundColor = MySkinManager.GiveColor('Front')
def __init__(self):
self._PosX = 0
self._PosY = 0
self._Height = 0
pass
def AnimateDraw(self,x2,y2):
pass
@@ -240,10 +214,10 @@ class WifiListSelector(PageSelector):
def Draw(self):
idx = self._Parent._PsIndex
if idx < len( self._Parent._WirelessList):
x = self._Parent._WirelessList[idx]._PosX+11
y = self._Parent._WirelessList[idx]._PosY+1
h = self._Parent._WirelessList[idx]._Height -3
if idx < len( self._Parent._MyList):
x = self._Parent._MyList[idx]._PosX+11
y = self._Parent._MyList[idx]._PosY+1
h = self._Parent._MyList[idx]._Height -3
self._PosX = x
self._PosY = y
@@ -270,7 +244,7 @@ class WifiListMessageBox(Label):
self._CanvasHWND.blit(my_text,(x,y,w,h))
class WifiList(Page):
_WirelessList = []
_MyList = []
#Wicd dbus part
_Wireless = None
_Daemon = None
@@ -300,7 +274,7 @@ class WifiList(Page):
def __init__(self):
Page.__init__(self)
self._WirelessList = []
self._MyList = []
self._CanvasHWND = None
def ShowBox(self,msg):
@@ -317,7 +291,7 @@ class WifiList(Page):
self._Screen.SwapAndShow()
def GenNetworkList(self):
self._WirelessList = []
self._MyList = []
start_x = 0
start_y = 0
@@ -336,7 +310,7 @@ class WifiList(Page):
#ni._Bssid = self._Wireless.GetWirelessProperty(network_id,"bssid")
ni.Init(network_id,is_active)
self._WirelessList.append(ni)
self._MyList.append(ni)
self._PsIndex = 0
@@ -397,8 +371,8 @@ class WifiList(Page):
if info != None:
if len(info) > 3:
_id = int(info[3])
if _id < len(self._WirelessList):
self._WirelessList[_id].UpdateStrenLabel( str(info[2]))
if _id < len(self._MyList):
self._MyList[_id].UpdateStrenLabel( str(info[2]))
self._PrevWicdState = state
@@ -521,7 +495,7 @@ class WifiList(Page):
netid = self._PsIndex
for i,v in enumerate(self._WirelessList):
for i,v in enumerate(self._MyList):
if v._Bssid == self._CurBssid:
netid = i
break
@@ -550,7 +524,7 @@ class WifiList(Page):
self.ShowBox(MyLangManager.Tr("Connecting"))
self._WirelessList[netid].Connect()
self._MyList[netid].Connect()
print("after Connect")
self.UpdateStatus()
@@ -584,31 +558,6 @@ class WifiList(Page):
"""
return results
def ScrollUp(self):
if len(self._WirelessList) == 0:
return
self._PsIndex-=1
if self._PsIndex < 0:
self._PsIndex = 0
cur_ni = self._WirelessList[self._PsIndex]
if cur_ni._PosY < 0:
for i in range(0,len(self._WirelessList)):
self._WirelessList[i]._PosY += self._WirelessList[i]._Height
def ScrollDown(self):
if len(self._WirelessList) == 0:
return
self._PsIndex+=1
if self._PsIndex >= len(self._WirelessList):
self._PsIndex = len(self._WirelessList) -1
cur_ni = self._WirelessList[self._PsIndex]
if cur_ni._PosY + cur_ni._Height > self._Height:
for i in range(0,len(self._WirelessList)):
self._WirelessList[i]._PosY -= self._WirelessList[i]._Height
def AbortedAndReturnToUpLevel(self):
self.HideBox()
self._Screen._FootBar.ResetNavText()
@@ -657,13 +606,13 @@ class WifiList(Page):
self._Screen.SwapAndShow()
if event.key == CurKeys["Enter"]: ## enter to set password,enter is B on GM
if len(self._WirelessList) == 0:
if len(self._MyList) == 0:
return
self._CurBssid = self._WirelessList[self._PsIndex]._Bssid
self._CurBssid = self._MyList[self._PsIndex]._Bssid
wicd_wirelss_encrypt_pwd = self.GetWirelessEncrypt(self._PsIndex)
if self._WirelessList[self._PsIndex]._IsActive:
if self._MyList[self._PsIndex]._IsActive:
self.ShowBox( self._Wireless.GetWirelessIP('') )
else:
self._Screen.PushCurPage()
@@ -693,7 +642,7 @@ class WifiList(Page):
self.Rescan(False)
if event.key == CurKeys["Y"]:
if len(self._WirelessList) == 0:
if len(self._MyList) == 0:
return
self._InfoPage._NetworkId = self._PsIndex
@@ -762,13 +711,13 @@ class WifiList(Page):
def Draw(self):
self.ClearCanvas()
if len(self._WirelessList) == 0:
if len(self._MyList) == 0:
return
self._Ps.Draw()
for i in self._WirelessList:
for i in self._MyList:
i.Draw()
self._Scroller.UpdateSize( len(self._WirelessList)*NetItem._Height, self._PsIndex*NetItem._Height)
self._Scroller.UpdateSize( len(self._MyList)*NetItem._Height, self._PsIndex*NetItem._Height)
self._Scroller.Draw()

View File

@@ -104,30 +104,6 @@ class ListPage(Page):
self._Scroller._PosY = 2
self._Scroller.Init()
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 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 Click(self):
cur_li = self._MyList[self._PsIndex]
if cur_li._LinkObj != None:

View File

@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
import pygame
import validators
from UI.constants import Width,Height,ICON_TYPES
from UI.simple_name_space import SimpleNamespace
from UI.page import Page
from UI.label import Label
from UI.fonts import fonts
from UI.icon_item import IconItem
from UI.icon_pool import MyIconPool
from UI.keys_def import CurKeys
from UI.skin_manager import MySkinManager
from UI.lang_manager import MyLangManager
from UI.textarea import Textarea
class Textbulletinboard(Textarea):
def Draw(self):
pass
class NOPICOPage(Page):
_FootMsg = ["Nav","","","Back",""]
_TextColor = MySkinManager.GiveColor('Text')
_DrawOnce = False
def KeyDown(self,event):
if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
if self._FootMsg[3] == "Back":
self.ReturnToUpLevelPage()
self._Screen.Draw()
self._Screen.SwapAndShow()
return
def Draw(self):
if self._DrawOnce == False:
self.ClearCanvas()
self._DrawOnce = True
class PICO8Page(Page):
_FootMsg = ["Nav","","","Back",""]
_MyList = []
_ListFontObj = fonts["varela13"]
_AList = {}
_Labels = {}
_Coords = {}
_URLColor = MySkinManager.GiveColor('URL')
_TextColor = MySkinManager.GiveColor('Text')
_Scrolled = 0
_PngSize = {}
_DrawOnce = False
_Scroller = None
_Scrolled = 0
class APIOBJ(object):
_Page = None
def __init__(self):
pass
def Init(self,main_screen):
pass
def API(self,main_screen):
if main_screen !=None:
main_screen._MsgBox.SetText("Starting pico-8")
main_screen._MsgBox.Draw()
main_screen.SwapAndShow()
pygame.time.delay(300)
OBJ = APIOBJ()
def Init(main_screen):
OBJ.Init(main_screen)
def API(main_screen):
OBJ.API(main_screen)

View File

@@ -0,0 +1,2 @@
a3f2995cf117499f880bd964d6a0e1f2 pico-8_0.1.11g_raspi.zip
6726141c784afd4a41be6b7414c1b932 pico-8_0.1.11g_amd64.zip

View File

@@ -196,35 +196,6 @@ class MusicLibListPage(Page):
self._Scroller._PosY = 2
self._Scroller.Init()
def ScrollUp(self,Step=1):
if len(self._MyList) == 0:
return
tmp = self._PsIndex
self._PsIndex -= Step
if self._PsIndex < 0:
self._PsIndex = 0
dy = tmp-self._PsIndex
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*dy
def ScrollDown(self,Step=1):
if len(self._MyList) == 0:
return
tmp = self._PsIndex
self._PsIndex +=Step
if self._PsIndex >= len(self._MyList):
self._PsIndex = len(self._MyList) -1
dy = self._PsIndex - tmp
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*dy
def Click(self):
if len(self._MyList) == 0:
return
@@ -272,12 +243,12 @@ class MusicLibListPage(Page):
"""
if event.key == CurKeys["Right"]:
self.ScrollDown(Step=5)
self.FScrollDown(Step=5)
self._Screen.Draw()
self._Screen.SwapAndShow()
if event.key == CurKeys["Left"]:
self.ScrollUp(Step=5)
self.FScrollUp(Step=5)
self._Screen.Draw()
self._Screen.SwapAndShow()
"""