chef/cookbooks/cpe_nudge/files/nudge-python/resources/nibbler.py [16:86]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class ProcessSerialNumber(Structure):
    _fields_ = [('highLongOfPSN', c_uint32), ('lowLongOfPSN',  c_uint32)]


kCurrentProcess = 2
kProcessTransformToForegroundApplication = 1
kProcessTransformToUIElementAppication = 4
ApplicationServices = CDLL(find_library('ApplicationServices'))
TransformProcessType = ApplicationServices.TransformProcessType
TransformProcessType.argtypes = [POINTER(ProcessSerialNumber), c_uint32]


def views_recursive(view_obj):
    yield view_obj
    for x in view_obj.subviews():
        for y in views_recursive(x):
            yield y


def views_dict(nib_obj):
    # Find the NSWindow instance at the top level
    all_windows = [x for x in nib_obj if x.className() == 'NSWindow']
    win = all_windows[0]
    # Now find all the views within the window where the identifier is defined
    top_view = win.contentView()
    v_dict = dict()
    for v in views_recursive(top_view):
        ident = v.identifier()
        if ident is not None:
            if not ident.startswith('_'):
                # Someone has customized it, remember it
                v_dict[ident] = v
    return v_dict


def quit_app():
    NSApplication.sharedApplication().terminate_(None)


class genericController(NSObject):
    def setTheThing_(self, f_obj):
        self.f = f_obj

    def doTheThing_(self, sender):
        if hasattr(self, 'f'):
            self.f()


def func_to_controller_selector(f_obj):
    o = genericController.alloc().init()
    o.setTheThing_(f_obj)
    return o


class Nibbler(object):
    def __init__(self, path):
        bundle = NSBundle.mainBundle()
        info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
        # Did you know you can override parts of infoDictionary (Info.plist,
        # after loading) even though Apple says it's read-only?
        info['LSUIElement'] = '1'
        # Initialize our shared application instance
        NSApplication.sharedApplication()
        # Two possibilities here
        # Either the path is a directory and we really want the file inside it
        # or the path is just a real .nib file
        if os.path.isdir(path):
            # Ok, so they just saved it from Xcode, not their fault
            # let's fix the path
            path = os.path.join(path, 'keyedobjects.nib')
        with open(path, 'rb') as f:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



chef/cookbooks/cpe_umad/files/resources/py2_nibbler.py [42:112]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class ProcessSerialNumber(Structure):
    _fields_ = [('highLongOfPSN', c_uint32), ('lowLongOfPSN',  c_uint32)]


kCurrentProcess = 2
kProcessTransformToForegroundApplication = 1
kProcessTransformToUIElementAppication = 4
ApplicationServices = CDLL(find_library('ApplicationServices'))
TransformProcessType = ApplicationServices.TransformProcessType
TransformProcessType.argtypes = [POINTER(ProcessSerialNumber), c_uint32]


def views_recursive(view_obj):
    yield view_obj
    for x in view_obj.subviews():
        for y in views_recursive(x):
            yield y


def views_dict(nib_obj):
    # Find the NSWindow instance at the top level
    all_windows = [x for x in nib_obj if x.className() == 'NSWindow']
    win = all_windows[0]
    # Now find all the views within the window where the identifier is defined
    top_view = win.contentView()
    v_dict = dict()
    for v in views_recursive(top_view):
        ident = v.identifier()
        if ident is not None:
            if not ident.startswith('_'):
                # Someone has customized it, remember it
                v_dict[ident] = v
    return v_dict


def quit_app():
    NSApplication.sharedApplication().terminate_(None)


class genericController(NSObject):
    def setTheThing_(self, f_obj):
        self.f = f_obj

    def doTheThing_(self, sender):
        if hasattr(self, 'f'):
            self.f()


def func_to_controller_selector(f_obj):
    o = genericController.alloc().init()
    o.setTheThing_(f_obj)
    return o


class Nibbler(object):
    def __init__(self, path):
        bundle = NSBundle.mainBundle()
        info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
        # Did you know you can override parts of infoDictionary (Info.plist,
        # after loading) even though Apple says it's read-only?
        info['LSUIElement'] = '1'
        # Initialize our shared application instance
        NSApplication.sharedApplication()
        # Two possibilities here
        # Either the path is a directory and we really want the file inside it
        # or the path is just a real .nib file
        if os.path.isdir(path):
            # Ok, so they just saved it from Xcode, not their fault
            # let's fix the path
            path = os.path.join(path, 'keyedobjects.nib')
        with open(path, 'rb') as f:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



