Re: [pygtk] Re: Manual drag and drop

2007-11-01 Thread François Ingelrest
The third parameter of drag_begin() should be 1, not
gtk.gdk.BUTTON1_MASK. This constant is a *mask* to test if a
particular bit is set in a field of bits, it's not the value that
represents mouse button 1. If I change that, the D'n'D works fine for
me.

On 10/31/07, Jeffrey Barish <[EMAIL PROTECTED]> wrote:
> I'm still stuck on this problem, so I created a test program.  It evinces
> the same behavior.  I suppose that there is a difference between my
> programs and the one that Francois wrote, but I'm not seeing it.  In the
> test program, DnD works fine when I allow the treeview to initiate it
> automatically (set MANUAL to False).  When I set MANUAL to True, it is no
> longer possible to drag a row to a new location (it is not possible to
> release the drag).  Any help appreciated.
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Re: Manual drag and drop

2007-10-31 Thread Jeffrey Barish
I'm still stuck on this problem, so I created a test program.  It evinces
the same behavior.  I suppose that there is a difference between my
programs and the one that Francois wrote, but I'm not seeing it.  In the
test program, DnD works fine when I allow the treeview to initiate it
automatically (set MANUAL to False).  When I set MANUAL to True, it is no
longer possible to drag a row to a new location (it is not possible to
release the drag).  Any help appreciated.
-- 
Jeffrey Barish
# DND works when I allow GTK to initiate it automatically, but not when I
# initiate it manually.  Set the MANUAL global to select the mode.

import pygtk
import gtk

MANUAL = True

numbers = ('zero', 'one', 'two', 'three', 'four', 'five', 'six')
data = [(str(i), d) for i, d in enumerate(numbers)]

class TreeViewDnDTest:
def __init__(self):
self.drag_context = None

self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("DND Test")
self.window.set_size_request(200, 300)
self.window.connect('delete-event', self.on_delete_event)

self.button = gtk.Button('Text on the button')

self.liststore = gtk.ListStore(str, str)
for item in data:
self.liststore.append(item)

self.treeview = gtk.TreeView(self.liststore)
self.treeview.connect('drag-data-received', self.on_drag_data_received)
if MANUAL:
self.treeview.connect('button-press-event', self.on_treeview_button_press_event)
self.treeview.connect('motion-notify-event', self.on_treeview_motion_notify_event)
self.treeview.connect('button-release-event', self.on_button_release_event)

renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('Int', renderer, text=0)
self.treeview.append_column(column)
column = gtk.TreeViewColumn('Str', renderer, text=1)
self.treeview.append_column(column)

self.button.drag_source_set(gtk.gdk.BUTTON1_MASK,
[('tree_model_row_from_button', gtk.TARGET_SAME_APP, 0)],
gtk.gdk.ACTION_MOVE)
if not MANUAL:
self.treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[('tree_model_row', gtk.TARGET_SAME_WIDGET, 1)],
gtk.gdk.ACTION_MOVE)
self.treeview.enable_model_drag_dest(
[('tree_model_row', 0, 1), ('tree_model_row_from_button', 0, 0)],
gtk.gdk.ACTION_DEFAULT)

self.vbox = gtk.VBox()
self.vbox.pack_start(self.button, False)
self.vbox.pack_start(self.treeview, True)
self.window.add(self.vbox)
self.window.show_all()

def on_delete_event(self, widget, event, data=None):
gtk.main_quit()
return False

def on_drag_data_received(self, treeview, context, x, y, selection,
info, etime):
source_widget = context.get_source_widget()
if source_widget == treeview:
model, source_iter = treeview.get_selection().get_selected()
source_row = model[source_iter]
elif source_widget == self.button:
model = treeview.get_model()
source_row = ('9', 'newrow')

drop_info = treeview.get_dest_row_at_pos(x, y)
if drop_info:
path, position = drop_info
iter = model.get_iter(path)
if (position == gtk.TREE_VIEW_DROP_BEFORE
or position == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
model.insert_before(iter, source_row)
else:
model.insert_after(iter, source_row)
else:
model.append(source_row)
if context.action == gtk.gdk.ACTION_MOVE:
context.finish(True, True, etime)

if MANUAL:
def on_treeview_button_press_event(self, treeview, event):
if event.button == 1:
self.press_start_x = int(event.x)
self.press_start_y = int(event.y)
self.press_start_event = event

def on_treeview_motion_notify_event(self, treeview, event):
if event.state == gtk.gdk.BUTTON1_MASK:
row = self.treeview.get_dest_row_at_pos(int(event.x), int(event.y))
if row:
treepath, drop_pos = row
threshold = treeview.drag_check_threshold(
self.press_start_x, self.press_start_y, int(event.x), int(event.y))
if self.drag_context is None and threshold:
targets = [('tree_model_row', gtk.TARGET_SAME_WIDGET, 1)]
actions = gtk.gdk.ACTION_MOVE
button = gtk.gdk.BUTTON1_MASK
self.drag_context = treeview.drag_begin(targets, actions, button,
self.press_start_event)

def on_button_release_event(self, treeview, event):
print "received button release event"


if __name__ == '__main__':
  

[pygtk] Re: Manual drag and drop

2007-10-26 Thread Jeffrey Barish
Jeffrey Barish wrote:

> Doesn't the appearance of that line indicate
> that there are valid drop locations as specified by the
> enable_model_drag_dest call?

I changed the target in the enable_model_drag_dest() call to something that
was clearly wrong and found that I no longer get the lines showing the drop
location.  I conclude that I have enable_model_drag_dest and drag_begin set
up correctly, so something else is preventing the drag from responding to
the button release.
-- 
Jeffrey Barish

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Re: Manual drag and drop

2007-10-25 Thread Jeffrey Barish
François Ingelrest wrote:

> Maybe you are missing something, because once you call drag_begin(),
> the DnD is automatically handled by GTK. Did you first call
> enable_model_drag_dest() on your tree?

Yes, I did call enable_model_drag_dest.  In fact, it is the same statement
that was already in place before I switched to drag_begin.  Also, I
transplanted the arguments from the original enable_model_drag_source to
the drag_begin call.

When I drag the row, the line appears in the treeview that shows the drop
location (between two rows).  Doesn't the appearance of that line indicate
that there are valid drop locations as specified by the
enable_model_drag_dest call?  When I release the mouse button after
dragging a row to a point above one of those lines, nothing happens -- I am
still dragging.  It isn't that the drag failed -- the drag icon does not
glide back to the source -- but rather it is as if I didn't release the
mouse button.
-- 
Jeffrey Barish

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/