本文整理汇总了Python中Foundation.NSMutableDictionary.alloc方法的典型用法代码示例。如果您正苦于以下问题:Python NSMutableDictionary.alloc方法的具体用法?Python NSMutableDictionary.alloc怎么用?Python NSMutableDictionary.alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foundation.NSMutableDictionary
的用法示例。
在下文中一共展示了NSMutableDictionary.alloc方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def export(self, canvasname, file, format='pdf', force=False, is_checksum=False):
"""
Exports one canvas named {@code canvasname}
"""
format = format.lower()
chksum = None
if os.path.isfile(file) and not force:
existing_chksum = checksum(file) if format != 'pdf' \
else checksum_pdf(file)
new_chksum = self.compute_canvas_checksum(canvasname)
if existing_chksum == new_chksum and existing_chksum != None:
logging.debug('No exporting - canvas %s not changed' %
canvasname)
return False
else:
chksum = new_chksum
elif format == 'pdf':
chksum = self.compute_canvas_checksum(canvasname)
win = self.og.windows.first()
canvas = [c for c in self.doc.canvases() if c.name() == canvasname]
if len(canvas) == 1:
canvas = canvas[0]
else:
logging.warn('Canvas %s does not exist in %s' %
(canvasname, self.schemafile))
return False
self.og.set(win.canvas, to=canvas)
export_format = OmniGraffleSchema.EXPORT_FORMATS[format]
if (export_format == None):
self.doc.save(in_=file)
else:
self.doc.save(as_=export_format, in_=file)
if not is_checksum and self.options.verbose:
print "%s" % file
logging.debug("Exported `%s' into `%s' as %s" % (canvasname, file, format))
if format == 'pdf':
# save the checksum
url = NSURL.fileURLWithPath_(file)
pdfdoc = PDFKit.PDFDocument.alloc().initWithURL_(url)
attrs = NSMutableDictionary.alloc().initWithDictionary_(pdfdoc.documentAttributes())
attrs[PDFKit.PDFDocumentSubjectAttribute] = \
'%s%s' % (OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE, chksum)
pdfdoc.setDocumentAttributes_(attrs)
pdfdoc.writeToFile_(file)
return True
示例2: SetPathValue
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def SetPathValue(self, path, value):
"""Sets the path value for a given path."""
base = os.path.basename(path)
if not base:
raise SysconfigError('Updating %s not permitted.' % path)
tree = os.path.dirname(path)
settings = SCPreferencesPathGetValue(self.session, tree)
if not settings:
settings = NSMutableDictionary.alloc().init()
settings[base] = value
SCPreferencesPathSetValue(self.session, tree, settings)
示例3: _ns_update_attributed_title
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def _ns_update_attributed_title(self):
if self._color:
ns_button = self._ns_view
ns_attrs = NSMutableDictionary.alloc().init()
ns_attrs[NSFontAttributeName] = ns_button.font()
ns_attrs[NSForegroundColorAttributeName] = self._color._ns_color
ns_parstyle = NSMutableParagraphStyle.alloc().init()
ns_parstyle.setAlignment_(ns_button.alignment())
ns_attrs[NSParagraphStyleAttributeName] = ns_parstyle
ns_attstr = NSAttributedString.alloc().initWithString_attributes_(
ns_button.title(), ns_attrs)
ns_button.setAttributedTitle_(ns_attstr)
示例4: SetPlistKey
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def SetPlistKey(plist, key, value):
"""Sets the value for a given key in a plist.
Args:
plist: plist to operate on
key: key to change
value: value to set
Returns:
boolean: success
Raises:
MissingImportsError: if NSMutableDictionary is missing
"""
if NSMutableDictionary:
mach_info = NSMutableDictionary.dictionaryWithContentsOfFile_(plist)
if not mach_info:
mach_info = NSMutableDictionary.alloc().init()
mach_info[key] = value
return mach_info.writeToFile_atomically_(plist, True)
else:
raise MissingImportsError('NSMutableDictionary not imported successfully.')
示例5: main
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def main():
if len(sys.argv) != 4:
print("Usage: {} in.pdf out.pdf \"creator string\"".format(__file__))
sys.exit(1)
in_PDF = os.path.expanduser(sys.argv[1])
out_PDF = os.path.expanduser(sys.argv[2])
creator_str = sys.argv[3]
fn = os.path.expanduser(in_PDF)
url = NSURL.fileURLWithPath_(fn)
pdfdoc = PDFDocument.alloc().initWithURL_(url)
attrs = (NSMutableDictionary.alloc()
.initWithDictionary_(pdfdoc.documentAttributes()))
attrs[PDFDocumentCreatorAttribute] = creator_str
pdfdoc.setDocumentAttributes_(attrs)
pdfdoc.writeToFile_(out_PDF)
示例6: export_one
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def export_one(schema, filename, canvasname, format='pdf', force=False):
def _checksum(filepath):
assert os.path.isfile(filepath), '%s is not a file' % filepath
c = hashlib.md5()
with open(filepath, 'rb') as f:
for chunk in iter(lambda: f.read(128), ''):
c.update(chunk)
return c.hexdigest()
def _checksum_pdf(filepath):
assert os.path.isfile(filepath), '%s is not a file' % filepath
url = NSURL.fileURLWithPath_(filepath)
pdfdoc = PDFKit.PDFDocument.alloc().initWithURL_(url)
assert pdfdoc != None
chsum = None
attrs = pdfdoc.documentAttributes()
if PDFKit.PDFDocumentSubjectAttribute in attrs:
chksum = pdfdoc.documentAttributes()[PDFKit.PDFDocumentSubjectAttribute]
else:
return None
if not chksum.startswith(OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE):
return None
else:
return chksum[len(OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE):]
def _compute_canvas_checksum(canvasname):
tmpfile = tempfile.mkstemp(suffix='.png')[1]
os.unlink(tmpfile)
export_one(schema, tmpfile, canvasname, 'png')
try:
chksum = _checksum(tmpfile)
return chksum
finally:
os.unlink(tmpfile)
# checksum
chksum = None
if os.path.isfile(filename) and not force:
existing_chksum = _checksum(filename) if format != 'pdf' \
else _checksum_pdf(filename)
new_chksum = _compute_canvas_checksum(canvasname)
if existing_chksum == new_chksum and existing_chksum != None:
logging.debug(
'Not exporting `%s` into `%s` as `%s` - canvas has not been changed' % (canvasname, filename, format))
return False
else:
chksum = new_chksum
elif format == 'pdf':
chksum = _compute_canvas_checksum(canvasname)
try:
schema.export(canvasname, filename, format=format)
except RuntimeError as e:
print >> sys.stderr, e.message
return False
# update checksum
if format == 'pdf':
# save the checksum
url = NSURL.fileURLWithPath_(filename)
pdfdoc = PDFKit.PDFDocument.alloc().initWithURL_(url)
attrs = NSMutableDictionary.alloc().initWithDictionary_(pdfdoc.documentAttributes())
attrs[PDFKit.PDFDocumentSubjectAttribute] = \
'%s%s' % (OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE, chksum)
pdfdoc.setDocumentAttributes_(attrs)
pdfdoc.writeToFile_(filename)
return True
示例7: export
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def export(self, canvasname, filename, format='pdf', force=False):
"""
Exports one canvas named {@code canvasname}
"""
# canvas name
if not canvasname or len(canvasname) == 0:
raise Exception('canvasname is missing')
logging.debug('Exporting canvas: %s ' % canvasname)
# format
if not format or len(format) == 0:
format = 'pdf'
else:
format = format.lower()
if format not in OmniGraffleSchema.EXPORT_FORMATS:
raise Exception('Unknown format: %s' % format)
logging.debug('Exporting into format: %s ' % format)
filename = os.path.abspath(filename)
# suffix
if filename[filename.rfind('.')+1:].lower() != format:
filename = '%s.%s' % (filename, format)
logging.debug('Exporting into: %s ' % filename)
# checksum
chksum = None
if os.path.isfile(filename) and not force:
existing_chksum = checksum(filename) if format != 'pdf' \
else checksum_pdf(filename)
new_chksum = self.compute_canvas_checksum(canvasname)
if existing_chksum == new_chksum and existing_chksum != None:
logging.debug('No exporting - canvas %s not changed' %
canvasname)
return False
else:
chksum = new_chksum
elif format == 'pdf':
chksum = self.compute_canvas_checksum(canvasname)
if self._export_internal(canvasname, filename, format):
if self.verbose:
print "%s" % filename
else:
print >> sys.stderr, 'Failed to export canvas: %s to %s' % \
(canvasname, filename)
# update checksum
if format == 'pdf':
# save the checksum
url = NSURL.fileURLWithPath_(filename)
pdfdoc = PDFKit.PDFDocument.alloc().initWithURL_(url)
attrs = NSMutableDictionary.alloc().initWithDictionary_(
pdfdoc.documentAttributes())
attrs[PDFKit.PDFDocumentSubjectAttribute] = \
'%s%s' % (OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE, chksum)
pdfdoc.setDocumentAttributes_(attrs)
pdfdoc.writeToFile_(filename)
return True
示例8: __init__
# 需要导入模块: from Foundation import NSMutableDictionary [as 别名]
# 或者: from Foundation.NSMutableDictionary import alloc [as 别名]
def __init__(self):
self.id = "com.apple.sidebarlists"
self.favoriteservers = NSMutableDictionary.alloc().initWithDictionary_copyItems_(CoreFoundation.CFPreferencesCopyAppValue("favoriteservers", self.id), True)
self.items = NSMutableArray.alloc().initWithArray_(self.favoriteservers["CustomListItems"] if self.favoriteservers.get("CustomListItems") else list())
self.labels = [item["Name"] for item in self.items]