cpython: a7c9869a5114 (original) (raw)
Mercurial > cpython
changeset 81011:a7c9869a5114
Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. [#16511]
Andrew Svetlov andrew.svetlov@gmail.com | |
---|---|
date | Mon, 24 Dec 2012 13:17:11 +0200 |
parents | 76c5f3371db6(current diff)10656b0975b3(diff) |
children | deee9f0a4b98 1fb26db7d719 6cfe2982de42 |
files | Lib/idlelib/EditorWindow.py Misc/NEWS |
diffstat | 5 files changed, 65 insertions(+), 35 deletions(-)[+] [-] Lib/idlelib/EditorWindow.py 21 Lib/idlelib/FormatParagraph.py 6 Lib/idlelib/configDialog.py 19 Lib/idlelib/configHandler.py 51 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -170,13 +170,15 @@ class EditorWindow(object): 'recent-files.lst') self.text_frame = text_frame = Frame(top) self.vbar = vbar = Scrollbar(text_frame, name='vbar')
self.width = idleConf.GetOption('main','EditorWindow','width')[](#l1.7)
self.width = idleConf.GetOption('main', 'EditorWindow',[](#l1.8)
'width', type='int')[](#l1.9) text_options = {[](#l1.10) 'name': 'text',[](#l1.11) 'padx': 5,[](#l1.12) 'wrap': 'none',[](#l1.13) 'width': self.width,[](#l1.14)
'height': idleConf.GetOption('main', 'EditorWindow', 'height')}[](#l1.15)
'height': idleConf.GetOption('main', 'EditorWindow',[](#l1.16)
'height', type='int')}[](#l1.17) if TkVersion >= 8.5:[](#l1.18) # Starting with tk 8.5 we have to set the new tabstyle option[](#l1.19) # to 'wordprocessor' to achieve the same display of tabs as in[](#l1.20)
@@ -253,7 +255,8 @@ class EditorWindow(object): if idleConf.GetOption('main', 'EditorWindow', 'font-bold', type='bool'): fontWeight='bold' text.config(font=(idleConf.GetOption('main', 'EditorWindow', 'font'),
idleConf.GetOption('main', 'EditorWindow', 'font-size'),[](#l1.25)
idleConf.GetOption('main', 'EditorWindow',[](#l1.26)
'font-size', type='int'),[](#l1.27) fontWeight))[](#l1.28) text_frame.pack(side=LEFT, fill=BOTH, expand=1)[](#l1.29) text.pack(side=TOP, fill=BOTH, expand=1)[](#l1.30)
@@ -268,7 +271,8 @@ class EditorWindow(object):
# Although use-spaces=0 can be configured manually in config-main.def,
# configuration of tabs v. spaces is not supported in the configuration
# dialog. IDLE promotes the preferred Python indentation: use spaces
usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool')[](#l1.35)
usespaces = idleConf.GetOption('main', 'Indent',[](#l1.36)
'use-spaces', type='bool')[](#l1.37) self.usetabs = not usespaces[](#l1.38)
# tabwidth is the display width of a literal tab character. @@ -382,9 +386,11 @@ class EditorWindow(object): self.text.tag_remove("sel", "1.0", "end") else: if not self.text.index("sel.first"):
self.text.mark_set("my_anchor", "insert") # there was no previous selection[](#l1.45)
# there was no previous selection[](#l1.46)
self.text.mark_set("my_anchor", "insert")[](#l1.47) else:[](#l1.48)
if self.text.compare(self.text.index("sel.first"), "<", self.text.index("insert")):[](#l1.49)
if self.text.compare(self.text.index("sel.first"), "<",[](#l1.50)
self.text.index("insert")):[](#l1.51) self.text.mark_set("my_anchor", "sel.first") # extend back[](#l1.52) else:[](#l1.53) self.text.mark_set("my_anchor", "sel.last") # extend forward[](#l1.54)
@@ -766,7 +772,8 @@ class EditorWindow(object): if idleConf.GetOption('main','EditorWindow','font-bold',type='bool'): fontWeight='bold' self.text.config(font=(idleConf.GetOption('main','EditorWindow','font'),
idleConf.GetOption('main','EditorWindow','font-size'),[](#l1.59)
idleConf.GetOption('main','EditorWindow','font-size',[](#l1.60)
type='int'),[](#l1.61) fontWeight))[](#l1.62)
--- a/Lib/idlelib/FormatParagraph.py +++ b/Lib/idlelib/FormatParagraph.py @@ -32,7 +32,8 @@ class FormatParagraph: self.editwin = None def format_paragraph_event(self, event):
maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph'))[](#l2.7)
maxformatwidth = int(idleConf.GetOption('main', 'FormatParagraph',[](#l2.8)
'paragraph', type='int'))[](#l2.9) text = self.editwin.text[](#l2.10) first, last = self.editwin.get_selection_indices()[](#l2.11) if first and last:[](#l2.12)
@@ -46,7 +47,8 @@ class FormatParagraph: lines = data.split("\n") lines = map(lambda st, l=len(comment_header): st[l:], lines) data = "\n".join(lines)
# Reformat to maxformatwidth chars or a 20 char width, whichever is greater.[](#l2.17)
# Reformat to maxformatwidth chars or a 20 char width,[](#l2.18)
# whichever is greater.[](#l2.19) format_width = max(maxformatwidth - len(comment_header), 20)[](#l2.20) newdata = reformat_paragraph(data, format_width)[](#l2.21) # re-split and re-insert the comment header.[](#l2.22)
--- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -925,7 +925,7 @@ class ConfigDialog(Toplevel): for font in fonts: self.listFontName.insert(END,font) configuredFont=idleConf.GetOption('main','EditorWindow','font',
default='courier')[](#l3.7)
default='courier')[](#l3.8) lc_configuredFont = configuredFont.lower()[](#l3.9) self.fontName.set(lc_configuredFont)[](#l3.10) lc_fonts = [s.lower() for s in fonts][](#l3.11)
@@ -935,13 +935,13 @@ class ConfigDialog(Toplevel): self.listFontName.select_set(currentFontIndex) self.listFontName.select_anchor(currentFontIndex) ##font size dropdown
fontSize=idleConf.GetOption('main','EditorWindow','font-size',[](#l3.16)
default='10')[](#l3.17)
fontSize=idleConf.GetOption('main', 'EditorWindow', 'font-size',[](#l3.18)
type='int', default='10')[](#l3.19) self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14',[](#l3.20)
'16','18','20','22'),fontSize )[](#l3.21)
'16','18','20','22'), fontSize )[](#l3.22) ##fontWeight[](#l3.23) self.fontBold.set(idleConf.GetOption('main','EditorWindow',[](#l3.24)
'font-bold',default=0,type='bool'))[](#l3.25)
'font-bold',default=0,type='bool'))[](#l3.26) ##font sample[](#l3.27) self.SetFontSample()[](#l3.28)
@@ -1022,10 +1022,13 @@ class ConfigDialog(Toplevel): self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave', default=0, type='bool')) #initial window size
self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))[](#l3.34)
self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))[](#l3.35)
self.winWidth.set(idleConf.GetOption('main','EditorWindow','width',[](#l3.36)
type='int'))[](#l3.37)
self.winHeight.set(idleConf.GetOption('main','EditorWindow','height',[](#l3.38)
type='int'))[](#l3.39) #initial paragraph reformat size[](#l3.40)
self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph'))[](#l3.41)
self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph',[](#l3.42)
type='int'))[](#l3.43) # default source encoding[](#l3.44) self.encoding.set(idleConf.GetOption('main', 'EditorWindow',[](#l3.45) 'encoding', default='none'))[](#l3.46)
--- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -238,24 +238,39 @@ class IdleConf: printed to stderr. """
if self.userCfg[configType].has_option(section,option):[](#l4.7)
return self.userCfg[configType].Get(section, option,[](#l4.8)
type=type, raw=raw)[](#l4.9)
elif self.defaultCfg[configType].has_option(section,option):[](#l4.10)
return self.defaultCfg[configType].Get(section, option,[](#l4.11)
type=type, raw=raw)[](#l4.12)
else: #returning default, print warning[](#l4.13)
if warn_on_default:[](#l4.14)
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'[](#l4.15)
' problem retrieving configuration option %r\n'[](#l4.16)
' from section %r.\n'[](#l4.17)
' returning default value: %r\n' %[](#l4.18)
(option, section, default))[](#l4.19)
try:[](#l4.20)
sys.stderr.write(warning)[](#l4.21)
except IOError:[](#l4.22)
pass[](#l4.23)
return default[](#l4.24)
try:[](#l4.25)
if self.userCfg[configType].has_option(section,option):[](#l4.26)
return self.userCfg[configType].Get(section, option,[](#l4.27)
type=type, raw=raw)[](#l4.28)
except ValueError:[](#l4.29)
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'[](#l4.30)
' invalid %r value for configuration option %r\n'[](#l4.31)
' from section %r: %r\n' %[](#l4.32)
(type, option, section,[](#l4.33)
self.userCfg[configType].Get(section, option,[](#l4.34)
raw=raw)))[](#l4.35)
try:[](#l4.36)
sys.stderr.write(warning)[](#l4.37)
except IOError:[](#l4.38)
pass[](#l4.39)
try:[](#l4.40)
if self.defaultCfg[configType].has_option(section,option):[](#l4.41)
return self.defaultCfg[configType].Get(section, option,[](#l4.42)
type=type, raw=raw)[](#l4.43)
except ValueError:[](#l4.44)
pass[](#l4.45)
#returning default, print warning[](#l4.46)
if warn_on_default:[](#l4.47)
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'[](#l4.48)
' problem retrieving configuration option %r\n'[](#l4.49)
' from section %r.\n'[](#l4.50)
' returning default value: %r\n' %[](#l4.51)
(option, section, default))[](#l4.52)
try:[](#l4.53)
sys.stderr.write(warning)[](#l4.54)
except IOError:[](#l4.55)
pass[](#l4.56)
return default[](#l4.57)
def SetOption(self, configType, section, option, value): """In user's config file, set section's option to value.
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -178,6 +178,9 @@ Core and Builtins Library ------- +- Issue #16511: Use default IDLE width and height if config param is not valid.