Exemple #1
0
 def _drag_start(self, event):
     near=self.listbox.nearest(event.y)
     if not self.listbox.select_includes(near):
         self._dnd_selection(near)
     tuples=self.selected_with_idx()
     items=DraggedItemsCopy(self, tuples)
     Tkdnd.dnd_start(items, event)
Exemple #2
0
def on_dnd_start(Event):
    """
    This is invoked by InitiationObject to start the drag and drop process
    """
    #Create an object to be dragged
    ThingToDrag = Dragged()
    #Pass the object to be dragged and the event to Tkdnd
    Tkdnd.dnd_start(ThingToDrag, Event)
Exemple #3
0
 def on_dnd_start(Event):
     """
     This is invoked by InitiationObject to start the drag and drop process.
     """
     #Create an object to be dragged
     ThingToDrag = Dragged()
     #Pass the object to be dragged and the event to Tkdnd
     Tkdnd.dnd_start(ThingToDrag,Event)
	def _descPress(self, event):
		self.root.balloon.withdraw()
		self.root._select(self)
		if self.dnd:
			Tkdnd.dnd_start(self, event)
			event.widget.bind('<Leave>', self._ignore, add=1)
			event.widget.bind('<Motion>', self._ignore, add=1)
		return 'break'
Exemple #5
0
    def on_dnd_start(self, event, type):
        # Create placeholder info and add it to tree
        print("dnd entered")
        ID = len(Workspace.current.get_tree().fields)
        info = self.info_from_type(ID, type)

        Workspace.current.get_tree().fields.insert(ID, info)

        ThingToDrag = Draggable(self, ID)
        Tkdnd.dnd_start(ThingToDrag, event)
Exemple #6
0
 def _drag_start(self, event):
     if self.notify_drag_start:
         self.notify_drag_start()
     near=self.listbox.nearest(event.y)
     if not self.listbox.select_includes(near):
         self._dnd_selection(near)
     tuples=self.selected_with_idx()
     #XXX# self.del_idx(map(lambda t: t[0], tuples))
     items=DraggedItems(self, tuples)
     Tkdnd.dnd_start(items, event)
     self._dnd_selection(self.listbox.nearest(event.y))
Exemple #7
0
 def start_move_fixation(self, event):
     # TODO Does this really belong here?
     # What is the closest fixation?
     i1, d1 = self.sc1.closest_fixation(event.x, event.y)
     i2, d2 = self.sc2.closest_fixation(event.x, event.y)
     if (d1 < d2):
         sc = self.sc1
         i = i1
     else:
         sc = self.sc2
         i = i2
     sc._translate = lambda dx, dy: sc.translate_fixation(i, dx, dy)
     sc._command = lambda dx, dy: TranslateFixationCommand(sc, i, dx, dy)
     Tkdnd.dnd_start(sc, event)
Exemple #8
0
 def start_move_fixation(self, event):
     # TODO Does this really belong here?
     # What is the closest fixation?
     i1, d1 = self.sc1.closest_fixation(event.x, event.y)
     i2, d2 = self.sc2.closest_fixation(event.x, event.y)
     if (d1 < d2):
         sc = self.sc1
         i = i1
     else:
         sc = self.sc2
         i = i2
     sc._translate = lambda dx, dy:sc.translate_fixation(i, dx, dy)
     sc._command = lambda dx, dy: TranslateFixationCommand(sc, i, dx, dy)
     Tkdnd.dnd_start(sc, event)
Exemple #9
0
 def on_dnd_start(event):
     """
     This is invoked by initiation_object to start the drag and drop process
     """
     #Create an object to be dragged
     try:
         image = Image.open("emoji/monsters/1.gif")
     except IOError:
         tkMessageBox.showerror(
             "Open file",
             "No emoji available! Ensure there are images in the folders emoji/land and emoji/monsters"
         )
         return
     thing_to_drag = Dragged(image)
     thing_to_drag.offset_x=20
     thing_to_drag.offset_y=10
     #Pass the object to be dragged and the event to Tkdnd
     Tkdnd.dnd_start(thing_to_drag,event)
