list_item.py 3.3 KB

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