Esempio n. 1
0
    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_,
                      SkinManager().GiveColor('Line'), 5, 0,
                      SkinManager().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,
                      SkinManager().GiveColor('Front'), 5, 0,
                      SkinManager().GiveColor('Front'))
Esempio n. 2
0
    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,
                              SkinManager().GiveColor('White'))

        self._title = Label()
        self._title.SetCanvasHWND(self._CanvasHWND)
        self._title.Init("Title:", self._ListFont,
                         SkinManager().GiveColor('White'))

        self._time = Label()
        self._time.SetCanvasHWND(self._CanvasHWND)
        self._time.Init("Time:", self._ListFont,
                        SkinManager().GiveColor('White'))

        self._time2 = Label()
        self._time2.SetCanvasHWND(self._CanvasHWND)
        self._time2.Init("00:00-00:00", self._ListFont,
                         SkinManager().GiveColor('White'))

        self.Start()
Esempio n. 3
0
    def Draw(self):
        my_text = self._FontObj.render( self._Text,True,self._Color)
        w  = my_text.get_width()
        h  = my_text.get_height()
        x  = (self._Parent._Width - w)/2
        y =  (self._Parent._Height - h)/2
        padding = 10 
        pygame.draw.rect(self._CanvasHWND,SkinManager().GiveColor('White'),(x-padding,y-padding, w+padding*2,h+padding*2))

        pygame.draw.rect(self._CanvasHWND,SkinManager().GiveColor('Black'),(x-padding,y-padding, w+padding*2,h+padding*2),1)

        self._CanvasHWND.blit(my_text,(x,y,w,h))
Esempio n. 4
0
class ListPageSelector(PageSelector):
    _BackgroundColor = SkinManager().GiveColor('Front')

    def __init__(self):
        self._PosX = 0
        self._PosY = 0
        self._Height = 0
        self._Width = Width - 12

    def AnimateDraw(self, x2, y2):
        pass

    def Draw(self):
        idx = self._Parent._PsIndex
        if idx > (len(self._Parent._MyList) - 1):
            idx = len(self._Parent._MyList)
            if idx > 0:
                idx -= 1
            elif idx == 0:  ##nothing in _MyList
                return

        self._Parent._PsIndex = idx  #sync PsIndex

        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, (x, y, self._Width - 4, h),
                      self._BackgroundColor, 4, 0, self._BackgroundColor)
Esempio n. 5
0
    def Draw(self):
        if self._DrawOnce == False:
            self.ClearCanvas()

            if is_wifi_connected_now():
                
                self._Icons["online"].NewCoord(self._Coords["online"].x, self._Coords["online"].y)
                self._Icons["online"].Draw()

                self.SetLabels()
                
                for i in self._Labels:
                    if i in self._Coords:
                        self._Labels[i].NewCoord( self._Coords[i].x, self._Coords[i].y)
                        self._Labels[i].Draw()

                self._Labels["key_and_pass"].NewCoord( 103,self._Coords["key_and_pass"].y)
                self._Labels["key_and_pass"].Draw()

            else:
                self._Icons["bg"].NewCoord(self._Coords["bg"].x, self._Coords["bg"].y)
                self._Icons["bg"].Draw()

                
            self._DrawOnce = True
            
        if self._HWND != None:
            self._HWND.fill(SkinManager().GiveColor('White'))
            self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width, self._Height ) )
Esempio n. 6
0
    def Draw(self):

        if self._MyType == ICON_TYPES["DIR"] and self._Path != "[..]":
            self._Parent._Icons["sys"]._IconIndex = 0
            self._Parent._Icons["sys"].NewCoord(
                self._PosX + 12, self._PosY +
                (self._Height - self._Parent._Icons["sys"]._Height) / 2 +
                self._Parent._Icons["sys"]._Height / 2)
            self._Parent._Icons["sys"].Draw()

        if self._MyType == ICON_TYPES["FILE"]:
            self._Parent._Icons["sys"]._IconIndex = 1
            self._Parent._Icons["sys"].NewCoord(
                self._PosX + 12, self._PosY +
                (self._Height - self._Parent._Icons["sys"]._Height) / 2 +
                self._Parent._Icons["sys"]._Height / 2)
            self._Parent._Icons["sys"].Draw()

        if self._Active == True:
            self._Labels["Text"]._Active = True
        else:
            self._Labels["Text"]._Active = False

        self._Labels["Text"]._PosY = self._PosY + (
            self._Height - self._Labels["Text"]._Height) / 2

        pygame.draw.line(
            self._Parent._CanvasHWND,
            SkinManager().GiveColor('Line'),
            (self._PosX, self._PosY + self._Height - 1),
            (self._PosX + self._Width, self._PosY + self._Height - 1), 1)

        self._Labels["Text"].Draw()
Esempio n. 7
0
class ListPageSelector(PageSelector):
    _BackgroundColor = SkinManager().GiveColor('Front')

    def __init__(self):
        self._PosX = 0
        self._PosY = 0
        self._Height = 0
        self._Width = Width

    def AnimateDraw(self, x2, y2):
        pass

    def Draw(self):
        idx = self._Parent._PsIndex
        if idx < len(self._Parent._MyList):
            x = 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, (x, y, self._Width - 4, h),
                          self._BackgroundColor, 4, 0, self._BackgroundColor)
Esempio n. 8
0
    def Draw(self):
        #pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY),(self._PosX+self._Width,self._PosY),1)        
        for i in self._Labels:
            self._Labels[i]._PosY = self._PosY + (self._Height - self._Labels[i]._Height)/2
            self._Labels[i].Draw()
            
        if self._IsActive:
            self._Icons["done"].NewCoord(14,self._PosY)
            self._Icons["done"].Draw()

        if self._Encrypt != "Unsecured":
            self._Icons["lock"].NewCoord( self._Width -23 - self._Labels["stren"].Width() - 2 - 18, self._PosY)
            self._Icons["lock"].Draw()
        
        ge = self._Parent._Screen._TitleBar.GetWifiStrength( self._Stren.replace('%',''))
        
        if ge > 0:
            self._Icons["wifistatus"]._IconIndex = ge
            self._Icons["wifistatus"].NewCoord(self._Width-23,self._PosY)
            self._Icons["wifistatus"].Draw()
            
        else:
            self._Icons["wifistatus"]._IconIndex = 0
            self._Icons["wifistatus"].NewCoord(self._Width-23,self._PosY)
            self._Icons["wifistatus"].Draw()
        
        pygame.draw.line(self._Parent._CanvasHWND,SkinManager().GiveColor('Line'),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)        
Esempio n. 9
0
    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

        ps = ListPageSelector()
        ps._Parent = self
        self._Ps = ps
        self._PsIndex = 0

        self.SyncList()
        gobject.timeout_add(850,self.GObjectInterval)

        self._BGpng = IconItem()
        self._BGpng._ImgSurf = MyIconPool._Icons["heart"]
        self._BGpng._MyType = ICON_TYPES["STAT"]
        self._BGpng._Parent = self
        self._BGpng.AddLabel("my favourites", fonts["varela18"])
        self._BGpng.SetLableColor(SkinManager().GiveColor('Disabled'))
        self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)

        self._Scroller = ListScroller()
        self._Scroller._Parent = self
        self._Scroller._PosX = self._Width - 10
        self._Scroller._PosY = 2
        self._Scroller.Init()
Esempio n. 10
0
    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_,
                      SkinManager().GiveColor('TitleBg'), 5, 0,
                      SkinManager().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,
                      SkinManager().GiveColor('Front'), 5, 0,
                      SkinManager().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()
Esempio n. 11
0
class ListItemLabel(Label):

    _ActiveColor = SkinManager().GiveColor('Active')
    _Active = False

    def Draw(self):

        self._FontObj.set_bold(self._Active)

        my_text = self._FontObj.render(self._Text, True, self._Color)
        self._CanvasHWND.blit(
            my_text, (self._PosX, self._PosY, self._Width, self._Height))
Esempio n. 12
0
class KeyboardIcon(IconItem):
    _PosX = 0
    _PosY = 0
    _Width = 0
    _Height = 0
    _Color = SkinManager().GiveColor('Text')
    _MyType = ICON_TYPES["NAV"]
    _Parent = None
    _Str = ""

    def Draw(self):
        self._Parent._CanvasHWND.blit(self._ImgSurf, \
            midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height))
Esempio n. 13
0
    def Draw(self):
        #pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY),(self._PosX+self._Width,self._PosY),1)
        for i in self._Labels:
            self._Labels[i]._PosY = self._PosY + (self._Height -
                                                  self._Labels[i]._Height) / 2
            self._Labels[i].Draw()

        if self._IsActive:
            self._Icons["done"].NewCoord(320 - 22, self._PosY)
            self._Icons["done"].Draw()

        pygame.draw.line(
            self._Parent._CanvasHWND,
            SkinManager().GiveColor('Line'),
            (self._PosX, self._PosY + self._Height - 1),
            (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
Esempio n. 14
0
    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

        ps = ListPageSelector()
        ps._Parent = self
        self._Ps = ps
        self._PsIndex = 0

        self.SyncList(self._Emulator["ROM"])

        self._MyStack._Emulator = self._Emulator

        icon_for_list = MultiIconItem()
        icon_for_list._ImgSurf = self._Parent._Icons["sys"]
        icon_for_list._MyType = ICON_TYPES["STAT"]
        icon_for_list._Parent = self
        icon_for_list.Adjust(0, 0, 18, 18, 0)

        self._Icons["sys"] = icon_for_list

        bgpng = IconItem()
        bgpng._ImgSurf = MyIconPool._Icons["star"]
        bgpng._MyType = ICON_TYPES["STAT"]
        bgpng._Parent = self
        bgpng.AddLabel("my favourites games", fonts["varela18"])
        bgpng.SetLableColor(SkinManager().GiveColor('Disabled'))
        bgpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)

        self._Icons["bg"] = bgpng

        self._Scroller = ListScroller()
        self._Scroller._Parent = self
        self._Scroller._PosX = self._Width - 10
        self._Scroller._PosY = 2
        self._Scroller.Init()

        rom_so_confirm_page = RomSoConfirmPage()
        rom_so_confirm_page._Screen = self._Screen
        rom_so_confirm_page._Name = "Download Confirm"
        rom_so_confirm_page._Parent = self
        rom_so_confirm_page.Init()

        self._RomSoConfirmDownloadPage = rom_so_confirm_page
Esempio n. 15
0
    def Draw(self):

        self._Labels["Text"]._PosY = self._PosY + (
            self._Height - self._Labels["Text"]._Height) / 2
        self._Labels["Text"].Draw()

        if "Small" in self._Labels:
            self._Labels[
                "Small"]._PosX = self._Width - self._Labels["Small"]._Width - 5

            self._Labels["Small"]._PosY = self._PosY + (
                self._Height - self._Labels["Small"]._Height) / 2
            self._Labels["Small"].Draw()

        pygame.draw.line(
            self._Parent._CanvasHWND,
            SkinManager().GiveColor('Line'),
            (self._PosX, self._PosY + self._Height - 1),
            (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
Esempio n. 16
0
class TextItem(IconItem):
    _PosX = 0
    _PosY = 0
    _Width = 0
    _Height = 0
    _Str = ""
    _Color = SkinManager().GiveColor('Text')
    _FontObj = None
    _Bold = False
    _MyType = ICON_TYPES["LETTER"]
    _Parent = None

    def Draw(self):
        self._FontObj.set_bold(self._Bold)
        my_text = self._FontObj.render(self._Str, True, self._Color)
        if my_text.get_width() != self._Width:
            self._Width = my_text.get_width()
        if my_text.get_height() != self._Height:
            self._Height = my_text.get_height()

        self._Parent._CanvasHWND.blit(my_text, \
            midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height))
Esempio n. 17
0
    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

        ps = ListPageSelector()
        ps._Parent = self
        self._Ps = ps
        self._PsIndex = 0

        self.SyncList("/")

        icon_for_list = MultiIconItem()
        icon_for_list._ImgSurf = MyIconPool._Icons["sys"]
        icon_for_list._MyType = ICON_TYPES["STAT"]
        icon_for_list._Parent = self
        
        icon_for_list.Adjust(0,0,18,18,0)        
        self._Icons["sys"] = icon_for_list


        self._BGpng = IconItem()
        self._BGpng._ImgSurf = MyIconPool._Icons["empty"]
        self._BGpng._MyType = ICON_TYPES["STAT"]
        self._BGpng._Parent = self
        self._BGpng.AddLabel("Please upload data over Wi-Fi", fonts["varela22"])
        self._BGpng.SetLableColor(SkinManager().GiveColor('Disabled'))
        self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)


        self._Scroller = ListScroller()
        self._Scroller._Parent = self
        self._Scroller._PosX = self._Width - 10
        self._Scroller._PosY = 2
        self._Scroller.Init()
Esempio n. 18
0
class DownloadProcessPage(Page):
    _FootMsg = ["Nav.", "", "", "Back", ""]
    _Downloader = None
    _DownloaderTimer = -1
    _Value = 0

    _URL = ""
    _DST_DIR = ""

    _PngSize = {}

    _FileNameLabel = None
    _SizeLabel = None

    _URLColor = SkinManager().GiveColor('URL')
    _TextColor = SkinManager().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("Download failed")
                    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 event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
            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_,
                      SkinManager().GiveColor('TitleBg'), 5, 0,
                      SkinManager().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,
                      SkinManager().GiveColor('Front'), 5, 0,
                      SkinManager().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()
Esempio n. 19
0
 def ClearCanvas(self):
     self._CanvasHWND.fill(SkinManager().GiveColor('Black'))
Esempio n. 20
0
    def Draw(self):
        self.ClearCanvas()
        self._frames += 1

        bw = 10
        gap = 2
        margin_bottom = 72

        spects = None
        meterNum = self._Width / float(bw + gap)  ## 320/12= 26
        meter_left = meterNum - int(meterNum)
        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()

        if self._Neighbor != None:
            if self._Neighbor._CurSongName != "":
                self._song_title.SetText(self._Neighbor._CurSongName)
            if self._Neighbor._CurSongTime != "":
                times = self._Neighbor._CurSongTime
                times_ = times.split(":")
                if len(times_) > 1:
                    cur = int(times_[0])
                    end = int(times_[1])
                    if cur > 3600:
                        cur_text = time.strftime('%H:%M:%S', time.gmtime(cur))
                    else:
                        cur_text = time.strftime('%M:%S', time.gmtime(cur))

                    if end > 3600:
                        end_text = time.strftime('%H:%M:%S', time.gmtime(end))
                    else:
                        end_text = time.strftime('%M:%S', time.gmtime(end))
                else:
                    cur_text = ""
                    end_text = times

                self._time2.SetText(cur_text + "-" + end_text)

        self._title.NewCoord(90, 167)
        self._title.Draw()

        self._time.NewCoord(90, 140)
        self._time.Draw()

        self._time2.NewCoord(135, 140)
        self._time2.Draw()

        if self._RollCanvas != None:
            #            self._RollCanvas.fill((111,22,33))
            self._RollCanvas.fill(SkinManager().GiveColor('Black'))
            if self._song_title._Width > self._RollW:
                if (self._song_title._PosX + self._song_title._Width
                    ) > self._RollW and self._frames % 30 == 0:
                    self._song_title._PosX -= 1
                elif (self._song_title._PosX + self._song_title._Width
                      ) <= self._RollW and self._frames % 30 == 0:
                    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):
                    value = 0

                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):
                    if self._vis_values[i] < value:
                        self._vis_values[i] = value

        except Exception, e:
            print(e)
            return
Esempio n. 21
0
class MPDSpectrumPage(Page):

    _Icons = {}
    _Selector = None
    _FootMsg = ["Nav", "", "", "Back", ""]
    _MyList = []
    _ListFont = fonts["veramono12"]
    _SongFont = fonts["notosanscjk12"]
    _PIFI = None
    _FIFO = None
    _Color = SkinManager().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,
                              SkinManager().GiveColor('White'))

        self._title = Label()
        self._title.SetCanvasHWND(self._CanvasHWND)
        self._title.Init("Title:", self._ListFont,
                         SkinManager().GiveColor('White'))

        self._time = Label()
        self._time.SetCanvasHWND(self._CanvasHWND)
        self._time.Init("Time:", self._ListFont,
                        SkinManager().GiveColor('White'))

        self._time2 = Label()
        self._time2.SetCanvasHWND(self._CanvasHWND)
        self._time2.Init("00:00-00:00", self._ListFont,
                         SkinManager().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(SkinManager().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 event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
            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()

        if event.key == CurKeys["Start"]:
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Enter"]:
            pass
Esempio n. 22
0
    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

        ps = ListPageSelector()
        ps._Parent = self
        self._Ps = ps
        self._PsIndex = 0

        self.SyncList(self._Emulator["ROM"])

        ### will also mkdir of the ***ROM self
        try:
            os.makedirs(self._Emulator["ROM"] + "/.Trash")
        except OSError:
            if not os.path.isdir(self._Emulator["ROM"] + "/.Trash"):
                raise

        try:
            os.makedirs(self._Emulator["ROM"] + "/.Fav")
        except OSError:
            if not os.path.isdir(self._Emulator["ROM"] + "/.Fav"):
                raise

        self._MyStack._Emulator = self._Emulator

        icon_for_list = MultiIconItem()
        icon_for_list._ImgSurf = self._Parent._Icons["sys"]
        icon_for_list._MyType = ICON_TYPES["STAT"]
        icon_for_list._Parent = self

        icon_for_list.Adjust(0, 0, 18, 18, 0)

        self._Icons["sys"] = icon_for_list

        bgpng = IconItem()
        bgpng._ImgSurf = MyIconPool._Icons["empty"]
        bgpng._MyType = ICON_TYPES["STAT"]
        bgpng._Parent = self
        bgpng.AddLabel("Please upload data over Wi-Fi", fonts["varela22"])
        bgpng.SetLableColor(SkinManager().GiveColor('Disabled'))
        bgpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)

        self._Icons["bg"] = bgpng

        self._Scroller = ListScroller()
        self._Scroller._Parent = self
        self._Scroller._PosX = self._Width - 10
        self._Scroller._PosY = 2
        self._Scroller.Init()

        rom_so_confirm_page = RomSoConfirmPage()
        rom_so_confirm_page._Screen = self._Screen
        rom_so_confirm_page._Name = "Download Confirm"
        rom_so_confirm_page._Parent = self
        rom_so_confirm_page.Init()

        self._RomSoConfirmDownloadPage = rom_so_confirm_page
Esempio n. 23
0
class Textarea:
    _PosX = 0
    _PosY = 0
    _Width = 0
    _Height = 0
    _BackgroundColor = SkinManager().GiveColor('TitleBg')
    _CanvasHWND = None
    _MyWords = []
    _BlitWords = []
    _FontObj = None
    _LineNumber = 0
    _TextLimit = 63
    _TextFull = False
    _TextIndex = 0
    _BlitIndex = 0

    def __init__(self):
        pass

    def Init(self):
        self._FontObj = fonts["veramono24"]
        #pygame.font.Font(fonts_path["veramono"],24)

    def SubTextIndex(self):

        self._TextIndex -= 1
        if self._TextIndex < 0:
            self._TextIndex = 0

    def AddTextIndex(self):
        self._TextIndex += 1
        if self._TextIndex > len(self._MyWords):
            self._TextIndex = len(self._MyWords)

    def ResetMyWords(self):
        self._MyWords = []
        self._TextIndex = 0

    def RemoveFromLastText(self):
        if len(self._MyWords) > 0:
            self.SubTextIndex()

            del self._MyWords[self._TextIndex]

            return self._MyWords

    def AppendText(self, alphabet):

        self.AppendAndBlitText(alphabet)

    def AppendAndBlitText(self, alphabet):

        if self._TextFull != True:

            self._MyWords.insert(self._TextIndex, alphabet)
            self.BlitText()
            self.AddTextIndex()
        else:
            print("is Full %s" % "".join(self._MyWords))

    def BuildBlitText(self):
        blit_rows = [[]]
        w = 0
        xmargin = 5
        endmargin = 15
        x = self._PosX + xmargin
        linenumber = 0
        cursor_row = 0

        for i, v in enumerate(self._MyWords):
            t = self._FontObj.render(v, True, (8, 135, 174))
            t_width = t.get_width()
            w += t_width
            del (t)

            blit_rows[linenumber].append(v)

            if i == self._TextIndex - 1:
                cursor_row = linenumber

            if w + t_width >= self._Width - endmargin:
                x = self._PosX + xmargin
                w = 0
                linenumber += 1
                blit_rows.append([])

        # only paint 2 rows
        if len(blit_rows) == 1:
            self._BlitWords = blit_rows[0]
            self._BlitIndex = self._TextIndex
        elif len(blit_rows) == 2 or cursor_row < 2:
            self._BlitWords = blit_rows[0] + blit_rows[1]
            self._BlitIndex = self._TextIndex
        else:
            self._BlitWords = blit_rows[cursor_row - 1] + blit_rows[cursor_row]
            self._BlitIndex = self._TextIndex
            for i, v in enumerate(blit_rows):
                if i == cursor_row - 1:
                    break
                self._BlitIndex -= len(v)

    def BlitText(self):
        """
        blit every single word into surface and calc the width ,check multi line 
        """
        # build up blitwords
        self.BuildBlitText()

        w = 0
        xmargin = 5
        endmargin = 15
        x = self._PosX + xmargin
        y = self._PosY
        linenumber = 0
        self._TextFull = len(self._MyWords) > self._TextLimit
        for i, v in enumerate(self._BlitWords):
            t = self._FontObj.render(v, True, (8, 135, 174))
            w += t.get_width()

            if w >= self._Width - endmargin and linenumber == 0:
                linenumber += 1
                x = self._PosX + xmargin
                y = self._PosY + t.get_height() * linenumber
                w = 0

            self._CanvasHWND.blit(t, (x, y))
            x += t.get_width()

    def Cursor(self):
        w = 0
        xmargin = 5
        endmargin = 15
        x = self._PosX + xmargin
        y = self._PosY
        linenumber = 0
        for i, v in enumerate(self._BlitWords[:self._BlitIndex]):
            t = self._FontObj.render(v, True, (8, 135, 174))
            w += t.get_width()

            if w >= self._Width - endmargin and linenumber == 0:
                x = self._PosX + xmargin
                y = self._PosY + t.get_height()
                w = 0
                linenumber += 1

            if w >= self._Width - endmargin * 3 and linenumber > 0:
                x += t.get_width()
                break
            x += t.get_width()

        self._CanvasHWND.blit(self._FontObj.render("_", True, (0, 0, 0)),
                              (x + 1, y - 2))

    def Draw(self):
        #aa_round_rect(self._CanvasHWND, (4,24.5+6,312,60),self._BackgroundColor,4,0,self._BackgroundColor)

        aa_round_rect(self._CanvasHWND,
                      (self._PosX, self._PosY, self._Width, self._Height),
                      self._BackgroundColor, 4, 0, self._BackgroundColor)

        self.BlitText()
        self.Cursor()
Esempio n. 24
0
class TinyCloudPage(Page):
    _FootMsg =  ["Nav.","","","Back",""]
    _MyList = []
    
    _ListFontObj = fonts["varela13"]
    
    _AList = {}
    _Labels = {}

    _Coords = {}
    
    _URLColor  = SkinManager().GiveColor('URL')
    _TextColor = SkinManager().GiveColor('Text')
    _Scrolled = 0
    
    _PngSize = {}
    
    _DrawOnce = False
    _Scroller = None
    _Scrolled = 0
    
    def __init__(self):
        Page.__init__(self)
        self._Icons = {}

    def OnLoadCb(self):
        self._Scrolled = 0
        self._PosY = 0
        self._DrawOnce = False

    def SetCoords(self):

        self._Coords["forID"] = SimpleNamespace()
        self._Coords["forID"].x = 15
        self._Coords["forID"].y = 11

        self._Coords["forKey"] = SimpleNamespace()
        self._Coords["forKey"].x = 71
        self._Coords["forKey"].y = self._Coords["forID"].y

        self._Coords["key_and_pass"] = SimpleNamespace()
        self._Coords["key_and_pass"].x = 36 # 141
        self._Coords["key_and_pass"].y = self._Coords["forID"].y

        self._Coords["forssh"] = SimpleNamespace()
        self._Coords["forssh"].x = self._Coords["forID"].x
        self._Coords["forssh"].y = 47

        self._Coords["ssh_addr"] = SimpleNamespace()
        self._Coords["ssh_addr"].x = self._Coords["forID"].x
        self._Coords["ssh_addr"].y = 65

        self._Coords["forwin"] = SimpleNamespace()
        self._Coords["forwin"].x = self._Coords["forID"].x
        self._Coords["forwin"].y = 101

        self._Coords["samba_games"] = SimpleNamespace()
        self._Coords["samba_games"].x = self._Coords["forID"].x
        self._Coords["samba_games"].y = 118

        self._Coords["samba_music"] = SimpleNamespace()
        self._Coords["samba_music"].x = self._Coords["samba_games"].x
        self._Coords["samba_music"].y = 136

        self._Coords["for_airplay"] = SimpleNamespace()
        self._Coords["for_airplay"].x = self._Coords["forID"].x
        self._Coords["for_airplay"].y = 173

        self._Coords["airplay_name"] = SimpleNamespace()
        self._Coords["airplay_name"].x = 68
        self._Coords["airplay_name"].y = self._Coords["for_airplay"].y
        

        self._Coords["bg"]          = SimpleNamespace()
        self._Coords["bg"].x        = self._Width/2
        self._Coords["bg"].y        = self._Height/2

        self._Coords["online"]          = SimpleNamespace()
        self._Coords["online"].x        = 266
        self._Coords["online"].y        = 99

    def SetLabels(self):
        if is_wifi_connected_now():
            self._IP = get_wifi_ip()
            print("TinyCould : %s" % self._IP)
            try:
                if validators.ip_address.ipv4(self._IP) == False:
                    self._IP = "xxx.xxx.xxx.xxx"
            except:
                print("ip error %s " % self._IP)
                self._IP = "xxx.xxx.xxx.xxx"
            
        else:
            self._IP = "xxx.xxx.xxx.xxx"
        
        labels = \
        [["forssh","For ssh and scp:",self._ListFontObj,self._TextColor],
         ["ssh_addr","ssh cpi@%s" % self._IP, self._ListFontObj,self._URLColor],
         ["forwin", "For Windows network:",    self._ListFontObj, self._TextColor],
         ["samba_games", "\\\\%s\games" % self._IP, self._ListFontObj,self._URLColor],
         ["samba_music", "\\\\%s\music" % self._IP, self._ListFontObj,self._URLColor],
         ["forID",      "ID:",                     self._ListFontObj, self._TextColor],
         ["forKey",     "Key:",                    self._ListFontObj, self._TextColor],
         ["key_and_pass", "cpi",                   self._ListFontObj, self._URLColor],
         ["for_airplay", "Airplay:",               self._ListFontObj, self._TextColor],
         ["airplay_name","clockworkpi",            self._ListFontObj, self._URLColor]]

        for i in labels:
            l = Label()
            l.SetCanvasHWND(self._CanvasHWND)
            l.Init(i[1],i[2])
            l.SetColor(i[3])
            self._Labels[ i[0] ] = l

        self.SetCoords() ##
        
    def Init(self):

        
        if self._Screen != None:
            if self._Screen._CanvasHWND != None and self._CanvasHWND == None:
                self._HWND = self._Screen._CanvasHWND
                self._CanvasHWND = pygame.Surface( (self._Screen._Width,self._Screen._Height) )
        
        self._PosX = self._Index*self._Screen._Width 
        self._Width = self._Screen._Width ## equal to screen width
        self._Height = self._Screen._Height

        self._PngSize["bg"] = (253,132)
        self._PngSize["online"] = (75,122)
        
        bgpng = IconItem()
        bgpng._ImgSurf = MyIconPool._Icons["needwifi_bg"]
        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
        
        onlinepng = IconItem()
        onlinepng._ImgSurf = MyIconPool._Icons["online"]
        onlinepng._MyType = ICON_TYPES["STAT"]
        onlinepng._Parent = self
        onlinepng.Adjust(0,0,self._PngSize["online"][0], self._PngSize["online"][1],0)

        self._Icons["online"] = onlinepng

        self.SetLabels()

    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()

            if is_wifi_connected_now():
                
                self._Icons["online"].NewCoord(self._Coords["online"].x, self._Coords["online"].y)
                self._Icons["online"].Draw()

                self.SetLabels()
                
                for i in self._Labels:
                    if i in self._Coords:
                        self._Labels[i].NewCoord( self._Coords[i].x, self._Coords[i].y)
                        self._Labels[i].Draw()

                self._Labels["key_and_pass"].NewCoord( 103,self._Coords["key_and_pass"].y)
                self._Labels["key_and_pass"].Draw()

            else:
                self._Icons["bg"].NewCoord(self._Coords["bg"].x, self._Coords["bg"].y)
                self._Icons["bg"].Draw()

                
            self._DrawOnce = True
            
        if self._HWND != None:
            self._HWND.fill(SkinManager().GiveColor('White'))
            self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width, self._Height ) )
Esempio n. 25
0
            print(e)
            return
        else:  # got line
            if len(self._vis_values) == 0:
                return

            for i in range(0, meterNum):
                value = self._vis_values[i]

                if len(self._capYPositionArray) < round(meterNum):
                    self._capYPositionArray.append(value)

                if value < self._capYPositionArray[i]:
                    self._capYPositionArray[i] -= 0.5
                else:
                    self._capYPositionArray[i] = value

                pygame.draw.rect(
                    self._CanvasHWND,
                    SkinManager().GiveColor('White'),
                    (i * (bw + gap) + margin_left, self._Height - gap -
                     self._capYPositionArray[i] - margin_bottom, bw, gap), 0)

                pygame.draw.rect(
                    self._CanvasHWND,
                    SkinManager().GiveColor('White'),
                    (i * (bw + gap) + margin_left, self._Height - value - gap -
                     margin_bottom, bw, value + gap), 0)

                self._vis_values[i] -= 2
Esempio n. 26
0
class StoragePage(Page):

    _Icons = {}
    _BGpng = None
    _BGwidth = 96
    _BGheight = 73
    _BGlabel = None
    _FreeLabel = None

    _BGmsg = "%.1fGB of %.1fGB Used"
    _DskUsg = None

    _HighColor = SkinManager().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._Icons["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]),
            fonts["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), fonts["varela25"])
        self._BGlabel.SetColor(self._HighColor)

        self._FreeLabel = Label()
        self._FreeLabel.SetCanvasHWND(self._CanvasHWND)
        self._FreeLabel.Init("Free", fonts["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_,
                      SkinManager().GiveColor('Line'), 5, 0,
                      SkinManager().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,
                      SkinManager().GiveColor('Front'), 5, 0,
                      SkinManager().GiveColor('Front'))