Ejemplo n.º 1
0
class BatteryPage(Page):

    _FootMsg = ["Nav", "", "Refresh", "Back", "Enter"]
    _Label = None

    def Init(self):
        self._CanvasHWND = self._Screen._CanvasHWND
        self._Width = self._Screen._Width
        self._Height = self._Screen._Height

        self._Label = Label()
        self._Label.SetCanvasHWND(self._CanvasHWND)
        self._Label.Init('', MySkinManager.GiveFont('varela25'))

    def _update_percent(self):
        self._Label.SetText('%s %%' % get_battery_percent())
        rect = midRect(self._Width / 2, self._Height / 2, self._Label._Width,
                       self._Label._Height, Width, Height)
        self._Label.NewCoord(rect.left, rect.top)

    def OnLoadCb(self):
        self._update_percent()

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

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

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

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

    def Draw(self):
        self.ClearCanvas()
        self._Label.Draw()
Ejemplo n.º 2
0
class DownloadProcessPage(Page):
    _FootMsg = ["Nav.", "", "", "Back", ""]
    _Downloader = None
    _DownloaderTimer = -1
    _Value = 0

    _URL = ""
    _DST_DIR = ""

    _PngSize = {}

    _FileNameLabel = None
    _SizeLabel = None

    _URLColor = MySkinManager.GiveColor('URL')
    _TextColor = MySkinManager.GiveColor('Text')

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

    def Init(self):
        self._PosX = self._Index * self._Screen._Width
        self._Width = self._Screen._Width
        self._Height = self._Screen._Height

        self._CanvasHWND = self._Screen._CanvasHWND

        self._PngSize["bg"] = (48, 79)
        self._PngSize["needwifi_bg"] = (253, 132)

        bgpng = IconItem()
        bgpng._ImgSurf = MyIconPool._Icons["rom_download"]
        bgpng._MyType = ICON_TYPES["STAT"]
        bgpng._Parent = self
        bgpng.Adjust(0, 0, self._PngSize["bg"][0], self._PngSize["bg"][1], 0)
        self._Icons["bg"] = bgpng

        needwifi_bg = IconItem()
        needwifi_bg._ImgSurf = MyIconPool._Icons["needwifi_bg"]
        needwifi_bg._MyType = ICON_TYPES["STAT"]
        needwifi_bg._Parent = self
        needwifi_bg.Adjust(0, 0, self._PngSize["needwifi_bg"][0],
                           self._PngSize["needwifi_bg"][1], 0)

        self._Icons["needwifi_bg"] = needwifi_bg

        self._FileNameLabel = Label()
        self._FileNameLabel.SetCanvasHWND(self._CanvasHWND)
        self._FileNameLabel.Init("", MyLangManager.TrFont("varela12"))

        self._SizeLabel = Label()
        self._SizeLabel.SetCanvasHWND(self._CanvasHWND)
        self._SizeLabel.Init("0/0Kb", MyLangManager.TrFont("varela12"))
        self._SizeLabel.SetColor(self._URLColor)

    def OnExitCb(self, event):
        print("DownloadProcessPage OnExitCb")
        if self._Downloader == None:
            return
        try:
            self._Downloader.stop()
        except:
            pass
        return

    def GObjectUpdateProcessInterval(self):
        if self._Screen.CurPage() == self:
            if self._Downloader.isFinished():
                if self._Downloader.isSuccessful():
                    print("Success!")
                    # Do something with obj.get_dest()
                    filename = os.path.basename(self._Downloader.get_dest())
                    cur_dir = os.getcwd()

                    if filename.endswith(".zip"):
                        os.chdir(self._DST_DIR)
                        os.system("unzip " + filename)

                    elif filename.endswith(".zsync"):
                        os.chdir(self._DST_DIR)
                        os.system("rm -rf " + filename)

                    elif filename.endswith(".tar.xz"):
                        os.chdir(self._DST_DIR)
                        os.system("tar xf " + filename)
                        os.system("rm -rf " + filename)

                    os.chdir(cur_dir)
                    self.ReturnToUpLevelPage()
                    self._Screen.Draw()
                    self._Screen.SwapAndShow()

                else:
                    print("Download failed with the following exceptions:")
                    for e in self._Downloader.get_errors():
                        print(unicode(e))

                    try:
                        self._Downloader.stop()
                    except:
                        pass

                    self._Screen._MsgBox.SetText("DownloadFailed")
                    self._Screen._MsgBox.Draw()
                    self._Screen.SwapAndShow()
                    return False
            else:
                self._Value = self._Downloader.get_progress()

                filename = os.path.basename(self._Downloader.get_dest())
                self._FileNameLabel.SetText(filename)

                downloaded = self._Downloader.progress["downloaded"]
                total = self._Downloader.progress["total"]

                downloaded = downloaded / 1000.0 / 1000.0
                total = total / 1000.0 / 1000.0

                self._SizeLabel.SetText("%.2f" % downloaded + "/" +
                                        "%.2f" % total + "Mb")

                print("Progress: %d%%" % (self._Value))
                self._Screen.Draw()
                self._Screen.SwapAndShow()
                return True
        else:
            return False

    def StartDownload(self, url, dst_dir):
        if is_wifi_connected_now() == False:
            return

        if validators.url(url) and os.path.isdir(dst_dir):
            self._URL = url
            self._DST_DIR = dst_dir
        else:
            self._Screen._MsgBox.SetText("Invaid")
            self._Screen._MsgBox.Draw()
            self._Screen.SwapAndShow()
            print("url or dst dir error")
            return

        self._Downloader = Download(url, dst_dir, None)
        self._Downloader.start()

        self._DownloaderTimer = gobject.timeout_add(
            100, self.GObjectUpdateProcessInterval)

    def KeyDown(self, event):
        if IsKeyMenuOrB(event.key):
            gobject.source_remove(self._DownloaderTimer)
            self._DownloaderTimer = -1

            if self._Downloader != None:
                try:
                    self._Downloader.stop()
                except:
                    print("user canceled ")

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

    def Draw(self):
        self.ClearCanvas()

        if is_wifi_connected_now() == False:
            self._Icons["needwifi_bg"].NewCoord(self._Width / 2,
                                                self._Height / 2)
            self._Icons["needwifi_bg"].Draw()
            return

        self._Icons["bg"].NewCoord(self._Width / 2, self._Height / 2 - 20)
        self._Icons["bg"].Draw()

        percent = self._Value
        if percent < 10:
            percent = 10

        rect_ = midRect(self._Width / 2, self._Height / 2 + 33, 170, 17, Width,
                        Height)
        aa_round_rect(self._CanvasHWND, rect_,
                      MySkinManager.GiveColor('TitleBg'), 5, 0,
                      MySkinManager.GiveColor('TitleBg'))

        rect2 = midRect(self._Width / 2, self._Height / 2 + 33,
                        int(170 * (percent / 100.0)), 17, Width, Height)
        rect2.left = rect_.left
        rect2.top = rect_.top
        aa_round_rect(self._CanvasHWND, rect2,
                      MySkinManager.GiveColor('Front'), 5, 0,
                      MySkinManager.GiveColor('Front'))

        rect3 = midRect(self._Width / 2, self._Height / 2 + 53,
                        self._FileNameLabel._Width,
                        self._FileNameLabel._Height, Width, Height)

        rect4 = midRect(self._Width / 2, self._Height / 2 + 70,
                        self._SizeLabel._Width, self._SizeLabel._Height, Width,
                        Height)

        self._FileNameLabel.NewCoord(rect3.left, rect3.top)
        self._SizeLabel.NewCoord(rect4.left, rect4.top)

        self._FileNameLabel.Draw()
        self._SizeLabel.Draw()
