當前位置: 首頁>>代碼示例>>Python>>正文


Python objc.selector方法代碼示例

本文整理匯總了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) 
開發者ID:EDCD,項目名稱:EDMarketConnector,代碼行數:26,代碼來源:hotkey.py

示例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_) 
開發者ID:macadmins,項目名稱:nudge,代碼行數:16,代碼來源:nibbler.py

示例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)
    ) 
開發者ID:mass-immersion-approach,項目名稱:MIA-Dictionary-Addon,代碼行數:12,代碼來源:_callable_docstr.py

示例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) 
開發者ID:mass-immersion-approach,項目名稱:MIA-Dictionary-Addon,代碼行數:30,代碼來源:_callable_docstr.py

示例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)) 
開發者ID:mass-immersion-approach,項目名稱:MIA-Dictionary-Addon,代碼行數:30,代碼來源:_bridgesupport.py

示例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_) 
開發者ID:macadmins,項目名稱:nibbler,代碼行數:15,代碼來源:nibbler.py

示例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) 
開發者ID:mass-immersion-approach,項目名稱:MIA-Dictionary-Addon,代碼行數:54,代碼來源:_properties.py

示例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!') 
開發者ID:taizilongxu,項目名稱:douban.fm,代碼行數:48,代碼來源:notification.py


注:本文中的objc.selector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。