本文整理汇总了Python中PathScripts.PathUtil.toUnicode方法的典型用法代码示例。如果您正苦于以下问题:Python PathUtil.toUnicode方法的具体用法?Python PathUtil.toUnicode怎么用?Python PathUtil.toUnicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathScripts.PathUtil
的用法示例。
在下文中一共展示了PathUtil.toUnicode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from PathScripts import PathUtil [as 别名]
# 或者: from PathScripts.PathUtil import toUnicode [as 别名]
def read(self, filename, listname):
"imports a tooltable from a file"
try:
fileExtension = os.path.splitext(filename[0])[1].lower()
xmlHandler = None
if fileExtension == '.tooltable':
xmlHandler = HeeksTooltableHandler()
if fileExtension == '.xml':
xmlHandler = FreeCADTooltableHandler()
if xmlHandler:
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_namespaces, 0)
parser.setContentHandler(xmlHandler)
parser.parse(PathUtil.toUnicode(filename[0]))
if not xmlHandler.tooltable:
return None
ht = xmlHandler.tooltable
else:
with open(PathUtil.toUnicode(filename[0]), "rb") as fp:
ht = self.tooltableFromAttrs(json.load(fp))
tt = self._findList(listname)
for t in ht.Tools:
newt = ht.getTool(t).copy()
tt.addTools(newt)
if listname == "<Main>":
self.saveMainLibrary(tt)
return True
except Exception as e:
print("could not parse file", e)
示例2: write
# 需要导入模块: from PathScripts import PathUtil [as 别名]
# 或者: from PathScripts.PathUtil import toUnicode [as 别名]
def write(self, filename, listname):
"exports the tooltable to a file"
tt = self._findList(listname)
if tt:
try:
def openFileWithExtension(name, ext):
fext = os.path.splitext(name)[1].lower()
if fext != ext:
name = "{}{}".format(name, ext)
return (open(PathUtil.toUnicode(name), 'wb'), name)
if filename[1] == self.TooltableTypeXML:
fp,fname = openFileWithExtension(filename[0], '.xml')
fp.write('<?xml version="1.0" encoding="UTF-8"?>\n')
fp.write(tt.Content)
elif filename[1] == self.TooltableTypeLinuxCNC:
fp,fname = openFileWithExtension(filename[0], '.tbl')
for key in tt.Tools:
t = tt.Tools[key]
fp.write("T{} P{} Y{} Z{} A{} B{} C{} U{} V{} W{} D{} I{} J{} Q{} ;{}\n".format(key,key,0,t.LengthOffset,0,0,0,0,0,0,t.Diameter,0,0,0,t.Name))
else:
fp,fname = openFileWithExtension(filename[0], '.json')
json.dump(self.templateAttrs(tt), fp, sort_keys=True, indent=2)
fp.close()
print("Written ", PathUtil.toUnicode(fname))
except Exception as e:
print("Could not write file:", e)
示例3: setFromTemplateFile
# 需要导入模块: from PathScripts import PathUtil [as 别名]
# 或者: from PathScripts.PathUtil import toUnicode [as 别名]
def setFromTemplateFile(self, obj, template):
'''setFromTemplateFile(obj, template) ... extract the properties from the given template file and assign to receiver.
This will also create any TCs stored in the template.'''
tcs = []
if template:
with open(PathUtil.toUnicode(template), 'rb') as fp:
attrs = json.load(fp)
if attrs.get(JobTemplate.Version) and 1 == int(attrs[JobTemplate.Version]):
attrs = self.setupSheet.decodeTemplateAttributes(attrs)
if attrs.get(JobTemplate.SetupSheet):
self.setupSheet.setFromTemplate(attrs[JobTemplate.SetupSheet])
if attrs.get(JobTemplate.GeometryTolerance):
obj.GeometryTolerance = float(attrs.get(JobTemplate.GeometryTolerance))
if attrs.get(JobTemplate.PostProcessor):
obj.PostProcessor = attrs.get(JobTemplate.PostProcessor)
if attrs.get(JobTemplate.PostProcessorArgs):
obj.PostProcessorArgs = attrs.get(JobTemplate.PostProcessorArgs)
else:
obj.PostProcessorArgs = ''
if attrs.get(JobTemplate.PostProcessorOutputFile):
obj.PostProcessorOutputFile = attrs.get(JobTemplate.PostProcessorOutputFile)
if attrs.get(JobTemplate.Description):
obj.Description = attrs.get(JobTemplate.Description)
if attrs.get(JobTemplate.ToolController):
for tc in attrs.get(JobTemplate.ToolController):
tcs.append(PathToolController.FromTemplate(tc))
if attrs.get(JobTemplate.Stock):
obj.Stock = PathStock.CreateFromTemplate(obj, attrs.get(JobTemplate.Stock))
PathLog.debug("setting tool controllers (%d)" % len(tcs))
obj.ToolController = tcs
else:
PathLog.error(translate('PathJob', "Unsupported PathJob template version %s") % attrs.get(JobTemplate.Version))
if not tcs:
self.addToolController(PathToolController.Create())
示例4: Execute
# 需要导入模块: from PathScripts import PathUtil [as 别名]
# 或者: from PathScripts.PathUtil import toUnicode [as 别名]
def Execute(cls, job, path, dialog=None):
attrs = job.Proxy.templateAttrs(job)
# post processor settings
if dialog and not dialog.includePostProcessing():
attrs.pop(PathJob.JobTemplate.PostProcessor, None)
attrs.pop(PathJob.JobTemplate.PostProcessorArgs, None)
attrs.pop(PathJob.JobTemplate.PostProcessorOutputFile, None)
# tool controller settings
toolControllers = dialog.includeToolControllers() if dialog else job.ToolController
if toolControllers:
tcAttrs = [tc.Proxy.templateAttrs(tc) for tc in toolControllers]
attrs[PathJob.JobTemplate.ToolController] = tcAttrs
# stock settings
stockAttrs = None
if dialog:
if dialog.includeStock():
stockAttrs = PathStock.TemplateAttributes(job.Stock, dialog.includeStockExtent(), dialog.includeStockPlacement())
else:
stockAttrs = PathStock.TemplateAttributes(job.Stock)
if stockAttrs:
attrs[PathJob.JobTemplate.Stock] = stockAttrs
# setup sheet
setupSheetAttrs = None
if dialog:
setupSheetAttrs = job.Proxy.setupSheet.templateAttributes(dialog.includeSettingToolRapid(), dialog.includeSettingOperationHeights(), dialog.includeSettingOperationDepths(), dialog.includeSettingOpsSettings())
else:
setupSheetAttrs = job.Proxy.setupSheet.templateAttributes(True, True, True)
if setupSheetAttrs:
attrs[PathJob.JobTemplate.SetupSheet] = setupSheetAttrs
encoded = job.Proxy.setupSheet.encodeTemplateAttributes(attrs)
# write template
with open(PathUtil.toUnicode(path), 'wb') as fp:
json.dump(encoded, fp, sort_keys=True, indent=2)
示例5: openFileWithExtension
# 需要导入模块: from PathScripts import PathUtil [as 别名]
# 或者: from PathScripts.PathUtil import toUnicode [as 别名]
def openFileWithExtension(name, ext):
fext = os.path.splitext(name)[1].lower()
if fext != ext:
name = "{}{}".format(name, ext)
return (open(PathUtil.toUnicode(name), 'wb'), name)
示例6: decodeAttributeString
# 需要导入模块: from PathScripts import PathUtil [as 别名]
# 或者: from PathScripts.PathUtil import toUnicode [as 别名]
def decodeAttributeString(self, attr):
'''decodeAttributeString(attr) ... return the decoded string of a template attribute.'''
return PathUtil.toUnicode(attr.replace(self.TemplateReference, self.expressionReference()))