Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the way we do it in RabbitVCS. Essentially, the main application creates the dialog and runs it using the PyGTK gtk.Dialog <a href="http://library.gnome.org/devel/pygtk/stable/class-gtkdialog.html#method-gtkdialog--run" rel="nofollow noreferrer">run() method</a>.</p> <p>Breaking it down, from the main app we have (see <a href="http://code.google.com/p/rabbitvcs/source/browse/trunk/rabbitvcs/ui/action.py#341" rel="nofollow noreferrer">action.py</a>):</p> <pre><code>def get_login(self, realm, username, may_save): # ...other code omitted... gtk.gdk.threads_enter() dialog = rabbitvcs.ui.dialog.Authentication( realm, may_save ) result = dialog.run() gtk.gdk.threads_leave() return result </code></pre> <p>This "get_login" function is the one that is <a href="http://code.google.com/p/rabbitvcs/source/browse/trunk/rabbitvcs/ui/action.py#586" rel="nofollow noreferrer">given as the callback</a> to the PySVN client instance.</p> <p>Note the <a href="http://library.gnome.org/devel/pygtk/stable/gdk-functions.html#function-gdk--threads-enter" rel="nofollow noreferrer">threads_enter()</a> and <a href="http://library.gnome.org/devel/pygtk/stable/gdk-functions.html#function-gdk--threads-leave" rel="nofollow noreferrer">threads_leave()</a> methods! These allow GTK to use Python threads, but note that the GIL may be locked by other extensions.</p> <p>What this does is create a dialog (already laid out using <a href="http://glade.gnome.org/" rel="nofollow noreferrer">Glade</a>), and the run() method on that class is a wrapper for the PyGTK method (see <a href="http://code.google.com/p/rabbitvcs/source/browse/trunk/rabbitvcs/ui/dialog.py#163" rel="nofollow noreferrer">dialog.py</a>):</p> <pre><code>def run(self): returner = None self.dialog = self.get_widget("Authentication") result = self.dialog.run() login = self.get_widget("auth_login").get_text() password = self.get_widget("auth_password").get_text() save = self.get_widget("auth_save").get_active() self.dialog.destroy() if result == gtk.RESPONSE_OK: return (True, login, password, save) else: return (False, "", "", False) </code></pre> <p>The RabbitVCS UI code is probably far more convoluted that you would need, but it might help to poke around. Those "get_widget" calls are convenience methods to get the widget from the Glade tree. If you are not using Glade, you will have references to the widgets directly.</p> <p>I hope it helps :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload