Re: [Pythonmac-SIG] using the "PyUSB" module

2009-04-02 Thread Chris Rebert
On Thu, Apr 2, 2009 at 5:36 PM, Rekow Warren
 wrote:
> I am a new MacPython (ver 2.6.1) user who has downloaded the "PyUSB" module,
> but am unclear about how to make it available for use in a program. Included
> among the downloaded files is 'setup.py' (and 'setup.pyc'). Running
> 'setup.py' via IDLE yields the following error msg:
> ---
> Traceback (most recent call last):
>  File "/Applications/Python 2.6/pyusb-0.4.1/setup.py", line 62, in 
>    ext_modules = [usbmodule])
>  File
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py",
> line 140, in setup
>    raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
> SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts]
> ...]
>   or: setup.py --help [cmd1 cmd2 ...]
>   or: setup.py --help-commands
>   or: setup.py cmd --help
>
> error: no commands supplied
> ---
> It seemed that 'setup.py' should be run in order to access functions in the
> PyUSB module, but perhaps I misunderstand the process. It would be
> appreciated if someone could suggest a related reference to read.

Use the command suggested in the error message:
setup.py --help-commands

You have to give setup.py a command argument; it cannot be run without
any arguments. That command should give you a list and explanation
from which you can figure out which command you want.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] using the "PyUSB" module

2009-04-02 Thread Rekow Warren
I am a new MacPython (ver 2.6.1) user who has downloaded the "PyUSB"  
module, but am unclear about how to make it available for use in a  
program. Included among the downloaded files is 'setup.py' (and  
'setup.pyc'). Running 'setup.py' via IDLE yields the following error  
msg:

---
Traceback (most recent call last):
  File "/Applications/Python 2.6/pyusb-0.4.1/setup.py", line 62, in  


ext_modules = [usbmodule])
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
python2.6/distutils/core.py", line 140, in setup

raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2  
[cmd2_opts] ...]

   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: no commands supplied
---
It seemed that 'setup.py' should be run in order to access functions  
in the PyUSB module, but perhaps I misunderstand the process. It  
would be appreciated if someone could suggest a related reference to  
read.

Thanks, Warren
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] py2app traceback with wxPython 2.8.9.2

2009-04-02 Thread Christopher Barker

Paul McNett wrote:
I get a traceback running py2app with wxPython 2.8.9.2, but not with 
wxPython 2.8.9.1. Here's the traceback:


copying 
/Library/Frameworks/Python.framework/Versions/2.5/lib/libncurses.5.dylib 
-> 



ValueError: Unknown load command: 27


Are you using the latest py2app and macholib?

$ easy_install macholib==dev


-Chris





--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] py2app traceback with wxPython 2.8.9.2

2009-04-02 Thread David Hughes

Paul McNett wrote:

Hi,

I get a traceback running py2app with wxPython 2.8.9.2, but not with 
wxPython 2.8.9.1. Here's the traceback:


copying 
/Library/Frameworks/Python.framework/Versions/2.5/lib/libncurses.5.dylib 
-> 



ValueError: Unknown load command: 27
> 
/Users/pmcnett/py/sbs/shutter_studio/trunk/clients/shutter_studio/build/bdist.macosx-10.3-i386/egg/macholib/MachO.py(178)load() 


(Pdb)


Everything is the same, except the wxPython version. Any ideas?

Paul
I recall getting an "Unknown load command"  message from py2app after I 
compiled the Reportlab extension *_renderPM.so* as a universal binary 
under OS X 10.5 (Leopard) and tried to include it in the app. When I 
compiled it again under 10.4 (Tiger), py2app (running under 10.5) 
accepted it without any problem. I didn't (have time to) investigate any 
further, only to note that the 10.5-built version was only 240 Kb 
compared to 560Kb for the working, 10.4-built version.


Maybe there are extensions in wxPython 2.8.9.2 built using OS X 10.5 
that were previously built using 10.4 and causing a similar problem?


Later
I have just rerun py2app with my original 10.5-built *_renderPM.so* 
and -apart from me using a slightly earlier version of py2app than Paul 
- it produces the  self same error word for word (see attachments). 
Could it be *_renderPM.so* itself that is causing your error Paul?


---
Regards,

David Hughes
Forestfield Software

Traceback (most recent call last):
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app-0.3.dev_r954-py2.5.egg/py2app/build_app.py",
 line 530, in _run
self.run_normal()
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app-0.3.dev_r954-py2.5.egg/py2app/build_app.py",
 line 601, in run_normal
self.create_binaries(py_files, pkgdirs, extensions, loader_files)
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app-0.3.dev_r954-py2.5.egg/py2app/build_app.py",
 line 709, in create_binaries
platfiles = mm.run()
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachOStandalone.py", line 
102, in run
mm.run_file(fn)
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachOGraph.py", line 66, in 
run_file
m = self.createNode(MachO, pathname)
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachOStandalone.py", line 23, 
in createNode
res = super(FilteredMachOGraph, self).createNode(cls, name)
  File "build/bdist.macosx-10.3-i386/egg/altgraph/ObjectGraph.py", line 148, in 
createNode
m = cls(name, *args, **kw)
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachO.py", line 61, in 
__init__
self.load(file(filename, 'rb'))
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachO.py", line 71, in load
self.load_fat(fh)
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachO.py", line 82, in 
load_fat
self.load_header(fh, arch.offset, arch.size)
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachO.py", line 106, in 
load_header
hdr = MachOHeader(self, fh, offset, size, magic, hdr, endian)
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachO.py", line 146, in 
__init__
self.load(fh)
  File "build/bdist.macosx-10.3-i386/egg/macholib/MachO.py", line 178, in load
raise ValueError("Unknown load command: %d" % (cmd_load.cmd,))
ValueError: Unknown load command: 27

Traceback (most recent call last):
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app-0.3.6-py2.5.egg/py2app/build_app.py",
 line 560, in _run
self.run_normal()
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app-0.3.6-py2.5.egg/py2app/build_app.py",
 line 631, in run_normal
self.create_binaries(py_files, pkgdirs, extensions, loader_files)
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app-0.3.6-py2.5.egg/py2app/build_app.py",
 line 744, in create_binaries
platfiles = mm.run()
  File "build/bdist.macosx-10.3-fat/egg/macholib/MachOStandalone.py", line 102, 
in run
mm.run_file(fn)
  File "build/bdist.macosx-10.3-fat/egg/macholib/MachOGraph.py", line 66, in 
run_file
m = self.createNode(MachO, pathname)
  File "build/bdist.macosx-10.3-fat/egg/macholib/MachOStandalone.py", line 23, 
in createNode
res = super(FilteredMachOGraph, self).createNode(cls, name)
  File "build/bdist.macosx-10.3-fat/egg/altgraph/ObjectGraph.py", line 148, in 
createNode
m = cls(name, *args, **kw)
  File "build/bdist.macosx-10.3-fat/egg/macholib/MachO.py", line 61, in __init__
self.load(file(filename, 'rb'))
  File "build/bdist.macosx-10.3-fat/egg/macholib/MachO.py", line 71, in load
self.load_fat(fh)
  File "build/bdist.macosx-10.3-fat/egg/macholib/MachO.py", line 82, in load_fat
self.load_header(fh, arch.offset, arch.size)
  File "build/bdist.macosx-10.3-fat/egg/macholib/MachO.py", line 106, in 
load_header
hdr = MachOHeader(self, fh, offs

Re: [Pythonmac-SIG] [PyObjC] setting button name in NSOpenPanel

2009-04-02 Thread Nicholas Riley
On Thu, Apr 02, 2009 at 01:36:46PM +0200, Steph-info wrote:
> Thanks Nicholas, it works for the "Open" button.
> 
> I found the following cocoa reference for the "Cancel" button :
> 
> """
> NSSavePanel *panel = [NSSavePanel savePanel];
> NSButton* cancelButton =
> [[panel contentView]  
> buttonWithTag:NSFileHandlingPanelCancelButton];
> """
> 
> Do you know how I can translate this to PyObjC ?

This is a hack - NSFileHandlingPanelCancelButton is 0, so trying to
match the tag like this will match all buttons with no tag assigned
(as is the default in Interface Builder).  In addition, it assumes
that the button is a direct descendant of the window's content view -
since 2002 when the code above was written, it is no longer the case,
so that code is already broken on OS X 10.5.

That said, if you really must, a better way would be to check the
control's action rather than its tag, searching through the entire
hierarchy - something like this.

  def buttons_with_action(view, action):
  for subview in view.subviews():
  if isinstance(subview, NSButton) and subview.action() == action:
  yield subview
  for i in buttons_with_action(subview, action):
  yield i
  cancelButtons = list(buttons_with_action(openPanel.contentView(), 'cancel:'))
  if len(cancelButtons) != 1:
  pass # handle error
  cancelButtons[0].setTitle_('Go Away')
  openPanel.runModalForTypes_(None)

and assuming you're going to be distributing your app, make sure you
handle the case when the button isn't there, or there are two of them,
or the button doesn't have a title, or something else weird happens in
a future OS version.

-- 
Nicholas Riley 
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] [PyObjC] setting button name in NSOpenPanel

