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

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