IBTS 0.9.1
[enigma2-plugins.git] / infobartunerstate / src / plugin.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
25 # Plugin
26 from Plugins.Plugin import PluginDescriptor
27
28 # MessageBox
29 from Screens.MessageBox import MessageBox
30
31 # Plugin internal
32 from IBTSConfiguration import InfoBarTunerStateConfiguration
33 from InfoBarTunerState import InfoBarTunerState, TunerStateInfo
34
35
36 # Contants
37 NAME = _("InfoBar Tuner State") 
38 DESCRIPTION = _("Show InfoBar Tuner State")
39 VERSION = "V0.9.1"
40 #TODO About
41
42
43 # Globals
44 gInfoBarTunerState = None
45
46
47 # Config choices
48 field_choices = [       
49                                                                         ("TypeIcon",                                                            _("Type (Icon)")),
50                                                                         ("TypeText",                                                            _("Type (Text)")),
51                                                                         ("Tuner",                                                                               _("Tuner")),
52                                                                         ("TunerType",                                                           _("Tuner Type")),
53                                                                         ("Number",                                                                      _("Channel Number")),
54                                                                         ("Channel",                                                                     _("Channel Name")),
55                                                                         ("Name",                                                                                _("Name")),
56                                                                         ("TimeLeftDuration",                            _("Time Left / Duration")),
57                                                                         ("TimeLeft",                                                            _("Time Left")),
58                                                                         ("TimeElapsed",                                                 _("Time Elapsed")),
59                                                                         ("Begin",                                                                               _("Begin")),
60                                                                         ("End",                                                                                 _("End")),
61                                                                         ("Duration",                                                            _("Duration")),
62                                                                         ("TimerProgressGraphical",      _("Timer Progress (Graphical)")),  #TODO howto do for file streams
63                                                                         ("TimerProgressText",                           _("Timer Progress (Text)")),  #TODO howto do for file streams
64                                                                         ("TimerDestination",                            _("Destination")),              #TODO howto do for file streams
65                                                                         ("StreamClient",                                                _("Stream Client")),
66                                                                         ("StreamClientPort",                            _("Stream Client with Port")),
67                                                                         ("DestinationStreamClient",     _("Destination / Client")),
68                                                                         #Throughput
69                                                                         #Overall transfer
70                                                                         ("FileSize",                                                            _("File Size")),
71                                                                         ("FreeSpace",                                                           _("Free Space")),
72                                                                         ("None",                                                                                _("None")),
73                                                                 ]
74
75 date_choices = [        
76                                                                         ("%H:%M",                                                       _("HH:MM")),
77                                                                         ("%d.%m %H:%M",                         _("DD.MM HH:MM")),
78                                                                         ("%m/%d %H:%M",                         _("MM/DD HH:MM")),
79                                                                         ("%d.%m.%Y %H:%M",              _("DD.MM.YYYY HH:MM")),
80                                                                         ("%Y/%m/%d %H:%M",              _("YYYY/MM/DD HH:MM")),
81                                                                         ("%H:%M %d.%m",                         _("HH:MM DD.MM")),
82                                                                         ("%H:%M %m/%d",                         _("HH:MM MM/DD")),
83                                                                         ("%H:%M %d.%m.%Y",              _("HH:MM DD.MM.YYYY")),
84                                                                         ("%H:%M %Y/%m/%d",              _("HH:MM YYYY/MM/DD")),
85                                                                 ]
86
87 # Config options
88 config.infobartunerstate                           = ConfigSubsection()
89
90 config.infobartunerstate.about                     = ConfigNothing()
91 config.infobartunerstate.enabled                   = ConfigEnableDisable(default = True)
92 config.infobartunerstate.extensions_menu           = ConfigYesNo(default = True)
93 #config.infobartunerstate.popup_time                = ConfigSelectionNumber(0, 10, 1, default = 5)
94 #Todo item enabler
95 #Show records
96 #Show streams
97
98 config.infobartunerstate.show_infobar              = ConfigYesNo(default = True)
99 config.infobartunerstate.show_events               = ConfigYesNo(default = True)                #TODO Show on start, end, start/end
100 config.infobartunerstate.show_overwrite            = ConfigYesNo(default = False)               # Show with MoviePlayer only is actually not possible
101
102 config.infobartunerstate.time_format               = ConfigSelection(default = "%H:%M", choices = date_choices)
103 config.infobartunerstate.number_finished_records   = ConfigSelectionNumber(0, 10, 1, default = 5)
104 config.infobartunerstate.timeout_finished_records  = ConfigSelectionNumber(0, 600, 10, default = 60)
105
106 config.infobartunerstate.fields                    = ConfigSubsection()
107 config.infobartunerstate.fields.a                  = ConfigSelection(default = "TypeIcon", choices = field_choices)
108 config.infobartunerstate.fields.b                  = ConfigSelection(default = "Tuner", choices = field_choices)
109 config.infobartunerstate.fields.c                  = ConfigSelection(default = "Number", choices = field_choices)
110 config.infobartunerstate.fields.d                  = ConfigSelection(default = "Channel", choices = field_choices)
111 config.infobartunerstate.fields.e                  = ConfigSelection(default = "Name", choices = field_choices)
112 config.infobartunerstate.fields.f                  = ConfigSelection(default = "TimerProgressGraphical", choices = field_choices)
113 config.infobartunerstate.fields.g                  = ConfigSelection(default = "TimeLeftDuration", choices = field_choices)
114 config.infobartunerstate.fields.h                  = ConfigSelection(default = "StreamClient", choices = field_choices)
115 config.infobartunerstate.fields.i                  = ConfigSelection(default = "None", choices = field_choices)
116 config.infobartunerstate.fields.j                  = ConfigSelection(default = "None", choices = field_choices)
117
118 config.infobartunerstate.offset_horizontal         = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
119 config.infobartunerstate.offset_vertical           = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
120 config.infobartunerstate.offset_padding            = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
121 config.infobartunerstate.offset_spacing            = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
122
123 config.infobartunerstate.background_transparency   = ConfigYesNo(default = False)
124
125
126 #######################################################
127 # Plugin main function
128 def Plugins(**kwargs):
129         #TODO localeInit()
130         
131         descriptors = []
132         
133         if config.infobartunerstate.enabled.value:
134                 # AutoStart and SessionStart
135                 descriptors.append( PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = start, needsRestart = False) )
136                 descriptors.append( PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = start, needsRestart = False) )
137                 if config.infobartunerstate.extensions_menu.value:
138                         descriptors.append( PluginDescriptor(name = NAME, description = DESCRIPTION, where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = extension, needsRestart = False) )
139         
140         #TODO icon
141         descriptors.append( PluginDescriptor(name = NAME, description = NAME + " " +_("configuration"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = setup, needsRestart = False) ) #icon = "/icon.png"
142
143         return descriptors
144
145
146 #######################################################
147 # Plugin # Plugin configuration
148 def setup(session, **kwargs):
149         #TODO config
150         # Overwrite Skin Position
151         # Show Live TV Tuners PiP LiveStream FileStream
152         # alltime permanent display, needs an dynamic update service
153         # Always display at least Nothing running
154         # show free tuner with dvb-type
155         # Used disk size
156         # Event popup timeout
157         # Feldbreitenbegrenzung fuer Namen ...
158         # Streaming amount of data
159         # Display next x timers also if deactivated
160         try:
161                 session.open(InfoBarTunerStateConfiguration)
162         except Exception, e:
163                 print "InfoBarTunerStateMenu exception " + str(e)
164
165
166 #######################################################
167 # Autostart and Sessionstart
168 def start(reason, **kwargs):
169         #print "InfoBarTunerState autostart "
170         #print str(reason)
171         #print str(kwargs)
172         if reason == 0: # start
173                 if kwargs.has_key("session"):
174                         if config.infobartunerstate.enabled.value:
175                                 global gInfoBarTunerState
176                                 session = kwargs["session"]
177                                 gInfoBarTunerState = InfoBarTunerState(session)
178
179
180 #######################################################
181 # Extension Menu
182 def extension(session, **kwargs):
183         global gInfoBarTunerState
184         if gInfoBarTunerState:
185                 if gInfoBarTunerState.entries:
186                         # There are active entries
187                         gInfoBarTunerState.show(True)
188                 else:
189                         # No entries available
190                         gInfoBarTunerState.info = gInfoBarTunerState.session.instantiateDialog( TunerStateInfo, _("Nothing running") )
191                         gInfoBarTunerState.info.show()
192         else:
193                 # No InfoBarTunerState Instance running
194                 session.open(MessageBox, _("InfoBarTunerState is disabled"), MessageBox.TYPE_INFO, 3)
195