comparison browser_side/base_widget.py @ 243:63e9b680d3e7

browser_side, blog: better PEP8 compliance
author souliane <souliane@mailoo.org>
date Tue, 15 Oct 2013 17:19:03 +0200
parents 0ed09cc0566f
children 28d3315a8003
comparison
equal deleted inserted replaced
242:a25aa882e09a 243:63e9b680d3e7
17 17
18 You should have received a copy of the GNU Affero General Public License 18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
24 from pyjamas.ui.AbsolutePanel import AbsolutePanel 24 from pyjamas.ui.AbsolutePanel import AbsolutePanel
25 from pyjamas.ui.VerticalPanel import VerticalPanel 25 from pyjamas.ui.VerticalPanel import VerticalPanel
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel 26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
27 from pyjamas.ui.ScrollPanel import ScrollPanel 27 from pyjamas.ui.ScrollPanel import ScrollPanel
60 self.addStyleName('dragover') 60 self.addStyleName('dragover')
61 DOM.eventPreventDefault(event) 61 DOM.eventPreventDefault(event)
62 62
63 def onDragLeave(self, event): 63 def onDragLeave(self, event):
64 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ 64 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\
65 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth() - 1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight() - 1: 65 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth() - 1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight() - 1:
66 # We check that we are inside widget's box, and we don't remove the style in this case because 66 # We check that we are inside widget's box, and we don't remove the style in this case because
67 # if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we 67 # if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we
68 # don't want that 68 # don't want that
69 self.removeStyleName('dragover') 69 self.removeStyleName('dragover')
70 70
71 def onDragOver(self, event): 71 def onDragOver(self, event):
72 DOM.eventPreventDefault(event) 72 DOM.eventPreventDefault(event)
73 73
74 def _getCellAndRow(self, grid, event): 74 def _getCellAndRow(self, grid, event):
75 """Return cell and row index where the event is occuring""" 75 """Return cell and row index where the event is occuring"""
76 cell = grid.getEventTargetCell(event) 76 cell = grid.getEventTargetCell(event)
77 row = DOM.getParent(cell) 77 row = DOM.getParent(cell)
78 return (row.rowIndex, cell.cellIndex) 78 return (row.rowIndex, cell.cellIndex)
79
80 79
81 def onDrop(self, event): 80 def onDrop(self, event):
82 DOM.eventPreventDefault(event) 81 DOM.eventPreventDefault(event)
83 dt = event.dataTransfer 82 dt = event.dataTransfer
84 # 'text', 'text/plain', and 'Text' are equivalent. 83 # 'text', 'text/plain', and 'Text' are equivalent.
135 for panel in _unempty_panels: 134 for panel in _unempty_panels:
136 td_elt = panel.getElement().parentNode 135 td_elt = panel.getElement().parentNode
137 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)""" 136 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)"""
138 #FIXME: delete object ? Check the right way with pyjamas 137 #FIXME: delete object ? Check the right way with pyjamas
139 138
139
140 class WidgetHeader(AbsolutePanel, LiberviaDragWidget): 140 class WidgetHeader(AbsolutePanel, LiberviaDragWidget):
141 141
142 def __init__(self, parent, title): 142 def __init__(self, parent, title):
143 AbsolutePanel.__init__(self) 143 AbsolutePanel.__init__(self)
144 self.add(title) 144 self.add(title)
564 564
565 def setRowSpan(self, row, col, value): 565 def setRowSpan(self, row, col, value):
566 cellFormatter = self.flextable.getFlexCellFormatter() 566 cellFormatter = self.flextable.getFlexCellFormatter()
567 return cellFormatter.setRowSpan(row, col, value) 567 return cellFormatter.setRowSpan(row, col, value)
568 568
569
569 class DropTab(Label, DropWidget): 570 class DropTab(Label, DropWidget):
570 571
571 def __init__(self, tab_panel, text): 572 def __init__(self, tab_panel, text):
572 Label.__init__(self, text) 573 Label.__init__(self, text)
573 DropWidget.__init__(self, tab_panel) 574 DropWidget.__init__(self, tab_panel)
578 579
579 def _getIndex(self): 580 def _getIndex(self):
580 """ get current index of the DropTab """ 581 """ get current index of the DropTab """
581 # XXX: awful hack, but seems the only way to get index 582 # XXX: awful hack, but seems the only way to get index
582 return self.tab_panel.tabBar.panel.getWidgetIndex(self.getParent().getParent()) - 1 583 return self.tab_panel.tabBar.panel.getWidgetIndex(self.getParent().getParent()) - 1
583
584 584
585 def onDragEnter(self, event): 585 def onDragEnter(self, event):
586 #if self == LiberviaDragWidget.current: 586 #if self == LiberviaDragWidget.current:
587 # return 587 # return
588 self.addStyleName('dragover') 588 self.addStyleName('dragover')
631 return 631 return
632 632
633 widgets_panel = self.tab_panel.getWidget(self._getIndex()) 633 widgets_panel = self.tab_panel.getWidget(self._getIndex())
634 widgets_panel.addWidget(_new_panel) 634 widgets_panel.addWidget(_new_panel)
635 635
636
636 class MainTabPanel(TabPanel): 637 class MainTabPanel(TabPanel):
637 638
638 def __init__(self, host): 639 def __init__(self, host):
639 TabPanel.__init__(self) 640 TabPanel.__init__(self)
640 self.host = host 641 self.host = host
655 tab_bar_h = 0 656 tab_bar_h = 0
656 else: 657 else:
657 tab_bar_h = _elts.item(0).offsetHeight 658 tab_bar_h = _elts.item(0).offsetHeight
658 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5 659 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5
659 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 660 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5
660 self.setWidth("%s%s" % (ideal_width, "px")); 661 self.setWidth("%s%s" % (ideal_width, "px"))
661 self.setHeight("%s%s" % (ideal_height, "px")); 662 self.setHeight("%s%s" % (ideal_height, "px"))
662 663
663 def add(self, widget, text=''): 664 def add(self, widget, text=''):
664 tab = DropTab(self, text) 665 tab = DropTab(self, text)
665 TabPanel.add(self, widget, tab, False) 666 TabPanel.add(self, widget, tab, False)
666 if self.getWidgetCount() > 1: 667 if self.getWidgetCount() > 1:
675 self.tabBar.setVisible(False) 676 self.tabBar.setVisible(False)
676 self.host.resize() 677 self.host.resize()
677 self.selectTab(0) 678 self.selectTab(0)
678 else: 679 else:
679 self.selectTab(widgets_count - 1) 680 self.selectTab(widgets_count - 1)
680