Advertisement
SharkyEXE

Untitled

Jun 17th, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.59 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #based on spzZapHistory and ZapHistoryBrowser mod aka Uchkun
  3. #created by Vasiliks 11.2015
  4. #added picon providers 05.01.2018
  5. #r0.1_r6 PLI version
  6. from . import _
  7. from Components.ActionMap import ActionMap
  8. from Components.config import config, ConfigEnableDisable, ConfigInteger, ConfigSelection, ConfigSubsection, getConfigListEntry
  9. from Components.ConfigList import ConfigListScreen
  10. from Components.Label import Label
  11. from Components.MenuList import MenuList
  12. from Components.MultiContent import MultiContentEntryProgress, MultiContentEntryText, MultiContentEntryPixmapAlphaBlend
  13. from enigma import BT_SCALE, getDesktop, eListboxPythonMultiContent, eServiceCenter, eServiceReference, eTimer, gFont, loadPNG, RT_HALIGN_LEFT, RT_HALIGN_CENTER, RT_HALIGN_RIGHT, RT_WRAP, RT_VALIGN_CENTER, iServiceInformation, iPlayableService, iPlayableServicePtr
  14. from Components.ParentalControl import parentalControl
  15. from Plugins.Plugin import PluginDescriptor
  16. from Screens.ChannelSelection import ChannelSelection
  17. from Screens.ParentalControlSetup import ProtectedScreen
  18. from Screens.Screen import Screen
  19. import Screens.InfoBar
  20. from time import localtime, time
  21. from Tools.Directories import fileExists, resolveFilename, SCOPE_SKIN_IMAGE, SCOPE_CURRENT_SKIN
  22. from Components.Converter.Converter import Converter
  23. from ServiceReference import resolveAlternate
  24. from Components.Element import cached
  25.  
  26. screenWidth = getDesktop(0).size().width()
  27.  
  28. color = [("0xffffff", _("белый")),
  29. ("0xc0c0c0", _("светлосерый")),
  30. ("0x8f8f8f", _("серый")),
  31. ("0x555555", _("тёмносерый")),
  32. ("0xffff55", _("жёлтый")),
  33. ("0xffcc33", _("золотой")),
  34. ("0xff80ff", _("розовый")),
  35. ("0xff8000", _("оранжевый")),
  36. ("0xff0000", _("красный")),
  37. ("0x800000", _("малиновый")),
  38. ("0x804000", _("коричневый")),
  39. ("0x80ff00", _("лайм")),
  40. ("0x00ff00", _("зелёный")),
  41. ("0x008000", _("тёмнозелёный")),
  42. ("0x00ffff", _("аква")),
  43. ("0x0099ff", _("голубой")),
  44. ("0x0000ff", _("синий")),
  45. ("0x000080", _("тёмносиний")),
  46. ("0x8080ff", _("сиреневый")),
  47. ("0x400080", _("фиолетовый"))]
  48.  
  49. config.plugins.vZapHistory = ConfigSubsection()
  50. config.plugins.vZapHistory.enable = ConfigSelection(default='on', choices=[('off', _('выключено')), ('on', _('включено')), ('parental_lock', _('выключено в родительском контроле'))])
  51. config.plugins.vZapHistory.maxEntries = ConfigInteger(default=20, limits=(2, 60))
  52. config.plugins.vZapHistory.viewMode = ConfigSelection(default='picons_prov', choices=[('menu', _('стандартный')), ('picons', _('с пиконами')), ('picons_prov', _('с пиконами: провайдеров')), ('picons_prov_sat', _('с пиконами: провайдеров + спутников'))])
  53. config.plugins.vZapHistory.alignment = ConfigSelection(default='left', choices=[('left', _('слева')), ('center', _('по центру')), ('right', _('справа'))])
  54. config.plugins.vZapHistory.autoZap = ConfigEnableDisable(default=False)
  55. config.plugins.vZapHistory.namecolor = ConfigSelection(default="0xffffff", choices = color)
  56. config.plugins.vZapHistory.namecolor_sel = ConfigSelection(default="0xffffff", choices = color)
  57. config.plugins.vZapHistory.eventcolor = ConfigSelection(default="0xffffff", choices = color)
  58. config.plugins.vZapHistory.eventcolor_sel = ConfigSelection(default="0xffffff", choices = color)
  59. config.plugins.vZapHistory.duratcolor = ConfigSelection(default="0xffffff", choices = color)
  60. config.plugins.vZapHistory.duratcolor_sel = ConfigSelection(default="0xffffff", choices = color)
  61. config.plugins.vZapHistory.barcolor = ConfigSelection(default="0xffffff", choices = color)
  62. config.plugins.vZapHistory.barcolor_sel = ConfigSelection(default="0xffffff", choices = color)
  63.  
  64. skin_sd = """
  65. <screen name="vZapHistory" position="center,center" size="530,400" >
  66. <widget name="list" position="0,40" size="530,350" transparent="1" alphatest="blend"/>
  67. <eLabel position="10,28" size="120,3" backgroundColor="#FF0000"/>
  68. <eLabel position="140,28" size="120,3" backgroundColor="#00FF00"/>
  69. <eLabel position="270,28" size="120,3" backgroundColor="#FFFF00"/>
  70. <eLabel position="400,28" size="120,3" backgroundColor="#0000FF"/>
  71. <widget name="key_red" position="0,5" zPosition="1" size="120,20" font="Regular; 18" valign="center" halign="center" transparent="1" />
  72. <widget name="key_green" position="140,5" zPosition="1" size="120,20" font="Regular; 18" valign="center" halign="center" transparent="1" />
  73. <widget name="key_yellow" position="270,5" zPosition="1" size="120,20" font="Regular; 18" valign="center" halign="center" transparent="1" />
  74. <widget name="key_blue" position="400,5" zPosition="1" size="120,20" font="Regular; 18" valign="center" halign="center" transparent="1" />
  75. </screen>"""
  76. skin_hd = """
  77. <screen name="vZapHistory" position="5,50" size="1270,665" >
  78. <widget name="list" position="5,45" size="1270,553" transparent="1" alphatest="blend"/>
  79. <ePixmap pixmap="skin_default/buttons/red.png" position="126,7" size="160,30" transparent="1" alphatest="blend" />
  80. <ePixmap pixmap="skin_default/buttons/green.png" position="412,7" size="160,30" transparent="1" alphatest="blend" />
  81. <ePixmap pixmap="skin_default/buttons/yellow.png" position="698,7" size="160,30" transparent="1" alphatest="blend" />
  82. <ePixmap pixmap="skin_default/buttons/blue.png" position="1018,7" size="160,30" transparent="1" alphatest="blend" />
  83. <widget name="key_red" position="126,9" zPosition="1" size="160,25" font="Regular; 16" valign="center" halign="center" transparent="1" />
  84. <widget name="key_green" position="412,9" zPosition="1" size="160,25" font="Regular; 16" valign="center" halign="center" transparent="1" />
  85. <widget name="key_yellow" position="698,9" zPosition="1" size="160,25" font="Regular; 16" valign="center" halign="center" transparent="1" />
  86. <widget name="key_blue" position="1018,9" zPosition="1" size="160,25" font="Regular; 16" valign="center" halign="center" transparent="1" />
  87. </screen>"""
  88. skin_fhd = """
  89. <screen name="vZapHistory" position="center,center" size="990,680" >
  90. <widget name="list" position="5,45" size="980,635" transparent="1" alphatest="blend"/>
  91. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/red.png" position="65,7" size="160,30" transparent="1" alphatest="blend" />
  92. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/green.png" position="295,7" size="160,30" transparent="1" alphatest="blend" />
  93. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/yellow.png" position="525,7" size="160,30" transparent="1" alphatest="blend" />
  94. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/blue.png" position="755,7" size="160,30" transparent="1" alphatest="blend" />
  95. <widget name="key_red" position="65,9" zPosition="1" size="160,24" font="Regular; 20" valign="center" halign="center" transparent="1" />
  96. <widget name="key_green" position="295,9" zPosition="1" size="160,24" font="Regular; 20" valign="center" halign="center" transparent="1" />
  97. <widget name="key_yellow" position="525,9" zPosition="1" size="160,24" font="Regular; 20" valign="center" halign="center" transparent="1" />
  98. <widget name="key_blue" position="755,9" zPosition="1" size="160,24" font="Regular; 20" valign="center" halign="center" transparent="1" />
  99. </screen>"""
  100.  
  101. skinConf_sd = """
  102. <screen name="vZapHistoryConf" position="center,center" size="530,400" >
  103. <widget name="config" position="0,50" size="530,350" scrollbarMode="showOnDemand" transparent="1" />
  104. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/red.png" position="55,7" size="160,30" transparent="1" alphatest="blend" />
  105. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/green.png" position="315,7" size="160,30" transparent="1" alphatest="blend" />
  106. <widget name="key_red" position="55,9" zPosition="5" size="160,25" font="Regular;16" valign="center" halign="center" transparent="1" shadowColor="black" />
  107. <widget name="key_green" position="315,9" zPosition="5" size="160,25" font="Regular;16" valign="center" halign="center" transparent="1" shadowColor="black" />
  108. </screen>"""
  109. skinConf_hd = """
  110. <screen name="vZapHistoryConf" position="center,center" size="660,390" >
  111. <widget name="config" position="10,50" size="640,340" scrollbarMode="showOnDemand" transparent="1" />
  112. <ePixmap pixmap="skin_default/buttons/red.png" position="80,7" size="160,30" transparent="1" alphatest="blend" />
  113. <ePixmap pixmap="skin_default/buttons/green.png" position="400,7" size="160,30" transparent="1" alphatest="blend" />
  114. <widget name="key_red" position="80,9" zPosition="5" size="160,25" font="Regular;16" valign="center" halign="center" transparent="1" shadowColor="black" />
  115. <widget name="key_green" position="400,9" zPosition="5" size="160,25" font="Regular;16" valign="center" halign="center" transparent="1" shadowColor="black" />
  116. </screen>"""
  117. skinConf_fhd = """
  118. <screen name="vZapHistoryConf" position="center,center" size="900,520" >
  119. <widget name="config" position="10,50" size="880,460" itemHeight="35" font="Regular;25" scrollbarMode="showOnDemand" transparent="1" />
  120. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/red.png" position="130,7" size="160,30" transparent="1" alphatest="blend" />
  121. <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/vZapHistory/buttons/green.png" position="590,7" size="160,30" transparent="1" alphatest="blend" />
  122. <widget name="key_red" position="130,9" zPosition="5" size="160,25" font="Regular;20" valign="center" halign="center" transparent="1" shadowColor="black" />
  123. <widget name="key_green" position="590,9" zPosition="5" size="160,25" font="Regular;20" valign="center" halign="center" transparent="1" shadowColor="black" />
  124. </screen>"""
  125.  
  126. def addToHistory(instance, ref):
  127. if config.plugins.vZapHistory.enable.value == 'off':
  128. return
  129. else:
  130. if config.ParentalControl.servicepinactive.value and config.plugins.vZapHistory.enable.value == 'parental_lock':
  131. if parentalControl.getProtectionLevel(ref.toCompareString()) != -1:
  132. return
  133. if instance.servicePath is not None:
  134. tmp = instance.servicePath[:]
  135. tmp.append(ref)
  136. score = 0
  137. remove = -1
  138. for x in instance.history:
  139. if len(x) == 2:
  140. xref = x[1]
  141. else:
  142. xref = x[2]
  143. if xref == ref and remove == -1:
  144. remove = score
  145. score += 1
  146. if remove > -1:
  147. del instance.history[remove]
  148. instance.history.append(tmp)
  149. hlen = len(instance.history)
  150. if hlen > config.plugins.vZapHistory.maxEntries.value:
  151. del instance.history[0]
  152. hlen -= 1
  153. instance.history_pos = hlen - 1
  154.  
  155. ChannelSelection.addToHistory = addToHistory
  156.  
  157. class vZapHistoryBrowserList(MenuList):
  158.  
  159. def __init__(self, list, enableWrapAround = False):
  160. MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
  161. self.l.setFont(0, gFont('Regular', 24))
  162. self.l.setFont(1, gFont('Regular', 18))
  163. self.l.setFont(2, gFont('Regular', 15))
  164. self.l.setFont(3, gFont('Regular', 15))
  165.  
  166. def vZapHistoryBrowserListEntry(self, serviceName, eventName, durationTime, bar, png, png_prov, png_prov_sat): #
  167. res = [serviceName]
  168. lasflags = RT_HALIGN_LEFT
  169. if config.plugins.vZapHistory.alignment.value == 'center':
  170. lasflags = RT_HALIGN_CENTER
  171. elif config.plugins.vZapHistory.alignment.value == 'right':
  172. lasflags = RT_HALIGN_RIGHT
  173. namecolor = int(config.plugins.vZapHistory.namecolor.value, 16)
  174. namecolor_sel = int(config.plugins.vZapHistory.namecolor_sel.value, 16)
  175. eventcolor = int(config.plugins.vZapHistory.eventcolor.value, 16)
  176. eventcolor_sel = int(config.plugins.vZapHistory.eventcolor_sel.value, 16)
  177. duratcolor = int(config.plugins.vZapHistory.duratcolor.value, 16)
  178. duratcolor_sel = int(config.plugins.vZapHistory.duratcolor_sel.value, 16)
  179. barcolor = int(config.plugins.vZapHistory.barcolor.value, 16)
  180. barcolor_sel = int(config.plugins.vZapHistory.barcolor_sel.value, 16)
  181.  
  182. if screenWidth == 1920:
  183. if config.plugins.vZapHistory.viewMode.value == 'picons':
  184. self['list'].l.setItemHeight(70)
  185. png_pos=(5, 5)
  186. png_size=(100, 60)
  187. serviceName_pos=(110, 3)
  188. serviceName_size=(675, 25)
  189. serviceName_font=0
  190. eventName_pos=(110, 28)
  191. eventName_size=(675, 40)
  192. eventName_font=1
  193. durationTime_pos=(795, 16)
  194. durationTime_size=(180, 25)
  195. durationTime_font=2
  196. bar_pos=(795, 45)
  197. bar_size=(180, 10)
  198. if config.plugins.vZapHistory.viewMode.value == 'picons_prov':
  199. self['list'].l.setItemHeight(70)
  200. png_pos=(5, 5)
  201. png_size=(100, 60)
  202. png_prov_pos=(110, 5)
  203. png_prov_size=(100, 60)
  204. serviceName_pos=(215, 3)
  205. serviceName_size=(570, 25)
  206. serviceName_font=0
  207. eventName_pos=(215, 28)
  208. eventName_size=(570, 40)
  209. eventName_font=1
  210. durationTime_pos=(795, 16)
  211. durationTime_size=(180, 25)
  212. durationTime_font=2
  213. bar_pos=(795, 45)
  214. bar_size=(180, 10)
  215. elif config.plugins.vZapHistory.viewMode.value == 'menu':
  216. self['list'].l.setItemHeight(50)
  217. serviceName_pos=(5, 1)
  218. serviceName_size=(785, 24)
  219. serviceName_font=0
  220. eventName_pos=(5, 25)
  221. eventName_size=(785, 25)
  222. eventName_font=1
  223. durationTime_pos=(795, 5)
  224. durationTime_size=(180, 20)
  225. durationTime_font=2
  226. bar_pos=(795, 30)
  227. bar_size=(180, 10)
  228.  
  229. elif screenWidth == 1280:
  230. if config.plugins.vZapHistory.viewMode.value == 'picons':
  231. self['list'].l.setItemHeight(61)
  232. png_pos=(3, 3)
  233. png_size=(90, 54)
  234. serviceName_pos=(100, 2)
  235. serviceName_size=(971, 21)
  236. serviceName_font=1
  237. eventName_pos=(100, 20)
  238. eventName_size=(971, 40)
  239. eventName_font=2
  240. durationTime_pos=(1076, 10)
  241. durationTime_size=(181, 20)
  242. durationTime_font=3
  243. bar_pos=(1076, 33)
  244. bar_size=(181, 6)
  245. elif config.plugins.vZapHistory.viewMode.value == 'picons_prov':
  246. self['list'].l.setItemHeight(61)
  247. png_prov_pos=(3, 3)
  248. png_prov_size=(90, 54)
  249. png_pos=(99, 3)
  250. png_size=(90, 54)
  251. serviceName_pos=(192, 2)
  252. serviceName_size=(879, 21)
  253. serviceName_font=1
  254. eventName_pos=(192, 20)
  255. eventName_size=(879, 40)
  256. eventName_font=2
  257. durationTime_pos=(1076, 10)
  258. durationTime_size=(181, 20)
  259. durationTime_font=3
  260. bar_pos=(1076, 33)
  261. bar_size=(181, 6)
  262. elif config.plugins.vZapHistory.viewMode.value == 'picons_prov_sat':
  263. self['list'].l.setItemHeight(61)
  264. png_prov_sat_pos=(3, 3)
  265. png_prov_sat_size=(90, 54)
  266. png_prov_pos=(98, 3)
  267. png_prov_size=(90, 54)
  268. png_pos=(193, 3)
  269. png_size=(90, 54)
  270. serviceName_pos=(288, 2)
  271. serviceName_size=(783, 21)
  272. serviceName_font=1
  273. eventName_pos=(288, 20)
  274. eventName_size=(783, 40)
  275. eventName_font=2
  276. durationTime_pos=(1076, 10)
  277. durationTime_size=(181, 20)
  278. durationTime_font=3
  279. bar_pos=(1076, 33)
  280. bar_size=(181, 6)
  281. elif config.plugins.vZapHistory.viewMode.value == 'menu':
  282. self['list'].l.setItemHeight(61)
  283. serviceName_pos=(5, 2)
  284. serviceName_size=(1066, 21)
  285. serviceName_font=1
  286. eventName_pos=(5, 20)
  287. eventName_size=(1066, 40)
  288. eventName_font=2
  289. durationTime_pos=(1076, 10)
  290. durationTime_size=(181, 20)
  291. durationTime_font=3
  292. bar_pos=(1076, 33)
  293. bar_size=(181, 6)
  294.  
  295. else:
  296. self['list'].l.setItemHeight(50)
  297. png_pos=(0, 0)
  298. png_size=(1, 1)
  299. serviceName_pos=(10, 2)
  300. serviceName_size=(360, 18)
  301. serviceName_font=1
  302. eventName_pos=(10, 20)
  303. eventName_size=(360, 30)
  304. eventName_font=2
  305. durationTime_pos=(380, 15)
  306. durationTime_size=(140, 25)
  307. durationTime_font=2
  308. bar_pos=(380, 32)
  309. bar_size=(140, 8)
  310.  
  311. if 'picons' in config.plugins.vZapHistory.viewMode.value:
  312. res.append(MultiContentEntryPixmapAlphaBlend(pos=png_pos, size=png_size, flags = BT_SCALE, png=png))
  313. if 'picons_prov' in config.plugins.vZapHistory.viewMode.value:
  314. res.append(MultiContentEntryPixmapAlphaBlend(pos=png_prov_pos, size=png_prov_size, flags = BT_SCALE, png=png_prov))
  315. res.append(MultiContentEntryText(pos=serviceName_pos, size=serviceName_size, font=serviceName_font, flags=lasflags, text=serviceName, color=namecolor, color_sel=namecolor_sel))
  316. res.append(MultiContentEntryText(pos=eventName_pos, size=eventName_size, font=eventName_font, flags=lasflags | RT_VALIGN_CENTER | RT_WRAP, text=eventName, color=eventcolor, color_sel=eventcolor_sel))
  317. res.append(MultiContentEntryText(pos=durationTime_pos, size=durationTime_size, font=durationTime_font, flags=lasflags, text=durationTime, color=duratcolor, color_sel=duratcolor_sel))
  318. if 'picons_prov_sat' in config.plugins.vZapHistory.viewMode.value:
  319. res.append(MultiContentEntryPixmapAlphaBlend(pos=png_prov_sat_pos, size=png_prov_sat_size, flags = BT_SCALE, png=png_prov_sat))
  320. res.append(MultiContentEntryText(pos=serviceName_pos, size=serviceName_size, font=serviceName_font, flags=lasflags, text=serviceName, color=namecolor, color_sel=namecolor_sel))
  321. res.append(MultiContentEntryText(pos=eventName_pos, size=eventName_size, font=eventName_font, flags=lasflags | RT_VALIGN_CENTER | RT_WRAP, text=eventName, color=eventcolor, color_sel=eventcolor_sel))
  322. res.append(MultiContentEntryText(pos=durationTime_pos, size=durationTime_size, font=durationTime_font, flags=lasflags, text=durationTime, color=duratcolor, color_sel=duratcolor_sel))
  323. if bar != 0:
  324. res.append(MultiContentEntryProgress(pos=bar_pos, size=bar_size, percent=bar, borderWidth=1, foreColor=barcolor, foreColorSelected=barcolor_sel))
  325. return res
  326.  
  327. class vZapHistory(Screen, ProtectedScreen):
  328. def __init__(self, session, servicelist):
  329. Screen.__init__(self, session)
  330. ProtectedScreen.__init__(self)
  331. if screenWidth and screenWidth == 1280:
  332. self.skin = skin_hd
  333. elif screenWidth and screenWidth == 1920:
  334. self.skin = skin_fhd
  335. else:
  336. self.skin = skin_sd
  337. self.session = session
  338. self.servicelist = servicelist or Screens.InfoBar.InfoBar.instance.servicelist
  339. self.serviceHandler = eServiceCenter.getInstance()
  340. self.allowChanges = True
  341. self.zapDown = False
  342. self.time = 3
  343. self['list'] = vZapHistoryBrowserList([])
  344. self['key_green'] = Label(_('Переключить'))
  345. self['key_red'] = Label(_('Очистить'))
  346. self['key_yellow'] = Label(_('Удалить'))
  347. self['key_blue'] = Label(_('Настройки'))
  348. self.setTitle(_("История переключения каналов"))
  349. self['actions'] = ActionMap(['OkCancelActions', 'ColorActions', 'DirectionActions'],
  350. {'cancel': self.cancel,
  351. 'left': self.keyLeft,
  352. 'right': self.keyRight,
  353. 'up': self.keyUp,
  354. 'down': self.keyDown,
  355. 'ok': self.zapAndClose,
  356. 'blue': self.config,
  357. 'green': self.zap,
  358. 'yellow': self.delete,
  359. 'red': self.clear}, -1)
  360. self.onLayoutFinish.append(self.buildList)
  361. self.timerAutoZap = eTimer()
  362. self.timerAutoZap.callback.append(self.zap)
  363.  
  364. def cancel(self):
  365. self.timerAutoZap.stop()
  366. self.close()
  367.  
  368. def findPicon(self, serviceName):
  369. try:
  370. if '::' in serviceName:
  371. serviceName = serviceName.split('::')[0] + ':'
  372. except:
  373. pass
  374. serviceName = serviceName.toString()
  375. serviceName = '_'.join(serviceName.split(':', 10)[:10])
  376. searchPaths = ['/media/hdd/picon/', '/media/usb/picon/', '/usr/share/enigma2/picon/', '/media/sda1/picon/', '/media/sdb1/picon/']
  377. for path in searchPaths:
  378. pngname = path + serviceName + '.png'
  379. if fileExists(pngname):
  380. return pngname
  381. pngname = path + 'picon_default.png'
  382. if fileExists(pngname):
  383. return pngname
  384. pngname = resolveFilename(SCOPE_CURRENT_SKIN, 'picon_default.png')
  385. if fileExists(pngname):
  386. return pngname
  387. else:
  388. return resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/picon_default.png')
  389.  
  390. def findPiconprov(self, service):
  391. name = self.getProviderName(service)
  392. serviceName = name.upper()
  393. searchPaths = ['/media/hdd/piconProv/', '/media/usb/piconProv/', '/usr/share/enigma2/piconProv/', '/media/sda1/piconProv/', '/media/sdb1/piconProv/']
  394. for path in searchPaths:
  395. pngname = path + serviceName + '.png'
  396. if fileExists(pngname):
  397. return pngname
  398. pngname = path + 'picon_default.png'
  399. if fileExists(pngname):
  400. return pngname
  401. pngname = resolveFilename(SCOPE_CURRENT_SKIN, 'picon_default.png')
  402. if fileExists(pngname):
  403. return pngname
  404. else:
  405. return resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/picon_default.png')
  406.  
  407. def findPiconprovsat(self, service):
  408. name = self.getProviderName(service)
  409. serviceName = name.upper()
  410. searchPaths = ['/media/hdd/piconProv/', '/media/usb/piconProv/', '/usr/share/enigma2/piconProv/', '/media/sda1/piconProv/', '/media/sdb1/piconProv/']
  411. for path in searchPaths:
  412. pngname = path + serviceName + '.png'
  413. if fileExists(pngname):
  414. return pngname
  415. pngname = path + 'picon_default.png'
  416. if fileExists(pngname):
  417. return pngname
  418. pngname = resolveFilename(SCOPE_CURRENT_SKIN, 'picon_default.png')
  419. if fileExists(pngname):
  420. return pngname
  421. else:
  422. return resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/picon_default.png')
  423.  
  424. def findPiconprovsat(self, service):
  425. name = self.getProviderName(service)
  426. serviceName = name.upper()
  427. searchPaths = ['/media/hdd/piconProv/', '/media/usb/piconProv/', '/usr/share/enigma2/piconProv/', '/media/sda1/piconProv/', '/media/sdb1/piconProv/']
  428. for path in searchPaths:
  429. pngname = path + serviceName + '.png'
  430. if fileExists(pngname):
  431. return pngname
  432. pngname = path + 'picon_default.png'
  433. if fileExists(pngname):
  434. return pngname
  435. pngname = resolveFilename(SCOPE_CURRENT_SKIN, 'picon_default.png')
  436. if fileExists(pngname):
  437. return pngname
  438. else:
  439. return resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/picon_default.png')
  440.  
  441. def getProviderName(self, ref):
  442. if isinstance(ref, eServiceReference):
  443. from Screens.ChannelSelection import service_types_radio, service_types_tv
  444. typestr = ref.getData(0) in (2,10) and service_types_radio or service_types_tv
  445. pos = typestr.rfind(':')
  446. rootstr = '%s (channelID == %08x%04x%04x) && %s FROM PROVIDERS ORDER BY name' %(typestr[:pos+1],ref.getUnsignedData(4),ref.getUnsignedData(2),ref.getUnsignedData(3),typestr[pos+1:])
  447. provider_root = eServiceReference(rootstr)
  448. serviceHandler = eServiceCenter.getInstance()
  449. providerlist = serviceHandler.list(provider_root)
  450. if not providerlist is None:
  451. while True:
  452. provider = providerlist.getNext()
  453. if not provider.valid(): break
  454. if provider.flags & eServiceReference.isDirectory:
  455. servicelist = serviceHandler.list(provider)
  456. if not servicelist is None:
  457. while True:
  458. service = servicelist.getNext()
  459. if not service.valid(): break
  460. if service == ref:
  461. info = serviceHandler.info(provider)
  462. return info and info.getName(provider) or "Unknown"
  463. return ""
  464.  
  465. def buildList(self):
  466. prov = ""
  467. list = []
  468. for x in self.servicelist.history:
  469. if len(x) == 2:
  470. ref = x[1]
  471. else:
  472. ref = x[2]
  473. png = loadPNG(self.findPicon(ref))
  474. png_prov = loadPNG(self.findPiconprov(ref))
  475. png_prov_sat = loadPNG(self.findPiconprovsat(ref))
  476. info = self.serviceHandler.info(ref)
  477. if info:
  478. name = info.getName(ref).replace('\xc2\x86', '').replace('\xc2\x87', '')
  479. event = info.getEvent(ref)
  480. if event is not None:
  481. eventName = event.getEventName()
  482. if eventName is None:
  483. eventName = ''
  484. else:
  485. eventName = eventName.replace('(18+)', '').replace('18+', '').replace('(16+)', '').replace('16+', '').replace('(12+)', '').replace('12+', '').replace('(7+)', '').replace('7+', '').replace('(6+)', '').replace('6+', '').replace('(0+)', '').replace('0+', '')
  486. try:
  487. begin = event.getBeginTime()
  488. if begin is not None:
  489. end = begin + event.getDuration()
  490. remaining = (end - int(time())) / 60
  491. prefix = ''
  492. if remaining > 0:
  493. prefix = "+"
  494. local_begin = localtime(begin)
  495. local_end = localtime(end)
  496. bar = 0
  497. perc = ''
  498. i = (100 * (int(time()) - begin)) / event.getDuration()
  499. if i < 101:
  500. bar = i
  501. durationTime = _("%02d:%02d - %02d:%02d ( %s%04d мин. )") % (local_begin[3],local_begin[4],local_end[3],local_end[4],prefix, remaining)
  502. except:
  503. durationTime = ''
  504. else:
  505. eventName = ''
  506. durationTime = ''
  507. descriptionName = ''
  508. bar = 0
  509. else:
  510. name = 'N/A'
  511. eventName = ''
  512. durationTime = ''
  513. descriptionName = ''
  514. bar = 0
  515. list.append(vZapHistoryBrowserListEntry(self, name, eventName, durationTime, bar, png, png_prov, png_prov_sat))
  516. list.reverse()
  517. self['list'].setList(list)
  518.  
  519. def keyRight(self):
  520. self.zapDown = False
  521. self.timerAutoZap.stop()
  522. self['list'].pageDown()
  523. if config.plugins.vZapHistory.autoZap.value:
  524. self.timerAutoZap.startLongTimer(self.time)
  525.  
  526. def keyLeft(self):
  527. self.zapDown = False
  528. self.timerAutoZap.stop()
  529. self['list'].pageUp()
  530. if config.plugins.vZapHistory.autoZap.value:
  531. self.timerAutoZap.stop()
  532. self.timerAutoZap.startLongTimer(self.time)
  533.  
  534. def keyUp(self):
  535. self.zapDown = False
  536. self.timerAutoZap.stop()
  537. pos = self['list'].getSelectionIndex()
  538. lon = len(self['list'].list)
  539. if pos == 0 and lon > 1:
  540. self['list'].moveToIndex(lon - 1)
  541. else:
  542. self['list'].up()
  543. if pos == 1:
  544. return
  545. if config.plugins.vZapHistory.autoZap.value:
  546. self.timerAutoZap.startLongTimer(self.time)
  547.  
  548. def keyDown(self):
  549. self.zapDown = True
  550. self.timerAutoZap.stop()
  551. pos = self['list'].getSelectionIndex()
  552. lon = len(self['list'].list)
  553. if pos == lon - 1 and lon > 1:
  554. self['list'].moveToIndex(0)
  555. else:
  556. self['list'].down()
  557. if config.plugins.vZapHistory.autoZap.value:
  558. self.timerAutoZap.startLongTimer(self.time)
  559.  
  560. def zapAndClose(self):
  561. self.zapDown = False
  562. self.zap()
  563. self.close()
  564.  
  565. def zap(self):
  566. self.timerAutoZap.stop()
  567. length = len(self.servicelist.history)
  568. if length > 0:
  569. self.servicelist.history_pos = length - self['list'].getSelectionIndex() - 1
  570. self.servicelist.setHistoryPath()
  571. idx = length - self['list'].getSelectionIndex() - 1
  572. value_idx = self.servicelist.history[idx]
  573. del self.servicelist.history[idx]
  574. self.servicelist.history.append(value_idx)
  575. self.time = 2
  576. if self.zapDown:
  577. self.time = 5
  578. self.keyDown()
  579. self.buildList()
  580.  
  581. def clear(self):
  582. self.timerAutoZap.stop()
  583. if self.allowChanges:
  584. for i in range(0, len(self.servicelist.history)):
  585. del self.servicelist.history[0]
  586. self.buildList()
  587. self.servicelist.history_pos = 0
  588.  
  589. def delete(self):
  590. self.timerAutoZap.stop()
  591. if self.allowChanges:
  592. length = len(self.servicelist.history)
  593. if length > 0:
  594. idx = length - self['list'].getSelectionIndex() - 1
  595. del self.servicelist.history[idx]
  596. self.buildList()
  597. currRef = self.session.nav.getCurrentlyPlayingServiceReference()
  598. idx = 0
  599. for x in self.servicelist.history:
  600. if len(x) == 2:
  601. ref = x[1]
  602. else:
  603. ref = x[2]
  604. if ref == currRef:
  605. self.servicelist.history_pos = idx
  606. break
  607. else:
  608. idx += 1
  609.  
  610. def config(self):
  611. self.timerAutoZap.stop()
  612. self.session.openWithCallback(self.buildList, vZapHistoryConf)
  613.  
  614. def isProtected(self):
  615. return config.ParentalControl.servicepinactive.value and config.ParentalControl.configured.value
  616.  
  617. def pinEntered(self, result):
  618. if result is None:
  619. self.allowChanges = False
  620. elif not result:
  621. self.allowChanges = False
  622. else:
  623. self.allowChanges = True
  624.  
  625. class vZapHistoryConf(ConfigListScreen, Screen):
  626.  
  627. def __init__(self, session):
  628. Screen.__init__(self, session)
  629. self.session = session
  630. if screenWidth == 1920:
  631. self.skin = skinConf_fhd
  632. elif screenWidth == 1280:
  633. self.skin = skinConf_hd
  634. else:
  635. self.skin = skinConf_sd
  636. self['key_red'] = Label(_('Cancel'))
  637. self['key_green'] = Label( _('Save'))
  638. self.setTitle(_('Настройки'))
  639. ConfigListScreen.__init__(self, [getConfigListEntry(_('Разрешить историю переключений:'), config.plugins.vZapHistory.enable),
  640. getConfigListEntry(_('Режим показа:'), config.plugins.vZapHistory.viewMode),
  641. getConfigListEntry(_('Выравнивание списка:'), config.plugins.vZapHistory.alignment),
  642. getConfigListEntry(_('Максимум записей в истории:'), config.plugins.vZapHistory.maxEntries),
  643. getConfigListEntry(_('Автопереключение при перемещении в списке:'), config.plugins.vZapHistory.autoZap),
  644. getConfigListEntry(_('Цвет названия канала:'), config.plugins.vZapHistory.namecolor),
  645. getConfigListEntry(_('Цвет названия передачи:'), config.plugins.vZapHistory.eventcolor),
  646. getConfigListEntry(_('Цвет времени передачи:'), config.plugins.vZapHistory.duratcolor),
  647. getConfigListEntry(_('Цвет прогресс-бара:'), config.plugins.vZapHistory.barcolor),
  648. getConfigListEntry(_('Цвет названия канала под курсором:'), config.plugins.vZapHistory.namecolor_sel),
  649. getConfigListEntry(_('Цвет названия передачи под курсором:'), config.plugins.vZapHistory.eventcolor_sel),
  650. getConfigListEntry(_('Цвет времени передачи под курсором:'), config.plugins.vZapHistory.duratcolor_sel),
  651. getConfigListEntry(_('Цвет прогресс-бара под курсором:'), config.plugins.vZapHistory.barcolor_sel)])
  652. self['actions'] = ActionMap(['OkCancelActions', 'ColorActions'],
  653. {'ok': self.save, 'green': self.save,
  654. 'cancel': self.exit, 'red': self.exit}, -2)
  655.  
  656. def save(self):
  657. for x in self['config'].list:
  658. x[1].save()
  659. self.close()
  660.  
  661. def exit(self):
  662. for x in self['config'].list:
  663. x[1].cancel()
  664. self.close()
  665.  
  666. def main(session, servicelist = None, **kwargs):
  667. session.open(vZapHistory, servicelist)
  668.  
  669. def Plugins(**kwargs):
  670. return PluginDescriptor(name=_('История переключения каналов'), description=_("Show the 'Channel Switching History' on the screen"), where=PluginDescriptor.WHERE_PLUGINMENU, icon = 'vzh.png', fnc=main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement