Skip to content

Commit

Permalink
method on_tool_options_changed to better update the text preview, #357
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Jan 2, 2023
1 parent 6b76f5d commit e4dd458
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/options_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _boolean_callback(self, *args):
new_value = args[1].get_boolean()

args[0].set_state(GLib.Variant.new_boolean(new_value))
self.window.set_window_subtitles()
self.window.on_tool_options_changed()
self.get_active_pane().hide_options_menu()

def _enum_callback(self, *args):
Expand All @@ -89,7 +89,7 @@ def _enum_callback(self, *args):

# Actually change the state to the new value.
args[0].set_state(GLib.Variant.new_string(new_value))
self.window.set_window_subtitles()
self.window.on_tool_options_changed()
self.get_active_pane().hide_options_menu()

############################################################################
Expand Down
28 changes: 12 additions & 16 deletions src/optionsbars/classic/optionsbar_classic.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
# optionsbar_classic.py
#
# Copyright 2018-2023 Romain F. T.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Licensed under GPL3 https://github.com/maoschanz/drawing/blob/master/LICENSE

import cairo
from .abstract_optionsbar import AbstractOptionsBar
Expand Down Expand Up @@ -48,6 +33,7 @@ def __init__(self, window):
last_size = self._get_tool_options().get_int('last-size')
self.thickness_spinbtn.set_value(last_size)
utilities_add_unit_to_spinbtn(self.thickness_spinbtn, 3, 'px')
self.thickness_spinbtn.connect('value-changed', self._on_size_changed)

self.minimap_btn = builder.get_object('minimap_btn')
self.minimap_label = builder.get_object('minimap_label')
Expand Down Expand Up @@ -99,9 +85,19 @@ def set_compact(self, state):
self.thickness_spinbtn.set_visible(not state)
self.minimap_arrow.set_visible(not state)

############################################################################
# Size #####################################################################

def _on_size_changed(self, *args):
self.window.on_tool_options_changed()

############################################################################
# Colors ###################################################################

def _on_color_changed(self, *args):
# TODO connect that to whatever needs it
self.window.on_tool_options_changed()

def middle_click_action(self):
left_color = self._color_l.color_widget.get_rgba()
self._color_l.color_widget.set_rgba(self._color_r.color_widget.get_rgba())
Expand Down
17 changes: 1 addition & 16 deletions src/optionsbars/selection/optionsbar_selection.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
# optionsbar_selection.py
#
# Copyright 2018-2023 Romain F. T.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Licensed under GPL3 https://github.com/maoschanz/drawing/blob/master/LICENSE

from .abstract_optionsbar import AbstractOptionsBar

Expand Down
3 changes: 3 additions & 0 deletions src/tools/abstract_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def update_modifier_state(self, event_state):
modifier_keys.append('ALT')
self._modifier_keys = modifier_keys

def on_options_changed(self):
pass

############################################################################
# Various utilities ########################################################

Expand Down
4 changes: 4 additions & 0 deletions src/tools/classic_tools/abstract_classic_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def set_common_values(self, event_btn, event_x, event_y):
self.y_press = event_y
self._operator = self.window.options_manager.get_operator()[0]

def on_options_changed(self):
self._use_antialias = self.get_option_value('antialias')
self.tool_width = self.window.options_manager.get_tool_width()

############################################################################
# Operations common methods ################################################

Expand Down
15 changes: 7 additions & 8 deletions src/tools/classic_tools/tool_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _set_font(self, *args):
self.window.lookup_action('text-active-family').set_state(font_gvar)
self._preview_text()
dialog.destroy()
# TODO update le editing tip !!
self.window.on_tool_options_changed()

def _set_font_options(self, *args):
# XXX incomplete? OBLIQUE exists
Expand All @@ -98,12 +98,6 @@ def get_options_label(self):
return _("Text options")

def get_editing_tips(self):
self._set_font_options()
self._set_background_style()

# get_editing_tips is likely called because an option changed
self._preview_text()

label_options = self.label + " - " + self._font_fam_name
if self._background_id != 'none':
bg_label = {
Expand All @@ -114,9 +108,14 @@ def get_editing_tips(self):
'rectangle': _("Rectangle background"),
}[self._background_id]
label_options += " - " + bg_label

return [label_options]

def on_options_changed(self):
super().on_options_changed()
self._set_font_options()
self._set_background_style()
self._preview_text()

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

def on_tool_selected(self):
Expand Down
9 changes: 8 additions & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def switch_to(self, new_tool_id, image_pointer=None):
self.active_tool().on_tool_selected()
self._update_bottom_pane()
self.get_active_image().update_actions_state()
self.set_window_subtitles()
self.on_tool_options_changed()

self.pointer_to_current_page = None

Expand Down Expand Up @@ -955,6 +955,13 @@ def _build_options_menu(self):
pane = self.options_manager.get_active_pane()
pane.build_options_menu(widget, model, label)

def on_tool_options_changed(self, *args):
self.active_tool().on_options_changed()
self.set_window_subtitles()

############################################################################
# CLASSIC TOOLS PANE #######################################################

def _update_use_color_editor(self, *args):
use_editor = self.gsettings.get_boolean('direct-color-edit')
self.options_manager.set_palette_setting(use_editor)
Expand Down

0 comments on commit e4dd458

Please sign in to comment.