bpo-34964: Make Tkinter sources more readable by adding blank lines. (GH-9822)

This commit is contained in:
Serhiy Storchaka 2018-10-12 19:01:00 +03:00 committed by GitHub
parent 2d6097d027
commit dc0d571b64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 565 additions and 9 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,7 @@
from tkinter import *
class Dialog:
command = None

View file

@ -19,8 +19,10 @@ class Dialog(Widget):
*cnf['strings']))
try: Widget.destroy(self)
except TclError: pass
def destroy(self): pass
def _test():
d = Dialog(None, {'title': 'File Modified',
'text':

View file

@ -201,7 +201,6 @@ class DndHandler:
source.dnd_end(target, event)
# ----------------------------------------------------------------------
# The rest is here for testing and demonstration purposes only!
@ -265,6 +264,7 @@ class Icon:
def dnd_end(self, target, event):
pass
class Tester:
def __init__(self, root):
@ -299,6 +299,7 @@ class Tester:
x, y = source.where(self.canvas, event)
source.attach(self.canvas, x, y)
def test():
root = tkinter.Tk()
root.geometry("+1+1")
@ -317,5 +318,6 @@ def test():
i3.attach(t3.canvas)
root.mainloop()
if __name__ == '__main__':
test()

View file

@ -264,7 +264,6 @@ class SaveFileDialog(FileDialog):
self.quit(file)
# For the following classes and modules:
#
# options (all have default values):
@ -341,6 +340,7 @@ class Open(_Dialog):
return self._fixresult(widget, widget.tk.splitlist(result))
return _Dialog._fixresult(self, widget, result)
class SaveAs(_Dialog):
"Ask for a filename to save as"
@ -369,16 +369,19 @@ class Directory(commondialog.Dialog):
#
# convenience stuff
def askopenfilename(**options):
"Ask for a filename to open"
return Open(**options).show()
def asksaveasfilename(**options):
"Ask for a filename to save as"
return SaveAs(**options).show()
def askopenfilenames(**options):
"""Ask for multiple filenames to open
@ -390,6 +393,7 @@ def askopenfilenames(**options):
# FIXME: are the following perhaps a bit too convenient?
def askopenfile(mode = "r", **options):
"Ask for a filename to open, and returned the opened file"
@ -398,6 +402,7 @@ def askopenfile(mode = "r", **options):
return open(filename, mode)
return None
def askopenfiles(mode = "r", **options):
"""Ask for multiple filenames and return the open file
objects
@ -423,12 +428,12 @@ def asksaveasfile(mode = "w", **options):
return open(filename, mode)
return None
def askdirectory (**options):
"Ask for a directory, and return the file name"
return Directory(**options).show()
# --------------------------------------------------------------------
# test stuff
@ -475,5 +480,6 @@ def test():
saveasfilename=asksaveasfilename()
print("saveas", saveasfilename.encode(enc))
if __name__ == '__main__':
test()

View file

@ -78,32 +78,39 @@ def _show(title=None, message=None, _icon=None, _type=None, **options):
# In others we get a Tcl_Obj.
return str(res)
def showinfo(title=None, message=None, **options):
"Show an info message"
return _show(title, message, INFO, OK, **options)
def showwarning(title=None, message=None, **options):
"Show a warning message"
return _show(title, message, WARNING, OK, **options)
def showerror(title=None, message=None, **options):
"Show an error message"
return _show(title, message, ERROR, OK, **options)
def askquestion(title=None, message=None, **options):
"Ask a question"
return _show(title, message, QUESTION, YESNO, **options)
def askokcancel(title=None, message=None, **options):
"Ask if operation should proceed; return true if the answer is ok"
s = _show(title, message, QUESTION, OKCANCEL, **options)
return s == OK
def askyesno(title=None, message=None, **options):
"Ask a question; return true if the answer is yes"
s = _show(title, message, QUESTION, YESNO, **options)
return s == YES
def askyesnocancel(title=None, message=None, **options):
"Ask a question; return true if the answer is yes, None if cancelled."
s = _show(title, message, QUESTION, YESNOCANCEL, **options)
@ -113,6 +120,7 @@ def askyesnocancel(title=None, message=None, **options):
return None
return s == YES
def askretrycancel(title=None, message=None, **options):
"Ask if operation should be retried; return true if the answer is yes"
s = _show(title, message, WARNING, RETRYCANCEL, **options)

View file

@ -16,6 +16,7 @@ __all__ = ['ScrolledText']
from tkinter import Frame, Text, Scrollbar, Pack, Grid, Place
from tkinter.constants import RIGHT, LEFT, Y, BOTH
class ScrolledText(Text):
def __init__(self, master=None, **kw):
self.frame = Frame(master)
@ -50,5 +51,6 @@ def example():
stext.focus_set()
stext.mainloop()
if __name__ == "__main__":
example()

View file

@ -28,6 +28,7 @@ from tkinter import messagebox
import tkinter # used at _QueryDialog for tkinter._default_root
class SimpleDialog:
def __init__(self, master,
@ -119,7 +120,6 @@ class Dialog(Toplevel):
'''
def __init__(self, parent, title = None):
'''Initialize a dialog.
Arguments:
@ -324,9 +324,11 @@ class _QueryDialog(Dialog):
class _QueryInteger(_QueryDialog):
errormessage = "Not an integer."
def getresult(self):
return self.getint(self.entry.get())
def askinteger(title, prompt, **kw):
'''get an integer from the user
@ -341,11 +343,14 @@ def askinteger(title, prompt, **kw):
d = _QueryInteger(title, prompt, **kw)
return d.result
class _QueryFloat(_QueryDialog):
errormessage = "Not a floating point value."
def getresult(self):
return self.getdouble(self.entry.get())
def askfloat(title, prompt, **kw):
'''get a float from the user
@ -360,6 +365,7 @@ def askfloat(title, prompt, **kw):
d = _QueryFloat(title, prompt, **kw)
return d.result
class _QueryString(_QueryDialog):
def __init__(self, *args, **kw):
if "show" in kw:
@ -378,6 +384,7 @@ class _QueryString(_QueryDialog):
def getresult(self):
return self.entry.get()
def askstring(title, prompt, **kw):
'''get a string from the user
@ -393,7 +400,6 @@ def askstring(title, prompt, **kw):
return d.result
if __name__ == '__main__':
def test():