Reply
Thread Tools
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#1
Hello. I have another Python question: I'm developing a Python Statusbar plugin, and have the interface pretty much all mapped out (in gtk). The interface basically is a dynamic/user-defined list of gtk submenu's, and each submenu has a list of a few predefined menu items. I implemented this using a fairly simple function that takes as an argument the parent menu's name, and builds the menu plus three submenu items.

The function is this:

Code:
# Create parent menu

   def create_parent_func(self, name):
      menu_group = gtk.MenuItem(name)
      self.menu.append(menu_group)

      self.submenu = gtk.Menu()
      menu_selection = gtk.MenuItem("Selection >> File")
      menu_open = gtk.MenuItem("Open")
      menu_edit = gtk.MenuItem("Edit")
      self.submenu.append(menu_selection)
      self.submenu.append(menu_open)
      self.submenu.append(menu_edit)
      menu_group.set_submenu(self.submenu)
Now I want to bind different functions to a user's click of the menu_edit, menu_open, and menu_selection MenuItems, but am finding it difficult to do. For instance, I want to bind menu_selection to this function (which needs the argument 'name' from the above function):

Code:
   def clip_selection(self, name):
      date_stamp = commands.getoutput('date +"%m/%d/%y, %l:%M %p: "')
      clip = commands.getoutput('xclip -o')
      seperator = "__________________"

      open_file = open('/home/user/.quickclip/' + name, 'a')

      open_file.write('\n\n%s%s\n\n%s' % (date_stamp, clip, seperator))
I tried putting something like "menu_selection.connect('activate', self.clip_selection(name))" (without the quotes) in the first function, but it doesn't work. I've tried everything I can think of, but nothing has worked. I'm really frustrated, my application is almost finished (I basically just need to bind a bunch of menuitems to functions...).

Thanks for any help
 
Posts: 1,208 | Thanked: 1,028 times | Joined on Oct 2007
#2
try with
Code:
menu_selection.connect('activate', self.clip_selection, name)
see http://www.pygtk.org/pygtk2tutorial/...Callbacks.html and http://www.pygtk.org/docs/pygobject/...bject--connect

Last edited by mikkov; 2009-01-22 at 22:26.
 

The Following 2 Users Say Thank You to mikkov For This Useful Post:
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#3
Thanks a bunch, mikkov. That worked great!

From the links you posted, I was able to figure out what was wrong (I was calling the function incorrectly, as you indicated, and one of my functions was missing a required argument).

Thanks again!
 
Reply


 
Forum Jump


All times are GMT. The time now is 21:34.