Package jazzparser :: Package utils :: Module gtk
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.utils.gtk

 1  from __future__ import absolute_import 
 2  """PyGtk extensions 
 3   
 4  Small utilities for use with pygtk. 
 5   
 6  @warning: pygtk is used by all of these utilities, so it's imported  
 7  at the module level. Don't import this module unless you're sure you  
 8  want your code to depend on pygtk. 
 9   
10  """ 
11  """ 
12  ============================== License ======================================== 
13   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
14    
15   This file is part of The Jazz Parser. 
16    
17   The Jazz Parser is free software: you can redistribute it and/or modify 
18   it under the terms of the GNU General Public License as published by 
19   the Free Software Foundation, either version 3 of the License, or 
20   (at your option) any later version. 
21    
22   The Jazz Parser is distributed in the hope that it will be useful, 
23   but WITHOUT ANY WARRANTY; without even the implied warranty of 
24   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
25   GNU General Public License for more details. 
26    
27   You should have received a copy of the GNU General Public License 
28   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
29   
30  ============================ End license ====================================== 
31   
32  """ 
33  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"  
34   
35  # Check we've got the right version of PyGtk 
36  # This check is made when this module first gets loaded 
37  import pygtk 
38  pygtk.require('2.0') 
39  import gtk 
40   
41 -def get_text_from_dialog(prompt=None, description=None, initial="", title=None):
42 """ 43 Displays a Gtk dialog window to request a text entry. 44 45 @type prompt: string 46 @param prompt: message to display as a prompt 47 @type description: string 48 @param description: longer string to put in as a secondary prompt 49 @type initial: string 50 @param initial: value to put in the entry box to start with 51 @type title: string 52 @param title: window title for the dialog 53 54 """ 55 if prompt is None: 56 # Default to something generic 57 prompt = "Please enter a value:" 58 if title is None: 59 title = "Enter value" 60 dialog = gtk.MessageDialog( 61 None, 62 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, 63 gtk.MESSAGE_QUESTION, 64 gtk.BUTTONS_OK, 65 None ) 66 dialog.set_markup(prompt) 67 dialog.set_title(title) 68 # Create the text input field 69 entry = gtk.Entry() 70 if initial: 71 entry.set_text(initial) 72 # Allow the user to press enter to confirm 73 entry.connect("activate", lambda entry,dia,resp:dia.response(resp), dialog, gtk.RESPONSE_OK) 74 if description: 75 # Some secondary text 76 dialog.format_secondary_markup(description) 77 dialog.vbox.pack_end(entry, True, True, 0) 78 dialog.show_all() 79 # Show the dialog 80 dialog.run() 81 text = entry.get_text() 82 dialog.destroy() 83 return text
84