aluntzer / gtknodes

A GTK-based library to create functional flow graphs with the ability to pass arbitrary data between connected elements.
Other
92 stars 10 forks source link

Issues with the drag-and-drop feature #14

Open vgrcs opened 1 year ago

vgrcs commented 1 year ago

Hi,

I have two questions about drag-and-drop: 1) noticed that the events "node_drag_begin" and "node_drag_end" are not being sent to the Node instances like "node_func_clicked" is. Can it be possible to forward these events? 2) when a Node is clicked on and sent to the foreground, and a drag-and-drop begins, the Node on the background is moved. This behavior can be observed in the example "demo.c". Can this be fixed?

Thank you, Vítor

aluntzer commented 1 year ago

Hi,

first of all, sorry for the late response. I was pretty busy and then I forgot.

@1: these are actually forwarded, but you need to connect the signals to a callback function in the implementation of a particular node.

So for example to add this in node_step.c you would connect 'node-drag-begin' in node_step_init() like so:

static void node_step_init(NodeStep *step)
{
        /*...*/
    g_signal_connect(G_OBJECT(step), "node-drag-begin",
             G_CALLBACK(node_step_drag_begin), NULL);
        /*...*/
}

and the somewhere in the file add the callback:

static void node_step_drag_begin(GtkWidget *widget, GdkDragContext *context,  gpointer user_data)
{
    g_print("DRAG BEGIN!");
}

@2: The z-order of the event window that belongs to a node was not raised along with the drawing order. The behaviour should now be as expected.

vgrcs commented 1 year ago

Hi,

As for @2, the behaviour is now the expected one. But the code snippets above still don't product the print expected for @1. Also, in the Python example, I've tried this:

    self.set_label("Image Mask")
    self.connect("node_func_clicked", self.remove)
    self.connect("node_drag_begin", self.drag_begin)

but the callback is not invoked.

aluntzer commented 1 year ago

Hi,

maybe we were thinking of different events. The node-drag signals were emitted when the drag on the actual node socket starts. I'm sorry for the confusing nomenclature.

I have changed the signal names to node-socket-drag-begin and node-socket-drag-end and added new signals node-drag-begin and node-drag-end which are emitted by the the drag/move action in the GtkNodeView

In case of the python example you would connect to the signal in the class init:

class Demo(object):
    def __init__(self):
# ...
          self.node_view.connect("node-drag-begin", self.node_drag_begin)
          self.node_view.connect("node-drag-end", self.node_drag_end)
# ...
     def node_drag_begin(self, node_view, node):
          print("node-drag-begin")

     def node_drag_end(self, node_view, node):
          print("node-drag-end")

I hope this helps with what you are trying to achieve. In case you really need these signals to be emitted by the node, i.e. forwarded from a NodeView to a Node, I can add that as well.

vgrcs commented 1 year ago

Hi,

You were right about the event names. Now it works as excepted.

Thanks.