0

maybe a trivial question, but I'm having some severe problems with PyGTK... I'm trying to programm an application indicator for unity with gtk, and I'm trying to set some of my menuitems insensitive (via set_sensitive(False)) after I clicked on them...

Here's a code snippet:

class CheckNAS: 
    def __init__(self): 
      self.ind = appindicator.Indicator("debian-doc-menu", "indicator-   messages",appindicator.CATEGORY_APPLICATION_STATUS)
      self.ind.set_status (appindicator.STATUS_ACTIVE)
      self.ind.set_attention_icon("icon1")
      self.ind.set_icon("icon2")

    def menu_setup(self):
      self.quit_item = gtk.MenuItem("QUIT") 
      self.quit_item.connect("activate",self.quit)

      if condition_function()==True:
        self.quit.set_sensitive(False)
      self.quit_item.show()
      self.menu.append(self.quit_item)

and then I do repeatedly menu_setup via an add_timeout(1000,self.condition_function). This works fine in principle, but I'd prefer that the menuitem turns insensitive immiediately after I clicked it... Sorry for the Noob-question:)

Lex Li
  • 60,503
  • 9
  • 116
  • 147
wa4557
  • 953
  • 3
  • 13
  • 25
  • You have a typo in `self.quit.set_sensitive(False)`, should be `self.quit_item.set_sensitive(False)`. Is that the problem? – deinonychusaur Jan 02 '13 at 18:58
  • no unfortunately not, this is just due to the fact, that I rearranged the code a little bit – wa4557 Jan 02 '13 at 19:21
  • 1
    Can you supply a minimal code that produces the problem and can be run? You should be able to just run `set_sensitive(False)` and have it stay, I've done so myself in an app without problem. So your problem is probably elsewhere. – deinonychusaur Jan 03 '13 at 09:26
  • The unity tag is for Microsoft Unity. Please don't misuse it. – Lex Li Jan 26 '13 at 04:25

1 Answers1

2

is that what you want?

class CheckNAS: 
    def __init__(self): 
      self.ind = appindicator.Indicator("debian-doc-menu", 
        "indicator-messages",appindicator.CATEGORY_APPLICATION_STATUS)
      self.ind.set_status (appindicator.STATUS_ACTIVE)
      self.ind.set_attention_icon("icon1")
      self.ind.set_icon("icon2")

    def menu_setup(self):
      self.quit_item = gtk.MenuItem("QUIT") 
      self.quit_item.connect("activate",self.sensitive)
      self.quit_item.show()
      self.menu.append(self.quit_item)

    def sensitive(self,widget):
      if widget.get_sensitive():
        widget.set_sensitive(False)
      else:
        widget.set_sensitive(True)
jkd
  • 1,327
  • 14
  • 29
  • yes thanks! that was exactly I was looking for. I didn't realize that I can work with the widgets as parameters for functions. I'm still learning – wa4557 Jan 03 '13 at 11:51
  • is it possible to run to connect one after another. In other words to make the button insensitive for let's say 5 seconds, and then make it sensitive again? – wa4557 Jan 03 '13 at 17:01
  • there is no need to connect the object to a second signal. Just do everything within the `sensitive` function. You can for example import the `time` module (`import time` in the first lines of your file and `time.sleep(5)` in the `sensitive` function (`widget.set_sensitive(False) \ time.sleep(5) \ widget.set_sensitive(True)`)) – jkd Jan 11 '13 at 18:54