0

I've wrote a simple program that should let archive managers such as Engrampa and Xarchiver to unpack in the destination folder any archive. Here is the sample code:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf
from gi.repository import GdkX11

import Xlib
from Xlib.display import Display
from Xlib import X

XDS_ATOM = Gdk.Atom.intern("XdndDirectSave0",1)
TEXT_ATOM = Gdk.Atom.intern("text/plain",1)


def drag_motion(wid, context, x, y, time):
    Gdk.drag_status(context,Gdk.DragAction(2), time)
    return True

def drag_drop(wid, context, x, y, time):
    wid.drag_get_data(context, context.list_targets()[0], time)
    swin = context.get_source_window()

    xid =swin.get_xid()

    display = Display()
    topw = display.create_resource_object('window', swin.get_xid())

    data2 = topw.get_full_property(display.intern_atom('XdndDirectSave0'),
                           display.intern_atom('text/plain'))
    # 540
    print("data2.property_type::", data2.property_type)
    # b'xds.txt'
    print("data2.value::", data2.value)
    # 8
    print("data2.format::", data2.format)

    fpath = "file:///tmp/"+data2.value.decode()
    data_sent = bytes(fpath, 'utf-8')

    topw.change_property(display.intern_atom('XdndDirectSave0'),
                           display.intern_atom('text/plain'), 8,
                           data_sent,
                           X.PropModeReplace)

    context.finish(True, False, time)

def  drag_data_received(wid, context, x, y, selection, info, time):
    # XdndDirectSave0
    print("get_target::", selection.get_target())
    # None
    print("get_text::", selection.get_text())
    # b'E'
    print("get_data::", selection.get_data())

    context.finish(True, False, time)

w = Gtk.Window()
w.set_size_request(200, 150)

##
w.drag_dest_set(0, [], 0)
w.connect('drag_motion', drag_motion)
w.connect('drag_drop', drag_drop)
w.connect('drag_data_received', drag_data_received)
##
w.connect("destroy", Gtk.main_quit)
w.show_all()
Gtk.main()

The program run without any error but Engrampa do not unpack anything. In the terminal I read that Engrampa send the 'E' message, and a dialog appears telling me that it cannot extract the archive in the folder [empty]. Maybe the problem is with the method change_property because before I get the data I should receive. I need help to get the program working. I've also wrote a python/gtk2 similar program using the native method context.source_window.property_change instead of that one, and works perfectly with Engrampa and Xarchiver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.