Skip to content

Instantly share code, notes, and snippets.

@niedbalski
Created October 11, 2012 16:02
Show Gist options
  • Save niedbalski/3873410 to your computer and use it in GitHub Desktop.
Save niedbalski/3873410 to your computer and use it in GitHub Desktop.
get_or_create a widget instance
def __init__(self):
item = gtk.MenuItem("Manage Services")
menu.append(item)
item.connect('activate', self.get_or_create_widget('services'))
def get_or_create_widget(self, widget_name):
widget_name = '%s_dialog' % widget_name
if hasattr(self, widget_name):
return lambda cb: getattr(self, widget_name).show()
return getattr(self, 'create_%s' % widget_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment