def Draw(self,title):
        self.ClearCanvas()
        title = MyLangManager.Tr(title)
        self._Title = title
        
        cur_time =  datetime.now().strftime("%H:%M")
        time_text_font = MySkinManager.GiveFont("varela12")
        time_text_size = time_text_font.size(cur_time)
        title_text_size = MyLangManager.TrFont("varela16").size(title)

        self._CanvasHWND.blit(MyLangManager.TrFont("varela16").render(title,True,self._SkinManager.GiveColor("Text")),midRect(title_text_size[0]/2+self._LOffset,
                                                                    title_text_size[1]/2+(self._BarHeight-title_text_size[1])/2,
                                                                    title_text_size[0],title_text_size[1],Width,Height))
        self._CanvasHWND.blit( time_text_font.render(cur_time,True,self._SkinManager.GiveColor("Text")),midRect(Width-time_text_size[0]/2-self._ROffset,
                                                                        time_text_size[1]/2+(self._BarHeight-time_text_size[1])/2,
                                                                        time_text_size[0],time_text_size[1],Width,Height))

        start_x = Width-time_text_size[0]-self._ROffset-self._icon_width*3 # near by the time_text
        
        self._Icons["bluetooth"].NewCoord(start_x - self._icon_width,self._icon_height/2+(self._BarHeight-self._icon_height)/2)
        
        self._Icons["sound"].NewCoord(start_x, self._icon_height/2+(self._BarHeight-self._icon_height)/2)
        
        #self._Icons["wifi"].NewCoord(start_x+self._icon_width+5,    self._icon_height/2+(self._BarHeight-self._icon_height)/2)
        
        self._Icons["battery"].NewCoord(start_x+self._icon_width+self._icon_width+8,self._icon_height/2+(self._BarHeight-self._icon_height)/2)

        
        if is_wifi_connected_now():
            ge = self.GetWifiStrength(wifi_strength())
            if ge > 0:
                self._Icons["wifistatus"]._IconIndex = ge
                self._Icons["wifistatus"].NewCoord(start_x+self._icon_width+5,self._icon_height/2+(self._BarHeight-self._icon_height)/2)
                self._Icons["wifistatus"].Draw()
            else:
                self._Icons["wifistatus"]._IconIndex = 0
                self._Icons["wifistatus"].Draw()
                print("wifi strength error")
        else:
            if self._InAirPlaneMode == False:
                self._Icons["wifistatus"]._IconIndex = 0
            else:
                self._Icons["wifistatus"]._IconIndex = 5 ## airplane mode icon
            
            self._Icons["wifistatus"].NewCoord(start_x+self._icon_width+5,self._icon_height/2+(self._BarHeight-self._icon_height)/2)
            self._Icons["wifistatus"].Draw()
        
        self._Icons["sound"].Draw()
        
        self._Icons["battery"].Draw()
        
        self._Icons["bluetooth"].Draw()
        
        pygame.draw.line(self._CanvasHWND,self._SkinManager.GiveColor("Line"),(0,self._BarHeight),(self._Width,self._BarHeight),self._BorderWidth)

        if self._HWND != None:
            self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height))
Example #2
0
    def UpdateNavText(self, texts):
        self._State = "tips"
        texts = MyLangManager.Tr(texts)
        my_text = self._LabelFont.render(texts, True,
                                         self._SkinManager.GiveColor("Text"))
        """
        _w = 0
        for i, x in enumerate(("b","a","y","x")):
            if self._Icons[x]._Label._Text!="":
                if i==0:
                    _w += self._Icons[x].TotalWidth()
                else:
                    _w += self._Icons[x].TotalWidth()+5
        """
        left_width = self._Width - 18

        final_piece = ""
        for i, v in enumerate(texts):
            text_slice = texts[:i + 1]
            my_text = self._LabelFont.render(
                text_slice, True, self._SkinManager.GiveColor("Text"))
            final_piece = text_slice
            if my_text.get_width() >= left_width:
                break

        print("finalpiece %s" % final_piece)
        self._Icons["nav"]._Label.SetText(final_piece)

        self.Draw()
Example #3
0
    def SetLabelTexts(self,texts):
        barr = ["nav","y","x","b","a","select"]
        texts2 = texts + [""] if len(texts) == 5 else texts

        for idx,x in enumerate(barr):
            try:
                self._Icons[x]._Label.SetText(MyLangManager.Tr(texts2[idx]))
            except IndexError:
                print("Index "+x+" doesn't exist!")
Example #4
0
class Word:
    _T = ""
    _Color = MySkinManager.GiveColor('Text')  ## default text color
    _FontObj = MyLangManager.TrFont("Eurostile12")  ##default font
    _Size = 12
    _Bold = False
    _UndLine = False

    def SetColor(self, color):
        self._Color = color

    def GetColor(self):
        return self._Color

    def SetFont(self, fnt):
        self._FontObj = fnt

    def SetBold(self, bd):
        self._Bold = bd

    def SetUnderLine(self, bd):
        self._UndLine = bd

    def __init__(self, v=""):
        self._T = v

    def __str__(self):
        return self._T

    def __unicode__(self):
        return self._T.encode("utf-8")

    def __add__(self, a):
        return self._T + a

    def __repr__(self):
        return self._T

    def __len__(self):
        return len(self._T)

    def __eq__(self, other):
        return self._T == other

    def FnHeight(self):
        return self._FontObj.get_height()

    def Render(self):
        self._FontObj.set_bold(self._Bold)
        self._FontObj.set_underline(self._UndLine)

        sur = self._FontObj.render(self._T, True, self._Color)

        self._FontObj.set_bold(False)
        self._FontObj.set_underline(False)
        return sur
Example #5
0
    def SetLabelTexts(self, texts):

        barr = ["nav", "x", "y", "a", "b"]
        if self.GetButtonsLayoutMode() == "snes":
            barr = ["nav", "y", "x", "b", "a"]

        for idx, x in enumerate(barr):
            try:
                self._Icons[x]._Label.SetText(MyLangManager.Tr(texts[idx]))
            except IndexError:
                print("Index " + x + " doesn't exist!")
class DeleteConfirmPage(ConfirmPage):

    _FileName = ""
    _TrashDir = ""
    _ConfirmText = MyLangManager.Tr("ConfirmDeleteQ")

    def SetTrashDir(self, d):
        self._TrashDir = d

        if os.path.isdir(self._TrashDir) == False:
            raise IOError("Trash not existed")

    def SetFileName(self, fn):
        self._FileName = fn

    def KeyDown(self, event):

        if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:

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

        if event.key == CurKeys["B"]:
            try:
                os.remove(self._TrashDir + "/" +
                          os.path.basename(self._FileName))
            except:
                pass

            try:
                shutil.move(self._FileName, self._TrashDir)
            except shutil.Error as e:
                if "already exists" in str(e):
                    self._Screen._MsgBox.SetText("AlreadyExisted")
                else:
                    self._Screen._MsgBox.SetText("Error")

                self._Screen._MsgBox.Draw()
                self._Screen.SwapAndShow()
            else:
                self.SnapMsg(MyLangManager.Tr("Deleting"))
                self._Screen.Draw()
                self._Screen.SwapAndShow()
                self.Reset()

                pygame.time.delay(300)
                self.ReturnToUpLevelPage()
                self._Screen.Draw()
                self._Screen.SwapAndShow()

            print(self._FileName)
