diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2024-06-04 22:27:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-04 22:27:33 +0200 |
| commit | 952ba0023a2b70de5fd7e5b2bb0d06566ec214e5 (patch) | |
| tree | 8c76bd48869951ab85c7af71c5799575bee5258c /lib/gui | |
| parent | 38206d4eade913cc846e00fd41e85b561e1c926b (diff) | |
Update tartan gui (#2965)
* update tartan gui
* params settings size
* fix issue with set_precision
* fix issue with linear gradient
* do not add ignore layer command to png rerealistic output
Diffstat (limited to 'lib/gui')
| -rw-r--r-- | lib/gui/satin_multicolor/__init__.py | 1 | ||||
| -rw-r--r-- | lib/gui/satin_multicolor/color_panel.py | 2 | ||||
| -rw-r--r-- | lib/gui/satin_multicolor/colorize_panel.py | 7 | ||||
| -rw-r--r-- | lib/gui/satin_multicolor/main_panel.py | 5 | ||||
| -rw-r--r-- | lib/gui/tartan/__init__.py | 1 | ||||
| -rw-r--r-- | lib/gui/tartan/customize_panel.py | 143 | ||||
| -rw-r--r-- | lib/gui/tartan/main_panel.py | 3 | ||||
| -rw-r--r-- | lib/gui/tartan/stripe_panel.py | 52 |
8 files changed, 116 insertions, 98 deletions
diff --git a/lib/gui/satin_multicolor/__init__.py b/lib/gui/satin_multicolor/__init__.py index 84406f22..5dc39049 100644 --- a/lib/gui/satin_multicolor/__init__.py +++ b/lib/gui/satin_multicolor/__init__.py @@ -3,6 +3,7 @@ # Copyright (c) 2024 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. +from .color_panel import ColorPanel from .colorize_panel import ColorizePanel from .help_panel import HelpPanel from .main_panel import MultiColorSatinPanel diff --git a/lib/gui/satin_multicolor/color_panel.py b/lib/gui/satin_multicolor/color_panel.py index c44599c8..e4961064 100644 --- a/lib/gui/satin_multicolor/color_panel.py +++ b/lib/gui/satin_multicolor/color_panel.py @@ -1,6 +1,6 @@ # Authors: see git history # -# Copyright (c) 2023 Authors +# Copyright (c) 2024 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. import wx diff --git a/lib/gui/satin_multicolor/colorize_panel.py b/lib/gui/satin_multicolor/colorize_panel.py index 3b595043..2dc10673 100644 --- a/lib/gui/satin_multicolor/colorize_panel.py +++ b/lib/gui/satin_multicolor/colorize_panel.py @@ -9,7 +9,7 @@ import wx from wx.lib.scrolledpanel import ScrolledPanel from ...i18n import _ -from .color_panel import ColorPanel +from . import ColorPanel class ColorizePanel(ScrolledPanel): @@ -169,9 +169,8 @@ class ColorizePanel(ScrolledPanel): self.Layout() def _remove_color(self, event): - sizer = event.GetEventObject().GetContainingSizer() - sizer.Clear(True) - self.color_sizer.Remove(sizer) + panel = event.GetEventObject().GetParent() + panel.Destroy() self.FitInside() self._update_colors() diff --git a/lib/gui/satin_multicolor/main_panel.py b/lib/gui/satin_multicolor/main_panel.py index e90ba855..197e197c 100644 --- a/lib/gui/satin_multicolor/main_panel.py +++ b/lib/gui/satin_multicolor/main_panel.py @@ -60,12 +60,11 @@ class MultiColorSatinPanel(wx.Panel): self.notebook_sizer.Add(apply_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 10) - self.SetSizer(self.notebook_sizer) - self.colorize_panel.add_color(self.elements[0].color) + self.SetSizerAndFit(self.notebook_sizer) + self.Layout() - self.SetMinSize(self.notebook_sizer.CalcMin()) def _hide_warning(self): self.warning_panel.clear() diff --git a/lib/gui/tartan/__init__.py b/lib/gui/tartan/__init__.py index 176d5d1e..7ba13789 100644 --- a/lib/gui/tartan/__init__.py +++ b/lib/gui/tartan/__init__.py @@ -4,6 +4,7 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. from .code_panel import CodePanel +from .stripe_panel import StripePanel from .customize_panel import CustomizePanel from .embroidery_panel import EmbroideryPanel from .help_panel import HelpPanel diff --git a/lib/gui/tartan/customize_panel.py b/lib/gui/tartan/customize_panel.py index a966bad1..cc2e372e 100644 --- a/lib/gui/tartan/customize_panel.py +++ b/lib/gui/tartan/customize_panel.py @@ -3,12 +3,11 @@ # Copyright (c) 2023 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. -from math import floor - import wx from wx.lib.scrolledpanel import ScrolledPanel from ...i18n import _ +from . import StripePanel class CustomizePanel(ScrolledPanel): @@ -114,92 +113,67 @@ class CustomizePanel(ScrolledPanel): self.add_stripe(False) def add_stripe(self, warp=True, stripe=None, update=True): - stripesizer = wx.BoxSizer(wx.HORIZONTAL) - - position = wx.Button(self, label='⁝', style=wx.BU_EXACTFIT) - position.SetToolTip(_("Drag and drop to adjust position.")) - position.Bind(wx.EVT_LEFT_DOWN, self._move_stripe_start) - position.Bind(wx.EVT_LEFT_UP, self._move_stripe_end) - - visibility = wx.CheckBox(self, style=wx.CHK_3STATE | wx.CHK_ALLOW_3RD_STATE_FOR_USER) - visibility.SetToolTip(_("Checked: stitch this stripe | Minus: spacer for strokes only | Disabled: spacer for fill and stroke")) - visibility.Set3StateValue(1) - visibility.Bind(wx.EVT_CHECKBOX, self._update_stripes_event) - - # hidden label used for linked colors - # there seems to be no native way to catch the old color setting - colorinfo = wx.StaticText(self, label='black') - colorinfo.Hide() - - colorpicker = wx.ColourPickerCtrl(self, colour=wx.Colour('black')) - colorpicker.SetToolTip(_("Select stripe color")) - colorpicker.Bind(wx.EVT_COLOURPICKER_CHANGED, self._update_color) - - stripe_width = wx.SpinCtrlDouble(self, min=0.0, max=500, initial=5, style=wx.SP_WRAP) - stripe_width.SetDigits(2) - stripe_width.SetToolTip(_("Set stripe width (mm)")) - stripe_width.Bind(wx.EVT_SPINCTRLDOUBLE, self._update_stripes_event) - - remove_button = wx.Button(self, label='X') - remove_button.SetToolTip(_("Remove stripe")) - remove_button.Bind(wx.EVT_BUTTON, self._remove_stripe) - - stripesizer.Add(position, 0, wx.CENTER | wx.RIGHT | wx.TOP, 5) - stripesizer.Add(visibility, 0, wx.CENTER | wx.RIGHT | wx.TOP, 5) - stripesizer.Add(colorinfo, 0, wx.RIGHT | wx.TOP, 5) - stripesizer.Add(colorpicker, 0, wx.RIGHT | wx.TOP, 5) - stripesizer.Add(stripe_width, 1, wx.RIGHT | wx.TOP, 5) - stripesizer.Add(remove_button, 0, wx.CENTER | wx.TOP, 5) + stripe_panel = StripePanel(self) if stripe is not None: - visibility.Set3StateValue(stripe['render']) - colorinfo.SetLabel(wx.Colour(stripe['color']).GetAsString(wx.C2S_HTML_SYNTAX)) - colorpicker.SetColour(wx.Colour(stripe['color'])) - stripe_width.SetValue(stripe['width']) + stripe_panel.visibility.Set3StateValue(stripe['render']) + stripe_panel.colorinfo.SetLabel(wx.Colour(stripe['color']).GetAsString(wx.C2S_HTML_SYNTAX)) + stripe_panel.colorpicker.SetColour(wx.Colour(stripe['color'])) + stripe_panel.stripe_width.SetValue(stripe['width']) + if warp: - self.warp_sizer.Add(stripesizer, 0, wx.EXPAND | wx.ALL, 5) + self.warp_sizer.Add(stripe_panel, 0, wx.EXPAND | wx.ALL, 5) else: - self.weft_sizer.Add(stripesizer, 0, wx.EXPAND | wx.ALL, 5) + self.weft_sizer.Add(stripe_panel, 0, wx.EXPAND | wx.ALL, 5) + if update: self.panel.update_from_stripes() - self.set_stripe_width_color(stripe_width) - self.FitInside() - def _move_stripe_start(self, event): - self.mouse_position = wx.GetMousePosition() + self._hide_first_position_button() + self.set_stripe_width_color(stripe_panel.stripe_width) + self.FitInside() - def _move_stripe_end(self, event): + def _move_stripe_up(self, event): stripe = event.GetEventObject() - sizer = stripe.GetContainingSizer() - if self.warp_sizer.GetItem(sizer): - main_sizer = self.warp_sizer - else: - main_sizer = self.weft_sizer - for i, item in enumerate(main_sizer.GetChildren()): - if item.GetSizer() == sizer: + + main_sizer = None + i = 0 + panel = stripe.GetParent() + for i, item in enumerate(self.warp_sizer.GetChildren()): + if item.GetWindow() == panel: + main_sizer = self.warp_sizer index = i - break - position = wx.GetMousePosition() - sizer_height = sizer.GetSize()[1] + 10 - move = floor((position[1] - self.mouse_position[1]) / sizer_height) - index = min(len(main_sizer.Children) - 1, max(0, (index + move))) - main_sizer.Detach(sizer) - main_sizer.Insert(index, sizer, 0, wx.EXPAND | wx.ALL, 5) + if not main_sizer: + for i, item in enumerate(self.weft_sizer.GetChildren()): + if item.GetWindow() == panel: + main_sizer = self.weft_sizer + index = i + + index = max(0, (index - 1)) + if index == 0: + previous_first = main_sizer.GetChildren()[0].GetWindow() + previous_first.position.Show() + + main_sizer.Detach(panel) + main_sizer.Insert(index, panel, 0, wx.EXPAND | wx.ALL, 5) + self._hide_first_position_button() self.panel.update_from_stripes() self.FitInside() + self.Layout() def _remove_stripe(self, event): - sizer = event.GetEventObject().GetContainingSizer() - sizer.Clear(True) - self.warp_sizer.Remove(sizer) - try: - self.weft_sizer.Remove(sizer) - except RuntimeError: - # we may have removed it already - pass + panel = event.GetEventObject().GetParent() + panel.Destroy() + self._hide_first_position_button() self.panel.update_from_stripes() self.FitInside() + def _hide_first_position_button(self): + if len(self.warp_sizer.GetChildren()) > 0: + self.warp_sizer.GetChildren()[0].GetWindow().position.Show(False) + if len(self.weft_sizer.GetChildren()) > 0: + self.weft_sizer.GetChildren()[0].GetWindow().position.Show(False) + def on_change(self, attribute, event): self.panel.settings[attribute] = event.EventObject.GetValue() self.panel.update_preview() @@ -217,11 +191,8 @@ class CustomizePanel(ScrolledPanel): def update_stripe_width_colors(self): for sizer in [self.warp_sizer, self.weft_sizer]: for stripe_sizer in sizer.GetChildren(): - inner_sizer = stripe_sizer.GetSizer() - for stripe_widget in inner_sizer: - widget = stripe_widget.GetWindow() - if isinstance(widget, wx.SpinCtrlDouble): - self.set_stripe_width_color(widget) + stripe_panel = stripe_sizer.GetWindow() + self.set_stripe_width_color(stripe_panel.stripe_width) def set_stripe_width_color(self, stripe_width_ctrl): scale = self.scale.GetValue() @@ -258,14 +229,11 @@ class CustomizePanel(ScrolledPanel): def _update_color_picker(self, old_color, new_color, sizer): for stripe_sizer in sizer.Children: - stripe_info = stripe_sizer.GetSizer() - for widget in stripe_info.GetChildren(): - widget = widget.GetWindow() - if isinstance(widget, wx.ColourPickerCtrl): - color = widget.GetColour() - if color == old_color: - widget.SetColour(new_color) - widget.GetPrevSibling().SetLabel(new_color.GetAsString(wx.C2S_HTML_SYNTAX)) + stripe_panel = stripe_sizer.GetWindow() + color = stripe_panel.colorpicker.GetColour() + if color == old_color: + stripe_panel.colorpicker.SetColour(new_color) + stripe_panel.colorinfo.SetLabel(new_color.GetAsString(wx.C2S_HTML_SYNTAX)) def update_symmetry(self, event=None): symmetry = self.symmetry_checkbox.GetValue() @@ -293,8 +261,5 @@ class CustomizePanel(ScrolledPanel): def _hide_colorinfo(self): for stripe_sizer in self.weft_sizer.Children: - stripe_info = stripe_sizer.GetSizer() - for stripe in stripe_info.GetChildren(): - widget = stripe.GetWindow() - if isinstance(widget, wx.StaticText): - widget.Hide() + stripe_panel = stripe_sizer.GetWindow() + stripe_panel.colorinfo.Hide() diff --git a/lib/gui/tartan/main_panel.py b/lib/gui/tartan/main_panel.py index 34015fb4..9df6a748 100644 --- a/lib/gui/tartan/main_panel.py +++ b/lib/gui/tartan/main_panel.py @@ -39,6 +39,7 @@ class TartanMainPanel(wx.Panel): # preview self.preview_renderer = PreviewRenderer(self.render_stitch_plan, self.on_stitch_plan_rendered) + # presets self.presets_panel = PresetsPanel(self) # warnings self.warning_panel = WarningPanel(self) @@ -73,7 +74,7 @@ class TartanMainPanel(wx.Panel): self.notebook_sizer.Add(self.presets_panel, 0, wx.EXPAND | wx.ALL, 10) self.notebook_sizer.Add(apply_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 10) - self.SetSizer(self.notebook_sizer) + self.SetSizerAndFit(self.notebook_sizer) self.load_settings() self.apply_settings() diff --git a/lib/gui/tartan/stripe_panel.py b/lib/gui/tartan/stripe_panel.py new file mode 100644 index 00000000..3188f56b --- /dev/null +++ b/lib/gui/tartan/stripe_panel.py @@ -0,0 +1,52 @@ +# Authors: see git history +# +# Copyright (c) 2023 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +import wx + +from ...i18n import _ + + +class StripePanel(wx.Panel): + def __init__(self, parent, *args, **kwargs): + self.panel = parent + wx.Panel.__init__(self, parent, wx.ID_ANY, *args, **kwargs) + + stripesizer = wx.BoxSizer(wx.HORIZONTAL) + + self.position = wx.Button(self, label='↑', style=wx.BU_EXACTFIT) + self.position.SetToolTip(_("Click to move color up.")) + self.position.Bind(wx.EVT_BUTTON, self.panel._move_stripe_up) + + self.visibility = wx.CheckBox(self, style=wx.CHK_3STATE | wx.CHK_ALLOW_3RD_STATE_FOR_USER) + self.visibility.SetToolTip(_("Checked: stitch this stripe | Minus: spacer for strokes only | Disabled: spacer for fill and stroke")) + self.visibility.Set3StateValue(1) + self.visibility.Bind(wx.EVT_CHECKBOX, self.panel._update_stripes_event) + + # hidden label used for linked colors + # there seems to be no native way to catch the old color setting + self.colorinfo = wx.StaticText(self, label='black') + self.colorinfo.Hide() + + self.colorpicker = wx.ColourPickerCtrl(self, colour=wx.Colour('black')) + self.colorpicker.SetToolTip(_("Select stripe color")) + self.colorpicker.Bind(wx.EVT_COLOURPICKER_CHANGED, self.panel._update_color) + + self.stripe_width = wx.SpinCtrlDouble(self, min=0.0, max=500, initial=5, style=wx.SP_WRAP) + self.stripe_width.SetDigits(2) + self.stripe_width.SetToolTip(_("Set stripe width (mm)")) + self.stripe_width.Bind(wx.EVT_SPINCTRLDOUBLE, self.panel._update_stripes_event) + + self.remove_button = wx.Button(self, label='X') + self.remove_button.SetToolTip(_("Remove stripe")) + self.remove_button.Bind(wx.EVT_BUTTON, self.panel._remove_stripe) + + stripesizer.Add(self.position, 0, wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.CENTER | wx.RIGHT | wx.TOP, 5) + stripesizer.Add(self.visibility, 0, wx.CENTER | wx.RIGHT | wx.TOP, 5) + stripesizer.Add(self.colorinfo, 0, wx.RIGHT | wx.TOP, 5) + stripesizer.Add(self.colorpicker, 0, wx.RIGHT | wx.TOP, 5) + stripesizer.Add(self.stripe_width, 1, wx.RIGHT | wx.TOP, 5) + stripesizer.Add(self.remove_button, 0, wx.CENTER | wx.TOP, 5) + + self.SetSizer(stripesizer) |
