本文整理汇总了Python中objc.selector方法的典型用法代码示例。如果您正苦于以下问题:Python objc.selector方法的具体用法?Python objc.selector怎么用?Python objc.selector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类objc
的用法示例。
在下文中一共展示了objc.selector方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def register(self, root, keycode, modifiers):
self.root = root
self.keycode = keycode
self.modifiers = modifiers
self.activated = False
if keycode:
if not self.observer:
self.root.after_idle(self._observe)
self.root.after(HotkeyMgr.POLL, self._poll)
# Monkey-patch tk (tkMacOSXKeyEvent.c)
if not self.tkProcessKeyEvent_old:
sel = 'tkProcessKeyEvent:'
cls = NSApplication.sharedApplication().class__()
self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel)
newmethod = objc.selector(self.tkProcessKeyEvent, selector = self.tkProcessKeyEvent_old.selector, signature = self.tkProcessKeyEvent_old.signature)
objc.classAddMethod(cls, sel, newmethod)
# Monkey-patch tk (tkMacOSXKeyEvent.c) to:
# - workaround crash on OSX 10.9 & 10.10 on seeing a composing character
# - notice when modifier key state changes
# - keep a copy of NSEvent.charactersIgnoringModifiers, which is what we need for the hotkey
# (Would like to use a decorator but need to ensure the application is created before this is installed)
示例2: attach
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def attach(self, func, identifier_label):
# look up the object with the identifer provided
o = self.views[identifier_label]
# get the classname of the object and handle appropriately
o_class = o.className()
if o_class == 'NSButton':
# Wow, we actually know how to do this one
temp = func_to_controller_selector(func)
# hold onto it
self._attached.append(temp)
o.setTarget_(temp)
# button.setAction_(objc.selector(controller.buttonClicked_,
# signature='v@:'))
o.setAction_(temp.doTheThing_)
示例3: describe_callable
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def describe_callable(callable):
name = callable.__name__
try:
metadata = callable.__metadata__()
except objc.internal_error:
return None
return describe_callable_metadata(
name, metadata, ismethod=isinstance(callable, objc.selector)
)
示例4: callable_signature
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def callable_signature(callable):
# Create an inspect.Signature for an PyObjC callable
# both objc.function and objc.native_selector only support positional
# arguments, and not keyword arguments.
try:
metadata = callable.__metadata__()
except objc.internal_error:
# This can happen with some private methods with undocumented
# characters in type encodings
return None
ismethod = isinstance(callable, objc.selector)
if ismethod:
args = metadata["arguments"][
2:
] # Skip 'self' and 'selector' implicit arguments
else:
args = metadata["arguments"]
parameters = []
for idx, arg in enumerate(args):
p_name = "arg%d" % (idx,)
parameters.append(
inspect.Parameter(p_name, inspect.Parameter.POSITIONAL_ONLY)
)
return inspect.Signature(parameters)
示例5: do_informal_protocol
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def do_informal_protocol(self, node):
name = self.attribute_string(node, "name", None)
if not name:
return
method_list = []
for method in node:
sel_name = self.attribute_string(method, "selector", None)
typestr = self.attribute_string(method, "type", "type64")
is_class = self.attribute_bool(method, "classmethod", None, _SENTINEL)
if is_class is _SENTINEL:
# Manpage says 'class_method', older PyObjC used 'classmethod'
is_class = self.attribute_bool(method, "class_method", None, False)
if not sel_name or not typestr:
continue
typestr = self.typestr2typestr(typestr)
sel = objc.selector(
None,
selector=_as_bytes(sel_name),
signature=_as_bytes(typestr),
isClassMethod=is_class,
)
method_list.append(sel)
if method_list:
self.informal_protocols.append((name, method_list))
示例6: attach
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def attach(self, func, identifier_label):
# look up the object with the identifer provided
o = self.views[identifier_label]
# get the classname of the object and handle appropriately
o_class = o.className()
if o_class in ('NSButton', 'NSTextField', 'NSSecureTextField'):
# Wow, we actually know how to do this one
temp = func_to_controller_selector(func)
# hold onto it
self._attached.append(temp)
o.setTarget_(temp)
# button.setAction_(objc.selector(controller.buttonClicked_, signature='v@:'))
o.setAction_(temp.doTheThing_)
示例7: __pyobjc_class_setup__
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def __pyobjc_class_setup__(self, name, class_dict, instance_methods, class_methods):
super(array_property, self).__pyobjc_class_setup__(
name, class_dict, instance_methods, class_methods
)
# Insert (Mutable) Indexed Accessors
# FIXME: should only do the mutable bits when we're actually a mutable property
name = self._name
Name = name[0].upper() + name[1:]
countOf, objectIn, insert, remove, replace = makeArrayAccessors(self._name)
countOf = selector(
countOf,
selector=("countOf%s" % (Name,)).encode("latin1"),
signature=_C_NSUInteger + b"@:",
)
countOf.isHidden = True
instance_methods.add(countOf)
objectIn = selector(
objectIn,
selector=("objectIn%sAtIndex:" % (Name,)).encode("latin1"),
signature=b"@@:" + _C_NSUInteger,
)
objectIn.isHidden = True
instance_methods.add(objectIn)
insert = selector(
insert,
selector=("insertObject:in%sAtIndex:" % (Name,)).encode("latin1"),
signature=b"v@:@" + _C_NSUInteger,
)
insert.isHidden = True
instance_methods.add(insert)
remove = selector(
remove,
selector=("removeObjectFrom%sAtIndex:" % (Name,)).encode("latin1"),
signature=b"v@:" + _C_NSUInteger,
)
remove.isHidden = True
instance_methods.add(remove)
replace = selector(
replace,
selector=("replaceObjectIn%sAtIndex:withObject:" % (Name,)).encode("latin1"),
signature=b"v@:" + _C_NSUInteger + b"@",
)
replace.isHidden = True
instance_methods.add(replace)
示例8: send_OS_X_notify
# 需要导入模块: import objc [as 别名]
# 或者: from objc import selector [as 别名]
def send_OS_X_notify(title, content, img_path):
'''发送Mac桌面通知'''
try:
from Foundation import (
NSDate, NSUserNotification, NSUserNotificationCenter)
from AppKit import NSImage
import objc
except ImportError:
logger.info('failed to init OSX notify!')
return
def swizzle(cls, SEL, func):
old_IMP = getattr(cls, SEL, None)
if old_IMP is None:
old_IMP = cls.instanceMethodForSelector_(SEL)
def wrapper(self, *args, **kwargs):
return func(self, old_IMP, *args, **kwargs)
new_IMP = objc.selector(wrapper, selector=old_IMP.selector,
signature=old_IMP.signature)
objc.classAddMethod(cls, SEL.encode(), new_IMP)
def swizzled_bundleIdentifier(self, original):
# Use iTunes icon for notification
return 'com.apple.itunes'
swizzle(objc.lookUpClass('NSBundle'),
'bundleIdentifier',
swizzled_bundleIdentifier)
notification = NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setSubtitle_(content)
notification.setInformativeText_('')
notification.setUserInfo_({})
if img_path is not None:
image = NSImage.alloc().initWithContentsOfFile_(img_path)
# notification.setContentImage_(image)
notification.set_identityImage_(image)
notification.setDeliveryDate_(
NSDate.dateWithTimeInterval_sinceDate_(0, NSDate.date())
)
NSUserNotificationCenter.defaultUserNotificationCenter().\
scheduleNotification_(notification)
logger.info('send notify success!')