Example #7
0
class AboveAllPatch(Widget):
    _PosX = Width / 2
    _PosY = Height / 2
    _Width = 50
    _Height = 120

    _Text = ""
    _FontObj = MyLangManager.TrFont("veramono20")
    _Parent = None
    _Color = MySkinManager.GiveColor('Text')
    _ValColor = MySkinManager.GiveColor('URL')
    _CanvasHWND = None
    _TextSurf = None
    _Icons = {}
    _Value = 0

    def __init__(self):
        self._Icons = {}

    def Init(self):
        pass

    def SetCanvasHWND(self, _canvashwnd):
        self._CanvasHWND = _canvashwnd

    def Draw(self):
        start_rect = midRect(self._PosX, self._PosY, self._Width, self._Height,
                             Width, Height)
        aa_round_rect(self._CanvasHWND, start_rect, self._Color, 3, 0,
                      self._Color)

        if self._Value > 10:
            vol_height = int(self._Height * (float(self._Value) / 100.0))
            dheight = self._Height - vol_height

            vol_rect = pygame.Rect(self._PosX - self._Width / 2,
                                   self._PosY - self._Height / 2 + dheight,
                                   self._Width, vol_height)

            aa_round_rect(self._CanvasHWND, vol_rect, self._ValColor, 3, 0,
                          self._ValColor)

        else:
            vol_height = 10
            dheight = self._Height - vol_height
            vol_rect = pygame.Rect(self._PosX - self._Width / 2,
                                   self._PosY - self._Height / 2 + dheight,
                                   self._Width, vol_height)

            aa_round_rect(self._CanvasHWND, vol_rect, self._ValColor, 3, 0,
                          self._ValColor)
Example #8
0
    def blit_text(self, surface, text, pos, font):
        iscjk = MyLangManager.IsCJKMode()

        color = self._Color
        words = [word.split(' ') for word in text.splitlines()]
        space = font.size(' ')[0]

        if iscjk:
            space = 0
            words = [list(word.decode("utf8")) for word in text.splitlines()]

        max_width = self._Width
        x, y = pos
        row_total_width = 0
        lines = 0
        line_max = 12
        row_max = 4
        if iscjk:
            line_max = line_max * 2

        for i, line in enumerate(words[:row_max]):
            for word in line[:line_max]:
                word_surface = font.render(word, True, color)
                word_width = word_surface.get_width()
                word_height = word_surface.get_height()
                row_total_width += word_width
                if row_total_width + space >= max_width:
                    x = pos[0]  # Reset the x.
                    y += word_height  # Start on new row.
                    row_total_width = word_width

                    if lines == 0:
                        lines += word_height
                    else:
                        lines += word_height

                surface.blit(word_surface, (x, y))
                x += word_width + space
            x = pos[0]  # Reset the x.
            y += word_height  # Start on new row.
            lines += word_height
        self._Height = lines
    def KeyDown(self, event):

        if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:

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

        if event.key == CurKeys["B"]:
            try:
                os.remove(self._TrashDir + "/" +
                          os.path.basename(self._FileName))
            except:
                pass

            try:
                shutil.move(self._FileName, self._TrashDir)
            except shutil.Error as e:
                if "already exists" in str(e):
                    self._Screen._MsgBox.SetText("AlreadyExisted")
                else:
                    self._Screen._MsgBox.SetText("Error")

                self._Screen._MsgBox.Draw()
                self._Screen.SwapAndShow()
            else:
                self.SnapMsg(MyLangManager.Tr("Deleting"))
                self._Screen.Draw()
                self._Screen.SwapAndShow()
                self.Reset()

                pygame.time.delay(300)
                self.ReturnToUpLevelPage()
                self._Screen.Draw()
                self._Screen.SwapAndShow()

            print(self._FileName)
Example #10
0
class FootBar(Widget):
    _Width = Width
    _Height = 20
    _BarHeight = 20.5
    _BorderWidth = 1
    _CanvasHWND = None
    _HWND = None
    _Icons = {}
    _IconWidth = 18
    _IconHeight = 18
    _LabelFont = MyLangManager.TrFont("veramono10")
    _State = "normal"

    _SkinManager = None

    def __init__(self):
        self._Icons = {}

    def ReadFootBarIcons(self, icondir):
        if FileExists(icondir) == False and os.path.isdir(icondir) == False:
            return

        keynames = ["nav", "x", "y", "a", "b", "select"]

        share_surf = pygame.image.load(icon_base_path +
                                       "footbar.png").convert_alpha()

        files = os.listdir(icondir)
        for _i, i in enumerate(keynames):
            it = FootBarIcon()
            it._MyType = ICON_TYPES["NAV"]
            it._Parent = self
            it._ImgSurf = share_surf
            it._Align = ALIGN["HLeft"]  # (x)text <=

            it.AddLabel("game", self._LabelFont)
            it.Adjust(self._IconWidth / 2 + _i * self._IconWidth,
                      self._IconHeight / 2 + 2, self._IconWidth,
                      self._IconHeight, 0)
            it._IconIndex = _i
            self._Icons[i] = it

    def Init(self, screen):
        self._HWND = screen
        self._CanvasHWND = pygame.Surface((Width, int(self._BarHeight)))

        self.ReadFootBarIcons(icon_base_path)

        round_corners = MultiIconItem()
        round_corners._IconWidth = 10
        round_corners._IconHeight = 10

        round_corners._MyType = ICON_TYPES["STAT"]
        round_corners._Parent = self
        round_corners._ImgSurf = MyIconPool.GiveIconSurface("roundcorners")
        round_corners.Adjust(0, 0, 10, 10, 0)

        self._Icons["round_corners"] = round_corners

    def ResetNavText(self):
        self._Icons["nav"]._Label.SetText(MyLangManager.Tr("Nav"))
        self._State = "normal"
        self.Draw()
        return False

    def UpdateNavText(self, texts):
        self._State = "tips"
        texts = MyLangManager.Tr(texts)
        my_text = self._LabelFont.render(texts, True,
                                         self._SkinManager.GiveColor("Text"))
        """
        _w = 0
        for i, x in enumerate(("b","a","y","x")):
            if self._Icons[x]._Label._Text!="":
                if i==0:
                    _w += self._Icons[x].TotalWidth()
                else:
                    _w += self._Icons[x].TotalWidth()+5
        """
        left_width = self._Width - 18

        final_piece = ""
        for i, v in enumerate(texts):
            text_slice = texts[:i + 1]
            my_text = self._LabelFont.render(
                text_slice, True, self._SkinManager.GiveColor("Text"))
            final_piece = text_slice
            if my_text.get_width() >= left_width:
                break

        print("finalpiece %s" % final_piece)
        self._Icons["nav"]._Label.SetText(final_piece)

        self.Draw()

    def SetLabelTexts(self, texts):
        if config.ButtonsLayout == "xbox":
            barr = ["nav", "y", "x", "b", "a", "select"]
        else:
            barr = ["nav", "x", "y", "a", "b", "select"]
        texts2 = texts + [""] if len(texts) == 5 else texts

        for idx, x in enumerate(barr):
            try:
                self._Icons[x]._Label.SetText(MyLangManager.Tr(texts2[idx]))
            except IndexError:
                print("Index " + x + " doesn't exist!")

    def ClearCanvas(self):
        self._CanvasHWND.fill(self._SkinManager.GiveColor("White"))

        self._Icons["round_corners"].NewCoord(5, self._Height - 5)
        self._Icons["round_corners"]._IconIndex = 2
        self._Icons["round_corners"].Draw()

        self._Icons["round_corners"].NewCoord(self._Width - 5,
                                              self._Height - 5)
        self._Icons["round_corners"]._IconIndex = 3
        self._Icons["round_corners"].Draw()
        """
        aa_round_rect(self._CanvasHWND,
                    (0,0,self._Width,self._Height),self._BgColor,8,0, self._BgColor)

        pygame.draw.rect(self._CanvasHWND,self._BgColor,(0,0,Width,self._BarHeight/2), 0 )
        """

    def Draw(self):
        self.ClearCanvas()
        self._Icons["nav"].NewCoord(self._IconWidth / 2 + 3,
                                    self._IconHeight / 2 + 2)
        self._Icons["nav"].Draw()

        if self._State == "normal":
            _w = 0
            #for i,x in enumerate(("a","b","x","y")):
            for i, x in enumerate(("b", "a", "y", "x", "select")):
                if self._Icons[x]._Label._Text != "":
                    if i == 0:
                        _w += self._Icons[x].TotalWidth()
                    else:
                        _w += self._Icons[x].TotalWidth() + 5

                    start_x = self._Width - _w
                    start_y = self._IconHeight / 2 + 2
                    self._Icons[x].NewCoord(start_x, start_y)
                    self._Icons[x].Draw()

        pygame.draw.line(self._CanvasHWND, self._SkinManager.GiveColor("Line"),
                         (0, 0), (Width, 0), self._BorderWidth)

        if self._HWND != None:
            self._HWND.blit(
                self._CanvasHWND,
                (self._PosX, Height - self._Height, Width, self._BarHeight))
Example #11
0
 def ResetNavText(self):
     self._Icons["nav"]._Label.SetText(MyLangManager.Tr("Nav"))
     self._State = "normal"
     self.Draw()
     return False
Example #12
0
    def Draw(self, title):
        self.ClearCanvas()
        title = MyLangManager.Tr(title)

        # Couldn't see where to change this anywhere, so let's be super explicit
        if title == "GameShell":
            title = "PocketCHIP"
        self._Title = title
        title_text_size = MyLangManager.TrFont("varela16").size(title)
        self._CanvasHWND.blit(
            MyLangManager.TrFont("varela16").render(
                title, True, self._SkinManager.GiveColor("Text")),
            # x,y,width,height,canWidth,canHeight
            midRect(
                title_text_size[0] / 2 + self._LOffset,
                title_text_size[1] / 2 +
                (self._BarHeight - title_text_size[1]) / 2, title_text_size[0],
                title_text_size[1], Width, Height))

        cur_time = datetime.now().strftime("%H:%M")
        time_text_font = MySkinManager.GiveFont("varela12")
        time_text_size = time_text_font.size(cur_time)
        self._CanvasHWND.blit(
            time_text_font.render(cur_time, True,
                                  self._SkinManager.GiveColor("Text")),
            # x,y,width,height,canWidth,canHeight
            midRect(
                Width - time_text_size[0] / 2 - self._ROffset,
                time_text_size[1] / 2 +
                (self._BarHeight - time_text_size[1]) / 2, time_text_size[0],
                time_text_size[1], Width, Height))

        #### Debug: Output the battery value as text...
        # cur_batt =  "Batt: %s, %s" % (str(BatteryAbstraction.AsPercentage()), str(BatteryAbstraction.IsCharging()))
        # batt_text_font = MySkinManager.GiveFont("varela12")
        # batt_text_size = batt_text_font.size(cur_batt)
        # self._CanvasHWND.blit(batt_text_font.render(
        #     cur_batt,
        #     True,
        #     self._SkinManager.GiveColor("Text")),
        #     # x,y,width,height,canWidth,canHeight
        #     midRect(
        #         # Width-batt_text_size[0]/2-self._ROffset,
        #         200,
        #         batt_text_size[1]/2+(self._BarHeight-batt_text_size[1])/2,
        #         batt_text_size[0],
        #         batt_text_size[1],
        #         Width,
        #         Height
        #     )
        # )

        start_x = Width - time_text_size[
            0] - self._ROffset - self._icon_width * 3  # near by the time_text

        self._Icons["bluetooth"].NewCoord(
            start_x - self._icon_width,
            self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2)

        self._Icons["sound"].NewCoord(
            start_x,
            self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2)

        #self._Icons["wifi"].NewCoord(start_x+self._icon_width+5,    self._icon_height/2+(self._BarHeight-self._icon_height)/2)

        self._Icons["battery"].NewCoord(
            start_x + self._icon_width + self._icon_width + 8,
            self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2)

        if is_wifi_connected_now():
            ge = self.GetWifiStrength(wifi_strength())
            if ge > 0:
                self._Icons["wifistatus"]._IconIndex = ge
                self._Icons["wifistatus"].NewCoord(
                    start_x + self._icon_width + 5, self._icon_height / 2 +
                    (self._BarHeight - self._icon_height) / 2)
                # self._Icons["wifistatus"].Draw()
            else:
                self._Icons["wifistatus"]._IconIndex = 0
                # self._Icons["wifistatus"].Draw()
                print("wifi strength error")
        else:
            if self._InAirPlaneMode == False:
                self._Icons["wifistatus"]._IconIndex = 0
            else:
                self._Icons["wifistatus"]._IconIndex = 5  ## airplane mode icon

            self._Icons["wifistatus"].NewCoord(
                start_x + self._icon_width + 5, self._icon_height / 2 +
                (self._BarHeight - self._icon_height) / 2)
            # self._Icons["wifistatus"].Draw()

        # Draw the title bar icons
        self._Icons["wifistatus"].Draw()
        self._Icons["sound"].Draw()
        self._Icons["battery"].Draw()
        # self._Icons["bluetooth"].Draw()

        pygame.draw.line(self._CanvasHWND, self._SkinManager.GiveColor("Line"),
                         (0, self._BarHeight), (self._Width, self._BarHeight),
                         self._BorderWidth)

        if self._HWND != None:
            self._HWND.blit(
                self._CanvasHWND,
                (self._PosX, self._PosY, self._Width, self._Height))
Example #13
0
 def DrawRun(self):
     self._MsgBox.SetText(MyLangManager.Tr("Launching"))
     self._MsgBox.Draw()
Example #14
0
 def SetText(self, text):
     self._Text = MyLangManager.Tr(text)
Example #15
0
    def ReadTheDirIntoPages(self, _dir, pglevel, cur_page):
        global commercialsoftware_flag

        if FileExists(_dir) == False and os.path.isdir(_dir) == False:
            return

        files = os.listdir(_dir)
        for i in sorted(files):
            if os.path.isdir(_dir + "/" + i) and i.startswith(
                    ".") == False:  # TOPLEVEL only is dir
                if pglevel == 0:
                    page = Page()
                    page._Name = self.ExtraName(i)
                    page._Icons = []
                    self._Pages.append(page)
                    self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1,
                                             self._Pages[len(self._Pages) - 1])
                else:  ## On CurPage now
                    i2 = self.ExtraName(i)
                    iconitem = IconItem()
                    iconitem._FileName = i
                    iconitem._CmdPath = ""
                    iconitem.AddLabel(MyLangManager.Tr(i2), self._IconFont)
                    if FileExists(_dir + "/" + i + "/" + i2 +
                                  ".png"):  ### 20_Prog/Prog.png , cut 20_
                        iconitem._ImageName = _dir + "/" + i + "/" + i2 + ".png"
                    elif FileExists(
                            MySkinManager.GiveIcon(_dir + "/" + i2 + ".png")):
                        iconitem._ImageName = MySkinManager.GiveIcon(_dir +
                                                                     "/" + i2 +
                                                                     ".png")
                    else:
                        untitled = UntitledIcon()
                        untitled.Init()
                        if len(i2) > 1:
                            untitled.SetWords(i2[:2])
                        elif len(i2) == 1:
                            untitled.SetWords([i2[0], i2[0]])
                        else:
                            untitled.SetWords(["G", "s"])

                        iconitem._ImgSurf = untitled.Surface()
                        iconitem._ImageName = ""

                    if self.IsPythonPackage(_dir + "/" + i):
                        iconitem._MyType = ICON_TYPES["FUNC"]
                        sys.path.append(_dir)
                        iconitem._CmdPath = __import__(i)
                        init_cb = getattr(iconitem._CmdPath, "Init", None)
                        if init_cb != None:
                            if callable(init_cb):
                                iconitem._CmdPath.Init(self)
                                cur_page._Icons.append(iconitem)

                    elif self.IsEmulatorPackage(_dir + "/" + i):
                        obj = {}
                        obj["ROM"] = ""
                        obj["ROM_SO"] = ""
                        obj["EXT"] = []
                        obj["EXCLUDE"] = []
                        obj["FILETYPE"] = "file"
                        obj["LAUNCHER"] = ""
                        obj["TITLE"] = "Game"
                        obj["SO_URL"] = ""
                        obj["RETRO_CONFIG"] = ""  ##
                        try:
                            f = open(_dir + "/" + i + "/" + emulator_flag)
                        except IOError:
                            print("action config open failed")
                            return
                        else:
                            with f:
                                content = f.readlines()
                                content = [x.strip() for x in content]
                        for c in content:
                            pis = c.split("=")
                            if len(pis) > 1:
                                if "EXT" in pis[0]:
                                    obj[pis[0]] = pis[1].split(",")
                                elif "EXCLUDE" in pis[0]:
                                    obj[pis[0]] = pis[1].split(",")
                                else:
                                    obj[pis[0]] = pis[1]

                        if FileExists(_dir + "/" + i + "/retroarch-local.cfg"):
                            obj["RETRO_CONFIG"] = CmdClean(
                                os.path.abspath(_dir + "/" + i +
                                                "/retroarch-local.cfg"))
                            print("a local retroarch cfg:",
                                  obj["RETRO_CONFIG"])

                        em = MyEmulator()
                        em._Emulator = obj

                        em.Init(self)
                        iconitem._CmdPath = em
                        iconitem._MyType = ICON_TYPES["Emulator"]
                        cur_page._Icons.append(iconitem)

                    elif self.IsCommercialPackage(os.path.join(_dir, i)):
                        data = None
                        em = MyCommercialSoftwarePackage()
                        if FileExists(_dir + "/" + i + "/.done"):
                            print(_dir + "/" + i + "/.done")
                            em._Done = os.path.realpath(_dir + "/" + i + "/" +
                                                        i2 + ".sh")
                        else:
                            with open(
                                    os.path.join(_dir, i) + "/" +
                                    commercialsoftware_flag) as f:
                                data = json.load(f)
                            em._ComPkgInfo = data
                            em._Done = ""

                        em._InvokeDir = os.path.realpath(os.path.join(_dir, i))
                        em.Init(self)

                        iconitem._CmdPath = em
                        iconitem._MyType = ICON_TYPES["Commercial"]
                        cur_page._Icons.append(iconitem)

                    elif self.IsExecPackage(
                            _dir + "/" +
                            i):  ## ExecPackage is the last one to check
                        iconitem._MyType = ICON_TYPES["EXE"]
                        iconitem._CmdPath = os.path.realpath(_dir + "/" + i +
                                                             "/" + i2 + ".sh")
                        MakeExecutable(iconitem._CmdPath)
                        cur_page._Icons.append(iconitem)
                    else:
                        iconitem._MyType = ICON_TYPES["DIR"]
                        iconitem._LinkPage = Page()
                        iconitem._LinkPage._Name = i2
                        cur_page._Icons.append(iconitem)
                        self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1,
                                                 iconitem._LinkPage)

            elif os.path.isfile(_dir + "/" + i) and i.startswith(
                    ".") == False and pglevel > 0:
                if i.lower().endswith(icon_ext):
                    i2 = self.ExtraName(i)

                    #cmd      =  ReadTheFileContent(_dir+"/"+i)
                    iconitem = IconItem()
                    iconitem._FileName = i
                    iconitem._CmdPath = os.path.realpath(_dir + "/" + i)
                    MakeExecutable(iconitem._CmdPath)
                    iconitem._MyType = ICON_TYPES["EXE"]
                    if FileExists(
                            MySkinManager.GiveIcon(_dir + "/" +
                                                   ReplaceSuffix(i2, "png"))):
                        iconitem._ImageName = MySkinManager.GiveIcon(
                            _dir + "/" + ReplaceSuffix(i2, "png"))
                    else:
                        untitled = UntitledIcon()
                        untitled.Init()
                        if len(i2) > 1:
                            untitled.SetWords(i2[:2])
                        elif len(i2) == 1:
                            untitled.SetWords([i2[0], i2[0]])
                        else:
                            untitled.SetWords(["G", "s"])

                        iconitem._ImgSurf = untitled.Surface()

                        iconitem._ImageName = ""

                    iconitem.AddLabel(MyLangManager.Tr(i2.split(".")[0]),
                                      self._IconFont)
                    iconitem._LinkPage = None
                    cur_page._Icons.append(iconitem)
Example #16
0
class ConfirmPage(Page):

    _Icons = {}
    _Selector = None
    _FootMsg = ["Nav", "", "", "Cancel", "Yes"]
    _MyList = []
    _ListFont = MyLangManager.TrFont("Eurostile20")
    _MyStack = None
    _FileName = ""
    _TrashDir = ""
    _ConfirmText = MyLangManager.Tr("ConfirmQ")
    _BGPosX = 0
    _BGPosY = 0
    _BGWidth = 0
    _BGHeight = 0
    _Parent = None

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

    def Reset(self):
        self._MyList[0].SetText(self._ConfirmText)
        self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width) / 2
        self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height) / 2

        self._BGPosX = self._MyList[0]._PosX - 10
        self._BGPosY = self._MyList[0]._PosY - 10
        self._BGWidth = self._MyList[0]._Width + 20
        self._BGHeight = self._MyList[0]._Height + 20

    def SnapMsg(self, msg):
        self._MyList[0].SetText(msg)
        self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width) / 2
        self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height) / 2

        self._BGPosX = self._MyList[0]._PosX - 10
        self._BGPosY = self._MyList[0]._PosY - 10
        self._BGWidth = self._MyList[0]._Width + 20
        self._BGHeight = self._MyList[0]._Height + 20

    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

        li = Label()
        li.SetCanvasHWND(self._CanvasHWND)
        li.Init(self._ConfirmText, self._ListFont)

        li._PosX = (self._Width - li._Width) / 2
        li._PosY = (self._Height - li._Height) / 2

        self._BGPosX = li._PosX - 10
        self._BGPosY = li._PosY - 10
        self._BGWidth = li._Width + 20
        self._BGHeight = li._Height + 20

        self._MyList.append(li)

    def KeyDown(self, event):

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

    def DrawBG(self):
        _rect = pygame.Rect(self._BGPosX, self._BGPosY, self._BGWidth,
                            self._BGHeight)

        pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('White'),
                         _rect, 0)
        pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'),
                         _rect, 1)

    def Draw(self):
        #self.ClearCanvas()

        self.DrawBG()
        for i in self._MyList:
            i.Draw()

        self.Reset()
Example #17
0
    def Draw(self, title):
        self.ClearCanvas()
        title = MyLangManager.Tr(title)
        self._Title = title

        # get battery percentage, but not for music spectrum(GameShell RTA)
        RTA_title = "GameShell RTA"
        bat_pct = ""
        if title != RTA_title and title != MyLangManager.Tr(RTA_title):
            out = commands.getstatusoutput(
                "upower -i /org/freedesktop/UPower/devices/battery_axp20x_battery | grep percentage | tail -c 5"
            )
            bat_pct = "".join(out[1]).strip() + "  "

        cur_time = datetime.now().strftime("%H:%M")
        cur_time = bat_pct + cur_time
        time_text_font = MySkinManager.GiveFont("Eurostile12")
        time_text_size = time_text_font.size(cur_time)
        title_text_size = MyLangManager.TrFont("Eurostile16").size(title)

        self._CanvasHWND.blit(
            MyLangManager.TrFont("Eurostile16").render(
                title, True, self._SkinManager.GiveColor("Text")),
            midRect(
                title_text_size[0] / 2 + self._LOffset,
                title_text_size[1] / 2 +
                (self._BarHeight - title_text_size[1]) / 2, title_text_size[0],
                title_text_size[1], Width, Height))
        self._CanvasHWND.blit(
            time_text_font.render(cur_time, True,
                                  self._SkinManager.GiveColor("Text")),
            midRect(
                Width - time_text_size[0] / 2 - self._ROffset,
                time_text_size[1] / 2 +
                (self._BarHeight - time_text_size[1]) / 2, time_text_size[0],
                time_text_size[1], Width, Height))

        start_x = Width - time_text_size[
            0] - self._ROffset - self._icon_width * 3  # near by the time_text

        self._Icons["dlstatus"].NewCoord(
            start_x - self._icon_width * 2,
            self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2)

        self._Icons["bluetooth"].NewCoord(
            start_x - self._icon_width,
            self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2)

        self._Icons["sound"].NewCoord(
            start_x,
            self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2)

        #self._Icons["wifi"].NewCoord(start_x+self._icon_width+5,    self._icon_height/2+(self._BarHeight-self._icon_height)/2)

        self._Icons["battery"].NewCoord(
            start_x + self._icon_width + self._icon_width + 8,
            self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2)

        if is_wifi_connected_now():
            ge = self.GetWifiStrength(wifi_strength())
            if ge > 0:
                self._Icons["wifistatus"]._IconIndex = ge
                self._Icons["wifistatus"].NewCoord(
                    start_x + self._icon_width + 5, self._icon_height / 2 +
                    (self._BarHeight - self._icon_height) / 2)
                self._Icons["wifistatus"].Draw()
            else:
                self._Icons["wifistatus"]._IconIndex = 0
                self._Icons["wifistatus"].Draw()
                print("wifi strength error")
        else:
            if self._InAirPlaneMode == False:
                self._Icons["wifistatus"]._IconIndex = 0
            else:
                self._Icons["wifistatus"]._IconIndex = 5  ## airplane mode icon

            self._Icons["wifistatus"].NewCoord(
                start_x + self._icon_width + 5, self._icon_height / 2 +
                (self._BarHeight - self._icon_height) / 2)
            self._Icons["wifistatus"].Draw()

        self._Icons["sound"].Draw()

        self._Icons["battery"].Draw()

        self._Icons["bluetooth"].Draw()

        #self._Icons["dlstatus"].Draw()

        pygame.draw.line(self._CanvasHWND, self._SkinManager.GiveColor("Line"),
                         (0, self._BarHeight), (self._Width, self._BarHeight),
                         self._BorderWidth)

        if self._HWND != None:
            self._HWND.blit(
                self._CanvasHWND,
                (self._PosX, self._PosY, self._Width, self._Height))
