• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Using NSAlert with PyObjc - basics
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using NSAlert with PyObjc - basics


  • Subject: Using NSAlert with PyObjc - basics
  • From: Tobias Prinz <email@hidden>
  • Date: Fri, 12 Sep 2008 16:40:19 +0200

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


My translation to Python is the following. Yes, that's step-by-step print-debugging, ugly, but it should run everywhere this way. Well since it does not run at all, it should get stuck everywhere (but well- documented):

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()



I am using Mac OS X 10.5.4.

What happens is that after executing this code (both via Eclipse and from the shell):

a) I get to see the rocket icon which symbolizes a Python process. The icon bounces a bit like pacman on crack, then stops moving after a while.

b) I see the output:
Step A1
Step A2
Step A3
Step B1
Step B2
Step B3
Step B4
Step B5
Step B6: 0

The process keeps running. If I cancel it, I get a lengthy error log. The pop-up is nowhere around. Is there something different I have to do to get Objective-C appkit stuff running in Python? Maybe I missed some basics, but until now I haven't found a tutorial geared towards Mac GUIs in Python/PyObjC. So if one of you can give me some directions, I'd appreciate that very much.

Kind regards,
Tierlieb

P.S.: I searched for NSAlert on the list an did not find a single e- mail. Weird... or am I using the wrong list? There is no AppKit group around, so I figure I am right asking here...
_______________________________________________


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


  • Follow-Ups:
    • Re: Using NSAlert with PyObjc - basics
      • From: Tobias Prinz <email@hidden>
  • Prev by Date: Two Dimensional Array
  • Next by Date: NSArrayController's canRemove controllerkey and toolbar items problem
  • Previous by thread: Re: Two Dimensional Array
  • Next by thread: Re: Using NSAlert with PyObjc - basics
  • Index(es):
    • Date
    • Thread