Moved get_hex_color_range() from util.py to network_graph.py to prevent

breaking the build.
This commit is contained in:
facetoe 2014-10-11 14:52:08 +08:00
parent 856bc5cc24
commit 48821e34ca
2 changed files with 29 additions and 29 deletions

View File

@ -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

View File

@ -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