class DownloadProcessPage(Page): _FootMsg = ["Nav.","","","Back",""] _Downloader = None _DownloaderTimer = -1 _Value = 0 _URL = "" _DST_DIR = "" _PngSize = {} _FileNameLabel = None _SizeLabel = None _URLColor = MySkinManager.GiveColor('URL') _TextColor = MySkinManager.GiveColor('Text') def __init__(self): Page.__init__(self) self._Icons = {} self._CanvasHWND = None def Init(self): self._PosX = self._Index * self._Screen._Width self._Width = self._Screen._Width self._Height = self._Screen._Height self._CanvasHWND = self._Screen._CanvasHWND self._PngSize["bg"] = (48,79) self._PngSize["needwifi_bg"] = (253,132) bgpng = IconItem() bgpng._ImgSurf = MyIconPool._Icons["rom_download"] bgpng._MyType = ICON_TYPES["STAT"] bgpng._Parent = self bgpng.Adjust(0,0,self._PngSize["bg"][0],self._PngSize["bg"][1],0) self._Icons["bg"] = bgpng needwifi_bg = IconItem() needwifi_bg._ImgSurf = MyIconPool._Icons["needwifi_bg"] needwifi_bg._MyType = ICON_TYPES["STAT"] needwifi_bg._Parent = self needwifi_bg.Adjust(0,0,self._PngSize["needwifi_bg"][0],self._PngSize["needwifi_bg"][1],0) self._Icons["needwifi_bg"] = needwifi_bg self._FileNameLabel = Label() self._FileNameLabel.SetCanvasHWND(self._CanvasHWND) self._FileNameLabel.Init("", fonts["varela12"]) self._SizeLabel = Label() self._SizeLabel.SetCanvasHWND(self._CanvasHWND) self._SizeLabel.Init("0/0Kb",fonts["varela12"]) self._SizeLabel.SetColor( self._URLColor ) def OnExitCb(self,event): print("DownloadProcessPage OnExitCb") if self._Downloader == None: return try: self._Downloader.stop() except: pass return def GObjectUpdateProcessInterval(self): if self._Screen.CurPage() == self: if self._Downloader.isFinished(): if self._Downloader.isSuccessful(): print("Success!") # Do something with obj.get_dest() filename = os.path.basename(self._Downloader.get_dest()) cur_dir = os.getcwd() if filename.endswith(".zip"): os.chdir(self._DST_DIR) os.system( "unzip " + filename ) elif filename.endswith(".zsync"): os.chdir(self._DST_DIR) os.system( "rm -rf " + filename) elif filename.endswith(".tar.xz"): os.chdir(self._DST_DIR) os.system( "tar xf " + filename) os.system( "rm -rf " + filename) os.chdir(cur_dir) self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() else: print("Download failed with the following exceptions:") for e in self._Downloader.get_errors(): print(unicode(e)) try: self._Downloader.stop() except: pass self._Screen._MsgBox.SetText("DownloadFailed") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() return False else: self._Value = self._Downloader.get_progress() filename = os.path.basename(self._Downloader.get_dest()) self._FileNameLabel.SetText( filename ) downloaded = self._Downloader.progress["downloaded"] total = self._Downloader.progress["total"] downloaded = downloaded/1000.0/1000.0 total = total/1000.0/1000.0 self._SizeLabel.SetText( "%.2f" % downloaded+"/"+ "%.2f" % total +"Mb") print("Progress: %d%%" % (self._Value)) self._Screen.Draw() self._Screen.SwapAndShow() return True else: return False def StartDownload(self,url,dst_dir): if is_wifi_connected_now() == False: return if validators.url(url) and os.path.isdir(dst_dir): self._URL = url self._DST_DIR = dst_dir else: self._Screen._MsgBox.SetText("Invaid") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() print("url or dst dir error") return self._Downloader = Download(url,dst_dir,None) self._Downloader.start() self._DownloaderTimer = gobject.timeout_add(100, self.GObjectUpdateProcessInterval) def KeyDown(self,event): if IsKeyMenuOrB(event.key): gobject.source_remove(self._DownloaderTimer) self._DownloaderTimer = -1 if self._Downloader != None: try: self._Downloader.stop() except: print("user canceled ") self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() def Draw(self): self.ClearCanvas() if is_wifi_connected_now() == False: self._Icons["needwifi_bg"].NewCoord(self._Width/2, self._Height/2) self._Icons["needwifi_bg"].Draw() return self._Icons["bg"].NewCoord(self._Width/2,self._Height/2-20) self._Icons["bg"].Draw() percent = self._Value if percent < 10: percent = 10 rect_ = midRect(self._Width/2,self._Height/2+33,170,17, Width,Height) aa_round_rect(self._CanvasHWND,rect_,MySkinManager.GiveColor('TitleBg'),5,0,MySkinManager.GiveColor('TitleBg')) rect2 = midRect(self._Width/2,self._Height/2+33,int(170*(percent/100.0)),17, Width,Height) rect2.left = rect_.left rect2.top = rect_.top aa_round_rect(self._CanvasHWND,rect2,MySkinManager.GiveColor('Front'),5,0,MySkinManager.GiveColor('Front')) rect3 = midRect(self._Width/2,self._Height/2+53,self._FileNameLabel._Width, self._FileNameLabel._Height,Width,Height) rect4 = midRect(self._Width/2,self._Height/2+70,self._SizeLabel._Width, self._SizeLabel._Height,Width,Height) self._FileNameLabel.NewCoord(rect3.left,rect3.top) self._SizeLabel.NewCoord(rect4.left, rect4.top) self._FileNameLabel.Draw() self._SizeLabel.Draw()
class LoadHousePage(Page): _FootMsg = ["Nav.", "", "", "Back", "Cancel"] _Value = 0 _URL = None _ListFontObj = MyLangManager.TrFont("varela18") _URLColor = MySkinManager.GiveColor('URL') _TextColor = MySkinManager.GiveColor('Text') _Caller = None _img = None _Downloader = None _DownloaderTimer = -1 def __init__(self): Page.__init__(self) self._Icons = {} self._CanvasHWND = None def Init(self): self._PosX = self._Index * self._Screen._Width self._Width = self._Screen._Width self._Height = self._Screen._Height self._CanvasHWND = self._Screen._CanvasHWND self._LoadingLabel = Label() self._LoadingLabel.SetCanvasHWND(self._CanvasHWND) self._LoadingLabel.Init("Loading", self._ListFontObj) self._LoadingLabel.SetColor(self._TextColor) def OnLoadCb(self): if self._URL is None: return self._img = None self.ClearCanvas() self._Screen.Draw() self._Screen.SwapAndShow() filename = self._URL.split("/")[-1].strip() local_dir = self._URL.split("raw.githubusercontent.com") if len(local_dir) > 1: menu_file = local_dir[1] local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'), menu_file) if FileExists(local_menu_file): #load json with open(local_menu_file) as json_file: try: local_menu_json = json.load(json_file) self._Caller._MyStack.Push(local_menu_json["list"]) except: pass self.Leave() else: self._Downloader = Download(self._URL, "/tmp", None) self._Downloader.start() self._DownloaderTimer = gobject.timeout_add( 400, self.GObjectUpdateProcessInterval) def GObjectUpdateProcessInterval(self): ret = True if self._Screen.CurPage() == self: if self._Downloader._stop == True: ret = False dst_filename = self._Downloader.get_dest() if self._Downloader.isFinished(): if self._Downloader.isSuccessful(): filename = self._URL.split("/")[-1].strip() local_dir = self._URL.split("raw.githubusercontent.com") menu_file = local_dir[1] local_menu_file = "%s/aria2download%s" % ( os.path.expanduser('~'), menu_file) dl_file = os.path.join("/tmp", filename) if not os.path.exists(os.path.dirname(local_menu_file)): os.makedirs(os.path.dirname(local_menu_file)) copyfile(dl_file, local_menu_file) with open(local_menu_file) as json_file: try: local_menu_json = json.load(json_file) self._Caller._MyStack.Push(local_menu_json["list"]) except: pass ret = False self.Leave() else: self._Screen._MsgBox.SetText("Fetch house failed") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() ret = False return ret else: return False def Leave(self): if self._DownloaderTimer != -1: gobject.source_remove(self._DownloaderTimer) self._DownloaderTimer = -1 if self._Downloader != None: try: self._Downloader.stop() except: print("user canceled ") self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() self._URL = None def KeyDown(self, event): if IsKeyMenuOrB(event.key): self.Leave() def Draw(self): self.ClearCanvas() self._LoadingLabel.NewCoord((Width - self._LoadingLabel._Width) / 2, (Height - 44) / 2) self._LoadingLabel.Draw() if self._img is not None: self._CanvasHWND.blit( self._img, midRect(Width / 2, (Height - 44) / 2, pygame.Surface.get_width(self._img), pygame.Surface.get_height(self._img), Width, Height - 44))
def Init(self, i, is_active): # Pick which strength measure to use based on what the daemon says # gap allocates more space to the first module if self._Parent._Daemon.GetSignalDisplayType() == 0: strenstr = 'quality' gap = 4 # Allow for 100% else: strenstr = 'strength' gap = 7 # -XX dbm = 7 self._NetId = i # All of that network property stuff self._Stren = self._Parent._Daemon.FormatSignalForPrinting( str( self._Parent._Wireless.GetWirelessProperty( self._NetId, strenstr))) self._Essid = self._Parent._Wireless.GetWirelessProperty( self._NetId, 'essid') self._Bssid = self._Parent._Wireless.GetWirelessProperty( self._NetId, 'bssid') if self._Parent._Wireless.GetWirelessProperty(self._NetId, 'encryption'): self._Encrypt = \ self._Parent._Wireless.GetWirelessProperty(self._NetId, 'encryption_method') else: self._Encrypt = 'Unsecured' self._Mode = \ self._Parent._Wireless.GetWirelessProperty(self._NetId, 'mode') # Master, Ad-Hoc self._Channel = self._Parent._Wireless.GetWirelessProperty( self._NetId, 'channel') theString = ' %-*s %25s %9s %17s %6s %4s' % \ (gap, self._Stren, self._Essid, self._Encrypt, self._Bssid, self._Mode, self._Channel) if is_active: theString = ">> " + theString[1:] self.SetActive(is_active) essid_label = Label() essid_label._PosX = 36 #essid_label._PosY = self._PosY + (self._Height - self._FontObj.render(self._Essid,True,(83,83,83)).get_height())/2 essid_label._CanvasHWND = self._Parent._CanvasHWND if len(self._Essid) > 19: essid_ = self._Essid[:20] else: essid_ = self._Essid essid_label.Init(essid_, self._FontObj) self._Labels["essid"] = essid_label stren_label = Label() #stren_label._PosY = self._PosY + (self._Height - self._FontObj.render(self._Stren,True,(83,83,83)).get_height())/2 stren_label._CanvasHWND = self._Parent._CanvasHWND stren_label.Init(self._Stren, self._FontObj) stren_label._PosX = self._Width - 23 - stren_label.Width() - 2 self._Labels["stren"] = stren_label lock_icon = NetItemIcon() lock_icon._ImgSurf = MyIconPool._Icons["lock"] lock_icon._CanvasHWND = self._Parent._CanvasHWND lock_icon._Parent = self self._Icons["lock"] = lock_icon done_icon = NetItemIcon() done_icon._ImgSurf = MyIconPool._Icons["done"] done_icon._CanvasHWND = self._Parent._CanvasHWND done_icon._Parent = self self._Icons["done"] = done_icon ## reuse the resource from TitleBar nimt = NetItemMultiIcon() nimt._ImgSurf = self._Parent._Screen._TitleBar._Icons[ "wifistatus"]._ImgSurf nimt._CanvasHWND = self._Parent._CanvasHWND nimt._Parent = self self._Icons["wifistatus"] = nimt
class Aria2DownloadProcessPage(Page): _FootMsg = ["Nav.", "", "Pause", "Back", "Cancel"] _DownloaderTimer = -1 _Value = 0 _GID = None _PngSize = {} _FileNameLabel = None _SizeLabel = None _URLColor = MySkinManager.GiveColor('URL') _TextColor = MySkinManager.GiveColor('Text') def __init__(self): Page.__init__(self) self._Icons = {} self._CanvasHWND = None def Init(self): self._PosX = self._Index * self._Screen._Width self._Width = self._Screen._Width self._Height = self._Screen._Height self._CanvasHWND = self._Screen._CanvasHWND bgpng = IconItem() bgpng._ImgSurf = MyIconPool.GiveIconSurface("rom_download") bgpng._MyType = ICON_TYPES["STAT"] bgpng._Parent = self bgpng.Adjust(0, 0, self._PngSize["bg"][0], self._PngSize["bg"][1], 0) self._Icons["bg"] = bgpng self._FileNameLabel = Label() self._FileNameLabel.SetCanvasHWND(self._CanvasHWND) self._FileNameLabel.Init("", MyLangManager.TrFont("varela12")) self._SizeLabel = Label() self._SizeLabel.SetCanvasHWND(self._CanvasHWND) self._SizeLabel.Init("0/0Kb", MyLangManager.TrFont("varela12")) self._SizeLabel.SetColor(self._URLColor) @property def GObjectUpdateProcessInterval(self): downloaded = 0 if self._Screen.CurPage() == self and self._GID is not None: self._Value = config.RPC.tellStatus(self._GID) downloaded = 0 total = 0 if self._Value["status"] == "waiting": self._FileNameLabel.SetText("waiting to download...") if self._Value["status"] == "paused": self._FileNameLabel.SetText("download paused...") if self._Value["status"] == "error": self._FileNameLabel.SetText("download errors,cancel it please") if self._Value["status"] == "active": downloaded = self._Value["completedLength"] total = self._Value["totalLength"] downloaded = downloaded / 1000.0 / 1000.0 total = total / 1000.0 / 1000.0 self._SizeLabel.SetText("%.2f" % downloaded + "/" + "%.2f" % total + "Mb") print("Progress: %d%%" % (self._Value)) self._Screen.Draw() self._Screen.SwapAndShow() return True def CheckDownload(self, aria2_gid): self._GID = aria2_gid self._DownloaderTimer = gobject.timeout_add( 234, self.GObjectUpdateProcessInterval) def KeyDown(self, event): if IsKeyMenuOrB(event.key): gobject.source_remove(self._DownloaderTimer) self._DownloaderTimer = -1 #if self._Downloader != None: # try: # self._Downloader.stop() # except: # print("user canceled ") self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() def Draw(self): self.ClearCanvas() self._Icons["bg"].NewCoord(self._Width / 2, self._Height / 2 - 20) self._Icons["bg"].Draw() percent = self._Value if percent < 10: percent = 10 rect_ = midRect(self._Width / 2, self._Height / 2 + 33, 170, 17, Width, Height) aa_round_rect(self._CanvasHWND, rect_, MySkinManager.GiveColor('TitleBg'), 5, 0, MySkinManager.GiveColor('TitleBg')) rect2 = midRect(self._Width / 2, self._Height / 2 + 33, int(170 * (percent / 100.0)), 17, Width, Height) rect2.left = rect_.left rect2.top = rect_.top aa_round_rect(self._CanvasHWND, rect2, MySkinManager.GiveColor('Front'), 5, 0, MySkinManager.GiveColor('Front')) rect3 = midRect(self._Width / 2, self._Height / 2 + 53, self._FileNameLabel._Width, self._FileNameLabel._Height, Width, Height) rect4 = midRect(self._Width / 2, self._Height / 2 + 70, self._SizeLabel._Width, self._SizeLabel._Height, Width, Height) self._FileNameLabel.NewCoord(rect3.left, rect3.top) self._SizeLabel.NewCoord(rect4.left, rect4.top) self._FileNameLabel.Draw() self._SizeLabel.Draw()
class MPDSpectrumPage(Page): _Icons = {} _Selector = None _FootMsg = ["Nav", "", "", "Back", ""] _MyList = [] _ListFont = MyLangManager.TrFont("veramono12") _SongFont = MyLangManager.TrFont("notosanscjk12") _PIFI = None _FIFO = None _Color = MySkinManager.GiveColor('Front') _GobjectIntervalId = -1 _Queue = None _KeepReading = True _ReadingThread = None _BGpng = None _BGwidth = 320 _BGheight = 200 _SheepHead = None _SheepHeadW = 69 _SheepHeadH = 66 _SheepBody = None _SheepBodyW = 105 _SheepBodyH = 81 _RollCanvas = None _RollW = 180 _RollH = 18 _freq_count = 0 _head_dir = 0 _Neighbor = None _bby = [] _bbs = [] _capYPositionArray = [] _frames = 0 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 self._Height = self._Screen._Height self._CanvasHWND = self._Screen._CanvasHWND self._RollCanvas = pygame.Surface((self._RollW, self._RollH)) """ self._BGpng = IconItem() self._BGpng._ImgSurf = MyIconPool._Icons["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._Icons["sheep_head"] self._SheepHead._MyType = ICON_TYPES["STAT"] self._SheepHead._Parent = self self._SheepHead.Adjust(0,0,self._SheepHeadW,self._SheepHeadH,0) self._SheepBody = IconItem() self._SheepBody._ImgSurf = MyIconPool._Icons["sheep_body"] self._SheepBody._MyType = ICON_TYPES["STAT"] self._SheepBody._Parent = self self._SheepBody.Adjust(0,0,self._SheepBodyW,self._SheepBodyH,0) """ self._cwp_png = IconItem() self._cwp_png._ImgSurf = MyIconPool._Icons["tape"] self._cwp_png._MyType = ICON_TYPES["STAT"] self._cwp_png._Parent = self self._cwp_png.Adjust(0, 0, 79, 79, 0) self._song_title = Label() self._song_title.SetCanvasHWND(self._RollCanvas) self._song_title.Init("Untitled", self._SongFont, MySkinManager.GiveColor('White')) self._title = Label() self._title.SetCanvasHWND(self._CanvasHWND) self._title.Init("Title:", self._ListFont, MySkinManager.GiveColor('White')) self._time = Label() self._time.SetCanvasHWND(self._CanvasHWND) self._time.Init("Time:", self._ListFont, MySkinManager.GiveColor('White')) self._time2 = Label() self._time2.SetCanvasHWND(self._CanvasHWND) 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 return def GetSpectrum(self): while self._KeepReading and self._FIFO != None: raw_samples = self._PIFI.GetSpectrum(self._FIFO) if len(raw_samples) < 1: #print("sleeping... 0.01") time.sleep(0.01) self.read_retry += 1 if self.read_retry > 20: 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() def Playing(self): self._Screen.Draw() self._Screen.SwapAndShow() def ClearCanvas(self): self._CanvasHWND.fill(MySkinManager.GiveColor('Black')) def SgsSmooth(self): passes = 1 points = 3 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] smooth_constant = 1.0 / (2.0 * pivot + 1.0) for i in range(pivot, len(origs) - pivot): _sum = 0.0 for j in range(0, (2 * pivot) + 1): _sum += (smooth_constant * origs[i + j - pivot]) + j - pivot self._bby[i] = _sum 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()
class CalendarPage(Page): _Icons = {} _BGpng = None _BGwidth = 320 _BGheight = 200 _BGlabel = None _FreeLabel = None month = 5 year = 2019 nuTxtMonth = {} _HighColor = MySkinManager.GiveColor('High') #_FootMsg = ["Nav.","","","Back",""] _FootMsg = ["Nav","","","Back","Today"] def __init__(self): Page.__init__(self) self._Icons = {} def CurMonth(self): global month global year global cur_monyear global nuTxtMonth nuTxtMonth = {1 : "Jan", 2 : "Feb", 3 : "Mar", 4 : "Apr", 5 : "May", 6 :"Jun", 7 : "Jul", 8 : "Aug", 9 : "Sep", 10 : "Oct", 11 :"Nov", 12 :"Dec", } time = datetime.now() month = int(time.now().strftime('%-m')) year = int(time.now().strftime('%Y')) cur_monyear = (nuTxtMonth[month])+" "+str(year) cal_list = calendar.monthcalendar(time.year, time.month) return cur_monyear, cal_list def NextMonth(self): global month global year global cur_monyear global nuTxtMonth if month !=12: month = month+1 elif month == 12: month = 1 year = year+1 cur_monyear = (nuTxtMonth[month])+" "+str(year) self._monyearlabel.SetText(cur_monyear) self._callist = calendar.monthcalendar(year, month) def PreMonth(self): global month global year global cur_monyear global nuTxtMonth if month !=1: month = month-1 elif month == 1: month = 12 year = year-1 cur_monyear = (nuTxtMonth[month])+" "+str(year) self._monyearlabel.SetText(cur_monyear) self._callist = calendar.monthcalendar(year, month) def NextYear(self): global month global year global cur_monyear global nuTxtMonth year = year+1 cur_monyear = (nuTxtMonth[month])+" "+str(year) self._monyearlabel.SetText(cur_monyear) self._callist = calendar.monthcalendar(year, month) def PreYear(self): global month global year global cur_monyear global nuTxtMonth year = year-1 cur_monyear = (nuTxtMonth[month])+" "+str(year) self._monyearlabel.SetText(cur_monyear) self._callist = calendar.monthcalendar(year, month) def MarkToDay(self): time = datetime.now() dayslist = calendar.monthcalendar(time.year, time.month) today = int(time.strftime("%d")) days = [] for x in dayslist: for y in x: days.append(y) todayINDEX = days.index(today) def GoToDay(self): self.CurMonth() self._monyearlabel.SetText(cur_monyear) self._callist = calendar.monthcalendar(year, month) def Init(self): self._dialog_index = 22 self._CanvasHWND = self._Screen._CanvasHWND self._Width = self._Screen._Width self._Height = self._Screen._Height self._BGpng = IconItem() self._BGpng._ImgSurf = MyIconPool._Icons["cpiCalbg5"] self._BGpng._MyType = ICON_TYPES["STAT"] self._BGpng._Parent = self self._monyearlabel = Label() self._monyearlabel.SetCanvasHWND(self._CanvasHWND) self._monyear, self._callist = self.CurMonth() self._monyearlabel.Init(self._monyear,fonts["varela15"]) calnum = MultiIconItem() calnum._ImgSurf = MyIconPool._Icons["calnum"] calnum._MyType = ICON_TYPES["STAT"] calnum._Parent = self calnum._IconWidth = 35 calnum._IconHeight = 26 calnum.Adjust(0,0,134,372,0) self._Icons["calnum"] = calnum def KeyDown(self,event): if IsKeyMenuOrB(event.key): self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() if IsKeyStartOrA(event.key): self.GoToDay() self._Screen.Draw() self._Screen.SwapAndShow() if event.key == CurKeys["Right"]: self.NextMonth() self._Screen.Draw() self._Screen.SwapAndShow() if event.key == CurKeys["Left"]: self.PreMonth() self._Screen.Draw() self._Screen.SwapAndShow() if event.key == CurKeys["Up"]: self.NextYear() self._Screen.Draw() self._Screen.SwapAndShow() if event.key == CurKeys["Down"]: self.PreYear() self._Screen.Draw() self._Screen.SwapAndShow() def Draw(self): self.ClearCanvas() self._BGpng.NewCoord(5,-30) self._BGpng.Draw() self._monyearlabel.NewCoord(230,5) self._monyearlabel.Draw() #self._Icons["calnum"].NewCoord(157,45) #self._Icons["calnum"]._IconIndex = self._dialog_index #self._Icons["calnum"].DrawTopLeft() ydic = {0:45, 1:74, 2:106, 3:137, 4:167} calrow = {0:0, 1:1, 2:2, 3:3, 4:4} if len(self._callist) is 4: for j in range(4): x = 40 y = ydic[j] row = calrow[j] for numbers in self._callist[row]: if numbers != 0: self._Icons["calnum"].NewCoord(x,y) self._Icons["calnum"]._IconIndex = numbers self._Icons["calnum"].DrawTopLeft() x = x+39 else: for j in range(5): x = 40 y = ydic[j] row = calrow[j] for numbers in self._callist[row]: if numbers != 0: self._Icons["calnum"].NewCoord(x,y) self._Icons["calnum"]._IconIndex = numbers self._Icons["calnum"].DrawTopLeft() x = x+39 if len(self._callist) is 6: x = 40 for numbers in self._callist[5]: if numbers != 0: self._Icons["calnum"].NewCoord(x,48) self._Icons["calnum"]._IconIndex = numbers self._Icons["calnum"].DrawTopLeft() x = x+39
class StoragePage(Page): _Icons = {} _BGpng = None _BGwidth = 96 _BGheight = 73 _BGlabel = None _FreeLabel = None _BGmsg = "%.1fGB of %.1fGB Used" _DskUsg = None _HighColor = MySkinManager.GiveColor('High') _FootMsg = ["Nav.", "", "", "Back", ""] def __init__(self): Page.__init__(self) self._Icons = {} def DiskUsage(self): statvfs = os.statvfs('/') total_space = (statvfs.f_frsize * statvfs.f_blocks) / 1024.0 / 1024.0 / 1024.0 avail_space = (statvfs.f_frsize * statvfs.f_bavail) / 1024.0 / 1024.0 / 1024.0 return avail_space, total_space def Init(self): self._DskUsg = self.DiskUsage() self._CanvasHWND = self._Screen._CanvasHWND self._Width = self._Screen._Width self._Height = self._Screen._Height self._BGpng = IconItem() self._BGpng._ImgSurf = MyIconPool.GiveIconSurface("icon_sd") self._BGpng._MyType = ICON_TYPES["STAT"] self._BGpng._Parent = self self._BGpng.AddLabel( self._BGmsg % (self._DskUsg[1] - self._DskUsg[0], self._DskUsg[1]), MySkinManager.GiveFont("varela15")) self._BGpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0) self._BGlabel = Label() self._BGlabel.SetCanvasHWND(self._CanvasHWND) usage_percent = (self._DskUsg[0] / self._DskUsg[1]) * 100.0 self._BGlabel.Init("%d%%" % int(usage_percent), MySkinManager.GiveFont("varela25")) self._BGlabel.SetColor(self._HighColor) self._FreeLabel = Label() self._FreeLabel.SetCanvasHWND(self._CanvasHWND) self._FreeLabel.Init("Free", MySkinManager.GiveFont("varela13")) self._FreeLabel.SetColor(self._BGlabel._Color) def OnLoadCb(self): pass def Draw(self): self.ClearCanvas() self._BGpng.NewCoord(self._Width / 2, self._Height / 2 - 10) self._BGpng.Draw() self._BGlabel.NewCoord(self._Width / 2 - 28, self._Height / 2 - 30) self._BGlabel.Draw() self._FreeLabel.NewCoord(self._BGlabel._PosX + 10, self._Height / 2) self._FreeLabel.Draw() #bgcolor = (238,238,238), fgcolor = (126,206,244) #aa_round_rect usage_percent = (self._DskUsg[0] / self._DskUsg[1]) if usage_percent < 0.1: usage_percent = 0.1 rect_ = midRect(self._Width / 2, self._Height - 30, 170, 17, Width, Height) aa_round_rect(self._CanvasHWND, rect_, MySkinManager.GiveColor('Line'), 5, 0, MySkinManager.GiveColor('Line')) rect2 = midRect(self._Width / 2, self._Height - 30, int(170 * (1.0 - usage_percent)), 17, Width, Height) rect2.left = rect_.left rect2.top = rect_.top aa_round_rect(self._CanvasHWND, rect2, MySkinManager.GiveColor('Front'), 5, 0, MySkinManager.GiveColor('Front'))
class StoragePage(Page): _Icons = {} _BGpng = None _BGwidth = 96 _BGheight = 73 _BGlabel = None _FreeLabel = None _GBmsg = "%.1fGB of %.1fGB Used" _DskUsg = None _TextColor = MySkinManager.GiveColor('Text') _FootMsg = ["Nav.", "", "", "Back", ""] def __init__(self): Page.__init__(self) self._Icons = {} def DiskUsage(self): statvfs = os.statvfs('/') total_space = (statvfs.f_frsize * statvfs.f_blocks) / 1024.0 / 1024.0 / 1024.0 avail_space = (statvfs.f_frsize * statvfs.f_bavail) / 1024.0 / 1024.0 / 1024.0 return avail_space, total_space def Init(self): self._DskUsg = self.DiskUsage() self._CanvasHWND = self._Screen._CanvasHWND self._Width = self._Screen._Width self._Height = self._Screen._Height self._GBLabel = Label() self._GBLabel.SetCanvasHWND(self._CanvasHWND) self._GBLabel.Init( self._GBmsg % (self._DskUsg[1] - self._DskUsg[0], self._DskUsg[1]), MySkinManager.GiveFont("varela11")) self._GBLabel.SetColor(self._TextColor) self._PctLabel = Label() self._PctLabel.SetCanvasHWND(self._CanvasHWND) usage_percent = (self._DskUsg[0] / self._DskUsg[1]) * 100.0 self._PctLabel.Init("%d%%" % int(usage_percent), MySkinManager.GiveFont("EurostileBold30")) self._PctLabel.SetColor(self._TextColor) self._FreeLabel = Label() self._FreeLabel.SetCanvasHWND(self._CanvasHWND) self._FreeLabel.Init("FREE", MySkinManager.GiveFont("varela12")) self._FreeLabel.SetColor(self._PctLabel._Color) def OnLoadCb(self): pass def Draw(self): self.ClearCanvas() self._PctLabel.NewCoord(32, 102 - 33) self._PctLabel.Draw() self._FreeLabel.NewCoord(33, 130 - 25) self._FreeLabel.Draw() self._GBLabel.NewCoord(145, 103 - 29) self._GBLabel.Draw() #bgcolor = (238,238,238), fgcolor = (126,206,244) usage_percent = (self._DskUsg[0] / self._DskUsg[1]) if usage_percent < 0.1: usage_percent = 0.1 rect_ = pygame.Rect(144, 118 - 25, 283 - 144, 139 - 117) pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'), rect_, 1) rect2 = pygame.Rect(144, 118 - 25, int((283 - 144) * (1.0 - usage_percent)), 139 - 117) rect2.left = rect_.left rect2.top = rect_.top pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'), rect2, 0) sep_rect = pygame.Rect(129, 99 - 25, 2, 42) pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'), sep_rect, 0) ##4 cross self.DrawCross(10, 10) self.DrawCross(self._Screen._Width - 20, 10) self.DrawCross(10, self._Screen._Height - 20) self.DrawCross(self._Screen._Width - 20, self._Screen._Height - 20)