Example #18
0
class MainScreen(Widget):
    _Pages = []
    _PageMax = 0
    _PageIndex = 0
    _PosY = TitleBar._BarHeight + 1
    _Width = Width
    _Height = Height - FootBar._BarHeight - TitleBar._BarHeight
    _MyPageStack = None
    _CurrentPage = None  # pointer to the current displaying Page Class
    _CanvasHWND = None
    _HWND = None
    _TitleBar = None
    _FootBar = None
    _MsgBox = None
    _MsgBoxFont = MyLangManager.TrFont("veramono20")
    _IconFont = MyLangManager.TrFont("varela15")
    _SkinManager = None

    _Closed = False
    _CounterScreen = None

    _LastKey = -1
    _LastKeyDown = -1

    def __init__(self):
        self._Pages = []
        self._MyPageStack = PageStack()

    def Init(self):
        self._CanvasHWND = pygame.Surface((self._Width, self._Height))
        self._MsgBox = MessageBox()
        self._MsgBox._Parent = self
        self._MsgBox.Init(" ", self._MsgBoxFont)

        self._SkinManager = MySkinManager

        self._CounterScreen = CounterScreen()
        self._CounterScreen._HWND = self._HWND

        self._CounterScreen.Init()

    def FartherPages(self):
        self._PageMax = len(self._Pages)
        for i in range(0, self._PageMax):
            self._Pages[i]._Index = i
            self._Pages[i]._CanvasHWND = self._CanvasHWND
            self._Pages[i]._IconNumbers = len(self._Pages[i]._Icons)
            self._Pages[i]._Screen = self
            self._Pages[i].Adjust()

            if self._Pages[i]._IconNumbers > 1:
                self._Pages[i]._PsIndex = 1
                self._Pages[i]._IconIndex = self._Pages[i]._PsIndex

        self._CurrentPage = self._Pages[self._PageIndex]
        self._CurrentPage._OnShow = True

    def GetMyRightSidePage(self):
        ret = self._PageIndex + 1
        if ret > (self._PageMax - 1):
            ret = self._PageMax - 1
        return ret

    def PageMoveLeft(self):
        self._Pages[self._PageIndex]._OnShow = False
        if self._PageIndex < (self._PageMax - 1):
            my_right_side_page = self.GetMyRightSidePage()
            for i in range(0, self._PageMax):
                if i != self._PageIndex and i != my_right_side_page:
                    self._Pages[i].MoveLeft(Width)

            self._Pages[self._PageIndex].EasingLeft(Width)

            if self._PageIndex != my_right_side_page:
                self._Pages[my_right_side_page].EasingLeft(Width)

            self._Pages[self._PageIndex].ResetPageSelector()

        self._PageIndex += 1
        if self._PageIndex > (self._PageMax - 1):
            self._PageIndex = (self._PageMax - 1)

        self._Pages[self._PageIndex]._OnShow = True
        self._CurrentPage = self._Pages[self._PageIndex]

    def GetMyLeftSidePage(self):
        ret = self._PageIndex - 1
        if ret < 0:
            ret = 0
        return ret

    def PageMoveRight(self):
        self._Pages[self._PageIndex]._OnShow = False
        if self._PageIndex > 0:
            my_left_side_page = self.GetMyLeftSidePage()
            for i in range(0, self._PageMax):
                if i != self._PageIndex and i != my_left_side_page:
                    pass
                #self._Pages[i].MoveRight(Width)

            self._Pages[self._PageIndex].EasingRight(Width)

            if self._PageIndex != my_left_side_page:
                self._Pages[my_left_side_page].EasingRight(Width)

            self._Pages[self._PageIndex].ResetPageSelector()

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

        self._Pages[self._PageIndex]._OnShow = True
        self._CurrentPage = self._Pages[self._PageIndex]

    def EasingAllPageLeft(self):
        current_time = 0.0
        start_posx = 0.0
        current_posx = start_posx
        final_posx = float(Width)
        posx_init = 0
        dur = 30
        last_posx = 0.0
        all_last_posx = []
        if self._PageIndex >= (self._PageMax - 1):
            return
        for i in range(0, Width * dur):
            current_posx = easing.SineIn(current_time, start_posx,
                                         final_posx - start_posx, float(dur))
            if current_posx >= final_posx:
                current_posx = final_posx

            dx = current_posx - last_posx
            all_last_posx.append(int(dx))
            current_time += 1
            last_posx = current_posx
            if current_posx >= final_posx:
                break

        c = 0
        for i in all_last_posx:
            c += i
        if c < final_posx - start_posx:
            all_last_posx.append(final_posx - c)

        for i in all_last_posx:
            self.ClearCanvas()
            for j in self._Pages:
                j._PosX -= i
                j.DrawIcons()
                j._Screen.SwapAndShow()

        self._Pages[self._PageIndex]._OnShow = False

        self._PageIndex += 1
        if self._PageIndex > (self._PageMax - 1):
            self._PageIndex = (self._PageMax - 1)

        self._Pages[self._PageIndex]._OnShow = True
        self._CurrentPage = self._Pages[self._PageIndex]

    def EasingAllPageRight(self):
        current_time = 0.0
        start_posx = 0.0
        current_posx = start_posx
        final_posx = float(Width)
        posx_init = 0
        dur = 30
        last_posx = 0.0
        all_last_posx = []
        if self._PageIndex <= 0:
            return
        for i in range(0, Width * dur):
            current_posx = easing.SineIn(current_time, start_posx,
                                         final_posx - start_posx, float(dur))
            if current_posx >= final_posx:
                current_posx = final_posx

            dx = current_posx - last_posx
            all_last_posx.append(int(dx))
            current_time += 1
            last_posx = current_posx
            if current_posx >= final_posx:
                break

        c = 0
        for i in all_last_posx:
            c += i
        if c < final_posx - start_posx:
            all_last_posx.append(final_posx - c)

        for i in all_last_posx:
            self.ClearCanvas()
            for j in reversed(self._Pages):
                j._PosX += i
                j.DrawIcons()
                j._Screen.SwapAndShow()

        self._Pages[self._PageIndex]._OnShow = False

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

        self._Pages[self._PageIndex]._OnShow = True
        self._CurrentPage = self._Pages[self._PageIndex]

    def CurPage(self):
        return self._CurrentPage

    def PushCurPage(self):
        self._MyPageStack.Push(self._CurrentPage)

    def SetCurPage(self, page):
        self._CurrentPage = page
        on_load_cb = getattr(self._CurrentPage, "OnLoadCb", None)
        if on_load_cb != None:
            if callable(on_load_cb):
                self._CurrentPage.OnLoadCb()

    def PushPage(self, page):
        self.PushCurPage()
        self.SetCurPage(page)

    def AppendPage(self, Page):
        self._Pages.append(Page)

    def ClearCanvas(self):
        self._CanvasHWND.fill(self._SkinManager.GiveColor('White'))

    def SwapAndShow(self):
        if self._Closed == True:
            return
        if self._HWND != None:
            self._HWND.blit(
                self._CanvasHWND,
                (self._PosX, self._PosY, self._Width, self._Height))
            pygame.display.update()

    def ExtraName(self, name):
        ## extra name like 1_xxx to be => xxx,
        parts = name.split("_")
        if len(parts) > 1:
            return parts[1]
        elif len(parts) == 1:
            return parts[0]
        else:
            return name

    def IsExecPackage(self, dirname):
        files = os.listdir(dirname)
        bname = os.path.basename(dirname)
        bname = self.ExtraName(bname)
        for i in sorted(files):
            if i == bname + ".sh":
                return True
        return False

    def IsEmulatorPackage(self, dirname):
        files = os.listdir(dirname)
        for i in sorted(files):
            if i.endswith(emulator_flag):
                return True
        return False

    def IsCommercialPackage(self, dirname):
        files = os.listdir(dirname)
        for i in sorted(files):
            if i.endswith(commercialsoftware_flag):
                return True
        return False

    def IsPythonPackage(self, dirname):
        files = os.listdir(dirname)
        for i in sorted(files):
            if i.endswith(python_package_flag):
                return True
        return False

    def ReunionPagesIcons(
        self
    ):  #This is for combining /home/cpi/apps/Menu and ~/launcher/Menu/GameShell
        for p in self._Pages:
            tmp = []
            for i, x in enumerate(p._Icons):
                tup = ('', 0)
                if hasattr(x, '_FileName'):
                    if str.find(x._FileName, "_") < 0:
                        tup = (
                            "98_" + x._FileName, i
                        )  # prefer to maintain PowerOFF in last position if the filename has no order labels
                    else:
                        tup = (x._FileName, i)
                else:
                    tup = ("", i)

                tmp.append(tup)
            tmp = sorted(tmp, key=itemgetter(0))

            retro_games_idx = []
            retro_games_dir = "20_Retro Games"
            for i, x in enumerate(tmp):
                if retro_games_dir in x[0]:
                    retro_games_idx.append(x[1])

            if len(retro_games_idx) > 1:
                for i in range(1, len(retro_games_idx)):
                    p._Icons[retro_games_idx[0]]._LinkPage._Icons.extend(
                        p._Icons[retro_games_idx[i]]._LinkPage._Icons
                    )  ### assumes the folder of ~/apps/Menu/20_Retro Games is legalzip","sfc"],

                tmp_swap = []
                for i, x in enumerate(tmp):
                    if retro_games_dir not in x[0]:
                        tmp_swap.append(x)
                    if retro_games_dir in x[0] and i == retro_games_idx[0]:
                        tmp_swap.append(x)

                tmp = tmp_swap

            #print(tmp)
            new_icons = []
            for x in tmp:
                new_icons.append(p._Icons[x[1]])
            p._Icons = new_icons

    def ReadTheDirIntoPages(self, _dir, pglevel, cur_page):
        global commercialsoftware_flag

        if FileExists(_dir) == False and os.path.isdir(_dir) == False:
            return

        files = os.listdir(_dir)
        for i in sorted(files):
            if os.path.isdir(_dir + "/" + i) and i.startswith(
                    ".") == False:  # TOPLEVEL only is dir
                if pglevel == 0:
                    page = Page()
                    page._Name = self.ExtraName(i)
                    page._Icons = []
                    self._Pages.append(page)
                    self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1,
                                             self._Pages[len(self._Pages) - 1])
                else:  ## On CurPage now
                    i2 = self.ExtraName(i)
                    iconitem = IconItem()
                    iconitem._FileName = i
                    iconitem._CmdPath = ""
                    iconitem.AddLabel(MyLangManager.Tr(i2), self._IconFont)
                    if FileExists(_dir + "/" + i + "/" + i2 +
                                  ".png"):  ### 20_Prog/Prog.png , cut 20_
                        iconitem._ImageName = _dir + "/" + i + "/" + i2 + ".png"
                    elif FileExists(
                            MySkinManager.GiveIcon(_dir + "/" + i2 + ".png")):
                        iconitem._ImageName = MySkinManager.GiveIcon(_dir +
                                                                     "/" + i2 +
                                                                     ".png")
                    else:
                        untitled = UntitledIcon()
                        untitled.Init()
                        if len(i2) > 1:
                            untitled.SetWords(i2[:2])
                        elif len(i2) == 1:
                            untitled.SetWords([i2[0], i2[0]])
                        else:
                            untitled.SetWords(["G", "s"])

                        iconitem._ImgSurf = untitled.Surface()
                        iconitem._ImageName = ""

                    if self.IsPythonPackage(_dir + "/" + i):
                        iconitem._MyType = ICON_TYPES["FUNC"]
                        sys.path.append(_dir)
                        iconitem._CmdPath = __import__(i)
                        init_cb = getattr(iconitem._CmdPath, "Init", None)
                        if init_cb != None:
                            if callable(init_cb):
                                iconitem._CmdPath.Init(self)
                                cur_page._Icons.append(iconitem)

                    elif self.IsEmulatorPackage(_dir + "/" + i):
                        obj = {}
                        obj["ROM"] = ""
                        obj["ROM_SO"] = ""
                        obj["EXT"] = []
                        obj["EXCLUDE"] = []
                        obj["FILETYPE"] = "file"
                        obj["LAUNCHER"] = ""
                        obj["TITLE"] = "Game"
                        obj["SO_URL"] = ""
                        obj["RETRO_CONFIG"] = ""  ##
                        try:
                            f = open(_dir + "/" + i + "/" + emulator_flag)
                        except IOError:
                            print("action config open failed")
                            return
                        else:
                            with f:
                                content = f.readlines()
                                content = [x.strip() for x in content]
                        for c in content:
                            pis = c.split("=")
                            if len(pis) > 1:
                                if "EXT" in pis[0]:
                                    obj[pis[0]] = pis[1].split(",")
                                elif "EXCLUDE" in pis[0]:
                                    obj[pis[0]] = pis[1].split(",")
                                else:
                                    obj[pis[0]] = pis[1]

                        if FileExists(_dir + "/" + i + "/retroarch-local.cfg"):
                            obj["RETRO_CONFIG"] = CmdClean(
                                os.path.abspath(_dir + "/" + i +
                                                "/retroarch-local.cfg"))
                            print("a local retroarch cfg:",
                                  obj["RETRO_CONFIG"])

                        em = MyEmulator()
                        em._Emulator = obj

                        em.Init(self)
                        iconitem._CmdPath = em
                        iconitem._MyType = ICON_TYPES["Emulator"]
                        cur_page._Icons.append(iconitem)

                    elif self.IsCommercialPackage(os.path.join(_dir, i)):
                        data = None
                        em = MyCommercialSoftwarePackage()
                        if FileExists(_dir + "/" + i + "/.done"):
                            print(_dir + "/" + i + "/.done")
                            em._Done = os.path.realpath(_dir + "/" + i + "/" +
                                                        i2 + ".sh")
                        else:
                            with open(
                                    os.path.join(_dir, i) + "/" +
                                    commercialsoftware_flag) as f:
                                data = json.load(f)
                            em._ComPkgInfo = data
                            em._Done = ""

                        em._InvokeDir = os.path.realpath(os.path.join(_dir, i))
                        em.Init(self)

                        iconitem._CmdPath = em
                        iconitem._MyType = ICON_TYPES["Commercial"]
                        cur_page._Icons.append(iconitem)

                    elif self.IsExecPackage(
                            _dir + "/" +
                            i):  ## ExecPackage is the last one to check
                        iconitem._MyType = ICON_TYPES["EXE"]
                        iconitem._CmdPath = os.path.realpath(_dir + "/" + i +
                                                             "/" + i2 + ".sh")
                        MakeExecutable(iconitem._CmdPath)
                        cur_page._Icons.append(iconitem)
                    else:
                        iconitem._MyType = ICON_TYPES["DIR"]
                        iconitem._LinkPage = Page()
                        iconitem._LinkPage._Name = i2
                        cur_page._Icons.append(iconitem)
                        self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1,
                                                 iconitem._LinkPage)

            elif os.path.isfile(_dir + "/" + i) and i.startswith(
                    ".") == False and pglevel > 0:
                if i.lower().endswith(icon_ext):
                    i2 = self.ExtraName(i)

                    #cmd      =  ReadTheFileContent(_dir+"/"+i)
                    iconitem = IconItem()
                    iconitem._FileName = i
                    iconitem._CmdPath = os.path.realpath(_dir + "/" + i)
                    MakeExecutable(iconitem._CmdPath)
                    iconitem._MyType = ICON_TYPES["EXE"]
                    if FileExists(
                            MySkinManager.GiveIcon(_dir + "/" +
                                                   ReplaceSuffix(i2, "png"))):
                        iconitem._ImageName = MySkinManager.GiveIcon(
                            _dir + "/" + ReplaceSuffix(i2, "png"))
                    else:
                        untitled = UntitledIcon()
                        untitled.Init()
                        if len(i2) > 1:
                            untitled.SetWords(i2[:2])
                        elif len(i2) == 1:
                            untitled.SetWords([i2[0], i2[0]])
                        else:
                            untitled.SetWords(["G", "s"])

                        iconitem._ImgSurf = untitled.Surface()

                        iconitem._ImageName = ""

                    iconitem.AddLabel(MyLangManager.Tr(i2.split(".")[0]),
                                      self._IconFont)
                    iconitem._LinkPage = None
                    cur_page._Icons.append(iconitem)

    def RunEXE(self, cmdpath):
        self.DrawRun()
        self.SwapAndShow()
        pygame.time.delay(1000)
        cmdpath = cmdpath.strip()
        cmdpath = CmdClean(cmdpath)
        pygame.event.post(pygame.event.Event(RUNEVT, message=cmdpath))

    def OnExitCb(self, event):
        ## leave rest to Pages
        on_exit_cb = getattr(self._CurrentPage, "OnExitCb", None)
        if on_exit_cb != None:
            if callable(on_exit_cb):
                self._CurrentPage.OnExitCb(event)
        return

    def KeyDown(self, event):
        """
        if event.key == pygame.K_PAGEUP:
            self.EasingAllPageLeft()
            #self.SwapAndShow()
        if event.key == pygame.K_PAGEDOWN:
            self.EasingAllPageRight()
            #self.SwapAndShow()
        """

        if event.key == pygame.K_t:
            self.DrawRun()
            self.SwapAndShow()
        """
        if event.key == CurKeys["Space"]:
            self._CounterScreen.Draw()
            self._CounterScreen.SwapAndShow()
            self._CounterScreen.StartCounter()
        """
        ## leave rest to Pages
        current_page_key_down_cb = getattr(self._CurrentPage, "KeyDown", None)
        if current_page_key_down_cb != None:
            if callable(current_page_key_down_cb):
                self._CurrentPage.KeyDown(event)

        self._LastKey = event.key

    def DrawRun(self):
        self._MsgBox.SetText(MyLangManager.Tr("Launching"))
        self._MsgBox.Draw()

    def Draw(self):
        if self._Closed == True:
            return

        self._CurrentPage.Draw()
        #if self._HWND != None:
        #    self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height))
        if self._TitleBar != None:
            self._TitleBar.Draw(self._CurrentPage._Name)
        if self._FootBar != None:
            if hasattr(self._CurrentPage, "_FootMsg"):
                self._FootBar.SetLabelTexts(self._CurrentPage._FootMsg)
                self._FootBar.Draw()