2009-04-02 Thread Steph-info


Le 2 avr. 09 à 12:28, Nicholas Riley a écrit :



On Thu, Apr 02, 2009 at 09:52:26AM +0200, Steph-info wrote:

Hi,

I have the following piece of code :

"""
@objc.IBAction
def chooseRec_(self, sender):
op = NSOpenPanel.openPanel()
op.setTitle_('Choisir un dossier')
op.setCanChooseDirectories_(True)
op.setCanChooseFiles_(False)
op.setResolvesAliases_(True)
op.setAllowsMultipleSelection_(False)
result = op.runModalForDirectory_file_types_(None, None,
None)
if result == NSOKButton:
self.pathRec = op.filename()
self.pathField.setStringValue_(self.pathRec)

"""
which open an NSOpenPanel but I can't find how to change the default
"Open" and "Cancel" button's names.

Could anybody post a line of code demonstrating how to achieve this
task ?


op.setPrompt_('foo') will change Open.  Note that NSOpenPanel inherits
from NSSavePanel and a bunch of the API you might be looking for is in
NSSavePanel.

I don't believe it's possible to change 'Cancel' (beyond localizing  
it).


Thanks Nicholas, it works for the "Open" button.

I found the following cocoa reference for the "Cancel" button :

"""
NSSavePanel *panel = [NSSavePanel savePanel];
NSButton* cancelButton =
[[panel contentView]  
buttonWithTag:NSFileHandlingPanelCancelButton];

"""

Do you know how I can translate this to PyObjC ?





--
Nicholas Riley 






Cordialement,

Stéphane Serra.




___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] [PyObjC] setting button name in NSOpenPanel

2009-04-02 Thread Nicholas Riley
On Thu, Apr 02, 2009 at 09:52:26AM +0200, Steph-info wrote:
> Hi,
> 
>   I have the following piece of code :
> 
> """
>   @objc.IBAction
>   def chooseRec_(self, sender):
>   op = NSOpenPanel.openPanel()
>   op.setTitle_('Choisir un dossier')
>   op.setCanChooseDirectories_(True)
>   op.setCanChooseFiles_(False)
>   op.setResolvesAliases_(True)
>   op.setAllowsMultipleSelection_(False)
>   result = op.runModalForDirectory_file_types_(None, None, 
>   None)
>   if result == NSOKButton:
>   self.pathRec = op.filename()
>   self.pathField.setStringValue_(self.pathRec)
> 
> """
>   which open an NSOpenPanel but I can't find how to change the default 
> "Open" and "Cancel" button's names.
>   
>   Could anybody post a line of code demonstrating how to achieve this  
> task ?

op.setPrompt_('foo') will change Open.  Note that NSOpenPanel inherits
from NSSavePanel and a bunch of the API you might be looking for is in
NSSavePanel.

I don't believe it's possible to change 'Cancel' (beyond localizing it).

-- 
Nicholas Riley 
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] [PyObjC] setting button name in NSOpenPanel

2009-04-02 Thread Steph-info

Hi,

I have the following piece of code :

"""
@objc.IBAction
def chooseRec_(self, sender):
op = NSOpenPanel.openPanel()
op.setTitle_('Choisir un dossier')
op.setCanChooseDirectories_(True)
op.setCanChooseFiles_(False)
op.setResolvesAliases_(True)
op.setAllowsMultipleSelection_(False)
result = op.runModalForDirectory_file_types_(None, None, None)
if result == NSOKButton:
self.pathRec = op.filename()
self.pathField.setStringValue_(self.pathRec)

"""
	which open an NSOpenPanel but I can't find how to change the default  
"Open" and "Cancel" button's names.


	Could anybody post a line of code demonstrating how to achieve this  
task ?



Thanks



Cordialement,

Stéphane Serra.




___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig