mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-34964: Make Tkinter sources more readable by adding blank lines. (GH-9822)
This commit is contained in:
parent
2d6097d027
commit
dc0d571b64
8 changed files with 565 additions and 9 deletions
File diff suppressed because it is too large
Load diff
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
|
|
||||||
|
|
||||||
class Dialog:
|
class Dialog:
|
||||||
|
|
||||||
command = None
|
command = None
|
||||||
|
|
|
@ -19,8 +19,10 @@ class Dialog(Widget):
|
||||||
*cnf['strings']))
|
*cnf['strings']))
|
||||||
try: Widget.destroy(self)
|
try: Widget.destroy(self)
|
||||||
except TclError: pass
|
except TclError: pass
|
||||||
|
|
||||||
def destroy(self): pass
|
def destroy(self): pass
|
||||||
|
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
d = Dialog(None, {'title': 'File Modified',
|
d = Dialog(None, {'title': 'File Modified',
|
||||||
'text':
|
'text':
|
||||||
|
|
|
@ -201,7 +201,6 @@ class DndHandler:
|
||||||
source.dnd_end(target, event)
|
source.dnd_end(target, event)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# The rest is here for testing and demonstration purposes only!
|
# The rest is here for testing and demonstration purposes only!
|
||||||
|
|
||||||
|
@ -265,6 +264,7 @@ class Icon:
|
||||||
def dnd_end(self, target, event):
|
def dnd_end(self, target, event):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Tester:
|
class Tester:
|
||||||
|
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
|
@ -299,6 +299,7 @@ class Tester:
|
||||||
x, y = source.where(self.canvas, event)
|
x, y = source.where(self.canvas, event)
|
||||||
source.attach(self.canvas, x, y)
|
source.attach(self.canvas, x, y)
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
root = tkinter.Tk()
|
root = tkinter.Tk()
|
||||||
root.geometry("+1+1")
|
root.geometry("+1+1")
|
||||||
|
@ -317,5 +318,6 @@ def test():
|
||||||
i3.attach(t3.canvas)
|
i3.attach(t3.canvas)
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test()
|
test()
|
||||||
|
|
|
@ -264,7 +264,6 @@ class SaveFileDialog(FileDialog):
|
||||||
self.quit(file)
|
self.quit(file)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# For the following classes and modules:
|
# For the following classes and modules:
|
||||||
#
|
#
|
||||||
# options (all have default values):
|
# options (all have default values):
|
||||||
|
@ -341,6 +340,7 @@ class Open(_Dialog):
|
||||||
return self._fixresult(widget, widget.tk.splitlist(result))
|
return self._fixresult(widget, widget.tk.splitlist(result))
|
||||||
return _Dialog._fixresult(self, widget, result)
|
return _Dialog._fixresult(self, widget, result)
|
||||||
|
|
||||||
|
|
||||||
class SaveAs(_Dialog):
|
class SaveAs(_Dialog):
|
||||||
"Ask for a filename to save as"
|
"Ask for a filename to save as"
|
||||||
|
|
||||||
|
@ -369,16 +369,19 @@ class Directory(commondialog.Dialog):
|
||||||
#
|
#
|
||||||
# convenience stuff
|
# convenience stuff
|
||||||
|
|
||||||
|
|
||||||
def askopenfilename(**options):
|
def askopenfilename(**options):
|
||||||
"Ask for a filename to open"
|
"Ask for a filename to open"
|
||||||
|
|
||||||
return Open(**options).show()
|
return Open(**options).show()
|
||||||
|
|
||||||
|
|
||||||
def asksaveasfilename(**options):
|
def asksaveasfilename(**options):
|
||||||
"Ask for a filename to save as"
|
"Ask for a filename to save as"
|
||||||
|
|
||||||
return SaveAs(**options).show()
|
return SaveAs(**options).show()
|
||||||
|
|
||||||
|
|
||||||
def askopenfilenames(**options):
|
def askopenfilenames(**options):
|
||||||
"""Ask for multiple filenames to open
|
"""Ask for multiple filenames to open
|
||||||
|
|
||||||
|
@ -390,6 +393,7 @@ def askopenfilenames(**options):
|
||||||
|
|
||||||
# FIXME: are the following perhaps a bit too convenient?
|
# FIXME: are the following perhaps a bit too convenient?
|
||||||
|
|
||||||
|
|
||||||
def askopenfile(mode = "r", **options):
|
def askopenfile(mode = "r", **options):
|
||||||
"Ask for a filename to open, and returned the opened file"
|
"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 open(filename, mode)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def askopenfiles(mode = "r", **options):
|
def askopenfiles(mode = "r", **options):
|
||||||
"""Ask for multiple filenames and return the open file
|
"""Ask for multiple filenames and return the open file
|
||||||
objects
|
objects
|
||||||
|
@ -423,12 +428,12 @@ def asksaveasfile(mode = "w", **options):
|
||||||
return open(filename, mode)
|
return open(filename, mode)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def askdirectory (**options):
|
def askdirectory (**options):
|
||||||
"Ask for a directory, and return the file name"
|
"Ask for a directory, and return the file name"
|
||||||
return Directory(**options).show()
|
return Directory(**options).show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# test stuff
|
# test stuff
|
||||||
|
|
||||||
|
@ -475,5 +480,6 @@ def test():
|
||||||
saveasfilename=asksaveasfilename()
|
saveasfilename=asksaveasfilename()
|
||||||
print("saveas", saveasfilename.encode(enc))
|
print("saveas", saveasfilename.encode(enc))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test()
|
test()
|
||||||
|
|
|
@ -78,32 +78,39 @@ def _show(title=None, message=None, _icon=None, _type=None, **options):
|
||||||
# In others we get a Tcl_Obj.
|
# In others we get a Tcl_Obj.
|
||||||
return str(res)
|
return str(res)
|
||||||
|
|
||||||
|
|
||||||
def showinfo(title=None, message=None, **options):
|
def showinfo(title=None, message=None, **options):
|
||||||
"Show an info message"
|
"Show an info message"
|
||||||
return _show(title, message, INFO, OK, **options)
|
return _show(title, message, INFO, OK, **options)
|
||||||
|
|
||||||
|
|
||||||
def showwarning(title=None, message=None, **options):
|
def showwarning(title=None, message=None, **options):
|
||||||
"Show a warning message"
|
"Show a warning message"
|
||||||
return _show(title, message, WARNING, OK, **options)
|
return _show(title, message, WARNING, OK, **options)
|
||||||
|
|
||||||
|
|
||||||
def showerror(title=None, message=None, **options):
|
def showerror(title=None, message=None, **options):
|
||||||
"Show an error message"
|
"Show an error message"
|
||||||
return _show(title, message, ERROR, OK, **options)
|
return _show(title, message, ERROR, OK, **options)
|
||||||
|
|
||||||
|
|
||||||
def askquestion(title=None, message=None, **options):
|
def askquestion(title=None, message=None, **options):
|
||||||
"Ask a question"
|
"Ask a question"
|
||||||
return _show(title, message, QUESTION, YESNO, **options)
|
return _show(title, message, QUESTION, YESNO, **options)
|
||||||
|
|
||||||
|
|
||||||
def askokcancel(title=None, message=None, **options):
|
def askokcancel(title=None, message=None, **options):
|
||||||
"Ask if operation should proceed; return true if the answer is ok"
|
"Ask if operation should proceed; return true if the answer is ok"
|
||||||
s = _show(title, message, QUESTION, OKCANCEL, **options)
|
s = _show(title, message, QUESTION, OKCANCEL, **options)
|
||||||
return s == OK
|
return s == OK
|
||||||
|
|
||||||
|
|
||||||
def askyesno(title=None, message=None, **options):
|
def askyesno(title=None, message=None, **options):
|
||||||
"Ask a question; return true if the answer is yes"
|
"Ask a question; return true if the answer is yes"
|
||||||
s = _show(title, message, QUESTION, YESNO, **options)
|
s = _show(title, message, QUESTION, YESNO, **options)
|
||||||
return s == YES
|
return s == YES
|
||||||
|
|
||||||
|
|
||||||
def askyesnocancel(title=None, message=None, **options):
|
def askyesnocancel(title=None, message=None, **options):
|
||||||
"Ask a question; return true if the answer is yes, None if cancelled."
|
"Ask a question; return true if the answer is yes, None if cancelled."
|
||||||
s = _show(title, message, QUESTION, YESNOCANCEL, **options)
|
s = _show(title, message, QUESTION, YESNOCANCEL, **options)
|
||||||
|
@ -113,6 +120,7 @@ def askyesnocancel(title=None, message=None, **options):
|
||||||
return None
|
return None
|
||||||
return s == YES
|
return s == YES
|
||||||
|
|
||||||
|
|
||||||
def askretrycancel(title=None, message=None, **options):
|
def askretrycancel(title=None, message=None, **options):
|
||||||
"Ask if operation should be retried; return true if the answer is yes"
|
"Ask if operation should be retried; return true if the answer is yes"
|
||||||
s = _show(title, message, WARNING, RETRYCANCEL, **options)
|
s = _show(title, message, WARNING, RETRYCANCEL, **options)
|
||||||
|
|
|
@ -16,6 +16,7 @@ __all__ = ['ScrolledText']
|
||||||
from tkinter import Frame, Text, Scrollbar, Pack, Grid, Place
|
from tkinter import Frame, Text, Scrollbar, Pack, Grid, Place
|
||||||
from tkinter.constants import RIGHT, LEFT, Y, BOTH
|
from tkinter.constants import RIGHT, LEFT, Y, BOTH
|
||||||
|
|
||||||
|
|
||||||
class ScrolledText(Text):
|
class ScrolledText(Text):
|
||||||
def __init__(self, master=None, **kw):
|
def __init__(self, master=None, **kw):
|
||||||
self.frame = Frame(master)
|
self.frame = Frame(master)
|
||||||
|
@ -50,5 +51,6 @@ def example():
|
||||||
stext.focus_set()
|
stext.focus_set()
|
||||||
stext.mainloop()
|
stext.mainloop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
example()
|
example()
|
||||||
|
|
|
@ -28,6 +28,7 @@ from tkinter import messagebox
|
||||||
|
|
||||||
import tkinter # used at _QueryDialog for tkinter._default_root
|
import tkinter # used at _QueryDialog for tkinter._default_root
|
||||||
|
|
||||||
|
|
||||||
class SimpleDialog:
|
class SimpleDialog:
|
||||||
|
|
||||||
def __init__(self, master,
|
def __init__(self, master,
|
||||||
|
@ -119,7 +120,6 @@ class Dialog(Toplevel):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, parent, title = None):
|
def __init__(self, parent, title = None):
|
||||||
|
|
||||||
'''Initialize a dialog.
|
'''Initialize a dialog.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
@ -324,9 +324,11 @@ class _QueryDialog(Dialog):
|
||||||
|
|
||||||
class _QueryInteger(_QueryDialog):
|
class _QueryInteger(_QueryDialog):
|
||||||
errormessage = "Not an integer."
|
errormessage = "Not an integer."
|
||||||
|
|
||||||
def getresult(self):
|
def getresult(self):
|
||||||
return self.getint(self.entry.get())
|
return self.getint(self.entry.get())
|
||||||
|
|
||||||
|
|
||||||
def askinteger(title, prompt, **kw):
|
def askinteger(title, prompt, **kw):
|
||||||
'''get an integer from the user
|
'''get an integer from the user
|
||||||
|
|
||||||
|
@ -341,11 +343,14 @@ def askinteger(title, prompt, **kw):
|
||||||
d = _QueryInteger(title, prompt, **kw)
|
d = _QueryInteger(title, prompt, **kw)
|
||||||
return d.result
|
return d.result
|
||||||
|
|
||||||
|
|
||||||
class _QueryFloat(_QueryDialog):
|
class _QueryFloat(_QueryDialog):
|
||||||
errormessage = "Not a floating point value."
|
errormessage = "Not a floating point value."
|
||||||
|
|
||||||
def getresult(self):
|
def getresult(self):
|
||||||
return self.getdouble(self.entry.get())
|
return self.getdouble(self.entry.get())
|
||||||
|
|
||||||
|
|
||||||
def askfloat(title, prompt, **kw):
|
def askfloat(title, prompt, **kw):
|
||||||
'''get a float from the user
|
'''get a float from the user
|
||||||
|
|
||||||
|
@ -360,6 +365,7 @@ def askfloat(title, prompt, **kw):
|
||||||
d = _QueryFloat(title, prompt, **kw)
|
d = _QueryFloat(title, prompt, **kw)
|
||||||
return d.result
|
return d.result
|
||||||
|
|
||||||
|
|
||||||
class _QueryString(_QueryDialog):
|
class _QueryString(_QueryDialog):
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
if "show" in kw:
|
if "show" in kw:
|
||||||
|
@ -378,6 +384,7 @@ class _QueryString(_QueryDialog):
|
||||||
def getresult(self):
|
def getresult(self):
|
||||||
return self.entry.get()
|
return self.entry.get()
|
||||||
|
|
||||||
|
|
||||||
def askstring(title, prompt, **kw):
|
def askstring(title, prompt, **kw):
|
||||||
'''get a string from the user
|
'''get a string from the user
|
||||||
|
|
||||||
|
@ -393,7 +400,6 @@ def askstring(title, prompt, **kw):
|
||||||
return d.result
|
return d.result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue