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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. from Screens.Screen import Screen
  2. from Components.ActionMap import NumberActionMap
  3. from Components.Label import Label
  4. from Components.ChoiceList import ChoiceEntryComponent, ChoiceList
  5. from Components.Sources.StaticText import StaticText
  6. from Components.Pixmap import Pixmap
  7. import enigma
  8. class ChoiceBox(Screen):
  9. def __init__(self, session, title="", list=None, keys=None, selection=0, skin_name=None, text=""):
  10. self.setTitle(_("Choice Box"))
  11. if not list: list = []
  12. if not skin_name: skin_name = []
  13. Screen.__init__(self, session)
  14. if isinstance(skin_name, str):
  15. skin_name = [skin_name]
  16. self.skinName = skin_name + ["ChoiceBox"]
  17. self["text"] = Label()
  18. self.var = ""
  19. if skin_name and 'SoftwareUpdateChoices' in skin_name and var and var in ('unstable', 'updating', 'stable', 'unknown'):
  20. self.var = var
  21. self['feedStatusMSG'] = Label()
  22. self['tl_off'] = Pixmap()
  23. self['tl_red'] = Pixmap()
  24. self['tl_yellow'] = Pixmap()
  25. self['tl_green'] = Pixmap()
  26. if title:
  27. title = _(title)
  28. if len(title) < 55 and title.find('\n') == -1:
  29. Screen.setTitle(self, title)
  30. elif title.find('\n') != -1:
  31. temptext = title.split('\n')
  32. if len(temptext[0]) < 55:
  33. Screen.setTitle(self, temptext[0])
  34. count = 2
  35. labeltext = ""
  36. while len(temptext) >= count:
  37. if labeltext:
  38. labeltext += '\n'
  39. labeltext = labeltext + temptext[count-1]
  40. count += 1
  41. print 'count',count
  42. self["text"].setText(labeltext)
  43. else:
  44. self["text"] = Label(title)
  45. else:
  46. self["text"] = Label(title)
  47. elif text:
  48. self["text"] = Label(_(text))
  49. self.list = []
  50. self.summarylist = []
  51. if keys is None:
  52. self.__keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
  53. else:
  54. self.__keys = keys + (len(list) - len(keys)) * [""]
  55. self.keymap = {}
  56. pos = 0
  57. for x in list:
  58. strpos = str(self.__keys[pos])
  59. self.list.append(ChoiceEntryComponent(key = strpos, text = x))
  60. if self.__keys[pos] != "":
  61. self.keymap[self.__keys[pos]] = list[pos]
  62. self.summarylist.append((self.__keys[pos], x[0]))
  63. pos += 1
  64. self["list"] = ChoiceList(list = self.list, selection = selection)
  65. self["summary_list"] = StaticText()
  66. self["summary_selection"] = StaticText()
  67. self.updateSummary(selection)
  68. self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions"],
  69. {
  70. "ok": self.go,
  71. "1": self.keyNumberGlobal,
  72. "2": self.keyNumberGlobal,
  73. "3": self.keyNumberGlobal,
  74. "4": self.keyNumberGlobal,
  75. "5": self.keyNumberGlobal,
  76. "6": self.keyNumberGlobal,
  77. "7": self.keyNumberGlobal,
  78. "8": self.keyNumberGlobal,
  79. "9": self.keyNumberGlobal,
  80. "0": self.keyNumberGlobal,
  81. "red": self.keyRed,
  82. "green": self.keyGreen,
  83. "yellow": self.keyYellow,
  84. "blue": self.keyBlue,
  85. "up": self.up,
  86. "down": self.down,
  87. "left": self.left,
  88. "right": self.right
  89. }, -1)
  90. self["cancelaction"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions"],
  91. {
  92. "back": self.cancel,
  93. }, -1)
  94. self.onShown.append(self.onshow)
  95. def onshow(self):
  96. if self.skinName and 'SoftwareUpdateChoices' in self.skinName and self.var and self.var in ('unstable', 'updating', 'stable', 'unknown'):
  97. status_msgs = {'stable': _('Feeds status: Stable'), 'unstable': _('Feeds status: Unstable'), 'updating': _('Feeds status: Updating'), 'unknown': _('No connection')}
  98. self['feedStatusMSG'].setText(status_msgs[self.var])
  99. self['tl_off'].hide()
  100. self['tl_red'].hide()
  101. self['tl_yellow'].hide()
  102. self['tl_green'].hide()
  103. if self.var == 'unstable':
  104. self['tl_red'].show()
  105. elif self.var == 'updating':
  106. self['tl_yellow'].show()
  107. elif self.var == 'stable':
  108. self['tl_green'].show()
  109. else:
  110. self['tl_off'].show()
  111. def autoResize(self):
  112. desktop_w = enigma.getDesktop(0).size().width()
  113. desktop_h = enigma.getDesktop(0).size().height()
  114. count = len(self.list)
  115. itemheight = self["list"].getItemHeight()
  116. if count > 15:
  117. count = 15
  118. if not self["text"].text:
  119. # move list
  120. textsize = (520, 0)
  121. listsize = (520, itemheight*count)
  122. self["list"].instance.move(enigma.ePoint(0, 0))
  123. self["list"].instance.resize(enigma.eSize(*listsize))
  124. else:
  125. textsize = self["text"].getSize()
  126. if textsize[0] < textsize[1]:
  127. textsize = (textsize[1],textsize[0]+10)
  128. if textsize[0] > 520:
  129. textsize = (textsize[0], textsize[1]+itemheight)
  130. else:
  131. textsize = (520, textsize[1]+itemheight)
  132. listsize = (textsize[0], itemheight*count)
  133. # resize label
  134. self["text"].instance.resize(enigma.eSize(*textsize))
  135. self["text"].instance.move(enigma.ePoint(10, 10))
  136. # move list
  137. self["list"].instance.move(enigma.ePoint(0, textsize[1]))
  138. self["list"].instance.resize(enigma.eSize(*listsize))
  139. wsizex = textsize[0]
  140. wsizey = textsize[1]+listsize[1]
  141. wsize = (wsizex, wsizey)
  142. self.instance.resize(enigma.eSize(*wsize))
  143. # center window
  144. self.instance.move(enigma.ePoint((desktop_w-wsizex)/2, (desktop_h-wsizey)/2))
  145. def left(self):
  146. if len(self["list"].list) > 0:
  147. while 1:
  148. self["list"].instance.moveSelection(self["list"].instance.pageUp)
  149. self.updateSummary(self["list"].l.getCurrentSelectionIndex())
  150. if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
  151. break
  152. def right(self):
  153. if len(self["list"].list) > 0:
  154. while 1:
  155. self["list"].instance.moveSelection(self["list"].instance.pageDown)
  156. self.updateSummary(self["list"].l.getCurrentSelectionIndex())
  157. if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
  158. break
  159. def up(self):
  160. if len(self["list"].list) > 0:
  161. while 1:
  162. self["list"].instance.moveSelection(self["list"].instance.moveUp)
  163. self.updateSummary(self["list"].l.getCurrentSelectionIndex())
  164. if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
  165. break
  166. def down(self):
  167. if len(self["list"].list) > 0:
  168. while 1:
  169. self["list"].instance.moveSelection(self["list"].instance.moveDown)
  170. self.updateSummary(self["list"].l.getCurrentSelectionIndex())
  171. if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
  172. break
  173. # runs a number shortcut
  174. def keyNumberGlobal(self, number):
  175. self.goKey(str(number))
  176. # runs the current selected entry
  177. def go(self):
  178. cursel = self["list"].l.getCurrentSelection()
  179. if cursel:
  180. self.goEntry(cursel[0])
  181. else:
  182. self.cancel()
  183. # runs a specific entry
  184. def goEntry(self, entry):
  185. if entry and len(entry) > 3 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
  186. arg = entry[3]
  187. entry[2](arg)
  188. elif entry and len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
  189. entry[2](None)
  190. else:
  191. self.close(entry)
  192. # lookups a key in the keymap, then runs it
  193. def goKey(self, key):
  194. if self.keymap.has_key(key):
  195. entry = self.keymap[key]
  196. self.goEntry(entry)
  197. # runs a color shortcut
  198. def keyRed(self):
  199. self.goKey("red")
  200. def keyGreen(self):
  201. self.goKey("green")
  202. def keyYellow(self):
  203. self.goKey("yellow")
  204. def keyBlue(self):
  205. self.goKey("blue")
  206. def updateSummary(self, curpos=0):
  207. pos = 0
  208. summarytext = ""
  209. for entry in self.summarylist:
  210. if curpos-2 < pos < curpos+5:
  211. if pos == curpos:
  212. summarytext += ">"
  213. self["summary_selection"].setText(entry[1])
  214. else:
  215. summarytext += entry[0]
  216. summarytext += ' ' + entry[1] + '\n'
  217. pos += 1
  218. self["summary_list"].setText(summarytext)
  219. def cancel(self):
  220. self.close(None)