comparison browser_side/list_manager.py @ 396:a71fcc27f231

browser_side: small improvements for ListManager
author souliane <souliane@mailoo.org>
date Tue, 11 Mar 2014 10:45:52 +0100
parents 83454ba70a9c
children 63f8469b4ad3
comparison
equal deleted inserted replaced
395:98cd5387d291 396:a71fcc27f231
28 from pyjamas.ui.DialogBox import DialogBox 28 from pyjamas.ui.DialogBox import DialogBox
29 from pyjamas.ui.KeyboardListener import KEY_ENTER 29 from pyjamas.ui.KeyboardListener import KEY_ENTER
30 from pyjamas.ui.MouseListener import MouseHandler 30 from pyjamas.ui.MouseListener import MouseHandler
31 from pyjamas.ui.FocusListener import FocusHandler 31 from pyjamas.ui.FocusListener import FocusHandler
32 from pyjamas.ui.DropWidget import DropWidget 32 from pyjamas.ui.DropWidget import DropWidget
33 from pyjamas.ui.DragWidget import DragWidget
34 from pyjamas.Timer import Timer 33 from pyjamas.Timer import Timer
35 from pyjamas import DOM 34 from pyjamas import DOM
36 35
37 from base_panels import PopupMenuPanel 36 from base_panels import PopupMenuPanel
38 37 from base_widget import DragLabel
39 38
40 # HTML content for the removal button (image or text) 39 # HTML content for the removal button (image or text)
41 REMOVE_BUTTON = '<span class="recipientRemoveIcon">x</span>' 40 REMOVE_BUTTON = '<span class="recipientRemoveIcon">x</span>'
42 41
43 # Item to be considered for an empty list box selection. 42 # Item to be considered for an empty list box selection.
241 def registerPopupMenuPanel(self, entries, hide, callback): 240 def registerPopupMenuPanel(self, entries, hide, callback):
242 "Register a popup menu panel that will be bound to all contact keys elements." 241 "Register a popup menu panel that will be bound to all contact keys elements."
243 self.popup_menu = PopupMenuPanel(entries=entries, hide=hide, callback=callback, style={"item": self.style["popupMenuItem"]}) 242 self.popup_menu = PopupMenuPanel(entries=entries, hide=hide, callback=callback, style={"item": self.style["popupMenuItem"]})
244 243
245 244
246 class DragAutoCompleteTextBox(AutoCompleteTextBox, DragWidget, MouseHandler, FocusHandler): 245 class DragAutoCompleteTextBox(AutoCompleteTextBox, DragLabel, MouseHandler, FocusHandler):
247 """A draggable AutoCompleteTextBox which is used for representing a contact. 246 """A draggable AutoCompleteTextBox which is used for representing a contact.
248 This class is NOT generic because of the onDragEnd method which call methods 247 This class is NOT generic because of the onDragEnd method which call methods
249 from ListPanel. It's probably not reusable for another scenario. 248 from ListPanel. It's probably not reusable for another scenario.
250 """ 249 """
251 250
252 def __init__(self, parent, event_cbs, style): 251 def __init__(self, parent, event_cbs, style):
253 AutoCompleteTextBox.__init__(self) 252 AutoCompleteTextBox.__init__(self)
254 DragWidget.__init__(self) 253 DragLabel.__init__(self, '', 'CONTACT_TEXTBOX') # The group prefix "@" is already in text so we use only the "CONTACT_TEXTBOX" type
255 self._parent = parent 254 self._parent = parent
256 self.event_cbs = event_cbs 255 self.event_cbs = event_cbs
257 self.style = style 256 self.style = style
258 self.addMouseListener(self) 257 self.addMouseListener(self)
259 self.addFocusListener(self) 258 self.addFocusListener(self)
273 else: 272 else:
274 self.addStyleName(self.style["textBox-invalid"]) 273 self.addStyleName(self.style["textBox-invalid"])
275 self.valid = valid 274 self.valid = valid
276 275
277 def onDragStart(self, event): 276 def onDragStart(self, event):
278 dt = event.dataTransfer 277 self._text = self.getText()
279 # The group prefix "@" is already in text so we use only the "CONTACT" type 278 DragLabel.onDragStart(self, event)
280 dt.setData('text/plain', "%s\n%s" % (self.getText(), "CONTACT_TEXTBOX")) 279 self._parent.setTargetDropCell(None)
281 self.setSelectionRange(len(self.getText()), 0) 280 self.setSelectionRange(len(self.getText()), 0)
282 281
283 def onDragEnd(self, event): 282 def onDragEnd(self, event):
284 if self.getText() == "": 283 target = self._parent.target_drop_cell # parent or another ListPanel
284 if self.getText() == "" or target is None:
285 return 285 return
286 target = self._parent.target_drop_cell # parent or another ListPanel
287 self.event_cbs["drop"](self, target) 286 self.event_cbs["drop"](self, target)
288 287
289 def setRemoveButton(self): 288 def setRemoveButton(self):
290 289
291 def remove_cb(sender): 290 def remove_cb(sender):
390 def __init__(self, parent, entry, style={}): 389 def __init__(self, parent, entry, style={}):
391 """Initialization with a button and a DragAutoCompleteTextBox.""" 390 """Initialization with a button and a DragAutoCompleteTextBox."""
392 FlowPanel.__init__(self, Visible=(False if entry["optional"] else True)) 391 FlowPanel.__init__(self, Visible=(False if entry["optional"] else True))
393 drop_cbs = {"GROUP": lambda panel, item: self.addContact("@%s" % item), 392 drop_cbs = {"GROUP": lambda panel, item: self.addContact("@%s" % item),
394 "CONTACT": lambda panel, item: self.addContact(item), 393 "CONTACT": lambda panel, item: self.addContact(item),
394 "CONTACT_TITLE": lambda panel, item: self.addContact('@@'),
395 "CONTACT_TEXTBOX": lambda panel, item: self.setTargetDropCell(panel) 395 "CONTACT_TEXTBOX": lambda panel, item: self.setTargetDropCell(panel)
396 } 396 }
397 DropCell.__init__(self, drop_cbs) 397 DropCell.__init__(self, drop_cbs)
398 self.style = style 398 self.style = style
399 self.addStyleName(self.style["keyPanel"]) 399 self.addStyleName(self.style["keyPanel"])
529 @property 529 @property
530 def target_drop_cell(self): 530 def target_drop_cell(self):
531 """@return: the panel where something has been dropped.""" 531 """@return: the panel where something has been dropped."""
532 return self._parent.target_drop_cell 532 return self._parent.target_drop_cell
533 533
534 @target_drop_cell.setter
535 def target_drop_cell(self, target_drop_cell):
536 """@param target_drop_cell: the panel where something has been dropped."""
537 self.setTargetDropCell(target_drop_cell)
538
539 def setTargetDropCell(self, target_drop_cell): 534 def setTargetDropCell(self, target_drop_cell):
535 """
536 XXX: Property setter here would not make it, you need a proper method!
537 @param target_drop_cell: the panel where something has been dropped."""
540 self._parent.target_drop_cell = target_drop_cell 538 self._parent.target_drop_cell = target_drop_cell
541 539
542 540
543 class ContactChooserPanel(DialogBox): 541 class ContactChooserPanel(DialogBox):
544 """Display the contacts chooser dialog. This has been implemented while 542 """Display the contacts chooser dialog. This has been implemented while