Exemplo n.º 1
0
def IBOutlet(name=None):
    """
    Create an instance variable that can be used as an outlet in
    Interface Builder.
    """
    if name is None:
        return ivar(isOutlet=1)
    else:
        return ivar(name, isOutlet=1)
Exemplo n.º 2
0
def IBOutlet(name=None):
    """
    Create an instance variable that can be used as an outlet in
    Interface Builder.
    """
    if name is None:
        return ivar(isOutlet=1)
    else:
        return ivar(name, isOutlet=1)
Exemplo n.º 3
0
def synthesize(name, copy=False, readwrite=True, type=_C_ID, ivarName=None):
    """
    Use this in a class dictionary to syntheze simple setting/setter methods.

    Note: this is only necessary to get propper behaviour when Key-Value coding
    is used and special features (like copying) are needed

    usage::
        
        class MyClass (NSObject):
            objc.synthesize('someTitle', copy=True)

    """
    if not name:
        raise ValueError("Empty property name")

    if ivarName is None:
        ivarName = "_" + name

    classDict = sys._getframe(1).f_locals

    setterName = "set%s%s_" % (name[0].upper(), name[1:])

    if copy:
        setter = textwrap.dedent(
            """
            def %(name)s(self, value):
                self.%(ivar)s = value.copy()
            """
            % dict(name=setterName, ivar=ivarName)
        )

    else:
        setter = textwrap.dedent(
            """
            def %(name)s(self, value):
                self.%(ivar)s = value
            """
            % dict(name=setterName, ivar=ivarName)
        )

    getter = textwrap.dedent(
        """
            def %(name)s(self):
                return self.%(ivar)s
            """
        % dict(name=name, ivar=ivarName)
    )

    if readwrite:
        exec setter in classDict

    exec getter in classDict

    classDict[ivarName] = ivar(type=type)
Exemplo n.º 4
0
def synthesize(name, copy=False, readwrite=True, type=_C_ID, ivarName=None):
    """
    Use this in a class dictionary to syntheze simple setting/setter methods.

    Note: this is only necessary to get propper behaviour when Key-Value coding
    is used and special features (like copying) are needed

    usage::
        
        class MyClass (NSObject):
            objc.synthesize('someTitle', copy=True)

    """
    if not name:
        raise ValueError("Empty property name")

    if ivarName is None:
        ivarName = '_' + name

    classDict = sys._getframe(1).f_locals

    setterName = 'set%s%s_' % (name[0].upper(), name[1:])

    if copy:
        setter = textwrap.dedent('''
            def %(name)s(self, value):
                self.%(ivar)s = value.copy()
            ''' % dict(name=setterName, ivar=ivarName))

    else:
        setter = textwrap.dedent('''
            def %(name)s(self, value):
                self.%(ivar)s = value
            ''' % dict(name=setterName, ivar=ivarName))

    getter = textwrap.dedent('''
            def %(name)s(self):
                return self.%(ivar)s
            ''' % dict(name=name, ivar=ivarName))

    if readwrite:
        exec setter in classDict

    exec getter in classDict

    classDict[ivarName] = ivar(type=type)
Exemplo n.º 5
0
def synthesize(name, copy=False, readwrite=True, type=_C_ID, ivarName=None):
    """
    Use this in a class dictionary to syntheze simple setting/setter methods.

    Note: this is only necessary to get propper behaviour when Key-Value coding
    is used and special features (like copying) are needed

    usage::
        
        class MyClass (NSObject):
            objc.synthesize('someTitle', copy=True)

    """
    if ivarName is None:
        ivarName = '_' + name

    classDict = sys._getframe(1).f_locals

    if copy:
        setter = textwrap.dedent('''
            def set%(name)s_(self, value):
                self.%(ivar)s = value.copy()
            ''' % dict(name=name.capitalize(), ivar=ivarName))

    else:
        setter = textwrap.dedent('''
            def set%(name)s_(self, value):
                self.%(ivar)s = value
            ''' % dict(name=name.capitalize(), ivar=ivarName))

    getter = textwrap.dedent('''
            def %(name)s(self):
                return self.%(ivar)s
            ''' % dict(name=name, ivar=ivarName))

    if readwrite:
        exec setter in classDict

    exec getter in classDict

    classDict[ivarName] = ivar(type=type)
Exemplo n.º 6
0
def IBOutlet(name):
    """
    Create an instance variable that can be used as an outlet in
    Interface Builder.
    """
    return ivar(name, isOutlet=1)