Pmw problem in cygwin with Tkinter

2006-01-05 Thread Stewart Midwinter
'''
self.mymessage(title, msg,'info')
root.focus_set()
root.update()

if __name__ == '__main__':
if 1:
root = Tk()
Pmw.initialise(root, size = 16, useTkOptionDb = 1)
root.geometry('500x400+100+100')
root.title(Test application)
app = PumpAdmin(root)
app.drawGui()
app.pack(fill = 'both', expand = 1)
root.deiconify()
root.update()
root.mainloop()

---
#test_subprocess2.py

from Tkinter import *

import os, sys
import subprocess

class AppUI(Frame):

def __init__(self, master=None):
Frame.__init__(self, master, relief=SUNKEN, bd=2)

def drawGui(self):
self.drawMenu()
self.drawCanvas()

def drawMenu(self):
self.menubar = Menu(self)
menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label=File, menu=menu)
menu.add_command(label=Exit, command=root.destroy)

menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label=Test, menu=menu)
menu.add_command(label=Dir list, command=self.dir_list)
try:
self.master.config(menu=self.menubar)
except AttributeError:
# master is a toplevel window (Python 1.4/Tkinter 1.63)
self.master.tk.call(master, config, -menu, self.menubar)

def drawCanvas(self):
self.canvas = Canvas(self, bg=white, width=400, height=400,
 bd=0, highlightthickness=0)
self.canvas.pack()

def dir_list(self):
'''provide a listing of files in a directory'''
#need to know which system to draw from
curdir = os.getcwd()
try:
#dirlist = subprocess.Popen('ls -l', shell=False,
bufsize=2048, stdout=subprocess.PIPE).stdout
#dirlist,retcode = subprocess.Popen('ls -l',
stdout=subprocess.PIPE).communicate()
#retcode = subprocess.call('ls -l', shell=False)
p = subprocess.Popen(['ls',' -l'], bufsize=2048,
shell=True, close_fds=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(child_stdin, dirlist, retcode) = (p.stdin, p.stdout, p.stderr)
if retcode  0:
print sys.stderr, Child was terminated by signal, retcode
print 'error'
self.myshowerror(Error,Sorry, couldn't get a
directory listing)
else:
print 'no error'
#print dirlist
msgList = []
for dir in dirlist:
#print dir
msgList.append(dir)
msg = ''.join(msgList)
#print msg
print 'got to 1'
self.myshowinfo(Directory Listing for %s % curdir, msg)
print 'got to 2'
self.drawMenu()
except OSError,e:
print sys.stderr, Execution failed:, e

def mymessage(self, title, msg, msgType='info'):
'''a workalike for the tkMessageBox showinfo since the former
results in invisible text in cygwin'''
top = Toplevel()
top.title(title)
t = Label(top, text='\n%s\n' % msgType.upper())
t.pack()
l = Label(top, text=msg)
l.pack()
b = Button(top,text=Ok, command=top.destroy)
b.pack()

def myshowinfo(self, title='', msg=''):
'''a workalike for the tkMessageBox showinfo since the former
results in invisible text in cygwin'''
self.mymessage(title, msg,'info')
root.focus_set()
root.update()


root = Tk()
app = AppUI(root)
app.drawGui()
app.pack()
root.mainloop()


thanks,
--
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Skype, GoogleTalk, iChatAV, MSN, Yahoo: midtoad
AIM:midtoad1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting from shell script to python

2006-01-05 Thread Stewart Midwinter
Greg Ewing (using news.cis.dfn.de) wrote:
 Alternatively, you can substitute things from a
 dictionary instead of a tuple:

vars = {'ROOTDIR': '/usr/lib'}
CLASSPATH = \
  %{ROOTDIR}s/a/a.jar:%{ROOTDIR}s/b/b.jar:%{ROOTDIR}s/c/c.jar % vars

Arriving late at the party (found this while searching for something else)...

This is a useful construct, but won't work as written. In the
CLASSPATH assignment, you have to use regular brackets around ROOTDIR,
not dictionary-type brackets.

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


subprocess problem in cygwin with Tkinter

2006-01-04 Thread Stewart Midwinter
this has me puzzled; I've created a small test app to show the problem
I'm having.

I want to use subprocess to execute system commands from inside a
Tkinter app running under Cygwin.

When I open a python interpreter and run my subprocess command, all is
well. But when I run the same command from inside a Tkinter app, I'm
getting errors.

I'm using this version of Cygwin:
$ uname -a
CYGWIN_NT-5.1 Mulata 1.5.18(0.132/4/2) 2005-07-02 20:30 i686 unknown unknown Cyg
win

When I run my command in a python shell, all is well:

[EMAIL PROTECTED] /cygdrive/c/programs/pipeworksb/lib/python/popt
$ python
Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type help, copyright, credits or license for more information.
 import subprocess
 dirlist = subprocess.Popen('/usr/bin/ls', shell=True, bufsize=2048, stdout=
subprocess.PIPE).stdout
 dirlist
open file 'fdopen', mode 'rb' at 0x49d848
 for dir in dirlist:
... print dir
...
__init__.pyc
browser.bat
test_subprocess.py
test_subprocess.py.bak



When I run the same command in a Tkinter app, I get an exception:

[EMAIL PROTECTED] /cygdrive/c/programs/pipeworksb/lib/python/popt
$ python test_subprocess.py
d:\cygwin\bin\python2.4.exe (7752): *** unable to remap d:\cygwin\bin\tk84.dll t
o same address as parent(0x18C4) != 0x18C5
  9 [main] python 4696 fork_parent: child 7752 died waiting for dll loading
Traceback (most recent call last):
  File test_subprocess.py, line 19, in ?
l = Tkinter.Label(text=dir_list())
  File test_subprocess.py, line 8, in dir_list
dirlist = subprocess.Popen('/usr/bin/ls', shell=True, bufsize=2048, stdout=s
ubprocess.PIPE).stdout
  File /usr/lib/python2.4/subprocess.py, line 558, in __init__
errread, errwrite)
  File /usr/lib/python2.4/subprocess.py, line 918, in _execute_child
self.pid = os.fork()
OSError: [Errno 2] No such file or directory


Here's a sample Tkinter app that reproduces the problem:

#test_subprocess.py
import subprocess, os
import Tkinter

def dir_list():
'''provide a listing of files in a directory'''
#need to know which system to draw from
curdir = os.getcwd()
dirlist = subprocess.Popen('/usr/bin/ls', shell=True,
bufsize=2048, stdout=subprocess.PIPE).stdout
#dirlist = subprocess.Popen(['ls',' -l'],
stdout=subprocess.PIPE).stdout.communicate()[0]
print dirlist
msgList = []
for dir in dirlist:
print dir
msgList.append(dir)
msg = '\n'.join(msgList)
return msg

root = Tkinter.Tk()
l = Tkinter.Label(text=dir_list())
l.pack()
b = Tkinter.Button(text='ok',command=root.destroy)
b.pack()
root.mainloop()


BTW, the test_subprocess.py test script that ships with Cygwin python runs fine.

any ideas?
thanks,
--
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Skype, GoogleTalk, iChatAV, MSN, Yahoo: midtoad
AIM:midtoad1
-- 
http://mail.python.org/mailman/listinfo/python-list


Popularity of blogging tools used by python programmers

2005-10-20 Thread Stewart Midwinter
I've made a comparison of the relative popularity of blogging tools
used by python programmers.  I was surprised by the number of python
developers not using python for their blogs; isn't that like GM
employees driving Toyota cars?

See my post at:

http://midtoad.homelinux.org/wp/?p=117

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


suggestion for Python graphing package, please

2005-08-29 Thread Stewart Midwinter
I need a graphing library that I can access from within a Tkinter application running on Windows.

It needs to be able to draw some *simple* 2D plots, and then output
them to a file (e.g. .PNG, .JPG) for inclusion in a HTML-formatted
e-mail to interested parties. 

Many of the packages that I've looked at a) either don't output to a
file, or b) are very old (3-5 years), or c) don't run on Windows.

I don't actually care if the library itself is written in Python or c++ or something else.
Any suggestions?

thanks,-- Stewart Midwinter[EMAIL PROTECTED][EMAIL PROTECTED]Skype:midtoadGoogleTalk:midtoadiChatAV:midtoad
MSN:midtoadYahoo:midtoadAIM:midtoad1
-- 
http://mail.python.org/mailman/listinfo/python-list

how to calc the difference between two datetimes?

2005-05-08 Thread Stewart Midwinter
After an hour of research, I'm more confused than ever. I don't know
if I should use the time module, or the eGenix datetime module. Here's
what I want to do:  I want to calculate the time difference (in
seconds would be okay, or minutes), between two date-time strings.

so: something like this:
time0 = 2005-05-06 23:03:44
time1 = 2005-05-07 03:03:44

timedelta = someFunction(time0,time1)
print 'time difference is %s seconds' % timedelta.

Which function should I use?

confusedly yours,
-- 
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Skype: midtoad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to calc the difference between two datetimes?

2005-05-08 Thread Stewart Midwinter
thanks Robert, those 4 lines of code sure beat the 58 of my
home-rolled time-date function!

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


App suggestion please: blog / forum software in Python

2005-04-26 Thread Stewart Midwinter
I'm starting up a new website for a small community of local sports
enthusiasts.  I want to be able to create pages of information easily
(i.e. a content management system), but also allow for discussion on
multiple topics (i.e. a forum). Numerous people should be able to log
in and create or update content, under the guidance of an admin
naturally.

Call me perverse, but I don't want to use phpBB for the forum.  I'm
not seeing anything available in Python though - except for Karrigell.
is that the only option, or am I missing something?

For the blog / CMS portion, I'm looking for something lightweight,
i.e. not Plone or Zope. I've looked at them before and they're total
overkill outside of an enterprise.Have any other suggestions?

I'm using CherryPy for a web application I'm building; it occurs to me
it could be used to build a discussion forum, but maybe someone's
already done that?

I currently use mySQL with CherryPy, but I'll add another db if necessary.

cheers,
-- 
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Skype: midtoad
--
http://mail.python.org/mailman/listinfo/python-list


Web application toolkit recommendation?

2005-04-04 Thread Stewart Midwinter
hi all:

I'm a python user in my day job. Now I want to take on a personal pet
project which will involve the creation of a website on my home
server.  I'll want to keep track of users through user accounts and
logins, allow them to upload information to a database (maybe mySQL or
SqLite), and in the future allow upload of GPS tracklogs and
subsequent presentation of those tracklogs on a graphical map image).

I can do all of the above today with the Leonardo project on SF, but
it's written in PHP, in which I am a relative neophyte, though I use
it to drive my own dynamic website using a mySQL database. (see
http://midtoad.homelinux.org/midwinter.ca/Poetry/index.php).

I would like to take a stab at doing this in Python instead of PHP,
but I'd like to hear from people who are familiar with both, or who
have a good understanding of web application toolkits in Python. 
Which is likely to be the least painful route?

I'm already using Snakelets for a private internet blog, and would use
this if there were a database access module available.

I don't want to hear anything about Zope - it's way too complex for my
needs or desires. Other than that, fire away!

thanks, 
-- 
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Skype: midtoad
-- 
http://mail.python.org/mailman/listinfo/python-list


Python modules for image / map manipulation?

2005-04-04 Thread Stewart Midwinter
I would like to do some image / map manipulation with Python. 

I've got a very large map file in .png format. My thought is to chop
it up into small tiles using some method.  What Python module would be
helpful for this?

Next, when I obtain the start and end co-ordinates of a user's trip,
I'd like to stitch together the approriate tiles and present the
images that show the terrain the user has travelled over.

Lastly, I'd like to plot the GPS tracklog of the trip on top of the map. 

Any suggestions for modules or projects to help accomplish this?  It's
a non-commercial hobby application.

thanks, 
-- 
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Skype: midtoad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Little Q: how to print a variable's name, not its value?

2005-03-30 Thread Stewart Midwinter
thanks Aaron, I'll pick what's behind door no. 1 !
That is, I liked your first solution.  Having said that, I would only
have to place either solution once in my code, then I could call it
again and again.  So either one would be just as 'light' in actual
usage.

Taking this idea a little further, I'd like to build a 'variable
inspector' for my GUI app, so that I don't have to resort to debug
statements.  Instead, I could pop open a window that lists every
variable that has an expected None, string, int or float value, and
select any one in order to see its value at that time.  I believe your
method would be useful in that situation as well, no?

cheers,
-- 
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Skype: midtoad
-- 
http://mail.python.org/mailman/listinfo/python-list


Can a method in one class change an object in another class?

2005-03-05 Thread Stewart Midwinter
I've got an app that creates an object in its main class (it also
creates a GUI).  My problem is that I need to pass this object, a
list, to a dialog that is implemented as a second class. I want to
edit the contents of that list and then pass back the results to the
first class.   So my question is, can a method in one class change an
object in another class?

If the answer is no, I suppose I could pass in the list as an argument
when I create the second class, then return the contents of the list
when I end the methods in that second class.

alternatively, I could make the list a global variable, then it would
be available to all classes.  I have a nagging feeling though that
global variables are to be avoided on general principle. Is this
correct?

Here's a simple example app that tries to have one class change the
object in another class.  It doesn't give the behaviour I want,
though.

---
#objtest.py

class first:
def __init__(self):
a = 'a'
self.a = a
print self.a

def update(self):
print 'initially, a is', self.a
self.a = second(self.a)
print 'afterwards, a is', self.a

class second:
def __init__(self, a):
pass

def __call__(self, a):
a = 'aa'
return a

if __name__ == '__main__':
app = first()
app.update()

thanks,
--
Stewart Midwinter
[EMAIL PROTECTED]
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list