comparison libervia.py @ 193:f2ae8e170c49

browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
author Goffi <goffi@goffi.org>
date Mon, 04 Mar 2013 00:01:23 +0100
parents cf5c83e7d515
children 6198be95a39c
comparison
equal deleted inserted replaced
192:cf5c83e7d515 193:f2ae8e170c49
119 119
120 class SatWebFrontend: 120 class SatWebFrontend:
121 def onModuleLoad(self): 121 def onModuleLoad(self):
122 print "============ onModuleLoad ==============" 122 print "============ onModuleLoad =============="
123 self.whoami = None 123 self.whoami = None
124 self._selected_listeners = set()
124 self.bridge = BridgeCall() 125 self.bridge = BridgeCall()
125 self.bridge_signals = BridgeSignals(self) 126 self.bridge_signals = BridgeSignals(self)
126 self.uni_box = None 127 self.uni_box = None
127 self.status_panel = panels.StatusPanel(self) 128 self.status_panel = panels.StatusPanel(self)
128 self.contact_panel = ContactPanel(self) 129 self.contact_panel = ContactPanel(self)
129 self.panel = panels.MainPanel(self) 130 self.panel = panels.MainPanel(self)
130 self.discuss_panel = self.panel.discuss_panel 131 self.discuss_panel = self.panel.discuss_panel
131 self.tab_panel = self.panel.tab_panel 132 self.tab_panel = self.panel.tab_panel
133 self.tab_panel.addTabListener(self)
132 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets 134 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets
133 self.room_list = set() #set of rooms 135 self.room_list = set() #set of rooms
134 self.mblog_cache = [] #used to keep our own blog entries in memory, to show them in new mblog panel 136 self.mblog_cache = [] #used to keep our own blog entries in memory, to show them in new mblog panel
135 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file) 137 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file)
136 self.current_action_ids = set() 138 self.current_action_ids = set()
141 RootPanel().add(self.panel) 143 RootPanel().add(self.panel)
142 DOM.addEventPreview(self) 144 DOM.addEventPreview(self)
143 self.resize() 145 self.resize()
144 self._register = RegisterCall() 146 self._register = RegisterCall()
145 self._register.call('isRegistered',self._isRegisteredCB) 147 self._register.call('isRegistered',self._isRegisteredCB)
146 self.selected = property(self.getSelected, self.setSelected) 148
149 def addSelectedListener(self, callback):
150 self._selected_listeners.add(callback)
147 151
148 def getSelected(self): 152 def getSelected(self):
149 wid = self.tab_panel.getCurrentPanel() 153 wid = self.tab_panel.getCurrentPanel()
150 if not isinstance(wid, WidgetsPanel): 154 if not isinstance(wid, WidgetsPanel):
151 print "ERROR: Tab widget is not a WidgetsPanel, can't get selected widget" 155 print "ERROR: Tab widget is not a WidgetsPanel, can't get selected widget"
158 if not isinstance(widgets_panel, WidgetsPanel): 162 if not isinstance(widgets_panel, WidgetsPanel):
159 return 163 return
160 164
161 selected = widgets_panel.selected 165 selected = widgets_panel.selected
162 166
167 if selected == widget:
168 return
169
163 if selected: 170 if selected:
164 if selected == widget:
165 return
166 selected.removeStyleName('selected_widget') 171 selected.removeStyleName('selected_widget')
167 172
168 widgets_panel.selected = widget 173 widgets_panel.selected = widget
174
169 if widget: 175 if widget:
170 widgets_panel.selected.addStyleName('selected_widget') 176 widgets_panel.selected.addStyleName('selected_widget')
171 177
172 178 for callback in self._selected_listeners:
179 callback(widget)
173 180
174 def resize(self): 181 def resize(self):
175 """Resize elements""" 182 """Resize elements"""
176 Window.onResize() 183 Window.onResize()
184
185 def onBeforeTabSelected(self, sender, tab_index):
186 return True
187
188 def onTabSelected(self, sender, tab_index):
189 selected = self.getSelected()
190 for callback in self._selected_listeners:
191 callback(selected)
177 192
178 def onEventPreview(self, event): 193 def onEventPreview(self, event):
179 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: 194 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE:
180 #needed to prevent request cancellation in Firefox 195 #needed to prevent request cancellation in Firefox
181 event.preventDefault() 196 event.preventDefault()