comparison browser_side/panels.py @ 84:8f35e9970e7f

browser side: new widget handling: - new design integration improved (ChatPanel is now working) - widget now register themselves for event handling
author Goffi <goffi@goffi.org>
date Sun, 26 Jun 2011 23:23:22 +0200
parents 68d360caeecb
children a8f027738c16
comparison
equal deleted inserted replaced
83:68d360caeecb 84:8f35e9970e7f
105 _new_panel.historyPrint() 105 _new_panel.historyPrint()
106 elif item_type=="CONTACT_TITLE": 106 elif item_type=="CONTACT_TITLE":
107 _new_panel = MicroblogPanel(self.host, accept_all=True) 107 _new_panel = MicroblogPanel(self.host, accept_all=True)
108 self.host.FillMicroblogPanel(_new_panel) 108 self.host.FillMicroblogPanel(_new_panel)
109 else: 109 else:
110 return 110 return False
111 self.host.mpanels.remove(self) 111 if isinstance(self, LiberviaWidget):
112 self.host.mpanels.append(_new_panel) 112 self.host.unregisterWidget(self)
113 if not isinstance(_new_panel, LiberviaWidget):
114 print ('WARNING: droping an object which is not a class of LiberviaWidget')
113 grid = self.getParent() 115 grid = self.getParent()
114 row_idx, cell_idx = self._getCellAndRow(grid, event) 116 row_idx, cell_idx = self._getCellAndRow(grid, event)
115 if self.host.selected == self: 117 if self.host.selected == self:
116 self.host.select(None) 118 self.host.select(None)
117 self.removeFromParent() 119 self.removeFromParent()
123 for panel in _unempty_panels: 125 for panel in _unempty_panels:
124 td_elt = panel.getElement().parentNode 126 td_elt = panel.getElement().parentNode
125 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width) 127 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)
126 #FIXME: delete object ? Check the right way with pyjamas 128 #FIXME: delete object ? Check the right way with pyjamas
127 129
128 class LiberviaWidget(DropCell, VerticalPanel): 130 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler):
129 """Libervia's widget which can replace itself with a dropped widget on DnD""" 131 """Libervia's widget which can replace itself with a dropped widget on DnD"""
130 132
131 def __init__(self, title=''): 133 def __init__(self, host, title='', selectable=False):
134 """Init the widget
135 @param host: SatWebFrontend object
136 @param title: title show in the header of the widget
137 @param selectable: True is widget can be selected by user"""
132 VerticalPanel.__init__(self) 138 VerticalPanel.__init__(self)
133 DropCell.__init__(self) 139 DropCell.__init__(self)
134 self.title_id = HTMLPanel.createUniqueId() 140 ClickHandler.__init__(self)
135 self.setting_button_id = HTMLPanel.createUniqueId() 141 self.host = host
136 self.close_button_id = HTMLPanel.createUniqueId() 142 self.__selectable = selectable
143 self.__title_id = HTMLPanel.createUniqueId()
144 self.__setting_button_id = HTMLPanel.createUniqueId()
145 self.__close_button_id = HTMLPanel.createUniqueId()
137 header = AbsolutePanel() 146 header = AbsolutePanel()
138 self.title = Label(title) 147 self.__title = Label(title)
139 self.title.setStyleName('widgetHeader_title') 148 self.__title.setStyleName('widgetHeader_title')
140 header.add(self.title) 149 header.add(self.__title)
141 #header.setCellVerticalAlignment(self.title, HasAlignment.ALIGN_MIDDLE) 150 #header.setCellVerticalAlignment(self.title, HasAlignment.ALIGN_MIDDLE)
142 #header.setCellWidth(self.title, '100%') 151 #header.setCellWidth(self.title, '100%')
143 button_group_wrapper = SimplePanel() 152 button_group_wrapper = SimplePanel()
144 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') 153 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
145 button_group = HorizontalPanel() 154 button_group = HorizontalPanel()
154 header.add(button_group_wrapper) 163 header.add(button_group_wrapper)
155 self.add(header) 164 self.add(header)
156 header.addStyleName('widgetHeader') 165 header.addStyleName('widgetHeader')
157 self.setSize('100%', '100%') 166 self.setSize('100%', '100%')
158 self.addStyleName('widget') 167 self.addStyleName('widget')
168 if self.__selectable:
169 self.addClickListener(self)
170 self.host.registerWidget(self)
171
172 def onClick(self, sender):
173 self.host.select(self)
159 174
160 def setTitle(self, text): 175 def setTitle(self, text):
161 """change the title in the header of the widget 176 """change the title in the header of the widget
162 @param text: text of the new title""" 177 @param text: text of the new title"""
163 self.title.setText(text) 178 self.__title.setText(text)
179
180 def isSelectable(self):
181 return self.__selectable
182
183 def setSelectable(self, selectable):
184 if not self.__selectable:
185 try:
186 self.removeClickListener(self)
187 except ValueError:
188 pass
189 if self.selectable and not self in self._clickListeners:
190 self.addClickListener(self)
191 self.__selectable = selectable
164 192
165 def setWidget(self, widget, scrollable=True): 193 def setWidget(self, widget, scrollable=True):
166 """Set the widget that will be in the body of the LiberviaWidget 194 """Set the widget that will be in the body of the LiberviaWidget
167 @param widget: widget to put in the body 195 @param widget: widget to put in the body
168 @param scrollable: if true, the widget will be in a ScrollPanelWrapper""" 196 @param scrollable: if true, the widget will be in a ScrollPanelWrapper"""
363 391
364 def __init__(self, host, title='', accept_all=False): 392 def __init__(self, host, title='', accept_all=False):
365 """Panel used to show microblog 393 """Panel used to show microblog
366 @param title: title of the panel 394 @param title: title of the panel
367 @param accept_all: if true, show every message, without filtering jids""" 395 @param accept_all: if true, show every message, without filtering jids"""
368 LiberviaWidget.__init__(self, title) 396 LiberviaWidget.__init__(self, host, title)
369 #ScrollPanelWrapper.__init__(self) 397 #ScrollPanelWrapper.__init__(self)
370 #DropCell.__init__(self) 398 #DropCell.__init__(self)
371 self.host = host
372 self.accept_all = accept_all 399 self.accept_all = accept_all
373 self.accepted_groups = [] 400 self.accepted_groups = []
374 self.entries = {} 401 self.entries = {}
375 self.vpanel = VerticalPanel() 402 self.vpanel = VerticalPanel()
376 self.vpanel.setStyleName('microblogPanel') 403 self.vpanel.setStyleName('microblogPanel')
474 501
475 def clear(self): 502 def clear(self):
476 self.occupants_list.clear() 503 self.occupants_list.clear()
477 AbsolutePanel.clear(self) 504 AbsolutePanel.clear(self)
478 505
479 class ChatPanel(DropCell, ClickHandler, ScrollPanelWrapper): 506 class ChatPanel(LiberviaWidget):
480 507
481 def __init__(self, host, target, type='one2one'): 508 def __init__(self, host, target, type='one2one'):
482 """Panel used for conversation (one 2 one or group chat) 509 """Panel used for conversation (one 2 one or group chat)
483 @param host: SatWebFrontend instance 510 @param host: SatWebFrontend instance
484 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) 511 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room)
485 @param type: one2one for simple conversation, group for MUC""" 512 @param type: one2one for simple conversation, group for MUC"""
486 ScrollPanelWrapper.__init__(self) 513 LiberviaWidget.__init__(self, host, target.bare, selectable = True)
487 DropCell.__init__(self)
488 ClickHandler.__init__(self)
489 self.vpanel = VerticalPanel() 514 self.vpanel = VerticalPanel()
490 self.vpanel.setSize('100%','100%') 515 self.vpanel.setSize('100%','100%')
491 self.host = host
492 self.type = type 516 self.type = type
493 self.nick = None 517 self.nick = None
494 if not target: 518 if not target:
495 print "ERROR: Empty target !" 519 print "ERROR: Empty target !"
496 return 520 return
497 self.target = target 521 self.target = target
498 title="%s" % target.bare 522 self.__body = AbsolutePanel()
499 _class = ['mb_panel_header'] 523 self.__body.setStyleName('chatPanel_body')
500 self.header = HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),html_sanitize(title)))
501 self.header.setStyleName('chatHeader')
502 self.body = AbsolutePanel()
503 self.body.setStyleName('chatPanel_body')
504 chat_area = HorizontalPanel() 524 chat_area = HorizontalPanel()
505 chat_area.setStyleName('chatArea') 525 chat_area.setStyleName('chatArea')
506 if type == 'group': 526 if type == 'group':
507 self.occupants_list = OccupantsList() 527 self.occupants_list = OccupantsList()
508 chat_area.add(self.occupants_list) 528 chat_area.add(self.occupants_list)
509 self.body.add(chat_area) 529 self.__body.add(chat_area)
510 self.content = AbsolutePanel() 530 self.content = AbsolutePanel()
511 self.content.setStyleName('chatContent') 531 self.content.setStyleName('chatContent')
512 self.content_scroll = ScrollPanelWrapper(self.content) 532 self.content_scroll = ScrollPanelWrapper(self.content)
513 chat_area.add(self.content_scroll) 533 chat_area.add(self.content_scroll)
514 chat_area.setCellWidth(self.content_scroll, '100%') 534 chat_area.setCellWidth(self.content_scroll, '100%')
515 self.vpanel.add(self.header) 535 self.vpanel.add(self.__body)
516 self.vpanel.setCellHeight(self.header, '1%') 536 self.addStyleName('chatPanel')
517 self.vpanel.add(self.body)
518 self.setWidget(self.vpanel) 537 self.setWidget(self.vpanel)
519 self.setStyleName('chatPanel') 538
520 self.addClickListener(self) 539 """def doDetachChildren(self):
521
522 def doDetachChildren(self):
523 #We need to force the use of a panel subclass method here, 540 #We need to force the use of a panel subclass method here,
524 #for the same reason as doAttachChildren 541 #for the same reason as doAttachChildren
525 ScrollPanelWrapper.doDetachChildren(self) 542 ScrollPanelWrapper.doDetachChildren(self)
526 543
527 def doAttachChildren(self): 544 def doAttachChildren(self):
528 #We need to force the use of a panel subclass method here, else 545 #We need to force the use of a panel subclass method here, else
529 #the event will not propagate to children 546 #the event will not propagate to children
530 ScrollPanelWrapper.doAttachChildren(self) 547 ScrollPanelWrapper.doAttachChildren(self)"""
531 548
532 def onClick(self, sender):
533 self.host.select(self)
534
535 def setUserNick(self, nick): 549 def setUserNick(self, nick):
536 """Set the nick of the user, usefull for e.g. change the color of the user""" 550 """Set the nick of the user, usefull for e.g. change the color of the user"""
537 self.nick = nick 551 self.nick = nick
538 552
539 def setPresents(self, nicks): 553 def setPresents(self, nicks):
577 self.content.add(_wid) 591 self.content.add(_wid)
578 592
579 593
580 def printMessage(self, from_jid, msg, timestamp=None): 594 def printMessage(self, from_jid, msg, timestamp=None):
581 """Print message in chat window. Must be implemented by child class""" 595 """Print message in chat window. Must be implemented by child class"""
596 print "print message:",msg
582 _jid=JID(from_jid) 597 _jid=JID(from_jid)
583 nick = _jid.node if self.type=='one2one' else _jid.resource 598 nick = _jid.node if self.type=='one2one' else _jid.resource
584 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user 599 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user
585 if msg.startswith('/me '): 600 if msg.startswith('/me '):
586 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') 601 self.printInfo('* %s %s' % (nick, msg[4:]),type='me')