Ejemplo n.º 1
0
class SoundSlider(Slider):
    OnChangeCB = None
    
    _BGpng = None
    _BGwidth = 192
    _BGheight = 173

    _NeedleSurf = None
    _Scale      = None
    _Parent     = None
    
    snd_segs = [ [0,20],[21,40],[41,50],[51,60],[61,70],[71,85],[86,90],[91,95],[96,100] ]

    
    def __init__(self):
        Slider.__init__(self)
        
    def Init(self):
        self._Width = self._Parent._Width
        self._Height = self._Parent._Height
        
        self._BGpng = IconItem()
        self._BGpng._ImgSurf = MyIconPool.GiveIconSurface("vol")
        self._BGpng._MyType = ICON_TYPES["STAT"]
        self._BGpng._Parent = self
        self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)

        ##self._NeedleSurf = pygame.Surface( (38,12),pygame.SRCALPHA )
        
        self._Scale = MultiIconItem()
        self._Scale._MyType = ICON_TYPES["STAT"]
        self._Scale._Parent = self
        self._Scale._ImgSurf = MyIconPool.GiveIconSurface("scale")
        self._Scale._IconWidth = 82
        self._Scale._IconHeight = 63
        self._Scale.Adjust(0,0,82,63,0)
        
    def SetValue(self,vol):#pct 0-100
        for i,v in enumerate(self.snd_segs):
            if vol  >= v[0] and vol <= v[1]:
                self._Value = i # self._Value :  0 - 8
                break
        
    def Further(self):
        self._Value+=1

        if self._Value > len(self.snd_segs)-1:
            self._Value = len(self.snd_segs) -1

        vol = self.snd_segs[self._Value][0] + (self.snd_segs[self._Value][1] - self.snd_segs[self._Value][0])/2 
        
        if self.OnChangeCB != None:
            if callable(self.OnChangeCB):
                self.OnChangeCB( vol )
        
    def StepBack(self):
        self._Value-=1

        if self._Value < 0:
            self._Value = 0

        vol = self.snd_segs[self._Value][0] + (self.snd_segs[self._Value][1] - self.snd_segs[self._Value][0])/2 
        
        if self.OnChangeCB != None:
            if callable(self.OnChangeCB):
                self.OnChangeCB( vol )
    
    def Draw(self):
        
        self._BGpng.NewCoord(self._Width/2,self._Height/2 )
        self._BGpng.Draw()

        self._Scale.NewCoord(self._Width/2,self._Height/2)

        self._Scale._IconIndex = self._Value
        
        self._Scale.Draw()
