libraries options not split in setup.cfg
Hi. I just noticed that the libraries options under the [build_ext] section in setup.cfg doesn't seem to get expanded. In particular, in distutils.command.build_ext.py of python 2.4. (line147): if type(self.libraries) is StringType: self.libraries = [self.libraries] though library_dirs for example gets split on ';' (line 156) elif type(self.library_dirs) is StringType: self.library_dirs = string.split(self.library_dirs, os.pathsep) is this a bug or am i using the libraries option in a wrong way in my setup.cfg libraries = libgsl;libgslcblas (btw, the above gets expanded on windows to libgsl;libgslcblas.lib on the cmdline (not splitting on the ';' character). thx for any help. -- http://mail.python.org/mailman/listinfo/python-list
portable extensions options for external libraries
Hi. I want to create a portable setup.py file for windows / linux for an extension package that i need to link with external libraries (gsl and boost). on windows i do something like this: imaging = Extension( 'pyag.imaging._imaging', sources = ( glob.glob( 'Source/pyag/imaging/Src/*.cpp' ) + glob.glob( 'Source/pyag/imaging/Src/*.h' ) ), include_dirs = ( get_numpy_include_dirs() + [ 'Source/pyag/imaging/Src/', 'C:/Program Files/boost/include/boost-1_35', 'C:/Program Files/GnuWin32/include'] ), library_dirs = [ 'C:/Program Files/GnuWin32/lib' ], libraries = [ 'libgsl', 'libgslcblas' ] ) obviously, the paths could vary. on unix, i need something like: imaging = Extension( 'pyag.imaging._imaging', sources = ( glob.glob( 'Source/pyag/imaging/Src/*.cpp' ) + glob.glob( 'Source/pyag/imaging/Src/*.h' ) ), include_dirs = ( get_numpy_include_dirs() + [ 'Source/pyag/imaging/Src/' ] ) ) so my question is: what is the right way of specifying extensions options (include_dirs, libraries, library_dirs) so that they are portable between windows and linux? i'm thinking environment variables. Though fairly easy to do, i was wondering if python/distutils provided something more convenient, like searching through common directories, though those aren't very standard on windows? Optimally, i would like to have something like: imaging = Extension( 'pyag.imaging._imaging', sources = ( glob.glob( 'Source/pyag/imaging/Src/*.cpp' ) + glob.glob( 'Source/pyag/imaging/Src/*.h' ) ), include_dirs = ( get_numpy_include_dirs() + [ 'Source/pyag/imaging/Src/' ] + boost_include_dirs + gsl_include_dirs ), library_dirs = boost_library_dirs + gsl_library_dirs, libraries = boost_libraries + gsl_libraries ) thx for any help. alex. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to deepcopy a slice object?
thx for all the help simon. good ideas i can work with. thx again. alex. Simon Forman wrote: Alexandre Guimond wrote: Here is my reason: I have an object that contrains a 2D regular grid (matrix). In this regular grid, I place points at regular intervals. In essence, i have something like (my code is obviously more complex, this is just to show what I want to do) obj.grid = numpy.zeros( ( 100, 100 ) ) obj.grid[ obj.y1: obj.y2 : obj.ys, obj.x1 : obj.x2 : obj.xs ] = embedded_parameters result = somefunc( obj.grid ) My goal was to reduce the number of elements in my obj object by replacing y1, y2, ys, and x1, x2, xs by 2 slice objects, and then do: obj.grid[ obj.slicey, obj.slicex ] = embedded_parameters But when I do this and then try to deepcopy my object, it doesn't work, as in the example below. Its not a big thing. I just liked the idea of having less elements in my obj class and actually modeling my slice concept by a slice object, specially since i'm going to 3D and 4D grid, and its somewhat annoying to carry so many indices in my class definition. Simon Forman wrote: Alexandre Guimond wrote: Hi all, i'm trying to deepcopy a slice object but i get the following error. Does anyone know a workaround? ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import copy copy.deepcopy( slice( 1, 10, 2 ) ) Traceback (most recent call last): File stdin, line 1, in ? File C:\Program Files\Python\lib\copy.py, line 204, in deepcopy y = _reconstruct(x, rv, 1, memo) File C:\Program Files\Python\lib\copy.py, line 336, in _reconstruct y = callable(*args) File C:\Program Files\Python\lib\copy_reg.py, line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: slice expected at least 1 arguments, got 0 thx for any help. Why would you want to [deep]copy a slice object? Anyway, I don't know much about them, other than that they are slightly unusual objects that play a very restricted role in python, rather like the Ellipsis. Workarounds are possible, I think, but really you almost certainly don't need to do this. Peace, ~Simon Ah, so you *do* want to deepcopy slice objects.. Neat. :-) I can't do that, but I can show you a couple of ways to deepcopy objects that have slices as attributes. First, if the __init__() method and its args are sufficient to recreate your objects then you could do something like this: class DeepCopyable0: def __init__(self, x, y, z, a, b, c): self.slicex = slice(x, y, z) self.slicey = slice(a, b, c) def __deepcopy__(self, memo): # Create local vars for brevity. sx, sy = self.slicex, self.slicey # Create a new DeepCopyable0 instance. return DeepCopyable0( sx.start, sx.stop, sx.step, sy.start, sy.stop, sy.step ) | d0 = DeepCopyable0(1, 2, 3, 4, 5, 6) | d0.slicex, d0.slicey (slice(1, 2, 3), slice(4, 5, 6)) | d1 = deepcopy(d0) | d1.slicex, d1.slicey (slice(1, 2, 3), slice(4, 5, 6)) Otherwise, another way to do it would be to provide the pickling protocol: class DeepCopyable1: def __init__(self, x, y, z, a, b, c): # Pretend this was something more complicated. self.slicex = slice(x, y, z) self.slicey = slice(a, b, c) def __getstate__(self): state = self.__dict__.copy() # Create local vars for brevity. sx, sy = self.slicex, self.slicey # Save the indices rather than the slices. state['slicex'] = sx.start, sx.stop, sx.step state['slicey'] = sy.start, sy.stop, sy.step return state def __setstate__(self, state): # Recreate the slice objects. state['slicex'] = slice(*state['slicex']) state['slicey'] = slice(*state['slicey']) self.__dict__.update(state) | d0 = DeepCopyable1(1, 2, 3, 4, 5, 6) | d0.slicex, d0.slicey (slice(1, 2, 3), slice(4, 5, 6)) | d1 = deepcopy(d0) | d1.slicex, d1.slicey (slice(1, 2, 3), slice(4, 5, 6)) Circular references seem work fine here too. Observe: | d0 = DeepCopyable1(1, 2, 3, 4, 5, 6) | d0.rec = d0 | d0 delme.DeepCopyable instance at 0xb7d5cb2c | d0.rec.rec #etc... delme.DeepCopyable instance at 0xb7d5cb2c | d1 = deepcopy(d0) | d1 delme.DeepCopyable instance at 0xb7d7878c | d1.rec delme.DeepCopyable instance at 0xb7d7878c Since you're going to be using more dimensions, you could make python do the work for you rather than cutting and pasting: class DeepCopyable2: # __init__() omitted... def __getstate__(self): state = self.__dict__.copy() # Keep track of the slice attributes
how to deepcopy a slice object?
Hi all, i'm trying to deepcopy a slice object but i get the following error. Does anyone know a workaround? ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import copy copy.deepcopy( slice( 1, 10, 2 ) ) Traceback (most recent call last): File stdin, line 1, in ? File C:\Program Files\Python\lib\copy.py, line 204, in deepcopy y = _reconstruct(x, rv, 1, memo) File C:\Program Files\Python\lib\copy.py, line 336, in _reconstruct y = callable(*args) File C:\Program Files\Python\lib\copy_reg.py, line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: slice expected at least 1 arguments, got 0 thx for any help. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to deepcopy a slice object?
Here is my reason: I have an object that contrains a 2D regular grid (matrix). In this regular grid, I place points at regular intervals. In essence, i have something like (my code is obviously more complex, this is just to show what I want to do) obj.grid = numpy.zeros( ( 100, 100 ) ) obj.grid[ obj.y1: obj.y2 : obj.ys, obj.x1 : obj.x2 : obj.xs ] = embedded_parameters result = somefunc( obj.grid ) My goal was to reduce the number of elements in my obj object by replacing y1, y2, ys, and x1, x2, xs by 2 slice objects, and then do: obj.grid[ obj.slicey, obj.slicex ] = embedded_parameters But when I do this and then try to deepcopy my object, it doesn't work, as in the example below. Its not a big thing. I just liked the idea of having less elements in my obj class and actually modeling my slice concept by a slice object, specially since i'm going to 3D and 4D grid, and its somewhat annoying to carry so many indices in my class definition. Simon Forman wrote: Alexandre Guimond wrote: Hi all, i'm trying to deepcopy a slice object but i get the following error. Does anyone know a workaround? ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import copy copy.deepcopy( slice( 1, 10, 2 ) ) Traceback (most recent call last): File stdin, line 1, in ? File C:\Program Files\Python\lib\copy.py, line 204, in deepcopy y = _reconstruct(x, rv, 1, memo) File C:\Program Files\Python\lib\copy.py, line 336, in _reconstruct y = callable(*args) File C:\Program Files\Python\lib\copy_reg.py, line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: slice expected at least 1 arguments, got 0 thx for any help. Why would you want to [deep]copy a slice object? Anyway, I don't know much about them, other than that they are slightly unusual objects that play a very restricted role in python, rather like the Ellipsis. Workarounds are possible, I think, but really you almost certainly don't need to do this. Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
tkFileDialog.Open to select a large number of files
Hi. I've noticed that when i select a large number of files ( 400) using tkFileDialog.Open i get an empty list. Does anyone knows the limits of that interface regarding the maximum number of files that can be selected, or the maximum length of the resulting list? Does anyone have any work around? thx. alex. -- http://mail.python.org/mailman/listinfo/python-list
distutils and binding a script to a file extension on windows
Hi. I built a little installer on windows XP using distutils for my package. In there i add a few files to the python script directory. I would like one of these scripts to be the default program to be used by files with a given extention (e.g. i have an image viewer and would like it to be used when ever i click on a .gif file). I can do this manually (through Tools-Folder Options-File Types), but it would be nicer if the installer could configure this. It seems this may be possible through the postinstallation script of distutils, but i have no clue how to do this. does any have experience with this? i assume i need to edit the registry entries, but i dont know how or which ones. thx for any help alex. -- http://mail.python.org/mailman/listinfo/python-list
python interpreter widget for Tkinter?
Hi i was wondering if there already existed a simple python interpreter widget for tkinter? Basically, i would like to be able to lauch a python interpreter in a seperate window from my tkinter app for debugging purposes. I would assume that this would be possible using idlelib, but i can't figure out how. Does anyone know how to do this? thx for any help alex -- http://mail.python.org/mailman/listinfo/python-list
creating custom options for custom widgets?
Hi all. I'm creating a new widget class using Tkinter (class inherited form Tkinter.Frame). This class creates a bunch of other widgets inside it that can be gridded either horizontally or vertically. I would like to provide the user of the class an option to change this layout on the fly, using something like widget[ 'layout' ] = 'vertical'. Does anyone have experience with that? I'm afraid i just down know how to proceed or where to look for an example. thx for any help. alex. -- http://mail.python.org/mailman/listinfo/python-list
logging to a text widget
Hi. I'm using the logging package. I would like to send my log messages to a Text widget creating using Tkinter. I was wondering if there was a logging handler class that would do this. It seems that the standard handlers do not support this. Has anyone tried to do this? Thx for any help, alex -- http://mail.python.org/mailman/listinfo/python-list