[Inteproxy-commits] r47 - trunk
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Apr 17 19:37:06 CEST 2007
Author: bh
Date: 2007-04-17 19:37:06 +0200 (Tue, 17 Apr 2007)
New Revision: 47
Modified:
trunk/ChangeLog
trunk/getpassword.py
Log:
* getpassword.py: Add new window system "gtk". gtk is the default
now. Also, the getpassword module can be run directly as a script
now, to test the default dialog.
(getpassword_gtk): New. Implements a simple password dialog using
gtk
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-04-17 14:43:27 UTC (rev 46)
+++ trunk/ChangeLog 2007-04-17 17:37:06 UTC (rev 47)
@@ -1,3 +1,11 @@
+2007-04-17 Bernhard Herzog <bh at intevation.de>
+
+ * getpassword.py: Add new window system "gtk". gtk is the default
+ now. Also, the getpassword module can be run directly as a script
+ now, to test the default dialog.
+ (getpassword_gtk): New. Implements a simple password dialog using
+ gtk
+
2007-04-17 Jan-Oliver Wagner <jan-oliver.wagner at intevation.de>
* doc/InteProxy-logo.svg, InteProxy-logo.png: New. The logo
Modified: trunk/getpassword.py
===================================================================
--- trunk/getpassword.py 2007-04-17 14:43:27 UTC (rev 46)
+++ trunk/getpassword.py 2007-04-17 17:37:06 UTC (rev 47)
@@ -13,11 +13,63 @@
# Determine the window system we're using. This determines how the user
# is asked for the username/password.
try:
- import pywin.dialogs.login
- windowsystem = "pywin"
+ # If gtk isn't available, we get an ImportError here. However, on
+ # Unix, if we gtk cannot establish the connection to the X-server,
+ # we get a RuntimeError here. We do not catch the RuntimeError for
+ # now, because we want to use gtk by default and don't want to hide
+ # configuration errors like missing or incorrect DISPLAY variables.
+ import gtk
+ windowsystem = "gtk"
except ImportError:
- windowsystem = "tty"
+ try:
+ import pywin.dialogs.login
+ windowsystem = "pywin"
+ except ImportError:
+ windowsystem = "tty"
+def getpassword_gtk(title):
+ dialog = gtk.Dialog("My dialog", None,
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+ (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
+ gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
+ label = gtk.Label(title)
+ label.show()
+ dialog.vbox.pack_start(label, True, True, 5)
+
+ table = gtk.Table(2, 2)
+ dialog.vbox.pack_start(table)
+
+ def add_field(row, name, visibility):
+ label = gtk.Label(name)
+ label.set_alignment(1.0, 0.5)
+ table.attach(label, 0, 1, row, row + 1, xoptions=gtk.FILL,
+ xpadding=5, ypadding=5)
+ entry = gtk.Entry()
+ entry.set_visibility(visibility)
+ table.attach(entry, 1, 2, row, row + 1, xoptions=gtk.FILL|gtk.EXPAND,
+ xpadding=5, ypadding=5)
+ return entry
+
+ username_entry = add_field(0, "Username:", True)
+ password_entry = add_field(1, "Password:", False)
+
+ table.show_all()
+
+ if dialog.run() == gtk.RESPONSE_ACCEPT:
+ result = (username_entry.get_text(),
+ password_entry.get_text())
+ else:
+ result = None
+
+ dialog.destroy()
+
+ # process pending events to make sure the dialog is destroyed and
+ # unmapped properly from the screen.
+ while gtk.events_pending():
+ gtk.main_iteration_do()
+
+ return result
+
def getpassword_pywin(title):
return pywin.dialogs.login.GetLogin(title)
@@ -61,3 +113,8 @@
return user, password
finally:
pw_lock.release()
+
+
+if __name__ == "__main__":
+ result = getpassword("Password Dialog Test")
+ print repr(result)
More information about the Inteproxy-commits
mailing list