list_item.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. from libs.roundrects import aa_round_rect
  4. ## local UI import
  5. from UI.constants import ICON_TYPES
  6. from UI.page import Page
  7. from UI.label import Label
  8. from UI.fonts import fonts
  9. from UI.icon_item import IconItem
  10. from UI.util_funcs import midRect
  11. # a item for List
  12. # - - - - - - - - - - - --
  13. # | Icon Text..... > |
  14. # ------------------------
  15. import myvars # icons_path
  16. class ListItemIcon(IconItem):
  17. _CanvasHWND = None
  18. _Parent = None
  19. _Width = 18
  20. _Height = 18
  21. def Draw(self):
  22. self._CanvasHWND.blit(self._ImgSurf,(self._PosX,self._PosY+(self._Parent._Height-self._Height)/2,self._Width,self._Height))
  23. class ListItemLabel(Label):
  24. _ActiveColor = pygame.Color(175,90,0)
  25. _Active = False
  26. def Draw(self):
  27. self._FontObj.set_bold(self._Active)
  28. """
  29. if self._Active == True:
  30. my_text = self._FontObj.render( self._Text,True,self._ActiveColor)
  31. else:
  32. my_text = self._FontObj.render( self._Text,True,self._Color)
  33. """
  34. my_text = self._FontObj.render( self._Text,True,self._Color)
  35. self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))
  36. class ListItem(object):
  37. _PosX = 0
  38. _PosY = 0
  39. _Width = 0
  40. _Height = 30
  41. _Labels = {}
  42. _Icons = {}
  43. _Fonts = {}
  44. _MyType = ICON_TYPES["EXE"]
  45. _LinkObj = None
  46. _Path = ""
  47. _Active = False
  48. _Playing = False ## play or pause
  49. _PlayingProcess = 0 # 0 - 100
  50. _Parent = None
  51. _Text = ""
  52. def __init__(self):
  53. self._Labels = {}
  54. self._Icons = {}
  55. self._Fonts = {}
  56. def Init(self,text):
  57. #self._Fonts["normal"] = fonts["veramono12"]
  58. self._Text = text
  59. l = ListItemLabel()
  60. l._PosX = 22
  61. l.SetCanvasHWND(self._Parent._CanvasHWND)
  62. if self._MyType == ICON_TYPES["DIR"]:
  63. l.Init(text,self._Fonts["normal"])
  64. self._Path = text
  65. else:
  66. l.Init(text,self._Fonts["normal"])
  67. self._Path = text
  68. self._Labels["Text"] = l
  69. def NewCoord(self,x,y):
  70. self._PosX = x
  71. self._PosY = y
  72. def Draw(self):
  73. if self._MyType == ICON_TYPES["DIR"] and self._Path != "[..]":
  74. self._Parent._Icons["sys"]._IconIndex = 0
  75. self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
  76. self._Parent._Icons["sys"].Draw()
  77. if self._MyType == ICON_TYPES["FILE"]:
  78. self._Parent._Icons["sys"]._IconIndex = 1
  79. self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
  80. self._Parent._Icons["sys"].Draw()
  81. if self._Active == True:
  82. self._Labels["Text"]._Active = True
  83. else:
  84. self._Labels["Text"]._Active = False
  85. self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
  86. pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
  87. if self._Playing == True:
  88. self._Labels["Text"]._Active =True
  89. self._Labels["Text"].Draw()
  90. #_rect = midRect(10,self._PosY+15,10,10,self._Parent._Width,self._Parent._Height)
  91. #aa_round_rect(self._Parent._CanvasHWND,_rect,(0,0,0),3,0,(0,0,0))
  92. #pygame.draw.polygon(self._Parent._CanvasHWND, (0,0,0), [[6, self._PosY+7], [11, self._PosY+14],[6, self._PosY+21]], 2)
  93. if self._PlayingProcess > 0:
  94. seek_posx = int(self._Width * self._PlayingProcess/100.0)
  95. pygame.draw.line(self._Parent._CanvasHWND,(255,169,169),(self._PosX,self._PosY+self._Height-2),(self._PosX+seek_posx,self._PosY+self._Height-2),2)
  96. else:
  97. self._Labels["Text"].Draw()