#!/usr/bin/python -tt import gtk import gnomekeyring as gkey from getpass import getpass def get_password(profile): try: return gkey.find_items_sync(0, {"profile": profile})[0].secret except gkey.NoMatchError: secret = getText(profile) gkey.item_create_sync(gkey.get_default_keyring_sync(), 0, "offline password for %s" % profile, {"profile": profile}, secret, True) return secret def responseToDialog(entry, dialog, response): dialog.response(response) def getText(profile): #base this on a message dialog dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None) dialog.set_markup('Password required') #create the text input field entry = gtk.Entry() entry.set_visibility(False) #allow the user to press enter to do ok entry.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK) #create a horizontal box to pack the entry and a label hbox = gtk.HBox() hbox.pack_start(gtk.Label("Password:"), False, 5, 5) hbox.pack_end(entry) #some secondary text dialog.format_secondary_markup("Please enter the password for \"%s\"" % \ profile) #add it and show it dialog.vbox.pack_end(hbox, True, True, 0) dialog.show_all() #go go go dialog.run() text = entry.get_text() dialog.destroy() return text