Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fff008

Browse files
committed
Merged revisions 74446-74449 via svnmerge from
svn+ssh://pythondev/python/trunk ........ r74446 | guilherme.polo | 2009-08-14 10:53:41 -0300 (Fri, 14 Aug 2009) | 1 line Issue #3344: Replace itertools.count by enumerate. ........ r74447 | guilherme.polo | 2009-08-14 11:03:07 -0300 (Fri, 14 Aug 2009) | 1 line Issue #3926: Fix the usage of the new showwarnings and formatwarning. ........ r74448 | guilherme.polo | 2009-08-14 11:36:45 -0300 (Fri, 14 Aug 2009) | 3 lines Issue #1135: Add the XView and YView mix-ins to avoid duplicating the xview* and yview* methods. ........ r74449 | guilherme.polo | 2009-08-14 11:43:43 -0300 (Fri, 14 Aug 2009) | 1 line Clarifying Entry.selection_present's docstring. ........
1 parent 6837083 commit 1fff008

7 files changed

Lines changed: 74 additions & 150 deletions

File tree

Lib/idlelib/EditorWindow.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44
import string
55
import imp
6-
from itertools import count
76
from tkinter import *
87
import tkinter.simpledialog as tkSimpleDialog
98
import tkinter.messagebox as tkMessageBox
@@ -785,8 +784,8 @@ def update_recent_files_list(self, new_file=None):
785784
for instance in self.top.instance_dict:
786785
menu = instance.recent_files_menu
787786
menu.delete(1, END) # clear, and rebuild:
788-
for i, file in zip(count(), rf_list):
789-
file_name = file[0:-1] # zap \n
787+
for i, file_name in enumerate(rf_list):
788+
file_name = file_name.rstrip() # zap \n
790789
# make unicode string to display non-ASCII chars correctly
791790
ufile_name = self._filename_to_unicode(file_name)
792791
callback = instance.__recent_file_callback(file_name)

Lib/idlelib/PyShell.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,21 @@
5555
else:
5656
def idle_showwarning(message, category, filename, lineno,
5757
file=None, line=None):
58-
file = warning_stream
58+
if file is None:
59+
file = warning_stream
5960
try:
60-
file.write(warnings.formatwarning(message, category, filename,\
61+
file.write(warnings.formatwarning(message, category, filename,
6162
lineno, file=file, line=line))
6263
except IOError:
6364
pass ## file (probably __stderr__) is invalid, warning dropped.
6465
warnings.showwarning = idle_showwarning
65-
def idle_formatwarning(message, category, filename, lineno,
66-
file=None, line=None):
66+
def idle_formatwarning(message, category, filename, lineno, line=None):
6767
"""Format warnings the IDLE way"""
6868
s = "\nWarning (from warnings module):\n"
6969
s += ' File \"%s\", line %s\n' % (filename, lineno)
70-
line = linecache.getline(filename, lineno).strip() \
71-
if line is None else line
70+
if line is None:
71+
line = linecache.getline(filename, lineno)
72+
line = line.strip()
7273
if line:
7374
s += " %s\n" % line
7475
s += "%s: %s\n>>> " % (category.__name__, message)
@@ -81,18 +82,17 @@ def extended_linecache_checkcache(filename=None,
8182
8283
Rather than repeating the linecache code, patch it to save the
8384
<pyshell#...> entries, call the original linecache.checkcache()
84-
(which destroys them), and then restore the saved entries.
85+
(skipping them), and then restore the saved entries.
8586
8687
orig_checkcache is bound at definition time to the original
8788
method, allowing it to be patched.
88-
8989
"""
9090
cache = linecache.cache
9191
save = {}
92-
for filename in cache:
93-
if filename[:1] + filename[-1:] == '<>':
94-
save[filename] = cache[filename]
95-
orig_checkcache()
92+
for key in list(cache):
93+
if key[:1] + key[-1:] == '<>':
94+
save[key] = cache.pop(key)
95+
orig_checkcache(filename)
9696
cache.update(save)
9797

9898
# Patch linecache.checkcache():

Lib/idlelib/run.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
pass
2626
else:
2727
def idle_formatwarning_subproc(message, category, filename, lineno,
28-
file=None, line=None):
28+
line=None):
2929
"""Format warnings the IDLE way"""
3030
s = "\nWarning (from warnings module):\n"
3131
s += ' File \"%s\", line %s\n' % (filename, lineno)
32-
line = linecache.getline(filename, lineno).strip() \
33-
if line is None else line
32+
if line is None:
33+
line = linecache.getline(filename, lineno)
34+
line = line.strip()
3435
if line:
3536
s += " %s\n" % line
3637
s += "%s: %s\n" % (category.__name__, message)

Lib/tkinter/__init__.py

Lines changed: 49 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,48 @@ def __call__(self, *args):
14031403
self.widget._report_exception()
14041404

14051405

1406+
class XView:
1407+
"""Mix-in class for querying and changing the horizontal position
1408+
of a widget's window."""
1409+
1410+
def xview(self, *args):
1411+
"""Query and change the horizontal position of the view."""
1412+
res = self.tk.call(self._w, 'xview', *args)
1413+
if not args:
1414+
return self._getdoubles(res)
1415+
1416+
def xview_moveto(self, fraction):
1417+
"""Adjusts the view in the window so that FRACTION of the
1418+
total width of the canvas is off-screen to the left."""
1419+
self.tk.call(self._w, 'xview', 'moveto', fraction)
1420+
1421+
def xview_scroll(self, number, what):
1422+
"""Shift the x-view according to NUMBER which is measured in "units"
1423+
or "pages" (WHAT)."""
1424+
self.tk.call(self._w, 'xview', 'scroll', number, what)
1425+
1426+
1427+
class YView:
1428+
"""Mix-in class for querying and changing the vertical position
1429+
of a widget's window."""
1430+
1431+
def yview(self, *args):
1432+
"""Query and change the vertical position of the view."""
1433+
res = self.tk.call(self._w, 'yview', *args)
1434+
if not args:
1435+
return self._getdoubles(res)
1436+
1437+
def yview_moveto(self, fraction):
1438+
"""Adjusts the view in the window so that FRACTION of the
1439+
total height of the canvas is off-screen to the top."""
1440+
self.tk.call(self._w, 'yview', 'moveto', fraction)
1441+
1442+
def yview_scroll(self, number, what):
1443+
"""Shift the y-view according to NUMBER which is measured in
1444+
"units" or "pages" (WHAT)."""
1445+
self.tk.call(self._w, 'yview', 'scroll', number, what)
1446+
1447+
14061448
class Wm:
14071449
"""Provides functions for the communication with the window manager."""
14081450

@@ -2041,7 +2083,7 @@ def At(x, y=None):
20412083
else:
20422084
return '@%r,%r' % (x, y)
20432085

2044-
class Canvas(Widget):
2086+
class Canvas(Widget, XView, YView):
20452087
"""Canvas widget to display graphical elements like lines or text."""
20462088
def __init__(self, master=None, cnf={}, **kw):
20472089
"""Construct a canvas widget with the parent MASTER.
@@ -2281,30 +2323,6 @@ def select_to(self, tagOrId, index):
22812323
def type(self, tagOrId):
22822324
"""Return the type of the item TAGORID."""
22832325
return self.tk.call(self._w, 'type', tagOrId) or None
2284-
def xview(self, *args):
2285-
"""Query and change horizontal position of the view."""
2286-
if not args:
2287-
return self._getdoubles(self.tk.call(self._w, 'xview'))
2288-
self.tk.call((self._w, 'xview') + args)
2289-
def xview_moveto(self, fraction):
2290-
"""Adjusts the view in the window so that FRACTION of the
2291-
total width of the canvas is off-screen to the left."""
2292-
self.tk.call(self._w, 'xview', 'moveto', fraction)
2293-
def xview_scroll(self, number, what):
2294-
"""Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2295-
self.tk.call(self._w, 'xview', 'scroll', number, what)
2296-
def yview(self, *args):
2297-
"""Query and change vertical position of the view."""
2298-
if not args:
2299-
return self._getdoubles(self.tk.call(self._w, 'yview'))
2300-
self.tk.call((self._w, 'yview') + args)
2301-
def yview_moveto(self, fraction):
2302-
"""Adjusts the view in the window so that FRACTION of the
2303-
total height of the canvas is off-screen to the top."""
2304-
self.tk.call(self._w, 'yview', 'moveto', fraction)
2305-
def yview_scroll(self, number, what):
2306-
"""Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2307-
self.tk.call(self._w, 'yview', 'scroll', number, what)
23082326

23092327
class Checkbutton(Widget):
23102328
"""Checkbutton widget which is either in on- or off-state."""
@@ -2335,7 +2353,7 @@ def toggle(self):
23352353
"""Toggle the button."""
23362354
self.tk.call(self._w, 'toggle')
23372355

2338-
class Entry(Widget):
2356+
class Entry(Widget, XView):
23392357
"""Entry widget which allows to display simple text."""
23402358
def __init__(self, master=None, cnf={}, **kw):
23412359
"""Construct an entry widget with the parent MASTER.
@@ -2386,7 +2404,8 @@ def selection_from(self, index):
23862404
self.tk.call(self._w, 'selection', 'from', index)
23872405
select_from = selection_from
23882406
def selection_present(self):
2389-
"""Return whether the widget has the selection."""
2407+
"""Return True if there are characters selected in the entry, False
2408+
otherwise."""
23902409
return self.tk.getboolean(
23912410
self.tk.call(self._w, 'selection', 'present'))
23922411
select_present = selection_present
@@ -2398,16 +2417,6 @@ def selection_to(self, index):
23982417
"""Set the variable end of a selection to INDEX."""
23992418
self.tk.call(self._w, 'selection', 'to', index)
24002419
select_to = selection_to
2401-
def xview(self, index):
2402-
"""Query and change horizontal position of the view."""
2403-
self.tk.call(self._w, 'xview', index)
2404-
def xview_moveto(self, fraction):
2405-
"""Adjust the view in the window so that FRACTION of the
2406-
total width of the entry is off-screen to the left."""
2407-
self.tk.call(self._w, 'xview', 'moveto', fraction)
2408-
def xview_scroll(self, number, what):
2409-
"""Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2410-
self.tk.call(self._w, 'xview', 'scroll', number, what)
24112420

24122421
class Frame(Widget):
24132422
"""Frame widget which may contain other widgets and can have a 3D border."""
@@ -2449,7 +2458,7 @@ def __init__(self, master=None, cnf={}, **kw):
24492458
"""
24502459
Widget.__init__(self, master, 'label', cnf, kw)
24512460

2452-
class Listbox(Widget):
2461+
class Listbox(Widget, XView, YView):
24532462
"""Listbox widget which can display a list of strings."""
24542463
def __init__(self, master=None, cnf={}, **kw):
24552464
"""Construct a listbox widget with the parent MASTER.
@@ -2528,30 +2537,6 @@ def selection_set(self, first, last=None):
25282537
def size(self):
25292538
"""Return the number of elements in the listbox."""
25302539
return getint(self.tk.call(self._w, 'size'))
2531-
def xview(self, *what):
2532-
"""Query and change horizontal position of the view."""
2533-
if not what:
2534-
return self._getdoubles(self.tk.call(self._w, 'xview'))
2535-
self.tk.call((self._w, 'xview') + what)
2536-
def xview_moveto(self, fraction):
2537-
"""Adjust the view in the window so that FRACTION of the
2538-
total width of the entry is off-screen to the left."""
2539-
self.tk.call(self._w, 'xview', 'moveto', fraction)
2540-
def xview_scroll(self, number, what):
2541-
"""Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2542-
self.tk.call(self._w, 'xview', 'scroll', number, what)
2543-
def yview(self, *what):
2544-
"""Query and change vertical position of the view."""
2545-
if not what:
2546-
return self._getdoubles(self.tk.call(self._w, 'yview'))
2547-
self.tk.call((self._w, 'yview') + what)
2548-
def yview_moveto(self, fraction):
2549-
"""Adjust the view in the window so that FRACTION of the
2550-
total width of the entry is off-screen to the top."""
2551-
self.tk.call(self._w, 'yview', 'moveto', fraction)
2552-
def yview_scroll(self, number, what):
2553-
"""Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2554-
self.tk.call(self._w, 'yview', 'scroll', number, what)
25552540
def itemcget(self, index, option):
25562541
"""Return the resource value for an ITEM and an OPTION."""
25572542
return self.tk.call(
@@ -2798,7 +2783,7 @@ def set(self, *args):
27982783

27992784

28002785

2801-
class Text(Widget):
2786+
class Text(Widget, XView, YView):
28022787
"""Text widget which can display text in various forms."""
28032788
def __init__(self, master=None, cnf={}, **kw):
28042789
"""Construct a text widget with the parent MASTER.
@@ -3120,32 +3105,6 @@ def window_names(self):
31203105
"""Return all names of embedded windows in this widget."""
31213106
return self.tk.splitlist(
31223107
self.tk.call(self._w, 'window', 'names'))
3123-
def xview(self, *what):
3124-
"""Query and change horizontal position of the view."""
3125-
if not what:
3126-
return self._getdoubles(self.tk.call(self._w, 'xview'))
3127-
self.tk.call((self._w, 'xview') + what)
3128-
def xview_moveto(self, fraction):
3129-
"""Adjusts the view in the window so that FRACTION of the
3130-
total width of the canvas is off-screen to the left."""
3131-
self.tk.call(self._w, 'xview', 'moveto', fraction)
3132-
def xview_scroll(self, number, what):
3133-
"""Shift the x-view according to NUMBER which is measured
3134-
in "units" or "pages" (WHAT)."""
3135-
self.tk.call(self._w, 'xview', 'scroll', number, what)
3136-
def yview(self, *what):
3137-
"""Query and change vertical position of the view."""
3138-
if not what:
3139-
return self._getdoubles(self.tk.call(self._w, 'yview'))
3140-
self.tk.call((self._w, 'yview') + what)
3141-
def yview_moveto(self, fraction):
3142-
"""Adjusts the view in the window so that FRACTION of the
3143-
total height of the canvas is off-screen to the top."""
3144-
self.tk.call(self._w, 'yview', 'moveto', fraction)
3145-
def yview_scroll(self, number, what):
3146-
"""Shift the y-view according to NUMBER which is measured
3147-
in "units" or "pages" (WHAT)."""
3148-
self.tk.call(self._w, 'yview', 'scroll', number, what)
31493108
def yview_pickplace(self, *what):
31503109
"""Obsolete function, use see."""
31513110
self.tk.call((self._w, 'yview', '-pickplace') + what)
@@ -3331,7 +3290,7 @@ def image_names(): return _default_root.tk.call('image', 'names')
33313290
def image_types(): return _default_root.tk.call('image', 'types')
33323291

33333292

3334-
class Spinbox(Widget):
3293+
class Spinbox(Widget, XView):
33353294
"""spinbox widget."""
33363295
def __init__(self, master=None, cnf={}, **kw):
33373296
"""Construct a spinbox widget with the parent MASTER.

Lib/tkinter/tix.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ def file_dialog(self):
850850
# FIXME: return python object
851851
pass
852852

853-
class HList(TixWidget):
853+
class HList(TixWidget, XView, YView):
854854
"""HList - Hierarchy display widget can be used to display any data
855855
that have a hierarchical structure, for example, file system directory
856856
trees. The list entries are indented and connected by branch lines
@@ -1037,12 +1037,6 @@ def selection_set(self, first, last=None):
10371037
def show_entry(self, entry):
10381038
return self.tk.call(self._w, 'show', 'entry', entry)
10391039

1040-
def xview(self, *args):
1041-
self.tk.call(self._w, 'xview', *args)
1042-
1043-
def yview(self, *args):
1044-
self.tk.call(self._w, 'yview', *args)
1045-
10461040
class InputOnly(TixWidget):
10471041
"""InputOnly - Invisible widget. Unix only.
10481042
@@ -1419,7 +1413,7 @@ def invoke(self, name):
14191413
if name in self.subwidget_list:
14201414
self.tk.call(self._w, 'invoke', name)
14211415

1422-
class TList(TixWidget):
1416+
class TList(TixWidget, XView, YView):
14231417
"""TList - Hierarchy display widget which can be
14241418
used to display data in a tabular format. The list entries of a TList
14251419
widget are similar to the entries in the Tk listbox widget. The main
@@ -1502,12 +1496,6 @@ def selection_includes(self, index):
15021496
def selection_set(self, first, last=None):
15031497
self.tk.call(self._w, 'selection', 'set', first, last)
15041498

1505-
def xview(self, *args):
1506-
self.tk.call(self._w, 'xview', *args)
1507-
1508-
def yview(self, *args):
1509-
self.tk.call(self._w, 'yview', *args)
1510-
15111499
class Tree(TixWidget):
15121500
"""Tree - The tixTree widget can be used to display hierachical
15131501
data in a tree form. The user can adjust
@@ -1777,7 +1765,7 @@ class of IconView. It implements automatic placement/adjustment of the
17771765
pass
17781766

17791767

1780-
class Grid(TixWidget):
1768+
class Grid(TixWidget, XView, YView):
17811769
'''The Tix Grid command creates a new window and makes it into a
17821770
tixGrid widget. Additional options, may be specified on the command
17831771
line or in the option database to configure aspects such as its cursor
@@ -1865,22 +1853,6 @@ def set(self, x, y, itemtype=None, **kw):
18651853
# def size dim index ?option value ...?
18661854
# def unset x y
18671855

1868-
def xview(self):
1869-
return self._getdoubles(self.tk.call(self, 'xview'))
1870-
def xview_moveto(self, fraction):
1871-
self.tk.call(self,'xview', 'moveto', fraction)
1872-
def xview_scroll(self, count, what="units"):
1873-
"Scroll right (count>0) or left <count> of units|pages"
1874-
self.tk.call(self, 'xview', 'scroll', count, what)
1875-
1876-
def yview(self):
1877-
return self._getdoubles(self.tk.call(self, 'yview'))
1878-
def yview_moveto(self, fraction):
1879-
self.tk.call(self,'ysview', 'moveto', fraction)
1880-
def yview_scroll(self, count, what="units"):
1881-
"Scroll down (count>0) or up <count> of units|pages"
1882-
self.tk.call(self, 'yview', 'scroll', count, what)
1883-
18841856
class ScrolledGrid(Grid):
18851857
'''Scrolled Grid widgets'''
18861858

0 commit comments

Comments
 (0)