Added radio options to the Cursor colour to make it easier to go back to the XOR'd foreground colour

This commit is contained in:
Stephen Boddy 2015-12-03 15:37:16 +01:00
parent e6fe49820f
commit f0330dadf3
4 changed files with 94 additions and 21 deletions

View File

@ -214,7 +214,8 @@ DEFAULTS = {
'color_scheme' : 'grey_on_black',
'cursor_blink' : True,
'cursor_shape' : 'block',
'cursor_color' : '#aaaaaa',
'cursor_color' : '',
'cursor_color_fg' : True,
'term' : 'xterm-256color',
'colorterm' : 'truecolor',
'font' : 'Mono 10',

View File

@ -1808,24 +1808,70 @@
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkColorButton" id="cursor_color">
<object class="GtkRadioButton" id="cursor_color_foreground_radiobutton">
<property name="label" translatable="yes">Foreground</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_cursor_color_color_set" swapped="no"/>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_cursor_color_type_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkHBox" id="hbox4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkRadioButton" id="cursor_color_custom_radiobutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">cursor_color_foreground_radiobutton</property>
<signal name="toggled" handler="on_cursor_color_type_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="cursor_color">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_cursor_color_color_set" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>

View File

@ -450,13 +450,24 @@ class PrefsEditor:
# Cursor blink
widget = guiget('cursor_blink')
widget.set_active(self.config['cursor_blink'])
# Cursor colour
# Cursor colour - Radio values
if self.config['cursor_color_fg']:
widget = guiget('cursor_color_foreground_radiobutton')
else:
widget = guiget('cursor_color_custom_radiobutton')
widget.set_active(True)
# Cursor colour - swatch
widget = guiget('cursor_color')
widget.set_sensitive(not self.config['cursor_color_fg'])
try:
widget.set_color(Gdk.color_parse(self.config['cursor_color']))
except ValueError:
self.config['cursor_color'] = "#FFFFFF"
widget.set_color(Gdk.color_parse(self.config['cursor_color']))
except (ValueError, TypeError):
try:
self.config['cursor_color'] = self.config['foreground_color']
widget.set_color(Gdk.color_parse(self.config['cursor_color']))
except ValueError:
self.config['cursor_color'] = "#FFFFFF"
widget.set_color(Gdk.color_parse(self.config['cursor_color']))
## Command tab
# Login shell
@ -931,6 +942,26 @@ class PrefsEditor:
self.config['custom_command'] = widget.get_text()
self.config.save()
def on_cursor_color_type_toggled(self, widget):
guiget = self.builder.get_object
customwidget = guiget('cursor_color_custom_radiobutton')
colorwidget = guiget('cursor_color')
colorwidget.set_sensitive(customwidget.get_active())
self.config['cursor_color_fg'] = not customwidget.get_active()
try:
colorwidget.set_color(Gdk.color_parse(self.config['cursor_color']))
except (ValueError, TypeError):
try:
self.config['cursor_color'] = self.config['foreground_color']
colorwidget.set_color(Gdk.color_parse(self.config['cursor_color']))
except ValueError:
self.config['cursor_color'] = "#FFFFFF"
colorwidget.set_color(Gdk.color_parse(self.config['cursor_color']))
self.config.save()
def on_cursor_color_color_set(self, widget):
"""Cursor colour changed"""
self.config['cursor_color'] = color2hex(widget)

View File

@ -780,18 +780,13 @@ class Terminal(Gtk.VBox):
def set_cursor_color(self):
"""Set the cursor color appropriately"""
if self.config['cursor_color'] == self.config['foreground_color']:
try:
self.vte.set_color_cursor(None)
except TypeError:
# FIXME: I think this is only necessary because of
# https://bugzilla.gnome.org/show_bug.cgi?id=614910
pass
elif self.config['cursor_color'] != '':
if self.config['cursor_color_fg']:
self.vte.set_color_cursor(None)
else:
cursor_color = Gdk.RGBA()
cursor_color.parse(self.config['cursor_color'])
self.vte.set_color_cursor(cursor_color)
def get_window_title(self):
"""Return the window title"""
return(self.vte.get_window_title() or str(self.command))