Enigma2 plugin to to play various online streams (mostly Latvian).

GUISkin.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. from GUIComponent import GUIComponent
  2. from skin import applyAllAttributes
  3. from Tools.CList import CList
  4. from Sources.StaticText import StaticText
  5. class GUISkin:
  6. __module__ = __name__
  7. def __init__(self):
  8. self["Title"] = StaticText()
  9. self.onLayoutFinish = [ ]
  10. self.summaries = CList()
  11. self.instance = None
  12. self.desktop = None
  13. def createGUIScreen(self, parent, desktop, updateonly = False):
  14. for val in self.renderer:
  15. if isinstance(val, GUIComponent):
  16. if not updateonly:
  17. val.GUIcreate(parent)
  18. if not val.applySkin(desktop, self):
  19. print "warning, skin is missing renderer", val, "in", self
  20. for key in self:
  21. val = self[key]
  22. if isinstance(val, GUIComponent):
  23. if not updateonly:
  24. val.GUIcreate(parent)
  25. depr = val.deprecationInfo
  26. if val.applySkin(desktop, self):
  27. if depr:
  28. print "WARNING: OBSOLETE COMPONENT '%s' USED IN SKIN. USE '%s' INSTEAD!" % (key, depr[0])
  29. print "OBSOLETE COMPONENT WILL BE REMOVED %s, PLEASE UPDATE!" % (depr[1])
  30. elif not depr:
  31. print "warning, skin is missing element", key, "in", self
  32. for w in self.additionalWidgets:
  33. if not updateonly:
  34. w.instance = w.widget(parent)
  35. # w.instance.thisown = 0
  36. applyAllAttributes(w.instance, desktop, w.skinAttributes, self.scale)
  37. for f in self.onLayoutFinish:
  38. if type(f) is not type(self.close): # is this the best way to do this?
  39. exec f in globals(), locals()
  40. else:
  41. f()
  42. def deleteGUIScreen(self):
  43. for (name, val) in self.items():
  44. if isinstance(val, GUIComponent):
  45. val.GUIdelete()
  46. def close(self):
  47. self.deleteGUIScreen()
  48. def createSummary(self):
  49. return None
  50. def addSummary(self, summary):
  51. self.summaries.append(summary)
  52. def removeSummary(self, summary):
  53. self.summaries.remove(summary)
  54. def setTitle(self, title):
  55. try:
  56. if self.instance:
  57. self.instance.setTitle(title)
  58. self["Title"].text = title
  59. self.summaries.setTitle(title)
  60. except:
  61. pass
  62. def getTitle(self):
  63. return self["Title"].text
  64. title = property(getTitle, setTitle)
  65. def setDesktop(self, desktop):
  66. self.desktop = desktop
  67. def applySkin(self):
  68. z = 0
  69. baseres = (720, 576) # FIXME: a skin might have set another resolution, which should be the base res
  70. idx = 0
  71. skin_title_idx = -1
  72. title = self.title
  73. for (key, value) in self.skinAttributes:
  74. if key == "zPosition":
  75. z = int(value)
  76. elif key == "title":
  77. skin_title_idx = idx
  78. if title:
  79. self.skinAttributes[skin_title_idx] = ("title", title)
  80. else:
  81. self["Title"].text = value
  82. self.summaries.setTitle(value)
  83. elif key == "baseResolution":
  84. baseres = tuple([int(x) for x in value.split(',')])
  85. idx += 1
  86. self.scale = ((baseres[0], baseres[0]), (baseres[1], baseres[1]))
  87. if not self.instance:
  88. from enigma import eWindow
  89. self.instance = eWindow(self.desktop, z)
  90. if skin_title_idx == -1 and title:
  91. self.skinAttributes.append(("title", title))
  92. # we need to make sure that certain attributes come last
  93. self.skinAttributes.sort(key=lambda a: {"position": 1}.get(a[0], 0))
  94. applyAllAttributes(self.instance, self.desktop, self.skinAttributes, self.scale)
  95. self.createGUIScreen(self.instance, self.desktop)