Source

pyobjc / Examples / 00ReadMe.txt

  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
===============
PyObjC Examples
===============

Simple scripts that demo the core modules
-----------------------------------------

The directory `Scripts`__ contains a number of simple command-line scripts
that make use of Cocoa features.

.. __: Scripts

* `autoreadme.py`_

  This script is a daemon that will open the ReadMe file in the root of any
  (removable) volume that is inserted while this script is running.

  The script is part of `Introduction to PyObjC`_, an article at O'Reilly
  `MacDevCenter.com`_.

.. _`autoreadme.py`: Scripts/autoreadme.py
.. _`Introduction to PyObjC`: http://macdevcenter.com/pub/a/mac/2003/01/31/pyobjc_one.html
.. _`MacDevCenter.com`: http://macdevcenter.com/

* `debugging.py`__

  This script shows how to use ``PyObjCTools.Debugging`` to show tracebacks
  of all (Cocoa) exceptions (handled and unhandled).

.. __: Scripts/debugging.py

* `dictionary.py`__

  Demonstrate the usage of an ``NSMutableDictionary`` object with both
  Objective-C and Python dictionary syntax.

.. __: Scripts/dictionary.py

* `exportBook.py`__

  An example of using the ``AddressBook`` framework, this script exports some
  of the information about people in your addressbook to a CSV file.

.. __: Scripts/exportBook.py

* `findPython.py`__

  Demonstrate the usage of ``objc.loadBundleFunctions`` to access
  functionality from the standard C library on Mac OS X (``libSystem``,
  which is also available as the ``System.framework`` bundle).  This
  example uses the dyld runtime to determine which dylib the Python
  runtime came from.

.. __: Scripts/findPython.py

* `HelloWorld.py`__

  Demonstrates a nib-less Cocoa GUI (purely for informational purposes, you
  probably shouldn't make a habit of this)

.. __: Scripts/HelloWorld.py

* `kvo-debugging.py`__

  XXX
  An example script that demonstrates how PyObjC interacts with Key-Value
  Observation (KVO) at the lowest level.  This script was used to debug
  the PyObjC runtime and should not be used as a guideline for writing
  new KVO code.  It may be interesting to some until we ensure that we
  have proper unit tests for KVO and remove this example!

.. __: Scripts/kvo-debugging.py

* `pydict-to-objcdict.py`__

  Shows how ``PyObjCTools.Conversion`` can be used to convert a Python
  collection into an Objective-C property list.  These functions should
  not typically be necessary as the proxies for Python objects are
  compatible with Objective-C plists.

.. __: Scripts/pydict-to-objcdict.py

* `rendezvous.py`__

  Use an NSNetService class to look for servers using rendezvous.

.. __: Scripts/rendezvous.py

* `signal-demo.py`__

  Demonstrates how to get a backtrace when handling a fatal signal using
  ``PyObjCTools.Signals``.

.. __: Scripts/signal-demo.py

* `stdinreader.py`__

  Demonstrates how to write a console runloop based application that uses
  ``NSFileHandle`` to read stdin asynchronously.

.. __: Scripts/stdinreader.py

* `subclassing-objective-c.py`__

  A doctest that demonstrates the subclassing of an Objective-C class from
  Python.  Note that it is typically discouraged to define a ``__del__``
  method.

.. __: Scripts/subclassing-objective-c.py

* `super-call.py`__

  Demonstrates how create a subclass of an Objective-C class that overrides
  a selector, but calls the super implementation using Python syntax
  equivalent to ``[super init]``.

.. __: Scripts/super-call.py

* `wmEnable.py`__

  Another ``objc.loadBundleFunctions`` demonstration that shows how to
  call into a private CoreGraphics SPI and enable full WindowManager
  access from a process that would not otherwise have it due to a
  quirk in the implementation of WindowManager (the reason why ``pythonw``
  should be used instead of ``python``).  Use at your own risk!

.. __: Scripts/wmEnable.py


Cocoa Applications
------------------

The directory `AppKit`__ contains example applications using the Cocoa
Application Framework (aka "AppKit").

.. __: AppKit

Most of the following examples contain a ``setup.py`` script that can
build an application. See `Building applications`_ for details how to invoke
these scripts. Some examples contain an ``Xcode`` or ``Project Builder``
project file; simply double-click it and choose ``Build and Run``, or invoke
``xcodebuild`` or ``pbxbuild`` from the command line depending on which you
have installed.

.. _`Building applications`: ../Doc/intro.html#building-applications

* `ClassBrowser`__

  A simple class browser, demonstrating the use of ``NSBrowser``
  (a "column view" hierarchical widget) and ``NSTableView``.

.. __: AppKit/ClassBrowser

* `CurrencyConverter`_

  A simple NIB based application. Start with this one. Also see the 
  `PyObjC tutorial`_.

.. _`CurrencyConverter`: AppKit/CurrencyConverter
.. _`PyObjC tutorial`: ../Doc/tutorial/tutorial.html

* `DotView`__

  A simple one-window demo showing how to custom drawing in a custom
  ``NSView``. Additionally shows how easy it is to embed a view in an
  ``NSScrollView``, as well as how to use an ``NSColorWell``.

.. __: AppKit/DotView

* `FieldGraph`__
  
  This shows an simple example of an MVC based application, that also
  makes use of ``NSBezierPaths``.  Contains a ``Project Builder`` project,
  as well as a ``setup.py`` script.

  The application calculates the field pattern and RMS field of an antenna 
  array with up to three elements.

.. __: AppKit/FieldGraph

* `HotKeyPython`__

  Demonstrates how to use Carbon global hot keys from a PyObjC application.
  Also demonstrates how to use a ``NSApplication`` subclass.

.. __: AppKit/HotKeyPYthon

* `iClass`__

  A more elaborate class browser; demonstrates ``NSOutlineView`` and
  ``NSTableView``.

.. __: AppKit/iClass

* `PackageManager`__
  
  An implementation of the MacPython PackageManager application using
  Cocoa.

.. __: AppKit/PackageManager

* `PyInterpreter`__

  A full featured embedded Python interpreter.  This demonstrates
  more complicated uses of ``NSTextView``, manual event dispatching,
  and the new text completion feature of OS X 10.3.

.. __: AppKit/PyInterpreter

* `PyObjCLauncher`__

  A reimplementation of the Python script launcher helper application
  in PyObjC.

.. __: AppKit/PyObjCLauncher

* `PythonBrowser`__

  A reusable Python object browser, demonstrating the use of ``NSOutlineView``
  as well as how to use an ``NSWindowController`` subclass to create a window
  from a menu action.

.. __: AppKit/PythonBrowser

* `SimpleService`__

  Shows how to implement entries for the Services menu.

.. __: AppKit/SimpleService

* `TableModel`__

  Basic demo that shows how to use a ``NSTableView``.

.. __: AppKit/TableModel

* `TinyTinyEdit`__

  A minimal Document-based text editor application.

.. __: AppKit/TinyTinyEdit

* `Todo`_

  A more complex NIB based applications. This is a document-based application.
  The code is a translation into Python of an example project in 
  `Learning Cocoa`_ from O'Reilly

.. _`Todo`: AppKit/ToDo
.. _`Learning Cocoa`: http://www.oreilly.com/catalog/learncocoa2/

* `WebServicesTool`__

  Queries an XML-RPC enabled web server for the methods that it implements.
  Demonstrates a more advanced use of an ``NSTableView``, how to make a
  toolbar as well as how to use multi-threading.  Contains a
  ``Project Builder`` project as well as a ``setup.py`` script.

.. __: AppKit/WebServicesTool


Cocoa Bindings
--------------

The `CocoaBindings`__ directory contains a number of examples that make use of
Key-Value Coding and Cocoa Bindings. These scripts require Mac OS X 10.3 or
later.

.. __: CocoaBindings

* `Bookmarks`_

  Shows custom array controller that implements table view data
  source methods to support drag and drop, including copying
  objects from one window to another, drop of URLs, and 
  re-ordering of the content array.

  Originally from `Cocoa Bindings Examples and Hints`_,
  converted to PyObjC by u.fiedler.

.. _`Bookmarks`: CocoaBindings/Bookmarks

* `ControlledPreferences`_
  
  Demonstrates how to use Cocoa Bindings to simplify storing and
  retrieving user preferences.  Also demonstrates how to use an
  ``NSValueTransformer`` to archive/unarchive a non-property-list
  type automatically (``NSColor``, in this case).

  Originally from `Cocoa Bindings Examples and Hints`_,
  converted to PyObjC by u.fiedler.

.. _`ControlledPreferences`: CocoaBindings/ControlledPreferences

* `CurrencyConvBinding`_

  A rewrite of `CurrencyConverter`_ using Cocoa Bindings.
    
  Originally from
  `Introduction to Developing Cocoa Applications Using Bindings`_,
  converted to PyObjC by u.fiedler.

.. _`CurrencyConvBinding`: CocoaBindings/CurrencyConvBinding
.. _`Introduction to Developing Cocoa Applications Using Bindings`: http://developer.apple.com/documentation/Cocoa/Conceptual/CurrencyConverterBindings/index.html

* `FilteringController`_

  Demonstrates how to subclass ``NSArrayController`` to implement filtering
  of a ``NSTableView``.  Also demonstrates the use of indexed accessors.
  
  Originally from `Cocoa Bindings Examples and Hints`_,
  converted to PyObjC by u.fiedler.

.. _`FilteringController`: CocoaBindings/FilteringController

* `GraphicsBindings`_

   Shows the use of a custom controller, a value transformer, and two custom
   bindings-enabled views. One view is a control that allows you to set the
   angle and offset of a shadow; the other view observes and displays a
   collection of graphic objects.

  Originally from `Cocoa Bindings Examples and Hints`_,
  converted to PyObjC by u.fiedler.

.. _`GraphicsBindings`: CocoaBindings/GraphicsBindings

* `ManualBindings`_

  A simple example that illustrates establishing bindings
  programmatically, including a number of options such as validation
  and an array operator, and indexed accessor methods. A custom model
  object implements custom validation method.
  
  Originally from `Cocoa Bindings Examples and Hints`_,
  converted to PyObjC by u.fiedler.

.. _`ManualBindings`: CocoaBindings/ManualBindings
.. _`Cocoa Bindings Examples and Hints`: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html

* `TableModel`__

  Shows how to fill an ``NSTableView`` using Key-Value Coding.  Contains
  contains an ``Xcode`` project as well as a ``setup.py`` script.

.. __: CocoaBindings/TableModel
  
* `TableModelWithSearch`__

  A more advanced example of Key-Value Coding. This uses a custom 
  ``NSArrayController``.  Contains contains an ``Xcode`` project
  as well as a ``setup.py`` script.

.. __: CocoaBindings/TableModelWithSearch

* `TemperatureTransformer`_

  An example that uses ``NSValueTransformer`` to convert between Celsius
  and Fahrenheit.

  Based on Apple's `Value Transformers`_ documentation,
  converted to PyObjC by u.fiedler.

.. _`TemperatureTransformer`: CocoaBindings/TemperatureTransformer
.. _`Value Transformers`: http://developer.apple.com/documentation/Cocoa/Conceptual/ValueTransformers/index.html

* `ToDos`_

  Shows two array controllers, one to manage the contents of a table
  view, the other to manage a pop-up menu in a table column. Also 
  shows two value transformers to alter the color of text.

  Originally from `Cocoa Bindings Examples and Hints`_,
  converted to PyObjC by u.fiedler.

.. _`ToDos`: CocoaBindings/ToDos

CoreData
--------

The directory `CoreData`__ contains a number of examples
that use the CoreData framework. This framework is available
in MacOS X 10.4 and later.

.. __: CoreData

* `OutlineEdit`__

  A python version of the OutlineEdit example that's included with
  Xcode 2.0.

.. __: CoreData/OutlineEdit

Foundation
----------

The directory `Foundation`_ contains a number of examples
that use only Foundation facilities.

* `simple-kvo.py`__

  Demonstrates the use of Key-Value Observing from a simple
  script, without a runloop.  Requires Mac OS X 10.3 or later.

.. __: Foundation/simple-kvo.py

Inject
------

The directory `Inject`_ contains a number of examples that use the
``objc.inject`` facility to inject code into another process.  These
examples require Mac OS X 10.3 or later.

.. _`Inject`: Inject

* `IDNSnitch`_

  A proof of concept `IDN spoofing defense`_ for Safari (tested with
  v1.2.4 on Mac OS X 10.3.8).  Demonstrates how to write an application
  that detects the launch of another application by bundle identifier,
  how to use ``objc.inject`` to load code into another application,
  how to override the implementation of an existing class but still
  call back into the original implementation, and how to reduce the
  size of such an application/plugin combination by using symlinks
  to share object files (the PyObjC extensions in this case).

.. _`IDNSnitch`: Inject/IDNSnitch
.. _`IDN spoofing defense`: http://bob.pythonmac.org/archives/2005/02/07/idn-spoofing-defense-for-safari/

* `InjectInterpreter`_:

  Shows how to inject an in-process Python interpreter into another
  process.  Based on the AppKit PyInterpreter example.

.. _`InjectInterpreter`: Inject/InjectInterpreter

* `InjectBrowser`_:

  Shows how to inject an in-process Python class browser into another
  process.  Based on the AppKit ClassBrowser example.

.. _`InjectBrowser`: Inject/ClassBrowser


OpenGL
------

The directory `OpenGL`_ contains a number of examples that use OpenGL with
a Cocoa UI.  These examples also require `PyOpenGL`__.

.. _`OpenGL`: OpenGL
.. __: http://pyopengl.sourceforge.net/

* `OpenGLDemo`__

  A simple program that shows how to use OpenGL in a Cocoa program.  It is a 
  port of Apple's "CocoaGL" example.

.. __: OpenGL/OpenGLDemo


Plugins
-------

The directory `Plugins`__ contains a number of examples that embed a Python
plugin into another application.  Note that due to an implementation detail
of the py2app bundle template, these plugins are only compatible with
Mac OS X 10.3 and later.

.. __: Plugins

* `EnvironmentPrefs`__

  This ``NSPreferencePane`` can be used to edit the default environment
  for the current user. It also is a simple example of a localized application.

.. __: Plugins/EnvironmentPrefs

* `ProgressViewPalette`__

  A simple InterfaceBuilder palette written in Python.

.. __: Plugins/ProgressViewPalette

* `SillyBallsSaver`__

  A simple screensaver written in Python.

.. __: Plugins/SillyBallsSaver

* `WebKitInterpreter`__
  
  Uses the new WebKit Cocoa plugin API available in Safari 1.3
  and later to embed a PyInterpreter in the browser.

.. __: Plugins/WebKitInterpreter

Twisted Integration
-------------------

The directory `Twisted`_ contains a number of examples that use
`Twisted (2.0 or later)`__ with Cocoa.

.. _`Twisted`: Twisted
.. __: http://www.twistedmatrix.com

* `WebServicesTool`__

  This is a refactor of the WebServicesTool example that is made much simpler
  and faster by using Twisted.

.. __: Twisted/WebServicesTool

* `WebServicesTool-ControllerLayer`__

  This is an even simpler refactor of the Twisted WebServicesTool example that
  uses Cocoa Bindings to remove a lot of the UI related code.

.. __: Twisted/WebServicesTool-ControllerLayer


WebKit
------

The directory `WebKit`__ contains a number of examples that use the ``WebKit``
framework, the HTML rendering engine from Safari.

.. __: WebKit

* `PyDocURLProtocol`__

  This example implements a subclass of ``NSURLProtocol`` that can be used
  to load the ``pydoc`` documentation of a module.

  It also includes a simple documentation browser using ``WebKit`` and the 
  ``PyDocURLProtocol`` class.

.. __: WebKit/PyDocURLProtocol 
 

Some work-in-progress examples
------------------------------

The directory `NonFunctional`__ may contain a number of examples that are not working
for one reason or another. The most likely reason is that example relies on features
that have not yet been implemented.

.. __: NonFunctional