Skip to content

Commit 0f6b26b

Browse files
Allow annotation options to be changed in select mode (#225)
1 parent d3958d5 commit 0f6b26b

File tree

5 files changed

+197
-110
lines changed

5 files changed

+197
-110
lines changed

gradia/backend/tool_config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(
3232
border_color: Gdk.RGBA = None,
3333
font: str = None,
3434
on_change_callback: Optional[Callable[['ToolOption'], None]] = None,
35+
is_temporary: bool = False,
3536
) -> None:
3637
self.mode = mode
3738
self._size = size
@@ -40,6 +41,7 @@ def __init__(
4041
self._border_color_str = self._rgba_to_str(border_color or Gdk.RGBA(0,0,0,0))
4142
self._font = font or "Adwaita Sans"
4243
self._on_change_callback = on_change_callback
44+
self._is_temporary = is_temporary
4345

4446
def _rgba_to_str(self, rgba: Gdk.RGBA) -> str:
4547
return f"rgba({rgba.red:.2f}, {rgba.green:.2f}, {rgba.blue:.2f}, {rgba.alpha:.2f})"
@@ -52,7 +54,7 @@ def _str_to_rgba(self, s: str) -> Gdk.RGBA:
5254
return Gdk.RGBA(r, g, b, a)
5355

5456
def _notify_change(self):
55-
if self._on_change_callback:
57+
if self._on_change_callback and not self._is_temporary:
5658
self._on_change_callback(self)
5759

5860
@property
@@ -138,15 +140,16 @@ def tuple_to_rgba(t):
138140
on_change_callback=on_change_callback,
139141
)
140142

141-
def copy(self) -> "ToolOption":
143+
def copy(self, is_temporary: bool = False) -> "ToolOption":
142144
return ToolOption(
143145
mode=self.mode,
144146
size=self.size,
145147
primary_color=self.primary_color,
146148
fill_color=self.fill_color,
147149
border_color=self.border_color,
148150
font=self.font,
149-
on_change_callback=self._on_change_callback,
151+
on_change_callback=self._on_change_callback if not is_temporary else None,
152+
is_temporary=is_temporary,
150153
)
151154

152155
def update_without_notify(self, **kwargs):
@@ -357,5 +360,3 @@ def get_all_tools_positions():
357360
secondary_color_list=ToolConfig.TEXT_BACKGROUND_COLORS
358361
),
359362
]
360-
361-

0 commit comments

Comments
 (0)