def command_output(self, values): out_path = [] v = self.v() while v is not None: out_path.append(v) v = self.v() for value in values: if not isinstance(value, tuple): continue pattern = value[0] filename = value[1] settings = value[2] for path in out_path: path = formatted_string(path, pattern, filename) ext_split = os.path.splitext(path) name = ext_split[0] ext = ext_split[1] if '*' in name: filename_suffix = os.path.split(filename)[1] name = name.replace('*', filename_suffix) if ext == "" or ext == ".*": for file_type in pyembroidery.supported_formats(): if 'writer' in file_type: out_file = name + '.' + file_type['extension'] self.log("Saving:", out_file) pyembroidery.write_embroidery(file_type['writer'], pattern, out_file, settings) else: self.log("Saving:", name + ext) pyembroidery.write(pattern, name + ext, settings) return []
def __init__(self, *args, **kwargs): InkstitchExtension.__init__(self) self.OptionParser.add_option("-c", "--collapse_len_mm", action="store", type="float", dest="collapse_length_mm", default=3.0, help="max collapse length (mm)") # it's kind of obnoxious that I have to do this... self.formats = [] for format in pyembroidery.supported_formats(): if 'writer' in format and format['category'] == 'embroidery': extension = format['extension'] self.OptionParser.add_option('--format-%s' % extension, type="inkbool", dest=extension) self.formats.append(extension) self.OptionParser.add_option('--format-svg', type="inkbool", dest='svg') self.OptionParser.add_option('--format-threadlist', type="inkbool", dest='threadlist') self.formats.append('svg') self.formats.append('threadlist')
def pyembroidery_output_formats(): for format in pyembroidery.supported_formats(): if 'writer' in format: description = format['description'] if format['category'] != "embroidery": description = "%s [DEBUG]" % description yield format['extension'], description, format['mimetype'], format['category']
def on_menu_export(self, event): page = self.main_notebook.GetCurrentPage() if not isinstance(page, EmbroideryView) or page.emb_pattern is None: return files = "" for format in pyembroidery.supported_formats(): try: if format["writer"] is not None: files += format["description"] + "(*." + format[ "extension"] + ")|*." + format["extension"] + "|" except KeyError: pass with wx.FileDialog(self, "Save Embroidery", wildcard=files[:-1], style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind # save the current contents in the file pathname = fileDialog.GetPath() pyembroidery.write(page.emb_pattern, str(pathname))
def on_menu_import(self, event): files = "" for format in pyembroidery.supported_formats(): try: if format["reader"] is not None: files += "*." + format["extension"] + ";" except KeyError: pass with wx.FileDialog(self, "Open Embroidery", wildcard="Embroidery Files (" + files + ")", style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind pathname = fileDialog.GetPath() self.read_file(pathname)
def __init__(self, *args, **kwargs): InkstitchExtension.__init__(self) # it's kind of obnoxious that I have to do this... self.formats = [] for format in pyembroidery.supported_formats(): if 'writer' in format and format['category'] == 'embroidery': extension = format['extension'] self.arg_parser.add_argument('--format-%s' % extension, type=Boolean, dest=extension) self.formats.append(extension) self.arg_parser.add_argument('--format-svg', type=Boolean, dest='svg') self.arg_parser.add_argument('--format-threadlist', type=Boolean, dest='threadlist') self.formats.append('svg') self.formats.append('threadlist')
def on_menu_import(self, event): files = "" for format in pyembroidery.supported_formats(): try: if format["reader"] is not None and format[ "category"] == "stitch": files += "*." + format["extension"] + ";" except KeyError: pass with wx.FileDialog(self, "Open Stitch", wildcard=files[:-1], style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind pathname = fileDialog.GetPath() self.stitch_panel.load(str(pathname))
def on_menu_export(self, event): files = "" for format in pyembroidery.supported_formats(): try: if format["writer"] is not None and format[ "category"] == "stitch": files += format["description"] + "(*." + format[ "extension"] + ")|*." + format["extension"] + "|" except KeyError: pass with wx.FileDialog(self, "Save Stitch", wildcard=files[:-1], style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind # save the current contents in the file pathname = fileDialog.GetPath() pyembroidery.write(self.stitch_panel.emb_pattern, str(pathname))
def pyembroidery_debug_formats(): for format in pyembroidery.supported_formats(): if 'writer' in format and format['category'] != 'embroidery': yield format['extension'], format['description']
def RunScript(self, Pattern, FilePath, Execute): # check supported formats supported = [d["extension"] for d in pyembroidery.supported_formats()] supported = ["." + ext for ext in supported] supported = {ext: True for ext in supported} # verify pattern and filepaths if Pattern and FilePath: # make info message if len(Pattern) > len(FilePath): rml = self.RuntimeMessageLevel.Remark imsg = ("List of supplied filepaths does not suffice. " + "Additional filepaths will be constructed based on " + "the last one to write all patterns!") self.AddRuntimeMessage(rml, imsg) # loop over patterns and verify/construct filepaths for i, pat in enumerate(Pattern): # if there is a valid supplied filepath if i <= len(FilePath) - 1: # normalize path and get extension fp = path.normpath(FilePath[i].strip("\n\r")) ext = path.splitext(fp)[1] # if format in not supported, add warning if ext not in supported: rml = self.RuntimeMessageLevel.Warning errMsg = ("Format with extension '{}' is not a " + "supported file format! Please check the " + "description for a list of supported " + "formats. This pattern will not be written!") errMsg = errMsg.format(ext) self.AddRuntimeMessage(rml, errMsg) continue else: fp = path.normpath(FilePath[-1].strip("\n\r")) fp, ext = path.splitext(fp) # if format in not supported, add warning if ext not in supported: rml = self.RuntimeMessageLevel.Warning errMsg = ("Format with extension '{}' is not a " + "supported file format! Please check the " + "description for a list of supported " + "formats. This pattern will not be written!") errMsg = errMsg.format(ext) self.AddRuntimeMessage(rml, errMsg) continue # alter filepath to avoid overwriting original files fp = fp + " ({})" fp = fp.format(i - len(FilePath) + 1) + ext # write on execute if Execute: pyembroidery.write(pat, fp) else: rml = self.RuntimeMessageLevel.Warning if not Pattern: errMsg = "Input Pattern failed to collect data!" self.AddRuntimeMessage(rml, errMsg) if not FilePath: errMsg = "Input FilePath failed to collect data!" self.AddRuntimeMessage(rml, errMsg)
def pyembroidery_input_formats(): for format in pyembroidery.supported_formats(): if 'reader' in format and format['category'] == 'embroidery': yield format['extension'], format['description']