コード例 #1
0
ファイル: editors.py プロジェクト: Shiloli-r/Formation
 def _parse_color(self, value):
     try:
         val = self.winfo_rgb(value)
     except Exception:
         return ""
     val = tuple(map(lambda x: round((x / 65535) * 255), val))
     return to_hex(val)
コード例 #2
0
ファイル: panels.py プロジェクト: ObaraEmmanuel/Formation
 def get(self) -> str:
     # return the hex color string
     # remember s and v are percentages and underlying hsv converter works with values from 0 to 255
     hsv = self.h.get(), self.s.get(), self.v.get()
     if any(i == "" for i in hsv):
         return self.initial
     return to_hex(from_hsv(hsv))
コード例 #3
0
ファイル: panels.py プロジェクト: ObaraEmmanuel/Formation
 def get(self) -> str:
     # return the hex color string
     rgb = self.r.get(), self.g.get(), self.b.get()
     # we shield ourselves from errors raised when trying to parse empty values
     if any(i == "" for i in rgb):
         return self.initial
     return to_hex(rgb)
コード例 #4
0
 def update_panel(self, *_):
     hsv = self.hue.get_hsv()[0], *self.col.get_hsv()[1:]
     hex_string = color.to_hex(color.from_hsv(hsv))
     # We have set panel value implicitly so we update the hex value ourselves
     self.monitor.set(hex_string, True)
     self.monitor.hex_string.set(hex_string)
     if self._on_change:
         self._on_change(self.monitor.get())
コード例 #5
0
 def update_panel(self, *_):
     hsl = self.hue.get_hsl()[0], self.sat.get_hsl()[1], self.lum.get_hsl(
     )[2]
     hex_string = color.to_hex(color.from_hsl(hsl))
     # We have set panel value implicitly so we update the hex value ourselves
     self.monitor.set(hex_string, True)
     self.monitor.hex_string.set(hex_string)
     if self._on_change:
         self._on_change(self.monitor.get())
コード例 #6
0
ファイル: editors.py プロジェクト: ObaraEmmanuel/Formation
 def _parse_color(self, value):
     if value == "" and self.style_def.get("allow_transparent", False):
         return value
     try:
         val = self.winfo_rgb(value)
     except Exception:
         return None
     val = tuple(map(lambda x: round((x / 65535) * 255), val))
     return to_hex(val)
コード例 #7
0
ファイル: panels.py プロジェクト: ObaraEmmanuel/Formation
 def on_hex_string_changed(self):
     # If the color format is incorrect no need to update the panel
     # If the string is 8 bit we need to expand it using to_hex
     if len(self.hex_string.get()) == 4:
         self.current_model.set(to_hex(self.hex_string.get()))
         self.callback(self.current_model.get())
     # if the color is 8 bit then we can update without errors
     elif len(self.hex_string.get()) == 7:
         self.current_model.set(self.hex_string.get())
         self.callback(self.current_model.get())
コード例 #8
0
ファイル: panels.py プロジェクト: ObaraEmmanuel/Formation
 def process(self, event):
     displace_x = 10 if self.winfo_screenwidth(
     ) - event.x_root > 60 else -50
     displace_y = 0 if self.winfo_screenheight(
     ) - event.y_root > 50 else -40
     self.place(x=event.x_root + displace_x,
                y=event.y_root + displace_y,
                width=40,
                height=40)
     color = self.pixel_access[event.x_root, event.y_root]
     self.color = to_hex(color)
     self.label.config(bg=self.color)
コード例 #9
0
 def __init__(self, master=None, color_array=None, **cnf):
     super().__init__(master, **cnf)
     self.config(**self.style.dark, **self.style.dark_highlight)
     self.color_strip = Canvas(self,
                               width=230,
                               height=27,
                               **self.style.dark,
                               highlightthickness=0)
     self.color_strip.pack(pady=5)
     self.color_strip.tk.eval(_ColorStrip._RECOLOR_PROC)
     setattr(self.color_strip, "pos", 5)
     self.color_strip.bind("<ButtonPress-1>", self._drag_start)
     self.color_strip.bind("<ButtonRelease>", self._drag_end)
     self.color_strip.bind("<Motion>", self._adjust)
     self.drag_state = False
     x, y = 5, 0
     self._width = int(self.color_strip['width'])
     self.step = step = (self._width - 10) / len(color_array)
     self.color_array = color_array
     for c in color_array:
         fill = color.to_hex(c)
         self.color_strip.create_rectangle(x,
                                           y,
                                           x + step,
                                           y + 15,
                                           fill=fill,
                                           width=0)
         x = x + step
     self.callback, self.implicit_callback = None, None
     self.selector = self.color_strip.create_polygon(
         5,
         15,
         0,
         25,
         10,
         25,
         splinesteps=1,
         joinstyle="miter",
         fill="#5a5a5a",
         outline="#f7f7f7",
         activeoutline="#3d8aff")
     # First, I apologise for the crappy syntax
     # But this was the quickest way to generate an anonymous event object for use with _adjust
     # Considering we are working inside a lambda function!
     # This should allow the use of arrow keys to adjust the strip
     self.bind(
         "<Left>", lambda e: self._adjust(
             type("", (), {"x": self.color_strip.pos - 1})(), True))
     self.bind(
         "<Right>", lambda e: self._adjust(
             type("", (), {"x": self.color_strip.pos + 1})(), True))
コード例 #10
0
ファイル: panels.py プロジェクト: ObaraEmmanuel/Formation
 def pick_from_clipboard(self, *_):
     value = self.clipboard_get()
     try:
         # convert color from clipboard to general rgb format first
         # if the color is valid this should not throw any errors
         # this means if the clipboard contains "red" what is set finally is "#ff0000"
         r, g, b = self.winfo_rgb(value)  # returns 12-bit color
         # scale down from 12-bit color to 8-bit color that the color-chooser understands
         color = to_hex(
             tuple(map(lambda x: round(x * (255 / 65535)), (r, g, b))))
         self.set(color)
     except Exception:
         # Not a valid color so ignore
         # TODO Show a message
         pass
コード例 #11
0
 def __init__(self, master, hue, **cnf):
     super().__init__(master, **cnf)
     self.hue = hue
     self._color = None
     self.color_space = Canvas(self,
                               width=230,
                               height=100,
                               **self.style.surface,
                               highlightthickness=0)
     self.color_space.pack()
     self.color_space.bind("<ButtonPress-1>", self._drag_start)
     self.color_space.bind("<ButtonRelease>", self._drag_end)
     self.color_space.bind("<Motion>", self._adjust)
     self.drag_state = False
     x, y = 0, 0
     self.pos = x, y
     self._width = w = int(self.color_space['width'])
     self._height = h = int(self.color_space['height'])
     step_x = round(w / 50)
     step_y = round(h / 50)
     for i in range(0, 101, 2):
         for j in range(100, -1, -2):
             fill = color.to_hex(color.from_hsv((hue, i, j)))
             self.color_space.create_rectangle(x,
                                               y,
                                               x + step_x,
                                               y + step_y,
                                               fill=fill,
                                               width=0)
             y += step_y
         y = 0
         x += step_x
     self.callback, self.implicit_callback = None, None
     self.selector = self.color_space.create_oval(0,
                                                  0,
                                                  1,
                                                  1,
                                                  outline="#f7f7f7",
                                                  activeoutline="#3d8aff")
コード例 #12
0
 def __init__(self, master=None, color_array=None, **cnf):
     super().__init__(master, **cnf)
     self.color_strip = Canvas(self,
                               width=230,
                               height=27,
                               **self.style.surface,
                               highlightthickness=0)
     self.color_strip.pack(pady=5)
     self.color_strip.bind("<ButtonPress-1>", self._drag_start)
     self.color_strip.bind("<ButtonRelease>", self._drag_end)
     self.color_strip.bind("<Motion>", self._adjust)
     self.drag_state = False
     x, y = 5, 0
     self.pos = x, y
     self._width = int(self.color_strip['width'])
     self.step = step = (self._width - 10) / len(color_array)
     self.color_array = color_array
     for c in color_array:
         fill = color.to_hex(c)
         self.color_strip.create_rectangle(x,
                                           y,
                                           x + step,
                                           y + 15,
                                           fill=fill,
                                           width=0)
         x = x + step
     self.selector = self.color_strip.create_polygon(
         5,
         15,
         0,
         25,
         10,
         25,
         splinesteps=1,
         joinstyle="miter",
         fill="#5a5a5a",
         outline="#f7f7f7",
         activeoutline="#3d8aff")
コード例 #13
0
ファイル: panels.py プロジェクト: ObaraEmmanuel/Formation
 def get(self) -> str:
     # return the hex color string
     hsl = self.h.get(), self.s.get(), self.l.get()
     if any(i == "" for i in hsl):
         return self.initial
     return to_hex(from_hsl(hsl))
コード例 #14
0
ファイル: panels.py プロジェクト: mardukbp/Formation
 def get(self) -> str:
     # return the hex color string
     # remember s and v are percentages and underlying hsv converter works with values from 0 to 255
     return to_hex(from_hsv((self.h.get(), self.s.get(), self.v.get())))
コード例 #15
0
ファイル: panels.py プロジェクト: mardukbp/Formation
 def get(self) -> str:
     # return the hex color string
     return to_hex(from_hsl((self.h.get(), self.s.get(), self.l.get())))
コード例 #16
0
 def get(self):
     return color.to_hex(color.from_hsv(self._color))