gnuplot stdout & python question

2005-10-21 Thread bwaha
I've posted this question to comp.graphics.apps.gnuplot too but given that
this python group may also comprise a lot of gnuplot users, and is far more
active, I've posted this question here too. My apologies to those who read
this twice. I posted to cgag before I decided to post here with a more
meaningful subject.


Anyone had any success getting stdout from gnuplot on an ms windows system
(XP)? I'm trying to read mouse coordinates using python. This link shows a
basic mechanism implemented in python.

http://www.physik.tu-dresden.de/~baecker/python/gnuplot.html

It is similar to the gnuplot.py code which I understand is unidirectional
only ie. send commands to gnuplot via gnuplot stdin. My hope is that I can
implement the bidirectional interface in gnuplot.py and give it away to
whoever might find it useful. But first, I gotta get it working.

I can't seem to get anything back to a python shell by this method. Hangs in
the function thats supposed to read stdout. Could be something I'm doing
wrong with python but I rather suspect there is something in the way gnuplot
on windows deals with stdout that I'm not understanding.

btw - I'm using gnuplot 4.1 (Oct 10 cvs build), python 2.3

bwaha


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


Re: suggestions on how to do this

2005-04-27 Thread bwaha
Hi bgs

Many thanks. This generates the correct coefficients. I am studying
your implementation now. I've  not used a dictionary of dictionaries
before so there's a bit of a learning curve going on right now. However
I can see that b[k] holds the relevant info (coefficients and powers)
so I can easily modify it to collect terms with like powers. As for
speed, its not a concern. Thanks again.

bwaha Chris

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


MVC programming with python (newbie) - please help

2006-01-06 Thread bwaha
I'd appreciate some experience from the gurus out there to help me
understand how to implement MVC design in python code.

Entry number 5 on the wxpython wiki at
http://wiki.wxpython.org/index.cgi/BuildingControls discusses MVC design in
building reusable controls. The author (Terrel Shumway) suggests that
instead of:

quote:

class MyCoolListControl(...):
def __init__(self,parent,id,choices):
...
def InsertItem(...):
def AppendItem(...):

where choices is a static list, do something like this

class ListDataModel:
""" a minimal model interface to be used by MyCoolListControl """
def __len__(self):
""" return the number of items in the list """
def __getitem__(self,index):
""" return the specified item """

# consider notifications for observers (e.g. the list control)

# allow the user to define whatever mutators are appropriate


class MyCoolListControl(...):
def __init__(self,parent,id,model):
...
def [GS]etModel(self,model):
...

This allows the user (programmer) to store the data the way he thinks is
best, rather than having to copy the data into your structure whenever it
changes. It also reduces the need for kludges like [GS]etItemData for
maintaining association of the real data with its currently displayed string
representation.

endquote

The author refers to mvctree.py in wxPython as an example of MVC design.
However I'm still too green so I find that particular example too complex
and I'm not understanding the separation the author is recommending.

Can anyone explain to me further the simple example above and/or supply a
simple example of their own? At some level I feel like there's a benefit but
I'm failing to grasp it, and how to implement it. If I understand correctly
then in the future for example I could completely change how data is stored
in the class ListDataModel and not require a change in class
MyCoolListControl. Say, hypothetically, I wanted to implement ListDataModel
using a dictionary rather than, more naturally, a list, where the "list"
data structure is implemented as a dictionary and the list entries
correspond to dictionary keys (dictionary values are not used in this case).
Then if I understand the MVC concept, class MyCoolListControl need not
change at all. If that's true then that's really cool. But I don't get how
that works.

I think I need a little further expansion of the example or an alternative
(20-30 liner) that I can work through.

The question arises in the context of wanting to build a dialog with a tree
control that presents projects and studys as a tree and allows selection of
projects and studies as required by the user. I want to parse a file with
contents as follows:

BEGIN PROJECT "mpi6_0"
STUDY "Cyc0302_0" cyc0302_beanoz_x1.sdy
STUDY "Cyc0305_0" cyc0305_beanoz_x1.sdy
STUDY "Cyc0308_0" cyc0308_beanoz_x1.sdy
STUDY "Cyc0311_0" cyc0311_beanoz_x1.sdy
STUDY "Cyc0314_0" cyc0314_beanoz_x1.sdy
END PROJECT
BEGIN PROJECT "mpi6_1"
STUDY "Cyc0302_1" cyc0302_beanoz_x1.sdy
STUDY "Cyc0305_1" cyc0305_beanoz_x1.sdy
STUDY "Cyc0308_1" cyc0308_beanoz_x1.sdy
STUDY "Cyc0311_1" cyc0311_beanoz_x1.sdy
STUDY "Cyc0314_1" cyc0314_beanoz_x1.sdy
END PROJECT
...

I have wriiten a class as follows that extracts the data from the file.

import os

class ProjectFileDecoder:
"""
parse project file to obtain project names and associated studies and
study files
"""
def __init__(self, file):
self.projects = {}
self.parse_file(file)

def parse_file(self, file):
f = open(file, 'r')
dir = os.path.split(file)
while 1:
line = f.readline()
if 'BEGIN PROJECT' in line:
proj_name = line.strip().split('"')[1]
self.projects[proj_name] = {}
elif 'STUDY' in line:
study_name = (line.strip().split('"'))[1].strip()
study_file = dir[0] + '/' +
(line.strip().split('"'))[2].strip()
self.projects[proj_name][study_name] = study_file
elif not len(line):
f.close()
break

def getProjectNames(self):
return self.projects.keys()

def getStudyNames(self):
return [self.projects[i].keys() for i in self.getProjectNames()]

def getStudyFiles(self):
return [self.projects[i].values() for i in self.getProjectNames()]

At some level this seems to me like the class ListDataModel above. I just
need to make a MyTreeControl class. However here GS(et) routines are
implemented in the ProjectFileDecoder class (data model?)  whereas in the
earlier advice they are in class MyCoolListControl. So I'm not understanding
how data gets from the DataModel class to the ListControl class. After all
the words I've said,  I think that's the core misunderstanding I have.

Hope someone can help clear that up for me.

Chris






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


Re: MVC programming with python (newbie) - please help

2006-01-07 Thread bwaha

"Gerard Flanagan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Gerard Flanagan wrote:
>
> > bwaha wrote:
> >
> > > I'd appreciate some experience from the gurus out there to help me
> > > understand how to implement MVC design in python code.
> > >
> >
>
> Badly snipped, not pretending to be a 'guru'
>
>
> Gerard
>

You taught me something so in in some part at least you are. Thanks.



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


Re: MVC programming with python (newbie) - please help

2006-01-07 Thread bwaha

"bwaha" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'd appreciate some experience from the gurus out there to help me
> understand how to implement MVC design in python code.



Thanks for all the help. Also this link was sent to me by pm and I found
this very useful too. Its a short wxpython MVC exmaple. (Thanks. Sanchit).

http://www.techietwo.com/detail-6332577.html




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


Re: MVC programming with python (newbie) - please help

2006-01-09 Thread bwaha

"has" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> bwaha wrote:
> > The author refers to mvctree.py in wxPython as an example of MVC design.
> > However I'm still too green so I find that particular example too
complex
> > and I'm not understanding the separation the author is recommending.
>
> MVC is all about separation of concerns.
>



Woh!!! A disertation (x3). Very much appreciated. It will take much more a
single reading but I'm sure it will help me understand the samples supplied
by the earlier posters. Thanks.



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


Re: MVC programming with python (newbie) - please help

2006-01-11 Thread bwaha


Well I read this in daylight hours. Talk about Enlightening!!!. It all
became clear. Now I even understand the point of an observer class, which
was shown in an example I posted back to the group from an earlier reply.

Thanks again for sharing your knowledge.

Be Well and Happy Always

Chris



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


Re: MVC in wxPython HELP!

2006-01-12 Thread bwaha
> Can I just suggest you search in Google Groups for the message by
> "has" labelled "Re: MVC programming with python (newbie) - please help".
> Dated: 7 Jan 2006 07:03:04 -0800.  It is one of the nicest short
> descriptions of the MVC pattern and why it works.

I'll second that 


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


matplotlib legend problem

2006-01-27 Thread bwaha
Has anyone figured out how to get a legend for each line in a
matplotlib.collections.LineCollection instance?

No problem if I plot lines the default way ie. line,=plot(x,y). But I've had
to resort to using LineCollections for the significant speed boost since I
am routinely plotting up to ten 3 point datasets in one plot. The legend
doc says that "legend by itself will try and build a legend using the label
property of the lines/patches/collections". But it seems that for a
collection the legend refers to the collection as a whole, not the
individual lines within the collection.

AFAIK this is a limitation of matplotlib 0.85. Any ideas on how I can
workaround this problem that won't kill my speed boost?


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


Re: matplotlib legend problem

2006-01-27 Thread bwaha

"bwaha" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Has anyone figured out how to get a legend for each line in a
> matplotlib.collections.LineCollection instance?
>
After frigging around for hours I finally tracked down the real cause of the
plotting speed problem which led me to use LineCollections in the first
place. Its the 'best' option in the legend location and setting it to
default in my application!

When I first put in the LineCollection code I cut out my legend code to keep
things simple. And sure enough LineCollections plotted really fast. Then,
since legends didn't work for LineCollection lines individually I figured
I'd fudge it by creating dummy lines from the collection, adding labels and
calling legend(). This worked with only a small speed penalty.  But I kept
getting a stackdump when I added the location argument. Finally realised it
was due to having a default of 'best' location in my code which meant it
went searching for intersection with lines that don't exist (outside of the
LineCollection). So I disabled the 'best' location option. Then I figured,
since I'd cleaned up my code a bit, I'd reinstate my earlier pylab.plot
based line drawing code to see if the clean up made any difference to what
was previously abysmal performance. The lines plotted faster than the
LineCollection code! When I removed the legend hack for LineCollections
there was virtually no difference. (Story is not finshed yet). So I figured
after all that that I'd reinstate my pylab.plot based code since I could
plot a greater range of symbols than with LineCollections with no speed
loss. And I thought why not go the whole hog and reinstate the 'best'
location option too. Boom! Plotting performance was abysmal again. Finally I
realised that enabling 'best' and having it as the default meant that as I
added new data to plot, the search time for a good place to put the legend
increased dramtically, and probably became more difficult with more and more
lines filling the canvas.

Anyway now I'm a lot happier than when I started because I've retained my
original range of plot styles and I got much faster plotting. Hopefully this
lesson can help someone else.




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


Re: Newbie Help!

2006-02-06 Thread bwaha

> 3. Any good ebooks or links to start with. (according to the web this is
the
> best place to start.)

If you get the point of wantig to buy a book, I can recommend Python Visual
Quickstart Guide by Chris Fhris Fehily as a very good text for beginners. I
has helped me a lot.



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


Re: charting

2006-04-20 Thread bwaha

"Gary Wessle" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Dear python users
>
> I am just wondering if python is the language to use to build a custom
> charting package which is live updated from live data stream coming
> through  a socket. as well as dynamically execute data analysis code
> on the data being fed. I have been looking at SpecTix.
>
> thank you

can't help much with the details but have you checked out the matplotlib
library? http://matplotlib.sourceforge.net/ Its an excellent python plotting
library. As I recall there's a sample to do with realtime updating of data
from an ECG.

As for whether python is the language to use ... fwiw ... if you're a
programmer then it is a no brainer to use, has a wealth of library support
and has a fantastic community to help you out ... and if your not a
programmer  need I say more.

bwaha


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


Re: Method Call in Exception

2006-04-20 Thread bwaha

"mwt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> In my latest attempt at some Python code, I've been tempted to write
> something in the form of:
>
> try:
> [...] #doing some internet stuff
> except IOError:
> alternate_method_that_doesnt_need_internet()
>
I'm only a hack at programming but where I find try: blocks useful is where
I have multiple statements within the try: block, any one or more of which
can produce an exception. I just want to trap a failure and get out of
there. This happens to me for any number of reasons when I drive other apps
through the com interface. (In my job I just write simple apps to make my
job easier, not bomb-proof customer-focused code). So in your case perhaps
you have open connection, find site, get data within the try block, and exit
gracefully if any one fails. How you use it depends on what level of detail
you need.

bwaha



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


Re: Recommended IDE for creating GUI?

2006-04-23 Thread bwaha

"Marty Christion" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> What are some good free or inexpensive (<$50) IDE's for learning how to
> program and create GUI's for Python?  I'm pretty good with the simple
> programming aspect of the language, but I'm a little mystified by the
world
> of GUI's, and the options available in python.
>
>

I've been using python on and off for about 12 months and WxPython for about
5 months. I've found the following combination works well together:

SPE - Stani's Python Editor http://stani.be/python/spe/blog/
WXGlade  - bundled with SPE
WinPDB - debugger bundled with in SPE that works with GUIs
WxPython - python bindings to WxWidgets library (fantastic demos that get
you up and running quickly) http://www.wxpython.org/
Ipython - interactive python shell http://ipython.scipy.org/

hth
bwaha



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


py2exe problem

2006-04-15 Thread bwaha
First time trying to create an executable with py2exe.  I have a small
program which makes use of python23 (2.3.5?), wxpython ('2.6.2.1'),
matplotlib ('0.83.2'), win32com (latest?), Numeric ('23.7') on Windows XP &
Win2000. The program runs without problem but as an exe it doesn't even get
to showing the GUI.

I get the following error log when I run the executable.

Traceback (most recent call last):
  File "mpival3.py", line 1264, in ?
  File "wx\_core.pyc", line 7668, in __init__
  File "wx\_core.pyc", line 7320, in _BootstrapApp
  File "mpival3.py", line 364, in OnInit
  File "mpival3.py", line 79, in __init__
  File "mpival3.py", line 204, in restore_inputs
  File "mpival3.py", line 275, in setConfig
  File "wx\_controls.pyc", line 621, in SetValue
TypeError: String or Unicode type required

Line 621 in wx\_controls.pyc refers to setting the value of a combobox at
the start up of my code. The initial values of various widgets (checkboxes,
textboxes and comboboxes) are stored in a pickled file which is read at the
program start. Running the program, not the exe, shows that the variables
are retrieved properly and of the correct type for the combobox.SetValue
method.

Furthermore, if I comment out the code to set the combobox value and
recreate the exe, then I get the same sort of error message for a different
(textbox) widget.

I've read all the py2exe WIKI entries, forum posts and Googled myself
senseless ... now I'm stuck. Can anyone shed any light on this problem, or
have some experience to share?

As an aside, I've found this a very frustrating process at this stage. Never
thought it would be so much trouble. Am I just dreaming in thinking I can
package up my program with this combination of modules?.


fwiw my py2exe setup.py file is included below. It's obviously a concoction
of includes, excludes and other options pieced together from hours of
browsing wiki's etc.

Thanks.

Chris

==

# setup.py
from distutils.core import setup
import py2exe
import sys

# If run without args, build executables, in quiet mode.
if len(sys.argv) == 1:
sys.argv.append("py2exe")
sys.argv.append("-q")


# Matplotlib
# We need to import the glob module to search for all files.
import glob
# We need to exclude matplotlib backends not being used by this executable.
You may find
# that you need different excludes to create a working executable with your
chosen backend.
# We also need to include matplotlib.numerix.random_array
options = {"py2exe": {
  "includes": ["matplotlib.numerix.random_array",
 "matplotlib.backends.backend_tkagg", "encodings",
   "encodings.*"],
#   "includes": ["matplotlib", "Numeric", "scipy",
"scipy_base"],
#  "excludes": ["_gtkagg", "_tkagg"],
  "packages": ["pytz"],
  "dll_excludes": ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll']
  }
   }

# Additional data files are required by matplotlib.  Note that the glob.glob
routine
# doesn't seem to pick up the .matplotlib resource file, so I copy that
separately.
# Do the same if you need to
#datf = [(r'matplotlibdata', glob.glob(r'c:\python23\share\matplotlib\*')),
#(r'matplotlibdata',
[r'c:\python23\share\matplotlib\.matplotlibrc'])]
datf = [(r'matplotlibdata', glob.glob(r'c:\python23\share\matplotlib\*'))]


# for scipy
excludes = []
includes = ["scipy.special.__cvs_version__", "scipy.linalg.__cvs_version__",
"scipy.special.cephes"]
options["py2exe"]["includes"].extend(includes)

# other
#options["py2exe"]["compressed"] = 1
#options["py2exe"]["optimize"] = 2
#options["py2exe"]["ascii"] = 1
#options["py2exe"]["bundle_files"] = 3
#options["py2exe"]["skip_archive"] = 1

setup(
options = options,
data_files = datf,
name = 'validation',
description = 'Validation Program',
windows = ['mpival3.py']
)




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


Re: py2exe problem

2006-04-16 Thread bwaha

"Serge Orlov" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> bwaha wrote:
> > First time trying to create an executable with py2exe.  I have a small
> > program which makes use of python23 (2.3.5?), wxpython ('2.6.2.1'),
> > matplotlib ('0.83.2'), win32com (latest?), Numeric ('23.7') on Windows
XP &
> > Win2000. The program runs without problem but as an exe it doesn't even
get
> > to showing the GUI.
>
> Do you have more than one wxwindows installed? Check you site-packages.
> Do you follow documentation
> http://wiki.wxpython.org/index.cgi/MultiVersionInstalls ? Seems like
> py2exe picks wrong wxwindows. Insert printing of wx.VERSION and
> wx.PlatformInfo and try to run it packaged and non-packaged.
>
>   Serge
>

Thanks for the suggestion, but I definitely have only one version installed.
In fact I uninstalled it and installed an earlier version (2.5.5.1) to see
if it was specifically wxPython related. No change.



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


Re: py2exe problem

2006-04-16 Thread bwaha

"Serge Orlov" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> bwaha wrote:
> > Thanks for the suggestion, but I definitely have only one version
installed.
> > In fact I uninstalled it and installed an earlier version (2.5.5.1) to
see
> > if it was specifically wxPython related. No change.
>
> Then why don't you try to print what is passed to SetValue in the exe,
> just change windows = ['mpival3.py'] in setup.py with console =
> ['mpival3.py'] and add prints.
>

Thanks. Turned out to be user error. I was trying to SetValue(None).


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