本文整理汇总了Python中Foundation.NSMutableDictionary类的典型用法代码示例。如果您正苦于以下问题:Python NSMutableDictionary类的具体用法?Python NSMutableDictionary怎么用?Python NSMutableDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NSMutableDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fixSpotlight
def fixSpotlight ():
DISABLED_ITEMS=set(["MENU_WEBSEARCH", "MENU_SPOTLIGHT_SUGGESTIONS", "OTHER", "BOOKMARKS", "MESSAGES"])
REQUIRED_ITEM_KEYS=set(["enabled", "name"])
BUNDLE_ID="com.apple.Spotlight"
PREF_NAME="orderedItems"
DEFAULT_VALUE=[
{'enabled' : True, 'name' : 'APPLICATIONS'},
{'enabled' : False, 'name' : 'MENU_SPOTLIGHT_SUGGESTIONS'},
{'enabled' : True, 'name' : 'MENU_CONVERSION'},
{'enabled' : True, 'name' : 'MENU_EXPRESSION'},
{'enabled' : True, 'name' : 'MENU_DEFINITION'},
{'enabled' : True, 'name' : 'SYSTEM_PREFS'},
{'enabled' : True, 'name' : 'DOCUMENTS'},
{'enabled' : True, 'name' : 'DIRECTORIES'},
{'enabled' : True, 'name' : 'PRESENTATIONS'},
{'enabled' : True, 'name' : 'SPREADSHEETS'},
{'enabled' : True, 'name' : 'PDF'},
{'enabled' : False, 'name' : 'MESSAGES'},
{'enabled' : True, 'name' : 'CONTACT'},
{'enabled' : True, 'name' : 'EVENT_TODO'},
{'enabled' : True, 'name' : 'IMAGES'},
{'enabled' : False, 'name' : 'BOOKMARKS'},
{'enabled' : True, 'name' : 'MUSIC'},
{'enabled' : True, 'name' : 'MOVIES'},
{'enabled' : True, 'name' : 'FONTS'},
{'enabled' : False, 'name' : 'MENU_OTHER'},
{'enabled' : False, 'name' : 'MENU_WEBSEARCH'}
]
items = CFPreferencesCopyValue(PREF_NAME, BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
newItems = None
if items is None or len(items) is 0:
# Actual preference values are populated on demand; if the user
# hasn't previously configured Spotlight, the preference value
# will be unavailable
newItems = DEFAULT_VALUE
else:
newItems = NSMutableArray.new()
for item in items:
print item['name']
missing_keys = []
for key in REQUIRED_ITEM_KEYS:
if not item.has_key(key):
missing_keys.append(key)
if len(missing_keys) != 0:
print "Preference item %s is missing expected keys (%s), skipping" % (item, missing_keys)
newItems.append(item)
continue
if item["name"] not in DISABLED_ITEMS:
newItems.append(item)
continue
newItem = NSMutableDictionary.dictionaryWithDictionary_(item)
newItem.setObject_forKey_(0, "enabled")
newItems.append(newItem)
CFPreferencesSetValue(PREF_NAME, newItems, BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
CFPreferencesSynchronize(BUNDLE_ID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
示例2: change_bundle_id
def change_bundle_id(filename, new_bundle_id):
keyToModify = 'CFBundleIdentifier'
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(filename)
if plist != None and keyToModify in plist.allKeys():
plist[keyToModify] = new_bundle_id
plist.writeToFile_atomically_(filename, 1)
示例3: testFunctions
def testFunctions(self):
ref = SCPreferencesCreate(None, "pyobjc.test", "pyobjc.test")
self.assertIsInstance(ref, SCPreferencesRef)
r = SCPreferencesAddValue(ref, "use",
NSMutableDictionary.dictionaryWithDictionary_(
{ "python2": True, "python3": False }))
self.assertTrue(r)
v = SCPreferencesPathCreateUniqueChild(ref, "/")
self.assertIsInstance(v, unicode)
v = SCPreferencesPathGetValue(ref, "/use")
self.assertIsInstance(v, NSDictionary)
v = SCPreferencesPathSetValue(ref, "/use", dict(python2=True, python3=True))
self.assertTrue(v is True)
v = SCPreferencesPathSetLink(ref, "/use_python", "/use")
self.assertTrue(v is True)
v = SCPreferencesPathGetLink(ref, "/use_python")
self.assertEqual(v, "/use")
v = SCPreferencesPathRemoveValue(ref, "/use")
self.assertTrue(v is True)
示例4: initialize
def initialize(self):
paraStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy()
paraStyle.setAlignment_(NSCenterTextAlignment)
self.badgeAttributes = NSMutableDictionary.dictionaryWithObjectsAndKeys_(NSFont.boldSystemFontOfSize_(8),
NSFontAttributeName, NSColor.whiteColor(), NSForegroundColorAttributeName,
paraStyle, NSParagraphStyleAttributeName)
示例5: export
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
示例6: get_version
def get_version(self, dry=False):
info = Folder(self.app.path).child('Contents/Info.plist')
if not File(info).exists:
self.fail("InfoPlist not found at :" + info)
from Foundation import NSMutableDictionary
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info)
self.app.build_version = plist['CFBundleVersion']
self.app.marketing_version = plist.get('CFBundleShortVersionString', self.app.build_version)
示例7: _common_init
def _common_init(self):
"""_common_init"""
self.userNS = NSMutableDictionary.dictionary()
self.waitingForEngine = False
self.lines = {}
self.tabSpaces = 4
self.tabUsesSpaces = True
self.currentBlockID = self.next_block_ID()
self.blockRanges = {} # blockID=>CellBlock
示例8: SetPathValue
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)
示例9: SetPlistKey
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.')
示例10: increment_release_version
def increment_release_version(filename, version):
keyToModify = 'CFBundleVersion'
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(filename)
if keyToModify in plist.allKeys():
versionString = plist[keyToModify]
versionList = versionString.split(".")
versionList.append(version)
versionString = ".".join(versionList)
plist[keyToModify] = versionString
plist.writeToFile_atomically_(filename, 1)
return versionString
示例11: _ns_update_attributed_title
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)
示例12: userNotificationCenter_didActivateNotification_
def userNotificationCenter_didActivateNotification_(
self, center: NSUserNotificationCenter, notification: NSMutableDictionary
) -> None:
info = notification.userInfo()
if info and "uuid" not in info:
return
notifications = self._manager.notification_service.get_notifications()
if (
info["uuid"] not in notifications
or notifications[info["uuid"]].is_discard_on_trigger()
):
center.removeDeliveredNotification_(notification)
self._manager.notification_service.trigger_notification(info["uuid"])
示例13: increment_development_version
def increment_development_version(filename, version):
keyToModify = 'CFBundleShortVersionString'
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(filename)
if keyToModify in plist.allKeys():
versionString = plist[keyToModify]
versionList = versionString.split(".")
lastVersionNumber = int(versionList[-1])
versionList.append(version)
versionString = ".".join(versionList)
plist[keyToModify] = versionString
plist.writeToFile_atomically_(filename, 1)
return versionString
示例14: getItemView
def getItemView(self):
array = NSMutableArray.array()
context = NSMutableDictionary.dictionary()
context.setObject_forKey_(self, NSNibOwner)
context.setObject_forKey_(array, NSNibTopLevelObjects)
path = NSBundle.mainBundle().pathForResource_ofType_("AlertPanelView", "nib")
if not NSBundle.loadNibFile_externalNameTable_withZone_(path, context, self.zone()):
raise RuntimeError("Internal Error. Could not find AlertPanelView.nib")
for obj in array:
if isinstance(obj, NSBox):
return obj
else:
raise RuntimeError("Internal Error. Could not find NSBox in AlertPanelView.nib")
示例15: change_provisioning_profile
def change_provisioning_profile(filename, build_conf_name, provisioning_profile):
pbx_dict = NSMutableDictionary.dictionaryWithContentsOfFile_(filename)
configurations = [x for x in pbx_dict['objects'] if pbx_dict['objects'][x]['isa'] == "XCBuildConfiguration" and pbx_dict['objects'][x]['name'] == "Release" and "PROVISIONING_PROFILE" in pbx_dict['objects'][x]['buildSettings'].allKeys()]
profiles_to_replace = []
for config in configurations:
profiles_to_replace.append(pbx_dict['objects'][config]['buildSettings']['PROVISIONING_PROFILE'])
profiles_to_replace.append(pbx_dict['objects'][config]['buildSettings']['PROVISIONING_PROFILE[sdk=iphoneos*]'])
for profile in profiles_to_replace:
print "%s was replaced with %s in %s" % (profile, provisioning_profile, filename)
replace(filename, profile, provisioning_profile)