GUI woes

2005-04-23 Thread jeff elkins
Howdy,

This may not belong here, if so apologies...

I'm a python newbie, but have completed a console app that I'd like to run 
under X. Reading recent postings here, wxpython seemed a reasonable choice so 
under debian sid, I installed (via apt-get) the various wxpython stuff 
available.:

libwxgtk2.4-python 
libwxgtk2.5.3-python
python-opengl
python-pythoncard
python2.1-opengl 
python2.2-opengl 
python2.3-opengl 
python2.3-pythoncard
pythoncard 
pythoncard-doc
pythoncard-tools
wx2.5-examples
wxpython2.5.3 
wxwin2.4-examples

test.py crashes with the error below. Any clues?  

===

Running test.py: 

Traceback (most recent call last):
  File "./test.py", line 87, in ?
app = MyApp(0) # Create an instance of the application class
  File "/usr/lib/python2.3/site-packages/wxPython/wx.py", line 1951, in 
__init__
_wxStart(self.OnInit)
  File "./test.py", line 76, in OnInit
frame = MyFrame(None, -1, "This is a test")
  File "./test.py", line 26, in __init__
self.Bind(wx.EVT_SIZE, self.OnSize)
AttributeError: MyFrame instance has no attribute 'Bind'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI woes

2005-04-24 Thread jeff elkins
On Sunday 24 April 2005 03:11 am, Roger Binns wrote:
> "jeff elkins" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> > under debian sid, I installed (via apt-get) the various wxpython stuff
> > available.:
> >
> > libwxgtk2.4-python
> > libwxgtk2.5.3-python
> > python-opengl
> > python-pythoncard
> > python2.1-opengl
> > python2.2-opengl
> > python2.3-opengl
> > python2.3-pythoncard
> > pythoncard
> > pythoncard-doc
> > pythoncard-tools
> > wx2.5-examples
> > wxpython2.5.3
> > wxwin2.4-examples
>
> You have a mixture of different versions of wxPython in there.
>
> > AttributeError: MyFrame instance has no attribute 'Bind'
>
> Bind was introduced in wxPython 2.5.  Looks like you are
> running against thr 2.4 library.
>
> Roger

Thanks. I'll see if I can delete/reinstall and fix things.


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


Re: GUI woes

2005-04-24 Thread jeff elkins
On Sunday 24 April 2005 02:07 am, Kartic wrote:
>
> Jeff - Could you please post your code?
>
>  From what you have posted it looks like your MyFrame class does not
> inherit from wx.Frame.
>

Thanks Kartic. That test.py was from the wxpython download site.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI woes

2005-04-24 Thread jeff elkins
On Sunday 24 April 2005 10:41 am, jeff elkins wrote:
> On Sunday 24 April 2005 03:11 am, Roger Binns wrote:
> > You have a mixture of different versions of wxPython in there.

> Thanks. I'll see if I can delete/reinstall and fix things.

Fixed and thanks for the clue :)

Jeff

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


Re: Which IDE is recommended?

2005-04-27 Thread jeff elkins
On Wednesday 27 April 2005 01:16 pm, monkey wrote:
> Read through python site for programming tool, really plenty of choices :-)
> (For c++, I just can't breath with very very limited choices)
>
> Tried Spe, it come with wxGlade built-in very nice(is Spe still actively
> develop?). But seem that Boa Constructor and PyDev(the plug-in for Eclipse)
> also worth looking. Actually which one are you guys using? and why? I think
> it is also valuable for those who are new to python as me.

Is Boa actively used? There doesn't seem to be much activity its mailing list. 
The tutorial fails for me using python 2.3.5, wxpython 2.5.3.2 and Boa 0.4.0 
under debian sid.

Jeff

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


Newbie: saving dialog variables

2005-05-07 Thread jeff elkins
Howdy,

I've written a program that calls an imported dialog to gather some needed 
input. What's the common method for passing that data back to the caller? I've 
tried a 'return data' prior to self.Close() ... all that happens then is the 
dialog won't close. I'm sure this is obvious, but this newbie's stuck!

Thanks,

Jeff

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


Re: Newbie: saving dialog variables

2005-05-07 Thread jeff elkins
On Saturday 07 May 2005 01:24 pm, jeff elkins wrote:
> Howdy,
>
> I've written a program that calls an imported dialog to gather some needed
> input. What's the common method for passing that data back to the caller?
> I've tried a 'return data' prior to self.Close() ... all that happens then
> is the dialog won't close. I'm sure this is obvious, but this newbie's
> stuck!
>
> Thanks,
>
> Jeff

If it makes any difference, the data is contained in an array...

Thanks again,

Jeff

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


Re: Newbie: saving dialog variables

2005-05-07 Thread jeff elkins
On Saturday 07 May 2005 02:34 pm, Jeremy Bowers wrote:
> On Sat, 07 May 2005 13:24:34 +0000, jeff elkins wrote:
> > Howdy,
> >
> > I've written a program that calls an imported dialog to gather some
> > needed input. What's the common method for passing that data back to the
> > caller? I've tried a 'return data' prior to self.Close() ... all that
> > happens then is the dialog won't close. I'm sure this is obvious, but
> > this newbie's stuck!
> >
> > Thanks,
> >
> > Jeff
>
> In general, the dialog is an instance of a class. Once the dialog closes,
> the window should be gone but the instance variable should still be around.
> Common practice is to put the relevant data in the dialog instance member
> for retrieval after closing. In certain cases, the method used to invoke
> the dialog will return the relevant value, but this is somewhat limiting.
> In even more rare cases, the dialog will be popped up by a function,
> giving no direct reference to the dialog at any point, and the value is
> returned by the function; this is generally limited to the "Yes/No/Cancel"
> style dialog or its simpler bretheren ("OK/Cancel" and "OK").
>
> I'm assuming that last one is not the case.
>
> To be more directly helpful, we'd need more data, ideally a code snippet
> fully demonstrating the problem (i.e., a runnable program). But at a bare
> minimum, we'd need to know where this dialog came from. Tk? PyGTK?
> wxPython? Some curses library? MFC?

Jeremy,

The dialog is from wxPython, generated using Boa Constructor. I'm cutting out 
hunks to try to be concise...

===
import wx

def create(parent):
return vents(parent)

[wxID_VENTS, wxID_VENTSEXITBUTTON, 
 wxID_VENTSVENTTYPETEXT,
[snip]

] = [wx.NewId() for _init_ctrls in range(14) ]

class vents(wx.Dialog):
def _init_ctrls(self, prnt):
wx.Dialog.__init__(self, id=wxID_VENTS, name=u'prefs', parent=prnt,
  pos=wx.Point(418, 320), size=wx.Size(321, 285),
  style=wx.DEFAULT_DIALOG_STYLE, title=u'Ventilator Settings')
self.SetClientSize(wx.Size(321, 285))

self.exitButton = wx.Button(id=wxID_VENTSEXITBUTTON, label=u'OK',
  name=u'exitButton', parent=self, pos=wx.Point(60, 250),
  size=wx.Size(85, 30), style=0)
self.exitButton.Bind(wx.EVT_BUTTON, self.OnExitButtonButton,
  id=wxID_VENTSEXITBUTTON)

self.venttypeText = wx.TextCtrl(id=wxID_VENTSVENTTYPETEXT,
  name=u'venttypeText', parent=self, pos=wx.Point(64, 24),
  size=wx.Size(144, 25), style=0, value=u'')

[snip]

def __init__(self, parent):
self._init_ctrls(parent)
 
# build an array of values entered in the dialog
# return array to calling program


def OnExitButtonButton(self, event):
  self.Close()

==

The dialog above is called by:

 def OnVentButtonButton(self, event):
dlg = vents.vents(self)
try:
dlg.ShowModal()
finally:
dlg.Destroy()


Thanks again,

Jeff

  




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


Re: Newbie: saving dialog variables

2005-05-07 Thread jeff elkins
On Saturday 07 May 2005 04:39 pm, Jeremy Bowers wrote:
> OK, I can't quite directly run this, but assuming you're trying to get the
> user to enter some text into the text control, you should be able to add
>   print dlg.venttypeText.GetValue()
> to print what the user entered; this comes after the try: finally: (i.e.,
> on the same indentation as "dlg = vents.vents(self)").

Thanks!  That did the trick.

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


Finding startup files

2005-05-11 Thread jeff elkins

I'm creating an app that relies on a configuration file at launch. The file 
will always exist in the app's installation directory, but I have no control 
over where that might be. 

Is there an OS-independent way that I can instruct the app to look in it's 
home directory for startup files? Right now, I'm hard coding the path, which 
won't work. 

Thanks,

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


Re: Finding startup files

2005-05-11 Thread jeff elkins
On Wednesday 11 May 2005 04:32 pm, [EMAIL PROTECTED] wrote:
> The following script demonstrates a method that should work for you. I
> believe it is entirely cross-platform.
>
> #! /usr/bin/python
>
> import sys
> import os
>
> print os.path.abspath(os.path.dirname(sys.argv[0]))

Works perfectly, thanks much!

Jeff

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


Re: Finding startup files

2005-05-11 Thread jeff elkins
On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
> On 2005-05-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > The following script demonstrates a method that should work for you. I
> > believe it is entirely cross-platform.
> >
> > #! /usr/bin/python
> >
> > import sys
> > import os
> >
> > print os.path.abspath(os.path.dirname(sys.argv[0]))
>
> That will probably work most of the time, but...
>
>  1) you're not gauranteed that argv[0] contains the application
> path/filename.
>
>  2) the directory containing the executable is not where
> configuration files are supposed to be stored under
> Unix/Linux.

Thanks Grant,

I live and develop in Linux, but unfortunately, 99.99% of the users of this 
particular application (analysis of medical laboratory data) will be working 
with Windows. 

I'm totally new to Python (obvious,yes?) so how might argv[0] fail?

Jeff




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


Re: Finding startup files

2005-05-11 Thread jeff elkins
On Wednesday 11 May 2005 10:18 pm, Robert Kern wrote:
> jeff elkins wrote:
> > On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
> >>On 2005-05-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >>>The following script demonstrates a method that should work for you. I
> >>>believe it is entirely cross-platform.
> >>>
> >>>#! /usr/bin/python
> >>>
> >>>import sys
> >>>import os
> >>>
> >>>print os.path.abspath(os.path.dirname(sys.argv[0]))
> >>
> >>That will probably work most of the time, but...
> >>
> >> 1) you're not gauranteed that argv[0] contains the application
> >>path/filename.
> >>
> >> 2) the directory containing the executable is not where
> >>configuration files are supposed to be stored under
> >>Unix/Linux.
> >
> > Thanks Grant,
> >
> > I live and develop in Linux, but unfortunately, 99.99% of the users of
> > this particular application (analysis of medical laboratory data) will be
> > working with Windows.
> >
> > I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
>
> If I make a symbolic link to the executable script and run it using that
> link, sys.argv[0] will give the filename of that link, not the real file
> it points to.


Thanks. I just tested that and it does indeed fail.

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


Re: Finding startup files

2005-05-12 Thread jeff elkins
On Thursday 12 May 2005 05:24 am, Mike Meyer wrote:
> jeff elkins <[EMAIL PROTECTED]> writes:
> > On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
> >> On 2005-05-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >> > The following script demonstrates a method that should work for you. I
> >> > believe it is entirely cross-platform.
> >> >
> >> > #! /usr/bin/python
> >> >
> >> > import sys
> >> > import os
> >> >
> >> > print os.path.abspath(os.path.dirname(sys.argv[0]))
> >>
> >> That will probably work most of the time, but...
> >>
> >>  1) you're not gauranteed that argv[0] contains the application
> >> path/filename.
> >>
> >>  2) the directory containing the executable is not where
> >> configuration files are supposed to be stored under
> >> Unix/Linux.
> >
> > Thanks Grant,
> >
> > I live and develop in Linux, but unfortunately, 99.99% of the users of
> > this particular application (analysis of medical laboratory data) will be
> > working with Windows.
>
> Yes, but Windows these days supports multiple users. Are you sure that
> you want to restrict your users to one configuration file per
> installed version of the program?
>
> I'm not sure Windows has a good solution to this problem. My
> experiences with trying to share applications between users on Windows
> haven't been very pleasant.
>
> http://mail.python.org/mailman/listinfo/python-list


Re: HELP Printing with wxPython

2005-05-12 Thread jeff elkins
On Thursday 12 May 2005 04:56 am, Mike Meyer wrote:
> James Carroll <[EMAIL PROTECTED]> writes:
> > If you are doing this just for yourself, and you know you have a
> > printer that will really print just the plain text when you send it
> > plain text (like a dot matrix printer from the early 90s) then you can
> > probably open the printer device  and send it text.  Under windows you
> > can try opening LPT1  or on unix it's probably /dev/lpr or something
> > like that.
>
> Under Unix, you shouldn't be able to open the line printer, whether
> it's /dev/lpr or /dev/lpt0 or whater. You shouldn't have
> permission.
>
> Instead, as was suggested earlier, use the "lpr" command and send it
> the text/data on standard input. Any reasonably managed Unix system
> should be able to handle a fair range of graphics formats, though
> postscript is preferred.
>
>  --
> Mike Meyer <[EMAIL PROTECTED]>
> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more
> information.

I've been using:

p=os.popen('lp','w')
p.write("some text')
p.Close()


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


Re: passing arguments

2005-05-20 Thread Jeff Elkins
On Friday 20 May 2005 06:46 pm, James Stroud wrote:
> import sys
>
> try:
>   arg1 = sys.argv[1]
> except IndexError:
>   print "This script takes an argument, you boob!"
>   sys.exit(1)
>
> OR, way better: See the optparse module.
>
> On Friday 20 May 2005 03:26 pm, Jeff Elkins wrote:
> > I'm sure this is obvious, but how the heck do pass an argument(s) to a
> > python script from the command line?
> >
> > Thanks,
> >
> > Jeff Elkins

Thanks!

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


Re: SQL Query via python

2005-05-21 Thread Jeff Elkins
On Saturday 21 May 2005 04:56 am, Heiko Wundram wrote:
> Am Samstag, 21. Mai 2005 06:54 schrieb Sakesun Roykiattisak:
> > Try
> >
> > cursor.execute (
> > """
> >   SELECT name, month, day ,category, city FROM bday
> >   WHERE %s = %s
> > """
> >   %(arg1,arg2))
>
> *argh* You don't do any quoting of SQL-parameters, and that's more than
> bad! (leaves you up to the mercy of SQL-injection attacks, for example)
>
> What you basically want to have is something like the following:
>
> # Make sure arg1 is actually just characters.
> if not arg1.isalpha():
> raise RuntimeError, "trying to do SQL-injection attack?!"
>
> # Now do query.
> cursor.execute("""
> SELECT name, month, day, category, city FROM body
> WHERE %s = %%s
> """ % (arg1,),
> (arg2,))
>
> See how I didn't just use arg1 to paste it in the query string, but checked
> it before trying the query to consist only of characters. You'd have to
> adjust this accordingly for field-names you use (maybe you use underscores,
> etc.). But, be sure that arg1 contains no ";"!
>
> HTH!

Hey, I could barely spell SQL yesterday...:)

I really appreciate the pointers!

Jeff




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


Re: SQL Query via python

2005-05-21 Thread Jeff Elkins
On Saturday 21 May 2005 01:32 pm, Dennis Lee Bieber wrote:
> On Fri, 20 May 2005 23:57:01 -0400, Jeff Elkins

>  You have to remember that .execute(), using the (template,
> (arg...)) format, is designed to apply suitable quoting to the
> arguments. It does not parse the SQL to determine if arguments are being
> used as identifiers and not data values.
>
>  The above sample probably generated:
>
> SELECT name, month, day, category, city from bday
> WHERE "month" = 5

This is getting much clearer. Thanks much.

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


Re: SQL Query via python

2005-05-21 Thread Jeff Elkins
Just as an fyi:

In one weekend I have gone from knowing zip about SQL/Python to implementing 
code on my personal server that emails info to family about birthdays and 
such. I know I could have installed other *nix programs that would do the 
same thing, but so what :)

Thanks so much to the folks on this list who took the trouble to reply. I hope 
I can pay it forward in the future.

Jeff Elkins

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


xml processing

2005-06-01 Thread Jeff Elkins
I've like to use python to maintain a small addressbook which lives on a Sharp 
Zaurus. This list will never grow beyond 200 or so entries. I've installed 
pyxml.

Speaking generally, given a wxpython app to do data entry, 
I'm planning to:

1. parse the addressbook file, loading its data into an array.
2. Perform any edit operations within the array.
3. Write out a finished xml file from the array when I'm done.

Is this reasonable? Better, smarter ways to accomplish this?

Thanks for any advice.

Jeff Elkins





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


Re: xml processing

2005-06-01 Thread Jeff Elkins
On Wednesday 01 June 2005 09:51 am, Magnus Lycka wrote:
> Jeff Elkins wrote:
> > I've like to use python to maintain a small addressbook which lives on a
> > Sharp Zaurus. This list will never grow beyond 200 or so entries. I've
> > installed pyxml.
> >
> > Speaking generally, given a wxpython app to do data entry,
> > I'm planning to:
> >
> > 1. parse the addressbook file, loading its data into an array.
> > 2. Perform any edit operations within the array.
> > 3. Write out a finished xml file from the array when I'm done.
> >
> > Is this reasonable? Better, smarter ways to accomplish this?
>
> Why XML?
>
> I guess the simplest solution whould be to use pickle.

The Zaurus addressbook app depends on an xml datafile, so I'm stuck with that 
format. I just want to to maintenence and data entry on the PC for ease of 
use vs typing on the Zaurus' tiny keyboard. I could just edit the raw xml 
file, then copy it to the Zaurus, but I'd like to have something a little 
spiffier...

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


Re: xml processing

2005-06-02 Thread Jeff Elkins
On Wednesday 01 June 2005 11:01 am, Steven Bethard wrote:

> If you're not committed to pyxml, you might consider using ElementTree:
>
> http://effbot.org/zone/element-index.htm
>
> I find it *way* easier to work with.

Thanks. I've installed it and am experimenting. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Walking through a mysql db

2005-06-04 Thread Jeff Elkins
I'm writing a small wxpython app to display and update a dataset. So far, I 
get the first record for display:

 try:
  cursor = conn.cursor ()
  cursor.execute ("SELECT * FROM dataset")
  item = cursor.fetchone ()

Now, how do I step through the dataset one row at a time?  My form has  'next' 
and 'back' buttons, and I'd like them to step forward or back, fetching the 
appropriate row in the table. I've tried setting cursor.rownumber by 
incrementing it prior to the fetchone() w/o effect.

Thanks for any pointers.

Jeff Elkins






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


Re: Walking through a mysql db

2005-06-04 Thread Jeff Elkins
On Saturday 04 June 2005 09:24 am, Jeff Elkins wrote:
> I'm writing a small wxpython app to display and update a dataset. So far, I
> get the first record for display:
>
>  try:
>   cursor = conn.cursor ()
>   cursor.execute ("SELECT * FROM dataset")
>   item = cursor.fetchone ()
>
> Now, how do I step through the dataset one row at a time?  My form has 
> 'next' and 'back' buttons, and I'd like them to step forward or back,
> fetching the appropriate row in the table. I've tried setting
> cursor.rownumber by incrementing it prior to the fetchone() w/o effect.

Thanks for the responses!  The buttons are working now.

Within this same app, I've got a search function working, but I need the 
rownumber when a record is fetched.

  sql = """select * from address where %s = %%s""" % arg1.lower()
cursor.execute(sql, (arg2,))
 item = cursor.fetchone ()
 index = cursor.rownumber

At this point, the record is on the screen, but cursor.rownumber doesn't 
reflect the actual rownumber...it always returns 1. How can I obtain the 
actual row number for the displayed record?

Jeff


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


Re: Walking through a mysql db

2005-06-04 Thread Jeff Elkins
Thanks for the replies!

I went ahead and used the fetchall() approach and work with the array,  
writing changes back to the database. It's working fine.

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