Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Example:
Drop a file in a glade designed window and it triggers Handler.open_from_path(path)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Set your window "main_win" Widget drag_data_received callback to on_main_win_drag_data_received. The URI is printed in the status bar.

from gi.repository import Gtk, Gdk

builder = Gtk.Builder()
builder.add_from_file("assets/ui/design.glade")

class UI():
    def __init__(self):
        #get window
        self.window = builder.get_object("main_win")
        #add drop target
        self.window.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
        self.window.drag_dest_add_uri_targets()
        self.window.set_title("Main Window")
        #show the window
        self.window.show_all()

#get an instance of the gui specific code
ui = UI()

class Worker():
    """
    Real worker code
    """

#get a worker instance
worker = Worker()

def log(uri):
    status = builder.get_object("status_bar")
    context = status.get_context_id('')
    status.pop(context)
    status.push(context, uri.rstrip())

class Handler():
    """
    Gtk callback handlers
    """
    def on_main_win_delete_event(self, *args, **kwds):
        Gtk.main_quit()
    def on_main_win_drag_data_received(self, widget, drag_context, x, y, data, info, time):
        log(data.get_data())

#connect handlers
builder.connect_signals(Handler())

if __name__ == '__main__':
    Gtk.main()

Tested and functional.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.