diff libervia.py @ 192:cf5c83e7d515

browser side: per tab selected widget management fix bug 6
author Goffi <goffi@goffi.org>
date Sun, 03 Mar 2013 23:30:25 +0100
parents 8475a29d7214
children f2ae8e170c49
line wrap: on
line diff
--- a/libervia.py	Sun Mar 03 23:26:09 2013 +0100
+++ b/libervia.py	Sun Mar 03 23:30:25 2013 +0100
@@ -123,7 +123,6 @@
         self.whoami = None
         self.bridge = BridgeCall()
         self.bridge_signals = BridgeSignals(self)
-        self.selected = None
         self.uni_box = None
         self.status_panel = panels.StatusPanel(self)
         self.contact_panel = ContactPanel(self)
@@ -144,6 +143,33 @@
         self.resize()
         self._register = RegisterCall()
         self._register.call('isRegistered',self._isRegisteredCB)
+        self.selected = property(self.getSelected, self.setSelected)
+
+    def getSelected(self):
+        wid = self.tab_panel.getCurrentPanel()
+        if not isinstance(wid, WidgetsPanel):
+            print "ERROR: Tab widget is not a WidgetsPanel, can't get selected widget"
+            return None
+        return wid.selected
+
+    def setSelected(self, widget):
+        """Define the selected widget"""
+        widgets_panel = self.tab_panel.getCurrentPanel()
+        if not isinstance(widgets_panel, WidgetsPanel):
+            return
+
+        selected = widgets_panel.selected
+
+        if selected:
+            if selected == widget:
+                return
+            selected.removeStyleName('selected_widget')
+        
+        widgets_panel.selected = widget
+        if widget:
+            widgets_panel.selected.addStyleName('selected_widget')
+
+
 
     def resize(self):
         """Resize elements"""
@@ -181,16 +207,6 @@
         self.uni_box = unibox
         self.uni_box.addKey("@@: ")
 
-    def select(self, widget):
-        """Define the selected widget"""
-        if self.selected:
-            if self.selected == widget:
-                return
-            self.selected.removeStyleName('selected_widget')
-        self.selected = widget
-        if widget:
-            self.selected.addStyleName('selected_widget')
-
     def addTab(self, wid, label):
         """Create a new tab and add a widget in
         @param wid: LiberviaWidget to add