Exemple #10
0
 def PVT_click(self, event):
     """Handle mouse clicks by kicking off possible drag'n'drop
     processing"""
     if self.widget.drop_callback:
         if Tkdnd.dnd_start(self, event):
             x1, y1, x2, y2 = self.widget.bbox(self.symbol)
             self.x_off = (x1 - x2) / 2
             self.y_off = (y1 - y2) / 2
     else:
         # no callback, don't bother with drag'n'drop
         self.widget.drag = 0
         self.dnd_end(None, None)
Exemple #11
0
 def PVT_click(self, event):
     """Handle mouse clicks by kicking off possible drag'n'drop
     processing"""
     if self.widget.drop_callback:
         if Tkdnd.dnd_start(self, event):
             x1, y1, x2, y2=self.widget.bbox(self.symbol)
             self.x_off=(x1-x2)/2
             self.y_off=(y1-y2)/2
     else:
         # no callback, don't bother with drag'n'drop
         self.widget.drag=0
         self.dnd_end(None, None)
    def Press(self, Event):
        # Save our current status
        self.OriginalCanvas = self.Canvas
        self.OriginalID = self.ID
        self.OriginalLabel = self.Label

        # Make phantom invisible
        self.Label.__hide__()

        # Say we have no current label
        self.ID = None
        self.Label = None
        self.Canvas = None

        # Ask Tkdnd to start the drag operation
        if Tkdnd.dnd_start(self, Event):
            # Save where the mouse pointer was in the label so it stays in the
            #    same relative position as we drag it around
            self.OffsetX, self.OffsetY = MouseInWidget(self.OriginalLabel,
                                                       Event)
            # Draw a label of ourself for the user to drag around
            XY = MouseInWidget(self.OriginalCanvas, Event)
            self.Appear(self.OriginalCanvas, XY)
Exemple #13
0
 def press(self,event):
     """
     User has clicked on a label representing us. Initiate drag and drop.
     """
     #Save our current label as the Original label
     self.original_id = self.id
     self.original_canvas = self.canvas
     self.canvas.itemconfig(self.id,state=HIDDEN)
     #Say we have no current label    
     self.id = None
     self.canvas = None
     #Ask Tkdnd to start the drag operation
     if Tkdnd.dnd_start(self,event):
         #Save where the mouse pointer was in the label so it stays in the
         #    same relative position as we drag it around
         self.offset_x, self.offset_y = mouse_in_item(self.original_canvas,self.original_id,event)
         #print self.offset_x, self.offset_y
         #Draw a label of ourself for the user to drag around
         xy = mouse_in_widget(self.original_canvas,event)
         width = self.original_canvas.winfo_width()
         height = self.original_canvas.winfo_height()
         bounds = (0,0,width,height)
         self.appear(self.original_canvas,xy,bounds)
	def cs_dragStart(self, event):
		# start drag
		Tkdnd.dnd_start(self, event)
	def dnd_start(self, event):
		Tkdnd.dnd_start(self, event)
 def cs_dragStart(self, event):
     # start drag
     Tkdnd.dnd_start(self, event)
