From 48821e34ca5b4094145b043f7fc285777b2dae17 Mon Sep 17 00:00:00 2001 From: facetoe Date: Sat, 11 Oct 2014 14:52:08 +0800 Subject: [PATCH] Moved get_hex_color_range() from util.py to network_graph.py to prevent breaking the build. --- i3pystatus/core/util.py | 27 --------------------------- i3pystatus/network_graph.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index f6e91cd..c5bdcf4 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -3,7 +3,6 @@ import functools import re import socket import string -from colour import Color def lchop(string, prefix): @@ -424,29 +423,3 @@ def user_open(url_or_command): import subprocess subprocess.Popen(url_or_command, shell=True) - -def get_hex_color_range(start_color, end_color, quantity): - """ - Generates a list of quantity Hex colors from start_color to end_color. - - :param start_color: Hex or plain English color for start of range - :param end_color: Hex or plain English color for end of range - :param quantity: Number of colours to return - :return: A list of Hex color values - """ - raw_colors = [c.hex for c in list(Color(start_color).range_to(Color(end_color), quantity))] - colors = [] - for color in raw_colors: - - # i3bar expects the full Hex value but for some colors the colour - # module only returns partial values. So we need to convert these colors to the full - # Hex value. - if len(color) == 4: - fixed_color = "#" - for c in color[1:]: - fixed_color += c * 2 - colors.append(fixed_color) - else: - colors.append(color) - return colors - diff --git a/i3pystatus/network_graph.py b/i3pystatus/network_graph.py index e3caa32..101b3cd 100644 --- a/i3pystatus/network_graph.py +++ b/i3pystatus/network_graph.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- +from colour import Color from i3pystatus.network_traffic import NetworkTraffic -from i3pystatus.core.util import make_graph, get_hex_color_range +from i3pystatus.core.util import make_graph class NetworkGraph(NetworkTraffic): @@ -37,9 +38,35 @@ class NetworkGraph(NetworkTraffic): upper_limit = 150.0 def init(self): - self.colors = get_hex_color_range(self.start_color, self.end_color, int(self.upper_limit)) + self.colors = self.get_hex_color_range(self.start_color, self.end_color, int(self.upper_limit)) self.kbs_arr = [0.0] * self.graph_width + @staticmethod + def get_hex_color_range(start_color, end_color, quantity): + """ + Generates a list of quantity Hex colors from start_color to end_color. + + :param start_color: Hex or plain English color for start of range + :param end_color: Hex or plain English color for end of range + :param quantity: Number of colours to return + :return: A list of Hex color values + """ + raw_colors = [c.hex for c in list(Color(start_color).range_to(Color(end_color), quantity))] + colors = [] + for color in raw_colors: + + # i3bar expects the full Hex value but for some colors the colour + # module only returns partial values. So we need to convert these colors to the full + # Hex value. + if len(color) == 4: + fixed_color = "#" + for c in color[1:]: + fixed_color += c * 2 + colors.append(fixed_color) + else: + colors.append(color) + return colors + def get_gradient(self, value): """ Map a value to a color