Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/configHandler.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 87ada87057a2 |
| children | 133f87a7dbf5 |
| rev | line source |
|---|---|
| 27245 | 1 """Provides access to stored IDLE configuration information. |
| 2 | |
| 3 Refer to the comments at the beginning of config-main.def for a description of | |
| 4 the available configuration files and the design implemented to update user | |
| 5 configuration information. In particular, user configuration choices which | |
| 6 duplicate the defaults will be removed from the user's configuration files, | |
| 27409 | 7 and if a file becomes empty, it will be deleted. |
| 27245 | 8 |
| 9 The contents of the user files may be altered using the Options/Configure IDLE | |
| 10 menu to access the configuration GUI (configDialog.py), or manually. | |
| 11 | |
| 12 Throughout this module there is an emphasis on returning useable defaults | |
| 13 when a problem occurs in returning a requested configuration value back to | |
| 14 idle. This is to allow IDLE to continue to function in spite of errors in | |
| 15 the retrieval of config information. When a default is returned instead of | |
| 16 a requested config value, a message is printed to stderr to aid in | |
| 17 configuration problem notification and resolution. | |
| 18 | |
|
21626
de1ebcef7d31
move core functionality of SearchBindings.py into EditorWindow.py proper
Steven M. Gava <elguavas@python.net>
parents:
21623
diff
changeset
|
19 """ |
| 27245 | 20 import os |
| 21 import sys | |
| 22 import string | |
|
63585
df378e44ba9a
Merged revisions 79576-79578 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47252
diff
changeset
|
23 from idlelib import macosxSupport |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
24 from ConfigParser import ConfigParser, NoOptionError, NoSectionError |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
25 |
|
26473
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
26 class InvalidConfigType(Exception): pass |
|
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
27 class InvalidConfigSet(Exception): pass |
|
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
28 class InvalidFgBg(Exception): pass |
|
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
29 class InvalidTheme(Exception): pass |
|
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
30 |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
31 class IdleConfParser(ConfigParser): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
32 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
33 A ConfigParser specialised for idle configuration file handling |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
34 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
35 def __init__(self, cfgFile, cfgDefaults=None): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
36 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
37 cfgFile - string, fully specified configuration file name |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
38 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
39 self.file=cfgFile |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
40 ConfigParser.__init__(self,defaults=cfgDefaults) |
| 26959 | 41 |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
42 def Get(self, section, option, type=None, default=None, raw=False): |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
43 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
44 Get an option value for given section/option or return default. |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
45 If type is specified, return as type. |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
46 """ |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
47 if not self.has_option(section, option): |
|
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
48 return default |
| 26959 | 49 if type=='bool': |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
50 return self.getboolean(section, option) |
| 26959 | 51 elif type=='int': |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
52 return self.getint(section, option) |
| 26959 | 53 else: |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
54 return self.get(section, option, raw=raw) |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
55 |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
56 def GetOptionList(self,section): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
57 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
58 Get an option list for given section |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
59 """ |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
60 if self.has_section(section): |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
61 return self.options(section) |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
62 else: #return a default value |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
63 return [] |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
64 |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
65 def Load(self): |
| 26959 | 66 """ |
| 67 Load the configuration file from disk | |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
68 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
69 self.read(self.file) |
| 26959 | 70 |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
71 class IdleUserConfParser(IdleConfParser): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
72 """ |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
73 IdleConfigParser specialised for user configuration handling. |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
74 """ |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
75 |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
76 def AddSection(self,section): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
77 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
78 if section doesn't exist, add it |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
79 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
80 if not self.has_section(section): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
81 self.add_section(section) |
| 26959 | 82 |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
83 def RemoveEmptySections(self): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
84 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
85 remove any sections that have no options |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
86 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
87 for section in self.sections(): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
88 if not self.GetOptionList(section): |
| 26959 | 89 self.remove_section(section) |
| 90 | |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
91 def IsEmpty(self): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
92 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
93 Remove empty sections and then return 1 if parser has no sections |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
94 left, else return 0. |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
95 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
96 self.RemoveEmptySections() |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
97 if self.sections(): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
98 return 0 |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
99 else: |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
100 return 1 |
| 26959 | 101 |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
102 def RemoveOption(self,section,option): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
103 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
104 If section/option exists, remove it. |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
105 Returns 1 if option was removed, 0 otherwise. |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
106 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
107 if self.has_section(section): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
108 return self.remove_option(section,option) |
| 26959 | 109 |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
110 def SetOption(self,section,option,value): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
111 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
112 Sets option to value, adding section if required. |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
113 Returns 1 if option was added or changed, otherwise 0. |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
114 """ |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
115 if self.has_option(section,option): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
116 if self.get(section,option)==value: |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
117 return 0 |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
118 else: |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
119 self.set(section,option,value) |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
120 return 1 |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
121 else: |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
122 if not self.has_section(section): |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
123 self.add_section(section) |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
124 self.set(section,option,value) |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
125 return 1 |
| 26959 | 126 |
|
22111
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21975
diff
changeset
|
127 def RemoveFile(self): |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21975
diff
changeset
|
128 """ |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21975
diff
changeset
|
129 Removes the user config file from disk if it exists. |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21975
diff
changeset
|
130 """ |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21975
diff
changeset
|
131 if os.path.exists(self.file): |
| 26959 | 132 os.remove(self.file) |
| 133 | |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
134 def Save(self): |
| 27245 | 135 """Update user configuration file. |
| 136 | |
| 137 Remove empty sections. If resulting config isn't empty, write the file | |
| 138 to disk. If config is empty, remove the file from disk if it exists. | |
| 139 | |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
140 """ |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
141 if not self.IsEmpty(): |
|
45328
76b2de9c9b0b
Could not open files in .idlerc directory if latter was hidden on Windows.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
142 fname = self.file |
|
76b2de9c9b0b
Could not open files in .idlerc directory if latter was hidden on Windows.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
143 try: |
|
76b2de9c9b0b
Could not open files in .idlerc directory if latter was hidden on Windows.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
144 cfgFile = open(fname, 'w') |
|
76b2de9c9b0b
Could not open files in .idlerc directory if latter was hidden on Windows.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
145 except IOError: |
|
76b2de9c9b0b
Could not open files in .idlerc directory if latter was hidden on Windows.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
146 os.unlink(fname) |
|
76b2de9c9b0b
Could not open files in .idlerc directory if latter was hidden on Windows.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
147 cfgFile = open(fname, 'w') |
|
21835
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
148 self.write(cfgFile) |
|
f379bc0c5e3f
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21798
diff
changeset
|
149 else: |
|
22111
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21975
diff
changeset
|
150 self.RemoveFile() |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
151 |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
152 class IdleConf: |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
153 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
154 holds config parsers for all idle config files: |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
155 default config files |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
156 (idle install dir)/config-main.def |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
157 (idle install dir)/config-extensions.def |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
158 (idle install dir)/config-highlight.def |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
159 (idle install dir)/config-keys.def |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
160 user config files |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
161 (user home dir)/.idlerc/config-main.cfg |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
162 (user home dir)/.idlerc/config-extensions.cfg |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
163 (user home dir)/.idlerc/config-highlight.cfg |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
164 (user home dir)/.idlerc/config-keys.cfg |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
165 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
166 def __init__(self): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
167 self.defaultCfg={} |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
168 self.userCfg={} |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
169 self.cfg={} |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
170 self.CreateConfigHandlers() |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
171 self.LoadCfgFiles() |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
172 #self.LoadCfg() |
| 26959 | 173 |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
174 def CreateConfigHandlers(self): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
175 """ |
| 26959 | 176 set up a dictionary of config parsers for default and user |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
177 configurations respectively |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
178 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
179 #build idle install path |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
180 if __name__ != '__main__': # we were imported |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
181 idleDir=os.path.dirname(__file__) |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
182 else: # we were exec'ed (for testing only) |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
183 idleDir=os.path.abspath(sys.path[0]) |
|
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
184 userDir=self.GetUserCfgDir() |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
185 configTypes=('main','extensions','highlight','keys') |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
186 defCfgFiles={} |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
187 usrCfgFiles={} |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
188 for cfgType in configTypes: #build config file names |
| 26959 | 189 defCfgFiles[cfgType]=os.path.join(idleDir,'config-'+cfgType+'.def') |
| 190 usrCfgFiles[cfgType]=os.path.join(userDir,'config-'+cfgType+'.cfg') | |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
191 for cfgType in configTypes: #create config parsers |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
192 self.defaultCfg[cfgType]=IdleConfParser(defCfgFiles[cfgType]) |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
193 self.userCfg[cfgType]=IdleUserConfParser(usrCfgFiles[cfgType]) |
| 26959 | 194 |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
195 def GetUserCfgDir(self): |
|
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
196 """ |
| 26959 | 197 Creates (if required) and returns a filesystem directory for storing |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
198 user config files. |
|
35003
52fed2d0641a
whitespace normalisation
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34469
diff
changeset
|
199 |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
200 """ |
|
34469
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
201 cfgDir = '.idlerc' |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
202 userDir = os.path.expanduser('~') |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
203 if userDir != '~': # expanduser() found user home dir |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
204 if not os.path.exists(userDir): |
|
34469
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
205 warn = ('\n Warning: os.path.expanduser("~") points to\n '+ |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
206 userDir+',\n but the path does not exist.\n') |
|
46526
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
207 try: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
208 sys.stderr.write(warn) |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
209 except IOError: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
210 pass |
|
34469
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
211 userDir = '~' |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
212 if userDir == "~": # still no path to home! |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
213 # traditionally IDLE has defaulted to os.getcwd(), is this adequate? |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
214 userDir = os.getcwd() |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
215 userDir = os.path.join(userDir, cfgDir) |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
216 if not os.path.exists(userDir): |
|
34469
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
217 try: |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
218 os.mkdir(userDir) |
|
34469
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
219 except (OSError, IOError): |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
220 warn = ('\n Warning: unable to create user config directory\n'+ |
|
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
221 userDir+'\n Check path and permissions.\n Exiting!\n\n') |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
222 sys.stderr.write(warn) |
|
34469
f738d64c827d
Improve error handling when .idlerc can't be created (warn and exit)
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
223 raise SystemExit |
|
21855
1f2e92850188
improve user config dir handling
Steven M. Gava <elguavas@python.net>
parents:
21854
diff
changeset
|
224 return userDir |
| 26959 | 225 |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
226 def GetOption(self, configType, section, option, default=None, type=None, |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
227 warn_on_default=True, raw=False): |
|
20628
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
228 """ |
| 26959 | 229 Get an option value for given config type and given general |
|
20628
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
230 configuration section/option or return a default. If type is specified, |
| 26959 | 231 return as type. Firstly the user configuration is checked, with a |
| 232 fallback to the default configuration, and a final 'catch all' | |
| 233 fallback to a useable passed-in default if the option isn't present in | |
|
20628
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
234 either the user or the default configuration. |
|
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
235 configType must be one of ('main','extensions','highlight','keys') |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
236 If a default is returned, and warn_on_default is True, a warning is |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
237 printed to stderr. |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
238 |
|
20628
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
239 """ |
|
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
240 if self.userCfg[configType].has_option(section,option): |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
241 return self.userCfg[configType].Get(section, option, |
|
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
242 type=type, raw=raw) |
|
20628
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
243 elif self.defaultCfg[configType].has_option(section,option): |
|
40743
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
244 return self.defaultCfg[configType].Get(section, option, |
|
ccac636b152c
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
38748
diff
changeset
|
245 type=type, raw=raw) |
|
21906
f881e0618df0
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21875
diff
changeset
|
246 else: #returning default, print warning |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
247 if warn_on_default: |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
248 warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' |
| 52400 | 249 ' problem retrieving configuration option %r\n' |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
250 ' from section %r.\n' |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
251 ' returning default value: %r\n' % |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
252 (option, section, default)) |
|
46526
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
253 try: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
254 sys.stderr.write(warning) |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
255 except IOError: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
256 pass |
|
20628
1598588ef1ad
font/tabs config dialog page now reads its data from the config file
Steven M. Gava <elguavas@python.net>
parents:
20052
diff
changeset
|
257 return default |
| 26959 | 258 |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
259 def SetOption(self, configType, section, option, value): |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
260 """In user's config file, set section's option to value. |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
261 |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
262 """ |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
263 self.userCfg[configType].SetOption(section, option, value) |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
264 |
|
20686
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
265 def GetSectionList(self, configSet, configType): |
|
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
266 """ |
| 26959 | 267 Get a list of sections from either the user or default config for |
|
20686
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
268 the given config type. |
| 26959 | 269 configSet must be either 'user' or 'default' |
|
21767
8a2cd1c0c135
extension config reading by configDialog and
Steven M. Gava <elguavas@python.net>
parents:
21764
diff
changeset
|
270 configType must be one of ('main','extensions','highlight','keys') |
|
20686
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
271 """ |
|
21767
8a2cd1c0c135
extension config reading by configDialog and
Steven M. Gava <elguavas@python.net>
parents:
21764
diff
changeset
|
272 if not (configType in ('main','extensions','highlight','keys')): |
|
26473
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
273 raise InvalidConfigType, 'Invalid configType specified' |
|
20686
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
274 if configSet == 'user': |
|
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
275 cfgParser=self.userCfg[configType] |
|
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
276 elif configSet == 'default': |
|
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
277 cfgParser=self.defaultCfg[configType] |
|
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
278 else: |
|
26473
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
279 raise InvalidConfigSet, 'Invalid configSet specified' |
|
20686
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
280 return cfgParser.sections() |
| 26959 | 281 |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
282 def GetHighlight(self, theme, element, fgBg=None): |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
283 """ |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
284 return individual highlighting theme elements. |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
285 fgBg - string ('fg'or'bg') or None, if None return a dictionary |
| 26959 | 286 containing fg and bg colours (appropriate for passing to Tkinter in, |
| 287 e.g., a tag_config call), otherwise fg or bg colour only as specified. | |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
288 """ |
|
21908
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
289 if self.defaultCfg['highlight'].has_section(theme): |
|
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
290 themeDict=self.GetThemeDict('default',theme) |
|
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
291 else: |
|
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
292 themeDict=self.GetThemeDict('user',theme) |
|
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
293 fore=themeDict[element+'-foreground'] |
|
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
294 if element=='cursor': #there is no config value for cursor bg |
|
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
295 back=themeDict['normal-background'] |
| 26959 | 296 else: |
|
21908
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
297 back=themeDict[element+'-background'] |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
298 highlight={"foreground": fore,"background": back} |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
299 if not fgBg: #return dict of both colours |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
300 return highlight |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
301 else: #return specified colour only |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
302 if fgBg == 'fg': |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
303 return highlight["foreground"] |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
304 if fgBg == 'bg': |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
305 return highlight["background"] |
| 26959 | 306 else: |
|
26473
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
307 raise InvalidFgBg, 'Invalid fgBg specified' |
|
21908
16faf6875004
base GetHighlight on GetThemeDict for better defaults
Steven M. Gava <elguavas@python.net>
parents:
21906
diff
changeset
|
308 |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
309 def GetThemeDict(self,type,themeName): |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
310 """ |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
311 type - string, 'default' or 'user' theme type |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
312 themeName - string, theme name |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
313 Returns a dictionary which holds {option:value} for each element |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
314 in the specified theme. Values are loaded over a set of ultimate last |
| 26959 | 315 fallback defaults to guarantee that all theme elements are present in |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
316 a newly created theme. |
|
20686
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
317 """ |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
318 if type == 'user': |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
319 cfgParser=self.userCfg['highlight'] |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
320 elif type == 'default': |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
321 cfgParser=self.defaultCfg['highlight'] |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
322 else: |
|
26473
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
323 raise InvalidTheme, 'Invalid theme type specified' |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
324 #foreground and background values are provded for each theme element |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
325 #(apart from cursor) even though all these values are not yet used |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
326 #by idle, to allow for their use in the future. Default values are |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
327 #generally black and white. |
| 26959 | 328 theme={ 'normal-foreground':'#000000', |
| 329 'normal-background':'#ffffff', | |
| 330 'keyword-foreground':'#000000', | |
| 331 'keyword-background':'#ffffff', | |
|
31625
1b02c77cdcfe
Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
332 'builtin-foreground':'#000000', |
|
1b02c77cdcfe
Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
333 'builtin-background':'#ffffff', |
| 26959 | 334 'comment-foreground':'#000000', |
| 335 'comment-background':'#ffffff', | |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
336 'string-foreground':'#000000', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
337 'string-background':'#ffffff', |
| 26959 | 338 'definition-foreground':'#000000', |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
339 'definition-background':'#ffffff', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
340 'hilite-foreground':'#000000', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
341 'hilite-background':'gray', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
342 'break-foreground':'#ffffff', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
343 'break-background':'#000000', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
344 'hit-foreground':'#ffffff', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
345 'hit-background':'#000000', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
346 'error-foreground':'#ffffff', |
| 26959 | 347 'error-background':'#000000', |
| 348 #cursor (only foreground can be set) | |
| 349 'cursor-foreground':'#000000', | |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
350 #shell window |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
351 'stdout-foreground':'#000000', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
352 'stdout-background':'#ffffff', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
353 'stderr-foreground':'#000000', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
354 'stderr-background':'#ffffff', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
355 'console-foreground':'#000000', |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
356 'console-background':'#ffffff' } |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
357 for element in theme.keys(): |
|
21906
f881e0618df0
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21875
diff
changeset
|
358 if not cfgParser.has_option(themeName,element): |
|
f881e0618df0
further work on config saving
Steven M. Gava <elguavas@python.net>
parents:
21875
diff
changeset
|
359 #we are going to return a default, print warning |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
360 warning=('\n Warning: configHandler.py - IdleConf.GetThemeDict' |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
361 ' -\n problem retrieving theme element %r' |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
362 '\n from theme %r.\n' |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
363 ' returning default value: %r\n' % |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
364 (element, themeName, theme[element])) |
|
46526
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
365 try: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
366 sys.stderr.write(warning) |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
367 except IOError: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
368 pass |
| 26959 | 369 colour=cfgParser.Get(themeName,element,default=theme[element]) |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
370 theme[element]=colour |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
371 return theme |
| 26959 | 372 |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
373 def CurrentTheme(self): |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
374 """ |
| 26959 | 375 Returns the name of the currently active theme |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
376 """ |
|
21627
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
377 return self.GetOption('main','Theme','name',default='') |
| 26959 | 378 |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
379 def CurrentKeys(self): |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
380 """ |
| 26959 | 381 Returns the name of the currently active key set |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
382 """ |
|
21627
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
383 return self.GetOption('main','Keys','name',default='') |
| 26959 | 384 |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
385 def GetExtensions(self, active_only=True, editor_only=False, shell_only=False): |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
386 """ |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
387 Gets a list of all idle extensions declared in the config files. |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
388 active_only - boolean, if true only return active (enabled) extensions |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
389 """ |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
390 extns=self.RemoveKeyBindNames( |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
391 self.GetSectionList('default','extensions')) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
392 userExtns=self.RemoveKeyBindNames( |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
393 self.GetSectionList('user','extensions')) |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
394 for extn in userExtns: |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
395 if extn not in extns: #user has added own extension |
| 26959 | 396 extns.append(extn) |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
397 if active_only: |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
398 activeExtns=[] |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
399 for extn in extns: |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
400 if self.GetOption('extensions', extn, 'enable', default=True, |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
401 type='bool'): |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
402 #the extension is enabled |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
403 if editor_only or shell_only: |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
404 if editor_only: |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
405 option = "enable_editor" |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
406 else: |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
407 option = "enable_shell" |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
408 if self.GetOption('extensions', extn,option, |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
409 default=True, type='bool', |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
410 warn_on_default=False): |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
411 activeExtns.append(extn) |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
412 else: |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
413 activeExtns.append(extn) |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
414 return activeExtns |
|
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
415 else: |
| 26959 | 416 return extns |
|
21623
be8697c70e7c
further development of highlighting and editor preference handling,
Steven M. Gava <elguavas@python.net>
parents:
21144
diff
changeset
|
417 |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
418 def RemoveKeyBindNames(self,extnNameList): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
419 #get rid of keybinding section names |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
420 names=extnNameList |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
421 kbNameIndicies=[] |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
422 for name in names: |
|
38704
ba6eebf7c719
Make use of new str.startswith/endswith semantics.
Georg Brandl <georg@python.org>
parents:
34515
diff
changeset
|
423 if name.endswith(('_bindings', '_cfgBindings')): |
| 26959 | 424 kbNameIndicies.append(names.index(name)) |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
425 kbNameIndicies.sort() |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
426 kbNameIndicies.reverse() |
| 26959 | 427 for index in kbNameIndicies: #delete each keybinding section name |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
428 del(names[index]) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
429 return names |
| 26959 | 430 |
|
21854
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
431 def GetExtnNameForEvent(self,virtualEvent): |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
432 """ |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
433 Returns the name of the extension that virtualEvent is bound in, or |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
434 None if not bound in any extension. |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
435 virtualEvent - string, name of the virtual event to test for, without |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
436 the enclosing '<< >>' |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
437 """ |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
438 extName=None |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
439 vEvent='<<'+virtualEvent+'>>' |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
440 for extn in self.GetExtensions(active_only=0): |
|
21854
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
441 for event in self.GetExtensionKeys(extn).keys(): |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
442 if event == vEvent: |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
443 extName=extn |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
444 return extName |
| 26959 | 445 |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
446 def GetExtensionKeys(self,extensionName): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
447 """ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
448 returns a dictionary of the configurable keybindings for a particular |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
449 extension,as they exist in the dictionary returned by GetCurrentKeySet; |
|
21854
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
450 that is, where previously used bindings are disabled. |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
451 """ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
452 keysName=extensionName+'_cfgBindings' |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
453 activeKeys=self.GetCurrentKeySet() |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
454 extKeys={} |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
455 if self.defaultCfg['extensions'].has_section(keysName): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
456 eventNames=self.defaultCfg['extensions'].GetOptionList(keysName) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
457 for eventName in eventNames: |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
458 event='<<'+eventName+'>>' |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
459 binding=activeKeys[event] |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
460 extKeys[event]=binding |
| 26959 | 461 return extKeys |
| 462 | |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
463 def __GetRawExtensionKeys(self,extensionName): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
464 """ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
465 returns a dictionary of the configurable keybindings for a particular |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
466 extension, as defined in the configuration files, or an empty dictionary |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
467 if no bindings are found |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
468 """ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
469 keysName=extensionName+'_cfgBindings' |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
470 extKeys={} |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
471 if self.defaultCfg['extensions'].has_section(keysName): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
472 eventNames=self.defaultCfg['extensions'].GetOptionList(keysName) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
473 for eventName in eventNames: |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
474 binding=self.GetOption('extensions',keysName, |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
475 eventName,default='').split() |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
476 event='<<'+eventName+'>>' |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
477 extKeys[event]=binding |
| 26959 | 478 return extKeys |
| 479 | |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
480 def GetExtensionBindings(self,extensionName): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
481 """ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
482 Returns a dictionary of all the event bindings for a particular |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
483 extension. The configurable keybindings are returned as they exist in |
| 26959 | 484 the dictionary returned by GetCurrentKeySet; that is, where re-used |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
485 keybindings are disabled. |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
486 """ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
487 bindsName=extensionName+'_bindings' |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
488 extBinds=self.GetExtensionKeys(extensionName) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
489 #add the non-configurable bindings |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
490 if self.defaultCfg['extensions'].has_section(bindsName): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
491 eventNames=self.defaultCfg['extensions'].GetOptionList(bindsName) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
492 for eventName in eventNames: |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
493 binding=self.GetOption('extensions',bindsName, |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
494 eventName,default='').split() |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
495 event='<<'+eventName+'>>' |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
496 extBinds[event]=binding |
| 26959 | 497 |
| 498 return extBinds | |
| 499 | |
|
21627
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
500 def GetKeyBinding(self, keySetName, eventStr): |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
501 """ |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
502 returns the keybinding for a specific event. |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
503 keySetName - string, name of key binding set |
| 26959 | 504 eventStr - string, the virtual event we want the binding for, |
|
21627
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
505 represented as a string, eg. '<<event>>' |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
506 """ |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
507 eventName=eventStr[2:-2] #trim off the angle brackets |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
508 binding=self.GetOption('keys',keySetName,eventName,default='').split() |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
509 return binding |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
510 |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
511 def GetCurrentKeySet(self): |
|
38744
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
512 result = self.GetKeySet(self.CurrentKeys()) |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
513 |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
514 if macosxSupport.runningAsOSXApp(): |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
515 # We're using AquaTk, replace all keybingings that use the |
|
38748
b50ab288ae27
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38744
diff
changeset
|
516 # Alt key by ones that use the Option key because the former |
|
38744
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
517 # don't work reliably. |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
518 for k, v in result.items(): |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
519 v2 = [ x.replace('<Alt-', '<Option-') for x in v ] |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
520 if v != v2: |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
521 result[k] = v2 |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
522 |
|
1b3b6b1982aa
This patch improves the L&F of IDLE on OSX. The changes are conditionalized on
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
38704
diff
changeset
|
523 return result |
| 26959 | 524 |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
525 def GetKeySet(self,keySetName): |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
526 """ |
| 26959 | 527 Returns a dictionary of: all requested core keybindings, plus the |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
528 keybindings for all currently active extensions. If a binding defined |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
529 in an extension is already in use, that binding is disabled. |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
530 """ |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
531 keySet=self.GetCoreKeys(keySetName) |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
532 activeExtns=self.GetExtensions(active_only=1) |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
533 for extn in activeExtns: |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
534 extKeys=self.__GetRawExtensionKeys(extn) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
535 if extKeys: #the extension defines keybindings |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
536 for event in extKeys.keys(): |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
537 if extKeys[event] in keySet.values(): |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
538 #the binding is already in use |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
539 extKeys[event]='' #disable this binding |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
540 keySet[event]=extKeys[event] #add binding |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
541 return keySet |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
542 |
|
21854
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
543 def IsCoreBinding(self,virtualEvent): |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
544 """ |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
545 returns true if the virtual event is bound in the core idle keybindings. |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
546 virtualEvent - string, name of the virtual event to test for, without |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
547 the enclosing '<< >>' |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
548 """ |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
549 return ('<<'+virtualEvent+'>>') in self.GetCoreKeys().keys() |
| 26959 | 550 |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
551 def GetCoreKeys(self, keySetName=None): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
552 """ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
553 returns the requested set of core keybindings, with fallbacks if |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
554 required. |
|
21798
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
555 Keybindings loaded from the config file(s) are loaded _over_ these |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
556 defaults, so if there is a problem getting any core binding there will |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
557 be an 'ultimate last resort fallback' to the CUA-ish bindings |
|
03a2ba74179b
further work on saving configs
Steven M. Gava <elguavas@python.net>
parents:
21767
diff
changeset
|
558 defined here. |
|
20686
311a2abea8a4
further work supporting reading config dialog values form config files.
Steven M. Gava <elguavas@python.net>
parents:
20628
diff
changeset
|
559 """ |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
560 keyBindings={ |
|
21854
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
561 '<<copy>>': ['<Control-c>', '<Control-C>'], |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
562 '<<cut>>': ['<Control-x>', '<Control-X>'], |
|
c433de17c158
more work on configuration saving
Steven M. Gava <elguavas@python.net>
parents:
21835
diff
changeset
|
563 '<<paste>>': ['<Control-v>', '<Control-V>'], |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
564 '<<beginning-of-line>>': ['<Control-a>', '<Home>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
565 '<<center-insert>>': ['<Control-l>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
566 '<<close-all-windows>>': ['<Control-q>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
567 '<<close-window>>': ['<Alt-F4>'], |
|
25456
41eb24b747c0
Fix Bug 612886 copy/paste menu items fail
Kurt B. Kaiser <kbk@shore.net>
parents:
25266
diff
changeset
|
568 '<<do-nothing>>': ['<Control-x>'], |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
569 '<<end-of-file>>': ['<Control-d>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
570 '<<python-docs>>': ['<F1>'], |
| 26959 | 571 '<<python-context-help>>': ['<Shift-F1>'], |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
572 '<<history-next>>': ['<Alt-n>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
573 '<<history-previous>>': ['<Alt-p>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
574 '<<interrupt-execution>>': ['<Control-c>'], |
| 27074 | 575 '<<view-restart>>': ['<F6>'], |
| 27336 | 576 '<<restart-shell>>': ['<Control-F6>'], |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
577 '<<open-class-browser>>': ['<Alt-c>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
578 '<<open-module>>': ['<Alt-m>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
579 '<<open-new-window>>': ['<Control-n>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
580 '<<open-window-from-file>>': ['<Control-o>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
581 '<<plain-newline-and-indent>>': ['<Control-j>'], |
|
23776
71db428f6e08
add a version of GvR's q&d python idle printing patch,
Steven M. Gava <elguavas@python.net>
parents:
22111
diff
changeset
|
582 '<<print-window>>': ['<Control-p>'], |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
583 '<<redo>>': ['<Control-y>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
584 '<<remove-selection>>': ['<Escape>'], |
|
31013
270d59e346e6
Keybindings with the Shift modifier now work correctly. So do bindings
Kurt B. Kaiser <kbk@shore.net>
parents:
27409
diff
changeset
|
585 '<<save-copy-of-window-as-file>>': ['<Alt-Shift-S>'], |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
586 '<<save-window-as-file>>': ['<Alt-s>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
587 '<<save-window>>': ['<Control-s>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
588 '<<select-all>>': ['<Alt-a>'], |
|
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
589 '<<toggle-auto-coloring>>': ['<Control-slash>'], |
|
21627
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
590 '<<undo>>': ['<Control-z>'], |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
591 '<<find-again>>': ['<Control-g>', '<F3>'], |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
592 '<<find-in-files>>': ['<Alt-F3>'], |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
593 '<<find-selection>>': ['<Control-F3>'], |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
594 '<<find>>': ['<Control-f>'], |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
595 '<<replace>>': ['<Control-h>'], |
| 26959 | 596 '<<goto-line>>': ['<Alt-g>'], |
|
25266
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
597 '<<smart-backspace>>': ['<Key-BackSpace>'], |
|
75986
87ada87057a2
Backport of Issue #14409 to 2.7
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
68256
diff
changeset
|
598 '<<newline-and-indent>>': ['<Key-Return>', '<Key-KP_Enter>'], |
|
25266
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
599 '<<smart-indent>>': ['<Key-Tab>'], |
|
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
600 '<<indent-region>>': ['<Control-Key-bracketright>'], |
|
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
601 '<<dedent-region>>': ['<Control-Key-bracketleft>'], |
|
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
602 '<<comment-region>>': ['<Alt-Key-3>'], |
|
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
603 '<<uncomment-region>>': ['<Alt-Key-4>'], |
|
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
604 '<<tabify-region>>': ['<Alt-Key-5>'], |
|
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
605 '<<untabify-region>>': ['<Alt-Key-6>'], |
|
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
606 '<<toggle-tabs>>': ['<Alt-Key-t>'], |
|
34515
e3074e94fb75
Add keybindings for del-word-left and del-word-right.
Kurt B. Kaiser <kbk@shore.net>
parents:
35003
diff
changeset
|
607 '<<change-indentwidth>>': ['<Alt-Key-u>'], |
|
e3074e94fb75
Add keybindings for del-word-left and del-word-right.
Kurt B. Kaiser <kbk@shore.net>
parents:
35003
diff
changeset
|
608 '<<del-word-left>>': ['<Control-Key-BackSpace>'], |
|
e3074e94fb75
Add keybindings for del-word-left and del-word-right.
Kurt B. Kaiser <kbk@shore.net>
parents:
35003
diff
changeset
|
609 '<<del-word-right>>': ['<Control-Key-Delete>'] |
|
25266
6ec1546840ae
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
23776
diff
changeset
|
610 } |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
611 if keySetName: |
|
21627
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
612 for event in keyBindings.keys(): |
|
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
613 binding=self.GetKeyBinding(keySetName,event) |
|
21975
8e0c3b75eff5
handle user theme and key set deletion
Steven M. Gava <elguavas@python.net>
parents:
21908
diff
changeset
|
614 if binding: |
|
21627
051f3b65ddab
loading core keybindings via new config system plus
Steven M. Gava <elguavas@python.net>
parents:
21626
diff
changeset
|
615 keyBindings[event]=binding |
|
21975
8e0c3b75eff5
handle user theme and key set deletion
Steven M. Gava <elguavas@python.net>
parents:
21908
diff
changeset
|
616 else: #we are going to return a default, print warning |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
617 warning=('\n Warning: configHandler.py - IdleConf.GetCoreKeys' |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
618 ' -\n problem retrieving key binding for event %r' |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
619 '\n from key set %r.\n' |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
620 ' returning default value: %r\n' % |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31013
diff
changeset
|
621 (event, keySetName, keyBindings[event])) |
|
46526
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
622 try: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
623 sys.stderr.write(warning) |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
624 except IOError: |
|
b12583643128
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45328
diff
changeset
|
625 pass |
|
21144
96a08fd38ef8
further work on new configuration system, specifically,
Steven M. Gava <elguavas@python.net>
parents:
20864
diff
changeset
|
626 return keyBindings |
| 26959 | 627 |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
628 def GetExtraHelpSourceList(self,configSet): |
| 27245 | 629 """Fetch list of extra help sources from a given configSet. |
| 27409 | 630 |
| 27245 | 631 Valid configSets are 'user' or 'default'. Return a list of tuples of |
| 632 the form (menu_item , path_to_help_file , option), or return the empty | |
| 633 list. 'option' is the sequence number of the help resource. 'option' | |
| 634 values determine the position of the menu items on the Help menu, | |
| 635 therefore the returned list must be sorted by 'option'. | |
| 636 | |
| 26959 | 637 """ |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
638 helpSources=[] |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
639 if configSet=='user': |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
640 cfgParser=self.userCfg['main'] |
| 26959 | 641 elif configSet=='default': |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
642 cfgParser=self.defaultCfg['main'] |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
643 else: |
|
26473
0690f81cce78
Convert string exceptions to classes, string exceptions are deprecated
Neal Norwitz <nnorwitz@gmail.com>
parents:
25456
diff
changeset
|
644 raise InvalidConfigSet, 'Invalid configSet specified' |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
645 options=cfgParser.GetOptionList('HelpFiles') |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
646 for option in options: |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
647 value=cfgParser.Get('HelpFiles',option,default=';') |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
648 if value.find(';')==-1: #malformed config entry with no ';' |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
649 menuItem='' #make these empty |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
650 helpPath='' #so value won't be added to list |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
651 else: #config entry contains ';' as expected |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
652 value=string.split(value,';') |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
653 menuItem=value[0].strip() |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
654 helpPath=value[1].strip() |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
655 if menuItem and helpPath: #neither are empty strings |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
656 helpSources.append( (menuItem,helpPath,option) ) |
|
63585
df378e44ba9a
Merged revisions 79576-79578 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47252
diff
changeset
|
657 helpSources.sort(key=lambda x: int(x[2])) |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
658 return helpSources |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
659 |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
660 def GetAllExtraHelpSourcesList(self): |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
661 """ |
| 26959 | 662 Returns a list of tuples containing the details of all additional help |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
663 sources configured, or an empty list if there are none. Tuples are of |
|
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
664 the format returned by GetExtraHelpSourceList. |
| 26959 | 665 """ |
| 666 allHelpSources=( self.GetExtraHelpSourceList('default')+ | |
|
21875
7faf0fddf7e6
further work on config system and config saving
Steven M. Gava <elguavas@python.net>
parents:
21855
diff
changeset
|
667 self.GetExtraHelpSourceList('user') ) |
| 26959 | 668 return allHelpSources |
| 669 | |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
670 def LoadCfgFiles(self): |
| 26959 | 671 """ |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
672 load all configuration files. |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
673 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
674 for key in self.defaultCfg.keys(): |
| 26959 | 675 self.defaultCfg[key].Load() |
| 676 self.userCfg[key].Load() #same keys | |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
677 |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
678 def SaveUserCfgFiles(self): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
679 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
680 write all loaded user configuration files back to disk |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
681 """ |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
682 for key in self.userCfg.keys(): |
| 26959 | 683 self.userCfg[key].Save() |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
684 |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
685 idleConf=IdleConf() |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
686 |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
687 ### module test |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
688 if __name__ == '__main__': |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
689 def dumpCfg(cfg): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
690 print '\n',cfg,'\n' |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
691 for key in cfg.keys(): |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
692 sections=cfg[key].sections() |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
693 print key |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
694 print sections |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
695 for section in sections: |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
696 options=cfg[key].options(section) |
| 26959 | 697 print section |
|
20052
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
698 print options |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
699 for option in options: |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
700 print option, '=', cfg[key].Get(section,option) |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
701 dumpCfg(idleConf.defaultCfg) |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
702 dumpCfg(idleConf.userCfg) |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
703 print idleConf.userCfg['main'].Get('Theme','name') |
|
0ee8903d3fed
start of new config handling stuff
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
704 #print idleConf.userCfg['highlight'].GetDefHighlight('Foo','normal') |
