put different hex to color functions in the same place: utils.py

svn: r20236
This commit is contained in:
Benny Malengier 2012-08-20 15:42:23 +00:00
parent 61738c91b6
commit 0ea744e5e5
2 changed files with 15 additions and 15 deletions

View File

@ -428,3 +428,17 @@ def rgb_to_hex(rgb):
rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)) rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))
return '#%02x%02x%02x' % rgbint return '#%02x%02x%02x' % rgbint
def color_to_hex(color):
"""Convert Gdk.Color to hex string."""
hexstring = ""
for col in 'red', 'green', 'blue':
hexfrag = hex(getattr(color, col) / (16 * 16)).split("x")[1]
if len(hexfrag) < 2:
hexfrag = "0" + hexfrag
hexstring += hexfrag
return '#' + hexstring
def hex_to_color(hex):
"""Convert hex string to Gdk.Color."""
color = Gdk.color_parse(hex)
return color

View File

@ -61,7 +61,7 @@ from gui.widgets.toolcomboentry import ToolComboEntry
from gui.widgets.springseparator import SpringSeparatorAction from gui.widgets.springseparator import SpringSeparatorAction
from gui.spell import Spell from gui.spell import Spell
from gui.display import display_url from gui.display import display_url
from gui.utils import SystemFonts, rgb_to_hex from gui.utils import SystemFonts, rgb_to_hex, hex_to_color, color_to_hex
from gen.config import config from gen.config import config
from gen.constfunc import has_display from gen.constfunc import has_display
@ -852,20 +852,6 @@ def uri_dialog(self, uri, callback):
# Module functions # Module functions
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def color_to_hex(color):
"""Convert Gdk.Color to hex string."""
hexstring = ""
for col in 'red', 'green', 'blue':
hexfrag = hex(getattr(color, col) / (16 * 16)).split("x")[1]
if len(hexfrag) < 2:
hexfrag = "0" + hexfrag
hexstring += hexfrag
return '#' + hexstring
def hex_to_color(hex):
"""Convert hex string to Gdk.Color."""
color = Gdk.color_parse(hex)
return color
def is_valid_fontsize(size): def is_valid_fontsize(size):
"""Validator function for font size selector widget.""" """Validator function for font size selector widget."""