add ConfigScreen to Pluginmenu
authorRico Schulte <ricoschulte@users.schwerkraft.elitedvb.net>
Sun, 21 Jan 2007 16:25:27 +0000 (16:25 +0000)
committerRico Schulte <ricoschulte@users.schwerkraft.elitedvb.net>
Sun, 21 Jan 2007 16:25:27 +0000 (16:25 +0000)
webinterface/src/WebIfConfig.py [new file with mode: 0644]
webinterface/src/plugin.py

diff --git a/webinterface/src/WebIfConfig.py b/webinterface/src/WebIfConfig.py
new file mode 100644 (file)
index 0000000..35e8c70
--- /dev/null
@@ -0,0 +1,45 @@
+from enigma import *
+from Screens.Screen import Screen
+from Components.config import config, getConfigListEntry
+from Components.ConfigList import *
+from Components.Label import Label
+from Components.ActionMap import ActionMap
+        
+class WebIfConfigScreen(ConfigListScreen,Screen):
+    skin = """
+        <screen position="100,100" size="550,400" title="Webinterface Setup" >
+        <widget name="config" position="20,10" size="460,350" scrollbarMode="showOnDemand" />
+        <widget name="buttonred" position="10,360" size="100,40" backgroundColor="red" valign="center" halign="center" zPosition="2"  foregroundColor="white" font="Regular;18"/> 
+        <widget name="buttongreen" position="120,360" size="100,40" backgroundColor="green" valign="center" halign="center" zPosition="2"  foregroundColor="white" font="Regular;18"/> 
+        </screen>"""
+    def __init__(self, session, args = 0):
+        self.session = session
+        Screen.__init__(self, session)
+        self.list = []
+        self.list.append(getConfigListEntry(_("start Webinterface"), config.plugins.Webinterface.enable))
+        self.list.append(getConfigListEntry(_("use Port"), config.plugins.Webinterface.port))
+        ConfigListScreen.__init__(self, self.list)
+        self["buttonred"] = Label(_("cancel"))
+        self["buttongreen"] = Label(_("ok"))
+
+        self["setupActions"] = ActionMap(["SetupActions"],
+        {
+            "green": self.save,
+            "red": self.cancel,
+            "save": self.save,
+            "cancel": self.cancel,
+            "ok": self.save,
+        }, -2)
+
+
+    def save(self):
+        print "saving"
+        for x in self["config"].list:
+            x[1].save()
+        self.close()
+
+    def cancel(self):
+        print "cancel"
+        for x in self["config"].list:
+            x[1].cancel()
+        self.close()
\ No newline at end of file
index 8f442ad..ef43826 100644 (file)
@@ -4,8 +4,17 @@ from twisted.internet import reactor
 from twisted.web2 import server, channel, static, resource, stream, http_headers, responsecode, http
 from twisted.python import util
 import webif
+import WebIfConfig  
 import os
 
+
+from Components.config import config, ConfigSubsection, ConfigInteger,ConfigYesNo
+
+config.plugins.Webinterface = ConfigSubsection()
+config.plugins.Webinterface.enable = ConfigYesNo(default = False)
+config.plugins.Webinterface.port = ConfigInteger(80,limits = (1, 999))
+
+
 sessions = [ ]
 
 # set DEBUG to True, if twisted should write logoutput to a file.
@@ -104,7 +113,8 @@ def startWebserver():
                                         (basic.BasicCredentialFactory('DM7025'),digest.DigestCredentialFactory(PASSWORDPROTECTION_mode,'DM7025')),
                                         portal, (IHTTPUser,))
                site = server.Site(root)
-       reactor.listenTCP(80, channel.HTTPFactory(site))
+       print "starting Webinterface on port",config.plugins.Webinterface.port.value
+       reactor.listenTCP(config.plugins.Webinterface.port.value, channel.HTTPFactory(site))
 
 # start classes for PASSWORDPROTECTION
 # end  classes for PASSWORDPROTECTION
@@ -128,9 +138,16 @@ def autostart(reason, **kwargs):
                                print "start twisted logfile, writing to %s" % DEBUGFILE 
                                startLogging(open(DEBUGFILE,'w'))
                        
-                       startWebserver()
+                       if config.plugins.Webinterface.enable.value:
+                               startWebserver()
+                       else:
+                               print "not starting Webinterface"
                except ImportError:
                        print "twisted not available, not starting web services"
+                       
+def openconfig(session, **kwargs):
+       session.open(WebIfConfig.WebIfConfigScreen)
 
 def Plugins(**kwargs):
-       return PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart)
+       return [PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
+                   PluginDescriptor(name=_("Webinterface"), description=_("Configuration for the Webinterface"),where = [PluginDescriptor.WHERE_PLUGINMENU], fnc = openconfig)]