• 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
Re: Cocoa Python broken in Leopard??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Python broken in Leopard??


  • Subject: Re: Cocoa Python broken in Leopard??
  • From: Bill Bumgarner <email@hidden>
  • Date: Wed, 7 Nov 2007 09:46:03 -0800

On Nov 7, 2007, at 9:04 AM, Uliano Guerrini wrote:
Il giorno 07/nov/07, alle ore 17:48, Bill Bumgarner ha scritto:
Import Quartz *after* the application's main event loop has been started, either in applicationDidFinishLaunching_() as I demonstrated in my first message:

class FoobarAppDelegate(NSObject):
  def applicationDidFinishLaunching_(self, sender):
      import Quartz

this is useless as the scope of that import is limited to that function in that file

The overhead for re-importing is not much.

Or import it as the first line of the drawRect_() method of your view.

I found a better (much efficient, I hope) workaround:

Quartz = None

class MyView(NSView):
   def awakeFromNib(self):
       global Quartz
       Quartz = __import__('Quartz')

   def drawRect_(self, rect):
       context = NSGraphicsContext.currentContext().graphicsPort()
       Quartz.whatever()

here the import happens to be called only once per class and Quartz is global to the whole file. Still it is not elegant but I can live with it

That isn't a workaround. That is one solution. There isn't really a bug here. This is just the way Python works -- some modules are designed such that their import has dependencies on certain other state pre-existing. Quartz is one of them.


Alternatively, if MyView exists as a part of an NSDocument, you could import MyView as a part of the NSDocument document loading mechanism. Since the class will be created in the ObjC runtime and instantiated by the loading of the NSDocument's NIB, no need to jump through the global/__import__hoops as per above (which, btw, are just fine and I'll add 'em to my recipes).

b.bum

_______________________________________________

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


References: 
 >Cocoa Python broken in Leopard?? (From: Uliano Guerrini <email@hidden>)
 >Re: Cocoa Python broken in Leopard?? (From: Bill Bumgarner <email@hidden>)
 >Re: Cocoa Python broken in Leopard?? (From: Uliano Guerrini <email@hidden>)
 >Re: Cocoa Python broken in Leopard?? (From: Bill Bumgarner <email@hidden>)
 >Re: Cocoa Python broken in Leopard?? (From: Uliano Guerrini <email@hidden>)
 >Re: Cocoa Python broken in Leopard?? (From: Bill Bumgarner <email@hidden>)
 >Re: Cocoa Python broken in Leopard?? (From: Uliano Guerrini <email@hidden>)

  • Prev by Date: Re: Enabling cut and paste in modal window
  • Next by Date: Re: custom menu for NSPopUpButton
  • Previous by thread: Re: Cocoa Python broken in Leopard??
  • Next by thread: Re: Cocoa Python broken in Leopard??
  • Index(es):
    • Date
    • Thread