fix typo
[enigma2-plugins.git] / easymedia / src / plugin.py
1 #######################################################################
2 #
3 #    EasyMedia for Dreambox-Enigma2
4 #    Coded by Vali (c)2010
5 #    Support: www.dreambox-tools.info
6 #
7 #
8 #  This plugin is licensed under the Creative Commons 
9 #  Attribution-NonCommercial-ShareAlike 3.0 Unported License.
10 #  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
11 #  or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12 #
13 #  Alternatively, this plugin may be distributed and executed on hardware which
14 #  is licensed by Dream Multimedia GmbH.
15 #
16 #
17 #  This plugin is NOT free software. It is open source, you are allowed to
18 #  modify it (if you keep the license), but it may not be commercially 
19 #  distributed other than under the conditions noted above.
20 #
21 #
22 #######################################################################
23
24
25
26 from Screens.Screen import Screen
27 from Screens.MessageBox import MessageBox
28 from Screens.InfoBarGenerics import InfoBarPlugins
29 from Screens.InfoBar import InfoBar
30 from Plugins.Plugin import PluginDescriptor
31 from Components.ActionMap import ActionMap
32 from Components.MenuList import MenuList
33 from Tools.Directories import fileExists
34 from Tools.LoadPixmap import LoadPixmap
35 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont, getDesktop
36
37
38
39 EMbaseInfoBarPlugins__init__ = None
40 EMStartOnlyOneTime = False
41 EMsession = None
42 InfoBar_instance = None
43
44
45
46 def Plugins(**kwargs):
47         return [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = EasyMediaAutostart),
48                         PluginDescriptor(name="EasyMedia", description=_("Not easy way to start EasyMedia"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc=notEasy),]
49
50
51
52 def EasyMediaAutostart(reason, **kwargs):
53         global EMbaseInfoBarPlugins__init__
54         if "session" in kwargs:
55                 global EMsession
56                 EMsession = kwargs["session"]
57                 if EMbaseInfoBarPlugins__init__ is None:
58                         EMbaseInfoBarPlugins__init__ = InfoBarPlugins.__init__
59                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
60                 InfoBarPlugins.pvr = pvr
61
62
63
64 def InfoBarPlugins__init__(self):
65         global EMStartOnlyOneTime
66         if not EMStartOnlyOneTime: 
67                 EMStartOnlyOneTime = True
68                 global InfoBar_instance
69                 InfoBar_instance = self
70                 self["EasyMediaActions"] = ActionMap(["EasyMediaActions"],
71                         {"video_but": self.pvr}, -1)
72         else:
73                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
74                 InfoBarPlugins.pvr = None
75         EMbaseInfoBarPlugins__init__(self)
76
77
78
79 def pvr(self):
80         self.session.openWithCallback(MPcallbackFunc, EasyMedia)
81
82
83
84 def notEasy(session, **kwargs):
85         session.openWithCallback(MPcallbackFunc, EasyMedia)
86
87
88
89 def MPanelEntryComponent(key, text):
90         res = [ text ]
91         res.append((eListboxPythonMultiContent.TYPE_TEXT, 160, 15, 300, 60, 0, RT_HALIGN_LEFT, text[0]))
92         png = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + key + ".png")
93         if png is not None:
94                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 30, 5, 100, 50, png))
95         return res
96
97
98
99 class MPanelList(MenuList):
100         def __init__(self, list, selection = 0, enableWrapAround=True):
101                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
102                 self.l.setFont(0, gFont("Regular", 24))
103                 self.l.setItemHeight(60)
104                 self.selection = selection
105         def postWidgetCreate(self, instance):
106                 MenuList.postWidgetCreate(self, instance)
107                 self.moveToIndex(self.selection)
108
109
110
111 class EasyMedia(Screen):
112         sz_w = getDesktop(0).size().width()
113         if sz_w > 1100:
114                 skin = """
115                 <screen flags="wfNoBorder" position="0,0" size="450,720" title="Easy Media">
116                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
117                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,576" size="450,145"/>
118                         <widget name="list" position="60,30" size="350,660" scrollbarMode="showNever" transparent="1" zPosition="2"/>
119                 </screen>"""
120         elif sz_w > 1000:
121                 skin = """
122                 <screen flags="wfNoBorder" position="-20,0" size="450,576" title="Easy Media">
123                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
124                         <widget name="list" position="70,48" size="320,480" scrollbarMode="showNever" transparent="1" zPosition="2"/>
125                 </screen>"""
126         else:
127                 skin = """
128                 <screen position="center,center" size="320,440" title="Easy Media">
129                         <widget name="list" position="10,10" size="300,420" scrollbarMode="showOnDemand" />
130                 </screen>"""
131         def __init__(self, session):
132                 Screen.__init__(self, session)
133                 self.list = []
134                 self.__keys = [ "movies", "pictures", "music", "weather", "files" ]
135                 MPaskList = [(_("Movies"), "PLAYMOVIES"),(_("Pictures"), "PICTURES"),(_("Music"), "MUSIC"),(_("Weather"), "WEATHER"),(_("Files"), "FILES")]
136                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
137                         self.__keys.append("dvd")
138                         MPaskList.append((_("DVD Player"), "DVD"))
139                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
140                         self.__keys.append("shoutcast")
141                         MPaskList.append((_("SHOUTcast"), "SHOUTCAST"))
142                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
143                         self.__keys.append("idream")
144                         MPaskList.append((_("iDream"), "IDREAM"))
145                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
146                         self.__keys.append("mytube")
147                         MPaskList.append((_("MyTube Player"), "MYTUBE"))
148                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
149                         self.__keys.append("vlc")
150                         MPaskList.append((_("VLC Player"), "VLC"))
151                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
152                         self.__keys.append("zdf")
153                         MPaskList.append((_("ZDFmediathek"), "ZDF"))
154                 self.keymap = {}
155                 pos = 0
156                 for x in MPaskList:
157                         strpos = str(self.__keys[pos])
158                         self.list.append(MPanelEntryComponent(key = strpos, text = x))
159                         if self.__keys[pos] != "":
160                                 self.keymap[self.__keys[pos]] = MPaskList[pos]
161                         pos += 1
162                 self["list"] = MPanelList(list = self.list, selection = 0)
163                 self["actions"] = ActionMap(["WizardActions", "EPGSelectActions"],
164                 {
165                         "ok": self.go,
166                         "back": self.cancel,
167                         "showMovies": self.cancel
168                 }, -1)
169
170         def cancel(self):
171                 self.close(None)
172
173         def go(self):
174                 cursel = self["list"].l.getCurrentSelection()
175                 if cursel:
176                         self.goEntry(cursel[0])
177                 else:
178                         self.cancel()
179
180         def goEntry(self, entry):
181                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
182                         arg = self["list"].l.getCurrentSelection()[0]
183                         entry[2](arg)
184                 else:
185                         self.close(entry)
186
187
188
189 def MPcallbackFunc(answer):
190         answer = answer and answer[1]
191         if answer == "PLAYMOVIES":
192                 if InfoBar_instance:
193                         InfoBar_instance.showMovies()
194         elif answer == "PICTURES":
195                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
196                         from Plugins.Extensions.PicturePlayer.plugin import picshow
197                         EMsession.open(picshow)
198                 else:
199                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
200         elif answer == "MUSIC":
201                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
202                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
203                         servicelist = None
204                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
205                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo"):
206                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
207                         EMsession.open(MediaPlayer)
208                 else:
209                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
210         elif answer == "FILES":
211                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Tuxcom/plugin.pyo"):
212                         from Plugins.Extensions.Tuxcom.plugin import TuxComStarter
213                         EMsession.open(TuxComStarter)
214                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo"):
215                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
216                         EMsession.open(DreamExplorerII)
217                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo"):
218                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
219                         EMsession.open(FilebrowserScreen)
220                 else:
221                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
222         elif answer == "WEATHER":
223                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
224                         from Plugins.Extensions.WeatherPlugin.plugin import WeatherPlugin
225                         EMsession.open(WeatherPlugin)
226                 else:
227                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
228         elif answer == "DVD":
229                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
230                         from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
231                         EMsession.open(DVDPlayer)
232                 else:
233                         EMsession.open(MessageBox, text = _('DVDPlayer Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
234         elif answer == "MYTUBE":
235                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
236                         from Plugins.Extensions.MyTube.plugin import *
237                         MyTubeMain(EMsession)
238                 else:
239                         EMsession.open(MessageBox, text = _('MyTube Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
240         elif answer == "SHOUTCAST":
241                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
242                         from Plugins.Extensions.SHOUTcast.plugin import SHOUTcastWidget
243                         EMsession.open(SHOUTcastWidget)
244                 else:
245                         EMsession.open(MessageBox, text = _('SHOUTcast Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
246         elif answer == "ZDF":
247                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
248                         from Plugins.Extensions.ZDFMediathek.plugin import ZDFMediathek
249                         EMsession.open(ZDFMediathek)
250                 else:
251                         EMsession.open(MessageBox, text = _('ZDFmediathek Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
252         elif answer == "VLC":
253                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
254                         from Plugins.Extensions.VlcPlayer.plugin import *
255                         main(EMsession)
256                 else:
257                         EMsession.open(MessageBox, text = _('VLC Player is not installed!'), type = MessageBox.TYPE_ERROR)
258         elif answer == "IDREAM":
259                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
260                         from Plugins.Extensions.MerlinMusicPlayer.plugin import iDreamMerlin
261                         servicelist = None
262                         EMsession.open(iDreamMerlin, servicelist)
263                 else:
264                         EMsession.open(MessageBox, text = _('Merlin iDream is not installed!'), type = MessageBox.TYPE_ERROR)
265         
266
267