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

Screen.py 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. from Tools.Profile import profile
  2. profile("LOAD:GUISkin")
  3. from Components.GUISkin import GUISkin
  4. profile("LOAD:Source")
  5. from Components.Sources.Source import Source
  6. profile("LOAD:GUIComponent")
  7. from Components.GUIComponent import GUIComponent
  8. profile("LOAD:eRCInput")
  9. from enigma import eRCInput
  10. class Screen(dict, GUISkin):
  11. False, SUSPEND_STOPS, SUSPEND_PAUSES = range(3)
  12. ALLOW_SUSPEND = False
  13. global_screen = None
  14. def __init__(self, session, parent = None):
  15. dict.__init__(self)
  16. self.skinName = self.__class__.__name__
  17. self.session = session
  18. self.parent = parent
  19. GUISkin.__init__(self)
  20. self.onClose = [ ]
  21. self.onFirstExecBegin = [ ]
  22. self.onExecBegin = [ ]
  23. self.onExecEnd = [ ]
  24. self.onShown = [ ]
  25. self.onShow = [ ]
  26. self.onHide = [ ]
  27. self.execing = False
  28. self.shown = True
  29. # already shown is false until the screen is really shown (after creation)
  30. self.already_shown = False
  31. self.renderer = [ ]
  32. # in order to support screens *without* a help,
  33. # we need the list in every screen. how ironic.
  34. self.helpList = [ ]
  35. self.close_on_next_exec = None
  36. # stand alone screens (for example web screens)
  37. # don't care about having or not having focus.
  38. self.stand_alone = False
  39. self.keyboardMode = None
  40. def saveKeyboardMode(self):
  41. rcinput = eRCInput.getInstance()
  42. self.keyboardMode = rcinput.getKeyboardMode()
  43. def setKeyboardModeAscii(self):
  44. rcinput = eRCInput.getInstance()
  45. rcinput.setKeyboardMode(rcinput.kmAscii)
  46. def setKeyboardModeNone(self):
  47. rcinput = eRCInput.getInstance()
  48. rcinput.setKeyboardMode(rcinput.kmNone)
  49. def restoreKeyboardMode(self):
  50. rcinput = eRCInput.getInstance()
  51. if self.keyboardMode is not None:
  52. rcinput.setKeyboardMode(self.keyboardMode)
  53. def execBegin(self):
  54. self.active_components = [ ]
  55. if self.close_on_next_exec is not None:
  56. tmp = self.close_on_next_exec
  57. self.close_on_next_exec = None
  58. self.execing = True
  59. self.close(*tmp)
  60. else:
  61. single = self.onFirstExecBegin
  62. self.onFirstExecBegin = []
  63. for x in self.onExecBegin + single:
  64. x()
  65. if not self.stand_alone and self.session.current_dialog != self:
  66. return
  67. # assert self.session == None, "a screen can only exec once per time"
  68. # self.session = session
  69. for val in self.values() + self.renderer:
  70. val.execBegin()
  71. if not self.stand_alone and self.session.current_dialog != self:
  72. return
  73. self.active_components.append(val)
  74. self.execing = True
  75. for x in self.onShown:
  76. x()
  77. def execEnd(self):
  78. active_components = self.active_components
  79. # for (name, val) in self.items():
  80. self.active_components = None
  81. if active_components is not None:
  82. for val in active_components:
  83. val.execEnd()
  84. # assert self.session != None, "execEnd on non-execing screen!"
  85. # self.session = None
  86. self.execing = False
  87. for x in self.onExecEnd:
  88. x()
  89. # never call this directly - it will be called from the session!
  90. def doClose(self):
  91. self.hide()
  92. for x in self.onClose:
  93. x()
  94. # fixup circular references
  95. del self.helpList
  96. GUISkin.close(self)
  97. # first disconnect all render from their sources.
  98. # we might split this out into a "unskin"-call,
  99. # but currently we destroy the screen afterwards
  100. # anyway.
  101. for val in self.renderer:
  102. val.disconnectAll() # disconnected converter/sources and probably destroy them. Sources will not be destroyed.
  103. del self.session
  104. for (name, val) in self.items():
  105. val.destroy()
  106. del self[name]
  107. self.renderer = [ ]
  108. # really delete all elements now
  109. self.__dict__.clear()
  110. def close(self, *retval):
  111. if not self.execing:
  112. self.close_on_next_exec = retval
  113. else:
  114. self.session.close(self, *retval)
  115. def setFocus(self, o):
  116. self.instance.setFocus(o.instance)
  117. def show(self):
  118. # Temporarily add to ease up identification of screens
  119. print '[SCREENNAME] ',self.skinName
  120. if (self.shown and self.already_shown) or not self.instance:
  121. return
  122. self.shown = True
  123. self.already_shown = True
  124. self.instance.show()
  125. for x in self.onShow:
  126. x()
  127. for val in self.values() + self.renderer:
  128. if isinstance(val, GUIComponent) or isinstance(val, Source):
  129. val.onShow()
  130. def hide(self):
  131. if not self.shown or not self.instance:
  132. return
  133. self.shown = False
  134. self.instance.hide()
  135. for x in self.onHide:
  136. x()
  137. for val in self.values() + self.renderer:
  138. if isinstance(val, GUIComponent) or isinstance(val, Source):
  139. val.onHide()
  140. def setAnimationMode(self, mode):
  141. if self.instance:
  142. self.instance.setAnimationMode(mode)
  143. def __repr__(self):
  144. return str(type(self))
  145. def getRelatedScreen(self, name):
  146. if name == "session":
  147. return self.session.screen
  148. elif name == "parent":
  149. return self.parent
  150. elif name == "global":
  151. return self.global_screen
  152. else:
  153. return None