- fixed console input mode restore
[enigma2.git] / components.py
index 7642338..ac4262e 100644 (file)
@@ -27,12 +27,18 @@ class GUISkin:
        def createGUIScreen(self, parent):
                for (name, val) in self.items():
                        self.data[name] = { }
-                       val.GUIcreate(self.data[name], parent, None)
+                       if isinstance(val, GUIComponent):
+                               val.GUIcreate(self.data[name], parent, None)
        
        def deleteGUIScreen(self):
                for (name, val) in self.items():
-                       w = self.data[name]["instance"]
-                       val.GUIdelete(self.data[name])
+                       if isinstance(val, GUIComponent):
+                               w = self.data[name]["instance"]
+                               val.GUIdelete(self.data[name])
+                       try:
+                               val.fix()
+                       except:
+                               pass
                        del self.data[name]
                        
                        # note: you'll probably run into this assert. if this happens, don't panic!
@@ -60,7 +66,7 @@ class GUISkin:
                        # way of having refcounted objects. So it must be in python.)
                        #
                        # It could be possible that you're calling deleteGUIscreen trough a call of
-                       # a PSignal. For example, you could try to call session.close() in response
+                       # a PSignal. For example, you could try to call screen.doClose() in response
                        # to a Button::click. This will fail. (It wouldn't work anyway, as you would
                        # remove a dialog while running it. It never worked - enigma1 just set a 
                        # per-mainloop variable on eWidget::close() to leave the exec()...)
@@ -174,18 +180,24 @@ class Clock(HTMLComponent, GUIComponent, VariableText):
                return self.getText()
 
 class Button(HTMLComponent, GUIComponent, VariableText):
-       def __init__(self, text=""):
+       def __init__(self, text="", onClick = [ ]):
                GUIComponent.__init__(self)
                VariableText.__init__(self)
                self.setText(text)
-               self.onClick = [ ]
+               self.onClick = onClick
        
        def push(self):
                for x in self.onClick:
                        x()
                return 0
        
-# html:        
+       def disable(self):
+               pass
+       
+       def enable(self):
+               pass
+
+# html:
        def produceHTML(self):
                return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
 
@@ -198,6 +210,21 @@ class Button(HTMLComponent, GUIComponent, VariableText):
        def GUIdeleteInstance(self, g):
                g.selected.get().remove(self.push)
 
+class Label(HTMLComponent, GUIComponent, VariableText):
+       def __init__(self, text=""):
+               GUIComponent.__init__(self)
+               VariableText.__init__(self)
+               self.setText(text)
+       
+# html:        
+       def produceHTML(self):
+               return self.getText()
+
+# GUI:
+       def GUIcreateInstance(self, priv, parent, skindata):
+               g = eLabel(parent)
+               return g
+
 class Header(HTMLComponent, GUIComponent, VariableText):
 
        def __init__(self, message):
@@ -224,7 +251,17 @@ class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
                g.setRange(0, 100)
                return g
 
+# a general purpose progress bar
+class ProgressBar(HTMLComponent, GUIComponent, VariableValue):
+       def __init__(self):
+               GUIComponent.__init__(self)
+               VariableValue.__init__(self)
 
+       def GUIcreateInstance(self, priv, parent, skindata):
+               g = eSlider(parent)
+               g.setRange(0, 100)
+               return g
+       
 class MenuList(HTMLComponent, GUIComponent):
        def __init__(self, list):
                GUIComponent.__init__(self)
@@ -241,3 +278,58 @@ class MenuList(HTMLComponent, GUIComponent):
        
        def GUIdeleteInstance(self, g):
                g.setContent(None)
+
+class ServiceList(HTMLComponent, GUIComponent):
+       def __init__(self):
+               GUIComponent.__init__(self)
+               self.l = eListboxServiceContent()
+
+       def GUIcreateInstance(self, priv, parent, skindata):
+               g = eListbox(parent)
+               g.setContent(self.l)
+               return g
+       
+       def GUIdeleteInstance(self, g):
+               g.setContent(None)
+
+       def setRoot(self, root):
+               self.l.setRoot(root)
+
+class ServiceScan:
+       
+       Idle = 1
+       Running = 2
+       Done = 3
+       Error = 4
+               
+       def scanStatusChanged(self):
+               if self.state == self.Running:
+                       self.progressbar.setValue(self.scan.getProgress())
+                       if self.scan.isDone():
+                               self.state = self.Done
+                       else:
+                               self.text.setText("scan in progress - %d %% done!\n%d services found!" % (self.scan.getProgress(), self.scan.getNumServices()))
+               
+               if self.state == self.Done:
+                       self.text.setText("scan done!")
+               
+               if self.state == self.Error:
+                       self.text.setText("ERROR - failed to scan!")
+       
+       def __init__(self, progressbar, text):
+               self.progressbar = progressbar
+               self.text = text
+               self.scan = eComponentScan()
+               if self.scan.start():
+                       self.state = self.Error
+               else:
+                       self.state = self.Running
+               self.scan.statusChanged.get().append(self.scanStatusChanged)
+               self.scanStatusChanged()
+
+       def isDone(self):
+               return self.state == self.Done
+
+       def fix(self):
+               self.scan.statusChanged.get().remove(self.scanStatusChanged)
+       
\ No newline at end of file