[Tutor] using SQLite with matplotlib - queries vs. lists

2007-02-20 Thread Pine Marten
I'm a novice hoping to use data stored in an SQLite database to make simple 
graphs using matplotlib embedded in a wxPython GUI.  I noticed that 
matplotlib uses lists of integers to make graphs, such as the simple example 
(from the tutorial) of:

from pylab import *
plot([1,2,3,4])
show()

But SQLite queries return as a list of tuples in rows, not a list of 
numbers.  For some reason I haven't found a way any ready-made converter for 
this purpose.  As an exercise, I've wrote this function that converts them:

#takes the result of a fetchall() in sql and returns it as a list of numbers
#assumes you've done the query first, i.e. cur.execute('SELECT * FROM 
table')
import sqlite3
import string
def query_to_list():
queryresult = cur.fetchall()
print Queryresult is , queryresult
queryrows = []
for tuple in queryresult:
num = tuple[0]
queryrows.append(num)
querylist = []
for row in queryrows:
num = int(row)
querylist.append(num)
print Query list is: , querylist

My question is, is there a better way to do this, or is there a ready-made 
way to go from an sql database to matplotlib?  I tried searching for it in 
various ways but haven't found anything.  I feel as though there should be a 
more direct way to go from a db to a plot.

Thanks in advance,
Chae

_
Mortgage rates as low as 4.625% - Refinance $150,000 loan for $579 a month. 
Intro*Terms  http://www.NexTag.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] questions about having python GUI apps running in the background

2006-11-03 Thread Pine Marten
First, I have to thank Alan Gauld for his previous helpful posts--I didn't 
get to thank him last until the topic had changed much so I felt I missed 
that window.  Also, big congratz on 1 millionth visitor to his great site (I 
like to think it may have been me that day or at least close).  And thanks 
to others who continue to be so helpful.

This is a pretty general topic, but it's Friday afternoon so here goes...  I 
want to create a Python GUI app that is meant to open at start up (either on 
Windows, Mac, or Linux) and stay running all the time--what I may be 
incorrectly calling running in the background.  This would be for the 
reasons of wanting the user to be able to interact with it quickly without 
having to open the program every time--it partly will have a stickies type 
use--and also to send timed pop up dialogues or alarms to the user at 
various pre-set times (which may be randomly assigned, user assigned, or 
both).

My concerns are:
1) The app may eat up too much memory if it is not done right.  What is 
reasonable and how can I know how much RAM it's chewing up?
2) What is a good way to time the popups/alarms?  The time module?  wxTimer? 
  Other?
3) How can it have it's own icon in the tray or the dock?

Any input would be appreciated.  Thanks

_
Get FREE company branded e-mail accounts and business Web site from 
Microsoft Office Live 
http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] recommendations for database module based on my needs

2006-10-27 Thread Pine Marten

I'm hoping to create an app which takes user data via a GUI with checkboxes, 
textcontrols, spinner controls, etc.  The data would be some text, some 
numbers, some checkboxes checked or not, etc.  I've been making a little 
progress on that via wxPython and Boa Constructor.

Now I want to save that info such that:

- the user can later search for any piece of data (search by date entered, 
for example).
- the non-text data can be plotted on a chart and simple line regression, 
etc., applied to it.
  this could be some variable over time line graph or one variable vs. 
another scatterplot.

The plotting I will pursue at another time, possibly via MatPlotLib or 
something.  But as for databases, I've heard a few choices, including gadfly 
or SQL and others.  I know zero about this, but I've heard gadfly is good if 
it is just a small dataset.  But how small is small?  The app I'm thinking 
of would take maybe 10-20 numbers/day and a few textboxes worth for 
potentially years.   Or should I just pony up to SQL or some other option 
that I don't know about?

Any recommendations or small python projects which are like this I might 
want to check out?  thanks.

_
Try the next generation of search with Windows Live Search today!  
http://imagine-windowslive.com/minisites/searchlaunch/?locale=en-ussource=hmtagline

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] 5 questions

2006-10-22 Thread Pine Marten


1. Is there a searchable archive of this list?

2. Is there list ettiquette one should be aware of?

3. Besides Vaults of Parnassus, are there other webpages which list projects 
written in Python?  I'm mainly interested in looking at non-technical 
software, things for the common user to use.  I've been surprised at just 
how little of that type I've found so far.

4. Can anyone recommend good books for non-programmers starting out learning 
Python?  I've looked through a few so far and they are ok (Learning 
Python, Python: How to Program) but am still hoping to find one that 
doesn't assume any prior knowledge of programming and defines terms when 
they are first presented.  (That might be a tall order, I know...)

5. If I want to take user information from text boxes, check boxes, etc., 
and store it for later re-display to the person (imagine a movie rating 
diary, with text review of the film and checkboxes or sliders to give it 5 
stars, or has action, or is a comedy, etc.) and have all of it be 
efficiently searchable, what are some good ways to go in terms of how to 
save the information?  For now I have textbox info saving just to a .txt 
file, but that can't be a good way to go about it.  I have the vague sense I 
should learn about databases, but really am not sure what to read about... 
Suggestions?

_
All-in-one security and maintenance for your PC.  Get a free 90-day trial! 
http://clk.atdmt.com/MSN/go/msnnkwlo005002msn/direct/01/?href=http://www.windowsonecare.com/?sc_cid=msn_hotmail

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 32, Issue 72

2006-10-18 Thread Pine Marten


I'm glad that you're not going to give up just yet!  Don't worry, I have 
much more effort in store for you :)
[long and useful description of some basics of Python deleted]

Wow, thanks very much!  That was extremely useful.  I had some time late 
last night when it was quiet here and I could just read through it, and I 
wound up making a little more progress, making the filename a variable which 
was named based on the current date (had to figure out to import the 
datetime module and how to use that), and also made the save button clear 
the textbox using Clear().

I'll no doubt encounter more confusions and the train of understanding may 
still be in the station, but it lurched forward a bit due to your 
explanations!  Thanks!

-PM

_
Add a Yahoo! contact to Windows Live Messenger for a chance to win a free 
trip! 
http://www.imagine-windowslive.com/minisites/yahoo/default.aspx?locale=en-ushmtagline

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 32, Issue 72

2006-10-17 Thread Pine Marten

(in reference to a question I had about how to simply save the content of a 
textCtrl to a text file)

#Okay, here is the function we need to change.


 def OnSaveButton(self, event):
 #from John's save(event) function:
 #
 #savefile = open(self.filename, 'w')
 #savefile.write(myTextBox.GetValue())
 #savefile.close()

 savefile = open('test.txt','w')
 #if you don't want 'test.txt' try using a variable.


 savefile.write(self.textCtrl1.GetValue())
 #textCtrl1 is an attribute of your Frame1 class.



 savefile.close()
 #then we just save it.

Do you understand which parts of John's examples were changed and why?
Hope That Helps,
-Luke

I tried it and it did work this time, thanks so much.  Your effort may keep 
me trying bit by bit to gain a little profiency.

And yes, I believe I see how much of this ought to work now.  I am just 
going to keep going over how one assigns a variable like savefile to a built 
in function like open() but then attaches a method to it such as when you 
write savefile.write.  I think if I work with that enough I will come to see 
it as intuitive; for now it still is unintuitive.   Thanks again.

_
Stay in touch with old friends and meet new ones with Windows Live Spaces 
http://clk.atdmt.com/MSN/go/msnnkwsp007001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=createwx_url=/friends.aspxmkt=en-us

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to save and later open text from a wxTextCtrl widget to a text file?

2006-10-16 Thread Pine Marten
I want to make a GUI in which user can write text in a text box and then 
click a button to save it to a text file.  I'm using wxPython's TextCtrl 
widget.

Then later I would want the user to be able to open it back into that 
window.

Any help appreciated, thank you.

_
Stay in touch with old friends and meet new ones with Windows Live Spaces 
http://clk.atdmt.com/MSN/go/msnnkwsp007001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=createwx_url=/friends.aspxmkt=en-us

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 32, Issue 69

2006-10-16 Thread Pine Marten

Thank you John for the code but I still can't get it to work and to simply 
save the contents of the text box to a file.  Here is the code I have which 
just makes a panel with a text control and two buttons, Save and Save 
As...  My hope is this can easily incorporate the changes you suggest, but 
I can't figure out how to do it:

#Boa:Frame:Frame1

import wx

def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1SAVE, wxID_FRAME1SAVEAS,
wxID_FRAME1TEXTCTRL1, ] = [wx.NewId() for _init_ctrls in range(5)]

class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  pos=wx.Point(367, 109), size=wx.Size(402, 489),
  style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(394, 455))

self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', 
parent=self,
  pos=wx.Point(0, 0), size=wx.Size(394, 455),
  style=wx.TAB_TRAVERSAL)

self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, 
name='textCtrl1',
  parent=self.panel1, pos=wx.Point(40, 56), size=wx.Size(264, 
248),
  style=wx.TE_MULTILINE, value='textCtrl1')

self.Save = wx.Button(id=wxID_FRAME1SAVE, label='Save', name='Save',
  parent=self.panel1, pos=wx.Point(152, 32), size=wx.Size(75, 
23),
  style=0)
self.Save.Bind(wx.EVT_BUTTON, self.OnSaveButton, id=wxID_FRAME1SAVE)

self.saveas = wx.Button(id=wxID_FRAME1SAVEAS, label='Save as...',
  name='saveas', parent=self.panel1, pos=wx.Point(232, 32),
  size=wx.Size(75, 23), style=0)
self.saveas.Bind(wx.EVT_BUTTON, self.OnSaveasButton,
  id=wxID_FRAME1SAVEAS)

def __init__(self, parent):
self._init_ctrls(parent)

def OnSaveButton(self, event):
event.Skip()

def OnSaveasButton(self, event):
event.Skip()

If you or someone could show me how to insert the save function into this 
properly so I can get it to work in this simple case, I think I'll 
understand it better.  In the meantime I will continue trying, and I will 
read up on Alan's suggestion about learning to open, write, and close files 
generally.

Thank you,
PM

_
Try Search Survival Kits: Fix up your home and better handle your cash with 
Live Search! 
http://imagine-windowslive.com/search/kits/default.aspx?kit=improvelocale=en-USsource=hmtagline

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 32, Issue 70

2006-10-16 Thread Pine Marten


Did you create this code, or did someone give it to you?  It looks
like it's been made with BoaConstructor.  If you're using Boa for
development, you'd probably be better off using it to add your save
functionality, rather than writing the code by hand.

Unfortunately, I can't help you with that, but maybe someone else can.

In fact, I see you've already got Save and SaveAs buttons, so maybe
you just need to edit OnSaveButton() and OnSaveAsButton().

I used Boa Constructor to make it.  As far as I understand it, Boa sets 
things up for you but then you have to add code to complete things, it does 
not have an option to add save functionality on its own.

In this case I did in fact try to add the code you originally suggested 
under the OnSaveButton() and OnSaveAsButton() but was unable to get it to 
work.

Teetering on the brink of just bagging trying to learn Python, but thanks 
for your suggestions.

_
Stay in touch with old friends and meet new ones with Windows Live Spaces 
http://clk.atdmt.com/MSN/go/msnnkwsp007001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=createwx_url=/friends.aspxmkt=en-us

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor