kopia lustrzana https://github.com/inkstitch/inkstitch
Thread catalog: fix broken path (#3281)
* thread catalog: fix broken path * apply threadlist: use wxpython to also include custom lists * apply_palette: save last choicepull/3288/head
rodzic
b20ad42733
commit
e8123b7274
|
@ -4,6 +4,9 @@
|
|||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||
|
||||
from ..elements import Clone, FillStitch
|
||||
from ..gui.abort_message import AbortMessageApp
|
||||
from ..gui.apply_palette import ApplyPaletteApp
|
||||
from ..i18n import _
|
||||
from ..threads import ThreadCatalog, ThreadColor
|
||||
from .base import InkstitchExtension
|
||||
|
||||
|
@ -12,19 +15,24 @@ class ApplyPalette(InkstitchExtension):
|
|||
'''
|
||||
Applies colors of a color palette to elements
|
||||
'''
|
||||
def __init__(self, *args, **kwargs):
|
||||
InkstitchExtension.__init__(self, *args, **kwargs)
|
||||
self.arg_parser.add_argument("-o", "--tabs")
|
||||
self.arg_parser.add_argument("-t", "--palette", type=str, default=None, dest="palette")
|
||||
|
||||
def effect(self):
|
||||
# Remove selection, we want all the elements in the document
|
||||
self.svg.selection.clear()
|
||||
|
||||
if not self.get_elements():
|
||||
app = AbortMessageApp(
|
||||
_("There is no stitchable element in the document."),
|
||||
_("https://inkstitch.org/")
|
||||
)
|
||||
app.MainLoop()
|
||||
return
|
||||
|
||||
palette_name = self.options.palette
|
||||
palette_choice = ApplyPaletteApp()
|
||||
if palette_choice.palette:
|
||||
self.apply_palette(palette_choice.palette)
|
||||
|
||||
def apply_palette(self, palette_name):
|
||||
palette = ThreadCatalog().get_palette_by_name(palette_name)
|
||||
|
||||
# Iterate through the color blocks to apply colors
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
# 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
|
||||
import wx.adv
|
||||
|
||||
from ..i18n import _
|
||||
from ..threads import ThreadCatalog
|
||||
from ..utils.settings import global_settings
|
||||
|
||||
|
||||
class ApplyPaletteFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title, **kwargs):
|
||||
super().__init__(None, title=title)
|
||||
|
||||
self.SetWindowStyle(wx.FRAME_FLOAT_ON_PARENT | wx.DEFAULT_FRAME_STYLE)
|
||||
|
||||
self.apply_hook = kwargs.pop('on_apply', None)
|
||||
|
||||
self.main_panel = wx.Panel(self, wx.ID_ANY)
|
||||
|
||||
notebook_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.notebook = wx.Notebook(self.main_panel, wx.ID_ANY)
|
||||
notebook_sizer.Add(self.notebook, 1, wx.EXPAND, 0)
|
||||
|
||||
self.palettes = wx.Panel(self.notebook, wx.ID_ANY)
|
||||
self.notebook.AddPage(self.palettes, _("Palettes"))
|
||||
|
||||
palette_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
palette_text = wx.StaticText(self.palettes, -1, _("Select color palette"))
|
||||
self.palette_list = wx.Choice(self.palettes, choices=ThreadCatalog().palette_names())
|
||||
last_selected_pallete = self.palette_list.FindString(global_settings['last_applied_palette'])
|
||||
self.palette_list.SetSelection(last_selected_pallete)
|
||||
|
||||
palette_sizer.Add(palette_text, 0, wx.ALL | wx.EXPAND, 10)
|
||||
palette_sizer.Add(self.palette_list, 0, wx.ALL | wx.EXPAND, 10)
|
||||
|
||||
button_sizer = wx.StdDialogButtonSizer()
|
||||
palette_sizer.Add(button_sizer, 1, wx.BOTTOM | wx.EXPAND, 10)
|
||||
button_sizer.Add((0, 0), 1, 0, 0)
|
||||
self.apply_button = wx.Button(self.palettes, wx.ID_ANY, _("Apply"))
|
||||
button_sizer.Add(self.apply_button, 0, wx.RIGHT, 10)
|
||||
self.Bind(wx.EVT_BUTTON, self.apply_button_clicked, self.apply_button)
|
||||
|
||||
self.help = wx.Panel(self.notebook, wx.ID_ANY)
|
||||
self.notebook.AddPage(self.help, _("Help"))
|
||||
|
||||
help_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
help_text = wx.StaticText(
|
||||
self.help,
|
||||
wx.ID_ANY,
|
||||
_("This extension applies nearest colors from chosen color palette to the elements in this document."),
|
||||
style=wx.ALIGN_LEFT
|
||||
)
|
||||
help_text.Wrap(500)
|
||||
help_sizer.Add(help_text, 0, wx.ALL, 8)
|
||||
|
||||
help_sizer.Add((20, 20), 0, 0, 0)
|
||||
|
||||
website_info = wx.StaticText(self.help, wx.ID_ANY, _("More information on our website:"))
|
||||
help_sizer.Add(website_info, 0, wx.ALL, 8)
|
||||
|
||||
self.website_link = wx.adv.HyperlinkCtrl(
|
||||
self.help,
|
||||
wx.ID_ANY,
|
||||
_("https://inkstitch.org/docs/thread-color/#apply-palette"),
|
||||
_("https://inkstitch.org/docs/thread-color/#apply-palette")
|
||||
)
|
||||
help_sizer.Add(self.website_link, 0, wx.ALL, 8)
|
||||
|
||||
self.help.SetSizer(help_sizer)
|
||||
self.palettes.SetSizer(palette_sizer)
|
||||
self.main_panel.SetSizer(notebook_sizer)
|
||||
|
||||
self.SetSizeHints(notebook_sizer.CalcMin())
|
||||
|
||||
self.Layout()
|
||||
|
||||
def apply_button_clicked(self, event):
|
||||
if self.apply_hook:
|
||||
self.apply_hook()
|
||||
self.Destroy()
|
||||
|
||||
|
||||
class ApplyPaletteApp(wx.App):
|
||||
def __init__(self):
|
||||
self.palette = None
|
||||
|
||||
app = wx.App()
|
||||
self.frame = ApplyPaletteFrame(
|
||||
title=_("Ink/Stitch"),
|
||||
on_apply=self.set_palette,
|
||||
)
|
||||
self.frame.Show()
|
||||
app.MainLoop()
|
||||
|
||||
def set_palette(self):
|
||||
if self.frame.palette_list.GetSelection() == -1:
|
||||
return
|
||||
self.palette = self.frame.palette_list.GetString(self.frame.palette_list.GetSelection())
|
||||
global_settings['last_applied_palette'] = self.palette
|
|
@ -4,12 +4,10 @@
|
|||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||
|
||||
import os
|
||||
import sys
|
||||
from collections.abc import Sequence
|
||||
from glob import glob
|
||||
from os.path import dirname, realpath
|
||||
|
||||
from ..utils import guess_inkscape_config_path
|
||||
from ..utils import get_bundled_dir, guess_inkscape_config_path
|
||||
from .palette import ThreadPalette
|
||||
|
||||
|
||||
|
@ -26,13 +24,8 @@ class _ThreadCatalog(Sequence):
|
|||
2. Palette directory of inkstitch
|
||||
"""
|
||||
path = [os.path.join(guess_inkscape_config_path(), 'palettes')]
|
||||
|
||||
if getattr(sys, 'frozen', None) is not None:
|
||||
inkstitch_path = os.path.join(sys._MEIPASS, "..")
|
||||
else:
|
||||
inkstitch_path = dirname(dirname(dirname(realpath(__file__))))
|
||||
|
||||
path.append(os.path.join(inkstitch_path, 'palettes'))
|
||||
inkstitch_path = get_bundled_dir('palettes')
|
||||
path.append(inkstitch_path)
|
||||
|
||||
return path
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from collections.abc import MutableMapping
|
||||
import json
|
||||
import os
|
||||
from collections.abc import MutableMapping
|
||||
|
||||
from .paths import get_user_dir
|
||||
|
||||
|
@ -15,7 +15,8 @@ DEFAULT_SETTINGS = {
|
|||
"cache_size": 100,
|
||||
"pop_out_simulator": False,
|
||||
"simulator_line_width": 0.1,
|
||||
"simulator_npp_size": 0.5
|
||||
"simulator_npp_size": 0.5,
|
||||
"last_applied_palette": ""
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,22 +3,7 @@
|
|||
<name>Apply Palette</name>
|
||||
<id>org.{{ id_inkstitch }}.apply_palette</id>
|
||||
<param name="extension" type="string" gui-hidden="true">apply_palette</param>
|
||||
<param name="tabs" type="notebook">
|
||||
<page name="options" gui-text="Options">
|
||||
<param name="palette" type="optiongroup" appearance="combo" gui-text="Select color palette">
|
||||
{%- for item in threadcatalog %}
|
||||
<item value="{{ item }}">{{ item }}</item>
|
||||
{%- endfor %}
|
||||
</param>
|
||||
</page>
|
||||
<page name="info" gui-text="Help">
|
||||
<label>This extension applies nearest colors from chosen color palette to the elements in this document.</label>
|
||||
<spacer />
|
||||
<label>Get more information on our website</label>
|
||||
<label appearance="url">https://inkstitch.org/docs/thread-color/#apply-palette</label>
|
||||
</page>
|
||||
</param>
|
||||
<effect>
|
||||
<effect implements-custom-gui="true" show-stderr="true">
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="{{ menu_inkstitch }}" translatable="no">
|
||||
|
|
Ładowanie…
Reference in New Issue