Advertisement
SharkyEXE

Untitled

Dec 27th, 2018
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # Не удалять эту строку - для правильного определения кодировки " 65001 (UTF-8) без BOM "
  3. from Components.config import config, ConfigNumber, ConfigSubsection, ConfigYesNo
  4. from Plugins.Plugin import PluginDescriptor
  5.  
  6. from . import _
  7.  
  8.  
  9. config.plugins.Animation = ConfigSubsection()
  10. config.plugins.Animation.enabled = ConfigYesNo(default=False)
  11. config.plugins.Animation.delay = ConfigNumber(default=500)
  12. config.plugins.Animation.aspect = ConfigYesNo(default=True)
  13.  
  14.  
  15. ##From Animation.py##
  16.  
  17. from os.path import exists
  18.  
  19. from enigma import ePicLoad, eTimer, getDesktop
  20. from Components.config import config
  21. from Components.Pixmap import Pixmap
  22. from Screens.Screen import Screen
  23. from Tools.Directories import resolveFilename, SCOPE_PLUGINS
  24.  
  25.  
  26. class AnimationScreen(Screen):
  27. def __init__(self, session):
  28. Screen.__init__(self, session)
  29. self.screenWidth = getDesktop(0).size().width()
  30. self.screenHeight = getDesktop(0).size().height()
  31. self.skin = """<screen position="fill" zPosition="-7" flags="wfNoBorder" backgroundColor="#ffffffff">
  32. <widget name="Animation" position="0,0" size="%s,%s" transparent="1"/>
  33. </screen>""" % (self.screenWidth, self.screenHeight)
  34. self['Animation'] = Pixmap()
  35. self['Animation'].hide()
  36. self.pixmapCount = 0
  37. self.picload = None
  38. self.pixmaps = {}
  39. if config.plugins.Animation.aspect.value:
  40. from Components.AVSwitch import AVSwitch
  41. self.sc = AVSwitch().getFramebufferScale()
  42. else:
  43. self.sc = [0, 0]
  44. self.pixmapTaimer = eTimer()
  45. self.pixmapTaimer.timeout.callback.append(self.updatePixmaps)
  46. self.animeTimer = eTimer()
  47. self.animeTimer.callback.append(self.startAnimation)
  48. self.onLayoutFinish.append(self.decodeAllPixmaps)
  49.  
  50. def decodeAllPixmaps(self):
  51. animePixmap = resolveFilename(SCOPE_PLUGINS,
  52. 'Extensions/Animation/anime/anime-%02d.png' % self.pixmapCount)
  53. if exists(animePixmap):
  54. self.decodePixmap(animePixmap)
  55. else:
  56. if self.pixmapCount == 0:
  57. print '[AnimationScreen] ERROR: Pixmaps not fund', animePixmap
  58. self.close()
  59. else:
  60. self.pixmapCount = 0
  61. self['Animation'].show()
  62. self.animeTimer.start(config.plugins.Animation.delay.value, False)
  63.  
  64. def decodePixmap(self, animePixmap):
  65. self.picload = ePicLoad()
  66. self.picload.PictureData.get().append(self.finishDecode)
  67. self.picload.setPara((
  68. self.screenWidth, self.screenHeight,
  69. self.sc[0], self.sc[1], False, 1, '#ff000000'))
  70. self.picload.startDecode(animePixmap)
  71.  
  72. def finishDecode(self, picInfo=None):
  73. ptr = self.picload.getData()
  74. if ptr:
  75. self.pixmaps[self.pixmapCount] = ptr
  76. self.picload = None
  77. self.pixmapTaimer.start(1)
  78.  
  79. def updatePixmaps(self):
  80. self.pixmapTaimer.stop()
  81. if self.picload is not None:
  82. self.pixmapTaimer.start(1)
  83. else:
  84. self.pixmapCount += 1
  85. self.decodeAllPixmaps()
  86.  
  87. def startAnimation(self):
  88. self['Animation'].instance.setPixmap(self.pixmaps[self.pixmapCount].__deref__())
  89. self.pixmapCount += 1
  90. if self.pixmapCount == len(self.pixmaps):
  91. self.pixmapCount = 0
  92.  
  93.  
  94. class Animation():
  95. def __init__(self):
  96. self.dialog = None
  97.  
  98. def startSession(self, session):
  99. self.dialog = session.instantiateDialog(AnimationScreen)
  100. self.dialog.show()
  101.  
  102. def stopSession(self, session):
  103. session.deleteDialog(self.dialog)
  104. self.dialog = None
  105.  
  106.  
  107. AnimationSession = Animation()
  108.  
  109.  
  110. ##From AnimationSetup.py##
  111.  
  112. from Components.ActionMap import ActionMap
  113. from Components.config import config, getConfigListEntry
  114. from Components.ConfigList import ConfigListScreen
  115. from Components.Label import Label
  116. from Components.Sources.StaticText import StaticText
  117. from Screens.Screen import Screen
  118.  
  119. from . import _
  120. #from Animation import AnimationSession
  121.  
  122.  
  123. class AnimationSetup(ConfigListScreen, Screen):
  124. def __init__(self, session):
  125. Screen.__init__(self, session)
  126. self.session = session
  127. self.skinName = ['AnimationSetup', 'Setup']
  128. self['key_red'] = StaticText(_('Cancel'))
  129. self['key_green'] = StaticText(_('Ok'))
  130. self['description'] = Label('')
  131. self['setupActions'] = ActionMap(['SetupActions', 'ColorActions'],
  132. {
  133. 'cancel': self.keyCancel,
  134. 'red': self.keyCancel,
  135. 'ok': self.ok,
  136. 'green': self.ok
  137. }, -2)
  138. configlist = []
  139. ConfigListScreen.__init__(self, configlist, session=session)
  140. configlist.append(getConfigListEntry(_('Start animation'),
  141. config.plugins.Animation.enabled,
  142. _('Start showing an animation.\nIt will work also after restart.')))
  143. configlist.append(getConfigListEntry(_('Dealey between animations'),
  144. config.plugins.Animation.delay,
  145. _('How long you will see one animated picture.\nAnimation will be faster at less value.')))
  146. configlist.append(getConfigListEntry(_('Keep aspect ratio'),
  147. config.plugins.Animation.aspect,
  148. _('Keep animation picture aspect ratio when scale it over the whole screen.')))
  149. self['config'].list = configlist
  150. self['config'].l.setList(configlist)
  151. self.setTitle(_('Animation setup'))
  152.  
  153. def ok(self):
  154. if AnimationSession.dialog is not None:
  155. AnimationSession.stopSession(self.session)
  156. if config.plugins.Animation.delay.value < 1:
  157. config.plugins.Animation.delay.value = 1
  158. if config.plugins.Animation.enabled.value:
  159. AnimationSession.startSession(self.session)
  160. self.keySave()
  161.  
  162.  
  163. #####################
  164.  
  165.  
  166. def sessionstart(reason, **kwargs):
  167. if reason == 0:
  168. #from Animation import AnimationSession
  169. AnimationSession.startSession(kwargs['session'])
  170.  
  171.  
  172. def main(session, **kwargs):
  173. #from AnimationSetup import AnimationSetup
  174. session.open(AnimationSetup)
  175.  
  176.  
  177. def Plugins(**kwargs):
  178. plugin = [PluginDescriptor(
  179. name=_('Snow'),
  180. description=_('Show the "Snow" on the screen'),
  181. where=[PluginDescriptor.WHERE_PLUGINMENU],
  182. #PluginDescriptor.WHERE_EXTENSIONSMENU],
  183. icon='plugin.png',
  184. fnc=main)]
  185. if config.plugins.Animation.enabled.value:
  186. plugin.append(PluginDescriptor(
  187. where=[PluginDescriptor.WHERE_SESSIONSTART],
  188. fnc=sessionstart))
  189. return plugin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement