comparison browser_side/panels.py @ 62:12e889a683ce SàT v0.2.0

server side: misc stuff: - fixed lot of misuse in callbacks - chat history fixed - a visual indicator now appear when we have message waiting from a contact - fixed About dialog size issue in webkit - fixed Drag'n'Drop for webkit - defaut room to join is now libervia@conference.libervia.org
author Goffi <goffi@goffi.org>
date Tue, 31 May 2011 17:06:59 +0200
parents 4fa3d57f72f8
children 9d8e79ac4c9c
comparison
equal deleted inserted replaced
61:80c490e6a1a7 62:12e889a683ce
142 _contacts_list = ListBox() 142 _contacts_list = ListBox()
143 143
144 def updateContactCb(sender): 144 def updateContactCb(sender):
145 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex()) 145 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
146 self.host.bridge.call('updateContact', None, _jid, '', _dialog.getSelectedGroups()) 146 self.host.bridge.call('updateContact', None, _jid, '', _dialog.getSelectedGroups())
147 print "contactUpdated"
148 147
149 def onContactChange(_list): 148 def onContactChange(_list):
150 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex()) 149 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
151 groups = self.host.contact_panel.getContactGroups(_jid) 150 groups = self.host.contact_panel.getContactGroups(_jid)
152 _dialog.setGroupsSelected(groups) 151 _dialog.setGroupsSelected(groups)
200 _dialog.hide() 199 _dialog.hide()
201 200
202 _main_panel = VerticalPanel() 201 _main_panel = VerticalPanel()
203 _label = Label("Discussion room:") 202 _label = Label("Discussion room:")
204 _edit = TextBox() 203 _edit = TextBox()
205 _edit.setText('libervia@conference.tazar.int') 204 _edit.setText('libervia@conference.libervia.org')
206 hpanel = HorizontalPanel() 205 hpanel = HorizontalPanel()
207 hpanel.add(_label) 206 hpanel.add(_label)
208 hpanel.add(_edit) 207 hpanel.add(_edit)
209 _main_panel.add(hpanel) 208 _main_panel.add(hpanel)
210 button_panel = HorizontalPanel() 209 button_panel = HorizontalPanel()
234 233
235 def __init__(self): 234 def __init__(self):
236 DropWidget.__init__(self) 235 DropWidget.__init__(self)
237 236
238 def onDragEnter(self, event): 237 def onDragEnter(self, event):
239 print "drag enter"
240 self.addStyleName('dragover') 238 self.addStyleName('dragover')
241 DOM.eventPreventDefault(event) 239 DOM.eventPreventDefault(event)
242 240
243 def onDragLeave(self, event): 241 def onDragLeave(self, event):
244 print "\ndrag leave"
245 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ 242 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\
246 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1: 243 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1:
247 #We check that we are inside widget's box, and we don't remove the style in this case because 244 #We check that we are inside widget's box, and we don't remove the style in this case because
248 #if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we 245 #if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we
249 #don't want that 246 #don't want that
258 row = DOM.getParent(cell) 255 row = DOM.getParent(cell)
259 return (row.rowIndex, cell.cellIndex) 256 return (row.rowIndex, cell.cellIndex)
260 257
261 258
262 def onDrop(self, event): 259 def onDrop(self, event):
263 print "Empty Panel: onDrop"
264 dt = event.dataTransfer 260 dt = event.dataTransfer
265 #'text', 'text/plain', and 'Text' are equivalent. 261 #'text', 'text/plain', and 'Text' are equivalent.
266 try: 262 try:
267 item = dt.getData("text/plain") 263 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed
268 item_type = dt.getData("type") 264 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and
265 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report
266 #item_type = dt.getData("type")
269 print "message: %s" % item 267 print "message: %s" % item
270 print "type: %s" % item_type 268 print "type: %s" % item_type
271 except: 269 except:
272 print "no message found" 270 print "no message found"
273 item='&nbsp;' 271 item='&nbsp;'
277 _new_panel = MicroblogPanel(self.host, item) 275 _new_panel = MicroblogPanel(self.host, item)
278 _new_panel.setAcceptedGroup(item) 276 _new_panel.setAcceptedGroup(item)
279 self.host.FillMicroblogPanel(_new_panel) 277 self.host.FillMicroblogPanel(_new_panel)
280 elif item_type=="CONTACT": 278 elif item_type=="CONTACT":
281 _contact = JID(item) 279 _contact = JID(item)
280 self.host.contact_panel.setContactMessageWaiting(_contact.bare, False)
282 _new_panel = ChatPanel(self.host, _contact) 281 _new_panel = ChatPanel(self.host, _contact)
283 _new_panel.historyPrint() 282 _new_panel.historyPrint()
284 elif item_type=="CONTACT_TITLE": 283 elif item_type=="CONTACT_TITLE":
285 _new_panel = MicroblogPanel(self.host, accept_all=True) 284 _new_panel = MicroblogPanel(self.host, accept_all=True)
286 self.host.FillMicroblogPanel(_new_panel) 285 self.host.FillMicroblogPanel(_new_panel)
429 type = "STATUS" 428 type = "STATUS"
430 elif isinstance(self.host.selected, ChatPanel): 429 elif isinstance(self.host.selected, ChatPanel):
431 type = "ONE2ONE" 430 type = "ONE2ONE"
432 target = str(self.host.selected.target) 431 target = str(self.host.selected.target)
433 else: 432 else:
434 print self.host.selected 433 print "Unknown selected host:",self.host.selected
435 type = "UNKNOWN" 434 type = "UNKNOWN"
436 return (type, target) 435 return (type, target)
437 436
438 def onKeyPress(self, sender, keycode, modifiers): 437 def onKeyPress(self, sender, keycode, modifiers):
439 _txt = self.getText() 438 _txt = self.getText()
548 547
549 def changeStatus(self, new_status): 548 def changeStatus(self, new_status):
550 self.status = new_status or '&nbsp;' 549 self.status = new_status or '&nbsp;'
551 self.setHTML(self.__getContent()) 550 self.setHTML(self.__getContent())
552 551
553 def onClick(self, sender, event): 552 def onClick(self, sender):
554 #As status is the default target of uniBar, we don't want to select anything if click on it 553 #As status is the default target of uniBar, we don't want to select anything if click on it
555 self.host.select(None) 554 self.host.select(None)
556 555
557 class ChatText(HTMLPanel): 556 class ChatText(HTMLPanel):
558 557
653 def doAttachChildren(self): 652 def doAttachChildren(self):
654 #We need to force the use of a panel subclass method here, else 653 #We need to force the use of a panel subclass method here, else
655 #the event will not propagate to children 654 #the event will not propagate to children
656 ScrollPanelWrapper.doAttachChildren(self) 655 ScrollPanelWrapper.doAttachChildren(self)
657 656
658 def onClick(self, sender, event): 657 def onClick(self, sender):
659 self.host.select(self) 658 self.host.select(self)
660 659
661 def setUserNick(self, nick): 660 def setUserNick(self, nick):
662 """Set the nick of the user, usefull for e.g. change the color of the user""" 661 """Set the nick of the user, usefull for e.g. change the color of the user"""
663 self.nick = nick 662 self.nick = nick
668 self.occupants_list.clear() 667 self.occupants_list.clear()
669 for nick in nicks: 668 for nick in nicks:
670 self.occupants_list.addOccupant(nick) 669 self.occupants_list.addOccupant(nick)
671 670
672 def userJoined(self, nick, data): 671 def userJoined(self, nick, data):
673 print "userJoined:", nick, data
674 self.occupants_list.addOccupant(nick) 672 self.occupants_list.addOccupant(nick)
675 self.printInfo("=> %s has joined the room" % nick) 673 self.printInfo("=> %s has joined the room" % nick)
676 674
677 def userLeft(self, nick, data): 675 def userLeft(self, nick, data):
678 print "userLeft:", nick, data
679 self.occupants_list.removeOccupant(nick) 676 self.occupants_list.removeOccupant(nick)
680 self.printInfo("<= %s has left the room" % nick) 677 self.printInfo("<= %s has left the room" % nick)
681 678
682 def historyPrint(self, size=20): 679 def historyPrint(self, size=20):
683 """Print the initial history""" 680 """Print the initial history"""
684 def getHistoryCB(history): 681 def getHistoryCB(history):
685 stamps=history.keys() 682 stamps=history.keys()
686 stamps.sort() 683 stamps.sort()
687 for stamp in stamps: 684 for stamp in stamps:
688 self.printMessage(history[stamp][0], history[stamp][1], stamp) 685 self.printMessage(history[stamp][0], history[stamp][1], stamp)
689 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, str(self.target), 20) 686 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, 20)
690 687
691 def printInfo(self, msg, type='normal'): 688 def printInfo(self, msg, type='normal'):
692 """Print general info 689 """Print general info
693 @param msg: message to print 690 @param msg: message to print
694 @type: one of: 691 @type: one of:
756 self.tabBar.setVisible(False) 753 self.tabBar.setVisible(False)
757 self.addStyleName('mainTabPanel') 754 self.addStyleName('mainTabPanel')
758 Window.addWindowResizeListener(self) 755 Window.addWindowResizeListener(self)
759 756
760 def onWindowResized(self, width, height): 757 def onWindowResized(self, width, height):
761 print "onWindowResized"
762 tab_panel_elt = self.getElement() 758 tab_panel_elt = self.getElement()
763 _elts = doc().getElementsByClassName('gwt-TabBar') 759 _elts = doc().getElementsByClassName('gwt-TabBar')
764 if not _elts.length: 760 if not _elts.length:
765 print ("ERROR: not TabBar found, it should exist !") 761 print ("ERROR: not TabBar found, it should exist !")
766 tab_bar_h = 0 762 tab_bar_h = 0