[Inteproxy-commits] r70 - in trunk: . inteproxy
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Apr 30 16:06:15 CEST 2007
Author: bh
Date: 2007-04-30 16:06:14 +0200 (Mon, 30 Apr 2007)
New Revision: 70
Modified:
trunk/ChangeLog
trunk/inteproxy/app.py
trunk/inteproxy/getpassword.py
trunk/inteproxy/gtkapp.py
Log:
* inteproxy/getpassword.py (getpassword): Moved to gtkapp.py.
* inteproxy/gtkapp.py (run_password_dialog): Copy of
getpassword.getpassword, but changed to include a doc-string and
the correct return value when the dialog is cancelled.
(InteProxyApplication.get_password): Overwrite the inherited
method to vall run_password_dialog.
* inteproxy/app.py (InteProxyApplication.get_password): Turned
into an abstract method
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-04-30 12:56:27 UTC (rev 69)
+++ trunk/ChangeLog 2007-04-30 14:06:14 UTC (rev 70)
@@ -1,5 +1,18 @@
2007-04-30 Bernhard Herzog <bh at intevation.de>
+ * inteproxy/getpassword.py (getpassword): Moved to gtkapp.py.
+
+ * inteproxy/gtkapp.py (run_password_dialog): Copy of
+ getpassword.getpassword, but changed to include a doc-string and
+ the correct return value when the dialog is cancelled.
+ (InteProxyApplication.get_password): Overwrite the inherited
+ method to vall run_password_dialog.
+
+ * inteproxy/app.py (InteProxyApplication.get_password): Turned
+ into an abstract method
+
+2007-04-30 Bernhard Herzog <bh at intevation.de>
+
* inteproxy/gtkapp.py (run_about_dialog): New. Convenience
function to run gtk.AboutDialog with properties given as keyword
arguments.
Modified: trunk/inteproxy/app.py
===================================================================
--- trunk/inteproxy/app.py 2007-04-30 12:56:27 UTC (rev 69)
+++ trunk/inteproxy/app.py 2007-04-30 14:06:14 UTC (rev 70)
@@ -10,7 +10,6 @@
from inteproxy.proxycore import MasterWorkerServer, InteProxyHTTPRequestHandler
from inteproxy.httpserver import ServerThread
-import inteproxy.getpassword
from inteproxy.feesdialog import run_fees_dialog
@@ -68,14 +67,16 @@
password dialog. The title should contain all information the
user may need to determine which username and password they have
to enter. This method returns the entered username/password
- pair as a tuple.
+ pair as a tuple. If the user cancels the interaction, the
+ return value is a tuple of two None objects.
This method should be called by request handlers of the server
when they need to query the user for usernames and passwords.
- The default implementation simply passes all parameters through
- to inteproxy.getpassword.getpassword.
+
+ This method has to be implemented by derived classes. The
+ default implementation only raises NotImplementedError.
"""
- return inteproxy.getpassword.getpassword(title)
+ raise NotImplementedError
def run_fees_dialog(self, title, fees, access_constraints):
"""Callback to run the fees dialog.
Modified: trunk/inteproxy/getpassword.py
===================================================================
--- trunk/inteproxy/getpassword.py 2007-04-30 12:56:27 UTC (rev 69)
+++ trunk/inteproxy/getpassword.py 2007-04-30 14:06:14 UTC (rev 70)
@@ -8,57 +8,11 @@
"""Code to ask the user for username and password"""
import threading
-import traceback
-import gtk
-
import inteproxy.main
-def getpassword(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
-
-
# password cache and lock
pw_cache = {}
pw_lock = threading.Lock()
Modified: trunk/inteproxy/gtkapp.py
===================================================================
--- trunk/inteproxy/gtkapp.py 2007-04-30 12:56:27 UTC (rev 69)
+++ trunk/inteproxy/gtkapp.py 2007-04-30 14:06:14 UTC (rev 70)
@@ -16,6 +16,59 @@
import inteproxy.main
+def run_password_dialog(title):
+ """Runs the password dialog.
+
+ The return value is a tuple of the form (username, password). If
+ the user ends the dialog with OK, both values are strings with the
+ information entered by the user. If the user cancels the dialog,
+ both values are None.
+ """
+ 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, 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
+
+
+
+
# UI definition with the menus used in the InteProxy GUI
ui_definition = """<ui>
<!-- Menubar for the main window -->
@@ -257,13 +310,13 @@
def get_password(self, *args):
"""Asks the user for username and password
-
- Extends the inherited method to be thread safe in GTK, so that
- it can be called from the server's worker threads.
+ Overwrites the base class method with code that uses the
+ run_password_dialog function to ask the user. The return value
+ is the return value of run_password_dialog.
"""
gtk.gdk.threads_enter()
try:
- return super(InteProxyApplication, self).get_password(*args)
+ return run_password_dialog(*args)
finally:
gtk.gdk.threads_leave()
More information about the Inteproxy-commits
mailing list