Does upgrade from 2.7.3 to 2.7.5 require uninstall?

2013-06-20 Thread Wanderer
Do I need to uninstall Python 2.7.3 before installing Python 2.7.5?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does upgrade from 2.7.3 to 2.7.5 require uninstall?

2013-06-20 Thread Wanderer
On Thursday, June 20, 2013 2:47:52 PM UTC-4, MRAB wrote:
> On 20/06/2013 19:35, Wanderer wrote:
> 
> > Do I need to uninstall Python 2.7.3 before installing Python 2.7.5?
> 
> >
> 
> No.

You're right. I had no problems. FYI the operating system is Windows 7.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ipython

2013-07-08 Thread Wanderer
On Monday, July 8, 2013 10:44:11 AM UTC-4, [email protected] wrote:
> Hi, I work with Python 3.3.
> 
> I downloaded an IPython executable version from 
> http://www.lfd.uci.edu/~gohlke/pythonlibs/
> 
> I installed it but no shortcut appears in my start menu.
> 
> How can I launch it or alternatively is there some other free source of 
> executable file for Windows 7?
> 
> Many Thanks

You must right click and 'run as administrator' to get the start menu shortcuts.
Otherwise, ipython.exe is in the Scripts subdirectory of your Python directory.

ie C:\Python27\Scripts
-- 
http://mail.python.org/mailman/listinfo/python-list


WxSlider Mouse Wheel Resolution

2012-07-02 Thread Wanderer
Is there a way to set the mouse wheel resolution for the wxPython
wx.Slider? I would like to use the graphic slider for coarse control
and the mouse wheel for fine control. Right now the mouse wheel makes
the slider jump ten counts and I would like it to be a single count.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WxSlider Mouse Wheel Resolution

2012-07-03 Thread Wanderer
On Monday, July 2, 2012 6:53:36 PM UTC-4, Dennis Lee Bieber wrote:
> On Mon, 2 Jul 2012 08:45:49 -0700 (PDT), Wanderer
>  declaimed the following in
> gmane.comp.python.general:
> 
> > Is there a way to set the mouse wheel resolution for the wxPython
> > wx.Slider? I would like to use the graphic slider for coarse control
> > and the mouse wheel for fine control. Right now the mouse wheel makes
> > the slider jump ten counts and I would like it to be a single count.
> >
>   Isn't that a condition of the OS Mouse driver?
> 
>   My LogiTech driver (WinXP) has "scroller: 1, 3, 6 lines"
> 
> -- 
>   Wulfraed Dennis Lee Bieber AF6VN
> [email protected]://wlfraed.home.netcom.com/

Maybe there are some system settings but I believe they can be overridden by 
the application. Check out the Firefox options for the mouse wheel.

http://www.pcworld.com/article/163639/change_the_speed_of_mousewheel_scrolling_in_firefox.html
-- 
http://mail.python.org/mailman/listinfo/python-list


assert expressions

2012-07-24 Thread Wanderer
If I use the code 

assert False, "unhandled option"

I get output like:

option -q not recognized
for help use --help

What other expressions can I use other than "unhandled option"? Is there a list 
somewhere?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 4:31 pm, Ian Kelly  wrote:
> On Tue, Jul 24, 2012 at 1:57 PM, Wanderer  wrote:
> > If I use the code
>
> > assert False, "unhandled option"
>
> > I get output like:
>
> > option -q not recognized
> > for help use --help
>
> > What other expressions can I use other than "unhandled option"? Is there a 
> > list somewhere?
>
> Are you using argparse or optparse or getopt or something else
> altogether?  And where are you placing this assert?  It would be
> helpful to see some actual code to understand what you are doing.
>
> And by the way, assert is a very bad way to check user input or to
> unconditionally raise an exception.  The reason is that if Python is
> invoked with -O, then all assertions are removed from the compiled
> bytecode, and then your unconditional exception code doesn't raise any
> exception at all.  If you want to raise an exception, just do it:
>
> raise Exception("unhandled option")
>
> Ideally, you would also subclass Exception to create a more specific
> exception class for your custom exception:
>
> class UnhandledOptionException(Exception):
>     pass
>
> # Then, later on...
>
> raise UnhandledOptionException("-q")

I left out the Usage class

class Usage(Exception):
def __init__(self, msg):
self.msg = msg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 4:47 pm, Wanderer  wrote:
> On Jul 24, 4:31 pm, Ian Kelly  wrote:
>
>
>
>
>
>
>
>
>
> > On Tue, Jul 24, 2012 at 1:57 PM, Wanderer  wrote:
> > > If I use the code
>
> > > assert False, "unhandled option"
>
> > > I get output like:
>
> > > option -q not recognized
> > > for help use --help
>
> > > What other expressions can I use other than "unhandled option"? Is there 
> > > a list somewhere?
>
> > Are you using argparse or optparse or getopt or something else
> > altogether?  And where are you placing this assert?  It would be
> > helpful to see some actual code to understand what you are doing.
>
> > And by the way, assert is a very bad way to check user input or to
> > unconditionally raise an exception.  The reason is that if Python is
> > invoked with -O, then all assertions are removed from the compiled
> > bytecode, and then your unconditional exception code doesn't raise any
> > exception at all.  If you want to raise an exception, just do it:
>
> > raise Exception("unhandled option")
>
> > Ideally, you would also subclass Exception to create a more specific
> > exception class for your custom exception:
>
> > class UnhandledOptionException(Exception):
> >     pass
>
> > # Then, later on...
>
> > raise UnhandledOptionException("-q")
>
> I left out the Usage class
>
> class Usage(Exception):
>     def __init__(self, msg):
>         self.msg = msg

I seem to be missing a post.

Here is the code.

class Usage(Exception):
def __init__(self, msg):
self.msg = msg

def main(argv=None):

help_message = \
("\nOtFixture.py:\n Set the Optics Test Fixture Light Source Light
Level\n" +
 "Options:\n"
 "  -l, --level= \n"
+
 "  -v, --verbose: Print messages to the terminal.\n"
 "  -h, --help: This message\n")

level = None
verbose = False
helpflag = False

options = "hl:v"
long_options = ["help","level=","verbose"]
if argv is None:
argv = sys.argv
try:
try:
opts, _args = getopt.getopt(argv[1:],
options,long_options)
except getopt.error, msg:
raise Usage(msg)

for o, a in opts:
if o in ("-h", "--help"):
print help_message
helpflag = True
elif o in ("-l", "--level"):
level = a
elif o in ("-v", "--verbose"):
verbose = True
else:
assert False, "unhandled option"

if not helpflag:
if level == None:
level = raw_input("Enter the light level from 0.0 to
100.0%: ")
if level.replace(".", "", 1).isdigit():
level = float(level)
else:
msg = "\n" + str(level) + " is not a number.\n"
raise Usage(msg)

if verbose and level is not None:
print "The level is ", level, " percent"

if level is not None:
if 0.0 <= level <= 100.0:
ot = OtFixture(verbose)
ot.setLightLevel(level)
print "Light Level set to ", level,"%."
else:
msg = "\n" + str(level) + " is not in the range 0.0 to
100.0%\n"
raise Usage(msg)


except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2

if __name__ == "__main__":
sys.exit(main())

I don't really have a problem. I'm was just curious.

How do you invoke python -O? When I run python.exe -O OtFixture.py -q,
I get the same response. It's a capital letter O, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 4:31 pm, Ian Kelly  wrote:
> On Tue, Jul 24, 2012 at 1:57 PM, Wanderer  wrote:
> > If I use the code
>
> > assert False, "unhandled option"
>
> > I get output like:
>
> > option -q not recognized
> > for help use --help
>
> > What other expressions can I use other than "unhandled option"? Is there a 
> > list somewhere?
>
> Are you using argparse or optparse or getopt or something else
> altogether?  And where are you placing this assert?  It would be
> helpful to see some actual code to understand what you are doing.
>
> And by the way, assert is a very bad way to check user input or to
> unconditionally raise an exception.  The reason is that if Python is
> invoked with -O, then all assertions are removed from the compiled
> bytecode, and then your unconditional exception code doesn't raise any
> exception at all.  If you want to raise an exception, just do it:
>
> raise Exception("unhandled option")
>
> Ideally, you would also subclass Exception to create a more specific
> exception class for your custom exception:
>
> class UnhandledOptionException(Exception):
>     pass
>
> # Then, later on...
>
> raise UnhandledOptionException("-q")

I'm using getopt but not at that point. I really don't have a problem.
I'm just curious. I've never seen anything else after
assert False,

Here is some code.

def main(argv=None):

help_message = \
("\nOtFixture.py:\n Set the Optics Test Fixture Light Source Light
Level\n" +
 "Options:\n"
 "  -l, --level= \n"
+
 "  -v, --verbose: Print messages to the terminal.\n"
 "  -h, --help: This message\n")

level = None
verbose = False
helpflag = False

options = "hl:v"
long_options = ["help","level=","verbose"]
if argv is None:
argv = sys.argv
try:
try:
opts, _args = getopt.getopt(argv[1:],
options,long_options)
except getopt.error, msg:
raise Usage(msg)

for o, a in opts:
if o in ("-h", "--help"):
print help_message
helpflag = True
elif o in ("-l", "--level"):
level = a
elif o in ("-v", "--verbose"):
verbose = True
else:
assert False, "unhandled option"

if not helpflag:
if level == None:
level = raw_input("Enter the light level from 0.0 to
100.0%: ")
if level.replace(".", "", 1).isdigit():
level = float(level)
else:
msg = "\n" + str(level) + " is not a number.\n"
raise Usage(msg)

if verbose and level is not None:
print "The level is ", level, " percent"

if level is not None:
if 0.0 <= level <= 100.0:
ot = OtFixture(verbose)
ot.setLightLevel(level)
print "Light Level set to ", level,"%."
else:
msg = "\n" + str(level) + " is not in the range 0.0 to
100.0%\n"
raise Usage(msg)


except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2

if __name__ == "__main__":
sys.exit(main())



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assert expressions

2012-07-24 Thread Wanderer
On Jul 24, 5:22 pm, Ian Kelly  wrote:
> On Tue, Jul 24, 2012 at 2:44 PM, Wanderer  wrote:
> > I'm using getopt but not at that point. I really don't have a problem.
> > I'm just curious. I've never seen anything else after
> > assert False,
>
> > Here is some code.
>
> It doesn't matter what you put after the assert False, because that
> line is not actually reached.  When getopt sees the -q, it immediately
> raises a getopt.error, which you catch and then immediately reraise as
> a Usage exception, which is then caught and printed at the end.  The
> chained ifs with the assert statement never even execute in this
> scenario.
>
> Seeing the assert in context, it makes more sense.  It's not
> intercepting some unimplemented option and preventing the program from
> proceeding; it's there as a development tool to catch programming
> errors where an option is added to the getopt configuration but is not
> implemented in the if chain.

Thanks. Now it makes more sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Numpy combine channels

2012-09-10 Thread Wanderer
I have an array generated by audiolab of left and right stereo channels. It 
looks like [[1,1],[1,2],[2,3]]. I would like to combine the left and right 
channels to get an array [2,3,5]. Is there a numpy command to do that?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy combine channels

2012-09-10 Thread Wanderer
On Monday, September 10, 2012 3:39:11 PM UTC-4, Wanderer wrote:
> I have an array generated by audiolab of left and right stereo channels. It 
> looks like [[1,1],[1,2],[2,3]]. I would like to combine the left and right 
> channels to get an array [2,3,5]. Is there a numpy command to do that?
> 
> 
> 
> Thanks

I figured it out. numpy.sum(array, axis=1). 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy combine channels

2012-09-10 Thread Wanderer
On Monday, September 10, 2012 4:12:40 PM UTC-4, MRAB wrote:
> On 10/09/2012 20:39, Wanderer wrote:
> 
> > I have an array generated by audiolab of left and right stereo
> 
> > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine
> 
> > the left and right channels to get an array [2,3,5]. Is there a numpy
> 
> > command to do that?
> 
> >
> 
> >>> import numpy
> 
> >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i")
> 
> array([[1, 1],
> 
> [1, 2],
> 
> [2, 3]])
> 
> >>> a[:, 0]
> 
> array([1, 1, 2])
> 
> >>> a[:, 1]
> 
> array([1, 2, 3])
> 
> >>> a[:, 0] + a[:, 1]
> 
> array([2, 3, 5])
> 
> 
> 
> But should they be added together to make mono?
> 
> 
> 
> Suppose, for example, that both channels have a maximum value. Their
> 
> sum would be _twice_ the maximum.
> 
> 
> 
> Therefore, I think that it should probably be the average.
> 
> 
> 
>  >>> (a[:, 0] + a[:, 1]) / 2
> 
> array([1, 1, 2])

I'm decoding morse code. So it's CV dots and dashes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy combine channels

2012-09-10 Thread Wanderer
On Monday, September 10, 2012 4:14:18 PM UTC-4, Wanderer wrote:
> On Monday, September 10, 2012 4:12:40 PM UTC-4, MRAB wrote:
> 
> > On 10/09/2012 20:39, Wanderer wrote:
> 
> > 
> 
> > > I have an array generated by audiolab of left and right stereo
> 
> > 
> 
> > > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine
> 
> > 
> 
> > > the left and right channels to get an array [2,3,5]. Is there a numpy
> 
> > 
> 
> > > command to do that?
> 
> > 
> 
> > >
> 
> > 
> 
> > >>> import numpy
> 
> > 
> 
> > >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i")
> 
> > 
> 
> > array([[1, 1],
> 
> > 
> 
> > [1, 2],
> 
> > 
> 
> > [2, 3]])
> 
> > 
> 
> > >>> a[:, 0]
> 
> > 
> 
> > array([1, 1, 2])
> 
> > 
> 
> > >>> a[:, 1]
> 
> > 
> 
> > array([1, 2, 3])
> 
> > 
> 
> > >>> a[:, 0] + a[:, 1]
> 
> > 
> 
> > array([2, 3, 5])
> 
> > 
> 
> > 
> 
> > 
> 
> > But should they be added together to make mono?
> 
> > 
> 
> > 
> 
> > 
> 
> > Suppose, for example, that both channels have a maximum value. Their
> 
> > 
> 
> > sum would be _twice_ the maximum.
> 
> > 
> 
> > 
> 
> > 
> 
> > Therefore, I think that it should probably be the average.
> 
> > 
> 
> > 
> 
> > 
> 
> >  >>> (a[:, 0] + a[:, 1]) / 2
> 
> > 
> 
> > array([1, 1, 2])
> 
> 
> 
> I'm decoding morse code. So it's CV dots and dashes.

In case anyone is interested, here is the full code.

# morsecode.py
import numpy as np
from scikits.audiolab import wavread
from scipy.signal import decimate
from pylab import plot
from pylab import show
import os

def movingaverage(interval, window_size):
window = np.ones(int(window_size)) / float(window_size)
return np.convolve(interval, window, 'same')

def wav2morse(resultDir, filename):
""" Convert a wave file to morse code
resultDir: directory for wave file and results
filename: wave file name

"""
data, _fs, _enc = wavread(resultDir + '\\' + filename)
data = np.sum(data, axis=1)
data = np.fabs(data)
data = movingaverage(data, 100)
data = decimate(data, 2)
highcount = 0
lowcount = 0
fileBase, _fileExt = os.path.splitext(filename)
f = open(resultDir + '\\' + fileBase + '.txt', 'w')
for d in data:
if d > 0.3:
if lowcount > 3000:
f.write(' ')
lowcount = 0
highcount += 1
else:
if highcount > 3000:
f.write('-')
elif highcount > 1000:
f.write('.')
highcount = 0
lowcount += 1
f.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess call is not waiting.

2012-09-14 Thread Wanderer
On Friday, September 14, 2012 8:22:44 AM UTC-4, [email protected] wrote:
> os.system worked fine, and I found something in another section of code that 
> was causing the "Too many open errors." (I was fooled, because output from 
> subprocess call didn't seem to be coming out until the open files error.
> 
> 
> 
> I'll go back and play with subprocess.call more, since os.system works. 
> That's interesting about using shlex at run time. Is that just for the sake 
> of computational cost?

I never got the hang of subprocess, either. I ended up wrapping os.system in a 
python file and using subprocess to call that with:

subprocess.Popen([sys.executable, 'Wrapper.py'])

This works for me. I'm using Windows 7.
-- 
http://mail.python.org/mailman/listinfo/python-list


splitting numpy array unevenly

2012-09-17 Thread Wanderer
I need to divide a 512x512 image array with the first horizontal and vertical 
division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit 
want to start at the edges and create a bunch of same size arrays. Is there a 
command to chop off different sized arrays?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: splitting numpy array unevenly

2012-09-18 Thread Wanderer
On Monday, September 17, 2012 7:43:06 PM UTC-4, Martin De Kauwe wrote:
> On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote:
> 
> > I need to divide a 512x512 image array with the first horizontal and 
> > vertical division 49 pixels in. Then every 59 pixels in after that. hsplit 
> > and vsplit want to start at the edges and create a bunch of same size 
> > arrays. Is there a command to chop off different sized arrays?
> 
> > 
> 
> > 
> 
> > 
> 
> > Thanks
> 
> 
> 
> I don't know that I follow completely, but can't you just slice what you are 
> after?
> 
> 
> 
> x = np.random.rand(512*512).reshape(512,512)
> 
> xx = x[0,:49]
> 
> And put the rest of the slices in a loop...?

I was trying to avoid the loop. I figured it out. hsplit and vsplit will work. 
I just need to give it a list of break points. I still need a loop though.

breakPoints = range(49,512,59)
rowArrays = hsplit(InputArray, breakPoints)
OutArrays = []
for r in rowArrays:
OutArrays.append(vsplit(r, breakPoints))
-- 
http://mail.python.org/mailman/listinfo/python-list


Checking for dlls in ctypes

2012-10-12 Thread Wanderer
I'm trying to write some code that will load one of three dll depending on the 
one available. I've tried the code below, but it doesn't work. The try except 
doesn't catch the exception. Is there a way to do this?

try:
self.dll = windll.pvcam64
except:
print "No pvcam64"
try:
self.dll = windll.pvcam32
except:
print "No pvcam32"
try:
self.dll = windll.pvcam
except:
print "No pvcam"
return
else:
print "installed pvcam"
else:
print "installed pvcam32"
else:
print "installed pvcam64"

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking for dlls in ctypes

2012-10-12 Thread Wanderer
On Friday, October 12, 2012 12:57:06 PM UTC-4, MRAB wrote:
> On 2012-10-12 16:36, Wanderer wrote:
> 
> > I'm trying to write some code that will load one of three dll depending on 
> > the one available. I've tried the code below, but it doesn't work. The try 
> > except doesn't catch the exception. Is there a way to do this?
> 
> >
> 
> >  try:
> 
> >  self.dll = windll.pvcam64
> 
> >  except:
> 
> >  print "No pvcam64"
> 
> >  try:
> 
> >  self.dll = windll.pvcam32
> 
> >  except:
> 
> >  print "No pvcam32"
> 
> >  try:
> 
> >  self.dll = windll.pvcam
> 
> >  except:
> 
> >  print "No pvcam"
> 
> >  return
> 
> >  else:
> 
> >  print "installed pvcam"
> 
> >  else:
> 
> >  print "installed pvcam32"
> 
> >  else:
> 
> >  print "installed pvcam64"
> 
> >
> 
> This works for me:
> 
> 
> 
>  for name in ("pvcam64", "pvcam32", "pvcam"):
> 
>  try:
> 
>  self.dll = getattr(windll, name)
> 
>  except OSError:
> 
>  print "No " + name
> 
>  else:
> 
>  print "Installed " + name
> 
>  return

Yes that works for me, too. Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking for dlls in ctypes

2012-10-12 Thread Wanderer
On Friday, October 12, 2012 12:29:02 PM UTC-4, Dave Angel wrote:
> On 10/12/2012 11:36 AM, Wanderer wrote:
> 
> > I'm trying to write some code that will load one of three dll depending on 
> > the one available. I've tried the code below, but it doesn't work. The try 
> > except doesn't catch the exception. Is there a way to do this?
> 
> >
> 
> > try:
> 
> > self.dll = windll.pvcam64
> 
> > except:
> 
> > print "No pvcam64"
> 
> > try:
> 
> > self.dll = windll.pvcam32
> 
> > except:
> 
> > print "No pvcam32"
> 
> > try:
> 
> > self.dll = windll.pvcam
> 
> > except:
> 
> > print "No pvcam"
> 
> > return
> 
> > else:
> 
> > print "installed pvcam"
> 
> > else:
> 
> > print "installed pvcam32"
> 
> > else:
> 
> > print "installed pvcam64"
> 
> >
> 
> 
> 
> I can't help you find the dll's, because I don't run Windows.  But I
> 
> could help you write a clearer question:
> 
> 
> 
> "doesn't work" is thoroughly useless for describing errors.  If you're
> 
> getting an exception, show us the full traceback.  That will show which
> 
> statement got the exception that wasn't caught.  Next question is which
> 
> of the dlls is missing.  Are you getting an exception because it's
> 
> missing or because of something more fundamental, like nesting exception
> 
> handlers?
> 
> 
> 
> Using bare excepts is almost never a good idea.  If it "works" you get
> 
> no clues what went wrong.  For example, a typo in source code can
> 
> trigger a bare exception, as can a user typing Ctrl-C.   So when you're
> 
> using bare excepts, you have robbed the user of any way to terminate the
> 
> program.
> 
> 
> 
> If I were you, I'd be writing a loop so there's only one try block.  Too
> 
> much duplicated code in the way you're doing it.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

Sorry. It was a WindowsError, but the code I posted now works for me and I 
can't reproduce the problem. I'll be more diligent in the future.
-- 
http://mail.python.org/mailman/listinfo/python-list


Exception Messages

2012-10-15 Thread Wanderer
How do you get Exceptions to print messages? I have an exception defined like 
this

class PvCamError(Exception):
def __init__(self, msg):
self.msg = msg

But when the error is raised I get this:

Traceback (most recent call last):
  File 
"C:\Python27\lib\site-packages\ipython-0.12.1-py2.7.egg\IPython\core\interactiveshell.py",
 line 2538, in run_code
exec code_obj in self.user_global_ns, self.user_ns
  File "", line 1, in 
import S477Test
  File "U:\workspace\camera\src\S477Test.py", line 13, in 
camera.getSerialNum()
  File "U:\workspace\camera\src\S477.py", line 131, in getSerialNum
num = self.pl.getParamValue(pvcamConstants.PARAM_HEAD_SER_NUM_ALPHA)
  File "U:\workspace\camera\src\pvcam.py", line 261, in getParamValue
raise PvCamError("Unhandled Type: {0}".format(attype))
PvCamError

Why wasn't the message printed out?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:

> 
> Yes, but you've put the message in msg, and Exception doesn't have that
> 
> attribute.
> 

That's weird. I got this Exception class definition idea from this post by 
Guido van Rostrum, Where he gives this main function to look like

import sys
import getopt

class Usage(Exception):
def __init__(self, msg):
self.msg = msg

def main(argv=None):
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "h", ["help"])
except getopt.error, msg:
 raise Usage(msg)
# more code, unchanged
except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2

if __name__ == "__main__":
sys.exit(main())




http://www.artima.com/weblogs/viewpost.jsp?thread=4829


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:18:52 PM UTC-4, Wanderer wrote:
> On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:
> 
> 
> 
> > 
> 
> > Yes, but you've put the message in msg, and Exception doesn't have that
> 
> > 
> 
> > attribute.
> 
> > 
> 
> 
> 
> That's weird. I got this Exception class definition idea from this post by 
> Guido van Rostrum, Where he gives this main function to look like
> 
> 
> 
> import sys
> 
> import getopt
> 
> 
> 
> class Usage(Exception):
> 
> def __init__(self, msg):
> 
> self.msg = msg
> 
> 
> 
> def main(argv=None):
> 
> if argv is None:
> 
> argv = sys.argv
> 
> try:
> 
> try:
> 
> opts, args = getopt.getopt(argv[1:], "h", ["help"])
> 
> except getopt.error, msg:
> 
>  raise Usage(msg)
> 
> # more code, unchanged
> 
> except Usage, err:
> 
> print >>sys.stderr, err.msg
> 
> print >>sys.stderr, "for help use --help"
> 
> return 2
> 
> 
> 
> if __name__ == "__main__":
> 
> sys.exit(main())
> 
> 
> 
> 
> 
> 
> 
> 
> 
> http://www.artima.com/weblogs/viewpost.jsp?thread=4829

Oops. I meant Guido van Rossum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:34:24 PM UTC-4, MRAB wrote:
> On 2012-10-15 18:18, Wanderer wrote:
> 
> > On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:
> 
> >
> 
> >>
> 
> >> Yes, but you've put the message in msg, and Exception doesn't have that
> 
> >>
> 
> >> attribute.
> 
> >>
> 
> >
> 
> > That's weird. I got this Exception class definition idea from this post by 
> > Guido van Rostrum, Where he gives this main function to look like
> 
> >
> 
> > import sys
> 
> > import getopt
> 
> >
> 
> > class Usage(Exception):
> 
> >  def __init__(self, msg):
> 
> >  self.msg = msg
> 
> >
> 
> > def main(argv=None):
> 
> >  if argv is None:
> 
> >  argv = sys.argv
> 
> >  try:
> 
> >  try:
> 
> >  opts, args = getopt.getopt(argv[1:], "h", ["help"])
> 
> >  except getopt.error, msg:
> 
> >   raise Usage(msg)
> 
> >  # more code, unchanged
> 
> >  except Usage, err:
> 
> >  print >>sys.stderr, err.msg
> 
> >  print >>sys.stderr, "for help use --help"
> 
> >  return 2
> 
> >
> 
> > if __name__ == "__main__":
> 
> >  sys.exit(main())
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > http://www.artima.com/weblogs/viewpost.jsp?thread=4829
> 
> >
> 
> >
> 
> Note how it explicitly prints err.msg.

Not in the raise statement. 

Adding the def __str__ made it work for me.
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Preventing tread collisions

2012-12-12 Thread Wanderer
I have a program that has a main GUI and a camera. In the main GUI, you can 
manipulate the images taken by the camera. You can also use the menu to check 
the camera's settings. Images are taken by the camera in a separate thread, so 
the long exposures don't block the GUI. I block conflicts between the camera 
snapshot thread and the main thread by setting a flag called self.cameraActive. 
I check to see if the cameraActive flag is false and set the cameraActive to 
True just before starting the thread. I generate an event on exiting the thread 
which sets the cameraActive flag to False. I also check and set and reset the 
flag in all the menu commands that access the camera. Like this.

def onProperties(self, event):
""" Display a message window with the camera properties
event -- The camera properties menu event
"""
# Update the temperature
if not self.cameraActive:
self.cameraActive = True
self.camera.getTemperature()
camDict = self.camera.getPropertyDict()
self.cameraActive = False
else:
camDict = {'Error': 'Camera Busy'}
dictMessage(camDict, 'Camera Properties')

This works but my question is, is there a better way using semaphores, locks or 
something else to prevent collisions between threads?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing tread collisions

2012-12-13 Thread Wanderer
On Wednesday, December 12, 2012 3:53:28 PM UTC-5, MRAB wrote:
> On 2012-12-12 20:11, Wanderer wrote:
> 
> > I have a program that has a main GUI and a camera. In the main GUI, you can 
> > manipulate the images taken by the camera. You can also use the menu to 
> > check the camera's settings. Images are taken by the camera in a separate 
> > thread, so the long exposures don't block the GUI. I block conflicts 
> > between the camera snapshot thread and the main thread by setting a flag 
> > called self.cameraActive. I check to see if the cameraActive flag is false 
> > and set the cameraActive to True just before starting the thread. I 
> > generate an event on exiting the thread which sets the cameraActive flag to 
> > False. I also check and set and reset the flag in all the menu commands 
> > that access the camera. Like this.
> 
> >
> 
> >  def onProperties(self, event):
> 
> >  """ Display a message window with the camera properties
> 
> >  event -- The camera properties menu event
> 
> >  """
> 
> >  # Update the temperature
> 
> >  if not self.cameraActive:
> 
> >  self.cameraActive = True
> 
> >  self.camera.getTemperature()
> 
> >  camDict = self.camera.getPropertyDict()
> 
> >  self.cameraActive = False
> 
> >  else:
> 
> >  camDict = {'Error': 'Camera Busy'}
> 
> >  dictMessage(camDict, 'Camera Properties')
> 
> >
> 
> > This works but my question is, is there a better way using semaphores, 
> > locks or something else to prevent collisions between threads?
> 
> >
> 
> That suffers from a race condition in that self.cameraActive might be
> 
> False when it's checked in the 'if' condition but set to True just
> 
> afterwards by the other thread.
> 
> 
> 
> You could try a non-blocking semaphore:
> 
> 
> 
> def __init__(self):
> 
>  self.cameraActive = Semaphore()
> 
> 
> 
> def onProperties(self, event):
> 
>  """ Display a message window with the camera properties
> 
>  event -- The camera properties menu event
> 
>  """
> 
>  # Update the temperature
> 
>  if self.cameraActive.acquire(False): # Non-blocking
> 
>  # Successfully acquired the semaphore, so the camera wasn't active
> 
>  self.camera.getTemperature()
> 
>  camDict = self.camera.getPropertyDict()
> 
>  self.cameraActive.release()
> 
>  else:
> 
>  camDict = {'Error': 'Camera Busy'}

Thanks. Why Non-blocking?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing tread collisions

2012-12-13 Thread Wanderer
On Thursday, December 13, 2012 11:54:10 AM UTC-5, Dave Angel wrote:
> On 12/13/2012 11:36 AM, Wanderer wrote:
> 
> > 
> 
> >
> 
> > Thanks. Why Non-blocking?
> 
> 
> 
> You said you didn't want the GUI to lock up.  Non-blocking lets you
> 
> choose alternative action when you would otherwise have to wait for the
> 
> resource.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

Thanks. I understand now.
-- 
http://mail.python.org/mailman/listinfo/python-list


WLAN tester

2013-01-28 Thread Wanderer
I'm looking to make a WLAN tester for a manufacturing test. Something that 
could send and receive a bunch of files and measure how long it took. I would 
repeat this a number of times for a device under test and then use some metric 
to decide pass/fail and create a report. What libraries are available for 
Python for communicating with networks? My google searches have been 
disappointing. I'd prefer to do this in Windows but I'll consider Linux if that 
is the better option. 

Thanks 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WLAN tester

2013-01-28 Thread Wanderer
On Monday, January 28, 2013 11:30:47 AM UTC-5, Dave Angel wrote:
> On 01/28/2013 10:47 AM, Wanderer wrote:
> 
> > I'm looking to make a WLAN tester for a manufacturing test. Something that 
> > could send and receive a bunch of files and measure how long it took. I 
> > would repeat this a number of times for a device under test and then use 
> > some metric to decide pass/fail and create a report. What libraries are 
> > available for Python for communicating with networks? My google searches 
> > have been disappointing. I'd prefer to do this in Windows but I'll consider 
> > Linux if that is the better option.
> 
> >
> 
> > Thanks
> 
> >
> 
> For what version of Python?
> 
> 
> 
> Depending on what's at the far end of your connection, you may not need 
> 
> to do much at all.  For example, if you have an ftp server, check out
> 
>  http://docs.python.org/2/library/ftplib.html
> 
> 
> 
> in the standard library.
> 
> 
> 
> 
> 
> 
> 
> Since you're doing performance testing, be aware that it's quite tricky 
> 
> to get meaningful results.For example, some connections have a 
> 
> satellite link in them, and thus have very long latency.  A simple 
> 
> protocol will go very slowly in such a case, but most downloaders will 
> 
> open multiple sockets, and do many transfers in parallel.  So you could 
> 
> either measure the slow way or the fast way, and both numbers are 
> 
> meaningful.
> 
> 
> 
> Of course, it's more than a  2-way choice.  Some protocols will compress 
> 
> the data, send it, and decompress it on the other end.  Others (like the 
> 
> one rsync uses) will evaluate both ends, and decide which (if any) files 
> 
> need to be transferred at all.  I believe it also does partial file 
> 
> updates if possible, but I'm not at all sure about that.
> 
> 
> 
> Naturally, the throughput will vary greatly from moment to moment, and 
> 
> may be affected by lots of things you cannot see.
> 
> 
> 
> -- 
> 
> DaveA

Yes. I noticed this variability. I've been using the Totusoft Lan_Speedtest.exe 
to test some modules. I've tested through the wifi to our intranet and saw 
variations I believe do to network traffic. I also tried peer to peer and the 
write time actual got worse. I don't know if it has do to with the firewall or 
the hard drive speed or just Windows giving this process low priority. I also 
saw drop outs. So figuring out the metric for pass/fail will be interesting. 
I'll check into setting an ftp for this test.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WLAN tester

2013-01-28 Thread Wanderer
On Monday, January 28, 2013 12:32:50 PM UTC-5, Rob Day wrote:
> On 28 January 2013 17:07, Wanderer wrote:
> 
> > Yes. I noticed this variability. I've been using the Totusoft 
> > Lan_Speedtest.exe to test some modules. I've tested through the wifi to our 
> > intranet and saw variations I believe do to network traffic. I also tried 
> > peer to peer and the write time actual got worse. I don't know if it has do 
> > to with the firewall or the hard drive speed or just Windows giving this 
> > process low priority. I also saw drop outs. So figuring out the metric for 
> > pass/fail will be interesting. I'll check into setting an ftp for this test.
> 
> 
> 
> Why involve a protocol at all? I'd just create a socket
> 
> (http://docs.python.org/3.3/library/socket.html) and measure how long,
> 
> on average, it took to write a given number of arbitrary bytes (e.g.
> 
> "This is a string" repeated a million times) to it and then read a
> 
> given number of bytes back. That would be a relatively consistent
> 
> metric, whereas if you try using FTP you'll run into issues, as
> 
> already noted, where disk read/write speed and details of your FTP
> 
> server implementation like compression or multiple network connections
> 
> affect the result significantly.
> 
> 
> 
> --
> 
> Robert K. Day
> 
>

Thanks, I'll check out sockets. That's probably what I needed to search for 
instead WLAN and Wi-Fi.
-- 
http://mail.python.org/mailman/listinfo/python-list


What happened tp scipy.stsci?

2012-01-23 Thread Wanderer
Back in scipy 0.7 there was a package called stsci that had  function
scipy.stsci.image.median that created a median image from a stack of
images. The stsci package is dropped in v0.8. Has this functionality
been moved to a different package?

Thanks

Apologies if this is a double post. I had problems with google groups.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What happened tp scipy.stsci?

2012-01-25 Thread Wanderer
I found it it is in the stsci package.

On Jan 24, 11:36 am, Eelco  wrote:

> Either way, if I understand correctly, what you are trying to do could
> be done with numpy.median(imagestack, axis=stackaxis), no?

Yes, I guess so. I didn't realize numpy.median had an axis option.
Thanks. That's one less import.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What happened tp scipy.stsci?

2012-01-26 Thread Wanderer
On Jan 25, 1:12 pm, Wanderer  wrote:
> I found it it is in the stsci package.
>
> On Jan 24, 11:36 am, Eelco  wrote:
>
> > Either way, if I understand correctly, what you are trying to do could
> > be done with numpy.median(imagestack, axis=stackaxis), no?
>
> Yes, I guess so. I didn't realize numpy.median had an axis option.
> Thanks. That's one less import.

Actually numpy.median doesn't work. numpy.median does not accept axis
greater than 2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What happened tp scipy.stsci?

2012-01-26 Thread Wanderer
On Jan 26, 2:56 pm, Wanderer  wrote:
> On Jan 25, 1:12 pm, Wanderer  wrote:
>
> > I found it it is in the stsci package.
>
> > On Jan 24, 11:36 am, Eelco  wrote:
>
> > > Either way, if I understand correctly, what you are trying to do could
> > > be done with numpy.median(imagestack, axis=stackaxis), no?
>
> > Yes, I guess so. I didn't realize numpy.median had an axis option.
> > Thanks. That's one less import.
>
> Actually numpy.median doesn't work. numpy.median does not accept axis
> greater than 2.

numpy.median does work. I had to use dstack to create my stacks.
-- 
http://mail.python.org/mailman/listinfo/python-list


PyDev not saving Ipython History between sessions

2012-02-08 Thread Wanderer
One feature I like about Ipython is that it saves the history between
sessions. The history isn't saved if you close Ipython with the corner
X, but if you type 'exit()' it is saved. This doesn't work when using
Ipython as the console in Pydev. Do I have something setup wrong? Is
there a different command than exit() I should use before closing a
session in PyDev. Is there a command to load the history when I start
a session?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Change os.makedirs to handle existing directory

2012-02-13 Thread Wanderer
I think wanting to create a directory if one doesn't exist or do
nothing if it does exist and just use the existing directory is a
fairly normal programming need. Apparently this is somewhat
complicated in Python. If you use

if not os.path.exists(dirName):
os.makedirs(dirName)

you create a race condition. If you use try:

try:
os.makedirs(dirName)
except OSError:
pass

Now you're silencing too many errors, so you need to select which
errors to silence. You can check to see if the directory already
exists and assume that the directory already existing is the cause of
the error.

try:
os.makedirs(dirName)
except OSError:
if os.path.exists(dirName):
# We are nearly safe
pass
else:
# There was an error on creation, so make sure we know about
it
raise

or check the error type:

try:
os.makedirs(dirName)
except OSError, e:
if e.errno != errno.EEXIST:
raise


IMHO, os.makedirs should do this for you with something like

os.makedirs(dirName, exist = False)

and have makedirs silence the error the 'right' way whatever that is,
without turning it into an exercise for the user.








-- 
http://mail.python.org/mailman/listinfo/python-list


Python recursive tree, linked list thingy

2012-03-07 Thread Wanderer
I have a list of defective CCD pixels and I need to find clusters
where a cluster is a group of adjacent defective pixels. This seems to
me to be a classic linked list tree search.I take a pixel from the
defective list and check if an adjacent pixel is in the list. If it is
I add the pixel to the cluster and remove it from the defective list.
I then check an adjacent pixel of the new pixel and so on down the
branch until I don't find a defective pixel. The I move up to the
previous pixel and check the next adjacent pixel  and so on until I'm
back at the head I can't find any more defective adjacent pixels. How
do you handle this sort of thing in Python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python recursive tree, linked list thingy

2012-03-08 Thread Wanderer
On Mar 7, 3:27 pm, Ian Kelly  wrote:
> On Wed, Mar 7, 2012 at 1:03 PM, Ian Kelly  wrote:
> > A set of defective pixels would be the probable choice, since it
> > offers efficient membership testing.
>
> Some actual code, using a recursive generator:
>
> def get_cluster(defective, pixel):
>     yield pixel
>     (row, column) = pixel
>     for adjacent in [(row - 1, column), (row, column - 1),
>                      (row, column + 1), (row + 1, column)]:
>         if adjacent in defective:
>             defective.remove(adjacent)
>             for cluster_pixel in get_cluster(defective, adjacent):
>                 yield cluster_pixel
>
> defective = {(327, 415), (180, 97), (326, 415), (42, 15),
>              (180, 98), (325, 414), (325, 415)}
> clusters = []
>
> while defective:
>     pixel = defective.pop()
>     clusters.append(list(get_cluster(defective, pixel)))
>
> from pprint import pprint
> pprint(clusters)
>
> Cheers,
> Ian

This works for me and I can modify it to look for column defects also.
It also shows I know less about Python then I thought I did. I had to
read up on generators and iterators to understand the code.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


PyDev IPython Confusion

2012-05-23 Thread Wanderer
I have two versions of Python and Ipython; Python 2.6.6 with Ipython
0.11 and Python 2.7.3 with Ipython 0.12.  When I run the Eclipse PyDev
console for the Python 2.7.3 it says it is using Ipython 0.11 as the
interpreter. Ipython 0.11 should not be in the Path for Python 2.7.3.
Is this a bug in Ipython 0.12? Is there a command to check the Ipython
version to verify it is Ipython 0.11 and not Ipython 0.12? Could this
be something in the Windows registry that Ipython 0.11 is the
'registered' version of Ipython?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with raw image files

2011-06-13 Thread Wanderer
On Jun 13, 2:18 pm, kafooster  wrote:
> I am working on some medical image data, and I try to look into
> specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
> dimensions are 352*470*96. I checked it in some pro medical image
> viewer, it is alright. However, with the code I use, I display just
> white noise image.(but worked well for other, 8bit raw image).
>  Also, printed size is half the original size, like it was 8 bit. I
> read some documentations on PIL, numpy etc but I think I just do not
> understand something.
> I open image data set, I change it to array, give it dimensions,
> dtype, and change it to image, right? I think there is something
> messed up in 'binvalues', but dont really know how to write it in
> simpler way.
>
> P.S.1
> If I want to change data type to e.g. 8 bit uint, is it just change in
> scipy.array? or it requires some more changes
>
> P.S.2
> Lets say I have my array of image data and want to save it to *.raw
> data set. is it array.tofile?
>
> Here is my code
>
> 
>
> import scipy as sc
> from pylab import *
> import array
> import Image
>
> fileobj = open("hand.raw", 'rb')
> binvalues = array.array('B')
> binvalues.read (fileobj, 352*470*96)
> data1 = sc.array(binvalues, dtype=sc.int16)
> data2 = sc.reshape(data1, (352,470,96))
> fileobj.close()
> print data2.size , data2.dtype
>
> im = Image.fromarray(data2[:,:,40])
> im.show()

Try using numpy arrays.

import numpy as np
import Image

image1 = Image.open("hand.raw", 'rb')
imshape = image1.size
npArray = np.array(image1.getdata())
npArray.shape = imshape

im = Image.fromarray(npArray)
im.show()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with raw image files

2011-06-13 Thread Wanderer
On Jun 13, 4:08 pm, Wanderer  wrote:
> On Jun 13, 2:18 pm, kafooster  wrote:
>
>
>
>
>
>
>
>
>
> > I am working on some medical image data, and I try to look into
> > specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
> > dimensions are 352*470*96. I checked it in some pro medical image
> > viewer, it is alright. However, with the code I use, I display just
> > white noise image.(but worked well for other, 8bit raw image).
> >  Also, printed size is half the original size, like it was 8 bit. I
> > read some documentations on PIL, numpy etc but I think I just do not
> > understand something.
> > I open image data set, I change it to array, give it dimensions,
> > dtype, and change it to image, right? I think there is something
> > messed up in 'binvalues', but dont really know how to write it in
> > simpler way.
>
> > P.S.1
> > If I want to change data type to e.g. 8 bit uint, is it just change in
> > scipy.array? or it requires some more changes
>
> > P.S.2
> > Lets say I have my array of image data and want to save it to *.raw
> > data set. is it array.tofile?
>
> > Here is my code
>
> > 
>
> > import scipy as sc
> > from pylab import *
> > import array
> > import Image
>
> > fileobj = open("hand.raw", 'rb')
> > binvalues = array.array('B')
> > binvalues.read (fileobj, 352*470*96)
> > data1 = sc.array(binvalues, dtype=sc.int16)
> > data2 = sc.reshape(data1, (352,470,96))
> > fileobj.close()
> > print data2.size , data2.dtype
>
> > im = Image.fromarray(data2[:,:,40])
> > im.show()
>
> Try using numpy arrays.
>
> import numpy as np
> import Image
>
> image1 = Image.open("hand.raw", 'rb')
> imshape = image1.size
> npArray = np.array(image1.getdata())
> npArray.shape = imshape
>
> im = Image.fromarray(npArray)
> im.show()

P.S.1
If you want to change data size from a data buffer, you could use
something like.

 image1 = np.frombuffer(Buffer, np.uint16)

P.S.2
I'm not sure what a *.raw file is but if Image has support for it you
just need to include the extension.

 im = Image.fromarray(npArray)
 im.save(self.resultDir + "\\" + imageName + '.tif')



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with raw image files

2011-06-13 Thread Wanderer
On Jun 13, 4:41 pm, kafooster  wrote:
> Wanderer: by *.raw I mean images with .raw extension, pure pixel data
> without headerhttp://en.wikipedia.org/wiki/Raw_image_format
>
> That is a clear and nice code however I think Image.open cannot
> handle .raw since i get error
>
>     image1 = Image.open("hand.raw", "rb")
>   File "D:\Python27\lib\site-packages\PIL\Image.py", line 1947, in
> open
>     raise ValueError("bad mode")
> ValueError: bad mode

Try dropping the "rb". I don't use it in my code. I copied it from the
OP.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with raw image files

2011-06-13 Thread Wanderer
On Jun 13, 4:58 pm, kafooster  wrote:
> On 13 Cze, 22:52, Wanderer  wrote:
>
>
>
>
>
>
>
>
>
> > On Jun 13, 4:41 pm, kafooster  wrote:
>
> > > Wanderer: by *.raw I mean images with .raw extension, pure pixel data
> > > without headerhttp://en.wikipedia.org/wiki/Raw_image_format
>
> > > That is a clear and nice code however I think Image.open cannot
> > > handle .raw since i get error
>
> > >     image1 = Image.open("hand.raw", "rb")
> > >   File "D:\Python27\lib\site-packages\PIL\Image.py", line 1947, in
> > > open
> > >     raise ValueError("bad mode")
> > > ValueError: bad mode
>
> > Try dropping the "rb". I don't use it in my code. I copied it from the
> > OP.
>
> I tried it, then it cannot identify image file

You're right raw is not a supported file format.

http://www.pythonware.com/library/pil/handbook/index.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating a multi colored graph with respect to the values in y-axis

2011-06-15 Thread Wanderer
On Jun 15, 11:04 am, Ravikanth  wrote:
> Hi all,
>
> I am a beginner in python. I need to implement a graph with multiple
> colors in it.
> In a way, I have a function which varies with respect to time and
> amplitude. I have time on x-axis and amplitude on y-axis. Lets say the
> amplitude of the graph is divided into 4 ranges, say 1-3,3-5,5-9,
> 10-3. I need to plot the graph in such a way that, when the values of
> amplitude are in a particular range say 1-3, the color of graph should
> be red.
> If the amplitude is in the range from 3-5 the graph need to be in
> color blue etc..,
>
> Can somebody guide me on this, how to achive this functionality.
>
> Regards,
> Ravikanth

Check out the examples in matplotlib.

http://matplotlib.sourceforge.net/examples/pylab_examples/multicolored_line.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating a multi colored graph with respect to the values in y-axis

2011-06-15 Thread Wanderer
On Jun 15, 12:00 pm, Ravikanth  wrote:
> On Jun 15, 10:32 am, Wanderer  wrote:
>
>
>
>
>
>
>
>
>
> > On Jun 15, 11:04 am, Ravikanth  wrote:
>
> > > Hi all,
>
> > > I am a beginner in python. I need to implement a graph with multiple
> > > colors in it.
> > > In a way, I have a function which varies with respect to time and
> > > amplitude. I have time on x-axis and amplitude on y-axis. Lets say the
> > > amplitude of the graph is divided into 4 ranges, say 1-3,3-5,5-9,
> > > 10-3. I need to plot the graph in such a way that, when the values of
> > > amplitude are in a particular range say 1-3, the color of graph should
> > > be red.
> > > If the amplitude is in the range from 3-5 the graph need to be in
> > > color blue etc..,
>
> > > Can somebody guide me on this, how to achive this functionality.
>
> > > Regards,
> > > Ravikanth
>
> > Check out the examples in matplotlib.
>
> >http://matplotlib.sourceforge.net/examples/pylab_examples/multicolore...Hide 
> >quoted text -
>
> > - Show quoted text -
>
> I did go through the side wanderer.
>
> I wasn't able to figure out the usage of boundaryNorm and
> lc.set_array(z) , in that link.
> according to my understanding,
>
> cmap = ListedColormap(['r', 'g', 'b'])
> norm = BoundaryNorm([-1, -0.5, 0.5, 1], cmap.N)
>
> In the above lines of code, as per my understanding,
> Listedcolor map, maps the colors r,g and b to specific indexes into
> cmap
> i.e cmap(0) represents red,
> cmap(1) represents blue
> cmap(2) represents green.
> for any index greater than 3 a color of blue is returned..
>
> >>> cmap = ListedColormap(['r', 'g', 'b'])
> >>> cmap(0)
>
> (1.0, 0.0, 0.0, 1.0)>>> cmap(1)
>
> (0.0, 0.5, 0.0, 1.0)>>> cmap(2)
>
> (0.0, 0.0, 1.0, 1.0)>>> cmap(3)
>
> (0.0, 0.0, 1.0, 1.0)
>
> In this context, I was not able to understand what does boundaryNorm
> does.
> We have 3 colors and we are using 4 values as argument in boundaryNorm.
> [-1, -0.5, 0.5, 1], the comment reads slope of 'z' is being mapped to
> the values in boundary norm. How is it handled.
> Does the function call " lc.set_array(z) " does it ?  what is the
> exact use of linecollection.set_array(z) in this context.
>
> Thanks,
> Ravikanth

The colors are referring to the slope of the line. Change
'lc.set_array(z)' to 'lc.set_array(y)' and it might be easier to
understand.  Here are the steps.

1. Define the functions x,y and z,
2. Define the colors 'red', 'green' and 'blue' with ListedColorMap
3. Define the three regions, (-1.0 to -0.50, -0.50 to 0.50, 0.50 to
1.0) with BoundaryNorm([-1,-0.50, 0.50,1], cmap.N).
   (Why they add the trailing zero in 0.50 and don't change 1 to 1.0;
I don't know)
4. Create an array of (x,y) points.
5. Create a collection of tiny segments [(x1,y1),(x2,y2)] and color
them with cmap using the boundary rules of norm. lc =
LineCollection(segments, cmap=cmap, norm=norm)
6. Use lc.set_array(y) to determine how to color the segments.
7. Plot it.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating a multi colored graph with respect to the values in y-axis

2011-06-15 Thread Wanderer
On Jun 15, 1:28 pm, Ravikanth  wrote:
> On Jun 15, 11:57 am, Wanderer  wrote:
>
>
>
>
>
>
>
>
>
> > On Jun 15, 12:00 pm, Ravikanth  wrote:
>
> > > On Jun 15, 10:32 am, Wanderer  wrote:
>
> > > > On Jun 15, 11:04 am, Ravikanth  wrote:
>
> > > > > Hi all,
>
> > > > > I am a beginner in python. I need to implement a graph with multiple
> > > > > colors in it.
> > > > > In a way, I have a function which varies with respect to time and
> > > > > amplitude. I have time on x-axis and amplitude on y-axis. Lets say the
> > > > > amplitude of the graph is divided into 4 ranges, say 1-3,3-5,5-9,
> > > > > 10-3. I need to plot the graph in such a way that, when the values of
> > > > > amplitude are in a particular range say 1-3, the color of graph should
> > > > > be red.
> > > > > If the amplitude is in the range from 3-5 the graph need to be in
> > > > > color blue etc..,
>
> > > > > Can somebody guide me on this, how to achive this functionality.
>
> > > > > Regards,
> > > > > Ravikanth
>
> > > > Check out the examples in matplotlib.
>
> > > >http://matplotlib.sourceforge.net/examples/pylab_examples/multicolore...text
> > > > -
>
> > > > - Show quoted text -
>
> > > I did go through the side wanderer.
>
> > > I wasn't able to figure out the usage of boundaryNorm and
> > > lc.set_array(z) , in that link.
> > > according to my understanding,
>
> > > cmap = ListedColormap(['r', 'g', 'b'])
> > > norm = BoundaryNorm([-1, -0.5, 0.5, 1], cmap.N)
>
> > > In the above lines of code, as per my understanding,
> > > Listedcolor map, maps the colors r,g and b to specific indexes into
> > > cmap
> > > i.e cmap(0) represents red,
> > > cmap(1) represents blue
> > > cmap(2) represents green.
> > > for any index greater than 3 a color of blue is returned..
>
> > > >>> cmap = ListedColormap(['r', 'g', 'b'])
> > > >>> cmap(0)
>
> > > (1.0, 0.0, 0.0, 1.0)>>> cmap(1)
>
> > > (0.0, 0.5, 0.0, 1.0)>>> cmap(2)
>
> > > (0.0, 0.0, 1.0, 1.0)>>> cmap(3)
>
> > > (0.0, 0.0, 1.0, 1.0)
>
> > > In this context, I was not able to understand what does boundaryNorm
> > > does.
> > > We have 3 colors and we are using 4 values as argument in boundaryNorm.
> > > [-1, -0.5, 0.5, 1], the comment reads slope of 'z' is being mapped to
> > > the values in boundary norm. How is it handled.
> > > Does the function call " lc.set_array(z) " does it ?  what is the
> > > exact use of linecollection.set_array(z) in this context.
>
> > > Thanks,
> > > Ravikanth
>
> > The colors are referring to the slope of the line. Change
> > 'lc.set_array(z)' to 'lc.set_array(y)' and it might be easier to
> > understand.  Here are the steps.
>
> > 1. Define the functions x,y and z,
> > 2. Define the colors 'red', 'green' and 'blue' with ListedColorMap
> > 3. Define the three regions, (-1.0 to -0.50, -0.50 to 0.50, 0.50 to
> > 1.0) with BoundaryNorm([-1,-0.50, 0.50,1], cmap.N).
> >    (Why they add the trailing zero in 0.50 and don't change 1 to 1.0;
> > I don't know)
> > 4. Create an array of (x,y) points.
> > 5. Create a collection of tiny segments [(x1,y1),(x2,y2)] and color
> > them with cmap using the boundary rules of norm. lc =
> > LineCollection(segments, cmap=cmap, norm=norm)
> > 6. Use lc.set_array(y) to determine how to color the segments.
> > 7. Plot it.- Hide quoted text -
>
> > - Show quoted text -
>
> Hi Wanderer,
>
> Thanks for your help. It works now.
> Just wanted to know how to go about when I have to do my color mapping
> not only with respect to range of values on y-axis but also based on
> some other conditions as well. i.e, say ( range &&  &&
>  ) where condition1 could be occurance of some event say,
> a flag1 is set true and condition2 may be another flag2 set to false.
> Just wanted to use my color mapping not only based on boundaries but
> also on occurance of other events as well.
> In this context do i have to modify the source of BoundaryNorm in
> matplotlib function...?? Can you give me some insights into this.
>
> Regards,
> Ravikanth

I don't know if there is another way, but I think changing the
lc.set_array input would be the easiest. Each point has an (x,y,z)
where z determines the color by what range it is in. You would use
your conditions to set points in z to the desired color.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating a multi colored graph with respect to the values in y-axis

2011-06-15 Thread Wanderer
On Jun 15, 2:10 pm, Ravikanth  wrote:
> On Jun 15, 12:59 pm, Wanderer  wrote:
>
>
>
>
>
>
>
>
>
> > On Jun 15, 1:28 pm, Ravikanth  wrote:
>
> > > On Jun 15, 11:57 am, Wanderer  wrote:
>
> > > > On Jun 15, 12:00 pm, Ravikanth  wrote:
>
> > > > > On Jun 15, 10:32 am, Wanderer  wrote:
>
> > > > > > On Jun 15, 11:04 am, Ravikanth  wrote:
>
> > > > > > > Hi all,
>
> > > > > > > I am a beginner in python. I need to implement a graph with 
> > > > > > > multiple
> > > > > > > colors in it.
> > > > > > > In a way, I have a function which varies with respect to time and
> > > > > > > amplitude. I have time on x-axis and amplitude on y-axis. Lets 
> > > > > > > say the
> > > > > > > amplitude of the graph is divided into 4 ranges, say 1-3,3-5,5-9,
> > > > > > > 10-3. I need to plot the graph in such a way that, when the 
> > > > > > > values of
> > > > > > > amplitude are in a particular range say 1-3, the color of graph 
> > > > > > > should
> > > > > > > be red.
> > > > > > > If the amplitude is in the range from 3-5 the graph need to be in
> > > > > > > color blue etc..,
>
> > > > > > > Can somebody guide me on this, how to achive this functionality.
>
> > > > > > > Regards,
> > > > > > > Ravikanth
>
> > > > > > Check out the examples in matplotlib.
>
> > > > > >http://matplotlib.sourceforge.net/examples/pylab_examples/multicolore...
>
> > > > > > - Show quoted text -
>
> > > > > I did go through the side wanderer.
>
> > > > > I wasn't able to figure out the usage of boundaryNorm and
> > > > > lc.set_array(z) , in that link.
> > > > > according to my understanding,
>
> > > > > cmap = ListedColormap(['r', 'g', 'b'])
> > > > > norm = BoundaryNorm([-1, -0.5, 0.5, 1], cmap.N)
>
> > > > > In the above lines of code, as per my understanding,
> > > > > Listedcolor map, maps the colors r,g and b to specific indexes into
> > > > > cmap
> > > > > i.e cmap(0) represents red,
> > > > > cmap(1) represents blue
> > > > > cmap(2) represents green.
> > > > > for any index greater than 3 a color of blue is returned..
>
> > > > > >>> cmap = ListedColormap(['r', 'g', 'b'])
> > > > > >>> cmap(0)
>
> > > > > (1.0, 0.0, 0.0, 1.0)>>> cmap(1)
>
> > > > > (0.0, 0.5, 0.0, 1.0)>>> cmap(2)
>
> > > > > (0.0, 0.0, 1.0, 1.0)>>> cmap(3)
>
> > > > > (0.0, 0.0, 1.0, 1.0)
>
> > > > > In this context, I was not able to understand what does boundaryNorm
> > > > > does.
> > > > > We have 3 colors and we are using 4 values as argument in 
> > > > > boundaryNorm.
> > > > > [-1, -0.5, 0.5, 1], the comment reads slope of 'z' is being mapped to
> > > > > the values in boundary norm. How is it handled.
> > > > > Does the function call " lc.set_array(z) " does it ?  what is the
> > > > > exact use of linecollection.set_array(z) in this context.
>
> > > > > Thanks,
> > > > > Ravikanth
>
> > > > The colors are referring to the slope of the line. Change
> > > > 'lc.set_array(z)' to 'lc.set_array(y)' and it might be easier to
> > > > understand.  Here are the steps.
>
> > > > 1. Define the functions x,y and z,
> > > > 2. Define the colors 'red', 'green' and 'blue' with ListedColorMap
> > > > 3. Define the three regions, (-1.0 to -0.50, -0.50 to 0.50, 0.50 to
> > > > 1.0) with BoundaryNorm([-1,-0.50, 0.50,1], cmap.N).
> > > >    (Why they add the trailing zero in 0.50 and don't change 1 to 1.0;
> > > > I don't know)
> > > > 4. Create an array of (x,y) points.
> > > > 5. Create a collection of tiny segments [(x1,y1),(x2,y2)] and color
> > > > them with cmap using the boundary rules of norm. lc =
> > > > LineCollection(segments, cmap=cmap, norm=norm)
> > > > 6. Use lc.set_array(y) to determine how to co

Re: ctypes: point to buffer in structure

2011-07-11 Thread Wanderer
On Jul 11, 1:12 am, Tim Roberts  wrote:
> Jesse R  wrote:
>
> >Hey I've been trying to convert this to run through ctypes and i'm
> >having a hard time
>
> >typedef struct _SYSTEM_PROCESS_ID_INFORMATION
> >{
> >    HANDLE ProcessId;
> >    UNICODE_STRING ImageName;
> >} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION,
> >*PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION;
>
> >to
>
> >class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure):
> >    _fields_ = [('pid', ctypes.c_ulong),
> >                    ('imageName', ctypes.c_wchar_p)]
> >...
> >does anyone know how to get this working?
>
> UNICODE_STRING is not just a pointer to wide characters.  It is itself a
> structure:
>
> typedef struct _UNICODE_STRING {
>     USHORT Length;
>     USHORT MaximumLength;
>     PWSTR  Buffer;
>
> } UNICODE_STRING;
>
> So, I think you want fields of ctypes.c_ulong, ctypes.c_ushort,
> ctypes.c_ushort, and ctypes.c_wchar_p.  MaximumLength gives the allocated
> size of the buffer.  Length gives the length of the string currently held
> in the buffer.  It can be less than the maximum length, and the buffer does
> NOT necessarily contain a zero-terminator.
>
> UNICODE_STRING and ANSI_STRING are used in kernel programming to avoid the
> potential ambiguities of counted strings.
> --
> Tim Roberts, [email protected]
> Providenza & Boekelheide, Inc.

if UNICODE_STRING is a structure you will want a structure for it

class UNICODE_STRING(ctypes.Structure):
_fields_ = [("Length", ctypes.c_ushort),
("MaximumLength" ,ctypes.c_ushort),
("Buffer", ctypes.c_wchar_p)]

class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure):
_fields_ = [("pid", ctypes.c_ulong),
("imageName", UNICODE_STRING)]


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An interesting beginner question: why we need colon at all in the python language?

2011-07-14 Thread Wanderer
On Jul 14, 10:34 am, Grant Edwards  wrote:
> On 2011-07-13, Thorsten Kampe  wrote:
>
> > * Grant Edwards (Wed, 13 Jul 2011 13:03:22 + (UTC))
> >> On 2011-07-13, Thorsten Kampe  wrote:
>
> >> >> and that that block is to be considered in relation to what was just
> >> >> said, before the colon.
>
> >> > The indentation makes it abundantly clear to the human reader that
> >> > that indented block is to be considered in relation to what was just
> >> > said, before the indentation.
>
> >> You would think so, but human readers like redundancy.
>
> > I also like redundancy (and consistency). That's why I'd much more
> > prefer a "then" than a colon which is easily overlooked while reading
> > /and/ while writing.
>
> How is the "then" going to be consistent with other things that also
> introduce blocks (def, try, with, etc.).
>
> --
> Grant Edwards               grant.b.edwards        Yow! !  I'm in a very
>                                   at               clever and adorable INSANE
>                               gmail.com            ASYLUM!!

But if you have the colon, why do you need the brackets or backslashes
in an if statement.

Why not

if condition1 or
   condition2 or
   condition3:
do_something()

The statement ain't over til there's a colon.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange output from arange()

2011-07-25 Thread Wanderer
On Jul 25, 3:20 pm, Christopher Barrington-Leigh
 wrote:
> The following code:
>
>     from pylab import arange
>     nSegments=5.0
>     print arange(0,1.0+1.0/nSegments,1.0/nSegments)
>     nSegments=6.0
>     print arange(0,1.0+1.0/nSegments,1.0/nSegments)
>     nSegments=8.0
>     print arange(0,1.0+1.0/nSegments,1.0/nSegments)
>     nSegments=10.0
>     print arange(0,1.0+1.0/nSegments,1.0/nSegments)
>
> gives an output of:
>
> [ 0.   0.2  0.4  0.6  0.8  1. ]
> [ 0.          0.1667  0.  0.5         0.6667
> 0.8333  1.          1.1667]
> [ 0.     0.125  0.25   0.375  0.5    0.625  0.75   0.875  1.   ]
> [ 0.   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9  1. ]
>
> These arrays have lengths, 6, 8, 9, and 11, in stead of 6, 7, 9, and
> 11.
> What is going on for the case of n=6?

It's rounding.

See http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html

  stop : number
  End of interval. The interval does not include this value,
except in some cases where step is not an integer and floating point
round-off affects the length of out.

The stops are

5 -- 1.2
6 -- 1.16667
8 -- 1.125
10 -- 1.1

Only 6 has to be rounded up.

-- 
http://mail.python.org/mailman/listinfo/python-list


Coding and Decoding in Python

2011-03-17 Thread Wanderer
I have a dll that to communicate with I need to send numeric codes. So
I created a dictionary. It works in one direction in that I can
address the key and get the value. But when the program returns the
value I can't get the key. This code is very simple and I could use a
list and the index except for the last value. Is there a better way to
handle coding and decoding values to strings?

QCam_Info = {
'qinfCameraType' : 0,# Camera model (see
QCam_qcCameraType)
'qinfSerialNumber': 1,# Deprecated
'qinfHardwareVersion'   : 2,# Hardware version
'qinfFirmwareVersion'   : 3,# Firmware version
'qinfCcd'  : 4,# CCD model (see
QCam_qcCcd)
'qinfBitDepth'   : 5,# Maximum bit depth
'qinfCooled'  : 6,# Returns 1 if
cooler is available, 0 if not
'qinfReserved1' : 7,# Reserved
'qinfImageWidth '  : 8,# Width of the ROI (in
pixels)
'qinfImageHeight'  : 9,# Height of the ROI (in
pixels)
'qinfImageSize' : 10,   # Size of returned
image (in bytes)
'qinfCcdType'   : 11,   # CDD type (see
QCam_qcCcdType)
'qinfCcdWidth'  : 12,   # CCD maximum width
'qinfCcdHeight' : 13,   # CCD maximum height
'qinfFirmwareBuild': 14,   # Build number of the
firmware
'qinfUniqueId': 15,   # Same as uniqueId
in QCam_CamListItem
'qinfIsModelB'   : 16,   # Cameras
manufactured after March 1, 2004 return 1, otherwise 0
'qinfIntensifierModel'  : 17,   # Intensifier tube
model (see QCam_qcIntensifierModel)
'qinfExposureRes' : 18,   # Exposure time
resolution (nanoseconds)
'qinfTriggerDelayRes' : 19,   # Trigger delay
Resolution (nanoseconds)
'qinfStreamVersion'   : 20,   # Streaming version
'qinfNormGainSigFigs'   : 21,   # Normalized Gain
Significant Figures resolution
'qinfNormGaindBRes': 22,   # Normalized Gain dB
resolution (in micro units)
'qinfNormITGainSigFigs': 23,   # Normalized Intensifier
Gain Significant Figures
'qinfNormITGaindBRes' : 24,   # Normalized Intensifier
Gain dB resolution (micro units)
'qinfRegulatedCooling'   : 25,   # 1 if camera has
regulated cooling
'qinfRegulatedCoolingLock': 26,   # 1 if camera is at
regulated temperature, 0 otherwise
'qinfFanControl'  : 29,   # 1 if camera can
control fan speed
'qinfHighSensitivityMode' : 30,   # 1 if camera has high
sensitivity mode available
'qinfBlackoutMode': 31,   # 1 if camera has
blackout mode available
'qinfPostProcessImageSize': 32,   # Returns the size (in
bytes) of the post-processed image
'qinfAsymmetricalBinning' : 33,   # 1 if camera has
asymmetrical binning (ex: 2x4)
'qinfEMGain'  : 34,   # 1 if EM gain is
supported, 0 if not
'qinfOpenDelay'   : 35,   # 1 if shutter open
delay controls are available, 0 if not
'qinfCloseDelay'  : 36,   # 1 if shutter close
delay controls are available, 0 if not
'qinfColorWheelSupported' : 37,   # 1 if color wheel is
supported, 0 if not
'qinfReserved2'   : 38,
'qinfReserved3'   : 39,
'qinfReserved4'   : 40,
'qinfReserved5'   : 41,
'qinfEasyEmModeSupported' : 42,   # 1 if camera supports
Easy EM mode
'qinfLockedGainModeSupported' : 43,
'qinf_last'   : 44,
'_qinf_force32'   : 0x
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding and Decoding in Python

