Skip to content

Commit 221659d

Browse files
committed
GTK gets its own color scheme which is more sane and readable (on a white background)
1 parent d9d6388 commit 221659d

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

bpython/config.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def loadini(struct, configfile):
6767
'up_one_line': 'C-p',
6868
'yank_from_buffer': 'C-y'},
6969
'gtk': {
70-
'font': 'monospace 10'}})
70+
'font': 'monospace 10',
71+
'color_scheme': 'default'}})
7172
config.read(config_path)
7273

7374
struct.dedent_after = config.getint('general', 'dedent_after')
@@ -106,6 +107,7 @@ def loadini(struct, configfile):
106107
struct.gtk_font = config.get('gtk', 'font')
107108

108109
color_scheme_name = config.get('general', 'color_scheme')
110+
color_gtk_scheme_name = config.get('gtk', 'color_scheme')
109111

110112
default_colors = {
111113
'keyword': 'y',
@@ -125,18 +127,44 @@ def loadini(struct, configfile):
125127
'prompt_more': 'g',
126128
}
127129

130+
default_gtk_colors = {
131+
'keyword': 'b',
132+
'name': 'k',
133+
'comment': 'b',
134+
'string': 'm',
135+
'error': 'r',
136+
'number': 'G',
137+
'operator': 'B',
138+
'punctuation': 'g',
139+
'token': 'C',
140+
'background': 'w',
141+
'output': 'k',
142+
'main': 'c',
143+
'paren': 'R',
144+
'prompt': 'b',
145+
'prompt_more': 'g',
146+
}
147+
148+
# TODO consolidate
128149
if color_scheme_name == 'default':
129150
struct.color_scheme = default_colors
130151
else:
131152
path = os.path.expanduser('~/.bpython/%s.theme' % (color_scheme_name,))
132153
load_theme(struct, path, config_path, default_colors)
133154

155+
if color_gtk_scheme_name == 'default':
156+
struct.color_gtk_scheme = default_gtk_colors
157+
else:
158+
path = os.path.expanduser('~/.bpython/%s.theme' % (color_gtk_scheme_name,))
159+
load_gtk_theme(struct, path, config_path, default_gtk_colors)
160+
161+
134162
# checks for valid key configuration this part still sucks
135163
for key in (struct.pastebin_key, struct.save_key):
136164
key_dispatch[key]
137165

138-
139-
def load_theme(struct, path, inipath, default_colors):
166+
# TODO consolidate
167+
def load_gtk_theme(struct, path, inipath, default_colors):
140168
theme = ConfigParser()
141169
try:
142170
f = open(path, 'r')
@@ -145,7 +173,7 @@ def load_theme(struct, path, inipath, default_colors):
145173
(inipath, e))
146174
sys.exit(1)
147175
theme.readfp(f)
148-
struct.color_scheme = {}
176+
struct.color_gtk_scheme = {}
149177
for k, v in chain(theme.items('syntax'), theme.items('interface')):
150178
if theme.has_option('syntax', k):
151179
struct.color_scheme[k] = theme.get('syntax', k)
@@ -159,6 +187,7 @@ def load_theme(struct, path, inipath, default_colors):
159187
f.close()
160188

161189

190+
162191
def migrate_rc(path):
163192
"""Use the shlex module to convert the old configuration file to the new
164193
format.

bpython/gtk_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ def __init__(self, interpreter, config):
267267
self.on_suggestion_selection_changed)
268268
self.list_win.hide()
269269

270-
self.modify_base('normal', gtk.gdk.color_parse(_COLORS[self.config.color_scheme['background']]))
270+
self.modify_base('normal', gtk.gdk.color_parse(_COLORS[self.config.color_gtk_scheme['background']]))
271271

272272
self.text_buffer = self.get_buffer()
273273
tags = dict()
274-
for (name, value) in self.config.color_scheme.iteritems():
274+
for (name, value) in self.config.color_gtk_scheme.iteritems():
275275
tag = tags[name] = self.text_buffer.create_tag(name)
276276
for (char, prop) in zip(value, ['foreground', 'background']):
277277
if char.lower() == 'd':

0 commit comments

Comments
 (0)