[Python-checkins] CVS: python/dist/src/Lib/lib-tk tkSimpleDialog.py,1.7,1.8

Fred L. Drake fdrake@users.sourceforge.net
Thu, 06 Dec 2001 08:51:43 -0800


Update of /cvsroot/python/python/dist/src/Lib/lib-tk
In directory usw-pr-cvs1:/tmp/cvs-serv14360/Lib/lib-tk

Modified Files:
	tkSimpleDialog.py 
Log Message:
Be more careful about accessing attributes of the parent: if Tk has not been
initialized, this will be None, but the functions will still work (there will
simply be a bogus parent on the screen).  Allowing the parent to be None
is useful when testing the functions from an interactive interpreter.

Add an optional keyword paramter "show" to the _QueryString class; when given
it is used to set the -show option to the entry widget.  This allows passing
show="*" or the like to askstring(), making it useful for requesting
passwords/passphrases from the user.
This closes SF bug #438517.

Changed a docstring to be less font-lock-hostile.


Index: tkSimpleDialog.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-tk/tkSimpleDialog.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** tkSimpleDialog.py	2001/02/09 11:25:11	1.7
--- tkSimpleDialog.py	2001/12/06 16:51:41	1.8
***************
*** 69,74 ****
          self.protocol("WM_DELETE_WINDOW", self.cancel)
  
!         self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
!                                   parent.winfo_rooty()+50))
  
          self.initial_focus.focus_set()
--- 69,75 ----
          self.protocol("WM_DELETE_WINDOW", self.cancel)
  
!         if self.parent is not None:
!             self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
!                                       parent.winfo_rooty()+50))
  
          self.initial_focus.focus_set()
***************
*** 96,100 ****
          '''add standard button box.
  
!         override if you don't want the standard buttons
          '''
  
--- 97,101 ----
          '''add standard button box.
  
!         override if you do not want the standard buttons
          '''
  
***************
*** 130,134 ****
  
          # put focus back to the parent window
!         self.parent.focus_set()
          self.destroy()
  
--- 131,136 ----
  
          # put focus back to the parent window
!         if self.parent is not None:
!             self.parent.focus_set()
          self.destroy()
  
***************
*** 271,274 ****
--- 273,290 ----
  
  class _QueryString(_QueryDialog):
+     def __init__(self, *args, **kw):
+         if kw.has_key("show"):
+             self.__show = kw["show"]
+             del kw["show"]
+         else:
+             self.__show = None
+         _QueryDialog.__init__(self, *args, **kw)
+ 
+     def body(self, master):
+         entry = _QueryDialog.body(self, master)
+         if self.__show is not None:
+             entry.configure(show=self.__show)
+         return entry
+ 
      def getresult(self):
          return self.entry.get()