Ejemplo n.º 2
0
class HashErrPage(Page):
    _FootMsg = ["Nav", "", "", "Cancel", "Continue"]
    _BG = "pico8_md5_err"

    _Leader = None
    _Padding = pygame.Rect(0, 12, 0, 6)

    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._BGpng = IconItem()
        self._BGpng._ImgSurf = MyIconPool.GiveIconSurface(self._BG)
        self._BGpng._MyType = ICON_TYPES["STAT"]
        self._BGpng._Parent = self
        self._BGpng.Adjust(0, 0, MyIconPool.Width(self._BG),
                           MyIconPool.Height(self._BG), 0)

        self._Board = Textbulletinboard()

        self._Board._PosX = 4
        self._Board._PosY = self._Height / 2 - 30
        self._Board._Width = self._Width - 4 * 2
        self._Board._Height = 100
        self._Board._CanvasHWND = self._CanvasHWND
        self._Board._RowPitch = 28
        self._Board._Align = "Center"
        self._Board.Init()

        if self._Leader != None and self._Leader._ComPkgInfo != None:
            if "HashErrMsg" in self._Leader._ComPkgInfo:
                d = []
                for i, v in enumerate(self._Leader._ComPkgInfo["HashErrMsg"]):
                    Color = None
                    Font = None
                    Bold = False
                    Und = False
                    Txt = ""
                    parts = v.split("|")
                    if len(parts) > 0:
                        Txt = parts[0]

                    if len(parts) == 2:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                    elif len(parts) == 3:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                        if parts[2] != "None":
                            Font = MyLangManager.TrFont(parts[2])
                    elif len(parts) == 4:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                        if parts[2] != "None":
                            Font = MyLangManager.TrFont(parts[2])
                        if parts[3] == "True":
                            Bold = True
                    elif len(parts) == 5:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                        if parts[2] != "None":
                            Font = MyLangManager.TrFont(parts[2])
                        if parts[3] == "True":
                            Bold = True
                        if parts[4] == "True":
                            Und = True

                    a = Text(Txt, Color, Font, Bold, Und)
                    d = d + a.Words()

                self._Board.SetAndBlitText(d)

            else:
                a = Text("MD5 check Failed!\n", None,
                         MyLangManager.TrFont("varela16"))
                b = Text("Do you want to continue?", None,
                         MyLangManager.TrFont("varela16"))
                self._Board.SetAndBlitText(a.Words() + b.Words())

    def KeyDown(self, event):
        if IsKeyMenuOrB(event.key):
            self.ReturnToUpLevelPage()
            self._Screen.Draw()
            self._Screen.SwapAndShow()
            return

        if IsKeyStartOrA(event.key):
            self._Leader.InstallPackage(self._Screen)
            return

    def OnLoadCb(self):
        pass

    def Draw(self):
        self.ClearCanvas()
        if self._BGpng != None:
            self._BGpng.NewCoord((self._Width - self._BGpng._Width) / 2,
                                 self._Padding.y)
            self._BGpng.DrawTopLeft()
            self._Board._PosY = self._BGpng._Height + self._Padding.y + self._Padding.h
        else:
            self._Board._PosY = self._Padding.y

        self._Board.Draw()
Ejemplo n.º 3
0
class NotFoundPage(Page):
    _FootMsg = ["Nav", "", "", "Back", ""]
    _BG = "pico8_notfound"
    _Leader = None
    _Padding = pygame.Rect(0, 12, 0, 6)

    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._BGpng = IconItem()
        self._BGpng._ImgSurf = MyIconPool.GiveIconSurface(self._BG)
        self._BGpng._MyType = ICON_TYPES["STAT"]
        self._BGpng._Parent = self
        #print( MyIconPool.Width(self._BG),MyIconPool.Height(self._BG) )
        self._BGpng.Adjust(0, 0, MyIconPool.Width(self._BG),
                           MyIconPool.Height(self._BG), 0)

        self._Board = Textbulletinboard()

        self._Board._PosX = 4
        self._Board._PosY = 100
        self._Board._Width = self._Width - 4 * 2
        self._Board._Height = 200
        self._Board._CanvasHWND = self._CanvasHWND
        self._Board._Align = "Center"
        self._Board._RowPitch = 28
        self._Board.Init()

        if self._Leader != None and self._Leader._ComPkgInfo != None:
            if "NotFoundMsg" in self._Leader._ComPkgInfo:
                d = []
                for i, v in enumerate(self._Leader._ComPkgInfo["NotFoundMsg"]):
                    Color = None
                    Font = None
                    Bold = False
                    Und = False
                    Txt = ""
                    parts = v.split("|")
                    if len(parts) > 0:
                        Txt = parts[0]

                    if len(parts) == 2:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                    elif len(parts) == 3:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                        if parts[2] != "None":
                            Font = MyLangManager.TrFont(parts[2])
                    elif len(parts) == 4:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                        if parts[2] != "None":
                            Font = MyLangManager.TrFont(parts[2])
                        if parts[3] == "True":
                            Bold = True
                    elif len(parts) == 5:
                        if parts[1] != "None":
                            Color = MySkinManager.GiveColor(parts[1])
                        if parts[2] != "None":
                            Font = MyLangManager.TrFont(parts[2])
                        if parts[3] == "True":
                            Bold = True
                        if parts[4] == "True":
                            Und = True

                    a = Text(Txt, Color, Font, Bold, Und)
                    d = d + a.Words()

                self._Board.SetAndBlitText(d)

    def KeyDown(self, event):
        if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
            self.ReturnToUpLevelPage()
            self._Screen.Draw()
            self._Screen.SwapAndShow()
            return

    def Draw(self):
        self.ClearCanvas()
        if self._BGpng != None:
            self._BGpng.NewCoord((self._Width - self._BGpng._Width) / 2,
                                 self._Padding.y)
            self._BGpng.DrawTopLeft()
            self._Board._PosY = self._BGpng._Height + self._Padding.y + self._Padding.h
        else:
            self._Board._PosY = self._Padding.y

        self._Board.Draw()
Ejemplo n.º 4
0
class MusicLibListPage(Page):

    _Icons = {}
    _Selector = None
    _FootMsg = ["Nav", "", "Scan", "Back", "Add to Playlist"]
    _MyList = []
    _SwapMyList = []
    _ListFont = MyLangManager.TrFont("notosanscjk15")
    _MyStack = None

    _Scroller = None

    _BGpng = None
    _BGwidth = 56
    _BGheight = 70

    def __init__(self):
        Page.__init__(self)
        self._Icons = {}
        self._CanvasHWND = None
        self._MyList = []
        self._SwapMyList = []
        self._MyStack = MusicLibStack()

    def SyncList(self, path):
        if myvars.Poller == None:
            return

        alist = myvars.Poller.listfiles(path)
        if alist == False:
            print("listfiles return false")
            return

        self._MyList = []
        self._SwapMyList = []

        start_x = 0
        start_y = 0
        hasparent = 0
        if self._MyStack.Length() > 0:
            hasparent = 1
            li = ListItem()
            li._Parent = self
            li._PosX = start_x
            li._PosY = start_y
            li._Width = Width
            li._Fonts["normal"] = self._ListFont
            li._MyType = ICON_TYPES["DIR"]
            li._Parent = self
            li.Init("[..]")
            self._MyList.append(li)

        for i, v in enumerate(sorted(alist)):
            li = ListItem()
            li._Parent = self
            li._PosX = start_x
            li._PosY = start_y + (i + hasparent) * ListItem._Height
            li._Width = Width
            li._Fonts["normal"] = self._ListFont
            li._MyType = ICON_TYPES["FILE"]
            li._Parent = self

            if "directory" in v:
                li._MyType = ICON_TYPES["DIR"]
                dir_base_name = os.path.basename(v["directory"])
                li.Init(dir_base_name)
                li._Path = v["directory"]
            elif "file" in v:
                bname = os.path.basename(v["file"])
                li.Init(bname)
                li._Path = v["file"]

            else:
                li.Init("NoName")

            self._MyList.append(li)

        for i in self._MyList:
            self._SwapMyList.append(i)

    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(MyLangManager.Tr("Please upload data over Wi-Fi"),
                             MyLangManager.TrFont("varela22"))
        self._BGpng.SetLableColor(MySkinManager.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()

    def Click(self):
        if len(self._MyList) == 0:
            return

        cur_li = self._MyList[self._PsIndex]

        if cur_li._MyType == ICON_TYPES["DIR"]:
            if cur_li._Path == "[..]":
                self._MyStack.Pop()
                self.SyncList(self._MyStack.Last())
                self._PsIndex = 0
            else:
                self._MyStack.Push(self._MyList[self._PsIndex]._Path)
                self.SyncList(self._MyStack.Last())
                self._PsIndex = 0

        if cur_li._MyType == ICON_TYPES["FILE"]:  ## add to playlist only
            myvars.Poller.addfile(cur_li._Path)
            myvars.PlayListPage.SyncList()
            print("add", cur_li._Path)

        self._Screen.Draw()
        self._Screen.SwapAndShow()

    def Rescan(self):
        self.SyncList("/")
        self._PsIndex = 0

    def KeyDown(self, event):

        if IsKeyMenuOrB(event.key) or event.key == CurKeys["Left"]:

            self.ReturnToUpLevelPage()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Up"]:
            self.ScrollUp()
            self._Screen.Draw()
            self._Screen.SwapAndShow()
        if event.key == CurKeys["Down"]:
            self.ScrollDown()
            self._Screen.Draw()
            self._Screen.SwapAndShow()
        """
        if event.key == CurKeys["Right"]:
            self.FScrollDown(Step=5)
            self._Screen.Draw()
            self._Screen.SwapAndShow()
            
        if event.key == CurKeys["Left"]:
            self.FScrollUp(Step=5)
            self._Screen.Draw()
            self._Screen.SwapAndShow()
        """

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

        if IsKeyStartOrA(event.key):
            self.Click()

    def Draw(self):
        self.ClearCanvas()
        """
        start_x = 0
        start_y = 0
        counter = 0
        
        self._MyList = []
        
        for i,v in enumerate(self._SwapMyList):
            if myvars.PlayListPage.InPlayList(v._Path):
                v._Active = True
            else:
                v._Active = False

            if v._Active == False:
                v.NewCoord(start_x, start_y+counter* ListItem._Height)
                counter+=1
                self._MyList.append(v)
        """

        if len(self._MyList) == 0:
            self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
            self._BGpng.Draw()
            return

        else:
            if len(self._MyList) * ListItem._Height > self._Height:
                self._Ps._Width = self._Width - 11

                self._Ps.Draw()
                for i in self._MyList:
                    if myvars.PlayListPage.InPlayList(i._Path):
                        i._Active = True
                    else:
                        i._Active = False

                    if i._PosY > self._Height + self._Height / 2:
                        break

                    if i._PosY < 0:
                        continue

                    i.Draw()

                self._Scroller.UpdateSize(
                    len(self._MyList) * ListItem._Height,
                    self._PsIndex * ListItem._Height)
                self._Scroller.Draw()
            else:
                self._Ps._Width = self._Width
                self._Ps.Draw()
                for i in self._MyList:
                    if myvars.PlayListPage.InPlayList(i._Path):
                        i._Active = True
                    else:
                        i._Active = False

                    if i._PosY > self._Height + self._Height / 2:
                        break

                    if i._PosY < 0:
                        continue

                    i.Draw()
Ejemplo n.º 5
0
class PlayListPage(Page):

    _Icons = {}
    _Selector = None
    _FootMsg = ["Nav", "Remove", "RTA", "Back", "Play/Pause"]
    _MyList = []
    _ListFont = MyLangManager.TrFont("notosanscjk15")

    _Scroller = None
    _CurSongTime = "0:0"

    _BGpng = None
    _BGwidth = 75
    _BGheight = 70

    _Scrolled = 0

    _CurSongName = ""

    def __init__(self):
        self._Icons = {}
        Page.__init__(self)
        self._CanvasHWND = None
        self._MyList = []

    def SyncList(self):
        self._MyList = []
        start_x = 0
        start_y = 0
        if myvars.Poller == None:
            return

        play_list = myvars.Poller.playlist()
        for i, v in enumerate(play_list):
            li = ListItem()
            li._Parent = self
            li._PosX = start_x
            li._PosY = start_y + i * ListItem._Height
            li._Width = Width
            li._Fonts["normal"] = self._ListFont

            if "title" in v:
                if isinstance(v["title"], (list, )):
                    li.Init(" | ".join(v["title"]))
                else:
                    li.Init(v["title"])

                if "file" in v:
                    li._Path = v["file"]

            elif "file" in v:
                li.Init(os.path.basename(v["file"]))
                li._Path = v["file"]
            else:
                li.Init("NoName")

            li._Labels["Text"]._PosX = 7
            self._MyList.append(li)

        self.SyncPlaying()

    def GObjectInterval(self):  ## 250 ms
        self.SyncPlaying()

        if self._Screen.CurPage() == self:
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        return True

    def SyncPlaying(self):
        if myvars.Poller == None:
            return

        current_song = myvars.Poller.poll()

        for i, v in enumerate(self._MyList):
            self._MyList[i]._Playing = False
            self._MyList[i]._PlayingProcess = 0

        if current_song != None:
            if "song" in current_song:
                posid = int(current_song["song"])
                if posid < len(self._MyList):  # out of index
                    self._CurSongName = self._MyList[posid]._Text

                    if "state" in current_song:
                        if current_song["state"] == "stop":
                            self._MyList[posid]._Playing = False
                        else:
                            self._MyList[posid]._Playing = True
                    if "time" in current_song:
                        self._CurSongTime = current_song["time"]
                        times_ = current_song["time"].split(":")
                        if len(times_) > 1:
                            cur = float(times_[0])
                            end = float(times_[1])
                            pros = int((cur / end) * 100.0)
                            self._MyList[posid]._PlayingProcess = pros

    def InPlayList(self, path):
        for i, v in enumerate(self._MyList):
            if v._Path == path:
                return True

    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(MyLangManager.Tr("my favorite music"),
                             MyLangManager.TrFont("varela18"))
        self._BGpng.SetLableColor(MySkinManager.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()

    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
            self._Scrolled += 1

    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
            self._Scrolled -= 1

    def SyncScroll(self):  # show where it left
        if self._Scrolled == 0:
            return

        if self._PsIndex < len(self._MyList):
            cur_li = self._MyList[self._PsIndex]
            if self._Scrolled > 0:
                if cur_li._PosY < 0:
                    for i in range(0, len(self._MyList)):
                        self._MyList[i]._PosY += self._Scrolled * self._MyList[
                            i]._Height
            elif self._Scrolled < 0:
                if cur_li._PosY + cur_li._Height > self._Height:
                    for i in range(0, len(self._MyList)):
                        self._MyList[i]._PosY += self._Scrolled * self._MyList[
                            i]._Height

    def Click(self):
        if len(self._MyList) == 0:
            return

        cur_li = self._MyList[self._PsIndex]
        play_pos_id = myvars.Poller.play(self._PsIndex)

        self.SyncPlaying()

        self._Screen.Draw()
        self._Screen.SwapAndShow()

    def OnReturnBackCb(self):  # return from music_lib_list_page
        self.SyncList()
        self.SyncScroll()

    def KeyDown(self, event):
        if IsKeyMenuOrB(event.key):
            if myvars.Poller != None:
                myvars.Poller.stop()
                self._CurSongTime = ""
                self._CurSongName = ""

            self.ReturnToUpLevelPage()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Up"]:
            self.ScrollUp()
            self._Screen.Draw()
            self._Screen.SwapAndShow()
        if event.key == CurKeys["Down"]:
            self.ScrollDown()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Right"]:  #add
            self._Screen.PushCurPage()
            self._Screen.SetCurPage(myvars.MusicLibListPage)
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Y"]:  # del selected songs
            myvars.Poller.delete(self._PsIndex)
            self.SyncList()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if IsKeyStartOrA(event.key):
            self.Click()

        if event.key == CurKeys["X"]:  # start spectrum
            myvars.SpectrumPage._Neighbor = self
            self._Screen.PushPage(myvars.SpectrumPage)
            self._Screen.Draw()
            self._Screen.SwapAndShow()

    def Draw(self):
        self.ClearCanvas()

        if len(self._MyList) == 0:
            self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
            self._BGpng.Draw()
            return
        else:
            if len(self._MyList) * ListItem._Height > self._Height:
                self._Ps._Width = self._Width - 11
                self._Ps.Draw()
                for i in self._MyList:
                    if i._PosY > self._Height + self._Height / 2:
                        break

                    if i._PosY < 0:
                        continue

                    i.Draw()
                self._Scroller.UpdateSize(
                    len(self._MyList) * ListItem._Height,
                    self._PsIndex * ListItem._Height)
                self._Scroller.Draw()
            else:
                self._Ps._Width = self._Width
                self._Ps.Draw()
                for i in self._MyList:

                    if i._PosY > self._Height + self._Height / 2:
                        break

                    if i._PosY < 0:
                        continue

                    i.Draw()
Ejemplo n.º 6
0
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._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_, 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 TimezoneListPage(Page):

    _Icons = {}
    _Selector = None
    _FootMsg = ["Nav", "", "", "Back", "Select"]
    _MyList = []
    _SwapMyList = []
    _ListFont = MyLangManager.TrFont("notosanscjk15")
    _MyStack = None

    _Scroller = None

    _BGpng = None
    _BGwidth = 56
    _BGheight = 70

    def __init__(self):
        Page.__init__(self)
        self._Icons = {}
        self._CanvasHWND = None
        self._MyList = []
        self._SwapMyList = []
        self._MyStack = TimeLibStack()

    def buildDirectoryList(self, path):
        elements = [{
            'name': f,
            'file_path': os.path.join(path, f),
            'is_file': os.path.isfile(os.path.join(path, f))
        } for f in os.listdir(path)]
        return elements

    def SyncList(self, path):

        alist = self.buildDirectoryList(path)
        if not alist:
            print("buildDirectoryList empty")
            return

        self._MyList = []
        self._SwapMyList = []

        start_x = 0
        start_y = 0
        hasparent = 0
        if self._MyStack.Length() > 0:
            hasparent = 1
            li = ListItem()
            li._Parent = self
            li._PosX = start_x
            li._PosY = start_y
            li._Width = Width
            li._Fonts["normal"] = self._ListFont
            li._MyType = ICON_TYPES["DIR"]
            li.Init("[..]")
            self._MyList.append(li)

        for i, v in enumerate(sorted(alist)):
            li = ListItem()
            li._Parent = self
            li._PosX = start_x
            li._PosY = start_y + (i + hasparent) * ListItem._Height
            li._Width = Width
            li._Fonts["normal"] = self._ListFont
            li._MyType = ICON_TYPES["FILE"]

            if not v['is_file']:
                li._MyType = ICON_TYPES["DIR"]
            else:
                li._MyType = ICON_TYPES["FILE"]

            li.Init(v['name'])
            li._Path = v["file_path"]

            self._MyList.append(li)

        for i in self._MyList:
            self._SwapMyList.append(i)

    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("/usr/share/zoneinfo/posix")

        icon_for_list = MultiIconItem()
        icon_for_list._ImgSurf = MyIconPool.GiveIconSurface("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.GiveIconSurface("empty")
        self._BGpng._MyType = ICON_TYPES["STAT"]
        self._BGpng._Parent = self
        self._BGpng.AddLabel("No timezones found on system!",
                             MyLangManager.TrFont("varela22"))
        self._BGpng.SetLableColor(MySkinManager.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()

    def Click(self):
        if len(self._MyList) == 0:
            return

        cur_li = self._MyList[self._PsIndex]

        if cur_li._MyType == ICON_TYPES["DIR"]:
            if cur_li._Path == "[..]":
                self._MyStack.Pop()
                self.SyncList(self._MyStack.Last())
                self._PsIndex = 0
            else:
                self._MyStack.Push(self._MyList[self._PsIndex]._Path)
                self.SyncList(self._MyStack.Last())
                self._PsIndex = 0

        if cur_li._MyType == ICON_TYPES["FILE"]:  ## set the current timezone
            subprocess.call(['sudo', 'cp', cur_li._Path, '/etc/localtime'])
            #copyfile(cur_li._Path, '/etc/localtime')
            print("add", cur_li._Path)

        self._Screen.Draw()
        self._Screen.SwapAndShow()

    def Rescan(self):
        self.SyncList("/usr/share/zoneinfo/posix")
        self._PsIndex = 0

    def KeyDown(self, event):

        if IsKeyMenuOrB(event.key):

            self.ReturnToUpLevelPage()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Up"]:
            self.ScrollUp()
            self._Screen.Draw()
            self._Screen.SwapAndShow()
        if event.key == CurKeys["Down"]:
            self.ScrollDown()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Right"]:
            self.FScrollDown(Step=5)
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Left"]:
            self.FScrollUp(Step=5)
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if IsKeyStartOrA(event.key):
            self.Click()

    def Draw(self):
        self.ClearCanvas()

        if len(self._MyList) == 0:
            self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
            self._BGpng.Draw()
            return

        else:
            if len(self._MyList) * ListItem._Height > self._Height:
                self._Ps._Width = self._Width - 11

                self._Ps.Draw()
                for i in self._MyList:
                    if False:
                        i._Active = True
                    else:
                        i._Active = False

                    if i._PosY > self._Height + self._Height / 2:
                        break

                    if i._PosY < 0:
                        continue

                    i.Draw()

                self._Scroller.UpdateSize(
                    len(self._MyList) * ListItem._Height,
                    self._PsIndex * ListItem._Height)
                self._Scroller.Draw()
            else:
                self._Ps._Width = self._Width
                self._Ps.Draw()
                for i in self._MyList:
                    if False:
                        i._Active = True
                    else:
                        i._Active = False

                    if i._PosY > self._Height + self._Height / 2:
                        break

                    if i._PosY < 0:
                        continue

                    i.Draw()
Ejemplo n.º 8
0
class SoundSlider(Slider):
    OnChangeCB = None

    _BGpng = None
    _BGwidth = 192
    _BGheight = 173

    _NeedleSurf = None
    _Scale = None
    _Parent = None
    _Segs = [0, 15, 29, 45, 55, 65, 75, 90, 100]
    snd_segs = [[0, 20], [21, 40], [41, 50], [51, 60], [61, 70], [71, 85],
                [86, 90], [91, 95], [96, 100]]

    def __init__(self):
        Slider.__init__(self)

    def Init(self):
        self._Width = self._Parent._Width
        self._Height = self._Parent._Height

        self._BGpng = IconItem()
        self._BGpng._ImgSurf = MyIconPool._Icons["vol"]
        self._BGpng._MyType = ICON_TYPES["STAT"]
        self._BGpng._Parent = self
        self._BGpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)

        ##self._NeedleSurf = pygame.Surface( (38,12),pygame.SRCALPHA )

        self._Scale = MultiIconItem()
        self._Scale._MyType = ICON_TYPES["STAT"]
        self._Scale._Parent = self
        self._Scale._ImgSurf = MyIconPool._Icons["scale"]
        self._Scale._IconWidth = 82
        self._Scale._IconHeight = 63
        self._Scale.Adjust(0, 0, 82, 63, 0)

    def SetValue(self, pct):  #pct 0-100

        for i, v in enumerate(self.snd_segs):
            if pct >= v[0] and pct <= v[1]:
                self._Value = i

    def Further(self):
        self._Value += 1
        if self._Value < len(self._Segs):
            if self.OnChangeCB != None:
                if callable(self.OnChangeCB):
                    self.OnChangeCB(self._Segs[self._Value])
        else:
            self._Value = len(self._Segs) - 1

    def StepBack(self):
        self._Value -= 1

        if self._Value < 0:
            self._Value = 0

        if self.OnChangeCB != None:
            if callable(self.OnChangeCB):
                self.OnChangeCB(self._Segs[self._Value])

    def Draw(self):

        self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
        self._BGpng.Draw()

        self._Scale.NewCoord(self._Width / 2, self._Height / 2)

        self._Scale._IconIndex = self._Value

        self._Scale.Draw()
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
class PlayListPage(Page):

    _Icons = {}
    _Selector = None
    _FootMsg = ["Nav", "", "Remove", "Back", "Play/Pause"]
    _MyList = []
    _ListFont = fonts["notosanscjk15"]

    _Scroller = None

    _BGpng = None
    _BGwidth = 75
    _BGheight = 70

    def __init__(self):
        self._Icons = {}
        Page.__init__(self)
        self._CanvasHWND = None
        self._MyList = []

    def SyncList(self):
        self._MyList = []
        start_x = 0
        start_y = 0
        if myvars.Poller == None:
            return

        play_list = myvars.Poller.playlist()
        for i, v in enumerate(play_list):
            li = ListItem()
            li._Parent = self
            li._PosX = start_x
            li._PosY = start_y + i * ListItem._Height
            li._Width = Width
            li._Fonts["normal"] = self._ListFont

            if "title" in v:
                li.Init(v["title"])
                if "file" in v:
                    li._Path = v["file"]

            elif "file" in v:
                li.Init(os.path.basename(v["file"]))
                li._Path = v["file"]
            else:
                li.Init("NoName")

            li._Labels["Text"]._PosX = 7
            self._MyList.append(li)

        self.SyncPlaying()

    def GObjectInterval(self):  ## 250 ms
        if self._Screen.CurPage() == self:
            self.SyncPlaying()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        return True

    def SyncPlaying(self):
        if myvars.Poller == None:
            return

        current_song = myvars.Poller.poll()

        for i, v in enumerate(self._MyList):
            self._MyList[i]._Playing = False
            self._MyList[i]._PlayingProcess = 0

        if current_song != None:
            if "song" in current_song:
                posid = int(current_song["song"])
                if posid < len(self._MyList):  # out of index
                    if "state" in current_song:
                        if current_song["state"] == "stop":
                            self._MyList[posid]._Playing = False
                        else:
                            self._MyList[posid]._Playing = True
                    if "time" in current_song:
                        times_ = current_song["time"].split(":")
                        if len(times_) > 1:
                            cur = float(times_[0])
                            end = float(times_[1])
                            pros = int((cur / end) * 100.0)
                            self._MyList[posid]._PlayingProcess = pros

    def InPlayList(self, path):
        for i, v in enumerate(self._MyList):
            if v._Path == path:
                return True

    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(pygame.Color(204, 204, 204))
        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()

    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):
        if len(self._MyList) == 0:
            return

        cur_li = self._MyList[self._PsIndex]
        play_pos_id = myvars.Poller.play(self._PsIndex)

        self.SyncPlaying()

        self._Screen.Draw()
        self._Screen.SwapAndShow()

    def OnReturnBackCb(self):
        self.SyncList()

    def KeyDown(self, event):
        if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
            if myvars.Poller != None:
                myvars.Poller.stop()

            self.ReturnToUpLevelPage()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Up"]:
            self.ScrollUp()
            self._Screen.Draw()
            self._Screen.SwapAndShow()
        if event.key == CurKeys["Down"]:
            self.ScrollDown()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Right"]:  #add
            self._Screen.PushCurPage()
            self._Screen.SetCurPage(myvars.MusicLibListPage)
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Y"]:  # del selected songs
            myvars.Poller.delete(self._PsIndex)
            self.SyncList()
            self._Screen.Draw()
            self._Screen.SwapAndShow()

        if event.key == CurKeys["Enter"]:
            self.Click()

        if event.key == CurKeys["Start"]:  # start spectrum
            self._Screen.PushPage(myvars.SpectrumPage)
            self._Screen.Draw()
            self._Screen.SwapAndShow()

    def Draw(self):
        self.ClearCanvas()

        if len(self._MyList) == 0:
            self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
            self._BGpng.Draw()
            return
        else:
            if len(self._MyList) * ListItem._Height > self._Height:
                self._Ps._Width = self._Width - 11
                self._Ps.Draw()
                for i in self._MyList:
                    i.Draw()
                self._Scroller.UpdateSize(
                    len(self._MyList) * ListItem._Height,
                    self._PsIndex * ListItem._Height)
                self._Scroller.Draw()
            else:
                self._Ps._Width = self._Width
                self._Ps.Draw()
                for i in self._MyList:
                    i.Draw()