(self, widget, drag_context, x, y, selection_data,
            info, _time, data)
Something has been dragged into the terminal. Handle it as either a
        URL or another terminal.
Something has been dragged into the terminal. Handle it as either a
        URL or another terminal.
Something has been dragged into the terminal . Handle it as either a URL or another terminal .
def on_drag_data_received(self, widget, drag_context, x, y, selection_data,
            info, _time, data):
        """Something has been dragged into the terminal. Handle it as either a
        URL or another terminal."""
        # FIXME this code is a mess that I don't quite understand how it works.
        dbg('drag data received of type: %s' % (selection_data.get_data_type()))
        # print(selection_data.get_urls())
        if Gtk.targets_include_text(drag_context.list_targets()) or \
           Gtk.targets_include_uri(drag_context.list_targets()):
            # copy text with no modification yet to destination
            txt = selection_data.get_data()
            # https://bugs.launchpad.net/terminator/+bug/1518705
            if info == self.TARGET_TYPE_MOZ:
                 txt = txt.decode('utf-16')
                 # KDE ends it's text/x-moz-url text with CRLF, :shrug:
                 if not txt.endswith('\r\n'):
                   txt = txt.split('\n')[0]
            else:
                 txt = txt.decode()

            txt_lines = txt.split( "\r\n" )
            if txt_lines[-1] == '':
                for line in txt_lines[:-1]:
                    if line[0:7] != 'file://':
                        txt = txt.replace('\r\n','\n')
                        break
                else:
                    # It is a list of crlf terminated file:// URL. let's
                    # iterate over all elements except the last one.
                    str=''
                    for fname in txt_lines[:-1]:
                        fname = "'%s'" % urlunquote(fname[7:].replace("'",
                                                                      '\'\\\'\''))
                        str += fname + ' '
                    txt = str
            # Never send a CRLF to the terminal from here
            txt = txt.rstrip('\r\n')
            for term in self.terminator.get_target_terms(self):
                term.feed(txt.encode())
            return

        widgetsrc = data.terminator.terminals[int(selection_data.get_data())]
        srcvte = Gtk.drag_get_source_widget(drag_context)
        # check if computation requireds
        if (isinstance(srcvte, Gtk.EventBox) and
                srcvte == self.titlebar) or srcvte == widget:
            return

        srchbox = widgetsrc

        # The widget argument is actually a Vte.Terminal(). Turn that into a
        # terminatorlib Terminal()
        maker = Factory()
        while True:
            widget = widget.get_parent()
            if not widget:
                # We've run out of widgets. Something is wrong.
                err('Failed to find Terminal from vte')
                return
            if maker.isinstance(widget, 'Terminal'):
                break

        dsthbox = widget

        dstpaned = dsthbox.get_parent()
        srcpaned = srchbox.get_parent()

        pos = self.get_location(widget, x, y)

        srcpaned.remove(widgetsrc)
        dstpaned.split_axis(dsthbox, pos in ['top', 'bottom'], None, widgetsrc, pos in ['bottom', 'right'])
        srcpaned.hoover()
        widgetsrc.ensure_visible_and_focussed()
def on_drag_data_received ( self , widget , drag_context , x , y , selection_data , info , _time , data ) : # FIXME this code is a mess that I don't quite understand how it works. dbg ( 'drag data received of type: %s' % ( selection_data . get_data_type ( ) ) ) # print(selection_data.get_urls()) if Gtk . targets_include_text ( drag_context . list_targets ( ) ) or Gtk . targets_include_uri ( drag_context . list_targets ( ) ) : # copy text with no modification yet to destination txt = selection_data . get_data ( ) # https://bugs.launchpad.net/terminator/+bug/1518705 if info == self . TARGET_TYPE_MOZ : txt = txt . decode ( 'utf-16' ) # KDE ends it's text/x-moz-url text with CRLF, :shrug: if not txt . endswith ( '\r\n' ) : txt = txt . split ( '\n' ) [ 0 ] else : txt = txt . decode ( ) txt_lines = txt . split ( "\r\n" ) if txt_lines [ - 1 ] == '' : for line in txt_lines [ : - 1 ] : if line [ 0 : 7 ] != 'file://' : txt = txt . replace ( '\r\n' , '\n' ) break else : # It is a list of crlf terminated file:// URL. let's # iterate over all elements except the last one. str = '' for fname in txt_lines [ : - 1 ] : fname = "'%s'" % urlunquote ( fname [ 7 : ] . replace ( "'" , '\'\\\'\'' ) ) str += fname + ' ' txt = str # Never send a CRLF to the terminal from here txt = txt . rstrip ( '\r\n' ) for term in self . terminator . get_target_terms ( self ) : term . feed ( txt . encode ( ) ) return widgetsrc = data . terminator . terminals [ int ( selection_data . get_data ( ) ) ] srcvte = Gtk . drag_get_source_widget ( drag_context ) # check if computation requireds if ( isinstance ( srcvte , Gtk . EventBox ) and srcvte == self . titlebar ) or srcvte == widget : return srchbox = widgetsrc # The widget argument is actually a Vte.Terminal(). Turn that into a # terminatorlib Terminal() maker = Factory ( ) while True : widget = widget . get_parent ( ) if not widget : # We've run out of widgets. Something is wrong. err ( 'Failed to find Terminal from vte' ) return if maker . isinstance ( widget , 'Terminal' ) : break dsthbox = widget dstpaned = dsthbox . get_parent ( ) srcpaned = srchbox . get_parent ( ) pos = self . get_location ( widget , x , y ) srcpaned . remove ( widgetsrc ) dstpaned . split_axis ( dsthbox , pos in [ 'top' , 'bottom' ] , None , widgetsrc , pos in [ 'bottom' , 'right' ] ) srcpaned . hoover ( ) widgetsrc . ensure_visible_and_focussed ( )