InfoBarTunerState - Added option for show only on key press
[enigma2-plugins.git] / infobartunerstate / src / IBTSConfiguration.py
1 #######################################################################
2 #
3 #    InfoBar Tuner State for Enigma-2
4 #    Coded by betonme (c) 2011 <glaserfrank(at)gmail.com>
5 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=162629
6 #
7 #    This program is free software; you can redistribute it and/or
8 #    modify it under the terms of the GNU General Public License
9 #    as published by the Free Software Foundation; either version 2
10 #    of the License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #######################################################################
18
19 # for localized messages
20 from . import _
21
22 # Config
23 from Components.config import *
24 from Components.ConfigList import ConfigListScreen
25 from Components.Sources.StaticText import StaticText
26
27 from Components.ActionMap import ActionMap
28 from Screens.MessageBox import MessageBox
29 from Screens.Screen import Screen
30 from Screens.Setup import SetupSummary
31
32 # Plugin internal
33 from InfoBarTunerState import InfoBarTunerState, addExtension, removeExtension, overwriteInfoBar, recoverInfoBar
34
35
36 #######################################################
37 # Configuration screen
38 class InfoBarTunerStateConfiguration(Screen, ConfigListScreen):
39         def __init__(self, session):
40                 Screen.__init__(self, session)
41                 self.skinName = [ "InfoBarTunerStateConfiguration", "Setup" ]
42                 
43                 # Summary
44                 from Plugins.Extensions.InfoBarTunerState.plugin import NAME, VERSION
45                 self.setup_title = NAME + " " + _("Configuration") + " " + VERSION
46                 self.onChangedEntry = []
47                 
48                 # Buttons
49                 self["key_red"] = StaticText(_("Cancel"))
50                 self["key_green"] = StaticText(_("OK"))
51                 
52                 # Define Actions
53                 self["custom_actions"] = ActionMap(["SetupActions", "ChannelSelectBaseActions"],
54                 {
55                         "cancel":                               self.keyCancel,
56                         "save":                                 self.keySave,
57                         "nextBouquet":  self.pageUp,
58                         "prevBouquet":  self.pageDown,
59                 }, -2) # higher priority
60                 
61                 # Initialize Configuration part
62                 self.list = []
63                 self.config = []
64                 self.defineConfig()
65                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
66                 self.createConfig()
67                 
68                 # Trigger change
69                 self.changed()
70
71                 self.onLayoutFinish.append(self.layoutFinished)
72
73         def defineConfig(self):
74                 
75                 separator = "".ljust(250,"-")
76                 separatorE2Usage = "- E2 "+_("Usage")+" "
77                 separatorE2Usage = separatorE2Usage.ljust(250-len(separatorE2Usage),"-")
78                 
79 #         _config list entry
80 #         _                                                     , config element
81                 self.config = [
82                         (  _("Enable InfoBarTunerState")                          , config.infobartunerstate.enabled ),
83                         (  separator                                              , config.infobartunerstate.about ),
84                         (  _("Add Show to extension menu")                        , config.infobartunerstate.extensions_menu_show ),
85                         (  _("Add Setup to extension menu")                       , config.infobartunerstate.extensions_menu_setup ),
86 #                       (  _("Pop-Up time in seconds")                            , config.infobartunerstate.popup_time ),
87                         (  _("Show and hide with InfoBar")                        , config.infobartunerstate.show_infobar ),
88                         (  _("Show on events")                                    , config.infobartunerstate.show_events ),
89 #                       (  _("Show on events")                                    , config.infobartunerstate.show_on_events ),
90                         (  _("Show streams")                                      , config.infobartunerstate.show_streams ),
91                         (  _("Show on key press")                                 , config.infobartunerstate.show_ontoggle ),
92                         (  _("MoviePlayer integration")                           , config.infobartunerstate.show_overwrite ),
93                         (  _("Time format begin")                                 , config.infobartunerstate.time_format_begin ),
94                         (  _("Time format end")                                   , config.infobartunerstate.time_format_end ),
95                         (  _("Number of pending records in list")                 , config.infobartunerstate.number_pending_records ),
96                         (  _("Number of finished records in list")                , config.infobartunerstate.number_finished_records ),
97                         (  _("Number of seconds for displaying finished records") , config.infobartunerstate.timeout_finished_records ),
98                         (  separator                                              , config.infobartunerstate.about ),
99                 ]
100                 
101                 for i, configinfobartunerstatefield in enumerate( config.infobartunerstate.fields.dict().itervalues() ):
102                         self.config.append(
103                         (  _("Field %d content") % (i)                            , configinfobartunerstatefield )
104                         )
105                 for i, configinfobartunerstatefieldwidth in enumerate( config.infobartunerstate.fieldswidth.dict().itervalues() ):
106                         self.config.append(
107                         (  _("Field %d width") % (i)                            , configinfobartunerstatefieldwidth )
108                         )
109
110                 self.config.extend( [
111                         (  separator                                              , config.infobartunerstate.about ),
112                         (  _("Horizontal offset left in pixel")                   , config.infobartunerstate.offset_horizontal ),
113                         (  _("Horizontal offset right in pixel")                  , config.infobartunerstate.offset_rightside ),
114                         (  _("Vertical offset in pixel")                          , config.infobartunerstate.offset_vertical ),
115                         (  _("Text padding offset in pixel")                      , config.infobartunerstate.offset_padding ),
116                         (  _("Text spacing offset in pixel")                      , config.infobartunerstate.offset_spacing ),
117                         (  _("Variable field width")                              , config.infobartunerstate.variable_field_width ),
118                         (  _("Placeholder for Progressbar")                       , config.infobartunerstate.placeholder_pogressbar ),
119                         (  _("List goes up")                                                      , config.infobartunerstate.list_goesup ),
120                         (  _("Background transparency")                           , config.infobartunerstate.background_transparency ),
121                         (  _("Overwrite Infobar timeout")                         , config.infobartunerstate.infobar_timeout ),
122                 ] )
123                 
124                 self.config.extend( [
125                         (  separatorE2Usage                                       , config.infobartunerstate.about ),
126                         (  _("Infobar timeout")                                   , config.usage.infobar_timeout ),
127                         (  _("Show Message when Recording starts")                , config.usage.show_message_when_recording_starts ),
128                 ] )
129
130         def createConfig(self):
131                 list = []
132                 for conf in self.config:
133                         # 0 entry text
134                         # 1 variable
135                         list.append( getConfigListEntry( conf[0], conf[1]) )
136                         if not config.infobartunerstate.enabled.value:
137                                 break
138                 self.list = list
139                 self["config"].setList(self.list)
140
141         def layoutFinished(self):
142                 self.setTitle(self.setup_title)
143
144         def changed(self):
145                 for x in self.onChangedEntry:
146                         x()
147                 self.createConfig()
148
149         # Overwrite ConfigListScreen keyCancel function
150         def keyCancel(self):
151                 if self["config"].isChanged():
152                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
153                 else:
154                         self.close()
155
156         # Overwrite ConfigListScreen cancelConfirm function
157         def cancelConfirm(self, result):
158                 if not result:
159                         return
160                 for x in self["config"].list:
161                         x[1].cancel()
162                 self.close()
163
164         # Overwrite ConfigListScreen keySave function
165         def keySave(self):
166                 # Check field configuration
167                 fieldname = []
168                 fieldicon = []
169                 fieldprogress = []
170                 text = ""
171                 for i, c in enumerate( config.infobartunerstate.fields.dict().itervalues() ):
172                         if c.value == "Name":
173                                 fieldname.append( i )
174                         if c.value == "TypeIcon":
175                                 fieldicon.append( i )
176                         if c.value == "TimerProgressGraphical":
177                                 fieldprogress.append( i )
178                 
179                 if len(fieldname) > 1:
180                         text += _("Only one Name field allowed:") + "\n" \
181                                                         + "\n".join(["Field " + (str(f)) for f in fieldname])
182                 
183                 if len(fieldicon) > 1:
184                         text += _("Only one Icon field allowed:") + "\n" \
185                                                         + "\n".join(["Field " + (str(f)) for f in fieldicon])
186                 
187                 if len(fieldprogress) > 1:
188                         if text: text += "\n\n"
189                         text += _("Only one Graphical Progress field allowed:") + "\n" \
190                                                         + "\n".join(["Field " + (str(f)) for f in fieldprogress])
191                 
192                 if text:
193                         self.session.open(MessageBox, text, MessageBox.TYPE_ERROR, 3)
194                         return
195                 
196                 # Now save all
197                 self.saveAll()
198                 
199                 # Overwrite Screen close function to handle new config
200                 
201                 # We need assign / "write" access import the plugin module
202                 # global won't work across module scope
203                 import plugin
204                 if config.infobartunerstate.enabled.value:
205                         # Plugin should be enabled
206                         #TODO use a separate init function similar to the close
207                         if plugin.gInfoBarTunerState:
208                                 # Plugin is active - close it
209                                 plugin.gInfoBarTunerState.close()
210                         
211                         # Force new instance
212                         plugin.gInfoBarTunerState = InfoBarTunerState(self.session)
213                         
214                         if plugin.gInfoBarTunerState:
215                                 
216                                 # Handle InfoBar overwrite
217                                 #if config.infobartunerstate.show_overwrite.value:
218                                 overwriteInfoBar()
219                                 #else:
220                                 #       recoverInfoBar()
221                                 
222                                 # Handle extension menu integration
223                                 if config.infobartunerstate.extensions_menu_show.value or config.infobartunerstate.extensions_menu_setup.value:
224                                         # Add to extension menu
225                                         addExtension()
226                                 else:
227                                         # Remove from extension menu
228                                         removeExtension()
229                                 
230                                 # Handle show with InfoBar
231                                 if config.infobartunerstate.show_infobar.value:
232                                         plugin.gInfoBarTunerState.bindInfoBar()
233                                 else:
234                                         plugin.gInfoBarTunerState.unbindInfoBar()
235                                 
236                                 #TODO actually not possible to do this, because these events provides the relevant information
237                                 #if config.infobartunerstate.show_events.value:
238                                 #       plugin.gInfoBarTunerState.appendEvents()
239                                 #else:
240                                 #       plugin.gInfoBarTunerState.removeEvents()
241                                 
242                                 # Remove and append because of show streams handling
243                                 plugin.gInfoBarTunerState.removeEvents()
244                                 plugin.gInfoBarTunerState.appendEvents()
245                                 
246                                 # Check for actual events
247                                 plugin.gInfoBarTunerState.updateRecordTimer()
248                                 if config.infobartunerstate.show_streams.value:
249                                         plugin.gInfoBarTunerState.updateStreams()
250                 else:
251                         # Plugin should be disabled
252                         if plugin.gInfoBarTunerState:
253                                 # Plugin is active, disable it
254                                 plugin.gInfoBarTunerState.close()
255
256                 self.close()
257         
258         # Overwrite Screen close function
259         def close(self):
260                 from plugin import ABOUT
261                 self.session.openWithCallback(self.closeConfirm, MessageBox, ABOUT, MessageBox.TYPE_INFO)
262
263         def closeConfirm(self, dummy=None):
264                 # Call baseclass function
265                 Screen.close(self)
266
267         def getCurrentEntry(self):
268                 return self["config"].getCurrent()[0]
269
270         def getCurrentValue(self):
271                 return str(self["config"].getCurrent()[1].getText())
272
273         def createSummary(self):
274                 return SetupSummary
275
276         def pageUp(self):
277                 self["config"].instance.moveSelection(self["config"].instance.pageUp)
278
279         def pageDown(self):
280                 self["config"].instance.moveSelection(self["config"].instance.pageDown)
281