On Wed, Jan 08, 2003 at 09:48:30AM -0500, Oscar Lopez wrote:
> Hi:
> 
> I need to know how to remove an item from a Clist but using the mouse, for example, 
>I select the item with the mouse and then I press the "delete" button and the item of 
>the Clist is delete, how do I do this???

First of all, don't bother using GTK+ 1.2 if you can avoid it. GTK+ 2.0
and PyGTK 1.99 are much better. If you are using GTK+ 2.0 you are
probably better off, in the long run, learning how to use GtkTreeView,
which is suitable for both trees and lists. 

> 
> I did the folowing:
> 
> win.listmon.connect("select_row", win.mouse_sel)
> 
> def mouse_sel(win,listmon,row,column,data=None):
> 
> return row

Please, if you are going to post code snippets to the list, take the
time to format and indent them properly.

Since you connected mouse_sel to the select-row signal, mouse_sel is a
signal handler. Signal handlers allow you to do arbitrary processing in
response to the signal you are connected to. The return value of a
signal handler should either be TRUE or FALSE, indicating whether the
current emission of the signal should be continued on to the next
handler in line, or should it be dropped.

For your particular task you are not doing any special handling when a
row is selected. The CList takes care of remembering what the currently
selected row is so you don't even need to store the current row. So you
don't even need to handle the select-row signal.

Also, I would strongly suggest that you do not use win, and instead use
self. This is such a universally accepted convention that it is foolish
to break it if you want others to understand what you're doing.


> 
> Then I connect delete button with the function delete:
> 
> win.buttondel.connect("clicked", win.delete,win.mouse_sel,win.mouse_sel)
> 
> def delete(win,clistmon,row,column,data=None):
> 
> print "The row to delete is :"
> 
> print row
> 
> win.listmon.remove(row)
> 
> return
> 
> I did that but the parameter "row" to the function isnt row, is another thing, what 
>did Ido wrong, explain me more and tell me how to do the right thing, i?m new in Py 
>GTK and I?m lost, I need to do this job for tomorrow, thanks for your help. Please 
>answer me to the e-mail. Thanks a lot
> 

Ok, if you look at the docs for GtkButton you will see that the clicked
signal does not pass any extra parameters to the handler. 
In PyGTK the connect function takes the: signal name (string), 
handler (callable object). Any additional parameters you pass will be
passed to you particular signal handler. So your delete handler is going
to be passed the button that the signal is being emitted from (not the
clist as your variable seems to indicate), and the win.mouse_sel (it'll
be passed twice). win.mouse_sel is simply the callable bound method
mouse_sel. 
This is certainly not what you want.

What you probably want:

self.buttondel.connect("clicked", self.delete)

def delete(self, button):
    self.clistmon.remove(self.clistmon.selection[0])
    return TRUE

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to