Results 1 to 8 of 8

Thread: [pygtk] getting row data from mouse click?

  1. #1
    Join Date
    Nov 2004
    Beans
    68
    Distro
    Gutsy Gibbon Testing

    [pygtk] getting row data from mouse click?

    In a treeview/liststore, I'm trying to figure out how to catch a mouseclick and return the data from that particular row...perhaps by connecting a signal to a treeview or something? I'd love input from anyone who's familiar w/ pygtk...thanks.
    Last edited by stateq2; January 8th, 2005 at 11:43 PM.

  2. #2
    Join Date
    Oct 2004
    Beans
    18

    Re: [pygtk] getting row data from mouse click?

    Yep, signal to treeview on click or mouse down event then grab the current row(s) from teh tree/list store. Don't have any examples off hand...

  3. #3
    Join Date
    Oct 2004
    Beans
    33

    Re: [pygtk] getting row data from mouse click?

    Do you have any links to the documentation of the pygtk api? I'd really appreciate it (and go write some nice-looking gnome-apps)!

  4. #4
    Join Date
    Oct 2004
    Location
    New York City
    Beans
    102
    Distro
    Ubuntu

    Re: [pygtk] getting row data from mouse click?

    You can find an API reference here: http://www.pygtk.org/reference.html

    I'm sure I've done what you are asking before, but I also don't have any examples of getting the current row at the moment...
    We rarely notice freedom. What we notice is the lack of freedom, and I'm afraid by then it is too late.
    Be a good Ubuntu citizen - Report bugs || http://programmer-art.org

  5. #5
    Join Date
    Oct 2004
    Beans
    33

    Re: [pygtk] getting row data from mouse click?

    Quote Originally Posted by Daniel G. Taylor
    You can find an API reference here: http://www.pygtk.org/reference.html

    I'm sure I've done what you are asking before, but I also don't have any examples of getting the current row at the moment...
    Ah, thanks!

  6. #6
    Join Date
    Nov 2004
    Beans
    68
    Distro
    Gutsy Gibbon Testing

    Re: [pygtk] getting row data from mouse click?

    Quote Originally Posted by iwasbiggs
    Yep, signal to treeview on click or mouse down event then grab the current row(s) from teh tree/list store. Don't have any examples off hand...
    thanks, that's the basic idea. I did a little more searching and found this page
    http://www.async.com.br/faq/pygtk/in...ick&req=search

    so basically, I added an event to my treeview, as well as connected the signal:
    Code:
    self.treeview.add_events(gtk.gdk.BUTTON_PRESS_MASK)
    self.treeview.connect('button_press_event', self.selectTest)
    the signal was to this callback:
    Code:
    def selectTest(self, widget, event):
                    if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
                            print 'left double click'
    
                            #get data from highlighted selection       
                            treeselection = self.treeview.get_selection()
                            (model, iter) = treeselection.get_selected()
                            name_of_data = self.liststore.get_value(iter, 0)
    
                            #do something w/ 'name_of_data' here
    and it worked great thanks for the info.....now to impliment threading

  7. #7
    Join Date
    Oct 2004
    Location
    New York City
    Beans
    102
    Distro
    Ubuntu

    Re: [pygtk] getting row data from mouse click?

    Quote Originally Posted by stateq2
    now to impliment threading
    Be careful with GTK + threading!

    Only access the GUI from a single thread (or use a queued dispatcher)!

    If you start to get seemingly random segmentation faults, it's most likely that different threads are touching data simultaneously or when they aren't supposed to.

    Check out (I think) gtk_threads_init or something like that and secure your variables with locks/semaphores.

    Alternatively check out gobject.timeout_add(milliseconds, function) (newest development pygtk version, for older versions use gtk.timeout_add). That will call function() every so many milliseconds and you can update your GUI that way. For an example, I use it with my Key Status Monitor app.
    We rarely notice freedom. What we notice is the lack of freedom, and I'm afraid by then it is too late.
    Be a good Ubuntu citizen - Report bugs || http://programmer-art.org

  8. #8
    Join Date
    Nov 2004
    Beans
    68
    Distro
    Gutsy Gibbon Testing

    Re: [pygtk] getting row data from mouse click?

    I almost got it, but there's a small problem...so here's the quick question about threading.....

    the following won't work right
    Code:
    threading.Thread(target=myClass.func(foo)).start()
    but this will
    Code:
    threading.Thread(target=myClass.func).start()
    'foo' is an argument passed to 'myClass.func()'. for some reason, threading doesn't work when I do this. is there any way I can pass an argument to this function? thanks

    edit:
    problem fixed....
    Code:
    threading.Thread(target=myClass.func, args=(foo, )).start()
    ....did the trick
    Last edited by stateq2; January 14th, 2005 at 08:45 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •