diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/elements/auto_fill.py | 4 | ||||
| -rw-r--r-- | lib/elements/element.py | 10 | ||||
| -rw-r--r-- | lib/elements/fill.py | 5 | ||||
| -rw-r--r-- | lib/extensions/embroider.py | 2 | ||||
| -rw-r--r-- | lib/extensions/install.py | 11 | ||||
| -rw-r--r-- | lib/extensions/params.py | 55 | ||||
| -rw-r--r-- | lib/output.py | 10 | ||||
| -rw-r--r-- | lib/stitches/auto_fill.py | 3 | ||||
| -rw-r--r-- | lib/utils/paths.py | 7 |
9 files changed, 84 insertions, 23 deletions
diff --git a/lib/elements/auto_fill.py b/lib/elements/auto_fill.py index cfee6d7d..65b11fb1 100644 --- a/lib/elements/auto_fill.py +++ b/lib/elements/auto_fill.py @@ -8,7 +8,7 @@ from .fill import Fill class AutoFill(Fill): - element_name = _("Auto-Fill") + element_name = _("AutoFill") @property @param('auto_fill', _('Automatically routed fill stitching'), type='toggle', default=True) @@ -55,7 +55,7 @@ class AutoFill(Fill): def fill_underlay_angle(self): underlay_angle = self.get_float_param("fill_underlay_angle") - if underlay_angle: + if underlay_angle is not None: return math.radians(underlay_angle) else: return self.angle + math.pi / 2.0 diff --git a/lib/elements/element.py b/lib/elements/element.py index 4edb00c0..ec50ce22 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -197,7 +197,11 @@ class EmbroideryElement(object): # In a path, each element in the 3-tuple is itself a tuple of (x, y). # Tuples all the way down. Hasn't anyone heard of using classes? - return cubicsuperpath.parsePath(self.node.get("d")) + d = self.node.get("d", "") + if not d: + self.fatal(_("Object %(id)s has an empty 'd' attribute. Please delete this object from your document.") % dict(id=self.node.get("id"))) + + return cubicsuperpath.parsePath(d) @cache def parse_path(self): @@ -264,5 +268,7 @@ class EmbroideryElement(object): return patches def fatal(self, message): - print >> sys.stderr, "error:", message + # L10N used when showing an error message to the user such as "satin column: One or more of the rungs doesn't + # intersect both rails." + print >> sys.stderr, self.node.get("id") + ":", _("error:"), message sys.exit(1) diff --git a/lib/elements/fill.py b/lib/elements/fill.py index 626573e6..4156a24b 100644 --- a/lib/elements/fill.py +++ b/lib/elements/fill.py @@ -120,7 +120,10 @@ class Fill(EmbroideryElement): poly_ary.sort(key=lambda point_list: shgeo.Polygon(point_list).area, reverse=True) polygon = shgeo.MultiPolygon([(poly_ary[0], poly_ary[1:])]) - # print >> sys.stderr, "polygon valid:", polygon.is_valid + + if not polygon.is_valid: + self.fatal(_("shape is not valid. This can happen if the border crosses over itself.")) + return polygon def to_patches(self, last_patch): diff --git a/lib/extensions/embroider.py b/lib/extensions/embroider.py index 921201d6..7c8adfc9 100644 --- a/lib/extensions/embroider.py +++ b/lib/extensions/embroider.py @@ -39,7 +39,7 @@ class Embroider(InkstitchExtension): def get_output_path(self): if self.options.output_file: - output_path = os.path.join(self.options.path, self.options.output_file) + output_path = os.path.join(os.path.expanduser(os.path.expandvars(self.options.path)), self.options.output_file) else: csv_filename = '%s.%s' % (self.get_base_file_name(), self.options.output_format) output_path = os.path.join(self.options.path, csv_filename) diff --git a/lib/extensions/install.py b/lib/extensions/install.py index eb9f5289..c6dadd42 100644 --- a/lib/extensions/install.py +++ b/lib/extensions/install.py @@ -56,6 +56,13 @@ class InstallerFrame(wx.Frame): self.path_input.SetValue(dialog.GetPath()) def install_button_clicked(self, event): + if sys.platform == "win32": + # On windows, the default icon shows as a broken image. No idea + # why. Workaround: don't show an icon. + style = wx.ICON_NONE + else: + style = 0 + try: self.install_addons('palettes') self.install_addons('symbols') @@ -63,12 +70,12 @@ class InstallerFrame(wx.Frame): wx.MessageDialog(self, _('Inkscape add-on installation failed') + ': \n' + traceback.format_exc(), _('Installation Failed'), - wx.OK).ShowModal() + wx.OK | style).ShowModal() else: wx.MessageDialog(self, _('Inkscape add-on files have been installed. Please restart Inkscape to load the new add-ons.'), _('Installation Completed'), - wx.OK).ShowModal() + wx.OK | style).ShowModal() self.Destroy() diff --git a/lib/extensions/params.py b/lib/extensions/params.py index c464e044..6012263a 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -17,7 +17,7 @@ from .base import InkstitchExtension from ..i18n import _ from ..stitch_plan import patches_to_stitch_plan from ..elements import EmbroideryElement, Fill, AutoFill, Stroke, SatinColumn -from ..utils import save_stderr, restore_stderr +from ..utils import save_stderr, restore_stderr, get_resource_dir from ..simulator import EmbroiderySimulator from ..commands import is_command @@ -112,10 +112,14 @@ class ParamsTab(ScrolledPanel): else: self.toggle = None - self.settings_grid = wx.FlexGridSizer(rows=0, cols=3, hgap=10, vgap=10) - self.settings_grid.AddGrowableCol(0, 1) + self.param_change_indicators = {} + + self.settings_grid = wx.FlexGridSizer(rows=0, cols=4, hgap=10, vgap=15) + self.settings_grid.AddGrowableCol(1, 2) self.settings_grid.SetFlexibleDirection(wx.HORIZONTAL) + self.pencil_icon = wx.Image(os.path.join(get_resource_dir("icons"), "pencil_20x20.png")).ConvertToBitmap() + self.__set_properties() self.__do_layout() @@ -218,7 +222,11 @@ class ParamsTab(ScrolledPanel): self.on_change_hook = callable def changed(self, event): - self.changed_inputs.add(event.GetEventObject()) + input = event.GetEventObject() + self.changed_inputs.add(input) + + param = self.inputs_to_params[input] + self.enable_change_indicator(param) event.Skip() if self.on_change_hook: @@ -235,9 +243,7 @@ class ParamsTab(ScrolledPanel): self.update_toggle_state() def save_preset(self, storage): - preset = storage[self.name] = {} - for name, input in self.param_inputs.iteritems(): - preset[name] = input.GetValue() + storage[self.name] = self.get_values() def update_description(self): if len(self.nodes) == 1: @@ -297,13 +303,17 @@ class ParamsTab(ScrolledPanel): box.Add(sizer, proportion=0, flag=wx.ALL, border=5) if self.toggle: - box.Add(self.toggle_checkbox, proportion=0, flag=wx.BOTTOM, border=10) + toggle_sizer = wx.BoxSizer(wx.HORIZONTAL) + toggle_sizer.Add(self.create_change_indicator(self.toggle.name), proportion = 0, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border=5) + toggle_sizer.Add(self.toggle_checkbox, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) + box.Add(toggle_sizer, proportion=0, flag=wx.BOTTOM, border=10) for param in self.params: + self.settings_grid.Add(self.create_change_indicator(param.name), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) + description = wx.StaticText(self, label=param.description) description.SetToolTip(param.tooltip) - - self.settings_grid.Add(description, proportion=1, flag=wx.EXPAND|wx.RIGHT, border=40) + self.settings_grid.Add(description, proportion=1, flag=wx.EXPAND|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=5) if param.type == 'boolean': @@ -317,7 +327,7 @@ class ParamsTab(ScrolledPanel): input.Bind(wx.EVT_CHECKBOX, self.changed) elif len(param.values) > 1: - input = wx.ComboBox(self, wx.ID_ANY, choices=sorted(param.values), style=wx.CB_DROPDOWN) + input = wx.ComboBox(self, wx.ID_ANY, choices=sorted(str(value) for value in param.values), style=wx.CB_DROPDOWN) input.Bind(wx.EVT_COMBOBOX, self.changed) input.Bind(wx.EVT_TEXT, self.changed) else: @@ -327,14 +337,33 @@ class ParamsTab(ScrolledPanel): self.param_inputs[param.name] = input - self.settings_grid.Add(input, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL) + self.settings_grid.Add(input, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL|wx.EXPAND|wx.LEFT, border=40) self.settings_grid.Add(wx.StaticText(self, label=param.unit or ""), proportion=1, flag=wx.ALIGN_CENTER_VERTICAL) + self.inputs_to_params = {v: k for k, v in self.param_inputs.iteritems()} + box.Add(self.settings_grid, proportion=1, flag=wx.ALL, border=10) self.SetSizer(box) self.Layout() + def create_change_indicator(self, param): + indicator = wx.Button(self, style=wx.BORDER_NONE | wx.BU_NOTEXT, size=(28, 28)) + indicator.SetToolTip(_('Click to force this parameter to be saved when you click "Apply and Quit"')) + indicator.Bind(wx.EVT_BUTTON, lambda event: self.enable_change_indicator(param)) + + self.param_change_indicators[param] = indicator + return indicator + + def enable_change_indicator(self, param): + self.param_change_indicators[param].SetBitmapLabel(self.pencil_icon) + self.param_change_indicators[param].SetToolTip(_('This parameter will be saved when you click "Apply and Quit"')) + + self.changed_inputs.add(self.param_inputs[param]) + + if self.on_change_hook(): + self.on_change_hook(self) + # end of class SatinPane class SettingsFrame(wx.Frame): @@ -689,7 +718,7 @@ class Params(InkstitchExtension): getter = 'get_param' values = filter(lambda item: item is not None, - (getattr(node, getter)(param.name, str(param.default)) for node in nodes)) + (getattr(node, getter)(param.name, param.default) for node in nodes)) return values diff --git a/lib/output.py b/lib/output.py index d5c513e2..cf7895e8 100644 --- a/lib/output.py +++ b/lib/output.py @@ -1,6 +1,8 @@ +import sys import pyembroidery import simpletransform +from .i18n import _ from .utils import Point from .svg import PIXELS_PER_MM, get_doc_size, get_viewbox_transform from .commands import global_command @@ -84,4 +86,10 @@ def write_embroidery_file(file_path, stitch_plan, svg): "full_jump": True, } - pyembroidery.write(pattern, file_path, settings) + try: + pyembroidery.write(pattern, file_path, settings) + except IOError as e: + # L10N low-level file error. %(error)s is (hopefully?) translated by + # the user's system automatically. + print >> sys.stderr, _("Error writing to %(path)s: %(error)s") % dict(path=file_path, error=e.message) + sys.exit(1) diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py index e732c940..1660cd4e 100644 --- a/lib/stitches/auto_fill.py +++ b/lib/stitches/auto_fill.py @@ -472,7 +472,8 @@ def connect_points(shape, start, end, running_stitch_length, row_spacing): # most cases. 1.4 is chosen as approximately the length of the # stitch connecting two rows if the side of the shape is at a 45 # degree angle to the rows of stitches (sqrt(2)). - if abs(end_projection - start_projection) < row_spacing * 1.4: + direct_distance = abs(end_projection - start_projection) + if direct_distance < row_spacing * 1.4 and direct_distance < running_stitch_length: return [InkstitchPoint(end.x, end.y)] # The outline path has a "natural" starting point. Think of this as diff --git a/lib/utils/paths.py b/lib/utils/paths.py index 863e8e69..6dbaf13d 100644 --- a/lib/utils/paths.py +++ b/lib/utils/paths.py @@ -8,3 +8,10 @@ def get_bundled_dir(name): return realpath(os.path.join(sys._MEIPASS, "..", name)) else: return realpath(os.path.join(dirname(realpath(__file__)), '..', '..', name)) + + +def get_resource_dir(name): + if getattr(sys, 'frozen', None) is not None: + return realpath(os.path.join(sys._MEIPASS, name)) + else: + return realpath(os.path.join(dirname(realpath(__file__)), '..', '..', name)) |
