Moved get_hex_color_range() from util.py to network_graph.py to prevent
breaking the build.
This commit is contained in:
parent
856bc5cc24
commit
48821e34ca
@ -3,7 +3,6 @@ import functools
|
|||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
from colour import Color
|
|
||||||
|
|
||||||
|
|
||||||
def lchop(string, prefix):
|
def lchop(string, prefix):
|
||||||
@ -424,29 +423,3 @@ def user_open(url_or_command):
|
|||||||
import subprocess
|
import subprocess
|
||||||
subprocess.Popen(url_or_command, shell=True)
|
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
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from colour import Color
|
||||||
from i3pystatus.network_traffic import NetworkTraffic
|
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):
|
class NetworkGraph(NetworkTraffic):
|
||||||
@ -37,9 +38,35 @@ class NetworkGraph(NetworkTraffic):
|
|||||||
upper_limit = 150.0
|
upper_limit = 150.0
|
||||||
|
|
||||||
def init(self):
|
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
|
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):
|
def get_gradient(self, value):
|
||||||
"""
|
"""
|
||||||
Map a value to a color
|
Map a value to a color
|
||||||
|
Loading…
Reference in New Issue
Block a user