EasyMedia first check in
[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
36
37
38
39 EMbaseInfoBarPlugins__init__ = None
40 EMStartOnlyOneTime = False
41 EMsession = None
42
43
44
45 def Plugins(**kwargs):
46         return [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = EasyMediaAutostart)]
47
48
49
50 def EasyMediaAutostart(reason, **kwargs):
51         global EMbaseInfoBarPlugins__init__
52         if "session" in kwargs:
53                 global EMsession
54                 EMsession = kwargs["session"]
55                 if EMbaseInfoBarPlugins__init__ is None:
56                         EMbaseInfoBarPlugins__init__ = InfoBarPlugins.__init__
57                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
58                 InfoBarPlugins.pvr = pvr
59
60
61
62 def InfoBarPlugins__init__(self):
63         global EMStartOnlyOneTime
64         if not EMStartOnlyOneTime: 
65                 EMStartOnlyOneTime = True
66                 self["EasyMediaActions"] = ActionMap(["EasyMediaActions"],
67                         {"video_but": self.pvr}, -1)
68         else:
69                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
70                 InfoBarPlugins.green = None
71                 InfoBarPlugins.yellow = None
72                 InfoBarPlugins.red = None
73                 InfoBarPlugins.blue = None
74                 InfoBarPlugins.pvr = None
75                 InfoBarPlugins.radio = None
76         EMbaseInfoBarPlugins__init__(self)
77
78
79
80 def pvr(self):
81         MPaskList = [(_("Movies"), "PLAYMOVIES"),
82                                 (_("Pictures"), "PICTURES"),
83                                 (_("Music"), "MUSIC"),
84                                 (_("Weather"), "WEATHER"),
85                                 (_("Files"), "FILES")]
86         self.session.openWithCallback(MPcallbackFunc, EasyMedia, list=MPaskList)
87
88
89
90 def MPanelEntryComponent(key, text):
91         res = [ text ]
92         res.append((eListboxPythonMultiContent.TYPE_TEXT, 160, 15, 300, 60, 0, RT_HALIGN_LEFT, text[0]))
93         png = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + key + ".png")
94         if png is not None:
95                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 30, 5, 100, 50, png))
96         return res
97
98
99
100 class MPanelList(MenuList):
101         def __init__(self, list, selection = 0, enableWrapAround=True):
102                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
103                 self.l.setFont(0, gFont("Regular", 24))
104                 self.l.setItemHeight(60)
105                 self.selection = selection
106         def postWidgetCreate(self, instance):
107                 MenuList.postWidgetCreate(self, instance)
108                 self.moveToIndex(self.selection)
109
110
111
112 class EasyMedia(Screen):
113         skin = """
114         <screen position="center,center" size="420,320" title="Easy Media">
115                 <widget name="list" position="10,10" size="400,300" scrollbarMode="showOnDemand" />
116         </screen>"""
117         def __init__(self, session, list = []):
118                 Screen.__init__(self, session)
119                 self.list = []
120                 self.__keys = [ "movies", "pictures", "music", "weather", "files" ] #+ (len(list) - 4) * [""]
121                 self.keymap = {}
122                 pos = 0
123                 for x in list:
124                         strpos = str(self.__keys[pos])
125                         self.list.append(MPanelEntryComponent(key = strpos, text = x))
126                         if self.__keys[pos] != "":
127                                 self.keymap[self.__keys[pos]] = list[pos]
128                         pos += 1
129                 self["list"] = MPanelList(list = self.list, selection = 0)
130                 self["actions"] = ActionMap(["WizardActions"],
131                 {
132                         "ok": self.go,
133                         "back": self.cancel
134                 }, -1)
135
136         def cancel(self):
137                 self.close(None)
138
139         def go(self):
140                 cursel = self["list"].l.getCurrentSelection()
141                 if cursel:
142                         self.goEntry(cursel[0])
143                 else:
144                         self.cancel()
145
146         def goEntry(self, entry):
147                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
148                         arg = self["list"].l.getCurrentSelection()[0]
149                         entry[2](arg)
150                 else:
151                         self.close(entry)
152
153
154
155 def MPcallbackFunc(answer):
156         answer = answer and answer[1]
157         if answer == "PLAYMOVIES":
158                 if InfoBar and InfoBar.instance:
159                         InfoBar.showMovies(InfoBar.instance)
160         elif answer == "PICTURES":
161                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
162                         from Plugins.Extensions.PicturePlayer.plugin import picshow
163                         EMsession.open(picshow)
164                 else:
165                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
166         elif answer == "MUSIC":
167                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
168                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
169                         servicelist = None
170                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
171                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo"):
172                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
173                         EMsession.open(MediaPlayer)
174                 else:
175                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
176         elif answer == "FILES":
177                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo"):
178                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
179                         EMsession.open(DreamExplorerII)
180                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo"):
181                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
182                         EMsession.open(FilebrowserScreen)
183                 else:
184                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
185         elif answer == "WEATHER":
186                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
187                         from Plugins.Extensions.WeatherPlugin.plugin import WeatherPlugin
188                         EMsession.open(WeatherPlugin)
189                 else:
190                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
191         
192
193