Simple wxPython SetLabel question

2008-06-19 Thread dp_pearce
Hi All,

Apologies if this should be seriously obvious. But I am quite new to
Python and it is not quite so obvious yet.

I have a GUI which will eventually load and display database
information. I want the user to be able to browse for a database and
then load it. My problem relates to how I set the value of a TextCtrl
once the user has selected the database they wish to load.

Here is a snip of my code:

import wx
import os

class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Code Snip")
panel   = wx.Panel(self)

databaseLbl = wx.StaticText(panel, -1, "Database:")
database= wx.TextCtrl(panel, -1, "")
databaseBtn = wx.Button(panel, -1, "Browse")
self.Bind(wx.EVT_BUTTON, self.OnBrowse, databaseBtn)
fetchSizer  = wx.BoxSizer(wx.HORIZONTAL)
fetchSizer.Add(databaseLbl)
fetchSizer.Add(database, -1, wx.LEFT |wx.RIGHT, 5)
fetchSizer.Add(databaseBtn)

panel.SetSizer(fetchSizer)

def OnBrowse(self, event):
wildcard = "Access Database (*.mdb) | *.mdb | Access Database
(*.MDB) | *.MDB | All Files (*.*) | *.*"
dialog   = wx.FileDialog(None, "Choose an database",
os.getcwd(), "", wildcard, wx.OPEN)

if dialog.ShowModal() == wx.ID_OK:
path = dialog.GetPath()
#
# NOW SET TEXTCTRL "database" TO "path"
panel.database.SetLabel(path)
#
dialog.Destroy()

app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()

The current code returns that "global name 'panel' is not defined" so
I must be referring to it in the wrong way. Can any body help? Any
directions towards any well recommended tutorials would also be
appreciated.

Thank you in advance for your time.

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


Re: Simple wxPython SetLabel question

2008-06-19 Thread dp_pearce
Thank you very much Cédric. I thought it would be something very
straight forward.
--
http://mail.python.org/mailman/listinfo/python-list


Anyone happen to have optimization hints for this loop?

2008-07-09 Thread dp_pearce
I have some code that takes data from an Access database and processes
it into text files for another application. At the moment, I am using
a number of loops that are pretty slow. I am not a hugely experienced
python user so I would like to know if I am doing anything
particularly wrong or that can be hugely improved through the use of
another method.

Currently, all of the values that are to be written to file are pulled
from the database and into a list called "domainVa". These values
represent 3D data and need to be written to text files using line
breaks to seperate 'layers'. I am currently looping through the list
and appending a string, which I then write to file. This list can
regularly contain upwards of half a million values...

count = 0
dmntString = ""
for z in range(0, Z):
for y in range(0, Y):
for x in range(0, X):
fraction = domainVa[count]
dmntString += "  "
dmntString += fraction
count = count + 1
dmntString += "\n"
dmntString += "\n"
dmntString += "\n***\n

dmntFile = open(dmntFilename, 'wt')
dmntFile.write(dmntString)
dmntFile.close()

I have found that it is currently taking ~3 seconds to build the
string but ~1 second to write the string to file, which seems wrong (I
would normally guess the CPU/Memory would out perform disc writing
speeds).

Can anyone see a way of speeding this loop up? Perhaps by changing the
data format? Is it wrong to append a string and write once, or should
hold a file open and write at each instance?

Thank you in advance for your time,

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


Anyone happen to have optimization hints for this loop?

2008-07-09 Thread dp_pearce
I have some code that takes data from an Access database and processes
it into text files for another application. At the moment, I am using
a number of loops that are pretty slow. I am not a hugely experienced
python user so I would like to know if I am doing anything
particularly wrong or that can be hugely improved through the use of
another method.

Currently, all of the values that are to be written to file are pulled
from the database and into a list called "domainVa". These values
represent 3D data and need to be written to text files using line
breaks to seperate 'layers'. I am currently looping through the list
and appending a string, which I then write to file. This list can
regularly contain upwards of half a million values...

count = 0
dmntString = ""
for z in range(0, Z):
for y in range(0, Y):
for x in range(0, X):
fraction = domainVa[count]
dmntString += "  "
dmntString += fraction
count = count + 1
dmntString += "\n"
dmntString += "\n"
dmntString += "\n***\n

dmntFile = open(dmntFilename, 'wt')
dmntFile.write(dmntString)
dmntFile.close()

I have found that it is currently taking ~3 seconds to build the
string but ~1 second to write the string to file, which seems wrong (I
would normally guess the CPU/Memory would out perform disc writing
speeds).

Can anyone see a way of speeding this loop up? Perhaps by changing the
data format? Is it wrong to append a string and write once, or should
hold a file open and write at each instance?

Thank you in advance for your time,

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


Re: Anyone happen to have optimization hints for this loop?

2008-07-15 Thread dp_pearce
Thank you so much for all your advice. I have learnt a lot.

In the end, the solution was perhaps self evident. Why try and build a
huge string AND THEN write it to file when you can just write it to
file? Writing this much data directly to file completed in ~1.5
seconds instead of the 3-4 seconds that any of the .join methods
produced.

Interestingly, I found that my tests agreed with Bruno. There wasn't a
huge change in speed between a lot of the other methods, other than
them looking a lot tidier.

Again, many thanks.

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


Zipping files

2008-07-15 Thread dp_pearce
Hi all,

I have come across an error while using zipfile and I can't seem to
find somewhere that explains the problem. My script needs to be able
to take text files from one drive and add them to zip files on another
drive. The following seems to work just fine.

import zipfile

# write test file in working directory directory
folder = "J:/"
filename = "testing.txt"
fullpath = folder+filename
fout = open(fullpath, 'wt')
fout.write(str1)
fout.close()

# Add text file to zip file on same drive
zFolder = "J:/"
zFilename = "testing.zip"
zFullpath = zFolder+zFilename
zout = zipfile.ZipFile(zFullpath, "w")
zout.write(fullpath)
zout.close()
print fullpath, "successfully added to", zFullpath

However, if I change the drive letters to anything other than the
drive from which the Python script is saved (e.g. run script from J:
but zip to C:), I get the following warning:

Traceback (most recent call last):
File "J:/test.py", line 18, in 
zout = zipfile.ZipFile(zFullpath, "w")
File "C:\Python25\lib\zipfile.py", line 339, in __init__
self.fp = open(file, modeDict[mode])
IOError: [Errno 13] Permission denied: 'C:/testing.zip'

Can anyopne shed some light on what I am missing here? If it has any
relevance to the permissions part of the error, I am currently using
Windows machines.

Thanks in advance for your time.

Dan

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


Re: Zipping files

2008-07-15 Thread dp_pearce
When I saw "Permission denied", this was my suspicion. And I think you
are very right. I have just gone back and tried writing to a file
outside of C:, in this case C:/output/, and it seems to work again.

Would I be right in guessing there is no way around this?

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


Is it possible to produce spider plots?

2009-08-05 Thread dp_pearce
I want to be able to use Python to produce Spider plots (perhaps you
know them as radar plots or star plots). Does anyone know how to
achieve this? Are there existing libraries?

Direction to any examples, especially those with tutorials, would be
greatly appreciated.

Cheers,
Dan

http://www.answers.com/topic/spider-plot
-- 
http://mail.python.org/mailman/listinfo/python-list