new pretty way to call showMovies
[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         global InfoBar_instance
67         InfoBar_instance = self
68         if not EMStartOnlyOneTime: 
69                 EMStartOnlyOneTime = True
70                 self["EasyMediaActions"] = ActionMap(["EasyMediaActions"],
71                         {"video_but": self.pvr}, -1)
72         else:
73                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
74                 InfoBarPlugins.green = None
75                 InfoBarPlugins.yellow = None
76                 InfoBarPlugins.red = None
77                 InfoBarPlugins.blue = None
78                 InfoBarPlugins.pvr = None
79                 InfoBarPlugins.radio = None
80         EMbaseInfoBarPlugins__init__(self)
81
82
83
84 def pvr(self):
85         self.session.openWithCallback(MPcallbackFunc, EasyMedia)
86
87
88
89 def notEasy(session, **kwargs):
90         session.openWithCallback(MPcallbackFunc, EasyMedia)
91
92
93
94 def MPanelEntryComponent(key, text):
95         res = [ text ]
96         res.append((eListboxPythonMultiContent.TYPE_TEXT, 160, 15, 300, 60, 0, RT_HALIGN_LEFT, text[0]))
97         png = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + key + ".png")
98         if png is not None:
99                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 30, 5, 100, 50, png))
100         return res
101
102
103
104 class MPanelList(MenuList):
105         def __init__(self, list, selection = 0, enableWrapAround=True):
106                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
107                 self.l.setFont(0, gFont("Regular", 24))
108                 self.l.setItemHeight(60)
109                 self.selection = selection
110         def postWidgetCreate(self, instance):
111                 MenuList.postWidgetCreate(self, instance)
112                 self.moveToIndex(self.selection)
113
114
115
116 class EasyMedia(Screen):
117         sz_w = getDesktop(0).size().width()
118         if sz_w > 1100:
119                 skin = """
120                 <screen flags="wfNoBorder" position="0,0" size="450,720" title="Easy Media">
121                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
122                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,576" size="450,145"/>
123                         <widget name="list" position="60,30" size="350,660" scrollbarMode="showNever" transparent="1" zPosition="2"/>
124                 </screen>"""
125         elif sz_w > 1000:
126                 skin = """
127                 <screen flags="wfNoBorder" position="-20,0" size="450,576" title="Easy Media">
128                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
129                         <widget name="list" position="70,48" size="320,480" scrollbarMode="showNever" transparent="1" zPosition="2"/>
130                 </screen>"""
131         else:
132                 skin = """
133                 <screen position="center,center" size="320,440" title="Easy Media">
134                         <widget name="list" position="10,10" size="300,420" scrollbarMode="showOnDemand" />
135                 </screen>"""
136         def __init__(self, session):
137                 Screen.__init__(self, session)
138                 self.list = []
139                 self.__keys = [ "movies", "pictures", "music", "weather", "files" ]
140                 MPaskList = [(_("Movies"), "PLAYMOVIES"),(_("Pictures"), "PICTURES"),(_("Music"), "MUSIC"),(_("Weather"), "WEATHER"),(_("Files"), "FILES")]
141                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
142                         self.__keys.append("dvd")
143                         MPaskList.append((_("DVD Player"), "DVD"))
144                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
145                         self.__keys.append("shoutcast")
146                         MPaskList.append((_("SHOUTcast"), "SHOUTCAST"))
147                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
148                         self.__keys.append("idream")
149                         MPaskList.append((_("iDream"), "IDREAM"))
150                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
151                         self.__keys.append("mytube")
152                         MPaskList.append((_("MyTube Player"), "MYTUBE"))
153                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
154                         self.__keys.append("vlc")
155                         MPaskList.append((_("VLC Player"), "VLC"))
156                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
157                         self.__keys.append("zdf")
158                         MPaskList.append((_("ZDFmediathek"), "ZDF"))
159                 self.keymap = {}
160                 pos = 0
161                 for x in MPaskList:
162                         strpos = str(self.__keys[pos])
163                         self.list.append(MPanelEntryComponent(key = strpos, text = x))
164                         if self.__keys[pos] != "":
165                                 self.keymap[self.__keys[pos]] = MPaskList[pos]
166                         pos += 1
167                 self["list"] = MPanelList(list = self.list, selection = 0)
168                 self["actions"] = ActionMap(["WizardActions", "EPGSelectActions"],
169                 {
170                         "ok": self.go,
171                         "back": self.cancel,
172                         "showMovies": self.cancel
173                 }, -1)
174
175         def cancel(self):
176                 self.close(None)
177
178         def go(self):
179                 cursel = self["list"].l.getCurrentSelection()
180                 if cursel:
181                         self.goEntry(cursel[0])
182                 else:
183                         self.cancel()
184
185         def goEntry(self, entry):
186                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
187                         arg = self["list"].l.getCurrentSelection()[0]
188                         entry[2](arg)
189                 else:
190                         self.close(entry)
191
192
193
194 def MPcallbackFunc(answer):
195         answer = answer and answer[1]
196         if answer == "PLAYMOVIES":
197                 if InfoBar_instance:
198                         InfoBar_instance.showMovies()
199         elif answer == "PICTURES":
200                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
201                         from Plugins.Extensions.PicturePlayer.plugin import picshow
202                         EMsession.open(picshow)
203                 else:
204                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
205         elif answer == "MUSIC":
206                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
207                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
208                         servicelist = None
209                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
210                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo"):
211                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
212                         EMsession.open(MediaPlayer)
213                 else:
214                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
215         elif answer == "FILES":
216                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Tuxcom/plugin.pyo"):
217                         from Plugins.Extensions.Tuxcom.plugin import TuxComStarter
218                         EMsession.open(TuxComStarter)
219                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo"):
220                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
221                         EMsession.open(DreamExplorerII)
222                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo"):
223                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
224                         EMsession.open(FilebrowserScreen)
225                 else:
226                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
227         elif answer == "WEATHER":
228                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
229                         from Plugins.Extensions.WeatherPlugin.plugin import WeatherPlugin
230                         EMsession.open(WeatherPlugin)
231                 else:
232                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
233         elif answer == "DVD":
234                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
235                         from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
236                         EMsession.open(DVDPlayer)
237                 else:
238                         EMsession.open(MessageBox, text = _('DVDPlayer Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
239         elif answer == "MYTUBE":
240                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
241                         from Plugins.Extensions.MyTube.plugin import *
242                         MyTubeMain(EMsession)
243                 else:
244                         EMsession.open(MessageBox, text = _('MyTube Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
245         elif answer == "SHOUTCAST":
246                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
247                         from Plugins.Extensions.SHOUTcast.plugin import SHOUTcastWidget
248                         EMsession.open(SHOUTcastWidget)
249                 else:
250                         EMsession.open(MessageBox, text = _('SHOUTcast Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
251         elif answer == "ZDF":
252                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
253                         from Plugins.Extensions.ZDFMediathek.plugin import ZDFMediathek
254                         EMsession.open(ZDFMediathek)
255                 else:
256                         EMsession.open(MessageBox, text = _('ZDFmediathek Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
257         elif answer == "VLC":
258                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
259                         from Plugins.Extensions.VlcPlayer.plugin import *
260                         main(EMsession)
261                 else:
262                         EMsession.open(MessageBox, text = _('VLC Player is not installed!'), type = MessageBox.TYPE_ERROR)
263         elif answer == "IDREAM":
264                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
265                         from Plugins.Extensions.MerlinMusicPlayer.plugin import iDreamMerlin
266                         servicelist = None
267                         EMsession.open(iDreamMerlin, servicelist)
268                 else:
269                         EMsession.open(MessageBox, text = _('Merlin iDream is not installed!'), type = MessageBox.TYPE_ERROR)
270         
271
272