Merge pull request #160 from dafrito/master

Allow live previewing of profile color changes
This commit is contained in:
Matt Rose 2020-07-10 14:35:09 -04:00 committed by GitHub
commit 0cbdbd89a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 247 additions and 200 deletions

View File

@ -2312,7 +2312,7 @@
<property name="label" translatable="yes">_Text color:</property> <property name="label" translatable="yes">_Text color:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="justify">center</property> <property name="justify">center</property>
<property name="mnemonic_widget">foreground_colorpicker</property> <property name="mnemonic_widget">foreground_colorbutton</property>
<property name="xalign">0</property> <property name="xalign">0</property>
</object> </object>
<packing> <packing>
@ -2327,7 +2327,7 @@
<property name="label" translatable="yes">_Background color:</property> <property name="label" translatable="yes">_Background color:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="justify">center</property> <property name="justify">center</property>
<property name="mnemonic_widget">background_colorpicker</property> <property name="mnemonic_widget">background_colorbutton</property>
<property name="xalign">0</property> <property name="xalign">0</property>
</object> </object>
<packing> <packing>
@ -2360,15 +2360,14 @@
<object class="GtkBox" id="hbox18"> <object class="GtkBox" id="hbox18">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="spacing">12</property>
<child> <child>
<object class="GtkColorButton" id="foreground_colorpicker"> <object class="GtkDrawingArea" id="foreground_colorbutton">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_foreground_colorbutton_draw" swapped="no"/>
<property name="receives_default">True</property> <signal name="button-press-event" handler="on_foreground_colorbutton_click" swapped="no"/>
<property name="title" translatable="yes">Choose Terminal Text Color</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_foreground_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -2389,15 +2388,14 @@
<object class="GtkBox" id="hbox19"> <object class="GtkBox" id="hbox19">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="spacing">12</property>
<child> <child>
<object class="GtkColorButton" id="background_colorpicker"> <object class="GtkDrawingArea" id="background_colorbutton">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_background_colorbutton_draw" swapped="no"/>
<property name="receives_default">True</property> <signal name="button-press-event" handler="on_background_colorbutton_click" swapped="no"/>
<property name="title" translatable="yes">Choose Terminal Background Color</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_background_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -2520,13 +2518,11 @@
<property name="row_homogeneous">True</property> <property name="row_homogeneous">True</property>
<property name="column_homogeneous">True</property> <property name="column_homogeneous">True</property>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_1"> <object class="GtkDrawingArea" id="palette_colorpicker_1">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
@ -2534,13 +2530,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_2"> <object class="GtkDrawingArea" id="palette_colorpicker_2">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
@ -2548,13 +2542,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_3"> <object class="GtkDrawingArea" id="palette_colorpicker_3">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">2</property> <property name="left_attach">2</property>
@ -2562,13 +2554,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_4"> <object class="GtkDrawingArea" id="palette_colorpicker_4">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">3</property> <property name="left_attach">3</property>
@ -2576,13 +2566,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_5"> <object class="GtkDrawingArea" id="palette_colorpicker_5">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">4</property> <property name="left_attach">4</property>
@ -2590,13 +2578,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_6"> <object class="GtkDrawingArea" id="palette_colorpicker_6">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">5</property> <property name="left_attach">5</property>
@ -2604,13 +2590,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_7"> <object class="GtkDrawingArea" id="palette_colorpicker_7">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">6</property> <property name="left_attach">6</property>
@ -2618,13 +2602,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_8"> <object class="GtkDrawingArea" id="palette_colorpicker_8">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">7</property> <property name="left_attach">7</property>
@ -2632,13 +2614,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_9"> <object class="GtkDrawingArea" id="palette_colorpicker_9">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
@ -2646,13 +2626,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_10"> <object class="GtkDrawingArea" id="palette_colorpicker_10">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
@ -2660,13 +2638,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_11"> <object class="GtkDrawingArea" id="palette_colorpicker_11">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">2</property> <property name="left_attach">2</property>
@ -2674,13 +2650,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_12"> <object class="GtkDrawingArea" id="palette_colorpicker_12">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">3</property> <property name="left_attach">3</property>
@ -2688,13 +2662,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_13"> <object class="GtkDrawingArea" id="palette_colorpicker_13">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">4</property> <property name="left_attach">4</property>
@ -2702,13 +2674,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_14"> <object class="GtkDrawingArea" id="palette_colorpicker_14">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">5</property> <property name="left_attach">5</property>
@ -2716,13 +2686,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_15"> <object class="GtkDrawingArea" id="palette_colorpicker_15">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">6</property> <property name="left_attach">6</property>
@ -2730,13 +2698,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="palette_colorpicker_16"> <object class="GtkDrawingArea" id="palette_colorpicker_16">
<property name="use_action_appearance">False</property> <property name="height_request">24</property>
<property name="width_request">36</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <signal name="draw" handler="on_palette_colorpicker_draw" swapped="no"/>
<property name="receives_default">True</property>
<property name="color">#000000000000</property>
<signal name="color-set" handler="on_palette_colorpicker_color_set" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">7</property> <property name="left_attach">7</property>
@ -4016,36 +3982,6 @@ Much of the behavior of Terminator is based on GNOME Terminal, and we are adding
<widget name="palette_combobox"/> <widget name="palette_combobox"/>
</widgets> </widgets>
</object> </object>
<object class="GtkSizeGroup" id="sizegroup3">
<property name="mode">both</property>
<widgets>
<widget name="title_transmit_fg_color"/>
<widget name="title_inactive_fg_color"/>
<widget name="title_receive_fg_color"/>
<widget name="title_transmit_bg_color"/>
<widget name="title_inactive_bg_color"/>
<widget name="title_receive_bg_color"/>
<widget name="cursor_color"/>
<widget name="foreground_colorpicker"/>
<widget name="background_colorpicker"/>
<widget name="palette_colorpicker_1"/>
<widget name="palette_colorpicker_2"/>
<widget name="palette_colorpicker_3"/>
<widget name="palette_colorpicker_4"/>
<widget name="palette_colorpicker_5"/>
<widget name="palette_colorpicker_6"/>
<widget name="palette_colorpicker_7"/>
<widget name="palette_colorpicker_8"/>
<widget name="palette_colorpicker_9"/>
<widget name="palette_colorpicker_10"/>
<widget name="palette_colorpicker_11"/>
<widget name="palette_colorpicker_12"/>
<widget name="palette_colorpicker_13"/>
<widget name="palette_colorpicker_14"/>
<widget name="palette_colorpicker_15"/>
<widget name="palette_colorpicker_16"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="sizegroup4"> <object class="GtkSizeGroup" id="sizegroup4">
<widgets> <widgets>
<widget name="scrollbar_position_combobox"/> <widget name="scrollbar_position_combobox"/>

View File

@ -19,11 +19,18 @@ from .terminator import Terminator
from .plugin import PluginRegistry from .plugin import PluginRegistry
from .version import APP_NAME from .version import APP_NAME
def get_color_string(widcol):
return('#%02x%02x%02x' % (widcol.red>>8, widcol.green>>8, widcol.blue>>8))
def color2hex(widget): def color2hex(widget):
"""Pull the colour values out of a Gtk ColorPicker widget and return them """Pull the colour values out of a Gtk ColorPicker widget and return them
as 8bit hex values, sinces its default behaviour is to give 16bit values""" as 8bit hex values, sinces its default behaviour is to give 16bit values"""
widcol = widget.get_color() return get_color_string(widget.get_color())
return('#%02x%02x%02x' % (widcol.red>>8, widcol.green>>8, widcol.blue>>8))
def rgba2hex(widget):
return get_color_string(widget.get_rgba().to_color())
NUM_PALETTE_COLORS = 16
# FIXME: We need to check that we have represented all of Config() below # FIXME: We need to check that we have represented all of Config() below
class PrefsEditor: class PrefsEditor:
@ -553,15 +560,16 @@ class PrefsEditor:
scheme = 'custom' scheme = 'custom'
# NOTE: The scheme is set in the GUI widget after the fore/back colours # NOTE: The scheme is set in the GUI widget after the fore/back colours
# Foreground color # Foreground color
widget = guiget('foreground_colorpicker') widget = guiget('foreground_colorbutton')
widget.set_color(Gdk.color_parse(self.config['foreground_color'])) widget.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
if scheme == 'custom': if scheme == 'custom':
widget.set_sensitive(True) widget.set_sensitive(True)
else: else:
widget.set_sensitive(False) widget.set_sensitive(False)
# Background color # Background color
widget = guiget('background_colorpicker') widget = guiget('background_colorbutton')
widget.set_color(Gdk.color_parse(self.config['background_color'])) widget.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
if scheme == 'custom': if scheme == 'custom':
widget.set_sensitive(True) widget.set_sensitive(True)
else: else:
@ -582,10 +590,13 @@ class PrefsEditor:
palette = 'custom' palette = 'custom'
# NOTE: The palette selector is set after the colour pickers # NOTE: The palette selector is set after the colour pickers
# Palette colour pickers # Palette colour pickers
colourpalette = self.config['palette'].split(':') for palette_id in range(0, NUM_PALETTE_COLORS):
for i in range(1, 17): widget = self.get_palette_widget(palette_id)
widget = guiget('palette_colorpicker_%d' % i) widget.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
widget.set_color(Gdk.color_parse(colourpalette[i - 1])) def on_palette_click(event, data, widget=widget):
self.edit_palette_button(widget)
widget.connect('button-press-event', on_palette_click)
self.load_palette()
# Now set the palette selector widget # Now set the palette selector widget
widget = guiget('palette_combobox') widget = guiget('palette_combobox')
widget.set_active(self.palettevalues[palette]) widget.set_active(self.palettevalues[palette])
@ -918,34 +929,28 @@ class PrefsEditor:
def on_palette_combobox_changed(self, widget): def on_palette_combobox_changed(self, widget):
"""Palette selector changed""" """Palette selector changed"""
value = None value = None
guiget = self.builder.get_object
active = widget.get_active() active = widget.get_active()
for key in list(self.palettevalues.keys()): for key in list(self.palettevalues.keys()):
if self.palettevalues[key] == active: if self.palettevalues[key] == active:
value = key value = key
if value == 'custom': sensitive = value == 'custom'
sensitive = True for palette_id in range(0, NUM_PALETTE_COLORS):
else: self.get_palette_widget(palette_id).set_sensitive(sensitive)
sensitive = False
for num in range(1, 17):
picker = guiget('palette_colorpicker_%d' % num)
picker.set_sensitive(sensitive)
if value in self.palettes: if value in self.palettes:
palette = self.palettes[value] palette = self.palettes[value]
palettebits = palette.split(':') palettebits = palette.split(':')
for num in range(1, 17): for palette_id in range(0, NUM_PALETTE_COLORS):
# Update the visible elements # Update the visible elements
picker = guiget('palette_colorpicker_%d' % num) color = Gdk.color_parse(palettebits[palette_id])
picker.set_color(Gdk.color_parse(palettebits[num - 1])) self.load_palette_color(palette_id, color)
elif value == 'custom': elif value == 'custom':
palettebits = [] palettebits = []
for num in range(1, 17): for palette_id in range(0, NUM_PALETTE_COLORS):
picker = guiget('palette_colorpicker_%d' % num) # Save the custom values into the configuration.
palettebits.append(color2hex(picker)) palettebits.append(get_color_string(self.get_palette_color(palette_id)))
palette = ':'.join(palettebits) palette = ':'.join(palettebits)
else: else:
err('Unknown palette value: %s' % value) err('Unknown palette value: %s' % value)
@ -954,32 +959,148 @@ class PrefsEditor:
self.config['palette'] = palette self.config['palette'] = palette
self.config.save() self.config.save()
def on_background_colorpicker_color_set(self, widget): def on_foreground_colorbutton_draw(self, widget, cr):
"""Background color changed""" width = widget.get_allocated_width()
self.config['background_color'] = color2hex(widget) height = widget.get_allocated_height()
self.config.save() col = Gdk.color_parse(self.config['foreground_color'])
cr.rectangle(0, 0, width, height)
cr.set_source_rgba(0.7, 0.7, 0.7, 1)
cr.fill()
cr.rectangle(1, 1, width-2, height-2)
cr.set_source_rgba(col.red_float, col.green_float, col.blue_float)
cr.fill()
def on_foreground_colorpicker_color_set(self, widget): def on_foreground_colorbutton_click(self, event, data):
dialog = Gtk.ColorChooserDialog("Choose Terminal Text Color")
fg = self.config['foreground_color']
dialog.set_rgba(Gdk.RGBA.from_color(Gdk.color_parse(self.config['foreground_color'])))
dialog.connect('notify::rgba', self.on_foreground_colorpicker_color_change)
res = dialog.run()
if res != Gtk.ResponseType.OK:
self.config['foreground_color'] = fg
self.config.save()
terminator = Terminator()
terminator.reconfigure()
dialog.destroy()
def on_foreground_colorpicker_color_change(self, widget, color):
"""Foreground color changed""" """Foreground color changed"""
self.config['foreground_color'] = color2hex(widget) self.config['foreground_color'] = rgba2hex(widget)
self.config.save() self.config.save()
terminator = Terminator()
terminator.reconfigure()
def on_palette_colorpicker_color_set(self, widget): def on_background_colorbutton_draw(self, widget, cr):
"""A palette colour changed""" width = widget.get_allocated_width()
palette = None height = widget.get_allocated_height()
palettebits = [] col = Gdk.color_parse(self.config['background_color'])
cr.rectangle(0, 0, width, height)
cr.set_source_rgba(0.7, 0.7, 0.7, 1)
cr.fill()
cr.rectangle(1, 1, width-2, height-2)
cr.set_source_rgba(col.red_float, col.green_float, col.blue_float)
cr.fill()
def on_background_colorbutton_click(self, event, data):
dialog = Gtk.ColorChooserDialog("Choose Terminal Background Color")
orig = self.config['background_color']
dialog.connect('notify::rgba', self.on_background_colorpicker_color_change)
dialog.set_rgba(Gdk.RGBA.from_color(Gdk.color_parse(orig)))
res = dialog.run()
if res != Gtk.ResponseType.OK:
self.config['background_color'] = orig
self.config.save()
terminator = Terminator()
terminator.reconfigure()
dialog.destroy()
def on_background_colorpicker_color_change(self, widget, color):
"""Background color changed"""
self.config['background_color'] = rgba2hex(widget)
self.config.save()
terminator = Terminator()
terminator.reconfigure()
def get_palette_widget(self, palette_id):
"""Returns the palette widget for the given palette ID."""
guiget = self.builder.get_object guiget = self.builder.get_object
return guiget('palette_colorpicker_%d' % (palette_id + 1))
# FIXME: We do this at least once elsewhere. refactor! def get_palette_id(self, widget):
for num in range(1, 17): """Returns the palette ID for the given palette widget."""
picker = guiget('palette_colorpicker_%d' % num) for palette_id in range(0, NUM_PALETTE_COLORS):
value = color2hex(picker) if widget == self.get_palette_widget(palette_id):
palettebits.append(value) return palette_id
palette = ':'.join(palettebits) return None
self.config['palette'] = palette def get_palette_color(self, palette_id):
"""Returns the configured Gdk color for the given palette ID."""
if self.config['palette'] in self.palettes:
colourpalette = self.palettes[self.config['palette']]
else:
colourpalette = self.config['palette'].split(':')
return Gdk.color_parse(colourpalette[palette_id])
def on_palette_colorpicker_draw(self, widget, cr):
width = widget.get_allocated_width()
height = widget.get_allocated_height()
cr.rectangle(0, 0, width, height)
cr.set_source_rgba(0.7, 0.7, 0.7, 1)
cr.fill()
cr.rectangle(1, 1, width-2, height-2)
col = self.get_palette_color(self.get_palette_id(widget))
cr.set_source_rgba(col.red_float, col.green_float, col.blue_float)
cr.fill()
def load_palette_color(self, palette_id, color):
"""Given a palette ID and a Gdk color, load that color into the
specified widget."""
widget = self.get_palette_widget(palette_id)
widget.queue_draw()
def replace_palette_color(self, palette_id, color):
"""Replace the configured palette color for the given palette ID
with the given color."""
palettebits = self.config['palette'].split(':')
palettebits[palette_id] = get_color_string(color)
self.config['palette'] = ':'.join(palettebits)
self.config.save() self.config.save()
def load_palette(self):
"""Load the palette from the configuration into the color buttons."""
colourpalette = self.config['palette'].split(':')
for palette_id in range(0, NUM_PALETTE_COLORS):
color = Gdk.color_parse(colourpalette[palette_id])
self.load_palette_color(palette_id, color)
def edit_palette_button(self, widget):
"""When the palette colorbutton is clicked, open a dialog to
configure a custom color."""
terminator = Terminator()
palette_id = self.get_palette_id(widget)
orig = self.get_palette_color(palette_id)
try:
# Create the dialog to choose a custom color
dialog = Gtk.ColorChooserDialog("Choose Palette Color")
dialog.set_rgba(Gdk.RGBA.from_color(orig))
def on_color_set(_, color):
# The color is set, so save the palette config and refresh Terminator
self.replace_palette_color(palette_id, dialog.get_rgba().to_color())
terminator.reconfigure()
dialog.connect('notify::rgba', on_color_set)
# Show the dialog
res = dialog.run()
if res != Gtk.ResponseType.OK:
# User cancelled the color change, so reset to the original.
self.replace_palette_color(palette_id, orig)
terminator.reconfigure()
finally:
if dialog:
dialog.destroy()
def on_exit_action_combobox_changed(self, widget): def on_exit_action_combobox_changed(self, widget):
"""Exit action changed""" """Exit action changed"""
selected = widget.get_active() selected = widget.get_active()
@ -1496,8 +1617,8 @@ class PrefsEditor:
if self.colorschemevalues[key] == active: if self.colorschemevalues[key] == active:
value = key value = key
fore = guiget('foreground_colorpicker') fore = guiget('foreground_colorbutton')
back = guiget('background_colorpicker') back = guiget('background_colorbutton')
if value == 'custom': if value == 'custom':
fore.set_sensitive(True) fore.set_sensitive(True)
back.set_sensitive(True) back.set_sensitive(True)
@ -1510,16 +1631,6 @@ class PrefsEditor:
if value in self.colourschemes: if value in self.colourschemes:
forecol = self.colourschemes[value][0] forecol = self.colourschemes[value][0]
backcol = self.colourschemes[value][1] backcol = self.colourschemes[value][1]
elif value == 'custom':
forecol = color2hex(fore)
backcol = color2hex(back)
else:
err('Unknown colourscheme value: %s' % value)
return
fore.set_color(Gdk.color_parse(forecol))
back.set_color(Gdk.color_parse(backcol))
self.config['foreground_color'] = forecol self.config['foreground_color'] = forecol
self.config['background_color'] = backcol self.config['background_color'] = backcol
self.config.save() self.config.save()
@ -1530,8 +1641,8 @@ class PrefsEditor:
active = widget.get_active() active = widget.get_active()
scheme = guiget('color_scheme_combobox') scheme = guiget('color_scheme_combobox')
fore = guiget('foreground_colorpicker') fore = guiget('foreground_colorbutton')
back = guiget('background_colorpicker') back = guiget('background_colorbutton')
if active: if active:
for widget in [scheme, fore, back]: for widget in [scheme, fore, back]: