Esempio n. 1
0
    def DrawWith(self, x_, y_, withborder):

        self.PreDraw()

        x_ = x_ - self._Width / 2
        y_ = y_ - self._Height / 2

        padding = 5

        pygame.draw.rect(self._HWND,
                         SkinManager().GiveColor('White'),
                         (x_ - padding, y_ - padding, self._Width +
                          padding * 2, self._Height + padding * 2))

        if self._HWND != None:
            rect = pygame.Rect(x_, y_, self._Width, self._Height)
            self._HWND.blit(self._CanvasHWND, rect,
                            (0, 0, self._Width, self._Height))
            #self._HWND.blit(self._CanvasHWND,rect)

        if withborder == True:
            pygame.draw.rect(self._HWND,
                             SkinManager().GiveColor('Black'),
                             (x_ - padding, y_ - padding, self._Width +
                              padding * 2, self._Height + padding * 2), 1)
Esempio n. 2
0
    def Draw(self):
        if self._ReadOnly == True:
            self._Labels["Text"].SetColor(
                SkinManager().GiveColor("ReadOnlyText"))
        else:
            self._Labels["Text"].SetColor(SkinManager().GiveColor("Text"))

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

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

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

        pygame.draw.line(
            self._Parent._CanvasHWND,
            SkinManager().GiveColor('Line'),
            (self._PosX, self._PosY + self._Height - 1),
            (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
Esempio n. 3
0
    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 = SkinManager()
        self._SkinManager.Init()
Esempio n. 4
0
    def DrawBG(self):
        _rect = pygame.Rect(self._BGPosX, self._BGPosY, self._BGWidth,
                            self._BGHeight)

        pygame.draw.rect(self._CanvasHWND,
                         SkinManager().GiveColor('White'), _rect, 0)
        pygame.draw.rect(self._CanvasHWND,
                         SkinManager().GiveColor('Text'), _rect, 1)
Esempio n. 5
0
    def Draw(self):
        # 200 total width
        # h = 40
        for i in range(0, self._Needle + 1):
            #w = 10,h = 40
            vol_rect = pygame.Rect(80 + i * 20, self._Height / 2 + 20, 10, 40)

            aa_round_rect(self._CanvasHWND, vol_rect,
                          SkinManager().GiveColor("Front"), 3, 0,
                          SkinManager().GiveColor("Front"))
Esempio n. 6
0
class AboveAllPatch(object):
    _PosX = Width / 2
    _PosY = Height / 2
    _Width = 50
    _Height = 120

    _Text = ""
    _FontObj = fonts["veramono20"]
    _Parent = None
    _Color = SkinManager().GiveColor('Text')
    _ValColor = SkinManager().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)
Esempio n. 7
0
class ListPageSelector(PageSelector):
    _BackgroundColor = SkinManager().GiveColor('Front')

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

    def AnimateDraw(self, x2, y2):
        pass

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

        x = self._Parent._MyList[idx]._PosX + 2
        y = self._Parent._MyList[idx]._PosY + 1
        h = self._Parent._MyList[idx]._Height - 3

        self._PosX = x
        self._PosY = y
        self._Height = h

        aa_round_rect(self._Parent._CanvasHWND, (x, y, self._Width - 4, h),
                      self._BackgroundColor, 4, 0, self._BackgroundColor)
Esempio n. 8
0
    def Init(self, text, font_obj, color=SkinManager().GiveColor('Text')):
        self._Color = color
        self._FontObj = font_obj
        self._Text = text

        my_text = self._FontObj.render(self._Text,True,self._Color)
        self._Width = my_text.get_width()
        self._Height = my_text.get_height()
Esempio n. 9
0
    def Init(self, text, font_obj, color=SkinManager().GiveColor('Text')):
        self._Color = color
        self._FontObj = font_obj
        self._Text = text

        self._Width = 0
        self._Height = 0
        self._CanvasHWND = pygame.Surface(
            (int(self._Parent._Width), int(self._Parent._Height)))
        self._HWND = self._Parent._CanvasHWND
Esempio n. 10
0
class Label:
    _PosX=0
    _PosY=0
    _Width=0
    _Height=0
    _Text=""
    _FontObj=None
    _Color = SkinManager().GiveColor('Text')
    _CanvasHWND = None
    _TextSurf = None
    def __init__(self):
        pass
    
    def Init(self, text, font_obj, color=SkinManager().GiveColor('Text')):
        self._Color = color
        self._FontObj = font_obj
        self._Text = text

        my_text = self._FontObj.render(self._Text,True,self._Color)
        self._Width = my_text.get_width()
        self._Height = my_text.get_height()

    def NewCoord(self,x,y):
        self._PosX = x
        self._PosY = y
        
    def SetColor(self,color):
        self._Color = color
    
    def GetText(self):
        return self._Text
    
    def SetText(self,text):
        self._Text = text
        
        my_text = self._FontObj.render(self._Text,True,self._Color)
        self._Width = my_text.get_width()
        self._Height = my_text.get_height()

    def Width(self):
        return self._Width
    
    def SetCanvasHWND(self,_canvashwnd):
        self._CanvasHWND = _canvashwnd

    def DrawCenter(self,bold=False):
        self._FontObj.set_bold(bold) ## avoing same font tangling set_bold to others
        my_text = self._FontObj.render( self._Text,True,self._Color)        
        self._CanvasHWND.blit(my_text,midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height))
        
    def Draw(self,bold=False):
        self._FontObj.set_bold(bold) ## avoing same font tangling set_bold to others
        my_text = self._FontObj.render( self._Text,True,self._Color)
        
        self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))
Esempio n. 11
0
class ListScroller(object):
    _PosX = 0
    _PosY = 0
    _Width = 7
    _Height = 0
    _MinHeight = 6 ## tested 
    _Parent    = None
    _Color     = SkinManager().GiveColor('Front')
    
    _StartX   = 0
    _StartY   = 0
    _EndX     = 0
    _EndY     = 0
    _Value    = 0
    _CanvasHWND = None
    
    def __init__(self):
        pass

    def Init(self):
        self.SetCanvasHWND(self._Parent._CanvasHWND)

    def SetCanvasHWND(self,canvas):
        self._CanvasHWND = canvas
        
    def AnimateDraw(self,x2,y2):
        pass

    def UpdateSize(self,bigheight,dirtyheight):
        bodyheight =  float(self._Parent._Height) / float(bigheight)
        if bodyheight > 1:
            bodyheight = 1 ## 100%

        margin = 4
        self._Height  = bodyheight * self._Parent._Height - margin ## Draw body
        
        if self._Height < self._MinHeight:
            self._Height = self._MinHeight
        
        self._StartX = self._Width/2
        self._StartY = margin/2+self._Height/2

        self._EndX   = self._Width/2
        self._EndY   = self._Parent._Height - margin/2 - self._Height/2

        process  = float(dirtyheight) / float(bigheight)
        value    = process* (self._EndY - self._StartY)

        self._Value = int(value)
        
    def Draw(self):
        
        start_rect = midRect(self._PosX+self._StartX,self._StartY+self._Value,self._Width,self._Height,self._Parent._Width,self._Parent._Height)
        aa_round_rect(self._CanvasHWND,start_rect, self._Color,3,0, self._Color)
Esempio n. 12
0
class CreateByScreen(FullScreen):

    _BG = None
    _BGColor = SkinManager().GiveColor('Black')

    def Init(self):
        self._BG = pygame.image.frombuffer(
            base64.b64decode(createby_clockworkpi_b64), (Width, Height),
            "RGBA")
        self._CanvasHWND = pygame.Surface((self._Width, self._Height))

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

        self._CanvasHWND.blit(self._BG, (0, 0, Width, Height))
Esempio n. 13
0
class UntitledIcon(object):
    _PosX = 0
    _PosY = 0
    _Width = 80
    _Height = 80

    _Words = ["G", "s"]
    _FontObj = fonts["varela40"]

    _BG = None  # initial surface

    _Color = SkinManager().GiveColor('Text')

    def __init__(self):
        self._Words = ["G", "s"]

    def Init(self):
        self._BG = pygame.image.load(BlankPng).convert_alpha()

    def SetWords(self, TwoWords):
        if len(TwoWords) == 1:
            self._Words[0] = TwoWords[0].upper()

        if len(TwoWords) == 2:
            self._Words[0] = TwoWords[0].upper()
            self._Words[1] = TwoWords[1].lower()

        self._Text = self._FontObj.render("".join(self._Words),True,self._Color)
        
    def Draw(self):
        if self._BG != None:
            w_ = self._Text.get_width()
            h_ = self._Text.get_height()
            
            self._BG.blit(self._Text,midRect(self._Width/2,self._Height/2,w_,h_,self._Width,self._Height))

    def Surface(self):
        self.Draw()

        return self._BG
Esempio n. 14
0
    def PreDraw(self):
        self._Width = 0
        self._Height = 0
        self._CanvasHWND.fill(SkinManager().GiveColor('White'))

        words = self._Text.split(' ')
        space = self._FontObj.size(' ')[0]
        max_width = self._Parent._Width - 40
        x, y = (0, 0)
        row_total_width = 0
        lines = 0

        for word in words:
            word_surface = self._FontObj.render(word, True, self._Color)
            word_width = word_surface.get_width()
            word_height = word_surface.get_height()
            row_total_width += word_width
            if lines == 0:
                lines += word_height
            if row_total_width + space >= max_width:
                x = 0  # Reset the x.
                y += word_height  # Start on new row.
                row_total_width = word_width

                lines += word_height

            self._CanvasHWND.blit(word_surface, (x, y))

            if len(words) == 1:  # single line
                x += word_width
            else:
                x += word_width + space

            if x > self._Width:
                self._Width = x

            if lines >= (self._Parent._Height - 40):
                break

        self._Height = lines
Esempio n. 15
0
 def ClearCanvas(self):
     self._CanvasHWND.fill(SkinManager().GiveColor('White'))
Esempio n. 16
0
class MainScreen(object):
    _Pages = []
    _PageMax = 0
    _PageIndex = 0
    _PosX = 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 = fonts["veramono20"]
    _IconFont = fonts["varela15"]
    _SkinManager = None

    _Closed = False
    _CounterScreen = None

    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 = SkinManager()
        self._SkinManager.Init()

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

        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):  # 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(i2, self._IconFont)
                    if FileExists(_dir + "/" + i + "/" + i2 +
                                  ".png"):  ### 20_Prog/Prog.png , cut 20_
                        iconitem._ImageName = _dir + "/" + i + "/" + i2 + ".png"
                    elif FileExists(SkinMap(_dir + "/" + i2 + ".png")):
                        iconitem._ImageName = SkinMap(_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.IsExecPackage(_dir + "/" + i):
                        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 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(
                            SkinMap(_dir + "/" + ReplaceSuffix(i2, "png"))):
                        iconitem._ImageName = SkinMap(_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(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)

    def DrawRun(self):
        self._MsgBox.SetText("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()
Esempio n. 17
0
class CounterScreen(FullScreen):

    _CounterFont = fonts["varela120"]
    _TextFont1    = fonts["varela15"]
    _TextFont2    = fonts["varela12"]
    
    _TopLabel = None
    _BottomLabel = None
    _NumberLabel = None
    
    _BGColor = SkinManager().GiveColor('Black')
    _FGColor = SkinManager().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

        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()
Esempio n. 18
0
class MultiLabel: ##Multi Line Label 
    _PosX=0
    _PosY=0
    _Width=135
    _Height=100
    _Text=""
    _FontObj=None
    _Color = SkinManager().GiveColor('Text')
    _CanvasHWND = None
    _TextSurf = None
    _MaxWidth = 0
    
    def __init__(self):
        pass
    
    def Init(self,text,font_obj,color=SkinManager().GiveColor('Text')):
        self._Color = color
        self._FontObj = font_obj
        self._Text = text
        
        self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj)
        
    def NewCoord(self,x,y):
        self._PosX = x
        self._PosY = y

    def SetColor(self,color):
        self._Color = color
    
    def GetText(self):
        return self._Text
    
    def SetText(self,text):
        self._Text = text
        
        self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj) 
        
    def Width(self):
        return self._Width
    
    def SetCanvasHWND(self,_canvashwnd):
        self._CanvasHWND = _canvashwnd

    def blit_text(self, surface,text, pos, font):
        color = self._Color
        words = [word.split(' ') for word in text.splitlines()]
        space = font.size(' ')[0]
        max_width = self._Width
        x ,y = pos
        row_total_width = 0
        lines = 0 
        for i,line in enumerate(words[:4]):
            for word in line[:12]:
                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 Draw(self):
        #my_text = self._FontObj.render( self._Text,True,self._Color)
        self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj)
Esempio n. 19
0
 def Init(self,text,font_obj,color=SkinManager().GiveColor('Text')):
     self._Color = color
     self._FontObj = font_obj
     self._Text = text
     
     self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj)