changeset 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 8213e22c1120
children f2ae8e170c49
files browser_side/panels.py libervia.py
diffstat 2 files changed, 45 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Sun Mar 03 23:26:09 2013 +0100
+++ b/browser_side/panels.py	Sun Mar 03 23:30:25 2013 +0100
@@ -122,8 +122,8 @@
         _flextable = self.getParent()
         _widgetspanel = _flextable.getParent().getParent()
         row_idx, cell_idx = self._getCellAndRow(_flextable, event)
-        if self.host.selected == self:
-            self.host.select(None)
+        if self.host.getSelected == self:
+            self.host.setSelected(None)
         _widgetspanel.changeWidget(row_idx, cell_idx, _new_panel)
         """_unempty_panels = filter(lambda wid:not isinstance(wid,EmptyWidget),list(_flextable))
         _width = 90/float(len(_unempty_panels) or 1)
@@ -183,7 +183,7 @@
         return current
     
     def onClick(self, sender):
-        self.host.select(self)
+        self.host.setSelected(self)
 
     def onClose(self, sender):
         """ Called when the close button is pushed """
@@ -439,6 +439,7 @@
         Return a tuple (target_type, target info)"""
         type = None
         target = None
+        selected = self.host.getSelected()
         if txt.startswith('@@: '):
             type = "PUBLIC"
         elif txt.startswith('@'):
@@ -450,13 +451,13 @@
                 target = txt[1:_end] #only one target group is managed for the moment
                 if not target in self.host.contact_panel.getGroups():
                     target = None
-        elif self.host.selected == None:
+        elif selected == None:
             type = "STATUS"
-        elif isinstance(self.host.selected, ChatPanel):
+        elif isinstance(selected, ChatPanel):
             type = "ONE2ONE"
-            target = str(self.host.selected.target)
+            target = str(selected.target)
         else:
-            print "Unknown selected host:",self.host.selected
+            print "Unknown selected host:",selected
             type = "UNKNOWN"
         return (type, target)
 
@@ -479,15 +480,16 @@
 
         self._timer.schedule(2000)
 
+        selected = self.host.getSelected()
         #if keycode == KEY_ENTER and not self.visible:
         if keycode == KEY_ENTER:
             if _txt:
                 if _txt.startswith('@'):
                     self.host.bridge.call('sendMblog', None, self.getText())
-                elif self.host.selected == None:
+                elif selected == None:
                     self.host.bridge.call('setStatus', None, _txt)
-                elif isinstance(self.host.selected, ChatPanel):
-                    _chat = self.host.selected
+                elif isinstance(selected, ChatPanel):
+                    _chat = selected
                     mess_type = "groupchat" if _chat.type=='group' else "chat"
                     self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type)
             self.setText('')
@@ -650,7 +652,7 @@
 
     def onClick(self, sender):
         #As status is the default target of uniBar, we don't want to select anything if click on it
-        self.host.select(None)
+        self.host.setSelected(None)
 
 class ChatText(HTMLPanel):
 
@@ -867,6 +869,7 @@
         self.setSize('100%', '100%')
         self.host = host
         self.locked = locked #if True: tab will not be removed when there are no more widgets inside
+        self.selected = None
         self.flextable = FlexTable()
         self.flextable.setSize('100%','100%')
         self.setWidget(self.flextable)
@@ -1029,6 +1032,10 @@
         self.addStyleName('mainTabPanel')
         Window.addWindowResizeListener(self)
 
+    def getCurrentPanel(self):
+        """ Get the panel of the currently selected tab """
+        return self.deck.visibleWidget
+
     def onWindowResized(self, width, height):
         tab_panel_elt = self.getElement()
         _elts = doc().getElementsByClassName('gwt-TabBar')
--- 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