Skip to content

Commit

Permalink
[ctrl tooltips #46] display a hexa color code under the color name
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Nov 14, 2021
1 parent 950c6b5 commit e01aeb7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/tools/classic_tools/tool_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from gi.repository import Gdk
from .abstract_classic_tool import AbstractClassicTool
from .utilities_colors import utilities_get_rgba_name, \
utilities_gdk_rgba_from_xy
utilities_gdk_rgba_from_xy, \
utilities_gdk_rgba_to_hexadecimal

class ToolPicker(AbstractClassicTool):
__gtype_name__ = 'ToolPicker'
Expand All @@ -36,7 +37,9 @@ def get_tooltip(self, event_x, event_y, motion_behavior):
color = utilities_gdk_rgba_from_xy(self.get_surface(), event_x, event_y)
if color is None:
return None
return utilities_get_rgba_name(color)
color_name = utilities_get_rgba_name(color)
color_code = utilities_gdk_rgba_to_hexadecimal(color)
return color_name + "\n" + color_code

def on_release_on_area(self, event, surface, event_x, event_y):
color = utilities_gdk_rgba_from_xy(surface, event_x, event_y)
Expand Down
7 changes: 5 additions & 2 deletions src/tools/selection_tools/select_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

from .abstract_select import AbstractSelectionTool
from .utilities_colors import utilities_get_rgba_name, \
utilities_gdk_rgba_from_xy
utilities_gdk_rgba_from_xy, \
utilities_gdk_rgba_to_hexadecimal
from .utilities_paths import utilities_get_magic_path

class ToolColorSelect(AbstractSelectionTool):
Expand All @@ -33,7 +34,9 @@ def get_tooltip(self, event_x, event_y, motion_behavior):
color = utilities_gdk_rgba_from_xy(self.get_surface(), event_x, event_y)
if color is None:
return None
return utilities_get_rgba_name(color)
color_name = utilities_get_rgba_name(color)
color_code = utilities_gdk_rgba_to_hexadecimal(color)
return color_name + "\n" + color_code

def press_define(self, event_x, event_y):
pass
Expand Down
11 changes: 11 additions & 0 deletions src/utilities/utilities_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def utilities_rgb_to_hexadecimal(r, g, b):
operators."""
return (r << 16) + (g << 8) + b

def utilities_gdk_rgba_to_hexadecimal(gdk_rgba):
"""Returns a displayable string of the hexadecimal code corresponding to a
Gdk.RGBA object."""
r = int(255 * gdk_rgba.red)
g = int(255 * gdk_rgba.green)
b = int(255 * gdk_rgba.blue)
hexa_raw = hex(utilities_rgb_to_hexadecimal(r, g, b))
hexa_string = str(hexa_raw)[2:]
hexa_string = "0" * (6 - len(hexa_string)) + hexa_string
return "#" + hexa_string

################################################################################

def utilities_gdk_rgba_from_xy(surface, event_x, event_y):
Expand Down

0 comments on commit e01aeb7

Please sign in to comment.