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

Skip to content

Commit 6a7a49c

Browse files
committed
Issue #16511: Use default IDLE width and height if config param is not valid.
Patch Serhiy Storchaka.
2 parents 7d2fad1 + 7174f08 commit 6a7a49c

5 files changed

Lines changed: 65 additions & 35 deletions

File tree

Lib/idlelib/EditorWindow.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,15 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
170170
'recent-files.lst')
171171
self.text_frame = text_frame = Frame(top)
172172
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
173-
self.width = idleConf.GetOption('main','EditorWindow','width')
173+
self.width = idleConf.GetOption('main', 'EditorWindow',
174+
'width', type='int')
174175
text_options = {
175176
'name': 'text',
176177
'padx': 5,
177178
'wrap': 'none',
178179
'width': self.width,
179-
'height': idleConf.GetOption('main', 'EditorWindow', 'height')}
180+
'height': idleConf.GetOption('main', 'EditorWindow',
181+
'height', type='int')}
180182
if TkVersion >= 8.5:
181183
# Starting with tk 8.5 we have to set the new tabstyle option
182184
# to 'wordprocessor' to achieve the same display of tabs as in
@@ -253,7 +255,8 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
253255
if idleConf.GetOption('main', 'EditorWindow', 'font-bold', type='bool'):
254256
fontWeight='bold'
255257
text.config(font=(idleConf.GetOption('main', 'EditorWindow', 'font'),
256-
idleConf.GetOption('main', 'EditorWindow', 'font-size'),
258+
idleConf.GetOption('main', 'EditorWindow',
259+
'font-size', type='int'),
257260
fontWeight))
258261
text_frame.pack(side=LEFT, fill=BOTH, expand=1)
259262
text.pack(side=TOP, fill=BOTH, expand=1)
@@ -268,7 +271,8 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
268271
# Although use-spaces=0 can be configured manually in config-main.def,
269272
# configuration of tabs v. spaces is not supported in the configuration
270273
# dialog. IDLE promotes the preferred Python indentation: use spaces!
271-
usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool')
274+
usespaces = idleConf.GetOption('main', 'Indent',
275+
'use-spaces', type='bool')
272276
self.usetabs = not usespaces
273277

274278
# tabwidth is the display width of a literal tab character.
@@ -382,9 +386,11 @@ def home_callback(self, event):
382386
self.text.tag_remove("sel", "1.0", "end")
383387
else:
384388
if not self.text.index("sel.first"):
385-
self.text.mark_set("my_anchor", "insert") # there was no previous selection
389+
# there was no previous selection
390+
self.text.mark_set("my_anchor", "insert")
386391
else:
387-
if self.text.compare(self.text.index("sel.first"), "<", self.text.index("insert")):
392+
if self.text.compare(self.text.index("sel.first"), "<",
393+
self.text.index("insert")):
388394
self.text.mark_set("my_anchor", "sel.first") # extend back
389395
else:
390396
self.text.mark_set("my_anchor", "sel.last") # extend forward
@@ -766,7 +772,8 @@ def ResetFont(self):
766772
if idleConf.GetOption('main','EditorWindow','font-bold',type='bool'):
767773
fontWeight='bold'
768774
self.text.config(font=(idleConf.GetOption('main','EditorWindow','font'),
769-
idleConf.GetOption('main','EditorWindow','font-size'),
775+
idleConf.GetOption('main','EditorWindow','font-size',
776+
type='int'),
770777
fontWeight))
771778

772779
def RemoveKeybindings(self):

Lib/idlelib/FormatParagraph.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def close(self):
3232
self.editwin = None
3333

3434
def format_paragraph_event(self, event):
35-
maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph'))
35+
maxformatwidth = int(idleConf.GetOption('main', 'FormatParagraph',
36+
'paragraph', type='int'))
3637
text = self.editwin.text
3738
first, last = self.editwin.get_selection_indices()
3839
if first and last:
@@ -46,7 +47,8 @@ def format_paragraph_event(self, event):
4647
lines = data.split("\n")
4748
lines = map(lambda st, l=len(comment_header): st[l:], lines)
4849
data = "\n".join(lines)
49-
# Reformat to maxformatwidth chars or a 20 char width, whichever is greater.
50+
# Reformat to maxformatwidth chars or a 20 char width,
51+
# whichever is greater.
5052
format_width = max(maxformatwidth - len(comment_header), 20)
5153
newdata = reformat_paragraph(data, format_width)
5254
# re-split and re-insert the comment header.

Lib/idlelib/configDialog.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ def LoadFontCfg(self):
925925
for font in fonts:
926926
self.listFontName.insert(END,font)
927927
configuredFont=idleConf.GetOption('main','EditorWindow','font',
928-
default='courier')
928+
default='courier')
929929
lc_configuredFont = configuredFont.lower()
930930
self.fontName.set(lc_configuredFont)
931931
lc_fonts = [s.lower() for s in fonts]
@@ -935,13 +935,13 @@ def LoadFontCfg(self):
935935
self.listFontName.select_set(currentFontIndex)
936936
self.listFontName.select_anchor(currentFontIndex)
937937
##font size dropdown
938-
fontSize=idleConf.GetOption('main','EditorWindow','font-size',
939-
default='10')
938+
fontSize=idleConf.GetOption('main', 'EditorWindow', 'font-size',
939+
type='int', default='10')
940940
self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14',
941-
'16','18','20','22'),fontSize )
941+
'16','18','20','22'), fontSize )
942942
##fontWeight
943943
self.fontBold.set(idleConf.GetOption('main','EditorWindow',
944-
'font-bold',default=0,type='bool'))
944+
'font-bold',default=0,type='bool'))
945945
##font sample
946946
self.SetFontSample()
947947

@@ -1022,10 +1022,13 @@ def LoadGeneralCfg(self):
10221022
self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave',
10231023
default=0, type='bool'))
10241024
#initial window size
1025-
self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))
1026-
self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))
1025+
self.winWidth.set(idleConf.GetOption('main','EditorWindow','width',
1026+
type='int'))
1027+
self.winHeight.set(idleConf.GetOption('main','EditorWindow','height',
1028+
type='int'))
10271029
#initial paragraph reformat size
1028-
self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph'))
1030+
self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph',
1031+
type='int'))
10291032
# default source encoding
10301033
self.encoding.set(idleConf.GetOption('main', 'EditorWindow',
10311034
'encoding', default='none'))

Lib/idlelib/configHandler.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,39 @@ def GetOption(self, configType, section, option, default=None, type=None,
238238
printed to stderr.
239239
240240
"""
241-
if self.userCfg[configType].has_option(section,option):
242-
return self.userCfg[configType].Get(section, option,
243-
type=type, raw=raw)
244-
elif self.defaultCfg[configType].has_option(section,option):
245-
return self.defaultCfg[configType].Get(section, option,
246-
type=type, raw=raw)
247-
else: #returning default, print warning
248-
if warn_on_default:
249-
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
250-
' problem retrieving configuration option %r\n'
251-
' from section %r.\n'
252-
' returning default value: %r\n' %
253-
(option, section, default))
254-
try:
255-
sys.stderr.write(warning)
256-
except IOError:
257-
pass
258-
return default
241+
try:
242+
if self.userCfg[configType].has_option(section,option):
243+
return self.userCfg[configType].Get(section, option,
244+
type=type, raw=raw)
245+
except ValueError:
246+
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
247+
' invalid %r value for configuration option %r\n'
248+
' from section %r: %r\n' %
249+
(type, option, section,
250+
self.userCfg[configType].Get(section, option,
251+
raw=raw)))
252+
try:
253+
sys.stderr.write(warning)
254+
except IOError:
255+
pass
256+
try:
257+
if self.defaultCfg[configType].has_option(section,option):
258+
return self.defaultCfg[configType].Get(section, option,
259+
type=type, raw=raw)
260+
except ValueError:
261+
pass
262+
#returning default, print warning
263+
if warn_on_default:
264+
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
265+
' problem retrieving configuration option %r\n'
266+
' from section %r.\n'
267+
' returning default value: %r\n' %
268+
(option, section, default))
269+
try:
270+
sys.stderr.write(warning)
271+
except IOError:
272+
pass
273+
return default
259274

260275
def SetOption(self, configType, section, option, value):
261276
"""In user's config file, set section's option to value.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ Core and Builtins
178178
Library
179179
-------
180180

181+
- Issue #16511: Use default IDLE width and height if config param is not valid.
182+
Patch Serhiy Storchaka.
183+
181184
- Issue #16443: Add docstrings to regular expression match objects.
182185
Patch by Anton Kasyanov.
183186

0 commit comments

Comments
 (0)