Created
January 24, 2017 21:23
-
-
Save jbylund/14fc022cd94ac8e01a2d4fd95e1641c8 to your computer and use it in GitHub Desktop.
Silly script to update the colors of gnome terminal to be uniformly spaced around the wheel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| from gi.repository import Gio, GLib | |
| class Color(object): | |
| def __init__(self, red, green, blue): | |
| self.red = red | |
| self.green = green | |
| self.blue = blue | |
| @classmethod | |
| def from_rgb(self, (r, g, b)): | |
| return Color(r, g, b) | |
| @classmethod | |
| def from_hsv(self, (h, s, v)): | |
| s /= 100.0 | |
| v /= 100.0 | |
| c = v * s | |
| x = c * (1 - abs((h/60.0) % 2 - 1)) | |
| m = v - c | |
| for step, seq in enumerate([ | |
| (c, x, 0), | |
| (x, c, 0), | |
| (0, c, x), | |
| (0, x, c), | |
| (x, 0, c), | |
| (c, 0, x)]): | |
| upper_bound = 60 * (1 + step) | |
| r_p, g_p, b_p = seq | |
| if not upper_bound < h: | |
| break | |
| r = (r_p + m) * 255.0 | |
| g = (g_p + m) * 255.0 | |
| b = (b_p + m) * 255.0 | |
| return Color(r, g, b) | |
| @classmethod | |
| def from_hex(self, hexcolor): | |
| pass | |
| def hexstr(self): | |
| return "".join("{:02X}".format(int(round(x))) for x in [self.red, self.green, self.blue]) | |
| def __str__(self): | |
| return "rgb({}, {}, {})".format( | |
| int(round(self.red)), | |
| int(round(self.green)), | |
| int(round(self.blue))) | |
| def __repr__(self): | |
| return str(self) | |
| circle = 360.0 | |
| pieces = 8 | |
| colors = [] | |
| for saturation in [50, 70]: | |
| for i in xrange(pieces): | |
| hue = i * circle / pieces | |
| color = Color.from_hsv((hue, saturation, 100)) | |
| colors.append(color) | |
| profile_list_registry = Gio.Settings.new("org.gnome.Terminal.ProfilesList") | |
| profile_id = profile_list_registry['default'] | |
| my_profile = Gio.Settings.new_with_path( | |
| "org.gnome.Terminal.Legacy.Profile", | |
| "/org/gnome/terminal/legacy/profiles:/:{}/".format(profile_id) | |
| ) | |
| print my_profile['palette'] | |
| my_profile['palette'] = [str(c) for c in colors] | |
| print my_profile['palette'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment