list_item.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. from UI.skin_manager import SkinManager
  12. # a item for List
  13. # - - - - - - - - - - - --
  14. # | Icon Text..... > |
  15. # ------------------------
  16. import myvars # icons_path
  17. class ListItemIcon(IconItem):
  18. _CanvasHWND = None
  19. _Parent = None
  20. _Width = 18
  21. _Height = 18
  22. def Draw(self):
  23. self._CanvasHWND.blit(self._ImgSurf,(self._PosX,self._PosY+(self._Parent._Height-self._Height)/2,self._Width,self._Height))
  24. class ListItemLabel(Label):
  25. _ActiveColor = SkinManager().GiveColor('Active')
  26. _Active = False
  27. def Draw(self):
  28. self._FontObj.set_bold(self._Active)
  29. my_text = self._FontObj.render( self._Text,True,self._Color)
  30. self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))
  31. class ListItem(object):
  32. _PosX = 0
  33. _PosY = 0
  34. _Width = 0
  35. _Height = 30
  36. _Labels = {}
  37. _Icons = {}
  38. _Fonts = {}
  39. _MyType = ICON_TYPES["EXE"]
  40. _LinkObj = None
  41. _Path = ""
  42. _Active = False
  43. _Parent = None
  44. _Text = ""
  45. def __init__(self):
  46. self._Labels = {}
  47. self._Icons = {}
  48. self._Fonts = {}
  49. def Init(self,text):
  50. self._Text = text
  51. l = ListItemLabel()
  52. l._PosX = 22
  53. l.SetCanvasHWND(self._Parent._CanvasHWND)
  54. if self._MyType == ICON_TYPES["DIR"]:
  55. l.Init(text,self._Fonts["normal"])
  56. self._Path = text
  57. else:
  58. l.Init(text,self._Fonts["normal"])
  59. self._Path = text
  60. self._Labels["Text"] = l
  61. def NewCoord(self,x,y):
  62. self._PosX = x
  63. self._PosY = y
  64. def Draw(self):
  65. if self._MyType == ICON_TYPES["DIR"] and self._Path != "[..]":
  66. self._Parent._Icons["sys"]._IconIndex = 0
  67. self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
  68. self._Parent._Icons["sys"].Draw()
  69. if self._MyType == ICON_TYPES["FILE"]:
  70. self._Parent._Icons["sys"]._IconIndex = 1
  71. self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
  72. self._Parent._Icons["sys"].Draw()
  73. if self._Active == True:
  74. self._Labels["Text"]._Active = True
  75. else:
  76. self._Labels["Text"]._Active = False
  77. self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
  78. 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)
  79. self._Labels["Text"].Draw()