Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 571 lines (397 sloc) 10.82 kb
61b460dd »
2004-12-10 initial import
1 60 Minutes of MacPython
2 -----------------------
3
4 Author
5 Bob Ippolito
6
7 Conference
8 PyCon DC, March 2004
9
10 Intended Audience
11 -----------------
12
13 - Python developers using Mac OS X 10.2 or later
14 - Spies from the Linux and Win32 camps
15
16 Topics
17 ------
18
19 - What is MacPython?
20 - MacPython IDEs
21 - Darwin
22 - Apple Events
23 - Cocoa
24 - Cross-Platform
25 - Community
26 - What's Next
27
28 What is MacPython?
29 ------------------
30
31 - It's just Python
32 - Compiled from the same Python source tree
33
34 MacPython's Past
35 ----------------
36
37 - MacPython was for "Classic" MacOS
38 - Guido used to own a Mac
39 - ... then Jack took over
40 - Uses WASTE for text widgets
41 - ... and GUSI to act more like \*NIX
42 - Still exists, but not as actively maintained
43 - ... though apparently it does have *some* users
44
45 MacPython Now
46 -------------
47
48 - Has some rough edges
49 - ... but we're working on it!
50 - Inherits the good stuff from BSD
51 - Has many new APIs of its own
52 - Ancient MacOS code happens to work
53 - ... and we still use a lot of it
54
55 MacPython Tools
56 ---------------
57
58 BuildApplet
59 Turns simple scripts into applications
60 PackageManager
61 Installs a few packages from a central db
62 PythonLauncher
63 Allows double-clicking of .py files
64 PythonIDE
65 Old MacOS IDE, unmaintained
66
67 ... all of these are being replaced!
68
69 How do I get it?
70 ----------------
71
72 **OS X 10.2**
73
74 - DO NOT USE Apple Python 2.2.0
75 - Get MacPython-Jaguar 2.3
76
77 **OS X 10.3**
78
79 - PLEASE USE Apple Python 2.3.0
80 - ... and don't install any other Python
81 - Also get the MacPython-Addons
82
83 MacPython IDEs
84 --------------
85
86 - General Purpose IDEs
87 - Aqua Python IDEs
88 - Other Python IDEs
89
90 Emacs
91 -----
92
93 .. image:: ../Emacs.jpg
94
95 Vim
96 ---
97
98 .. image:: ../Vim.jpg
99
100 SubEthaEdit
101 -----------
102
103 .. image:: ../SubEthaEdit.jpg
104
105 Xcode
106 -----
107
108 .. image:: ../Xcode.jpg
109
110 BBEdit
111 ------
112
113 .. image:: ../BBEdit.jpg
114
115 PythonIDE
116 ---------
117
118 .. image:: ../PythonIDE.jpg
119
120 PyOXIDE
121 -------
122
123 .. image:: ../PyOXIDE.jpg
124
125 X11 Python Editors are Ugly
126 ---------------------------
127
128 .. image:: ../WingIDE.jpg
129
130 Cross-Platform Toolkits Are Broken
131 ----------------------------------
132
133 .. image:: ../IDLETclTkAqua.jpg
134
135 Darwin
136 ------
137
138 .. image:: ../darwin.jpg
139
140 - os.name == 'posix' ... but it's not quite BSD
141 - Forking Files
142 - Three Flavors of Property Lists
143 - Objective C?
144 - Bundles Bundles Bundles
145
146 os.name == 'posix'
147 ------------------
148
149 **So, it is a \*NIX?**
150
151 - Typically acts like any other BSD
152 - Especially in modules such as os, sys, socket
153 - ... but there's a lot more to it
154
155 ... but it's not quite BSD
156 --------------------------
157
158 **HFS+ Thinks Different**
159
160 - Case insensitive file system
161 - Files can have multiple forks
162
163 **Inherited from NeXT**
164
165 - XML property lists for configuration
166 - Bundles and Frameworks
167 - dyld is not your average linker
168 - Tons of new APIs
169
170 Forking Files
171 -------------
172
173 **Resource forks are Not For POSIX**
174
175 - Files may have a resource fork
176 - Not really useful without Carbon APIs
177 - POSIX layer sees only the data fork!
178 - Be careful not to lose them when copying files!
179
180 **But you can get at one if you need to**::
181
182 file(filename + '../namedfork/rsrc')
183
184 Three Flavors of Property Lists
185 -------------------------------
186
187 * Binary
188 * Text
189 * XML
190
191 Binary Property Lists
192 ---------------------
193
194 - Deprecated, but still used
195 - Object serialization (pickle)
196 - Old Nib files (GUI pickle)
197
198 ::
199
200 >>> open('keyedobjects.nib').read()
201 'bplist00\xd4\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07
202 \x00\nY$archiverX$versionT$topX$objects_\x10\x0fNSKeyedArchiver\x12\x00
203 \x01\x86\xa0\xd1\x00\x08\x00\t]IB.objectdata\x80\x01\xaf\x11\x04#\x00
204 \x0b\x00\x0c\x00+\x00/\x003\x00:\x00=\x00?\x00C\x00G\x00\xa5\x00\xab\x00
205 \xbb\x00\xc2\x00\xc3\x00\xc4\x00\xc9\x00\xca\x00\xcb\x00\xcf\x00\xd1\x00
206 \xd2\x00\xd5\x00\xd7\x00\xdb\x00\xde\x00\xe1\x00\xe2\x00\xe3\x00\xe5\x00
207 \xe8\x00\xec\x00\xef\x00\xf0\x00\xf1\x00\xf3\x00\xf7\x00\xfb\x00\xff\x01
208 \x00\x01\x01\x01\x03\x01\x06\x01\n\x01\x0b\x01\x0c\x01\r\x01\x10\x01\x13
209 \x01\x0b\x01\x14\x01\x15\x01\x18\x01\x1a\x01\x1b\x01\x1c\x01 \x01#\x01$
210 ...'
211
212 Text Property Lists
213 -------------------
214
215 - Deprecated, but still used
216 - Looks sort of like YAML
217 - StartupItems (like /etc/init.d)
218
219 ::
220
221 {
222 Description = "uControl";
223 Provides = ("uControl");
224 /* depend on something so that we don't come too early */
225 Requires = ("Resolver");
226 OrderPreference = "None";
227 Messages = {
228 start = "Starting uControl";
229 stop = "Stopping uControl";
230 };
231 }
232
233
234 XML Property Lists
235 ------------------
236
237 - Preferred
238 - Dictionary serialization
239 - Preference files (~/Library/Preferences)
240 - Info.plist in every application bundle
241 - New Nib files (GUI pickle)
242
243 ::
244
245 <?xml version="1.0" encoding="UTF-8"?>
246 <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
247 <plist version="0.9">
248 <dict>
249 <key>CFBundleDevelopmentRegion</key>
250 <string>English</string>
251 <key>CFBundleDocumentTypes</key>
252 <array>
253 <dict>
254 <key>CFBundleTypeOSTypes</key>
255 <array>
256 <string>****</string>
257
258
259
260 Apple's Property List Editor
261 ----------------------------
262
263 .. image:: ../loginwindowplist.jpg
264
265 plistlib Example
266 ----------------
267
268 **Using plistlib to find the name of the last logged in user**::
269
270 >>> import plistlib
271 >>> filename = '/Library/Preferences/com.apple.loginwindow.plist'
272 >>> plist = plistlib.Plist.fromFile(file(filename))
273 >>> plist['lastUserName']
274 'bob'
275
276 **Limitations**:
277
278 - Only works for XML plist files!
279 - Not very good at handling dates
280 - Might not be unicode safe
281
282 NSDictionary Example
283 --------------------
284
285 **Using PyObjC to find the name of the last logged in user**::
286
287 >>> from Foundation import NSDictionary
288 >>> filename = u'/Library/Preferences/com.apple.loginwindow.plist'
289 >>> plist = NSDictionary.dictionaryWithContentsOfFile_(filename)
290 >>> plist['lastUserName']
291 u'bob'
292
293 **Limitations**:
294
295 - Requires PyObjC to be installed
296 - ... but PyObjC is awesome, so get it!
297
298 Why Objective C
299 ---------------
300
301 - Comes from NeXT
302 - Apple has a lot of great frameworks that use it
303 - ... like Cocoa and Foundation
304
305 Objective C Portability
306 -----------------------
307
308 - The GNUStep project uses it too
309 - ... and PyObjC is portable to GNUStep
310 - GNUStep works on Win32
311 - ... but doesn't have a decent backend
312
313 What is Objective C
314 -------------------
315
316 - Mostly just C, but with [some new:syntax]
317 - ... and a very dynamic runtime (sound familiar?)
318 - Simpler than C++, similar to Smalltalk
319
320 PyObjC
321 ------
322
323 - Plays along VERY nicely with Python
324 - ... if you have PyObjC, of course
325
326 Bundles are like Packages
327 -------------------------
328
329 - They have a fixed directory structure
330 - General purpose (documents, code, resources)
331 - Localization features baked in
332 - Most look like a single file from Finder
333 - All applications should be bundles
334 - ... and they need to be to use the GUI
335
336 PackageManager.app, dissected
337 -----------------------------
338
339 .. image:: ../packmanbundle.jpg
340
341 - Bootstrap code in MacOS folder
342 - Python code and resources in Resources folder
343 - Info.plist and PkgInfo are required metadata
344
345 /usr/bin/pythonw
346 ----------------
347
348 **The Way to run GUI scripts**
349
350 - GUI-enabled scripts can use the pythonw command
351 - ... it tricks WindowServer
352 - ... pretends to be running from the Python application bundle
353 - Unfortunately, not very useful for Cocoa applications
354
355 bundlebuilder
356 -------------
357
358 **The Way to make Python-based Applications**
359 ... for now
360
361 - Standard MacPython module
362 - Similar in purpose to py2exe or freeze
363 - Similar in API to distutils, but not (yet) integrated
364 - Documented at the pythonmac.org wiki
365 - ... but something better is coming soon
366
367 Document Bundles
368 ----------------
369
370 **Documents**
371
372 - Interface Builder nibs
373 - OmniGraffle
374 - Keynote
375 - TextEdit
376 - ... most other Cocoa applications
377
378 Code Bundles
379 ------------
380
381 **Frameworks**
382
383 - Versioned
384 - Shared Libraries
385 - Headers
386 - Other data
387
388 **Other Code**
389
390 - StartupItems
391 - Plugins
392 - Preference Panes
393
394 Apple Events
395 ------------
396
397 .. image:: ../aehighlevel.jpg
398
399 - What are Apple Evevnts?
400 - Apple Script
401 - Python and Apple Events
402
403 What are Apple Events?
404 ----------------------
405
406 - Interapplication Communication
407 - Many, but not all, applications support it
408 - Used primarily for automation tasks
409 - Very old, low level
410 - Difficult API
411 - ... except from Apple Script
412 - ... or from Cocoa
413
414 Apple Script
415 ------------
416
417 .. image:: ../applescript_simple.jpg
418
419 - Looks easy enough, but it's not Python!
420 - It's crufty, slow, and doesn't scale
421 - One of the few "read only" languages ;)
422
423 Python and Apple Events
424 -----------------------
425
426 Carbon
427 You may as well write it in assembly!
428 gensuitemodule
429 Really old, has limitations, on its way out
430 aeve
431 Pythonic bridge, development on hold
432 appscript
433 Closer to Apple Script, actively developed
434
435 appscript and Finder
436 --------------------
437
438 **The URL of the current user's Desktop**::
439
440 >>> from appscript import *
441 >>> finder = app('Finder.app')
442 >>> finder.desktop.URL.get()
443 u'file://localhost/Users/bob/Desktop/'
444
445 appscript and iTunes
446 --------------------
447
448 **Finding the artist of the song "Python Patrol"**::
449
450 >>> from appscript import *
451 >>> library = app('iTunes.app').sources[1].playlists[1]
452 >>> mytrack = library.tracks.test(its.name == u'Python Patrol')[1]
453 >>> mytrack.artist.get()[0]
454 u'GI Joe Killaz'
455
456 Cocoa
457 -----
458
459 .. image:: ../cocoa.jpg
460
461
462 ReSTedit
463 --------
464
465 .. image:: ../ReSTedit.jpg
466
467 Zope Edit Manager
468 -----------------
469
470 .. image:: ../ZopeEditManager.jpg
471
472 DrawBot
473 -------
474
475 .. image:: ../DrawBot.jpg
476
477 This Is What Happens
478 --------------------
479
480 .. image:: ../drawbot00.jpg
481
482 When You Teach Python
483 ---------------------
484
485 .. image:: ../drawbot01.jpg
486
487 To Graphic Designers
488 --------------------
489
490 .. image:: ../drawbot02.jpg
491
492 In A Simple Way
493 ---------------
494
495 .. image:: ../drawbot03.jpg
496
497 That They Understand
498 --------------------
499
500 .. image:: ../drawbot04.jpg
501
502 PyInterpreter
503 -------------
504
505 .. image:: ../PyInterpreter.jpg
506
507 It Really Is Easy
508 -----------------
509
510 **This is where you get to see me use Xcode**
511
512 "Cross-Platform" Toolkits
513 -------------------------
514
515 **MOST OF THEM ARE NOT READY YET!**
516
517 - Tkinter is buggy
518 - PyQt is buggy
519 - wxPython is buggy
520
521 **So why not just use Cocoa, it's easy!**
522
523 pygame
524 ------
525
526 .. image:: ../pygame.jpg
527
528 PyOpenGL
529 --------
530
531 .. image:: ../PyOpenGL.jpg
532
533 wxPython
534 --------
535
536 .. image:: ../wxPython.jpg
537
538 Tkinter
539 -------
540
541 .. image:: ../IDLETclTkAqua.jpg
542
543 PyQt
544 ----
545
546 **It's probably still building.**
547
548 ... but it does work. somewhat.
549
550 And of course, X11 is still ugly
551 --------------------------------
552
553 .. image:: ../WingIDE.jpg
554
555 Community
556 ---------
557
558 - pythonmac-sig
559 - pythonmac.org
560 - MacPython channel
561 - Various blogs
562
563 The Future
564 ----------
565
566 **New tools!**
567
568 Questions?
569 ----------
570
571 **Go ahead, ask.**
Something went wrong with that request. Please try again.