Package pycocoa :: Module nstypes
[frames] | no frames]

Module nstypes

ObjC classes NS... and conversions from NS... to Python and vice versa.


Version: 18.04.26

Classes
  CFStr
Python wrapper for the ObjC CFString class, creating retained instances, by default.
  NSDecimal
Optimized NSDecimalNumber class.
  NSStr
Python wrapper for the ObjC NSString class, creating auto-released instances, by default.
  at
Acronym for the Python wrapper of NSStr.
Functions
 
isNone(obj)
Return True if obj is nil, None, NSNone, etc.
 
nsArray2listuple(ns, ctype=<class 'ctypes.c_void_p'>)
Create a Python list or tuple from an NS[Mutable]Array.
 
nsBoolean2bool(ns, dflt=missing())
Create a Python bool from an NSBool[ean].
 
nsBundleRename(nsTitle, match='Python')
Change the bundle title if the current title matches.
 
nsData2bytes(ns, dflt='')
Create Python bytes from NSData.
 
nsDecimal2decimal(ns)
Create a Python Decimal from an NSDecimalNumber.
 
nsDictionary2dict(ns, ctype_keys=<class 'ctypes.c_void_p'>, ctype_vals=<class 'ctypes.c_void_p'>)
Create a Python dict from an NS[Mutable]Dictionary.
 
nsIter2(ns, reverse=False)
Iterate over an NS.. objects's (reverse) enumerator.
 
nsLog(fmt, *args)
Formatted write to the console.
 
nsNull2none(ns)
Return Python None for an NS/CFNull or nil.
 
nsNumber2num(ns, dflt=missing())
Create a Python Decimal, int or float from an NSNumber.
 
nsOf(inst)
Return the .NS object of a Python wrapper or Type instance.
 
nsSet2set(ns, ctype=<class 'ctypes.c_void_p'>)
Create a Python set or frozenset from an NS[Mutable]Set.
 
nsString2str(ns, dflt=None)
Create a Python str or unicode from an NS[Mutable]Str[ing].
 
ns2py(ns, dflt=None)
Convert (an instance of) an ObjC class to an instance of the equivalent Python standard type or wrapper and value.
 
ns2Type(ns)
Convert an NS/Instance object to an instance of the corresponding Python Type and value.
Variables
  NSApplication = ObjCClass('NSApplication')
  NSArray = ObjCClass('NSArray')
  NSAutoreleasePool = ObjCClass('NSAutoreleasePool')
  NSBezierPath = ObjCClass('NSBezierPath')
  NSBundle = ObjCClass('NSBundle')
  NSColor = ObjCClass('NSColor')
  NSConstantString = ObjCClass('NSConstantString')
  NSData = ObjCClass('NSData')
  NSDecimalNumber = ObjCClass('NSDecimalNumber')
  NSDictionary = ObjCClass('NSDictionary')
  NSDockTile = ObjCClass('NSDockTile')
  NSEnumerator = ObjCClass('NSEnumerator')
  NSFont = ObjCClass('NSFont')
  NSImage = ObjCClass('NSImage')
  NSMenu = ObjCClass('NSMenu')
  NSMenuItem = ObjCClass('NSMenuItem')
  NSMutableArray = ObjCClass('NSMutableArray')
  NSMutableData = ObjCClass('NSMutableData')
  NSMutableDictionary = ObjCClass('NSMutableDictionary')
  NSMutableSet = ObjCClass('NSMutableSet')
  NSMutableString = ObjCClass('NSMutableString')
  NSConcreteNotification = ObjCClass('NSConcreteNotification')
  NSNotification = ObjCClass('NSNotification')
  NSNull = ObjCClass('NSNull')
  NSNumber = ObjCClass('NSNumber')
  NSObject = ObjCClass('NSObject')
  NSOpenPanel = ObjCClass('NSOpenPanel')
  NSPageLayout = ObjCClass('NSPageLayout')
  NSPrinter = ObjCClass('NSPrinter')
  NSPrintInfo = ObjCClass('NSPrintInfo')
  NSPrintOperation = ObjCClass('NSPrintOperation')
  NSPrintPanel = ObjCClass('NSPrintPanel')
  NSSavePanel = ObjCClass('NSSavePanel')
  NSScreen = ObjCClass('NSScreen')
  NSScrollView = ObjCClass('NSScrollView')
  NSSet = ObjCClass('NSSet')
  NSStatusBar = ObjCClass('NSStatusBar')
  NSString = ObjCClass('NSString')
  NSTableColumn = ObjCClass('NSTableColumn')
  NSTableView = ObjCClass('NSTableView')
  NSTextField = ObjCClass('NSTextField')
  NSThread = ObjCClass('NSThread')
  NSURL = ObjCClass('NSURL')
  NSView = ObjCClass('NSView')
  NSWindow = ObjCClass('NSWindow')
  NSBool = NSNumber.numberWithBool_
  NSDouble = NSNumber.numberWithDouble_
  NSFalse = False
  NSFloat = NSNumber.numberWithDouble_
  NSInt = NSNumber.numberWithInt_
  NSLong = NSNumber.numberWithLong_
  NSLongLong = NSNumber.numberWithLongLong_
  NSnil = None
hash(x)
  NSNone = NSNone
  NSTrue = True
Function Details

isNone(obj)

 

Return True if obj is nil, None, NSNone, etc.

Parameters:
Returns:
True or False (bool).

nsArray2listuple(ns, ctype=<class 'ctypes.c_void_p'>)

 

Create a Python list or tuple from an NS[Mutable]Array.

Parameters:
  • ns - The NS[Mutable]Array (ObjCInstance).
  • ctype - The array item type (ctypes).
Returns:
The array (list or tuple).

nsBoolean2bool(ns, dflt=missing())

 

Create a Python bool from an NSBool[ean].

Parameters:
  • ns - The NSBool[ean] (ObjCInstance).
  • dflt - Default for missing, unobtainable value (missing).
Returns:
The bool (bool) of dlft.
Raises:
  • TypeError - Unexpected NumberType.

nsBundleRename(nsTitle, match='Python')

 

Change the bundle title if the current title matches.

Parameters:
  • nsTitle - New bundle title (NSStr).
  • match - Optional, previous title to match (str).
Returns:
The previous bundle title (str) or None.

Note: Useful to mimick NSApplication.setTitle_(nsTitle), the name of an App shown in the menu bar.

nsData2bytes(ns, dflt='')

 

Create Python bytes from NSData.

Parameters:
  • ns - The NSData (ObjCInstance).
  • dflt - Default for empty NSData (bytes).
Returns:
The bytes (bytes) or dflt.

nsDecimal2decimal(ns)

 

Create a Python Decimal from an NSDecimalNumber.

Parameters:
Returns:
The decimal (Decimal).
Raises:
  • ValueError - If ns not an NSNumber.

nsDictionary2dict(ns, ctype_keys=<class 'ctypes.c_void_p'>, ctype_vals=<class 'ctypes.c_void_p'>)

 

Create a Python dict from an NS[Mutable]Dictionary.

Parameters:
  • ns - The NSDictionary (ObjCInstance).
  • ctype_keys - The dictionay keys type (ctypes).
  • ctype_vals - The dictionay values type (ctypes).
Returns:
The dict (dict).

nsIter2(ns, reverse=False)

 

Iterate over an NS.. objects's (reverse) enumerator.

Parameters:
  • ns - The NS.. object to iterate over (ObjCInstance).
  • reverse - Reverse or forward order (bool).
Returns:
For each iteration, yield 2-Tuple (value, raw) where value is the value -a Python Type instance- and raw object.

nsLog(fmt, *args)

 

Formatted write to the console.

Parameters:
  • fmt - The printf-like format string (str).
  • args - Optional arguments to format (all positional).

nsNull2none(ns)

 

Return Python None for an NS/CFNull or nil.

Parameters:
Returns:
The singleton (None).
Raises:
  • ValueError - If ns not isNone.

nsNumber2num(ns, dflt=missing())

 

Create a Python Decimal, int or float from an NSNumber.

Parameters:
  • ns - The NSNumber (ObjCInstance).
  • dflt - Default for missing, unobtainable value (missing).
Returns:
The number (Decimal, int or float).
Raises:
  • TypeError - Unexpected NumberType.
  • ValueError - If ns not an NSNumber.

nsOf(inst)

 

Return the .NS object of a Python wrapper or Type instance.

Parameters:
Returns:
The .NS object (NS...).
Raises:
  • TypeError - No .NS for this inst.

nsSet2set(ns, ctype=<class 'ctypes.c_void_p'>)

 

Create a Python set or frozenset from an NS[Mutable]Set.

Parameters:
  • ns - The NS[Mutable]Set (ObjCInstance).
  • ctype - The set item type (ctypes).
Returns:
The set (set or frozenset).

nsString2str(ns, dflt=None)

 

Create a Python str or unicode from an NS[Mutable]Str[ing].

Parameters:
Returns:
The string (str or unicode) or dflt.

ns2py(ns, dflt=None)

 

Convert (an instance of) an ObjC class to an instance of the equivalent Python standard type or wrapper and value.

Parameters:
  • ns - The NS... (ObjCInstance).
  • dflt - Default for unhandled, unexpected NS...s (None).
Returns:
The value (Python type) or dflt.
Raises:
  • TypeError - Unhandled, unexpected TypeID.

Note: Conversion map:

  • NSArray -> tuple
  • NSBoolean -> bool
  • NSData -> bytes
  • NSDecimalNumber -> Decimal
  • NSDictionary -> dict
  • NSMutableArray -> list
  • NSMutableSet -> set
  • NSMutableString -> str
  • NSNumber -> int or float
  • NSNull -> None
  • NSSet -> frozenset
  • NSString -> str
  • NSStr/CFStr -> str

ns2Type(ns)

 

Convert an NS/Instance object to an instance of the corresponding Python Type and value.

Parameters:
Returns:
The value (Python Type).