Python objc.selector() Examples
The following are 10
code examples of objc.selector().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
objc
, or try the search function
.
Example #1
Source File: hotkey.py From EDMarketConnector with GNU General Public License v2.0 | 6 votes |
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)
Example #2
Source File: nibbler.py From nudge with Apache License 2.0 | 5 votes |
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_)
Example #3
Source File: nibbler.py From umad with Apache License 2.0 | 5 votes |
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_)
Example #4
Source File: _callable_docstr.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 5 votes |
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) )
Example #5
Source File: _callable_docstr.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: _bridgesupport.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 5 votes |
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))
Example #7
Source File: nibbler.py From nibbler with MIT License | 5 votes |
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_)
Example #8
Source File: nibbler.py From nibbler with MIT License | 5 votes |
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_)
Example #9
Source File: _properties.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 4 votes |
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)
Example #10
Source File: notification.py From douban.fm with MIT License | 4 votes |
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!')