Example #19
0
class CounterScreen(FullScreen):

    _CounterFont = MyLangManager.TrFont("varela120")
    _TextFont1 = MyLangManager.TrFont("varela15")
    _TextFont2 = MyLangManager.TrFont("varela12")

    _TopLabel = None
    _BottomLabel = None
    _NumberLabel = None

    _BGColor = MySkinManager.GiveColor('Black')
    _FGColor = MySkinManager.GiveColor('White')

    _Counting = False
    _Number = 10
    _GobjectIntervalId = -1

    _inter_counter = 0

    def GObjectInterval(self):

        self._inter_counter += 1

        if self._Number == 0:
            self._Counting = False
            print("do the real shutdown")

            if config.CurKeySet != "PC":
                cmdpath = "feh --bg-center gameshell/wallpaper/seeyou.png;"
                cmdpath += "sleep 3;"
                cmdpath += "sudo halt -p"
                pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath))\

            return False

        if self._inter_counter >= 2:
            self._Number -= 1
            if self._Number < 0:
                self._Number = 0
            print("sub Number %d " % self._Number)
            self._inter_counter = 0

            self.Draw()
            self.SwapAndShow()

        return self._Counting

    def StartCounter(self):
        if self._Counting == True:
            return

        self._Number = 10
        self._Counting = True

        self._GobjectIntervalId = gobject.timeout_add(500,
                                                      self.GObjectInterval)

    def StopCounter(self):
        if self._Counting == False:
            return
        self._Counting = False
        self._Number = 10
        self._inter_counter = 0

        if self._GobjectIntervalId != -1:
            gobject.source_remove(self._GobjectIntervalId)
            self._GobjectIntervalId = -1

        return

    def Init(self):
        self._CanvasHWND = pygame.Surface((self._Width, self._Height))
        self._TopLabel = Label()
        self._TopLabel.SetCanvasHWND(self._CanvasHWND)
        self._TopLabel.Init("System shutdown in", self._TextFont1,
                            self._FGColor)

        self._BottomLabel = Label()
        self._BottomLabel.SetCanvasHWND(self._CanvasHWND)
        self._BottomLabel.Init("Press any key to stop countdown",
                               self._TextFont2, self._FGColor)

        self._NumberLabel = Label()
        self._NumberLabel.SetCanvasHWND(self._CanvasHWND)
        self._NumberLabel.Init(str(self._Number), self._CounterFont,
                               self._FGColor)

    def Draw(self):
        self._CanvasHWND.fill(self._BGColor)

        self._TopLabel.NewCoord(Width / 2, 15)
        self._TopLabel.DrawCenter()

        self._BottomLabel.NewCoord(Width / 2, Height - 15)
        self._BottomLabel.DrawCenter()

        self._NumberLabel.NewCoord(Width / 2, Height / 2)
        self._NumberLabel.SetText(str(self._Number))
        self._NumberLabel.DrawCenter()