pyobjc-dev Mailing List for PyObjC (Page 50)
Brought to you by:
ronaldoussoren
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(9) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(1) |
Feb
(2) |
Mar
(3) |
Apr
(30) |
May
(18) |
Jun
|
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2002 |
Jan
(7) |
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
(3) |
Jul
(13) |
Aug
|
Sep
(23) |
Oct
(180) |
Nov
(291) |
Dec
(95) |
| 2003 |
Jan
(338) |
Feb
(352) |
Mar
(97) |
Apr
(46) |
May
(226) |
Jun
(184) |
Jul
(145) |
Aug
(141) |
Sep
(69) |
Oct
(161) |
Nov
(96) |
Dec
(90) |
| 2004 |
Jan
(66) |
Feb
(87) |
Mar
(98) |
Apr
(132) |
May
(115) |
Jun
(68) |
Jul
(150) |
Aug
(92) |
Sep
(59) |
Oct
(52) |
Nov
(17) |
Dec
(75) |
| 2005 |
Jan
(84) |
Feb
(191) |
Mar
(133) |
Apr
(114) |
May
(158) |
Jun
(185) |
Jul
(62) |
Aug
(28) |
Sep
(36) |
Oct
(88) |
Nov
(65) |
Dec
(43) |
| 2006 |
Jan
(85) |
Feb
(62) |
Mar
(92) |
Apr
(75) |
May
(68) |
Jun
(101) |
Jul
(73) |
Aug
(37) |
Sep
(91) |
Oct
(65) |
Nov
(30) |
Dec
(39) |
| 2007 |
Jan
(24) |
Feb
(28) |
Mar
(10) |
Apr
(2) |
May
(18) |
Jun
(16) |
Jul
(21) |
Aug
(6) |
Sep
(30) |
Oct
(31) |
Nov
(153) |
Dec
(31) |
| 2008 |
Jan
(63) |
Feb
(70) |
Mar
(47) |
Apr
(24) |
May
(59) |
Jun
(22) |
Jul
(12) |
Aug
(7) |
Sep
(14) |
Oct
(26) |
Nov
(5) |
Dec
(5) |
| 2009 |
Jan
(10) |
Feb
(41) |
Mar
(70) |
Apr
(88) |
May
(49) |
Jun
(62) |
Jul
(34) |
Aug
(15) |
Sep
(55) |
Oct
(40) |
Nov
(67) |
Dec
(21) |
| 2010 |
Jan
(60) |
Feb
(17) |
Mar
(26) |
Apr
(26) |
May
(29) |
Jun
(4) |
Jul
(21) |
Aug
(21) |
Sep
(10) |
Oct
(12) |
Nov
(3) |
Dec
(19) |
| 2011 |
Jan
(3) |
Feb
(13) |
Mar
(8) |
Apr
(8) |
May
(17) |
Jun
(20) |
Jul
(21) |
Aug
(7) |
Sep
|
Oct
|
Nov
(9) |
Dec
(11) |
| 2012 |
Jan
(3) |
Feb
|
Mar
|
Apr
(5) |
May
(4) |
Jun
(14) |
Jul
(5) |
Aug
(2) |
Sep
(15) |
Oct
(2) |
Nov
(23) |
Dec
(1) |
| 2013 |
Jan
(8) |
Feb
(1) |
Mar
|
Apr
|
May
(5) |
Jun
(1) |
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(12) |
Nov
(10) |
Dec
(3) |
| 2014 |
Jan
(7) |
Feb
(14) |
Mar
(2) |
Apr
|
May
(2) |
Jun
(11) |
Jul
(10) |
Aug
(4) |
Sep
|
Oct
(8) |
Nov
(1) |
Dec
(2) |
| 2015 |
Jan
(9) |
Feb
(7) |
Mar
(1) |
Apr
|
May
(7) |
Jun
|
Jul
(5) |
Aug
(6) |
Sep
|
Oct
(1) |
Nov
(4) |
Dec
|
| 2016 |
Jan
(1) |
Feb
(1) |
Mar
(4) |
Apr
(2) |
May
(1) |
Jun
|
Jul
(6) |
Aug
(8) |
Sep
(21) |
Oct
(17) |
Nov
|
Dec
(36) |
| 2017 |
Jan
(6) |
Feb
(2) |
Mar
(4) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
(6) |
| 2018 |
Jan
(2) |
Feb
(3) |
Mar
(3) |
Apr
(14) |
May
(2) |
Jun
(2) |
Jul
(4) |
Aug
(3) |
Sep
(6) |
Oct
(16) |
Nov
(1) |
Dec
(6) |
| 2019 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
(6) |
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(2) |
Jun
(1) |
Jul
(7) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(2) |
Dec
(1) |
| 2021 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(5) |
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
|
From: Orestis M. <or...@or...> - 2009-04-05 21:08:20
|
>>> import objc
>>> from Foundation import *
>>> class NSObject(objc.Category(NSObject)):
... "docstring"
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/
Extras/lib/python/PyObjC/objc/_category.py", line 44, in __new__
classAddMethods(c, m)
TypeError: Error when calling the metaclass bases
All objects in methodArray must be of type <objc.selector>,
<function>, <method> or <classmethod>
Tripped me up by the misleading error message :)
Orestis
--
or...@or...
http://orestis.gr/
|
|
From: Ronald O. <ron...@ma...> - 2009-04-05 14:30:47
|
On 4 Apr, 2009, at 19:52, Nico Weber wrote: > Hi, > > I sent this a few days before this list became more active again, so I > dare to repost my question (sorry). I found the question "How do I > handle an FSRef in pyobjc?" in several other places of the web, so I > guess other people would benefit from an answer too. I've added looking into this to my TODO list. There is support for FSRef's in pyobjc-core, but I haven't checked yet if that still works. Ronald |
|
From: Ronald O. <ron...@ma...> - 2009-04-05 14:27:06
|
On 5 Apr, 2009, at 14:58, Orestis Markou wrote: > Hi there, > > I just came across this: http://developer.apple.com/graphicsimaging/pythonandquartz.html > > Which describes a set of nice pythonic APIs for Quartz. Example: > > # step 1: import the required modules > from CoreGraphics import * > import math > > > > I was wondering if this is: > > a) Part of PyObjC (it seems not) No > b) up-to-date Don't know > c) recommended to use I don't use it because... > d) open-source No, and hence only useable with Apple's build of Python. It also seems to implement an extended subset of the C API for CoreGraphics, and I'm not sure if all of the implementation uses public API's. This API is the primary reason why the PyObjC bindings to CoreGraphics are named Quartz.CoreGraphics, I had to pick a different name to avoid a nameclash. Ronald |
|
From: Orestis M. <or...@or...> - 2009-04-05 12:58:57
|
Hi there, I just came across this: http://developer.apple.com/graphicsimaging/pythonandquartz.html Which describes a set of nice pythonic APIs for Quartz. Example: # step 1: import the required modules from CoreGraphics import * import math # step 2: create the bitmap context # NOTE: on Panther use cs = CGColorSpaceCreateDeviceRGB() cs = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) c = CGBitmapContextCreateWithColor( 256, 256, cs, (0,0,0,0) ) # step 3: draw a yellow square with a red outline c.saveGState() c.setRGBStrokeColor(1,0,0,1) # red c.setRGBFillColor(1,1,0,1) # yellow c.setLineWidth(3) c.setLineJoin(kCGLineJoinBevel) c.addRect( CGRectMake( 32.5, 32.5, 191, 191 ) ) c.drawPath( kCGPathFillStroke ); c.restoreGState() # step 4: write out the file in PNG format c.writeToFile ("out.png", kCGImageFormatPNG) I was wondering if this is: a) Part of PyObjC (it seems not) b) up-to-date c) recommended to use d) open-source Any ideas? Thanks, Orestis -- or...@or... http://orestis.gr/ |
|
From: Orestis M. <or...@or...> - 2009-04-04 20:00:09
|
On 4 Apr 2009, at 20:52, Ronald Oussoren wrote: > > On 4 Apr, 2009, at 19:47, Orestis Markou wrote: > >> Woo my first bug! Should I file a ticket about it? If you give me a >> pointer on where it should live I may be able to write a test... > > I've already fixed in a simple testcase that triggers the bug. > > Ronald Out of curiosity, how do you manage test runs that may crash? Is there a buildbot running PyObjC or do you just run the tests manually? We're looking to setup a buildbot to test PyObjC code and perhaps there's some insights you can share. IME, PyObjC programs are a bit hard to test, for example, there's no easy way to cleanly launch and close an application. Of course, a lot of this has nothing to do with PyObjC but with Obj-C and Mac OS X. Another very annoying thing is having (for practical reasons) to do "from somewhere import *". I've also found that using mock[1] and its "patch" method, that monkey-patches a namespace lead to a bus error, which was very unusual. I'll see if I can reproduce that... Any suggestions on testing PyObjC programs welcome! Orestis [1]: http://pypi.python.org/pypi/mock |
|
From: Ronald O. <ron...@ma...> - 2009-04-04 19:53:12
|
On 4 Apr, 2009, at 19:47, Orestis Markou wrote: > Woo my first bug! Should I file a ticket about it? If you give me a > pointer on where it should live I may be able to write a test... I've already fixed in a simple testcase that triggers the bug. Ronald |
|
From: Nico W. <nic...@gm...> - 2009-04-04 17:52:41
|
Hi, I sent this a few days before this list became more active again, so I dare to repost my question (sorry). I found the question "How do I handle an FSRef in pyobjc?" in several other places of the web, so I guess other people would benefit from an answer too. Nico On 31.01.2009, at 20:00, Nico Weber wrote: > Hi, > > I want to load a font from a ttf file and then draw some text using > this font, and I want to do that in Python using the PyObjC bridge. > My program already does some drawing; it uses NSBitmapImageReps and > NSGraphicsContext for that. The font I'm trying to load is http://damieng.com/blog/2008/05/26/envy-code-r-preview-7-coding-font-released > . > > If someone has an idea how I could get this to work, please speak up. > > Here's what I tried so far: > > > 1.) Activate the font through ATS, then load it through NSFont > through its postscript name. > > This is what most programs written in ObjC do – they call > ATSFontActivateFromFileReference to load a ttf file and then can use > NSFont to load the font given its postscript name. The problem is > that there seems to be no built-in python binding for ATS. This fails: > > import ATS > > Now, ATS.framework is a subframework in the ApplicationServices > framework, but this fails as well: > > import ApplicationServices > > Fair enough. The pyobjc documentation shows how to write your own > wrapper: > > import objc > b = objc.loadBundle("ApplicationServices", globals(), > bundle_path=objc.pathForFramework(u'/System/Library/Frameworks/ > ApplicationServices.framework/')) > > For reasons I don't quite understand, this doesn't load the ATS > subframework methods, though (might be related that there is no > ATS.bridgesupport in /System/Library/Frameworks/ > ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/ > Versions/A/Resources/BridgeSupport). I tried to create the > bridgesupport file on my own, using > > gen_bridge_metadata -f /System/Library/Frameworks/ > ApplicationServices.framework/Frameworks/ATS.framework -o > ATS.bridgesupport > > This gave some linking errors, and didn't work. `man > gen_bridge_metadata` even says that there might be problems if you > want to create bridgesupport files for subframeworks of umbrella > frameworks, but doesn't really say how to work around them. I tried > explicitly setting special compiler flags with > > gen_bridge_metadata -f /System/Library/Frameworks/ > ApplicationServices.framework/Frameworks/ATS.framework -o > ATS.bridgesupport -c ' -F /System/Library/Frameworks/ > ApplicationServices.framework/Frameworks/ATS.framework -framework > ApplicationServices' > > , but in vain. > > Now, pyobjc has a `loadBundleFunctions` function that can be used to > load functions from a bundle. One of the examples in /Developer/ > Examples/Python/PyObjC/Cocoa/AppKit/PyObjCLauncher/LaunchServices.py > does use this function to load a specific function from a bundle. So > I tried loading ATSFontActivateFromFileReference thusly (in its own > file `myfile.py`): > > import objc > > __bundle__ = objc.loadBundle("ApplicationServices", globals(), > bundle_path=objc.pathForFramework(u'/System/Library/ > Frameworks/ApplicationServices.framework/')) > functions = [( u'ATSFontActivateFromFileReference', > 's^{FSRef=[80C]}II^vIo^I' )] > objc.loadBundleFunctions(__bundle__, globals(), functions) > > (See http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html > for how the type encodings work; you can use `NSLog(@"FSRef*: %s", > @encode(FSRef*));` to let gcc show you the type encoding for a given > type). > > To some extent, this even worked. After `import myfile`, I can call > ATSFontActivateFromFileReference on the `myfile` module. Cool. Now I > need an FSRef of my font to pass it to the function. I tried: > > from Cocoa import * > from CoreFoundation import * > import myfile > > url = NSURL.fileURLWithPath_(u'Envy Code R Bold.ttf') > status, fsref = CFURLGetFSRef(url, None) > > kATSFontContextLocal = 2 > kATSFontFormatUnspecified = 0 > kATSOptionFlagsDefault = 0 > print myfile.ATSFontActivateFromFileReference(fsref, > kATSFontContextLocal, kATSFontFormatUnspecified, None, > kATSOptionFlagsDefault, None) > > However, this fails with the error message "# ValueError: > depythonifying 'pointer', got 'Carbon.File.FSRef'". The problem is > that I claimed that ATSFontActivate... takes a > '^{FSRef=[80C]}' ("pointer to a struct FSRef which is 80 bytes"), > but CFURLGetFSRef returns a Carbon.File.FSRef object instead (which, > as far as I understand, is something from the days before pyobjc). > Now, this object has a `.data()` function that returns the raw 80 > bytes that make up the FSRef as a str, but there seems to be no way > to pass raw data to a function that was loaded through > loadBundleFunctions – so I have a reference to the function and all > data I need to call it, but I can't get my data through the bridge. > > Looks like a dead end (and http://osdir.com/ml/python.pyobjc.devel/2006-12/msg00024.html > seems to agree. Then again, that is a pre-Leopard post). > > > 2.) Load the font through CoreGraphics, then convert it to a > CoreText CTFont, which is toll-free bridged to NSFont, and use that > for drawing. > > CoreGraphics provides a function to load a font from a file, which I > can then convert to a CTFont, which is toll-free bridged to an > NSFont. So I should be able to load a font this way and then use > Cocoa's normal drawInRect_withAttributes_ function to draw it. I > tried: > > from CoreGraphics import * > from CoreText import * > > fontDataProvider = CGDataProviderCreateWithFilename('Envy Code > R.ttf') > customFont = CGFontCreateWithDataProvider(fontDataProvider) > print customFont # looks good so far! > > ctFont = CTFontCreateWithGraphicsFont(customFont, 12.0, None, None) > print CTFontCopyPostScriptName(ctFont) # looks still good > print ctFont > > However, printing the ctFont or using it as an NSFont gives the > error message "<Error>: can't find font object for font id > 13828539." – and after that, even printing the postscript name > returns "(null)". This does also happen when I call the same > functions in an Objective-C program, so this is a limitation of the > Cocoa runtime. Another dead end. > > > 3.) Load the font through CoreGraphics, and also draw the text > through CoreGraphics > > It's possible to get a CoreGraphics context from an > NSGraphicsContext. Then I can set the current font of the cg context > to the font I loaded from the ttf file. The first few steps even work: > > from CoreGraphics import * > from CoreText import * # contains CGContextSetFont for some reason > > fontDataProvider = CGDataProviderCreateWithFilename('Envy Code > R.ttf') > customFont = CGFontCreateWithDataProvider(fontDataProvider) > > cgContext = NSGraphicsContext.currentContext().graphicsPort() > CGContextSetFont(cgContext, customFont) > > Now, CG has a function CGContextShowTextAtPoint that draws a given > string (char*) at a given position into a cg context. Sounds great, > but as it turns out this function doesn't work for fonts loaded from > a file – it only works for activated system fonts loaded through > CGContextSelectFont (source: http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_text/chapter_18_section_4.html > ). There is a function CGContextShowGlyphsAtPoint that works, but > it takes a list of glyphs (indices into the font's glyph table – > which glyph corresponds to which character is font-dependent!). > There is no official function that converts a string to a list of > glyphs for a given font, however. But there is an undocumented > function: CGFontGetGlyphsForUnichars. As this function is > undocumented, we have to load it ourselves again: > > # CoreGraphics is part of the ApplicationServices umbrella > framework > functions = [ > # bool CGFontGetGlyphsForUnichars(CGFontRef, unichar[], > CGGlyph[], size_t); > ( u'CGFontGetGlyphsForUnichars', 'B^{CGFont=}^So^SI'), > ] > > # This gives a bus error btw: > #import CoreGraphics > #objc.loadBundleFunctions(CoreGraphics, globals(), functions) > > AppServices = objc.loadBundle("ApplicationServices", globals(), > bundle_path=objc.pathForFramework(u'/System/Library/ > Frameworks/ApplicationServices.framework/')) > objc.loadBundleFunctions(AppServices, globals(), functions) > > Now, let's try to call it: > > print CGFontGetGlyphsForUnichars(customFont, 'py', None, 2) > > This gives "ValueError: depythonifying 'pointer', got 'str'" as > error. I couldn't figure out how to pass python text to a function > that takes `unichar*`. This is probably possible somehow, but since > this needs undocumented functions anyways, I'm not too happy with > this approach anyway. > > > 4.) Give up, write a small C-based module that calls > ATSFontActivateFromFileReference given an string, call that from > Python, and call it a day > > That's what I ended up doing. It works, but it is strange that this > seems necessary for such mundane a task. > > > Thanks, > Nico |
|
From: Orestis M. <or...@or...> - 2009-04-04 17:47:37
|
Woo my first bug! Should I file a ticket about it? If you give me a pointer on where it should live I may be able to write a test... Orestis -- or...@or... http://orestis.gr/ On 4 Apr 2009, at 17:15, Ronald Oussoren wrote: > This is a clear bug in PyObjC. The bug is still present in the > trunk, although with a different error message. > > Ronald > > On 3 Apr, 2009, at 21:21, Orestis Markou wrote: > >> Hello, >> >> I'm trying to subclass an Objective-C class (CALayer) and add my own >> setValue_forKey_ to observe changes to specific KVC attributes. >> However, I get this obscure message: >> >> TypeError: Error when calling the metaclass bases >> Sorry, cannot create IMP for instances of type >> objc.native_selector >> >> Am I missing something obvious? Here's a minimal repro: >> >> class CrashTest(NSObject): >> def setValue_forKey_(self, v, k): >> pass >> >> I presume that I can use proper KVO to get around this, but I needed >> to subclass anyway, so it seemed like a good solution... >> >> Thanks, >> Orestis >> -- >> or...@or... >> http://orestis.gr/ >> >> >> >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Pyobjc-dev mailing list >> Pyo...@li... >> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > |
|
From: Ronald O. <ron...@ma...> - 2009-04-04 16:15:41
|
This is a clear bug in PyObjC. The bug is still present in the trunk, although with a different error message. Ronald On 3 Apr, 2009, at 21:21, Orestis Markou wrote: > Hello, > > I'm trying to subclass an Objective-C class (CALayer) and add my own > setValue_forKey_ to observe changes to specific KVC attributes. > However, I get this obscure message: > > TypeError: Error when calling the metaclass bases > Sorry, cannot create IMP for instances of type > objc.native_selector > > Am I missing something obvious? Here's a minimal repro: > > class CrashTest(NSObject): > def setValue_forKey_(self, v, k): > pass > > I presume that I can use proper KVO to get around this, but I needed > to subclass anyway, so it seemed like a good solution... > > Thanks, > Orestis > -- > or...@or... > http://orestis.gr/ > > > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
|
From: Orestis M. <or...@or...> - 2009-04-03 20:37:29
|
Hello,
I'm struggling in using registerCFSignature. What I want is to use
CGColorGetComponents that returns a variable length array of floats. I
think that this particular case is fixed in trunk, given that I found
a testcase for it. However, I have to use the stock PyObjC that comes
with Leopard for now, and I'm looking for ways I could update that
signature at runtime.
The closest I got was:
objc.registerCFSignature('CGColorGetComponents', '[3f]',
CGColorGetTypeID())
Unfortunately, I still get a PyObjCPointer and the accompanying error
message.
Is there any way of doing what I want to do?
Thanks,
Orestis
--
or...@or...
http://orestis.gr/
|
|
From: Orestis M. <or...@or...> - 2009-04-03 19:21:09
|
Hello,
I'm trying to subclass an Objective-C class (CALayer) and add my own
setValue_forKey_ to observe changes to specific KVC attributes.
However, I get this obscure message:
TypeError: Error when calling the metaclass bases
Sorry, cannot create IMP for instances of type objc.native_selector
Am I missing something obvious? Here's a minimal repro:
class CrashTest(NSObject):
def setValue_forKey_(self, v, k):
pass
I presume that I can use proper KVO to get around this, but I needed
to subclass anyway, so it seemed like a good solution...
Thanks,
Orestis
--
or...@or...
http://orestis.gr/
|
|
From: Bill B. <bb...@ma...> - 2009-04-03 06:48:32
|
On Apr 2, 2009, at 10:54 PM, Greg Ewing wrote: > Ronald Oussoren wrote: >> Is anyone actually using objc.inject? > I haven't used it so far, but it's cool-sounding enough > that I might want to one day, and I'd be disappointed if > it disappeared from the face of the earth before I got > a chance. > > If you remove it, at least preserve the code somewhere > in case anyone wants to resurrect it. The repository never forgets.... :) b.bum |
|
From: Greg E. <gre...@ca...> - 2009-04-03 05:52:49
|
Ronald Oussoren wrote: > Is anyone actually using objc.inject? I haven't used it so far, but it's cool-sounding enough that I might want to one day, and I'd be disappointed if it disappeared from the face of the earth before I got a chance. If you remove it, at least preserve the code somewhere in case anyone wants to resurrect it. -- Greg |
|
From: Black <py...@bl...> - 2009-04-01 19:33:45
|
On Apr 1, 2009, at 2:34 PM, Thomas Robitaille wrote: >> In fact, displaying a PIL image is pretty simple in OpenGL and the >> whole ObjC side could be side stepped. I'm curious what is meant by >> "displaying a numpy array". There are many ways one could "display" >> an array in OpenGL. If it contains bitmap data then you could just >> use PyOpenGL again. If it is arbitrary data, one could visualize it >> by mapping the values to visual glyphs. There is nothing >> particularly visual about arrays of numbers however, so I'm not >> sure what is meant by "display the contents"... > > I should have been clearer. Essentially, I am reading an image (in > FITS format) using a specific module which stores the image in a > numpy array. I can easily convert this to a PIL image if need be. > > What I would like to do is to show this image inside an interface > with buttons and text fields, which is why I was interested in using > PyObjC to do this rather than pyopengl alone. Since I sent my > original email to this list, I've realized that this could also be > down with a Quartz Composer item inside the interface. > > Which would be easiest, and either way, does anyone know of any > examples of showing an image (from an array, whether numpy or PIL) > inside an interface build in the 'Interface Builder'? I sort of > understand the default PyObjC OpenGL example, but not enough to make > it show an image instead of just a solid color. > > Any advice/examples would be welcome! If you figured out how to do this with Quartz Composer, I'd say go ahead and do it that way, you will probably get more support from the API that way - especially if you've never worked with OpenGL before. OpenGL is pretty much like the C of the graphics world - not exactly the highest level way to do things. That said if you want to go the OpenGL way, you have two basic options: glDrawPixels(), which just rasterizes your image onto the display or Load the image into a texture and map it to a quad. Either one would work, texture mapping is a little more involved, but probably a little more robust. Either way, I'd load your data through PIL - PIL has some nice methods for extracting bits in reasonable formats, which is essential for using either of those techniques. |
|
From: Thomas R. <tho...@gm...> - 2009-04-01 18:35:03
|
> In fact, displaying a PIL image is pretty simple in OpenGL and the > whole ObjC side could be side stepped. I'm curious what is meant by > "displaying a numpy array". There are many ways one could "display" > an array in OpenGL. If it contains bitmap data then you could just > use PyOpenGL again. If it is arbitrary data, one could visualize it > by mapping the values to visual glyphs. There is nothing > particularly visual about arrays of numbers however, so I'm not sure > what is meant by "display the contents"... I should have been clearer. Essentially, I am reading an image (in FITS format) using a specific module which stores the image in a numpy array. I can easily convert this to a PIL image if need be. What I would like to do is to show this image inside an interface with buttons and text fields, which is why I was interested in using PyObjC to do this rather than pyopengl alone. Since I sent my original email to this list, I've realized that this could also be down with a Quartz Composer item inside the interface. Which would be easiest, and either way, does anyone know of any examples of showing an image (from an array, whether numpy or PIL) inside an interface build in the 'Interface Builder'? I sort of understand the default PyObjC OpenGL example, but not enough to make it show an image instead of just a solid color. Any advice/examples would be welcome! Thanks, Thomas |
|
From: Black <py...@bl...> - 2009-04-01 18:12:06
|
On Mar 31, 2009, at 9:38 AM, Ronald Oussoren wrote: > > On 30 Mar, 2009, at 21:28, Thomas Robitaille wrote: > >> Hello, >> >> I have been using Python for a few months, and have now learned how >> to >> use PyObjC in a basic way to design a Cocoa interface (.nib) for a >> python script. >> >> I am interested in displaying a numpy array or PIL image using the >> interface. Is the way to do this to use an OpenGL view? or an Image >> View? Are there examples of such scripts anywhere? I looked at the >> OpenGLDemo.py example, but could not understand how this could be >> used >> to display the contents of an array. >> >> Any advice would be welcome, > > There will be some code to convert to/from PIL images in a future > release of PyObjC, > but I haven't written that code yet and wouldn't mind if someone > send me a patch > for that ;-). I've played on both sides of the fence, I might be able to do something along those lines - but I make no commitments at the moment, I'm pretty busy right now. > > A kludgy way to display a PIL image is to convert the image to a > string and then > create an NSImage from that. > > I have no personal experience with numpy or OpenGL. AFAIK the OpenGL > stuff > works almost completely through PyOpenGL and the Cocoa bindings in > Cocoa > are just a way to represent a regular OpenGL canvas as a Cocoa object. Yes, the OpenGL stuff just works with PyOpenGL. In fact, displaying a PIL image is pretty simple in OpenGL and the whole ObjC side could be side stepped. I'm curious what is meant by "displaying a numpy array". There are many ways one could "display" an array in OpenGL. If it contains bitmap data then you could just use PyOpenGL again. If it is arbitrary data, one could visualize it by mapping the values to visual glyphs. There is nothing particularly visual about arrays of numbers however, so I'm not sure what is meant by "display the contents"... > > That btw. would be another nice contribution to PyObjC: write an > OpenGL example > that does something more interesting than displaying a solid color. > I guess a rotating > teapot would be appropriate for such an example. I might also be able to provide this. I've certainly done some PyObjC / OpenGL work, and as mentioned above, once you have the context, there is very little that is ObjC related. Again no promises, but I'll put it on my list. > Ronald >> >> Thanks, >> >> Thomas >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Pyobjc-dev mailing list >> Pyo...@li... >> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > > ------------------------------------------------------------------------------ > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
|
From: Ronald O. <ron...@ma...> - 2009-03-31 23:30:08
|
On 31 Mar, 2009, at 17:40, Greg Ewing wrote: > Orestis Markou wrote: > >> pythonw does display the dock icon (and virtualenv doesn't copy that, >> I'll raise an issue). I'm more interested in having a menubar so I >> can >> press command-Q to exit. > > I don't know what's up with that. Even using pythonw, > I've never been able to get the stock Quit menu item that > the interpreter gives you to work. In PyGUI I'm creating > all of my own menus (including the application menu) and > handling them myself. That doesn't surprise me at all. You get the Quit menu item for free, but as Python doesn't run an eventloop itself it won't notice that the menu-item is selected. That's why you have to run your own eventloop to get nice gui behaviour. > >> For some reason ctrl-c doesn't work, even when >> using the relevant AppHelper method >> (AppHelper.installMachInterrupt()). > > Control-backslash in the Terminal window seems to work > for me (I think that sends a SIGQUIT instead of a SIGINT). IIRC CTRL+C only works when your application hits Python once in a while. Ronald |
|
From: Ronald O. <ron...@ma...> - 2009-03-31 23:23:00
|
On 31 Mar, 2009, at 18:02, Greg Ewing wrote: > Ronald Oussoren wrote: > >> Both should work the same on recent versions of Python (at worst >> starting at 2.6, I haven't check 2.5 but IIRC even there python and >> pythonw are the same executable). > > On further investigation, it seems you're right. I was sure > I had a situation just recently where python wouldn't give > me a dock icon, but I can't seem to reproduce it now. > > The part about it being inside an app bundle doesn't seem > to be right, though, at least for 2.5: We're way more sneaky than that ;-). If you look carefully you'll notice that the pythonw executable is tiny and doesn't actually link with the Python framework. That's because this executable has just one task: exec-ing the executable inside the Python.app application. This is needed to ensure that the C-level argv[0] contains a path that is an absolute path that contains proof that we're inside a .app bundle. We cannot tweak argv[0] inside a running application, Apple's framework fetch the value of argv[0] from some other, hidden and undocumented, location. That's why the executable inside virtualenv environments behaves differently, that executable is the one that is normally inside the "Python.app" bundle. Ronald |
|
From: Greg E. <gre...@ca...> - 2009-03-31 23:01:12
|
Ronald Oussoren wrote: > Both should work the same on recent versions of Python (at worst > starting at 2.6, I haven't check 2.5 but IIRC even there python and > pythonw are the same executable). On further investigation, it seems you're right. I was sure I had a situation just recently where python wouldn't give me a dock icon, but I can't seem to reproduce it now. The part about it being inside an app bundle doesn't seem to be right, though, at least for 2.5: % which pythonw /usr/local/bin/pythonw % ls -l /usr/local/bin/pythonw lrwxr-xr-x 1 root wheel 61 Apr 8 2007 /usr/local/bin/pythonw -> /Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw -- Greg |
|
From: Greg E. <gre...@ca...> - 2009-03-31 22:38:29
|
Orestis Markou wrote: > pythonw does display the dock icon (and virtualenv doesn't copy that, > I'll raise an issue). I'm more interested in having a menubar so I can > press command-Q to exit. I don't know what's up with that. Even using pythonw, I've never been able to get the stock Quit menu item that the interpreter gives you to work. In PyGUI I'm creating all of my own menus (including the application menu) and handling them myself. > For some reason ctrl-c doesn't work, even when > using the relevant AppHelper method (AppHelper.installMachInterrupt()). Control-backslash in the Terminal window seems to work for me (I think that sends a SIGQUIT instead of a SIGINT). -- Greg |
|
From: Ronald O. <ron...@ma...> - 2009-03-31 14:52:47
|
On 31 Mar, 2009, at 9:44, Mike Matz wrote: > Thanks Ronald. Could you recommend anything for understanding the > Cocoa classes. For example, right now I am stuck on implementing a > search field using the NSSearchField class. Is there any literature > out there that would help explain how to implement that class? And > possibly provide examples. I have the O'Reilly Python Cookbook and > that has worked great for me because I can see how the code works. > I was stuck on implementing an NSTableView with an array before and > found a great tutorial to get me through it. I feel like I am > missing something or not looking in the right places for answers. > The tutorial was completely different from Apples documentation. > Would I benefit more by posting to an Apple Cocoa list as well? One great resource to get help is the pythonmac-sig mailinglist. That is a maillist for Python users on OSX and they tend to be a helpful bunch of people. Any Cocoa book should help you get to understand how to use these frameworks. All books I know of assume that you'll program in Objective-C, but it is pretty straightforward to translate from ObjC to Python; the hard part is to understand how to use the frameworks in the first place. Ronald > Thanks, > Mike > > > On Mar 31, 2009, at 9:52 AM, Ronald Oussoren wrote: > >> >> On 31 Mar, 2009, at 8:23, Mike Matz wrote: >> >>> I am attempting to write a small program using Python/PyObjC 2.0 and >>> Xcode 3. I have Python experience, but no Objective C >>> experience. I >>> have developed Cocoa applications in the past using AppleScript, >>> but I >>> am finding there is a huge learning curve to using Python and Cocoa. >>> I have found one or two good tutorials that that have gotten me >>> pretty >>> far. However, I am now at the point where I am trying to use >>> Apple's >>> built in documentation of the ObjC/Cocoa classes and having trouble >>> implementing them in my Python code. I have searched Google high >>> and >>> low for material relating to PyObjC 2.0 and Xcode 3.0, but have not >>> found much. Can anyone recommend tutorials, websites, even books, >>> that might help me get a handle on Cocoa development with Python in >>> Xcode? >> >> The examples and documentation on the PyObjc website should get you >> going as far as actual code is concerned. Development using Xcode >> isn't documented very well (or at all) at the moment, mostly >> because I don't use Xcode a lot myself. >> >> For simple applications it you can just add all your Python files >> to an Xcode project that's started from one of the Python Cocoa >> templates that ship with Xcode. Don't forget to import all modules >> that define classes that are used by your NIB files (the "main.py" >> file seems a great place to do that), otherwise the modules won't >> be loaded and Cocoa won't see your classes. >> >> Things get a little messy when you have dependencies on 3th party >> libraries, Xcode won't automaticly copy those into your .app bundle >> and you'll have to add a custom shell-script step to your Xcode >> project to do that for you. It should be possible to create a tool >> based on py2app that does this for you, but AFAIK nobody has looked >> into that yet. >> >> Ronald >> > |
|
From: Ronald O. <ron...@ma...> - 2009-03-31 13:52:38
|
On 31 Mar, 2009, at 8:23, Mike Matz wrote: > I am attempting to write a small program using Python/PyObjC 2.0 and > Xcode 3. I have Python experience, but no Objective C experience. I > have developed Cocoa applications in the past using AppleScript, but I > am finding there is a huge learning curve to using Python and Cocoa. > I have found one or two good tutorials that that have gotten me pretty > far. However, I am now at the point where I am trying to use Apple's > built in documentation of the ObjC/Cocoa classes and having trouble > implementing them in my Python code. I have searched Google high and > low for material relating to PyObjC 2.0 and Xcode 3.0, but have not > found much. Can anyone recommend tutorials, websites, even books, > that might help me get a handle on Cocoa development with Python in > Xcode? The examples and documentation on the PyObjc website should get you going as far as actual code is concerned. Development using Xcode isn't documented very well (or at all) at the moment, mostly because I don't use Xcode a lot myself. For simple applications it you can just add all your Python files to an Xcode project that's started from one of the Python Cocoa templates that ship with Xcode. Don't forget to import all modules that define classes that are used by your NIB files (the "main.py" file seems a great place to do that), otherwise the modules won't be loaded and Cocoa won't see your classes. Things get a little messy when you have dependencies on 3th party libraries, Xcode won't automaticly copy those into your .app bundle and you'll have to add a custom shell-script step to your Xcode project to do that for you. It should be possible to create a tool based on py2app that does this for you, but AFAIK nobody has looked into that yet. Ronald |
|
From: Ronald O. <ron...@ma...> - 2009-03-31 13:46:37
|
On 31 Mar, 2009, at 6:12, Greg Ewing wrote: > Orestis Markou wrote: > >> I'm a bit confused about Dock icons and applications - some times >> I get >> the rocket icon, some times I don't > > Is it python vs. pythonw? I find I need to use pythonw > in order to get a dock icon. Both should work the same on recent versions of Python (at worst starting at 2.6, I haven't check 2.5 but IIRC even there python and pythonw are the same executable). Ronald |
|
From: Ronald O. <ron...@ma...> - 2009-03-31 13:45:26
|
On 31 Mar, 2009, at 4:39, Orestis Markou wrote: > Hi, > > I'm a bit confused about Dock icons and applications - some times I > get the rocket icon, which I can use to force quit the app, some times > I don't get anything and I have to kill the process by getting the > PID. > > How can I get the standard application behaviour with no nibs? The most important bit is to make sure your application is in an .app bundle and has a proper main loop. That way you'll get real access to the Window Manager and an icon in the Dock. OSX wants all GUI programs to run as part of a .app bundle (ignoring CFM based Carbon apps because nobody should use those anyway), you won't get the right experience otherwise. Python hacks around that by using a Python.app bundle inside the Python framework, but that's only there as a convenience to users and shouldn't be used for packaging real applications (IMHO). Ronald |
|
From: Ronald O. <ron...@ma...> - 2009-03-31 13:42:23
|
On 31 Mar, 2009, at 4:46, Orestis Markou wrote: > Interesting - I'm using virtualenv, and when using the python > executable created by virtualenv I don't get the dock icon, whereas if > I use the system python executable I do. I wonder if there's a way to > overcome this... The python executable in a virtualenv is not equivalent to "pythonw" while the regular one is. That is, the executable that gets started when you start python outside of a virtual env is one that's located in an .app bundle (check sys.executable for evidence). I'll probably get around to fixing virtualenv in the near future as I'm about to move my development environment to something that's entirely based on clean installs of Python with per-project virtual environments. I've looked into such a fix in the past as well and getting the semantics of virtualenv exactly right could be a challenge, but still doable. Ronald |