Re: Using NSAlert with PyObjc - basics
Re: Using NSAlert with PyObjc - basics
- Subject: Re: Using NSAlert with PyObjc - basics
- From: Tobias Prinz <email@hidden>
- Date: Tue, 16 Sep 2008 15:39:46 +0200
Am 12.09.2008 um 16:40 schrieb Tobias Prinz:
Hello there,
I am trying to display a little pop-up using NSAlert. I've used a
fairly standard snippet from this page (which is written in German,
plus it is ObjC code): http://cocoa-coding.de/nsalert/nsalert.html
As far as I know, my message has been awaiting moderation for five
days and has not been posted. But some archives seem to list it
anyway, so for their sake I'll post the solution which I found in the
meantime.
It is simply a different way of starting the application. It has to be
a NSApp, otherwise it won't get the rights to display itself, it seems
to me.
Here is the corrected code. If this is messed up, have a look at
http://www.tobias-prinz.de/index.php/Python#PyObjC And NSAlert
Kind regards,
Tobias "Tierlieb" Prinz
Correct code:
import objc
from AppKit import *
from Foundation import *
class MessageTest(object):
def createAlert_(self, timer):
print "Step B1"
alert = NSAlert.alloc().init()
print "Step B2"
alert.setMessageText_("Important message")
print "Step B3"
alert.setInformativeText_("Please listen, this is a very
important message!")
print "Step B4"
alert.setAlertStyle_(NSInformationalAlertStyle)
print "Step B5"
buttonPressed=alert.runModal();
print "Step B6: " + str(buttonPressed)
def startRunLoop(self):
print "Step A1"
NSTimer
.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1,
self, 'createAlert:', "", False)
print "Step A2"
NSApplication.sharedApplication() # Connect me to the Window
Manager
print "Step A3"
NSApp.run() # Start the applications RunLoop
print "Step A4"
MessageTest().startRunLoop()
Wrong code:
Code:
import objc
from AppKit import *
from Foundation import *
class MessageTest(object):
def createAlert_(self, timer):
print "Step B1"
alert = NSAlert.alloc().init()
print "Step B2"
alert.setMessageText_("Important message")
print "Step B3"
alert.setInformativeText_("Please listen, this is a very
important message!")
print "Step B4"
alert.setAlertStyle_(NSInformationalAlertStyle)
print "Step B5"
buttonPressed=alert.runModal();
print "Step B6: " + str(buttonPressed)
def startRunLoop(self):
print "Step A1"
NSTimer
.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1,
self, 'createAlert:', "", False)
print "Step A2"
runLoop = NSRunLoop.currentRunLoop()
print "Step A3"
runLoop.run()
print "Step A4"
MessageTest().startRunLoop()
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden