Re: Tasks
Wezzy <[email protected]> Fri, 20 Feb 2004 15:59:44 +0100
| Newsgroups | gmane.comp.python.anygui.devel |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail-2-197737156
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Il giorno 20/feb/04, alle 13:27, Matthew Schinckel ha scritto:
> There are no stupid questions, only stupid answers...
>
> I've spent the last couple of hours looking for info about the MacOS
> interface(s). Here is my summary:
>
> There is already a group of (apple supplied?) shared libraries that
> provide a Carbon interface. This is on standard python OSX install.
> (?)
> I'm not sure if there is a similar thing for Cocoa.
> I'm still learning the difference ;)
> [edit]Cocoa might be better, since Carbon is partly a legacy thing,
> but Carbon apps might run in OS9. Care?[/edit]
> I need to source the Learning Carbon and/or Learning Cocoa books from
> O'Reilly, since I can't stay connected to the internet to look at
> Apple's docs all day and night.
If you install XCode CD you've got all the apple documentation and some
tutorial for Cocoa's beginners ( ithink that thare are also Carbon
tutorials but i've never studied Carbon). I have two books about Cocoa
:
Learning Cocoa With Objective-C from O'Reilly
Cocoa Programming from Sams.
The first is an introduction for beginners, it is a good book really
easy that explains lot of concepts but if you don't have any problem
with studing on screen you can read the same information into the
/Developer/Documentation directory.
The second is a reference, it is really good because it have a lot of
triks and useful suggestion.
> Someone has created a Python thingo for Xcode, Apple's Development
> Environment. This might allow for direct creation of MacOS X apps in
> python! (Sorry, i got excited about that bit!)
With pyobjc you have some scripts that create OS X app.
> PyObjC exists also. (Allows use of Objective-C [MacOS X standard
> language] bits in python)
Probably this is the best choice. If you learn Cocoa with ObjC
translate the code into Python is very easy and your scripts looks like
a native application. As you noticed with Cocoa we loose os9 support
but i also Apple doesn't support it.
> Apple have included stuff for Quartz access, which allows for graphics
> handling, but, IIUC (if I understand correctly) not for UI stuff.
You don't have to use Quarts directly for GUI. Cocoa (or Quartz) hides
it and helps you a lot with GUI.
> [OT]Running limewire causes safari to fail on dns lookups.[/OT]
> pythonmac.wiki.org has some good information...
>
The best resource for Cocoa is Cocoa-dev ML, look at Apple Developer
site.
I've done some experiment with cocoa application without nibs. Building
Cocoa Application
(http://www.oreilly.com/catalog/buildcocoa/index.html?CMP=IL7015)
explains how to create an app only with code (without IB). i've
downloaded chapter's examples and translate them. I hope that they can
be a useful resource.
Fabio "Wezzy" Trezzi
--Apple-Mail-2-197737156
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="Tiny2.m"
Content-Disposition: attachment;
filename=Tiny2.m
/* Tiny2.m
*
* A tiny Cocoa application which creates a
* a window and displays graphics in it.
*
* (C) 2002 by Simson L. Garfinkel and Michael K. Mahoney.
* all rights reserved.
*/
#import <Cocoa/Cocoa.h>
/****************************************************************
** The CView draws the image.
****************************************************************/
@interface CView : NSView
{
}
- (void)drawRect:(NSRect)rect;
- (void)mouseDown:(NSEvent *)theEvent;
- (void)windowWillClose:(NSNotification *)notification;
@end
@implementation CView
- (void)drawRect:(NSRect)rect
{
/* Clear the background */
[[NSColor whiteColor] set];
NSRectFill([self bounds]);
}
-(void)windowWillClose:(NSNotification *)notification
{
[NSApp terminate:self];
}
- (void)mouseDown:(NSEvent *)theEvent
{
NSRect r;
r.origin = [theEvent locationInWindow];
r.origin.x -= 5;
r.origin.y -= 5;
r.size.width = 10;
r.size.height = 10;
[[NSColor blackColor] set];
[self lockFocus];
[NSBezierPath fillRect:r];
[self unlockFocus];
[[self window] flushWindow];
}
@end
void setup()
{
NSWindow *myWindow;
NSView *theView;
NSRect graphicsRect;
/* Now create the window */
graphicsRect = NSMakeRect(100.0, 350.0, 400.0, 400.0);
myWindow = [ [NSWindow alloc]
initWithContentRect: graphicsRect
styleMask: NSTitledWindowMask
|NSClosableWindowMask
|NSMiniaturizableWindowMask
backing: NSBackingStoreBuffered
defer: NO];
[myWindow setTitle:@"Tiny Application Window"];
/* Create the CView for the Window. */
theView = [ [CView alloc] init];
[myWindow setContentView:theView ];
[myWindow setDelegate:theView ];
[myWindow makeKeyAndOrderFront: nil];
}
int main()
{
/* Create the autorelease pool */
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
/* Create the application object. */
NSApp = [[NSApplication alloc] init];
setup();
/* run the main event loop */
[NSApp run];
/* We get here when the user closes the window. */
[NSApp release]; /* free the app */
[pool release]; /* release the autorelease pool */
return(EXIT_SUCCESS);
}
--Apple-Mail-2-197737156
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="Tiny2.py"
Content-Disposition: attachment;
filename=Tiny2.py
# Tiny2.m
#
# A tiny Cocoa application which creates a
# a window and displays graphics in it.
# (C) 2002 by Simson L. Garfinkel and Michael K. Mahoney.
# all rights reserved.
#Traslated to Python by Fabio "Wezzy" Trezzi
from AppKit import *
import sys
global myWindow
global app
class CView(NSView):
"Main View"
def drawRect_(self,rect):
"Clear the background"
NSColor.whiteColor().set()
NSRectFill(super(CView,self).bounds())
def windowWillClose_(self,notification):
"Exit Program"
#sys.exit("You have closed the main window")
global app
app.terminate_(self)
def mouseDown_(self,theEvent):
"Draw"
r_origin = theEvent.locationInWindow()
r = ((r_origin[0]-5,r_origin[1]-5),(10,10))
NSColor.blackColor().set()
self.lockFocus()
NSBezierPath.fillRect_(r)
self.unlockFocus()
myWindow.flushWindow()
def setup():
"Now create the window"
global myWindow
graphicsRect = ((100,350),(400,400))
myWindow = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(graphicsRect,(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask),NSBackingStoreBuffered,0)
myWindow.setTitle_("Tiny Application Window")
#Create the CView for the Window
theView = CView.alloc().init()
myWindow.setContentView_(theView)
myWindow.setDelegate_(theView)
#myWindow.makeKeyAndOrderFront_(None)
if(__name__ == "__main__"):
global myWindow
global app
app = NSApplication.sharedApplication()
setup()
app.runModalForWindow_(myWindow)
--Apple-Mail-2-197737156--
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click