def _mouse_move(self, event): """ Handles the mouse moving over the window. """ # Update tooltips if no mouse button is currently pressed: if self._dragging is None: feature = self._feature_at(event) if feature is not self._tooltip_feature: self._tooltip_feature = feature tooltip = '' if feature is not None: tooltip = feature.tooltip wx.ToolTip.Enable(False) wx.ToolTip.Enable(True) self.control.SetToolTip(wx.ToolTip(tooltip)) # Check to see if the mouse has left the window, and mark it # completed if it has: x, y = event.GetX(), event.GetY() dx, dy = self.control.GetSizeTuple() if (x < 0) or (y < 0) or (x >= dx) or (y >= dy): self.control.ReleaseMouse() self._tooltip_feature = None self.completed = True return # Check to see if we are in 'drag mode' yet: if not self._dragging: x, y = self._xy if (abs(x - event.GetX()) + abs(y - event.GetY())) < 3: return self._dragging = True # Check to see if user is trying to drag a 'feature': feature = self._feature if feature is not None: feature._set_event(event) prefix = button = '' if event.RightIsDown(): button = 'right_' if event.ControlDown(): prefix = 'control_' elif event.AltDown(): prefix = 'alt_' elif event.ShiftDown(): prefix = 'shift_' object = getattr(feature, '%s%sdrag' % (prefix, button))() if object is not None: self.control.ReleaseMouse() self._feature = None self.completed = True self.dock_control.pre_drag_all(object) PythonDropSource(self.control, object) self.dock_control.post_drag_all() self._dragging = None
def _element_begin_drag_changed(self, element): """ Called when a drag is started on a element. """ # We ask the label provider for the actual value to drag. drag_value = self.label_provider.get_drag_value(self, element) # Start the drag. PythonDropSource(self.control, drag_value) return
def _mouse_move(self, event): """Handles the mouse being moved.""" if self._x is not None: if (abs(self._x - event.GetX()) + abs(self._y - event.GetY())) >= 3: self.control.ReleaseMouse() self._x = None if self._is_file: FileDropSource(self.control, self.value) else: PythonDropSource(self.control, self.value) event.Skip()
def _begin_drag(self, event): """Handles the user beginning a drag operation with the left mouse button. """ if PythonDropSource is not None: adapter = self.adapter object, name = self.object, self.name index = event.GetIndex() selected = self._get_selected() drag_items = [] # Collect all of the selected items to drag: for index in selected: drag = adapter.get_drag(object, name, index) if drag is None: return drag_items.append(drag) # Save the drag item indices, so that we can later handle a # completed 'move' operation: self._drag_indices = selected try: # If only one item is being dragged, drag it as an item, not a # list: if len(drag_items) == 1: drag_items = drag_items[0] # Perform the drag and drop operation: ds = PythonDropSource(self.control, drag_items) # If moves are allowed and the result was a drag move: if (ds.result == wx.DragMove) and ( self._drag_local or self.factory.drag_move ): # Then delete all of the original items (in reverse order # from highest to lowest, so the indices don't need to be # adjusted): indices = self._drag_indices indices.reverse() for index in indices: adapter.delete(object, name, index) finally: self._drag_indices = None self._drag_local = False
def _on_tree_begin_drag(self, event): """ Called when a drag operation is starting on a tree item. """ # Get the node, its id and the point where the event occurred. data, wxid, flags, point = self._unpack_event(event, event.GetItem()) if point == (0, 0): # Apply workaround for GTK. point = self.point_left_clicked wxid, flags = self.HitTest(point) data = self.control.GetItemData(wxid) if data is not None: populated, node = data # Give the model a chance to veto the drag. if self.model.is_draggable(node): # We ask the model for the actual value to drag. drag_value = self.model.get_drag_value(node) # fixme: This is a terrible hack to get the binding x passed # during a drag operation. Bindings should probably *always* # be dragged and our drag and drop mechanism should allow # extendable ways to extract the actual data. from pyface.wx.drag_and_drop import clipboard clipboard.node = [node] # Make sure that the tree selection is updated before we start # the drag. If we don't do this then if the first thing a # user does is drag a tree item (i.e., without a separate click # to select it first) then the selection appears empty. self.selection = self._get_selection() # Start the drag. PythonDropSource(self.control, drag_value, self) # Trait event notification. self.node_begin_drag = node else: event.Veto() return