Mercurial > libervia-web
comparison browser_side/base_widget.py @ 198:ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 07 Mar 2013 01:16:13 +0100 |
parents | 0fc32122a877 |
children | aa76793da353 |
comparison
equal
deleted
inserted
replaced
197:0fc32122a877 | 198:ab239b3b67b3 |
---|---|
76 row = DOM.getParent(cell) | 76 row = DOM.getParent(cell) |
77 return (row.rowIndex, cell.cellIndex) | 77 return (row.rowIndex, cell.cellIndex) |
78 | 78 |
79 | 79 |
80 def onDrop(self, event): | 80 def onDrop(self, event): |
81 DOM.eventPreventDefault(event) | |
81 dt = event.dataTransfer | 82 dt = event.dataTransfer |
82 #'text', 'text/plain', and 'Text' are equivalent. | 83 #'text', 'text/plain', and 'Text' are equivalent. |
83 try: | 84 try: |
84 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed | 85 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed |
85 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and | 86 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and |
89 print "type: %s" % item_type | 90 print "type: %s" % item_type |
90 except: | 91 except: |
91 print "no message found" | 92 print "no message found" |
92 item=' ' | 93 item=' ' |
93 item_type = None | 94 item_type = None |
94 DOM.eventPreventDefault(event) | |
95 if item_type == "WIDGET": | 95 if item_type == "WIDGET": |
96 if not LiberviaDragWidget.current: | 96 if not LiberviaDragWidget.current: |
97 print "ERROR: No widget registered in LiberviaDragWidget !" | 97 print "ERROR: No widget registered in LiberviaDragWidget !" |
98 return | 98 return |
99 _new_panel = LiberviaDragWidget.current | 99 _new_panel = LiberviaDragWidget.current |
519 | 519 |
520 def setRowSpan(self, row, col, value): | 520 def setRowSpan(self, row, col, value): |
521 cellFormatter = self.flextable.getFlexCellFormatter() | 521 cellFormatter = self.flextable.getFlexCellFormatter() |
522 return cellFormatter.setRowSpan(row, col, value) | 522 return cellFormatter.setRowSpan(row, col, value) |
523 | 523 |
524 class DropTab(Label, DropWidget): | |
525 | |
526 def __init__(self, tab_panel, text): | |
527 Label.__init__(self, text) | |
528 DropWidget.__init__(self, tab_panel) | |
529 self.tab_panel = tab_panel | |
530 self.setStyleName('dropCell') | |
531 self.setWordWrap(False) | |
532 DOM.setStyleAttribute(self.getElement(), "min-width", "30px") | |
533 | |
534 def _getIndex(self): | |
535 """ get current index of the DropTab """ | |
536 # XXX: awful hack, but seems the only way to get index | |
537 return self.tab_panel.tabBar.panel.getWidgetIndex(self.getParent().getParent()) - 1 | |
538 | |
539 | |
540 def onDragEnter(self, event): | |
541 #if self == LiberviaDragWidget.current: | |
542 # return | |
543 self.addStyleName('dragover') | |
544 DOM.eventPreventDefault(event) | |
545 | |
546 def onDragLeave(self, event): | |
547 self.removeStyleName('dragover') | |
548 | |
549 def onDragOver(self, event): | |
550 DOM.eventPreventDefault(event) | |
551 | |
552 def onDrop(self, event): | |
553 DOM.eventPreventDefault(event) | |
554 self.removeStyleName('dragover') | |
555 if self._getIndex() == self.tab_panel.tabBar.getSelectedTab(): | |
556 # the widget come from the DragTab, so nothing to do, we let it there | |
557 return | |
558 | |
559 # FIXME: quite the same stuff as in DropCell, need some factorisation | |
560 dt = event.dataTransfer | |
561 #'text', 'text/plain', and 'Text' are equivalent. | |
562 try: | |
563 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed | |
564 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and | |
565 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report | |
566 #item_type = dt.getData("type") | |
567 print "message: %s" % item | |
568 print "type: %s" % item_type | |
569 except: | |
570 print "no message found" | |
571 item=' ' | |
572 item_type = None | |
573 if item_type == "WIDGET": | |
574 if not LiberviaDragWidget.current: | |
575 print "ERROR: No widget registered in LiberviaDragWidget !" | |
576 return | |
577 _new_panel = LiberviaDragWidget.current | |
578 _new_panel.getWidgetsPanel().removeWidget(_new_panel) | |
579 elif item_type in DropCell.drop_keys: | |
580 _new_panel = DropCell.drop_keys[item_type](self.tab_panel.host,item) | |
581 else: | |
582 print "WARNING: unmanaged item type" | |
583 return | |
584 | |
585 widgets_panel = self.tab_panel.getWidget(self._getIndex()) | |
586 widgets_panel.addWidget(_new_panel) | |
587 | |
524 class MainTabPanel(TabPanel): | 588 class MainTabPanel(TabPanel): |
525 | 589 |
526 def __init__(self, host): | 590 def __init__(self, host): |
527 TabPanel.__init__(self) | 591 TabPanel.__init__(self) |
528 self.host=host | 592 self.host=host |
546 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5 | 610 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5 |
547 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 | 611 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 |
548 self.setWidth("%s%s" % (ideal_width, "px")); | 612 self.setWidth("%s%s" % (ideal_width, "px")); |
549 self.setHeight("%s%s" % (ideal_height, "px")); | 613 self.setHeight("%s%s" % (ideal_height, "px")); |
550 | 614 |
551 def add(self, widget, tabText=None, asHTML=False): | 615 def add(self, widget, text=''): |
552 TabPanel.add(self, widget, tabText, asHTML) | 616 tab = DropTab(self, text) |
617 TabPanel.add(self, widget, tab, False) | |
553 if self.getWidgetCount()>1: | 618 if self.getWidgetCount()>1: |
554 self.tabBar.setVisible(True) | 619 self.tabBar.setVisible(True) |
555 self.host.resize() | 620 self.host.resize() |
556 | 621 |
557 def onWidgetPanelRemove(self, panel): | 622 def onWidgetPanelRemove(self, panel): |