2011-03-17 Thread Wanderer
On Mar 17, 11:44 am, John Gordon  wrote:
> In <2f4a08df-55ea-4a4e-9cc0-24e6b9f81...@f15g2000pro.googlegroups.com> 
> Wanderer  writes:
>
> > But when the program returns the value I can't get the key.
>
> What happens when two keys have the same value?  How would you know which
> key to return?
>
> In your sample code all the values are different, but surely that won't
> always be the case with real data.
>
> --
> John Gordon                   A is for Amy, who fell down the stairs
> [email protected]              B is for Basil, assaulted by bears
>                                 -- Edward Gorey, "The Gashlycrumb Tinies"

I guess two keys having the same value is why dictionaries don't
return keys for values, but this is a code. Each value has a unique
meaning to both sender and receiver. The text part is for making the
program understandable and printing understandable error messages.

-- 
http://mail.python.org/mailman/listinfo/python-list


ctypes pointer to structure memory swap

2011-03-18 Thread Wanderer
I'm observing some strange behavior with ctypes. I created this test
code to try to figure out what I'm doing wrong creating pointers to
structures.

from ctypes import *

class QCamSettingId(Structure):
""" QCam_settings_id
"""
_fields_ = [("f1", c_ulong),
("f2", c_ushort),
("f3", c_ushort),
("f4", c_ubyte * 8)]


class QCamSettingsEx(Structure):
""" QCam_SettingsEx
"""
_fields_ = [("size", c_ulong), # Filled by
the init routine
("pSettingsID", POINTER(QCamSettingId)),   # pointer
to the camera settings ID
("private_data", c_void_p )]   # Pointer
to a camera settings array

class QMemDriver():
""" The wrapper of QCamDriver
"""
def __init__(self):

self.QSetID = QCamSettingId()
self.QSetID_p = pointer(self.QSetID)
self.QSettings = QCamSettingsEx()
self.QSettings.pSettingsID = self.QSetID_p
self.QSettings_p = pointer(self.QSettings)

def Test(self):
"""
Test the QCamSettinsEx object
"""
print self.QSettings.pSettingsID
print self.QSettings.pSettingsID[0]
print self.QSettings.pSettingsID
print self.QSettings.pSettingsID[0]
print "pSettingsID is at", self.QSettings.pSettingsID
print "pSettingsID[0] is at", self.QSettings.pSettingsID[0]
print "pSettingsID is at", self.QSettings.pSettingsID
print "pSettingsID[0] is at", self.QSettings.pSettingsID[0]


The results I get are.

>>> qmem.Test()




pSettingsID is at 
pSettingsID[0] is at 
pSettingsID is at 
pSettingsID[0] is at 
>>> qmem = QMEMTest.QMemDriver()
>>> qmem.Test()




pSettingsID is at 
pSettingsID[0] is at 
pSettingsID is at 
pSettingsID[0] is at 

Sometimes the pointer and the object swap location and sometimes they
don't.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes pointer to structure memory swap

2011-03-18 Thread Wanderer
On Mar 18, 5:48 pm, Nobody  wrote:
> On Fri, 18 Mar 2011 10:34:35 -0700, Wanderer wrote:
> > I'm observing some strange behavior with ctypes. I created this test
> > code to try to figure out what I'm doing wrong creating pointers to
> > structures.
>
> What makes you think that you're doing anything wrong.
>
> Note that the hex number shown when printing a ctypes object is the
> object's ID (as per the id() function). This is typically the address of
> the Python object. It is not the address of the structured data nor (in
> the case of a ctypes pointer) the value of the pointer.
>
> If you want to see the actual value of a ctypes pointer, cast it to
> c_void_p then examine the .value field, e.g.:
>
>         p = pointer(x)
>         print hex(cast(p, c_void_p).value)

In the real program the pointer to the structure is passed to the DLL.
The DLL has functions CreateCameraSettingsStruct and
ReleaseCameraSettingsStruct. Once I call CreateCameraSettingStruct, I
can't delete the pointer without crashing Python. Calling
ReleaseCameraSettingStruct doesn't help. The result is the program
crashes on exit during the class destruction. I was trying to figure
out why ReleaseCameraSettingStruct doesn't release the pointer so
Python can close the program. I was checking to see what happened
before and after ReleaseCameraSettingStruct and saw this. But it
happens even if I don't run ReleaseCameraSettingStruct.

Thanks for the reply, but I'm still not sure I understand. Why should
Object1 be at address1 and Object2 be at address2 and the next moment
Object2 is at address1 and Object1 is at address2? I'll try casting
them to see what the value is before and after calling
ReleaseCameraSettingStruct.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes pointer to structure memory swap

2011-03-19 Thread Wanderer
On Mar 18, 6:42 pm, Nobody  wrote:
> On Fri, 18 Mar 2011 15:16:40 -0700, Wanderer wrote:
> > Thanks for the reply, but I'm still not sure I understand. Why should
> > Object1 be at address1 and Object2 be at address2 and the next moment
> > Object2 is at address1 and Object1 is at address2? I'll try casting
> > them to see what the value is before and after calling
> > ReleaseCameraSettingStruct.
>
> QCamSettingsEx is a ctypes Struct object. The pSettingsID "field" is a
> ctypes field, not a Python field. It will contain a "bare" pointer to the
> C-struct for the QCamSettingId object.
>
> The point of a ctypes Struct is to store data in a format usable by C
> code, i.e. the memory layout will match that of a C struct. In particular,
> pointers within that struct will be pointers to C-compatible data (e.g. C
> structs), not pointers to Python objects. If you access the fields from
> Python, ctypes will generate Python objects on-the-fly from the raw data.
>
> Whenever you read the pSettingsID field, ctypes will generate a ctypes
> pointer object (LP_QCamSettingId?) which wraps the underlying C pointer.
> If you dereference that, ctypes will generate a Python QCamSettingId
> object which wraps the C struct.
>
> As you aren't storing the references, as soon as the print statement
> completes, the reference count will drop to zero and the object will be
> deallocated. The next time you reference pSettingsID or pSettingsID[0], a
> new object will be constructed. The addresses (and thus IDs) of the Python
> objects are entirely arbitrary.

Great explanation. Now I understand. Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert ctypes 16 bit c_short array to a 32 bit numpy array

2011-03-24 Thread Wanderer

I'm using ctypes to have a dll fill a buffer with 16 bit data. I then
want to convert this data to a numpy array. The code snippet below
converts the data from 16 bit to 32 bit, but two 16 bit numbers are
concatenated to make a 32 bit number and half the array is zero.

Buffer = (c_short * byteSize)()
self.cam.Qframe.pBuffer = cast(pointer(Buffer), c_void_p)
perr = self.cam.GrabFrame()
image1 = np.frombuffer(Buffer, int)
xdim = self.cam.Qframe.width
ydim = self.cam.Qframe.height
image2 = image1.reshape(xdim, ydim)

image2 looks like

[[6291555 6357091 6160481 ..., 6488160 6226020 6553697]
 [6488163 6422625 6684770 ..., 6422624 6553697 6553696]
 [6488160 6357091 6226018 ..., 6815842 6422627 6553696]
 ...,
 [  0   0   0 ...,   0   0   0]
 [  0   0   0 ...,   0   0   0]
 [  0   0   0 ...,   0   0   0]]

How do convert 16 bit data to 32 bit data?
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert ctypes 16 bit c_short array to a 32 bit numpy array

2011-03-24 Thread Wanderer
On Mar 24, 3:14 pm, Wanderer  wrote:
> I'm using ctypes to have a dll fill a buffer with 16 bit data. I then
> want to convert this data to a numpy array. The code snippet below
> converts the data from 16 bit to 32 bit, but two 16 bit numbers are
> concatenated to make a 32 bit number and half the array is zero.
>
>         Buffer = (c_short * byteSize)()
>         self.cam.Qframe.pBuffer = cast(pointer(Buffer), c_void_p)
>         perr = self.cam.GrabFrame()
>         image1 = np.frombuffer(Buffer, int)
>         xdim = self.cam.Qframe.width
>         ydim = self.cam.Qframe.height
>         image2 = image1.reshape(xdim, ydim)
>
> image2 looks like
>
> [[6291555 6357091 6160481 ..., 6488160 6226020 6553697]
>  [6488163 6422625 6684770 ..., 6422624 6553697 6553696]
>  [6488160 6357091 6226018 ..., 6815842 6422627 6553696]
>  ...,
>  [      0       0       0 ...,       0       0       0]
>  [      0       0       0 ...,       0       0       0]
>  [      0       0       0 ...,       0       0       0]]
>
> How do convert 16 bit data to 32 bit data?
> Thanks

I figured it out.

Buffer = (c_ubyte * byteSize)()
self.cam.Qframe.pBuffer = cast(pointer(Buffer), c_void_p)
perr = self.cam.GrabFrame()
image1 = np.frombuffer(Buffer, np.uint16)
xdim = self.cam.Qframe.width
ydim = self.cam.Qframe.height
image2 = image1.reshape(xdim, ydim)

Though Eclipse thinks
Buffer = (c_ubyte * byteSize)()

is an error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Argh!! Can't wrap my head around this Python stuff!

2017-11-26 Thread Wanderer
On Sunday, November 26, 2017 at 4:10:12 AM UTC-5, Greg Tibbet wrote:
> I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit
> of Java and trying to learn this new-fangled Python language!
> 
> I've got a small program that uses PIL to create an image, draw some
> primitives (rectanges, ellipses, etc...) and save it.  Works fine...
> no issues.
> 
> I've found in the past, the best way to "really learn" the language
> was to "dig into the guts" and understand it,.. I thought I was making
> progress, but when looking into the PIL library to see what's going on
> behind the scenes, I find the following code in ImageDraw.py
> 
> def ellipse(self, xy, fill=None, outline=None):
> """Draw an ellipse."""
> ink, fill = self._getink(outline, fill)
> if fill is not None:
> self.draw.draw_ellipse(xy, fill, 1)
> <...snipped...>
> 
> ellipse() uses the method  self.draw.draw_ellipse()   Okay, fine...
> but WHERE is draw_ellipse defined??  What magic is happening there?
> I've searched the entire PIL directory tree, and the ONLY two places
> draw_ellipse is mentioned are right there in the ellipse() function...
> WHAT am I missing??  
> 
> Thanks!
> -Stumpy (aka Greg)

I'm googlesmart when it comes to Python. I used to know C. I practically knew 
what the assembly language would look like when it compiled. There was no 
internet and searching through books can be really laborious so you almost had 
to really know it to use it. But with Python, I don't start from first 
principles. I google what I want to do, download the appropriate packages and 
read through the examples. It can be really frustrating when you get bugs, 
because you don't know what's going on deep down in the code.
-- 
https://mail.python.org/mailman/listinfo/python-list


subprocess call question

2017-12-14 Thread Wanderer
This dos batch files works on windows 7

"C:\Program Files (x86)\DOOM 3\qoom3.exe" +set fs_game_base darkmod +set 
fs_game training_mission

but this python subprocess.call doesn't

subprocess.call(['C:/Program Files (x86)/DOOM 3/qoom3.exe', '+set fs_game_base 
darkmod', '+set fs_game training_mission'])

qoom3.exe starts but it gives the warnings "unknown commands set fs_game_base 
darkmod and set fs_game training_mission"

Why?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess call question

2017-12-14 Thread Wanderer
That works. Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 7z archive reader akin to zipfile?

2018-01-06 Thread Wanderer
On Wednesday, January 3, 2018 at 1:11:31 PM UTC-5, Skip Montanaro wrote:
> The zipfile module is kind of cool because you can access elements of
> the archive without explicitly uncompressing the entire archive and
> writing the structure to disk. I've got some 7z archives I'd like to
> treat the same way (read specific elements without first extractingg
> the entire tree to disk). I see the pylzma module for compressing and
> uncompressing files, but nothing slightly higher level. Does something
> like that exist?
> 
> Thx,
> 
> Skip

I made this wrapper class for 7zip. It might be useful for you.

#python wrapper for 7zip
import os
import zlib
from subprocess import Popen, PIPE
"""
p = Popen(['program', 'arg1'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
rc = p.returncode
"""

SEVEN_ZIP_PATH = "C:/Program Files/7-Zip/7z.exe" 

class SevenZip(object):

def __new__(cls, ZipProgram=SEVEN_ZIP_PATH):
if os.path.isfile(ZipProgram):
return super(SevenZip, cls).__new__(cls)
else:
raise ValueError("7zip program not found in %s" %(ZipProgram))

def __init__(self, ZipProgram=SEVEN_ZIP_PATH):
self.ZipProgram = ZipProgram
self.archive = None
self.outputDir = None
self.fileList = []
self.archiveType = "zip"


def call(self, cmdList=None):
""" Used by the other methods to call the 7zip command line. 
Can be used directly to run 7zip if the wrapper methods don't suffice.

cmdList -- Subprocess style list of command line options with
the first item in the list being self.ZipProgram
"""
if cmdList is not None:
zip7 = Popen(cmdList, stdin=PIPE, stdout=PIPE, stderr=PIPE )
output ,err = zip7.communicate()
rc = zip7.returncode
print "output" , output
print "return code", rc
if len(err) > 0:
print "errors found", err

   
def modify(self, archive=None, fileList=None, cmd=None):
""" Modify an archive (add, delete or update)
[optional]
archive -- the zip file
fileList -- a list of file paths or a single filepath
cmd -- 'a': add, 'd': delete or 'u': update
"""
if not cmd in ['a','u','d']:
raise ValueError("Invalid command %s" %cmd)
if fileList is not None:
if type(fileList) is list:
self.fileList = fileList
else:
self.fileList = [fileList]
"""
for f in self.fileList:
if not (os.path.isfile(f) or os.path.isdir(f)):
raise ValueError("File %s not found" %f)
"""

if archive is not None:
self.archive = archive
if self.archive is not None:
if os.path.isfile(self.archive) or cmd == 'a':
cmdList = [self.ZipProgram, cmd, '-y'] 
if self.archiveType is not None:
cmdList.append("-t"+self.archiveType)
cmdList.append(self.archive)
cmdList.extend(self.fileList)
print cmdList
self.call(cmdList)
else:
raise ValueError("Archive not found in %s" %(self.archive)) 



def usage(self):
""" Returns the 7zip command line usage text. 
These options can be accessed directly with call.

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Usage: 7z  [...]  [...]
   [<@listfiles...>]


  a: Add files to archive
  b: Benchmark
  d: Delete files from archive
  e: Extract files from archive (without using directory names)
  l: List contents of archive
  t: Test integrity of archive
  u: Update files to archive
  x: eXtract files with full paths

  -ai[r[-|0]]{@listfile|!wildcard}: Include archives
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
  -bd: Disable percentage indicator
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames
  -m{Parameters}: set compression Method
  -o{Directory}: set Output directory
  -p{Password}: set Password
  -r[-|0]: Recurse subdirectories
  -scs{UTF-8 | WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive
  -si[{name}]: read data from stdin
  -slt: show technical information for l (List) command
  -so: write data to stdout
  -ssc[-]: set sensitive case mode
  -ssw: compress shared files
  -t{Type}: Set type of archive
  -u[-][p#][

Fatal Python error

2016-08-31 Thread Wanderer
Dear friendI'm very sorry to bother you in a busy schedule.
But I have a questions about Sigil's environment that really need your help.


I'm trying to use Sigil at a windows system,the follow are the relation of 
Sigil build and run environment.


OS:WIN10
Python:python-3.6.0a4-amd64
QT:qt5.5.1
ActivePerl:ActivePerl-5.24.0.2400-MSWin32-x64-300558
Ruby:rubyinstaller-2.3.1-x64
Sigil:Sigil-0.9.6-Code
VS:VS2015


The system environment I alse configured.The Sigil project also build successed.
But When I run the Sigil.exe that follow errors occured.
--
Fatal Python error: Py_Initialize: unable to load the file system codec
--


The Sigil.exe can not run, and the main sigil form also can not appearses.


Can you help me which I should do to solove this problems?


Thanks very much.
-- 
https://mail.python.org/mailman/listinfo/python-list


pySerial raw data

2016-12-11 Thread Wanderer
I have an outdoor thermometer that transmits to an indoor receiver at 433Mhz. I 
also have a 433Mhz USB serial port jig from a TI development tool. I would like 
to use the TI USB serial port to capture the temperature information. The TI 
USB port registers as a COM port that I can access with pySerial. Now the 
datasheet from the temperature probe only says that the RF frequency is 433MHz 
and that it transmits every 39 seconds. Since I don't know what protocol the 
thermometer uses or baud rate, I want to look at the rawest level of data 
collected with the USB com port and see if I can make anything out of the 
gobbledy gook coming in. Is there a way to get this kind of data from pySerial? 
I've tried scanning at different baud rates but so far I haven't captured 
anything.

Also in the advanced settings in windows device manager, there are some 
settings for Fifo buffers, and receive and transmit buffers. Can these be 
accessed in pySerial? Does pySerial override the settings for baud rate, etc in 
windows device manager or do I need to set those to match what I'm using in 
pySerial?

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pySerial raw data

2016-12-11 Thread Wanderer
On Sunday, December 11, 2016 at 12:52:04 PM UTC-5, MRAB wrote:
> On 2016-12-11 16:28, Wanderer wrote:
> > I have an outdoor thermometer that transmits to an indoor receiver at 
> > 433Mhz. I also have a 433Mhz USB serial port jig from a TI development 
> > tool. I would like to use the TI USB serial port to capture the temperature 
> > information. The TI USB port registers as a COM port that I can access with 
> > pySerial. Now the datasheet from the temperature probe only says that the 
> > RF frequency is 433MHz and that it transmits every 39 seconds. Since I 
> > don't know what protocol the thermometer uses or baud rate, I want to look 
> > at the rawest level of data collected with the USB com port and see if I 
> > can make anything out of the gobbledy gook coming in. Is there a way to get 
> > this kind of data from pySerial? I've tried scanning at different baud 
> > rates but so far I haven't captured anything.
> >
> > Also in the advanced settings in windows device manager, there are some 
> > settings for Fifo buffers, and receive and transmit buffers. Can these be 
> > accessed in pySerial? Does pySerial override the settings for baud rate, 
> > etc in windows device manager or do I need to set those to match what I'm 
> > using in pySerial?
> >
> What is the make and model of the thermometer? Is the datasheet online 
> somewhere?

http://global.oregonscientific.com/manual/THN132N.pdf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Filtering computer.lang.python

2018-04-10 Thread Wanderer
On Tuesday, April 10, 2018 at 3:28:05 AM UTC-4, Thomas Jollans wrote:
> On 2018-04-10 07:06, T Berger wrote:
> > This is the first time I've joined a google group and I don't understand 
> > the setup. Why are most of the posts in this group unrelated to python, and 
> > how do I filter this junk (sorry) out?
> > 
> 
> Welcome to python-list/comp.lang.python!
> 
> This isn't originally a Google group. Google just mirrors the old USENET
> group, which is awash with spam.
> 
> There is also a mailing list version of this group (posts are mirrored
> both ways) at https://mail.python.org/mailman/listinfo/python-list
> 
> The mailing list has proper spam filtering and some moderation. None (or
> barely any) of the regulars use Google Groups. Some people use USENET
> directly and maintain their own extensive filtering regime to make it
> readable. Probably most of us use the mailing list, because it's just so
> much nicer!
> 
> -- Thomas

Here's my python code for filtering google groups again. You need to bookmark 
pyc files to run them from the bookmarks in firefox. You also need to create 
the bannedAuthors.txt and bannedSubjects.txt files. 



# remove banned author and authors with mostly caps

# to compile to pyc
#>>>import py_compile
#>>>py_compile.compile("file.py")


import urllib2
import webbrowser
import os
from bs4 import BeautifulSoup
import argparse

class Usage(Exception):
def __init__(self, msg):
self.msg = msg


PALEMOON = 'Mozilla/5.0 (Windows NT 6.1; WOW64) KHTML/4.11 Gecko/20130308 
Firefox/33.0 (PaleMoon/25.2)'
WATERFOX = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) Gecko/20100101 
Firefox/51.1.0 Waterfox/51.1.0'
USERAGENTBASE = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) 
Gecko/20100101 '
BROWSERPATH = 'C:\\"Program Files"\\Waterfox\\waterfox.exe'
FILENAME = 'C:\\Pystuff\\pygroup.htm'
SEDFILENAME = 'C:\\Pystuff\\SED.htm'
WEBPAGE_START = "https://groups.google.com/forum/?_escaped_fragment_=forum/";
PYGROUP_WEBPAGE = "comp.lang.python%5B"
SED_WEBPAGE = "sci.electronics.design%5B"
WEBPAGE_END = "%5D"
BANNED_AUTHORS_FILE = 'C:\\Pystuff\\bannedAuthors.txt'
BANNED_SUBJECTS_FILE = 'C:\\Pystuff\\bannedSubjects.txt'

def getUserAgentVersion():
""" get the useragent version
returns agentVersion
-- user agent version in format Firefox/51.0.1 Waterfox/51.0.1
"""
bvers = os.popen(BROWSERPATH + " -v").read()
bversList = bvers.split()
agentVersion = 'Firefox/' + bversList[2] + ' ' + bversList[1] + '/' + 
bversList[2]
return agentVersion

def getwebpage(url):
""" Open a webpage 
url --  the url to the webpage
returns 
page -- the source for the webpage
"""
user_agent = USERAGENTBASE + getUserAgentVersion()
headers = { 'User-Agent' : user_agent }
req = urllib2.Request(url, None, headers)
response = urllib2.urlopen(req)
page = response.read()
return page

def getBannedAuthors():
""" Convert the banned authors text file into a list
returns
bannedAuthors -- list of banned author strings
"""
f = open(BANNED_AUTHORS_FILE, 'r')
bannedAuthors = f.read().split('\n')
f.close()
return bannedAuthors

def getBannedSubjects():
""" Convert the banned subjects text file into a list
returns
bannedAuthors -- list of banned author strings
"""
f = open(BANNED_SUBJECTS_FILE, 'r')
bannedSubjects = f.read().split('\n')
f.close()
return bannedSubjects

def removeBadAuthors(html_doc, filecode):
""" Remove posts from google group by authors that are mostly caps or on 
the Banned List
html_doc -- an html document
"""
bannedAuthors = getBannedAuthors()
bannedSubjects = getBannedSubjects()
#print bannedAuthors

soup = BeautifulSoup(html_doc)
#print soup.prettify()
post = soup.find("tr")
postcount = 0
banNoneCount = 0
banNameCount = 0
banBigCount = 0
banSubjectCount = 0
while post is not None:
postcount += 1
author = post.find("td", "author")
subject = post.find("td", "subject")
if author is None or subject is None:
print "Author is None"
oldpost = post
post = oldpost.find_next_sibling('tr')
oldpost.decompose()
postcount = postcount - 1
banNoneCount += 1
else:
aname = author.get_text()
print aname.encode("ascii", "ignore")
asubject = ((subject.get_text()).lower()).replace(" ", "")
bannedsubject = False
for badsubject in bannedSubjects:
print "BAD SUBJECT", badsubject
if badsubject in asubject and len(badsubject) > 3:
print "ASUBJECT", asubject.encode("ascii", "ignore")
bannedsubject = True
break
if bannedsubject:
print "Subject is Banned"
oldpost = post
post = oldpost.find_

Problems with wxPython _core_.pyd on windows98

2018-08-02 Thread Wanderer
I have a laptop with windows 98 I use to connect to the OBD2 port on my car. 
I'm trying to install pyobd. I have a build for Python 2.7 for Windows98 that 
works but I'm having trouble with running wxPython. I get the following error.

C:\pyobd>python pyobd.py
Traceback (most recent call last):
  File "pyobd.py", line 28, in 
 import wx
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\__init__.py", line 45, in 

  from wx_core import *
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line4, in 

  import _core_
Import Error: DLL load failed: A device attached to the system is not 
functioning.


So what is going on? 

Do these pyd files need to be compiled specifically for win98? If so how do I 
do that? Does python compile these dlls or do I need a C compiler? 

Is there an old version of wxPython that will work on windows 98?

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems with wxPython _core_.pyd on windows98

2018-08-02 Thread Wanderer
On Thursday, August 2, 2018 at 12:03:01 PM UTC-4, Wanderer wrote:
> I have a laptop with windows 98 I use to connect to the OBD2 port on my car. 
> I'm trying to install pyobd. I have a build for Python 2.7 for Windows98 that 
> works but I'm having trouble with running wxPython. I get the following error.
> 
> C:\pyobd>python pyobd.py
> Traceback (most recent call last):
>   File "pyobd.py", line 28, in 
>  import wx
>   File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\__init__.py", line 45, in 
> 
>   from wx_core import *
>   File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line4, in 
> 
>   import _core_
> Import Error: DLL load failed: A device attached to the system is not 
> functioning.
> 
> 
> So what is going on? 
> 
> Do these pyd files need to be compiled specifically for win98? If so how do I 
> do that? Does python compile these dlls or do I need a C compiler? 
> 
> Is there an old version of wxPython that will work on windows 98?
> 
> Thanks

I got it working with
Python 2.5.1
pywin32-207
pyserial 2.4
wxPython2.7

Though I'm still getting a warning
API version mismatch for module win32event. This Python has API version 1013, 
module win32event has version 1012
I don't know what it means.

pyobd.py has bug in it line 354

if "OS" in os.environ.keys() : running windows
 
"OS" is not in os.environ.keys() in windows 98, so I changed "OS" to "WINDIR" 
which is in os environ.keys in windows 98.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Editing tabular data [was: PEP8 79 char max]

2013-07-31 Thread Wanderer
On Wednesday, July 31, 2013 2:39:29 PM UTC-4, Skip Montanaro wrote:
> > I don't understand.  That just moves them to a different file --
> 
> > doesn't it?  You've still got to deal with editing a large table of
> 
> > data (for example when I want to add instructions to your assembler).
> 
> 
> 
> My guess is it would be more foolproof to edit that stuff with a spreadsheet.
> 
> 
> 
> Skip

Has anyone tried Pyspread?

http://manns.github.io/pyspread/
-- 
http://mail.python.org/mailman/listinfo/python-list


Send alt key to subprocess.PIPE stdin

2013-09-11 Thread Wanderer
How do I send the command 'Alt+D' to subprocess.PIPE?

My code is

import subprocess
rsconfig = subprocess.Popen(["C:\Program 
Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", 
],stdin=subprocess.PIPE)

rsconfig.stdin.write('Alt+D')

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send alt key to subprocess.PIPE stdin

2013-09-11 Thread Wanderer
On Wednesday, September 11, 2013 1:43:09 PM UTC-4, Gary Herron wrote:
> On 09/11/2013 07:26 AM, Wanderer wrote:
> 
> > How do I send the command 'Alt+D' to subprocess.PIPE?
> 
> >
> 
> > My code is
> 
> >
> 
> > import subprocess
> 
> > rsconfig = subprocess.Popen(["C:\Program 
> > Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", 
> > ],stdin=subprocess.PIPE)
> 
> >
> 
> > rsconfig.stdin.write('Alt+D')
> 
> >
> 
> > Thanks
> 
> 
> 
> That question doesn't really make sense.  A pipe provides a method to 
> 
> transfer a stream of bytes.  You could indeed send that byte across the 
> 
> pipe, but it's just a byte, written by one process and read by another 
> 
> process.  The receiving process can examine the byte stream, and do 
> 
> whatever it wants in response.
> 
> 
> 
> By calling it a _command_, you seem to expect some particular behavior 
> 
> out of the receiving process.  Please tell us *what* that might be, and 
> 
> we'll see what we can do to help out.
> 
> 
> 
> Gary Herron
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Dr. Gary Herron
> 
> Department of Computer Science
> 
> DigiPen Institute of Technology
> 
> (425) 895-4418

I found Sendkeys works.

import subprocess
import time
import SendKeys

rsconfig = subprocess.Popen(["C:\Program 
Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ])
time.sleep(2)
SendKeys.SendKeys('%D\n', with_newlines=True)

Basically there is a dialog with a Done button and 'Alt D' selects the Done 
button. The subprocess program runs some interface code which sets up an ini 
file that the rest of the program needs. But then I run into another problem 
with Windows permissions. The program needs to edit this ini file located in 
the C:\Windows directory. Windows won't let you without administrator 
permissions. So then I run into login issues, etc. I kind of gave up and this 
program has to be run outside my main program. It's annoying since it's just 
this stupid little text ini file, but I can't convince Windows it doesn't 
matter if gets edited because it's in a system directory.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send alt key to subprocess.PIPE stdin

2013-09-12 Thread Wanderer
On Wednesday, September 11, 2013 4:23:57 PM UTC-4, Dave Angel wrote:
> On 11/9/2013 10:26, Wanderer wrote:
> 
> 
> 
> > How do I send the command 'Alt+D' to subprocess.PIPE?
> 
> 
> 
> That's not a command, it's a keystroke combination.  And without knowing
> 
> what RSConfig.exe is looking to get its keystrokes, it might not even be
> 
> possible to feed it any keystrokes via the pipe.
> 
> 
> 
> if the program does indeed use stdin, there's no portable encoding for
> 
> Alt-D.  But if your program only runs on one particular platform, you
> 
> might be able to find docs for that platform that explain it.
> 
> 
> 
> >
> 
> > My code is
> 
> >
> 
> > import subprocess
> 
> > rsconfig = subprocess.Popen(["C:\Program 
> > Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", 
> > ],stdin=subprocess.PIPE)
> 
> 
> 
> That string will only work by accident.  You need to make it a raw
> 
> string, or use forward slashes, or double them.  As it happens, with
> 
> this PARTICULAR set of directories, you won't get into trouble with
> 
> Python 2.7.3
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> DaveA

Thanks, I didn't know that. I thought there would be some \n \t kind of 
combination or a unicode string for all the key combinations on my keyboard.
-- 
https://mail.python.org/mailman/listinfo/python-list


numpy masked_where

2013-10-22 Thread Wanderer
Why does the numpy masked_where create a special case for all False?

import numpy
x = numpy.array([[9,9,9,9,9,9],[9,9,9,9,9,9],[9,9,9,9,9,9],[9,9,9,9,9,9]])
y = numpy.ma.masked_where(x<3,x)
y.mask
Out[1]: False
z= numpy.arange(20)
z.reshape(4,5)
Out[1]: 
array([[ 0,  1,  2,  3,  4],
   [ 5,  6,  7,  8,  9],
   [10, 11, 12, 13, 14],
   [15, 16, 17, 18, 19]])
y = numpy.ma.masked_where(z<3,z)
y.mask
Out[1]: 
array([ True,  True,  True, False, False, False, False, False, False,
   False, False, False, False, False, False, False, False, False,
   False, False], dtype=bool)

Is there a good way to work around this and get an all False array?

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


PyDev Code Analysis

2014-09-02 Thread Wanderer

I'm trying to set up Eclipse with PyDev and I can't get the code analysis to 
work the way I want.

Whenever I type 'def' it generates an error before I finish the line. I don't 
want to see errors until I finish typing. It's not an error I'm just not done 
yet. So I try to turn this off by going to 
Window>Preferences>PyDev>Editor>CodeAnalysis and setting the option When do we 
analyze? to Only on save. This doesn't stop these errors from showing up while 
I'm typing. What it does is stop checking for warnings like 'unused variable' 
even on save. If I set the option to 'On any successful parse' then it will 
check for these warning only on save.

To summarize
Setting 'Only on save', turns off warnings but keeps giving real time errors.

Setting 'On any successful parse', checks for warnings only on save and keeps 
giving real time errors.

I'm using 
Eclipse IDE for C/C++ Developers 4.4.0.21040612
Pydev for Eclipse 3.7.0.201408261926


What I am I doing wrong?

Thanks

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyDev Code Analysis

2014-09-02 Thread Wanderer
On Tuesday, September 2, 2014 8:29:32 PM UTC-4, Fabio Zadrozny wrote:
> On Tue, Sep 2, 2014 at 2:27 PM, Wanderer  wrote:
> 
> 
> 
> 
> I'm trying to set up Eclipse with PyDev and I can't get the code analysis to 
> work the way I want.
> 
> 
> 
> Whenever I type 'def' it generates an error before I finish the line. I don't 
> want to see errors until I finish typing. It's not an error I'm just not done 
> yet. So I try to turn this off by going to 
> Window>Preferences>PyDev>Editor>CodeAnalysis and setting the option When do 
> we analyze? to Only on save. This doesn't stop these errors from showing up 
> while I'm typing. What it does is stop checking for warnings like 'unused 
> variable' even on save. If I set the option to 'On any successful parse' then 
> it will check for these warning only on save.
> 
> 
> 
> 
> 
> To summarize
> 
> Setting 'Only on save', turns off warnings but keeps giving real time errors.
> 
> 
> 
> Setting 'On any successful parse', checks for warnings only on save and keeps 
> giving real time errors.
> 
> 
> 
> I'm using
> 
> Eclipse IDE for C/C++ Developers 4.4.0.21040612
> 
> Pydev for Eclipse 3.7.0.201408261926
> 
> 
> 
> 
> 
> What I am I doing wrong?
> 
> 
> 
> Thanks
> 
> 
> Well, there are 2 different things there:
> 
> 
> Code analysis and syntax analysis.
> 
> 
> Syntax analysis is always done on the fly (and you can't really turn it off 
> -- the places which require an AST will usually use the AST which is computed 
> there and when it's computed and there's a syntax error, that error will be 
> shown). It should usually be computed when a new line is entered, on a save 
> or after you entered some text and the timeout specified at preferences > 
> pydev > builders is elapsed.
> 
> 
> 
> 
> As for the code analysis (which will check errors and warnings such as unused 
> imports / unresolved imports / undefined variables, etc.), it has the options 
> you saw (which are affected by the only on save/on any successful parse).
> 
> 
> 
> 
> Cheers,
> 
> 
> Fabio 

Changing the time in builders is what I needed. Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Installing Python 2.6.7 on Windows

2011-09-27 Thread Wanderer
How do I install Python 2.6.7 on Windows? The Python 2.6.6 page says

"Python 2.6.6 has been replaced by a newer security-fix only source
release of Python. Please download Python 2.6.7 instead."

But there is no windows installer on the 2.6.7 page. Do I install
2.6.6 first and then update to 2.6.7?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python 2.6.7 on Windows

2011-09-27 Thread Wanderer
On Sep 27, 5:19 pm, becky_lewis  wrote:
> On Sep 27, 9:54 pm, Wanderer  wrote:
>
> > How do I install Python 2.6.7 on Windows? The Python 2.6.6 page says
>
> > "Python 2.6.6 has been replaced by a newer security-fix only source
> > release of Python. Please download Python 2.6.7 instead."
>
> > But there is no windows installer on the 2.6.7 page. Do I install
> > 2.6.6 first and then update to 2.6.7?
>
> > Thanks
>
> Hi,
>
> is there any reason that you specifically need the 2.6 branch or would
> it be possible to update to 2.7?
>
> As someone else already pointed out, there's the ActivePython route if
> you really need 2.6.7.

I need to stay in sink with the rest of the company which is still
using 2.6 flavors. There was some investigation into going to Python 3
but not enough of the libraries we use were available. I'll install
2.6.6. I don't think the security stuff really effects me. I think it
is strange to release a security update but not really expect people
to use it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IPython 0.12 is out!

2011-12-19 Thread Wanderer
On Dec 19, 4:49 am, Fernando Perez  wrote:
> Hi all,
>
> on behalf of the IPython development team, I'm thrilled to announce, after
> an intense 4 1/2 months of work, the official release of IPython 0.12.
>
> This is a very important release for IPython, for several reasons. First
> and foremost, we have a major new feature, our interactive web-based
> notebook, that has been in our sights for a very long time.  We tried to
> build one years ago (with WX) as a Google SoC project in 2005, had other
> prototypes later on, but things never quite worked.  Finally the
> refactoring effort started two years ago, the communications architecture
> we built in 2010, and the advances of modern browsers, gave us all the
> necessary pieces.
>
> With this foundation in place, while part of the team worked on the 0.11
> release, Brian Granger had already started quietly building the web
> notebook, which we demoed in early-alpha mode at the SciPy 2011 conference
> (http://www.archive.org/details/Wednesday-203-6-
> IpythonANewArchitectureForInteractiveAndParallel).  By the EuroScipy
> conference in August we had merged Brian's amazing effort into our master
> branch, and after that multiple people (old and new) jumped in to make all
> kinds of improvements, leaving us today with something that is an
> excellent foundation.  It's still the first release of the notebook, and
> as such we know it has a number of rough edges, but several of us have
> been using it as a daily research tool for the last few months.  Do not
> hesitate to file issues for any problems you encounter with it, and we
> even have an 'open issue' for general discussion of ideas and features for
> the notebook at:https://github.com/ipython/ipython/issues/977.
>
> Furthermore, it is clear that our big refactoring work, combined with the
> amazing facilities at Github, are paying off.  The 0.11 series was a major
> amount of work, with 511 issues closed over almost two years. But that
> pales in comparison to this cycle: in only 4 1/2 months we closed 515
> issues, with 50% being Pull Requests. And very importantly, our list of
> contributors includes many new faces (see the credits section in our
> release notes for full details), which is the best thing that can happen
> to an open source project.
>
> We hope you will find the new features (the notebook isn't the only one!
> see below) compelling, and that many more will not only use IPython but
> will join the project; there's plenty to do and now there are tasks for
> many different skill sets (web, javascript, gui work, low-level
> networking, parallel machinery, console apps, etc).
>
> *Downloads*
>
> Download links and instructions are at:http://ipython.org/download.html
> And IPython is also on PyPI:http://pypi.python.org/pypi/ipython
>
> Those contain a built version of the HTML docs; if you want pure source
> downloads with no docs, those are available on github:
>
> Tarball:https://github.com/ipython/ipython/tarball/rel-0.12
> Zipball:https://github.com/ipython/ipython/zipball/rel-0.12
>
> * Features *
> Here is a quick listing of the major new features:
>
> - An interactive browser-based Notebook with rich media support
> - Two-process terminal console
> - Tabbed QtConsole
> - Full Python 3 compatibility
> - Standalone Kernel
> - PyPy support
>
> And many more...
>
> We closed over 500 tickets, merged over 200 pull requests, and more than
> 45 people contributed commits for the final release.
>
> Please see our release notes for the full details on everything about this
> release:http://ipython.org/ipython-doc/stable/whatsnew/version0.12.html
>
> * IPython tutorial at PyCon 2012 *
>
> Those of you attending (or planning on it) PyCon 2012 in Santa Clara, CA,
> may be interested in attending a hands-on tutorial we will be presenting
> on the many faces of IPython.  Seehttps://us.pycon.org/2012/schedule/
> presentation/121/ for full details.
>
> * Errata *
> This was caught by Matthias Bussionnier's (one of our great new
> contributors) sharp eyes while I was writing these release notes: In the
> example notebook called display_protocol, the first cell starts with:
>
> from IPython.lib.pylabtools import print_figure
>
> which should instead be:
>
> from IPython.core.pylabtools import print_figure
>
> This has already been fixed on master, but since the final 0.12 files have
> been uploaded to github and PyPI, we'll let them be.
>
> As usual, if you find any other problem, please file a ticket --or even
> better, a pull request fixing it-- on our github issues site (https://
> github.com/ipython/ipython/issues/).
>
> Many thanks to all who contributed!
>
> Fernando, on behalf of the IPython development team.
>
> http://ipython.org

Doesn't work for me. I installed it over my IPython 0.11 which did
work for me. I get the following complaint.

Traceback (most recent call last):
 File "C:\Python27\scripts\ipython.py", line 26, in (module)
  import Ipython.Shell
 File "C:\Python27\lib\site-packages\I

Re: IPython 0.12 is out!

2011-12-19 Thread Wanderer
On Dec 19, 12:12 pm, Wanderer  wrote:
> On Dec 19, 4:49 am, Fernando Perez  wrote:
>
>
>
>
>
>
>
>
>
> > Hi all,
>
> > on behalf of the IPython development team, I'm thrilled to announce, after
> > an intense 4 1/2 months of work, the official release of IPython 0.12.
>
> > This is a very important release for IPython, for several reasons. First
> > and foremost, we have a major new feature, our interactive web-based
> > notebook, that has been in our sights for a very long time.  We tried to
> > build one years ago (with WX) as a Google SoC project in 2005, had other
> > prototypes later on, but things never quite worked.  Finally the
> > refactoring effort started two years ago, the communications architecture
> > we built in 2010, and the advances of modern browsers, gave us all the
> > necessary pieces.
>
> > With this foundation in place, while part of the team worked on the 0.11
> > release, Brian Granger had already started quietly building the web
> > notebook, which we demoed in early-alpha mode at the SciPy 2011 conference
> > (http://www.archive.org/details/Wednesday-203-6-
> > IpythonANewArchitectureForInteractiveAndParallel).  By the EuroScipy
> > conference in August we had merged Brian's amazing effort into our master
> > branch, and after that multiple people (old and new) jumped in to make all
> > kinds of improvements, leaving us today with something that is an
> > excellent foundation.  It's still the first release of the notebook, and
> > as such we know it has a number of rough edges, but several of us have
> > been using it as a daily research tool for the last few months.  Do not
> > hesitate to file issues for any problems you encounter with it, and we
> > even have an 'open issue' for general discussion of ideas and features for
> > the notebook at:https://github.com/ipython/ipython/issues/977.
>
> > Furthermore, it is clear that our big refactoring work, combined with the
> > amazing facilities at Github, are paying off.  The 0.11 series was a major
> > amount of work, with 511 issues closed over almost two years. But that
> > pales in comparison to this cycle: in only 4 1/2 months we closed 515
> > issues, with 50% being Pull Requests. And very importantly, our list of
> > contributors includes many new faces (see the credits section in our
> > release notes for full details), which is the best thing that can happen
> > to an open source project.
>
> > We hope you will find the new features (the notebook isn't the only one!
> > see below) compelling, and that many more will not only use IPython but
> > will join the project; there's plenty to do and now there are tasks for
> > many different skill sets (web, javascript, gui work, low-level
> > networking, parallel machinery, console apps, etc).
>
> > *Downloads*
>
> > Download links and instructions are at:http://ipython.org/download.html
> > And IPython is also on PyPI:http://pypi.python.org/pypi/ipython
>
> > Those contain a built version of the HTML docs; if you want pure source
> > downloads with no docs, those are available on github:
>
> > Tarball:https://github.com/ipython/ipython/tarball/rel-0.12
> > Zipball:https://github.com/ipython/ipython/zipball/rel-0.12
>
> > * Features *
> > Here is a quick listing of the major new features:
>
> > - An interactive browser-based Notebook with rich media support
> > - Two-process terminal console
> > - Tabbed QtConsole
> > - Full Python 3 compatibility
> > - Standalone Kernel
> > - PyPy support
>
> > And many more...
>
> > We closed over 500 tickets, merged over 200 pull requests, and more than
> > 45 people contributed commits for the final release.
>
> > Please see our release notes for the full details on everything about this
> > release:http://ipython.org/ipython-doc/stable/whatsnew/version0.12.html
>
> > * IPython tutorial at PyCon 2012 *
>
> > Those of you attending (or planning on it) PyCon 2012 in Santa Clara, CA,
> > may be interested in attending a hands-on tutorial we will be presenting
> > on the many faces of IPython.  Seehttps://us.pycon.org/2012/schedule/
> > presentation/121/ for full details.
>
> > * Errata *
> > This was caught by Matthias Bussionnier's (one of our great new
> > contributors) sharp eyes while I was writing these release notes: In the
> > example notebook called display_protocol, the first cell starts with:
>
> > from IPython.lib.pylabtools import print_figure
>
> > which should instead be:
>
> > from IPytho

Re: IPython 0.12 is out!

2011-12-20 Thread Wanderer
On Dec 19, 11:00 pm, alex23  wrote:
> On Dec 20, 4:07 am, Wanderer  wrote:
>
> > The windows installer didn't work but installing from the tar file
> > did. But installing from the tar file doesn't install Ipython in the
> > site-packages directory. It installs it wherever you untar the tar
> > file. I don't remember ever having to deal with this before. Most
> > things just install in the site-packages directory without me having
> > to do anything special.
>
> You read the installation instructions and did a 'python setup.py
> install' as it states, yes?
>
> Installed that way for Python 2.7.2 under Win64 with no issues
> whatsoever.

No I scrolled down to the Windows directions and used
setuptools,'python setupegg.py install' It works but it is installed
in 'C:Python27\Lib\site-packages\ipython-0.12.tar\dist\ipython-0.12'
which is weird. I used 7zip to unzip and untar it maybe that is the
issue.

I'm using winXP. I should be getting my system upgraded to Win7 any
day now, so I'm going to leave it where it is for now.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


PyDev, pep8.py conflict on spaces around negative numbers

2013-02-11 Thread Wanderer
If I check the 'Use space before and after operators? (+, -, /, *, //, **, 
etc.)' in the Eclipse>PyDev>Editor>Code Style> Code Formatter, PyDev will 
insert a space before a negative number in a keyword parameter declaration. 
Pep8.py will then post a warning 'E251 no spaces around keyword / parameter 
equals'.

For example:
foo(bar= -25)

So which is right? Should there be a space before a negative number?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyDev, pep8.py conflict on spaces around negative numbers

2013-02-11 Thread Wanderer
On Monday, February 11, 2013 1:09:38 PM UTC-5, MRAB wrote:
> On 2013-02-11 16:39, Wanderer wrote:
> 
> > If I check the 'Use space before and after operators? (+, -, /, *,
> 
> > //, **, etc.)' in the Eclipse>PyDev>Editor>Code Style> Code
> 
> > Formatter, PyDev will insert a space before a negative number in a
> 
> > keyword parameter declaration. Pep8.py will then post a warning 'E251
> 
> > no spaces around keyword / parameter equals'.
> 
> >
> 
> > For example:
> 
> > foo(bar= -25)
> 
> >
> 
> > So which is right? Should there be a space before a negative number?
> 
> >
> 
> Pep8.py is right.
> 
> 
> 
> This is preferred:
> 
> 
> 
>  foo(bar=-25)
> 
> 
> 
> as is this:
> 
> 
> 
>  bar = -25

Then, I guess I'll uncheck the 'Use space before and after operators' in PyDev.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Suppress PyDev warning for wx event variable

2013-03-20 Thread Wanderer
I have two versions of Eclipse on two different machines; Indigo and Juno. In 
Indigo, the wxPython event variable in the definitions is not flagged as an 
unused variable even though I don't use it in the method. In Juno I keep 
getting the warnings. The event variable is just there to bind the method to 
the button event and I would like to suppress the warnings, but I can't figure 
out what I have set up differently between the two machines. I looked through 
the preferences but nothing jumps out at me. How do I suppress these warnings?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lists and Decimal numbers

2013-03-20 Thread Wanderer
On Wednesday, March 20, 2013 11:27:30 AM UTC-4, Ana Dionísio wrote:
> So, I have this script that puts in a list every minute in 24 hours
> 
> 
> 
> hour=[]
> 
> i=0
> 
> t=-(1.0/60.0)
> 
> while i<24*60:
> 
> i = i+1
> 
> t = t+(1.0/60.0)
> 
> hour.append([t])
> 
> 
> 
> When it is doing the cicle it can have all the decimal numbers, but I need to 
> print the result with only 4 decimal numbers
> 
> 
> 
> How can I define the number of decimal numbers I want to print in this case? 
> For example with 4 decimal numbers, it would print:
> 
> 
> 
> 0.
> 
> 0.0167
> 
> 0.0333
> 
> ...
> 
> 
> 
> Can you help?

You can use round.

for t in hour:
print round(t,4)
-- 
http://mail.python.org/mailman/listinfo/python-list


LiClipse

2013-03-22 Thread Wanderer
I just updated PyDev and I got this message that they are looking for funding 
for a new flavor of Eclipse called LiClipse. The description of what LiClipse 
will be is kind of sketchy. No offense intended, but why? There is already a 
bunch of downloads at Eclipse and there is also Easy Eclipse. The only reason 
for a redesign of Eclipse, I would want would be change it from being Java 
based. Oracle is losing money and I wonder what their next business model will 
be for Java. Anyway, does anyone know what this LiClipse is all about?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LiClipse

2013-03-23 Thread Wanderer
On Saturday, March 23, 2013 7:11:10 AM UTC-4, Fabio Zadrozny wrote:
> On Sat, Mar 23, 2013 at 12:38 AM, rusi  wrote:
> 
> 
> 
> 
> On Mar 23, 7:58 am, Fabio Zadrozny  wrote:
> 
> 
> 
> > Hello there,
> 
> >
> 
> > As I've proposed it, let me try to explain it a bit better (if you have
> 
> > doubts, I should probably rephrase the proposal).
> 
> >
> 
> > There are 2 main targets there: keeping PyDev properly supported (which
> 
> > hopefully doesn't need more explanation) and creating LiClipse.
> 
> >
> 
> > The idea for LiClipse is definitely not making a fork, but having an easier
> 
> > way to add a basic editor inside Eclipse (while developing PyDev, I do get
> 
> > many requests for adding support for editors related to Python, such as
> 
> > Django templates, Mako, Restructured text, Cython, etc), so, this will
> 
> > provide me with a basis to do that (and with the basis in place, the idea
> 
> > is having the possibility of creating an editor without knowledge of
> 
> > Eclipse and in a very fast way -- current technologies for that such as
> 
> > DLTK or XText aim much higher and are not trivial. I really want to have a
> 
> > way to have a basic editor inside Eclipse just specifying the language very
> 
> > 'loosely' -- say, something that'd take you 15-30 minutes and almost no
> 
> > special knowledge of Eclipse internals -- and which would need more
> 
> > knowledge of Eclipse internals only for more advanced stuff).
> 
> >
> 
> > As for the dark theme, it's something that annoys me a lot (so, I was
> 
> > hoping it was also something interesting for other people -- right now,
> 
> > it's not possible to have a professional dark theme in Eclipse, there are
> 
> > many loose ends -- so, for those that would like to work with a dark theme
> 
> > -- as myself -- it may be very annoying -- although yes, it may not be
> 
> > applicable if you're happy with the current non-dark UI).
> 
> >
> 
> > As for distributions, yes, I plan to do an Eclipse distribution with
> 
> > LiClipse / PyDev bundled -- Easy Eclipse is definitely not a solution as it
> 
> > is NOT supported (it has an ancient version of PyDev which only serves to
> 
> > confuse users and Eclipse.org does not have a Python version with PyDev).
> 
> > I'd hardly call that a fork thought (and it should be possible to install
> 
> > it as a separate plugin anyways, so, you can use the Eclipse you got from
> 
> > anywhere and just use the update site to get those plugins).
> 
> >
> 
> > Cheers,
> 
> >
> 
> > Fabio
> 
> 
> 
> I am interested in the new eclipse plugin capabilities.
> 
> Where does liclipse stand with respect to this?
> 
> 
> 
> The idea is providing a way to add a language just by saying things like 
> keywords, elements (such as function or class -- if your language has that), 
> indenting words and it'll provide you an editor that has all the common 
> functions you'd expect, such as syntax highlighting, outline, indenting, 
> template completion, etc. So, in LiClipse, you shouldn't need to create a 
> plugin at this level, just one configuration file (which you should be able 
> to fill in 15-30 minutes).
> 
> 
> 
> 
> After that, if you want more things (such as code analysis or a semantic 
> aware code completion), then you'd have to go the route of actually creating 
> an Eclipse plugin.
>  
> 
> 
> ie Eclipse-4 claims to have made plugin development (for new custom
> 
> languages) easier.
> 
> What is the relation of liclipse to eclipse 3<->4 plugin architecture?
> 
> 
> 
> Well, it may have become a bit easier (with dltk and xtext), but it's still 
> far from trivial (you still have to know at least java, how plugins work, 
> eclipse internals, creating a grammar, etc.).
> 
> 
> 
> 
> The editors structure for LiClipse should work in both Eclipse 3 or 4, 
> although the theming enhancements will require Eclipse 4 (as it'll need some 
> features only available there).
> 
> 
> 
> 
> Cheers,
> 
> 
> Fabio

Thanks for the response. Now I understand better what you're trying to do. 
Eclipse can be something of a pain to get basic support to use new languages. I 
never was able to get it to work with Vpascal. I would also like the bundle, 
since I can't get the version in the lab to work like the version on my desk. 
I've never been one for dark themes. My pet peeve is the battle over negative 
numbers between PyDev and pep8.py. PyDev put the space in and pep8.py gives me 
a warning.

Anyway, PyDev deserves my support and thank you for all your hard work.
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I Block Events in wxPython

2009-12-09 Thread Wanderer
I have a wxPython program which does some calculations and displays
the results. During these calculations if I click the mouse inside the
dialog the program locks up. If I leave the dialog alone the process
completes fine. I have tried running the function from a separate
dialog with Show Modal and I have tried using SetEvtHandlerEnabled all
to no avail. The program is long and occupies several files so I won't
show the whole thing but here is the calculation part. How do I block
events?

def DoEfficiency(self):

  from time import sleep

  self.timer.Stop()



  TotalPower = 0
  Counter = 0
  for ang in range(1,89):
self.tc_angle.SetValue(ang)
height = int(self.eclwidth * 10)
for hgt in range(0,height):
  self.tc_height.SetValue(float(hgt)/10.0)
  self.UpdateValues()
  self.Redraw()
  self.DrawRays()
  sPower = self.tc_power.GetValue()
  Power = sPower.split('%')
  TotalPower +=float(Power[0])
  Counter +=1
  sleep(0.1)

  efficiency = TotalPower/Counter
  self.tc_eff.SetLabel(str(round(efficiency,1)))
  self.timer.Start(10)


# end DoEfficiency

def OnEfficiency(self, event):

  self.tc_aangle.SetEvtHandlerEnabled(False)
  self.tc_angle.SetEvtHandlerEnabled(False)
  self.tc_calc_len.SetEvtHandlerEnabled(False)
  self.tc_cpclength.SetEvtHandlerEnabled(False)
  self.tc_cpcwidth.SetEvtHandlerEnabled(False)
  self.tc_det.SetEvtHandlerEnabled(False)
  self.tc_ecl.SetEvtHandlerEnabled(False)
  self.tc_eff.SetEvtHandlerEnabled(False)
  self.tc_gap1.SetEvtHandlerEnabled(False)
  self.tc_gap2.SetEvtHandlerEnabled(False)
  self.tc_height.SetEvtHandlerEnabled(False)
  self.tc_parab.SetEvtHandlerEnabled(False)
  self.tc_power.SetEvtHandlerEnabled(False)
  self.tc_refresh.SetEvtHandlerEnabled(False)
  self.tc_tlength.SetEvtHandlerEnabled(False)
  self.tc_twidth.SetEvtHandlerEnabled(False)
  self.tc_use_tir.SetEvtHandlerEnabled(False)
  self.SetEvtHandlerEnabled(False)

  dlf = CalcEfficiency(self,"CalcEfficiency",wx.DefaultPosition,
(90,60))

  self.tc_aangle.SetEvtHandlerEnabled(True)
  self.tc_angle.SetEvtHandlerEnabled(True)
  self.tc_calc_len.SetEvtHandlerEnabled(True)
  self.tc_cpclength.SetEvtHandlerEnabled(True)
  self.tc_cpcwidth.SetEvtHandlerEnabled(True)
  self.tc_det.SetEvtHandlerEnabled(True)
  self.tc_ecl.SetEvtHandlerEnabled(True)
  self.tc_eff.SetEvtHandlerEnabled(True)
  self.tc_gap1.SetEvtHandlerEnabled(True)
  self.tc_gap2.SetEvtHandlerEnabled(True)
  self.tc_height.SetEvtHandlerEnabled(True)
  self.tc_parab.SetEvtHandlerEnabled(True)
  self.tc_power.SetEvtHandlerEnabled(True)
  self.tc_refresh.SetEvtHandlerEnabled(True)
  self.tc_tlength.SetEvtHandlerEnabled(True)
  self.tc_twidth.SetEvtHandlerEnabled(True)
  self.tc_use_tir.SetEvtHandlerEnabled(True)
  self.SetEvtHandlerEnabled(True)

# end MyInterface


class CalcEfficiency(wx.Dialog):
"""
"""
def __init__(self, parent, title, pos, size):

self.parent = parent


wx.Dialog.__init__(self,parent, -1, title, pos, size)

self.runButton = wx.ToggleButton(self, ID_TOGGLE, "Start",
wx.DefaultPosition, (70,30))
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, id =
ID_TOGGLE)

self.ShowModal()

self.Destroy()

# end init

def OnToggle(self, event):

  if self.runButton.GetValue():
self.runButton.SetLabel("WAIT")
self.SetEvtHandlerEnabled(False)
self.parent.DoEfficiency()
self.SetEvtHandlerEnabled(True)
  else:
self.Close()


# end OnQuit

# end CalcEfficiency


if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()

# end main
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I Block Events in wxPython

2009-12-09 Thread Wanderer
On Dec 9, 11:48 am, r0g  wrote:
> Wanderer wrote:
> > I have a wxPython program which does some calculations and displays
> > the results. During these calculations if I click the mouse inside the
> > dialog the program locks up. If I leave the dialog alone the process
> > completes fine.
>
> If anything in your GUI app takes a non trivial length of time to
> execute you need to run it in either a thread or a separate process.
>
> http://linuxgazette.net/107/pai.html
>
> Roger

Thanks Everyone. I'll have to look over these wikis about threading. I
decided to go another route and user a timer to perform the loops.
That way the events can be processed normally.

def DoEfficiency(self, event):


  ang = self.tc_angle.GetValue()
  hgt = self.tc_height.GetValue()
  hgt += 0.1
  if hgt > self.eclwidth:
hgt = 0
ang +=1
self.tc_angle.SetValue(ang)
  self.height = hgt
  self.tc_height.SetValue(hgt)
  self.tc_height.SetValue(hgt)
  self.UpdateValues()
  self.Redraw()
  self.DrawRays()
  sPower = self.tc_power.GetValue()
  Power = sPower.split('%')
  self.TotalPower +=float(Power[0])
  self.Counter +=1
  efficiency = self.TotalPower/self.Counter
  self.tc_eff.SetLabel(str(round(efficiency,1)))
  if ang > 89:
self.efftimer.Stop()
self.timer.Start(10)



# end DoEfficiency

def OnEfficiency(self, event):

self.TotalPower = 0
self.Counter = 0
self.tc_angle.SetValue(1)
self.tc_height.SetValue(0)
self.timer.Stop()
self.efftimer.Start(100)


# end MyInterface

Found another strange bug (Strange to me, anyway). int(0.8 * 10.0) =
7. Had to change the code to int(0.8 * 10.0 + 0.0001).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: importing with .m instead of .py

2009-09-25 Thread Wanderer
On Sep 25, 2:05 pm, Andrew Svetlov  wrote:
> On Sep 25, 1:16 pm, Wanderer  wrote:
>
> > execfile(x) does what I'm looking for.
>
> Perhaps you are looking for Python import 
> hook:http://www.python.org/dev/peps/pep-0302/
>
> In you import hook you can do everything (and locate/import file with
> any extension :)

I'm just porting a bunch of octave functions into pylab that use data
I collected in files like I show above. The execfile() method lets me
verify I get the same results in Octave and Python. It is in the NumPy
for Matlab users page at Mathesaurus 
http://mathesaurus.sourceforge.net/matlab-numpy.html,
but they make it look like it needs a .py extension. Like Ishwor said
'Trivial', now that I know how :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Decimal values in wx.slider

2009-10-20 Thread Wanderer
Is there way to get decimal values displayed in wx.slider? I would
like to use a slider to set values like 3.11.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Background Zones in Pylab Plot

2010-02-03 Thread Wanderer
I would like to add background zones in pylab plots. Colored sections
of the background that the curves pass through. Is this possible? My
google searches don't turn up anything but maybe my search terms
aren't the right ones.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Background Zones in Pylab Plot

2010-02-04 Thread Wanderer
On Feb 3, 10:50 pm, CM  wrote:
> On Feb 3, 10:49 am, Wanderer  wrote:
>
> > I would like to add background zones in pylab plots. Colored sections
> > of the background that the curves pass through. Is this possible? My
> > google searches don't turn up anything but maybe my search terms
> > aren't the right ones.
>
> > Thanks
>
> If you look at the matplotlib gallery, I think there may be some
> images
> that show something like what you want, and then you can look at the
> code.  It's here:
>
> http://matplotlib.sourceforge.net/gallery.html
>
> HTH,
> Che

That helped. There should be something in there I can use.
Thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


method names nounVerb or verbNoun

2010-02-05 Thread Wanderer
Which is the more accepted way to compose method names nounVerb or
verbNoun?

For example voltageGet or getVoltage? getVoltage sounds more normal,
but voltageGet is more like voltage.Get. I seem to mix them and I
should probably pick one way and stick with it.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: method names nounVerb or verbNoun

2010-02-05 Thread Wanderer
On Feb 5, 3:26 pm, Chris Rebert  wrote:
> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer  wrote:
> > Which is the more accepted way to compose method names nounVerb or
> > verbNoun?
>
> > For example voltageGet or getVoltage? getVoltage sounds more normal,
> > but voltageGet is more like voltage.Get. I seem to mix them and I
> > should probably pick one way and stick with it.
>
> Use properties[1] and just call it `voltage`. Python is not Java [2];
> explicit getters/setters are unpythonic.
>
> [1]http://docs.python.org/library/functions.html#property
> [2]http://dirtsimple.org/2004/12/python-is-not-java.html
>
> Cheers,
> Chris
> --http://blog.rebertia.com

Maybe I'm not using Get right either. I'm wrapping functions.

def AbbeGet(self, Lens):
"""
Get the Abbe Number V for the material
where
V = (Nd - 1)/(Nf - Nc)
where the Index of Refractions are
Nd at the Fraunhofer D line 0.5892um
Nf at the Fraunhofer F line 0.4861um
Nc at the Fraunhofer C line 0.6563um
"""

Nd = Lens.Mat.NtGet(0.5892)
Nf = Lens.Mat.NtGet(0.4861)
Nc = Lens.Mat.NtGet(0.6563)

if (Nf - Nc) != 0:
V = (Nd - 1)/(Nf - Nc)
else:
V = 1e6

return V

# end AbbeGet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: method names nounVerb or verbNoun

2010-02-05 Thread Wanderer
On Feb 5, 4:53 pm, Chris Rebert  wrote:
> On Fri, Feb 5, 2010 at 1:49 PM, Wanderer  wrote:
> > On Feb 5, 3:26 pm, Chris Rebert  wrote:
> >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer  wrote:
> >> > Which is the more accepted way to compose method names nounVerb or
> >> > verbNoun?
>
> >> > For example voltageGet or getVoltage? getVoltage sounds more normal,
> >> > but voltageGet is more like voltage.Get. I seem to mix them and I
> >> > should probably pick one way and stick with it.
>
> >> Use properties[1] and just call it `voltage`. Python is not Java [2];
> >> explicit getters/setters are unpythonic.
>
> >> [1]http://docs.python.org/library/functions.html#property
>
> > Maybe I'm not using Get right either. I'm wrapping functions.
>
> >    def AbbeGet(self, Lens):
> >        """
> >        Get the Abbe Number V for the material
> >        where
> >        V = (Nd - 1)/(Nf - Nc)
> >        where the Index of Refractions are
> >        Nd at the Fraunhofer D line 0.5892um
> >        Nf at the Fraunhofer F line 0.4861um
> >        Nc at the Fraunhofer C line 0.6563um
> >        """
>
> >        Nd = Lens.Mat.NtGet(0.5892)
> >        Nf = Lens.Mat.NtGet(0.4861)
> >        Nc = Lens.Mat.NtGet(0.6563)
>
> >        if (Nf - Nc) != 0:
> >            V = (Nd - 1)/(Nf - Nc)
> >        else:
> >            V = 1e6
>
> >        return V
>
> This isn't even really a method; you don't refer to "self" in the body
> at all. Why isn't it just a function?
>
> Cheers,
> Chris
> --http://blog.rebertia.com

Okay, I guess it should be a function called abbe() instead of a
method called AbbeGet(). That should solve the problem of trying to
remember whether I called it GetAbbe or AbbeGet.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: method names nounVerb or verbNoun

2010-02-08 Thread Wanderer
On Feb 5, 5:21 pm, Wanderer  wrote:
> On Feb 5, 4:53 pm, Chris Rebert  wrote:
>
>
>
> > On Fri, Feb 5, 2010 at 1:49 PM, Wanderer  wrote:
> > > On Feb 5, 3:26 pm, Chris Rebert  wrote:
> > >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer  
> > >> wrote:
> > >> > Which is the more accepted way to compose method names nounVerb or
> > >> > verbNoun?
>
> > >> > For example voltageGet or getVoltage? getVoltage sounds more normal,
> > >> > but voltageGet is more like voltage.Get. I seem to mix them and I
> > >> > should probably pick one way and stick with it.
>
> > >> Use properties[1] and just call it `voltage`. Python is not Java [2];
> > >> explicit getters/setters are unpythonic.
>
> > >> [1]http://docs.python.org/library/functions.html#property
>
> > > Maybe I'm not using Get right either. I'm wrapping functions.
>
> > >    def AbbeGet(self, Lens):
> > >        """
> > >        Get the Abbe Number V for the material
> > >        where
> > >        V = (Nd - 1)/(Nf - Nc)
> > >        where the Index of Refractions are
> > >        Nd at the Fraunhofer D line 0.5892um
> > >        Nf at the Fraunhofer F line 0.4861um
> > >        Nc at the Fraunhofer C line 0.6563um
> > >        """
>
> > >        Nd = Lens.Mat.NtGet(0.5892)
> > >        Nf = Lens.Mat.NtGet(0.4861)
> > >        Nc = Lens.Mat.NtGet(0.6563)
>
> > >        if (Nf - Nc) != 0:
> > >            V = (Nd - 1)/(Nf - Nc)
> > >        else:
> > >            V = 1e6
>
> > >        return V
>
> > This isn't even really a method; you don't refer to "self" in the body
> > at all. Why isn't it just a function?
>
> > Cheers,
> > Chris
> > --http://blog.rebertia.com
>
> Okay, I guess it should be a function called abbe() instead of a
> method called AbbeGet(). That should solve the problem of trying to
> remember whether I called it GetAbbe or AbbeGet.
>
> Thanks

Actually I decided it still should be a method, just not of doublet
but of Lens. so the calls change from

V1 = self.AbbeGet(Lens1)
V2 = self.AbbeGet(Lens2)

V1 = self.Lens1.abbe()
V2 = self.Lens2.abbe()

-- 
http://mail.python.org/mailman/listinfo/python-list


Pylint Argument number differs from overridden method

2010-03-03 Thread Wanderer
Pylint W0221 gives the warning
Argument number differs from overridden method.

Why is this a problem? I'm overriding the method to add additional
functionality.

This
def GetRays(self, angle, pt, lmbda = 0.6):
"""
"""

angle, x, y, Rays, Power = self.ARefract(angle, pt[0], pt[1],
lmbda)
pt1 = (x, y)

return Rays, Power, angle, pt1


def ARefract(self, angle, x, y, lmbda = 0.6):
"""
"""

Nt = self.Mat.NtGet(lmbda)
self.NtSet(Nt)
angle, x, y, Rays, Power = self.Refract(angle, x, y)

return angle, x, y, Rays, Power



Over rides this

def GetRays(self, angle, pt):
"""
"""

angle, x, y, Rays, Power = self.Refract(angle, pt[0], pt[1])
pt1 = (x, y)

return Rays, Power, angle, pt1


Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pylint Argument number differs from overridden method

2010-03-03 Thread Wanderer
On Mar 3, 2:33 pm, Robert Kern  wrote:
> On 2010-03-03 11:39 AM, Wanderer wrote:
>
> > Pylint W0221 gives the warning
> > Argument number differs from overridden method.
>
> > Why is this a problem? I'm overriding the method to add additional
> > functionality.
>
> There are exceptions to every guideline. Doing this could easily be a mistake,
> so it's one of the many things that Pylint checks for. Silence the warning if
> you like.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it 
> had
>   an underlying truth."
>    -- Umberto Eco

Thanks I was just wondering if I was overlooking something about
inheritance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pylint Argument number differs from overridden method

2010-03-04 Thread Wanderer
On Mar 4, 5:45 am, Jean-Michel Pichavant 
wrote:
> Wanderer wrote:
> > On Mar 3, 2:33 pm, Robert Kern  wrote:
>
> >> On 2010-03-03 11:39 AM, Wanderer wrote:
>
> >>> Pylint W0221 gives the warning
> >>> Argument number differs from overridden method.
>
> >>> Why is this a problem? I'm overriding the method to add additional
> >>> functionality.
>
> >> There are exceptions to every guideline. Doing this could easily be a 
> >> mistake,
> >> so it's one of the many things that Pylint checks for. Silence the warning 
> >> if
> >> you like.
>
> >> --
> >> Robert Kern
>
> >> "I have come to believe that the whole world is an enigma, a harmless 
> >> enigma
> >>   that is made terrible by our own mad attempt to interpret it as though 
> >> it had
> >>   an underlying truth."
> >>    -- Umberto Eco
>
> > Thanks I was just wondering if I was overlooking something about
> > inheritance.
>
> This is only my opinion but you get this warning because of 2 disctinct
> issues:
> 1/ you just made a basic mistake in your signature and need to correct it
> 2/ you did not make any mistake in the signature, but this warning may
> reveal a (small) flaw in your class design.
>
> I don't know the exact context for your code, but it's better to have a
> consistant interface over your methods and mask the implementation
> details from the user.
> In your case, the getRays method may always ask for the lambda
> parameters and just ignore it for one of its implementation.
>
> And don't write empty doctrings to trick pylint. Either write them, or
> remove this rule, you are loosing all the tool benefits.
>
> JM

Okay different example. I'm not really using inheritance here but its
the same idea.
The wx.SpinCtrl is annoyingly integer. I want decimal values. so I
created dSpinCtrl.
It adds the argument places. It's a drop in replacement for SpinCtrl.
(okay its not, because I didn't create all the members). If you
replace SpinCtrl with dSpinCtrl the program should work the same
because the new argument places has a default value. I don't see a
problem with more arguments. Less arguments would be a problem.
Expanding functionality from a base class is what I thought
inheritance is about.

class dSpinCtrl():
"""Adds decimal values to SpinCtrl. Almost a drop in replacement
for SpinCtrl.
Adds 'places' variable for number of places after decimal point
"""

def __init__ (self,
  parent,
  iD = ID_SPIN,
  value = wx.EmptyString,
  pos = wx.DefaultPosition,
  size = wx.DefaultSize,
  style = wx.SP_ARROW_KEYS,
  dmin = -100.0,
  dmax = 100.0,
  dinitial = 0.0,
  places = 0):


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: off topic but please forgive me me and answer

2010-04-02 Thread Wanderer
On Apr 1, 7:34 pm, Patrick Maupin  wrote:
> On Apr 1, 4:42 pm, Tim Chase  wrote:

> > Uh, did you try it at the python prompt?  


When I try it at the IPython prompt, I get

Object 'how much is one half times one half' not found.
-- 
http://mail.python.org/mailman/listinfo/python-list


find in smartpdf files

2011-01-06 Thread Wanderer
We generate PCB assembly files in pdf format using SmartPDF. This
allows us to search for a component in the assembly using the find
feature. We would like to be able to generate a list of components
sorted by part type and then use that list to cycle through a search
by ref designator in the pdf file. Is there a way to use Python
scripts to interface PDF files?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >