pyobjc / Scripts / CodeGenerators / cocoa_generator.py

The branch 'pyobjc-ancient' does not exist.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
#
# This script generates part of the python-wrappers around Cocoa.
#
# This script is based on some (not to clever) regular expressions, and seems
# to work pretty well with the current version of the Cocoa headers.
#
# NOTES:
# - This script is probably MacOSX specific.
# - This script should be rewritten, it's getting unmaintainable.
#
import enum_generator
import strconst_generator
import var_generator
import func_collector
import func_builder
import os
import sys
from dupfile import dupfile

#
# This script contains some MacOS X version dependencies. Because uname
# doesn't tell anything usefull, we use sw_vers to find the actual OS version.
#
import os
import sys
VER=None

if sys.platform == "darwin":
    fd = os.popen('/usr/bin/sw_vers', 'r')
    for ln in fd.readlines():
        if ln.startswith('ProductVersion:'):
            VER=ln.split()[-1]
    fd.close()
    fd = None
    VER = 'MacOS X ' + '.'.join(VER.split('.')[:2])

    FRAMEWORKS="/System/Library/Frameworks"
    def pathjoin(*args):
        res = os.path.join(*args)
        if not os.path.exists(res):
            return None
        return res

    ADDRESSBOOK_HDRS=pathjoin(FRAMEWORKS, "AddressBook.framework", "Headers")
    APPKIT_HDRS=pathjoin(FRAMEWORKS, "AppKit.framework", "Headers")
    FOUNDATION_HDRS=pathjoin(FRAMEWORKS, "Foundation.framework", "Headers")
    FOUNDATION_FUNCTION_PREFIX="FOUNDATION_EXPORT"
    FOUNDATION_INLINE_PREFIX='FOUNDATION_STATIC_INLINE'
    FOUNDATION_VAR_PREFIX="FOUNDATION_EXPORT"

    IB_HDRS=pathjoin(FRAMEWORKS, "InterfaceBuilder.framework", "Headers")
    PREFPANES_HDRS=pathjoin(FRAMEWORKS, "PreferencePanes.framework", "Headers")
    SECINT_HDRS=pathjoin(FRAMEWORKS, "SecurityInterface.framework", "Headers")

    WEBKIT_HDRS=pathjoin(FRAMEWORKS, "WebKit.framework", "Headers")
    APPLESCRIPTKIT_HDRS=pathjoin(FRAMEWORKS, "AppleScriptKit.framework", "Headers")
    AUTOMATOR_HDRS=pathjoin(FRAMEWORKS, "Automator.framework", "Headers")
    COREDATA_HDRS=pathjoin(FRAMEWORKS, "CoreData.framework", "Headers")
    DISCRECORDING_HDRS=pathjoin(FRAMEWORKS, "DiscRecording.framework", "Headers")
    DISCRECORDING2_HDRS=pathjoin(FRAMEWORKS, "DiscRecording.framework", "Frameworks", "DiscRecordingEngine.framework", "Headers")
    DISCRECORDING3_HDRS=pathjoin(FRAMEWORKS, "DiscRecording.framework", "Frameworks", "DiscRecordingContent.framework", "Headers")
    DISCRECORDINGUI_HDRS=pathjoin(FRAMEWORKS, "DiscRecordingUI.framework", "Headers")
    SYNCSERVICES_HDRS=pathjoin(FRAMEWORKS, "SyncServices.framework", "Headers")
    XGRIDFOUNDATION_HDRS=pathjoin(FRAMEWORKS, "XgridFoundation.framework", "Headers")

    EXCHND_HDRS=pathjoin(FRAMEWORKS, "ExceptionHandling.framework", "Headers")
    QTKIT_HDRS=pathjoin(FRAMEWORKS, "QTKit.framework", "Headers")
    QUARTZ_HDRS=pathjoin(FRAMEWORKS, "Quartz.framework", "Headers")
    QUARTZ2_HDRS=pathjoin(FRAMEWORKS, "Quartz.framework", "Frameworks", "QuartzComposer.framework", "Headers")
    QUARTZ3_HDRS=pathjoin(FRAMEWORKS, "Quartz.framework", "Frameworks", "PDFKit.framework", "Headers")
    OSAKIT_HDRS=pathjoin(FRAMEWORKS, "OSAKit.framework", "Headers")
    SENTESTINGKIT_HDRS=pathjoin(FRAMEWORKS, "SenTestingKit.framework", "Headers")

else:
    # This is probably incorrect, and was added to help a future
    # port to GNUstep
    x = os.uname()
    VER = x[0] + ' ' + x[2]

    HDR_BASE=os.environ.get('GNUSTEP_SYSTEM_ROOT')
    HDR_BASE=os.path.join(HDR_BASE, "Library", "Headers")

    ADDRESSBOOK_HDRS=os.path.join(HDR_BASE, "AddressBook")
    if not os.path.exists(ADDRESSBOOK_HDRS):
        ADDRESSBOOK_HDRS=None

    APPKIT_HDRS=os.path.join(HDR_BASE, "AppKit")
    if not os.path.exists(APPKIT_HDRS):
        APPKIT_HDRS=None

    FOUNDATION_HDRS=os.path.join(HDR_BASE, "Foundation")
    FOUNDATION_FUNCTION_PREFIX="GS_EXPORT"
    FOUNDATION_INLINE_PREFIX='GS_GEOM_SCOPE'
    FOUNDATION_VAR_PREFIX="GS_EXPORT"
    if not os.path.exists(FOUNDATION_HDRS):
        FOUNDATION_HDRS=None

    IB_HDRS=os.path.join(HDR_BASE, "InterfaceBuilder")
    if not os.path.exists(IB_HDRS):
        IB_HDRS=None

    PREFPANES_HDRS=os.path.join(HDR_BASE, "PreferencePanes")
    if not os.path.exists(PREFPANES_HDRS):
        PREFPANES_HDRS=None

    WEBKIT_HDRS=os.path.join(HDR_BASE, "WebKit")
    if not os.path.exists(WEBKIT_HDRS):
        WEBKIT_HDRS=None

    EXCHND_HDRS=os.path.join(HDR_BASE, "ExceptionHandling")
    if not os.path.exists(EXCHND_HDRS):
        EXCHND_HDRS=None

    SECINT_HDRS=os.path.join(HDR_BASE, "SecurityInterface")
    if not os.path.exists(SECINT_HDRS):
        SECINT_HDRS=None

    APPLESCRIPTKIT_HDRS=None
    AUTOMATOR_HDRS=None
    COREDATA_HDRS=None
    DISCRECORDING_HDRS=None
    DISCRECORDINGUI_HDRS=None
    SYNCSERVICES_HDRS=None
    XGRIDFOUNDATION_HDRS=None
    QTKIT_HDRS=None
    OSAKIT_HDRS=None
    QUARTZ_HDRS=None
    QUARTZ2_HDRS=None
    QUARTZ3_HDRS=None



if not os.path.isdir('Modules'):
    print "Run me from the root of the PyObjC source tree"
    sys.exit(1)

if not os.path.exists('build'):
    os.mkdir('build')

if not os.path.exists('build/codegen'):
    os.mkdir('build/codegen')



def filterAddressBookHeaders(fn):
    if fn[-3:] == 'C.h':
        return 0

    if fn == 'ABPeoplePickerView.h':
        return 0

    return 1

if FOUNDATION_HDRS is not None:
    enum_generator.generate(
            FOUNDATION_HDRS,
            'build/codegen/_Fnd_Enum.inc',
            ignore_files=['NSCompatibility.h', 'NSSerialization.h', 'NSUtilities.h'])
    strconst_generator.generate(
            FOUNDATION_HDRS,
            'build/codegen/_Fnd_Str.inc',
            ignore=(
                # Declared on GNUstep, but not actually inside the
                # shared lib?
                'ConnectionBecameInvalidNotification',
            )
    )
    FOUNDATION_IGNORE_LIST=(
        # All have types that are not (yet) mapped to python
        "NSNonOwnedPointerHashCallBacks",
        "NSNonRetainedObjectHashCallBacks",
        "NSObjectHashCallBacks",
        "NSOwnedObjectIdentityHashCallBacks",
        "NSOwnedPointerHashCallBacks",
        "NSPointerToStructHashCallBacks",
        "NSIntMapKeyCallBacks",
        "NSNonOwnedPointerMapKeyCallBacks",
        "NSNonOwnedPointerOrNullMapKeyCallBacks",
        "NSNonRetainedObjectMapKeyCallBacks",
        "NSObjectMapKeyCallBacks",
        "NSOwnedPointerMapKeyCallBacks",
        "NSIntMapValueCallBacks",
        "NSNonOwnedPointerMapValueCallBacks",
        "NSObjectMapValueCallBacks",
        "NSNonRetainedObjectMapValueCallBacks",
        "NSOwnedPointerMapValueCallBacks",
        "NSIntHashCallBacks",
        "NSHangOnMallocError",
    )

    var_generator.generate(
            FOUNDATION_HDRS,
            'build/codegen/_Fnd_Var.inc',
            FOUNDATION_VAR_PREFIX,
            FOUNDATION_IGNORE_LIST)

    FOUNDATION_IGNORE_LIST=(
        # Private functions
        '_NSAddHandler2(',
        '_NSRemoveHandler2(',
        '_NSExceptionObjectFromHandler2(',
        '_NSAutoreleaseNoPool(',
        '_NSAutoreleaseFreedObject(',
        '_NSAutoreleaseHighWaterLog(',
        'NXReadNSObjectFromCoder(',


        # List of functions that are not usefull from Python:
        "NSAllocateCollectable",
        "NSReallocateCollectable",
        'NSFrameAddress(',
        'NSReturnAddress(',
        'NSRecordAllocationEvent(',
        'NSCreateHashTableWithZone(',
        'NSCreateHashTable(',
        'NSFreeHashTable(',
        'NSResetHashTable(',
        'NSCompareHashTables(',
        'NSCopyHashTableWithZone(',
        'NSHashGet(',
        'NSHashInsert(',
        'NSHashInsertKnownAbsent(',
        'NSHashInsertIfAbsent(',
        'NSHashRemove(',
        'NSEnumerateHashTable(',
        'NSNextHashEnumeratorItem(',
        'NSEndHashTableEnumeration(',
        'NSCountHashTable(',
        'NSStringFromHashTable(',
        'NSAllHashTableObjects(',
        'NSJavaClassesFromPath(',
        'NSJavaClassesForBundle(',
        'NSCreateMapTableWithZone(',
        'NSCreateMapTable(',
        'NSFreeMapTable(',
        'NSResetMapTable(',
        'NSCompareMapTables(',
        'NSCopyMapTableWithZone(',
        'NSMapMember(',
        'NSMapGet(',
        'NSMapInsert(',
        'NSMapInsertKnownAbsent(',
        'NSMapInsertIfAbsent(',
        'NSMapRemove(',
        'NSEnumerateMapTable(',
        'NSNextMapEnumeratorPair(',
        'NSEndMapTableEnumeration(',
        'NSCountMapTable(',
        'NSStringFromMapTable(',
        'NSAllMapTableKeys(',
        'NSAllMapTableValues(',
        'NSGetSizeAndAlignment(', # Hmm, shouldn't we use this in the bridge?
        'NSLogv(',
        'NSLog(',
        'NSAllocateObject(',
        'NSCopyObject(',
        'NSShouldRetainWithZone(',
        'NSAllocateMemoryPages(',
        'NSDeallocateMemoryPages(',
        'NSCopyMemoryPages(',


        # List of manually wrapped functions:
        'NSFileTypeForHFSTypeCode(',
        'NSHFSTypeCodeFromFileType(',
        'NSStringFromPoint',
        'NSDivideRect(',

        # Zones might be usefull someday
        'NSCreateZone(',
        'NSRecycleZone(',
        'NSSetZoneName(',
        'NSZoneName(',
        'NSZoneFromPointer(',
        'NSZoneMalloc(',
        'NSZoneCalloc(',
        'NSZoneRealloc(',
        'NSZoneFree(',
        'NSDefaultMallocZone(',

        # TODO
        'NSUncaughtExceptionHandler(',
        'NSSetUncaughtExceptionHandler(',
        'NSGetUncaughtExceptionHandler(',

        # GNUstep functions
        'GSDebugAllocationClassList(',
        '_NSAddHandler(',
        '_NSRemoveHandler(',
        'NSStringFromMapTable(',
        'GSLogLock(',
        'NSLogv (',
        'NSLog (',
        'NSCreateZone (',
        'NSZoneFromPointer (',
        'NSZoneCalloc (',
        'NSSetZoneName (',
        'NSAllocateMemoryPages (',
        'NSDeallocateMemoryPages (',
        'NSCopyMemoryPages (',
        'GSDebugAllocation',
        'NSStringFromMapTable (',
        'NSDeallocateObject(',
        'GSDebugFunctionMsg(',
        'GSDebugMethodMsg(',
    )

    func_collector.generate(
            FOUNDATION_HDRS,
            'build/codegen/Foundation.prototypes',
            FOUNDATION_FUNCTION_PREFIX,
            FOUNDATION_IGNORE_LIST)

    func_collector.generate(
            FOUNDATION_HDRS,
            'build/codegen/Foundation.prototype2',
            FOUNDATION_INLINE_PREFIX,
            FOUNDATION_IGNORE_LIST)



    for arg in [
        'NSSearchPathDomainMask', 'NSCalculationError',
        'NSComparisonResult', 'NSInsertionPosition',
        'NSNotificationCoalescing', 'NSNotificationCoalescing',
        'NSRectEdge', 'NSRelativePosition',
        'NSRoundingMode', 'NSSaveOptions', 'NSSearchPathDirectory',
        'NSSearchPathDomainMask', 'NSTestComparisonOperation',
        'NSURLHandleStatus', 'NSWhoseSubelementIdentifier']:
        func_builder.TYPE_ALIASES[arg] = 'int'

    func_builder.TYPE_ALIASES['NSGlyph'] = 'unsigned int'

    func_builder.IGNORE_VARARGS.extend([
        # Some of these are Foundation some are AppKit
        'NSGetInformationalAlertPanel',
        'NSRunAlertPanel',
        'NSRunInformationalAlertPanel',
        'NSRunCriticalAlertPanel',
        'NSRunAlertPanelRelativeToWindow',
        'NSRunInformationalAlertPanelRelativeToWindow',
        'NSRunCriticalAlertPanelRelativeToWindow',
        'NSBeginAlertSheet',
        'NSBeginInformationalAlertSheet',
        'NSBeginCriticalAlertSheet',
        'NSGetAlertPanel',
        'NSGetCriticalAlertPanel',
    ])

    def BeginSheetMapper(funcname, args):
        new_args = []
        for tp, name in args:
            if name == 'contextInfo':
                tp = 'PYOBJC_VOIDPTR'
            new_args.append((tp, name))
        return tuple(new_args)

    func_builder.FUNC_MAP['NSBeginAlertSheet'] = BeginSheetMapper
    func_builder.FUNC_MAP['NSBeginInformationalAlertSheet'] = BeginSheetMapper
    func_builder.FUNC_MAP['NSBeginCriticalAlertSheet'] = BeginSheetMapper

    fd = dupfile('build/codegen/_Fnd_Functions.inc', 'w')

    func_builder.SIMPLE_TYPES['NSDecimal*'] = (
            '\tresult = Decimal_New(%(varname)s);\n\tif (result == NULL) return NULL;',
            'O&',
            'Decimal_Convert, &%(varname)s'
        )

    structs = ['NSPoint', 'NSSize', 'NSRect', 'NSRange', 'NSSwappedFloat', 'NSSwappedDouble']
    if sys.platform == 'darwin':
        structs.append('NSTimeInterval')
    for s in structs:
        func_builder.SIMPLE_TYPES[s] = (
            '\tresult = PyObjC_ObjCToPython(@encode(%s), (void*)&%%(varname)s); \n\tif (result == NULL) return NULL;'%s,
            'O&',
            'convert_%s, &%%(varname)s'%s
        )
        fd.write('''\

    static inline int convert_%(type)s(PyObject* object, void* pvar)
    {
            int err;

            err = PyObjC_PythonToObjC(@encode(%(type)s), object, pvar);
            if (err == -1) {
                    return 0;
            }
            return 1;
    }
    '''%{'type': s })

    fd.write('typedef void* PYOBJC_VOIDPTR;\n')

    funcs = func_builder.process_list(fd , file('build/codegen/Foundation.prototypes'))
    funcs2 = func_builder.process_list(fd , file('build/codegen/Foundation.prototype2'))

    # These are macro's
    funcs3 = func_builder.process_list(fd, [
        'NSString* NSLocalizedString(NSString* key, NSString* comment);',
        'NSString* NSLocalizedStringFromTable(NSString* key, NSString* tableName, NSString* comment);',
        'NSString* NSLocalizedStringFromTableInBundle(NSString* key, NSString* tableName, NSString* comment, NSBundle* bunlde);',
    ])
    func_builder.gen_method_table_entries(fd, funcs + funcs2 + funcs3)
    fd = None
    for s in structs:
        del func_builder.SIMPLE_TYPES[s]


if APPKIT_HDRS is not None:
    enum_generator.generate(
            APPKIT_HDRS,
            'build/codegen/_App_Enum.inc')

    strconst_generator.generate(
            APPKIT_HDRS,
            'build/codegen/_App_Str.inc')
    APPKIT_PREFIX="APPKIT_EXTERN"
    APPKIT_IGNORE_LIST=(
        # First two have types that are not yet mapped
        'NSIconSize',
        'NSTokenSize',

        # NSApp is a 'real' variable, will probably add get/set functions
        'NSApp')

    var_generator.generate(
            APPKIT_HDRS,
            'build/codegen/_App_Var.inc',
            APPKIT_PREFIX,
            APPKIT_IGNORE_LIST)

    APPKIT_IGNORE_LIST=(
        # List of manually wrapped functions:
        'NSApplicationMain(',
        'NSCountWindows(',
        'NSCountWindowsForContext(',
        'NSAvailableWindowDepths(',
        'NSRectFillList(',
        'NSGetWindowServerMemory(',
        'NSDrawTiledRects(',
        'NSDrawColorTiledRects(',
        'NSRectFillListWithGrays(',
        'NSRectFillListWithColors(',
        'NSRectFillListUsingOperation(',
        'NSRectFillListWithColorsUsingOperation(',
        'NSRectClipList(',
        'NSWindowList(',
        'NSWindowListForContext(',
        'NSBestDepth (',
        'NSAvailableWindowDepths (',

        #TODO:
        'NSDrawBitmap(',
    )

    if VER == "MacOS X 10.1":
        APPKIT_IGNORE_LIST = APPKIT_IGNORE_LIST + ('NSCopyBitmapFromGState',)

    func_collector.generate(
            APPKIT_HDRS,
            'build/codegen/AppKit.prototypes',
            APPKIT_PREFIX,
            APPKIT_IGNORE_LIST)

    func_builder.FUNC_MAP['NSShowAnimationEffect'] = BeginSheetMapper

    fd = dupfile('build/codegen/_App_Functions.inc', 'w')
    structs = ['NSAffineTransformStruct', 'NSRect', 'NSPoint', 'NSSize']
    for s in structs:
        func_builder.SIMPLE_TYPES[s] = (
            '\tresult = PyObjC_ObjCToPython(@encode(%s), (void*)&%%(varname)s); \n\tif (result == NULL) return NULL;'%s,
            'O&',
            'convert_%s, &%%(varname)s'%s
        )
        fd.write('''\
    static inline int convert_%(type)s(PyObject* object, void* pvar)
    {
            int err;

            err = PyObjC_PythonToObjC(@encode(%(type)s), object, pvar);
            if (err == -1) {
                    return 0;
            }
            return 1;
    }
    '''%{'type': s })

    for arg in [
        'NSApplicationTerminateReply', 'NSBackingStoreType',
        'NSBezelStyle', 'NSBezierPathElement',
        'NSBitmapImageFileType', 'NSBorderType', 'NSBoxType',
        'NSButtonType', 'NSCellAttribute', 'NSCellImagePosition',
        'NSCellStateValue', 'NSCellType', 'NSCompositingOperation',
        'NSControlSize', 'NSControlTint', 'NSDocumentChangeType',
        'NSDragOperation', 'NSDrawerState', 'NSEventType',
        'NSFocusRingPlacement', 'NSFontAction', 'NSFontTraitMask',
        'NSGlyph', 'NSGlyphInscription', 'NSGlyphLayoutMode',
        'NSGlyphRelation', 'NSGradientType', 'NSImageAlignment',
        'NSImageFrameStyle', 'NSImageInterpolation', 'NSImageScaling',
        'NSInterfaceStyle', 'NSLayoutDirection', 'NSLayoutStatus',
        'NSLineBreakMode', 'NSLineCapStyle', 'NSLineJoinStyle',
        'NSLineMovementDirection', 'NSLineSweepDirection',
        'NSMatrixMode', 'NSMultibyteGlyphPacking', 'NSOpenGLContextParameter',
        'NSOpenGLGlobalOption', 'NSOpenGLPixelFormatAttribute',
        'NSPopUpArrowPosition', 'NSPrinterTableStatus',
        'NSPrintingOrientation', 'NSPrintingPageOrder',
        'NSPrintingPaginationMode', 'NSProgressIndicatorThickness',
        'NSQTMovieLoopMode', 'NSRequestUserAttentionType',
        'NSRulerOrientation', 'NSSaveOperationType',
        'NSScrollArrowPosition', 'NSScrollerArrow',
        'NSScrollerPart', 'NSSelectionAffinity',
        'NSSelectionDirection', 'NSSelectionGranularity',
        'NSTabState', 'NSTabViewState', 'NSTableViewDropOperation',
        'NSTextAlignment', 'NSTextTabType', 'NSTickMarkPosition',
        'NSTIFFCompression', 'NSTitlePosition', 'NSToolbarDisplayMode',
        'NSToolTipTag', 'NSTrackingRectTag', 'NSUsableScrollerParts',
        'NSWindingRule', 'NSWindowDepth', 'NSWindowOrderingMode',
        'NSAnimationEffect',
        ]:
        func_builder.TYPE_ALIASES[arg] = 'int'

    func_builder.ID_MAP['NSGlyph*'] = 'id'

    fd.write('typedef void* PYOBJC_VOIDPTR;\n')
    funcs = func_builder.process_list(fd, file('build/codegen/AppKit.prototypes'))

    funcs2 = func_builder.process_list(fd, [

            # This is a very ugly macro, it access 'glyphs' in the enclosing
            # block ???
            #'void NSGlyphInfoAtIndex(int IX);',
        ])

    func_builder.gen_method_table_entries(fd, funcs + funcs2)
    for s in structs:
        del func_builder.SIMPLE_TYPES[s]


if ADDRESSBOOK_HDRS is not None:
    enum_generator.generate(
            ADDRESSBOOK_HDRS,
            'build/codegen/_Addr_Enum.inc',
            filter=filterAddressBookHeaders)
    strconst_generator.generate(
            ADDRESSBOOK_HDRS,
                'build/codegen/_Addr_Str.inc',
                filter=filterAddressBookHeaders)

if PREFPANES_HDRS is not None:
    enum_generator.generate(
            PREFPANES_HDRS,
            'build/codegen/_PreferencePanes_Enum.inc')
    strconst_generator.generate(
            PREFPANES_HDRS,
            'build/codegen/_PreferencePanes_Str.inc')

if IB_HDRS is not None:
    enum_generator.generate(
            IB_HDRS,
            'build/codegen/_InterfaceBuilder_Enum.inc')
    strconst_generator.generate(
            IB_HDRS,
            'build/codegen/_InterfaceBuilder_Str.inc')

if WEBKIT_HDRS is not None:
    enum_generator.generate(
            WEBKIT_HDRS,
            'build/codegen/_WebKit_Enum.inc',
                ignore_files=['npapi.h', 'npruntime.h', 'npfunctions.h'])

    # The two items on the ignore-list cause link errors,
    # to-be-investigated.
    strconst_generator.generate(WEBKIT_HDRS,
                                'build/codegen/_WebKit_Str.inc',
                                ignore=('WebElementImageAltStringKey',
                                        'WebPreferencesChangedNotification')
    )

if APPLESCRIPTKIT_HDRS is not None:
    enum_generator.generate(
            APPLESCRIPTKIT_HDRS,
            'build/codegen/_AppleScriptKit_Enum.inc',
                ignore_files=[])

    strconst_generator.generate(APPLESCRIPTKIT_HDRS,
                                'build/codegen/_AppleScriptKit_Str.inc',
                                ignore=())

if AUTOMATOR_HDRS is not None:
    enum_generator.generate(
            AUTOMATOR_HDRS,
            'build/codegen/_Automator_Enum.inc',
                ignore_files=[])

    strconst_generator.generate(AUTOMATOR_HDRS,
                                'build/codegen/_Automator_Str.inc',
                                ignore=())

if COREDATA_HDRS is not None:
    COREDATA_VAR_PREFIX='COREDATA_EXTERN'
    COREDATA_IGNORE_LIST=()
    enum_generator.generate(
            COREDATA_HDRS,
            'build/codegen/_CoreData_Enum.inc',
                ignore_files=[])

    var_generator.generate(
            COREDATA_HDRS,
            'build/codegen/_CoreData_Var.inc',
            COREDATA_VAR_PREFIX,
            COREDATA_IGNORE_LIST)

    strconst_generator.generate(COREDATA_HDRS,
                                'build/codegen/_CoreData_Str.inc',
                                ignore=())

if QTKIT_HDRS is not None:
    QTKIT_VAR_PREFIX='QTKIT_EXTERN'
    QTKIT_FUNCTION_PREFIX='QTKIT_EXTERN'
    QTKIT_IGNORE_LIST=()
    enum_generator.generate(
            QTKIT_HDRS,
            'build/codegen/_QTKit_Enum.inc',
                ignore_files=[])

    var_generator.generate(
            QTKIT_HDRS,
            'build/codegen/_QTKit_Var.inc',
            QTKIT_VAR_PREFIX,
            QTKIT_IGNORE_LIST)

    func_collector.generate(
            QTKIT_HDRS,
            'build/codegen/QTKit.prototypes',
            QTKIT_FUNCTION_PREFIX,
            QTKIT_IGNORE_LIST)

    fd = dupfile('build/codegen/_QTKit_Functions.inc', 'w')

    func_builder.ID_MAP['NSTimeInterval*'] = 'id'

    structs = ['QTTime', 'QTTimeRange', 'TimeRecord']
    if sys.platform == 'darwin':
        structs.append('NSTimeInterval')
    for s in structs:
        func_builder.SIMPLE_TYPES[s] = (
            '\tresult = PyObjC_ObjCToPython(@encode(%s), (void*)&%%(varname)s); \n\tif (result == NULL) return NULL;'%s,
            'O&',
            'convert_%s, &%%(varname)s'%s
        )
        fd.write('''\

    static inline int convert_%(type)s(PyObject* object, void* pvar)
    {
            int err;

            err = PyObjC_PythonToObjC(@encode(%(type)s), object, pvar);
            if (err == -1) {
                    return 0;
            }
            return 1;
    }
    '''%{'type': s })
    func_builder.TYPE_ALIASES['OSType'] = 'int'
    funcs = func_builder.process_list(fd , file('build/codegen/QTKit.prototypes'))
    func_builder.gen_method_table_entries(fd, funcs)
    fd.close()


    strconst_generator.generate(QTKIT_HDRS,
                                'build/codegen/_QTKit_Str.inc',
                                ignore=())

if DISCRECORDING_HDRS is not None:
    enum_generator.generate(
            DISCRECORDING_HDRS,
            'build/codegen/_DiscRecording_Enum.inc',
                ignore_files=[], emit_imports=0, emit_footer=0)
    enum_generator.generate(
            DISCRECORDING2_HDRS,
            'build/codegen/_DiscRecording2_Enum.inc',
                ignore_files=[], emit_imports=0, emit_footer=0, emit_header=0)
    enum_generator.generate(
            DISCRECORDING3_HDRS,
            'build/codegen/_DiscRecording3_Enum.inc',
                ignore_files=[], emit_imports=0, emit_header=0)

    strconst_generator.generate(DISCRECORDING_HDRS,
                                'build/codegen/_DiscRecording_Str.inc',
                                ignore=(), emit_footer=0)
    strconst_generator.generate(DISCRECORDING2_HDRS,
                                'build/codegen/_DiscRecording2_Str.inc',
                                ignore=(), emit_footer=0, emit_header=0)
    strconst_generator.generate(DISCRECORDING3_HDRS,
                                'build/codegen/_DiscRecording3_Str.inc',
                                ignore=(), emit_header=0)

if DISCRECORDINGUI_HDRS is not None:
    enum_generator.generate(
            DISCRECORDINGUI_HDRS,
            'build/codegen/_DiscRecordingUI_Enum.inc',
                ignore_files=[])

    strconst_generator.generate(DISCRECORDINGUI_HDRS,
                                'build/codegen/_DiscRecordingUI_Str.inc',
                                ignore=())

if SYNCSERVICES_HDRS is not None:
    enum_generator.generate(
            SYNCSERVICES_HDRS,
            'build/codegen/_SyncServices_Enum.inc',
                ignore_files=[])

    strconst_generator.generate(SYNCSERVICES_HDRS,
                                'build/codegen/_SyncServices_Str.inc',
                                ignore=())


if XGRIDFOUNDATION_HDRS is not None:
    enum_generator.generate(
            XGRIDFOUNDATION_HDRS,
            'build/codegen/_XgridFoundation_Enum.inc',
                ignore_files=[])

    strconst_generator.generate(XGRIDFOUNDATION_HDRS,
                                'build/codegen/_XgridFoundation_Str.inc',
                                ignore=())



if EXCHND_HDRS is not None:
    enum_generator.generate(
            EXCHND_HDRS,
            'build/codegen/_ExceptionHandling_Enum.inc')

    # The two items on the ignore-list cause link errors,
    # to-be-investigated.
    strconst_generator.generate(
        EXCHND_HDRS,
        'build/codegen/_ExceptionHandling_Str.inc')


if SECINT_HDRS is not None:
    enum_generator.generate(
            SECINT_HDRS,
            'build/codegen/_SecInt_Enum.inc')
    strconst_generator.generate(
            SECINT_HDRS,
            'build/codegen/_SecInt_Str.inc')

if OSAKIT_HDRS is not None:
    enum_generator.generate(
            OSAKIT_HDRS,
            'build/codegen/_OSAKit_Enum.inc')
    strconst_generator.generate(
            OSAKIT_HDRS,
            'build/codegen/_OSAKit_Str.inc')

if QUARTZ_HDRS is not None:
    enum_generator.generate(
            QUARTZ_HDRS,
            'build/codegen/_Quartz_Enum.inc', emit_imports=0, emit_footer=0)
    enum_generator.generate(
            QUARTZ2_HDRS,
            'build/codegen/_Quartz2_Enum.inc', emit_imports=0, emit_header=0, emit_footer=0)
    enum_generator.generate(
            QUARTZ3_HDRS,
            'build/codegen/_Quartz3_Enum.inc', emit_imports=0, emit_header=0)
    strconst_generator.generate(
            QUARTZ_HDRS,
            'build/codegen/_Quartz_Str.inc', emit_footer=0)
    strconst_generator.generate(
            QUARTZ2_HDRS,
            'build/codegen/_Quartz2_Str.inc', emit_header=0, emit_footer=0)
    strconst_generator.generate(
            QUARTZ3_HDRS,
            'build/codegen/_Quartz3_Str.inc', emit_header=0)

if SENTESTINGKIT_HDRS is not None:
    enum_generator.generate(
            SENTESTINGKIT_HDRS,
            'build/codegen/_SenTestingKit_Enum.inc')
    strconst_generator.generate(
            SENTESTINGKIT_HDRS,
            'build/codegen/_SenTestingKit_Str.inc')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.