Ejemplo n.º 3
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'))
Ejemplo n.º 4
0
class BSlider(Slider):

    
    OnChangeCB = None
    _Parent     = None
    _Icons      = {}
    
    def __init__(self):
        Slider.__init__(self)
        self._Icons = {}
    def Init(self):
        self._Width = self._Parent._Width
        self._Height = self._Parent._Height
        
        self._BrightnessLabel = Label()
        self._BrightnessLabel.SetCanvasHWND(self._CanvasHWND)
        self._BrightnessLabel.Init("BRIGHT",MySkinManager.GiveFont("EurostileBold13"))
        self._BrightnessLabel.SetColor(MySkinManager.GiveColor('Text'))
        

    def SetValue(self,brt):
        self._Value = brt
        
    def Further(self):
        self._Value+=1
        if self._Value > 9:
            self._Value = 9
            
        if self.OnChangeCB != None:
            if callable(self.OnChangeCB):
                self.OnChangeCB(self._Value)
                    
    def StepBack(self):
        self._Value-=1

        if self._Value < 1:
            self._Value = 1

        if self.OnChangeCB != None:
            if callable(self.OnChangeCB):
                self.OnChangeCB(self._Value)
    
    def Draw(self):
        start_x = 82
        start_y = self._Parent._Screen._Height/2-5
        height = 30
        width = 4
        padding = 15
        seg = self._Value-1

        for i in range(0,9):
            rect = pygame.Rect(start_x+i*(width+padding),start_y,width,height)
            if i > seg:
                pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('Text'),rect, 1)
                #aa_round_rect(self._CanvasHWND,rect, MySkinManager.GiveColor('Text'),1,1, MySkinManager.GiveColor('White'))
            else:
                pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('Text'),rect, 0)   
                #aa_round_rect(self._CanvasHWND,rect, MySkinManager.GiveColor('Text'),1,0, MySkinManager.GiveColor('White'))
        
        self._BrightnessLabel.NewCoord(118,self._Parent._Screen._Height/2-30)
        self._BrightnessLabel.Draw(True)
        
        minus_box_rect = pygame.Rect(start_x- (4+6)*4,start_y,6*4,30)
        pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('Text'),minus_box_rect, 0) 
        
        minus_rect     = pygame.Rect(start_x-8*4,start_y+14,2*4,2)
        pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('White'),minus_rect, 0) 
        
        plus_box_rect = pygame.Rect(start_x + 39*4 +4*4,start_y,6*4,30)
        pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('Text'),plus_box_rect, 0) 
        
        cross1_rect     = pygame.Rect(start_x+39*4+4*4+2*4,start_y+14,2*4,2)
        pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('White'),cross1_rect, 0) 
        cross2_rect     = pygame.Rect(start_x+39*4+4*4+2*4+3,start_y+14-3,2,2*4)
        pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('White'),cross2_rect, 0) 
Ejemplo n.º 5
0
class LoadHousePage(Page):
    _FootMsg = ["Nav.", "", "", "Back", "Cancel"]
    _Value = 0
    _URL = None
    _ListFontObj = MyLangManager.TrFont("varela18")
    _URLColor = MySkinManager.GiveColor('URL')
    _TextColor = MySkinManager.GiveColor('Text')
    _Caller = None
    _img = None
    _Downloader = None
    _DownloaderTimer = -1

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

    def Init(self):
        self._PosX = self._Index * self._Screen._Width
        self._Width = self._Screen._Width
        self._Height = self._Screen._Height

        self._CanvasHWND = self._Screen._CanvasHWND
        self._LoadingLabel = Label()
        self._LoadingLabel.SetCanvasHWND(self._CanvasHWND)
        self._LoadingLabel.Init("Loading", self._ListFontObj)
        self._LoadingLabel.SetColor(self._TextColor)

    def OnLoadCb(self):
        if self._URL is None:
            return
        self._img = None
        self.ClearCanvas()
        self._Screen.Draw()
        self._Screen.SwapAndShow()

        filename = self._URL.split("/")[-1].strip()
        local_dir = self._URL.split("raw.githubusercontent.com")

        if len(local_dir) > 1:
            menu_file = local_dir[1]
            local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),
                                                      menu_file)

            if FileExists(local_menu_file):
                #load json
                with open(local_menu_file) as json_file:
                    try:
                        local_menu_json = json.load(json_file)
                        self._Caller._MyStack.Push(local_menu_json["list"])
                    except:
                        pass

                    self.Leave()

            else:
                self._Downloader = Download(self._URL, "/tmp", None)
                self._Downloader.start()
                self._DownloaderTimer = gobject.timeout_add(
                    400, self.GObjectUpdateProcessInterval)

    def GObjectUpdateProcessInterval(self):
        ret = True
        if self._Screen.CurPage() == self:
            if self._Downloader._stop == True:
                ret = False

            dst_filename = self._Downloader.get_dest()
            if self._Downloader.isFinished():
                if self._Downloader.isSuccessful():
                    filename = self._URL.split("/")[-1].strip()
                    local_dir = self._URL.split("raw.githubusercontent.com")
                    menu_file = local_dir[1]
                    local_menu_file = "%s/aria2download%s" % (
                        os.path.expanduser('~'), menu_file)

                    dl_file = os.path.join("/tmp", filename)
                    if not os.path.exists(os.path.dirname(local_menu_file)):
                        os.makedirs(os.path.dirname(local_menu_file))

                    copyfile(dl_file, local_menu_file)
                    with open(local_menu_file) as json_file:
                        try:
                            local_menu_json = json.load(json_file)
                            self._Caller._MyStack.Push(local_menu_json["list"])
                        except:
                            pass

                    ret = False

                    self.Leave()
                else:
                    self._Screen._MsgBox.SetText("Fetch house failed")
                    self._Screen._MsgBox.Draw()
                    self._Screen.SwapAndShow()
                    ret = False
            return ret
        else:
            return False

    def Leave(self):
        if self._DownloaderTimer != -1:
            gobject.source_remove(self._DownloaderTimer)
        self._DownloaderTimer = -1

        if self._Downloader != None:
            try:
                self._Downloader.stop()
            except:
                print("user canceled ")

        self.ReturnToUpLevelPage()
        self._Screen.Draw()
        self._Screen.SwapAndShow()
        self._URL = None

    def KeyDown(self, event):
        if IsKeyMenuOrB(event.key):
            self.Leave()

    def Draw(self):
        self.ClearCanvas()
        self._LoadingLabel.NewCoord((Width - self._LoadingLabel._Width) / 2,
                                    (Height - 44) / 2)
        self._LoadingLabel.Draw()

        if self._img is not None:
            self._CanvasHWND.blit(
                self._img,
                midRect(Width / 2, (Height - 44) / 2,
                        pygame.Surface.get_width(self._img),
                        pygame.Surface.get_height(self._img), Width,
                        Height - 44))
Ejemplo n.º 6
0
class Aria2DownloadProcessPage(Page):
    _FootMsg = ["Nav.", "", "Pause", "Back", "Cancel"]
    _DownloaderTimer = -1
    _Value = 0
    _GID = None

    _PngSize = {}

    _FileNameLabel = None
    _SizeLabel = None

    _URLColor = MySkinManager.GiveColor('URL')
    _TextColor = MySkinManager.GiveColor('Text')

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

    def Init(self):
        self._PosX = self._Index * self._Screen._Width
        self._Width = self._Screen._Width
        self._Height = self._Screen._Height

        self._CanvasHWND = self._Screen._CanvasHWND

        bgpng = IconItem()
        bgpng._ImgSurf = MyIconPool.GiveIconSurface("rom_download")
        bgpng._MyType = ICON_TYPES["STAT"]
        bgpng._Parent = self
        bgpng.Adjust(0, 0, self._PngSize["bg"][0], self._PngSize["bg"][1], 0)
        self._Icons["bg"] = bgpng

        self._FileNameLabel = Label()
        self._FileNameLabel.SetCanvasHWND(self._CanvasHWND)
        self._FileNameLabel.Init("", MyLangManager.TrFont("varela12"))

        self._SizeLabel = Label()
        self._SizeLabel.SetCanvasHWND(self._CanvasHWND)
        self._SizeLabel.Init("0/0Kb", MyLangManager.TrFont("varela12"))
        self._SizeLabel.SetColor(self._URLColor)

    @property
    def GObjectUpdateProcessInterval(self):
        downloaded = 0
        if self._Screen.CurPage() == self and self._GID is not None:
            self._Value = config.RPC.tellStatus(self._GID)

            downloaded = 0
            total = 0

        if self._Value["status"] == "waiting":
            self._FileNameLabel.SetText("waiting to download...")
        if self._Value["status"] == "paused":
            self._FileNameLabel.SetText("download paused...")
        if self._Value["status"] == "error":
            self._FileNameLabel.SetText("download errors,cancel it please")

        if self._Value["status"] == "active":
            downloaded = self._Value["completedLength"]
            total = self._Value["totalLength"]

            downloaded = downloaded / 1000.0 / 1000.0
            total = total / 1000.0 / 1000.0

        self._SizeLabel.SetText("%.2f" % downloaded + "/" + "%.2f" % total +
                                "Mb")

        print("Progress: %d%%" % (self._Value))
        self._Screen.Draw()
        self._Screen.SwapAndShow()
        return True

    def CheckDownload(self, aria2_gid):
        self._GID = aria2_gid
        self._DownloaderTimer = gobject.timeout_add(
            234, self.GObjectUpdateProcessInterval)

    def KeyDown(self, event):
        if IsKeyMenuOrB(event.key):
            gobject.source_remove(self._DownloaderTimer)
            self._DownloaderTimer = -1

            #if self._Downloader != None:
            #    try:
            #        self._Downloader.stop()
            #    except:
            #        print("user canceled ")

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

    def Draw(self):
        self.ClearCanvas()

        self._Icons["bg"].NewCoord(self._Width / 2, self._Height / 2 - 20)
        self._Icons["bg"].Draw()

        percent = self._Value
        if percent < 10:
            percent = 10

        rect_ = midRect(self._Width / 2, self._Height / 2 + 33, 170, 17, Width,
                        Height)
        aa_round_rect(self._CanvasHWND, rect_,
                      MySkinManager.GiveColor('TitleBg'), 5, 0,
                      MySkinManager.GiveColor('TitleBg'))

        rect2 = midRect(self._Width / 2, self._Height / 2 + 33,
                        int(170 * (percent / 100.0)), 17, Width, Height)
        rect2.left = rect_.left
        rect2.top = rect_.top
        aa_round_rect(self._CanvasHWND, rect2,
                      MySkinManager.GiveColor('Front'), 5, 0,
                      MySkinManager.GiveColor('Front'))

        rect3 = midRect(self._Width / 2, self._Height / 2 + 53,
                        self._FileNameLabel._Width,
                        self._FileNameLabel._Height, Width, Height)

        rect4 = midRect(self._Width / 2, self._Height / 2 + 70,
                        self._SizeLabel._Width, self._SizeLabel._Height, Width,
                        Height)

        self._FileNameLabel.NewCoord(rect3.left, rect3.top)
        self._SizeLabel.NewCoord(rect4.left, rect4.top)

        self._FileNameLabel.Draw()
        self._SizeLabel.Draw()
Ejemplo n.º 7
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.º 8
0
class StoragePage(Page):

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

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

    _TextColor = MySkinManager.GiveColor('Text')
    _FootMsg = ["Nav.", "", "", "Back", ""]

    def __init__(self):
        Page.__init__(self)

        self._Icons = {}

    def DiskUsage(self):
        statvfs = os.statvfs('/')

        total_space = (statvfs.f_frsize *
                       statvfs.f_blocks) / 1024.0 / 1024.0 / 1024.0

        avail_space = (statvfs.f_frsize *
                       statvfs.f_bavail) / 1024.0 / 1024.0 / 1024.0

        return avail_space, total_space

    def Init(self):

        self._DskUsg = self.DiskUsage()

        self._CanvasHWND = self._Screen._CanvasHWND
        self._Width = self._Screen._Width
        self._Height = self._Screen._Height

        self._GBLabel = Label()
        self._GBLabel.SetCanvasHWND(self._CanvasHWND)
        self._GBLabel.Init(
            self._GBmsg % (self._DskUsg[1] - self._DskUsg[0], self._DskUsg[1]),
            MySkinManager.GiveFont("varela11"))
        self._GBLabel.SetColor(self._TextColor)

        self._PctLabel = Label()
        self._PctLabel.SetCanvasHWND(self._CanvasHWND)

        usage_percent = (self._DskUsg[0] / self._DskUsg[1]) * 100.0

        self._PctLabel.Init("%d%%" % int(usage_percent),
                            MySkinManager.GiveFont("EurostileBold30"))
        self._PctLabel.SetColor(self._TextColor)

        self._FreeLabel = Label()
        self._FreeLabel.SetCanvasHWND(self._CanvasHWND)
        self._FreeLabel.Init("FREE", MySkinManager.GiveFont("varela12"))
        self._FreeLabel.SetColor(self._PctLabel._Color)

    def OnLoadCb(self):
        pass

    def Draw(self):
        self.ClearCanvas()

        self._PctLabel.NewCoord(32, 102 - 33)
        self._PctLabel.Draw()

        self._FreeLabel.NewCoord(33, 130 - 25)
        self._FreeLabel.Draw()

        self._GBLabel.NewCoord(145, 103 - 29)
        self._GBLabel.Draw()

        #bgcolor = (238,238,238), fgcolor = (126,206,244)

        usage_percent = (self._DskUsg[0] / self._DskUsg[1])
        if usage_percent < 0.1:
            usage_percent = 0.1

        rect_ = pygame.Rect(144, 118 - 25, 283 - 144, 139 - 117)

        pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'),
                         rect_, 1)

        rect2 = pygame.Rect(144, 118 - 25,
                            int((283 - 144) * (1.0 - usage_percent)),
                            139 - 117)

        rect2.left = rect_.left
        rect2.top = rect_.top

        pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'),
                         rect2, 0)

        sep_rect = pygame.Rect(129, 99 - 25, 2, 42)

        pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'),
                         sep_rect, 0)

        ##4 cross
        self.DrawCross(10, 10)
        self.DrawCross(self._Screen._Width - 20, 10)
        self.DrawCross(10, self._Screen._Height - 20)
        self.DrawCross(self._Screen._Width - 20, self._Screen._Height - 20)