Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4325162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:13:49+00:00 2026-05-21T09:13:49+00:00

I am writing an pygtk app that uses a treeview, which has a connection

  • 0

I am writing an pygtk app that uses a treeview, which has a connection to button_press_event. What I can’t figure out is how to pass the information about the treeview (specifically which row is clicked) to a gtk.Menu or another method. If I used the row-activated signal, it passes in the row and column information in as an argument, but this does not happen with button_press_event. Here is the code in question:

    self.liststore = gtk.ListStore(str,int, int, int,str, 'gboolean')
    self.treeview = gtk.TreeView(self.liststore)

    self.treeview.connect("button_press_event",self.serverListEvent)
    self.treeview.set_search_column(0)
    self.draw_columns(self.treeview)

    self.blackmenu = gtk.Menu()
    self.bitem = gtk.MenuItem("Blacklist server")
    self.blackmenu.append(self.bitem)
    self.bitem.connect("activate",self.blacklistServer)
    self.bitem.show()

def serverListEvent(self,treeview,event):
    x = int(event.x)
    y = int(event.y)
    time = event.time
    model = treeview.get_model()

    pthinfo = treeview.get_path_at_pos(x, y)
    if pthinfo is not None:
        path, col, cellx, celly = pthinfo
        # Error here for the model with the column
        print 'url clicked '+model[col][0]
        treeview.grab_focus()
        treeview.set_cursor( path, col, 0)
        # Popup blacklist menu on right click
        if event.button == 3:            
            self.blackmenu.popup( None, None, None, event.button, time)
        # Join game on double click
        elif event.type == gtk.gdk._2BUTTON_PRESS:
            self.joinGame(treeview,model[col][0])
    return True

I then need to pass the information from the clicked row to the self.joinGame and self.blacklistServer methods, but don’t know how to do this either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:13:49+00:00Added an answer on May 21, 2026 at 9:13 am

    I remember that one being kindy tricky. I set up my treeview’s gtk.TreeSelection to whatever mode of selection preferred. Then this:

    def get_selected_ids(self):
        ids = []
        store, paths = self.get_selection().get_selected_rows()
    
        # self.adapter is a mapping class from my data-model to a model column index.
        # If you know the column index from your gtk.ListStore, you don't need it.
        colindex = self.adapter.get_column_modelindex("id")
    
        for path in paths:
            treeiter = store.get_iter(path)
            # Pull value from liststore
            val = store.get_value(
                treeiter, 
                colindex
            )
            ids.append(val)
        return ids
    

    Edit:

    I never used gtk.Menu and gtk.MenuItem, so I didn’t get that you already had your menu connected to a callback (blacklistServer). This is untested, but should give you an idea.

    def blacklistServer(self, menuitem, *ignore):
        # you have to modify *get_selected_ids* so it returns the values you need for
        # blacklisting.
        values = self.get_selected_ids()
        blacklist = set(values)
        self.saveBlacklist(blacklist)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a PyGTK/Twisted app that uses Matplotlib for graphing. It's easy enough to
Writing some XML documentation for a predicate helper class. But I can't figure out
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
Writing an iPhone app in which I want to save the user the grief
I am writing an email application using PyGTK. In almost every message that I
Writing a Jabber client that uses Twisted Words. I would like to know an
I'm currently writing a screen capture app for Windows and Linux using PyGTK, and
Writing a small app that ( among other things ) lets users upload a
I am writing a python/pygtk application that is adding some custom scripts (bash) in
I've been writing writing a small pygtk application using glade to put together the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.