Merge branch 'refs/heads/master' of ssh://sreichholf@scm.schwerkraft.elitedvb.net...
[vuplus_dvbapp-plugin] / movieselectionquickbutton / src / plugin.py
1 #
2 #  MovieSelectionQuickButton E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2009
7 #  Support: www.dreambox-tools.info
8 #
9 #  This plugin is licensed under the Creative Commons 
10 #  Attribution-NonCommercial-ShareAlike 3.0 Unported 
11 #  License. To view a copy of this license, visit
12 #  http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
13 #  Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
14 #
15 #  Alternatively, this plugin may be distributed and executed on hardware which
16 #  is licensed by Dream Multimedia GmbH.
17
18 #  This plugin is NOT free software. It is open source, you are allowed to
19 #  modify it (if you keep the license), but it may not be commercially 
20 #  distributed other than under the conditions noted above.
21 #
22
23 from Plugins.Plugin import PluginDescriptor
24 from Screens.Screen import Screen
25 from Screens.MovieSelection import MovieSelection, MovieContextMenu
26 from Components.MovieList import MovieList
27 from Components.ActionMap import HelpableActionMap, ActionMap
28 from Components.Button import Button
29 from Components.PluginComponent import plugins
30 from Components.ConfigList import ConfigList, ConfigListScreen
31 from Components.config import ConfigSubsection, ConfigText, configfile, ConfigSelection, getConfigListEntry
32 from Components.config import config
33 from Screens.MessageBox import MessageBox
34 # for localized messages
35 from . import _
36
37 config.plugins.MovieSelectionQuickButton = ConfigSubsection()
38 config.plugins.MovieSelectionQuickButton.red = ConfigText(default = _("Delete"), visible_width = 50, fixed_size = False)
39 config.plugins.MovieSelectionQuickButton.green = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
40 config.plugins.MovieSelectionQuickButton.yellow = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
41 config.plugins.MovieSelectionQuickButton.blue = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
42 config.plugins.MovieSelectionQuickButton.buttoncaption = ConfigSelection(default="0", choices = [("0", _("display plugin name")),("1", _("display plugin description"))])
43
44 ###########################################
45 # MovieSelection
46 ###########################################
47 baseMovieSelection__init__ = None
48 baseupdateTags = None
49 def MovieSelectionInit():
50         global baseMovieSelection__init__, baseupdateTags
51         if baseMovieSelection__init__ is None:
52                 baseMovieSelection__init__ = MovieSelection.__init__
53         if baseupdateTags is None:
54                 baseupdateTags = MovieSelection.updateTags
55         MovieSelection.__init__ = MovieSelection__init__
56         MovieSelection.updateTags = noUpdateTages
57         # new methods
58         MovieSelection.redpressed = redpressed
59         MovieSelection.greenpressed = greenpressed
60         MovieSelection.yellowpressed = yellowpressed
61         MovieSelection.bluepressed = bluepressed
62         MovieSelection.getPluginCaption = getPluginCaption
63
64 def MovieSelection__init__(self, session, selectedmovie = None):
65         baseMovieSelection__init__ (self, session, selectedmovie)
66         self["key_red"] = Button(self.getPluginCaption(str(config.plugins.MovieSelectionQuickButton.red.value)))
67         self["key_green"] = Button(self.getPluginCaption(str(config.plugins.MovieSelectionQuickButton.green.value)))
68         self["key_yellow"] = Button(self.getPluginCaption(str(config.plugins.MovieSelectionQuickButton.yellow.value)))
69         self["key_blue"] = Button(self.getPluginCaption(str(config.plugins.MovieSelectionQuickButton.blue.value)))
70         self["ColorActions"] = HelpableActionMap(self, "ColorActions",
71         {
72                 "red": (self.redpressed, _("Assign plugin to red key pressed")),
73                 "green": (self.greenpressed, _("Assign plugin to green key pressed")),
74                 "yellow": (self.yellowpressed, _("Assign plugin to yellow key pressed")),
75                 "blue": (self.bluepressed, _("Assign plugin to blue key pressed")),
76         })
77
78 def redpressed(self):
79         startPlugin(self,str(config.plugins.MovieSelectionQuickButton.red.value),0)
80
81 def greenpressed(self):
82         startPlugin(self,str(config.plugins.MovieSelectionQuickButton.green.value),1)
83
84 def yellowpressed(self):
85         startPlugin(self,str(config.plugins.MovieSelectionQuickButton.yellow.value),2)
86
87 def bluepressed(self):
88         startPlugin(self,str(config.plugins.MovieSelectionQuickButton.blue.value),3)
89
90 def getPluginCaption(self,pname):
91         if pname != _("Nothing"):
92                 if pname == _("Delete"):
93                         return _("Delete")
94                 elif pname == _("Home"):
95                         return _("Home")
96                 elif pname == _("Sort"):
97                         if config.movielist.moviesort.value == MovieList.SORT_ALPHANUMERIC:
98                                 return _("sort by date")
99                         else:
100                                 return _("alphabetic sort")
101                 else:
102                         for p in plugins.getPlugins(where = [PluginDescriptor.WHERE_MOVIELIST]):
103                                 if pname == str(p.name):
104                                         if config.plugins.MovieSelectionQuickButton.buttoncaption.value == "1":
105                                                 return p.description
106                                         else:
107                                                 return p.name
108         return ""
109
110 def startPlugin(self,pname, index):
111         plugin = None
112         no_plugin = True
113         msgText = _("Unknown Error")
114         current = self.getCurrent()
115         if current is not None:
116                 if pname != _("Nothing"):
117                         if pname == _("Delete"):
118                                 MCM = MovieContextMenu(self.session,self,current)
119                                 MCM.delete()
120                                 no_plugin = False
121                         elif pname == _("Home"):
122                                 self.gotFilename(config.usage.default_path.value)
123                                 no_plugin = False
124                         elif pname == _("Sort"):
125                                 if config.movielist.moviesort.value == MovieList.SORT_ALPHANUMERIC:
126                                         newType = MovieList.SORT_RECORDED
127                                         newCaption =  _("alphabetic sort")
128                                 else:
129                                         newType = MovieList.SORT_ALPHANUMERIC
130                                         newCaption = _("sort by date")
131                                 config.movielist.moviesort.value = newType
132                                 self.setSortType(newType)
133                                 self.reloadList()
134                                 if index == 0:
135                                         self["key_red"].setText(newCaption)
136                                 elif index == 1:
137                                         self["key_green"].setText(newCaption)
138                                 elif index == 2:
139                                         self["key_yellow"].setText(newCaption)
140                                 elif index == 3:
141                                         self["key_blue"].setText(newCaption)
142                                 no_plugin = False
143                         else:
144                                 for p in plugins.getPlugins(where = [PluginDescriptor.WHERE_MOVIELIST]):
145                                         if pname == str(p.name):
146                                                 plugin = p
147                                 if plugin is not None:
148                                         try:
149                                                 plugin(self.session, current)
150                                                 no_plugin = False
151                                         except Exception, e:
152                                                 msgText = _("Error!\nError Text: %s"%e)
153                                 else: 
154                                         msgText = _("Plugin not found!")
155                 else:
156                         msgText = _("No plugin assigned!")
157                 if no_plugin:
158                         self.session.open(MessageBox,msgText, MessageBox.TYPE_INFO)
159
160 def noUpdateTages(self):
161         pass #nothing to do here, just ovewrite the method
162
163 class MovieSelectionButtonSetup(ConfigListScreen, Screen):
164         skin = """
165                 <screen position="center,center" size="550,400" title="MovieSelection QuickButton Setup" >
166                         <widget name="config" position="20,10" size="510,330" scrollbarMode="showOnDemand" />
167                         <widget name="key_red" position="0,350" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
168                         <widget name="key_green" position="140,350" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
169                         <ePixmap name="red" pixmap="skin_default/buttons/red.png" position="0,350" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
170                         <ePixmap name="green" pixmap="skin_default/buttons/green.png" position="140,350" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
171                 </screen>"""
172
173         def __init__(self, session, args = None):
174                 Screen.__init__(self, session)
175                 self["key_red"] = Button(_("Cancel"))
176                 self["key_green"] = Button(_("OK"))
177                 self.entryguilist = []
178                 self.entryguilist.append(("0",_("Nothing")))
179                 self.entryguilist.append(("1",_("Delete")))
180                 self.entryguilist.append(("2",_("Home")))
181                 self.entryguilist.append(("3",_("Sort")))
182                 index = 4
183                 red_selectedindex = self.getStaticName(config.plugins.MovieSelectionQuickButton.red.value)
184                 green_selectedindex = self.getStaticName(config.plugins.MovieSelectionQuickButton.green.value)
185                 yellow_selectedindex = self.getStaticName(config.plugins.MovieSelectionQuickButton.yellow.value)
186                 blue_selectedindex = self.getStaticName(config.plugins.MovieSelectionQuickButton.blue.value)
187                 for p in plugins.getPlugins(where = [PluginDescriptor.WHERE_MOVIELIST]):
188                         self.entryguilist.append((str(index),str(p.name)))
189                         if config.plugins.MovieSelectionQuickButton.red.value == str(p.name):
190                                 red_selectedindex = str(index)
191                         if config.plugins.MovieSelectionQuickButton.green.value == str(p.name):
192                                 green_selectedindex = str(index)
193                         if config.plugins.MovieSelectionQuickButton.yellow.value == str(p.name):
194                                 yellow_selectedindex = str(index)
195                         if config.plugins.MovieSelectionQuickButton.blue.value == str(p.name):
196                                 blue_selectedindex = str(index)
197                         index = index + 1
198                 self.redchoice = ConfigSelection(default = red_selectedindex, choices = self.entryguilist)
199                 self.greenchoice = ConfigSelection(default = green_selectedindex, choices = self.entryguilist)
200                 self.yellowchoice = ConfigSelection(default = yellow_selectedindex, choices = self.entryguilist)
201                 self.bluechoice = ConfigSelection(default = blue_selectedindex, choices = self.entryguilist)
202                 cfglist = [
203                         getConfigListEntry(_("assigned to red"), self.redchoice),
204                         getConfigListEntry(_("assigned to green"), self.greenchoice),
205                         getConfigListEntry(_("assigned to yellow"), self.yellowchoice),
206                         getConfigListEntry(_("assigned to blue"), self.bluechoice),
207                         getConfigListEntry(_("button caption"), config.plugins.MovieSelectionQuickButton.buttoncaption),
208                         ]
209                 ConfigListScreen.__init__(self, cfglist, session)
210                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
211                 {
212                         "green": self.keySave,
213                         "cancel": self.keyClose,
214                         "ok": self.keySave,
215                 }, -2)
216
217         def keySave(self):
218                 config.plugins.MovieSelectionQuickButton.red.value = self.entryguilist[int(self.redchoice.value)][1]
219                 config.plugins.MovieSelectionQuickButton.green.value = self.entryguilist[int(self.greenchoice.value)][1]
220                 config.plugins.MovieSelectionQuickButton.yellow.value = self.entryguilist[int(self.yellowchoice.value)][1]
221                 config.plugins.MovieSelectionQuickButton.blue.value = self.entryguilist[int(self.bluechoice.value)][1]
222                 config.plugins.MovieSelectionQuickButton.save()
223                 configfile.save()
224                 self.close()
225
226         def keyClose(self):
227                 self.close()
228
229         def getStaticName(self,value):
230                 if value == _("Delete"):
231                         return "1"
232                 elif value == _("Home"):
233                         return "2"
234                 elif value == _("Sort"):
235                         return "3"
236                 else:
237                         return "0"
238
239 def setup(session,**kwargs):
240         session.open(MovieSelectionButtonSetup)
241
242 def main(session, **kwargs):
243         try: MovieSelectionInit()
244         except: pass
245
246 def Plugins(**kwargs):
247         list = [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = main)]      
248         list.append(PluginDescriptor(name="Setup MovieSelection QuickButton", description=_("Setup for MovieSelection QuickButton"), where = [PluginDescriptor.WHERE_PLUGINMENU],
249         icon = "plugin.png", fnc=setup))
250         return list
251