list_item.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. #from beeprint import pp
  4. import os
  5. ## local UI import
  6. from UI.constants import ICON_TYPES
  7. from UI.page import Page
  8. from UI.label import Label
  9. from UI.icon_item import IconItem
  10. from UI.util_funcs import midRect
  11. from UI.skin_manager import MySkinManager
  12. # a item for List
  13. # - - - - - - - - - - - --
  14. # | Icon Text..... > |
  15. # ------------------------
  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 ListItem(object):
  24. _PosX = 0
  25. _PosY = 0
  26. _Width = 0
  27. _Height = 32
  28. _Labels = {}
  29. _Icons = {}
  30. _Fonts = {}
  31. _MyType = ICON_TYPES["EXE"]
  32. _LinkObj = None
  33. _Path = ""
  34. _Active = False
  35. _Playing = False ## play or pause
  36. _Parent = None
  37. def __init__(self):
  38. self._Labels = {}
  39. self._Icons = {}
  40. self._Fonts = {}
  41. def IsFile(self):
  42. if self._MyType == ICON_TYPES["FILE"]:
  43. return True
  44. return False
  45. def IsDir(self):
  46. if self._MyType == ICON_TYPES["DIR"]:
  47. return True
  48. return False
  49. def Init(self,text):
  50. #self._Fonts["normal"] = fonts["Eurostile12"]
  51. l = Label()
  52. l._PosX = 20
  53. l.SetCanvasHWND(self._Parent._CanvasHWND)
  54. if self._MyType == ICON_TYPES["DIR"] or self._MyType == ICON_TYPES["FILE"]:
  55. self._Path = text
  56. label_text = os.path.basename(text)
  57. alias_file = os.path.splitext(text)[0] + ".alias"
  58. if os.path.isfile(alias_file.encode("utf8")):
  59. fp = open(alias_file.encode("utf8"), "r")
  60. alias = fp.read()
  61. fp.close()
  62. label_text = alias.decode("utf8")
  63. if self._MyType == ICON_TYPES["DIR"]:
  64. l.Init(label_text,self._Fonts["normal"])
  65. else:
  66. l.Init(label_text,self._Fonts["normal"])
  67. self._Labels["Text"] = l
  68. def Draw(self):
  69. if self._Path != "[..]":
  70. self._Labels["Text"]._PosX = 23
  71. else:
  72. self._Labels["Text"]._PosX = 3
  73. self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
  74. self._Labels["Text"].Draw()
  75. """
  76. if self._Active == True:
  77. pass
  78. """
  79. if self._MyType == ICON_TYPES["DIR"] and self._Path != "[..]":
  80. self._Parent._Icons["sys"]._IconIndex = 0
  81. self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
  82. self._Parent._Icons["sys"].Draw()
  83. if self._MyType == ICON_TYPES["FILE"]:
  84. self._Parent._Icons["sys"]._IconIndex = 1
  85. self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
  86. self._Parent._Icons["sys"].Draw()
  87. pygame.draw.line(self._Parent._CanvasHWND,MySkinManager.GiveColor('Line'),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)