Exemple #17
0
    def Press(self,Event):
        """
        User has clicked on a label representing us. Initiate drag and drop.
        
        There is a problem, er, opportunity here. In this case we would like to
            act as both the InitiationObject (because the user clicked on us
            and it't up to us to start the drag and drop) but we also want to
            act as the dragged object (because it's us the user wants to drag
            around). If we simply pass ourself to "Tkdnd" as the dragged object
            it won't work because the entire drag and drop process is moved
            along by <motion> events as a result of a binding by the widget
            on which the user clicked. That widget is the label which represents
            us and it get moved around by our "move" method. It also gets
            DELETED by our "vanish" method if the user moves it off the current
            canvas, which is a perfectly legal thing from them to do. If the
            widget which is driving the process gets deleted, the whole drag and
            drop grinds to a real quick halt. We use a little sleight of hand to
            get around this:
            
            o  We take the label which is currently representing us (self.Label)
               and we make it into an invisible phantom by setting its text to ''
               and settings its relief to FLAT. It is now, so to speak, a polar
               bear in a snowstorm. It's still there, but it blends in with the
               rest of then canvas on which it sits. 
            o  We move all the information about the phantom label (Canvas, ID
               and Label) into variables which store information about the 
               previous label (PreviousCanvas, PreviousID and PreviousLabel)
            o  We set self.Canvas and friends to None, which indicates that we 
               don't have a label representing us on the canvas. This is a bit
               of a lie (the phantom is technically on the canvas) but it does no
               harm.
            o  We call "self.Appear" which, noting that don't have a label
               representing us on the canvas, promptly draws one for us, which
               gets saved as self.Canvas etc.
               
        We went to all this trouble so that:
        
            o  The original widget on which the user clicked (now the phantom)
               could hang around driving the drag and drop until it is done, and
            o  The user has a label (the one just created by Appear) which they 
               can drag around, from canvas to canvas as desired, until they 
               drop it. THIS one can get deleted from the current canvas and
               redrawn on another canvas without Anything Bad happening.           

        From the users viewpoint the whole thing is seamless: they think
            the ARE dragging around the original label, but they are not. To 
            make it really clear what is happening, go to the top of the
            code and set "LeavePhantomVisible" to 1. Then when you drag an 
            existing object, you will see the phantom.

        The phantom is resolved by routine "dnd_end" above. If the user 
            drops us on a canvas, then we take up residence on the canvas and
            the phantom label, no longer needed, is deleted. If the user tries
            to drop us in the middle of nowhere, then there will be no
            'current' label for us (because we are in the middle of nowhere)
            and thus we resurrect the phantom label which in this case
            continues to represent us.    

        Note that this whole deal happens ONLY when the user clicks on an
            EXISTING instance of us. In the case where the user clicks over
            the button marked "InitiationObject" then it it that button that
            IS the initiation object, it creates a copy of us and the whole
            opportunity never happens, since the "InitiationObject" button 
            is never in any danger of being deleted.
        """
        Blab(1, "Dragged.press")
        #Save our current label as the Original label
        self.OriginalID = self.ID
        self.OriginalLabel = self.Label
        self.OriginalCanvas = self.Canvas
        #Make the phantom invisible (unless the user asked to see it)
        self.WidgetHide(self.OriginalLabel)
        #Say we have no current label    
        self.ID = None
        self.Canvas = None
        self.Label = None
        #Ask Tkdnd to start the drag operation
        if Tkdnd.dnd_start(self,Event):
            #Save where the mouse pointer was in the label so it stays in the
            #    same relative position as we drag it around
            self.OffsetX, self.OffsetY = MouseInWidget(self.OriginalLabel,self.OriginalCanvas,Event,Xlate=0)
            #Draw a label of ourself for the user to drag around
            XY = MouseInWidget(self.OriginalCanvas,self.OriginalCanvas,Event)
            self.Appear(self.OriginalCanvas,XY)
Exemple #18
0
 def start_move_scanpath(self, event):
     sc = self.find_closest_scanpath(event.x, event.y)
     # NOTE This mess could be avoided if fixations were objects of their own.
     sc._translate = sc.translate
     sc._command = lambda dx, dy: TranslateScanpathCommand(sc, dx, dy)
     Tkdnd.dnd_start(sc, event)
Exemple #19
0
 def Press(self,Event):
     """
     User has clicked on a label representing us. Initiate drag and drop.
     There is a problem, er, opportunity here. In this case we would like to
         act as both the InitiationObject (because the user clicked on us
         and it't up to us to start the drag and drop) but we also want to
         act as the dragged object (because it's us the user wants to drag
         around). If we simply pass ourself to "Tkdnd" as the dragged object
         it won't work because the entire drag and drop process is moved
         along by <motion> events as a result of a binding by the widget
         on which the user clicked. That widget is the label which represents
         us and it get moved around by our "move" method. It also gets
         DELETED by our "vanish" method if the user moves it off the current
         canvas, which is a perfectly legal thing from them to do. If the
         widget which is driving the process gets deleted, the whole drag and
         drop grinds to a real quick halt. We use a little sleight of hand to
         get around this:
         1) From the label which is currently representing us (self.Label) 
            we take the text and save it in self.OriginalText. This will allow 
            us to resurrect the label at a later time if so desired. (It turns 
            out we so desire if the user tries to drop us in the middle of 
            nowhere, but that's a different story; see "dnd_end", above).
         2) We take the label which is currently representing us (self.Label)
            and we make it into an invisible phantom by setting its text to ''
            and settings its relief to FLAT. It is now, so to speak, a polar
            bear in a snowstorm. It's still there, but it blends in with the
            rest of then canvas on which it sits. 
         3) We move all the information about the phantom label (Canvas, ID
            and Label) into variables which store information about the 
            previous label (PreviousCanvas, PreviousID and PreviousLabel)
         4) We set self.Canvas and friends to None, which indicates that we 
            don't have a label representing us on the canvas. This is a bit
            of a lie (the phantom is technically on the canvas) but it does no
            harm.
         5) We call "self.Appear" which, noting that don't have a label
            representing us on the canvas, promptly draws one for us, which
            gets saved as self.Canvas etc.
         We went to all this trouble so that:
         a) The original widget on which the user clicked (now the phantom)
            could hang around driving the drag and drop until it is done, and
         b) The user has a label (the one just created by Appear) which they 
            can drag around, from canvas to canvas as desired, until they 
            drop it. THIS one can get deleted from the current canvas and
            redrawn on another canvas without Anything Bad happening.           
         From the users viewpoint the whole thing is seamless: they think
             the ARE dragging around the original label, but they are not. To 
             make it really clear what is happening, go to the top of the
             code and set "LeavePhantomVisible" to 1. Then when you drag an 
             existing object, you will see the phantom.
         The phantom is resolved by routine "dnd_end" above. If the user 
             drops us on a canvas, then we take up residence on the canvas and
             the phantom label, no longer needed, is deleted. If the user tries
             to drop us in the middle of nowhere, then there will be no
             'current' label for us (because we are in the middle of nowhere)
             and thus we resurrect the phantom label which in this case
             continues to represent us.    
         Note that this whole deal happens ONLY when the user clicks on an
             EXISTING instance of us. In the case where the user clicks over
             the button marked "InitiationObject" then it it that button that
             IS the initiation object, it creates a copy of us and the whole
             opportunity never happens, since the "InitiationObject" button 
             is never in any danger of being deleted.
     """
     Blab(1, "Dragged.press")
     #Save our current label as the Original label
     self.OriginalID = self.ID
     self.OriginalLabel = self.Label
     self.OriginalText = self.OriginalLabel['text']
     self.OriginalCanvas = self.Canvas
     #Made the phantom invisible (unless the user asked to see it)
     if LeavePhantomVisible:
         self.OriginalLabel['text'] = '<phantom>'
         self.OriginalLabel['relief']=RAISED
     else:
         self.OriginalLabel['text'] = ''
         self.OriginalLabel['relief']=FLAT
     #Say we have no current label    
     self.ID = None
     self.Canvas = None
     self.Label = None
     #Ask Tkdnd to start the drag operation
     if Tkdnd.dnd_start(self,Event):
         #Save where the mouse pointer was in the label so it stays in the
         #    same relative position as we drag it around
         self.OffsetX, self.OffsetY = MouseInWidget(self.OriginalLabel,Event)
         #Draw a label of ourself for the user to drag around
         XY = MouseInWidget(self.OriginalCanvas,Event)
         self.Appear(self.OriginalCanvas,XY)
 def dnd_start(self, event):
     Tkdnd.dnd_start(self, event)
Exemple #21
0
 def _drag_start(self, event):
     if self.content:
         items=DraggedItemsCopy(self, [(0, self.content)])
         Tkdnd.dnd_start(items, event)
Exemple #22
0
 def start_move_scanpath(self, event):
     sc = self.find_closest_scanpath(event.x, event.y)
     # NOTE This mess could be avoided if fixations were objects of their own.
     sc._translate = sc.translate
     sc._command = lambda dx, dy: TranslateScanpathCommand(sc, dx, dy)
     Tkdnd.dnd_start(sc, event)