comparison src/browser/sat_browser/base_widget.py @ 594:a099990f77a6 frontends_multi_profiles

browser side: border widgets are now visible on drag start + they float right or left in the cell
author Goffi <goffi@goffi.org>
date Fri, 06 Feb 2015 19:11:02 +0100
parents a5019e62c3e9
children 9054793ab60d
comparison
equal deleted inserted replaced
593:b97c85b8a47e 594:a099990f77a6
45 import base_menu 45 import base_menu
46 46
47 47
48 class DragLabel(DragWidget): 48 class DragLabel(DragWidget):
49 49
50 def __init__(self, text, _type): 50 def __init__(self, text, type_, host=None):
51 """Base of Drag n Drop mecanism in Libervia
52
53 @param text: data embedded with in drag n drop operation
54 @param type_: type of data that we are dragging
55 @param host: if not None, the host will be use to highlight BorderWidgets
56 """
51 DragWidget.__init__(self) 57 DragWidget.__init__(self)
58 self.host = host
52 self._text = text 59 self._text = text
53 self._type = _type 60 self.type_ = type_
54 61
55 def onDragStart(self, event): 62 def onDragStart(self, event):
56 dt = event.dataTransfer 63 dt = event.dataTransfer
57 dt.setData('text/plain', "%s\n%s" % (self._text, self._type)) 64 dt.setData('text/plain', "%s\n%s" % (self._text, self.type_))
58 dt.setDragImage(self.getElement(), 15, 15) 65 dt.setDragImage(self.getElement(), 15, 15)
66 if self.host is not None:
67 current_panel = self.host.tab_panel.getCurrentPanel()
68 for widget in current_panel.widgets:
69 if isinstance(widget, BorderWidget):
70 widget.addStyleName('borderWidgetOnDrag')
71
72 def onDragEnd(self, event):
73 if self.host is not None:
74 current_panel = self.host.tab_panel.getCurrentPanel()
75 for widget in current_panel.widgets:
76 if isinstance(widget, BorderWidget):
77 widget.removeStyleName('borderWidgetOnDrag')
59 78
60 79
61 class LiberviaDragWidget(DragLabel): 80 class LiberviaDragWidget(DragLabel):
62 """ A DragLabel which keep the widget being dragged as class value """ 81 """ A DragLabel which keep the widget being dragged as class value """
63 current = None # widget currently dragged 82 current = None # widget currently dragged
64 83
65 def __init__(self, text, _type, widget): 84 def __init__(self, text, type_, widget):
66 DragLabel.__init__(self, text, _type) 85 DragLabel.__init__(self, text, type_, widget.host)
67 self.widget = widget 86 self.widget = widget
68 87
69 def onDragStart(self, event): 88 def onDragStart(self, event):
70 LiberviaDragWidget.current = self.widget 89 LiberviaDragWidget.current = self.widget
71 DragLabel.onDragStart(self, event) 90 DragLabel.onDragStart(self, event)
72 91
73 def onDragEnd(self, event): 92 def onDragEnd(self, event):
93 DragLabel.onDragEnd(self, event)
74 LiberviaDragWidget.current = None 94 LiberviaDragWidget.current = None
75 95
76 96
77 class DropCell(DropWidget): 97 class DropCell(DropWidget):
78 """Cell in the middle grid which replace itself with the dropped widget on DnD""" 98 """Cell in the middle grid which replace itself with the dropped widget on DnD"""