Re: [Tutor] wxPython shaped window

2005-06-26 Thread Adam Cripps
On 6/25/05, Adam Bark <[EMAIL PROTECTED]> wrote:
> Thanks for the info Adam I just seem to be having a problem with the panel
> size it greys out nearly all the image. Ideally I would like to make the
> panel transparent but I can't work out how to do that.
> 
> 
> On 6/25/05, Adam Cripps <[EMAIL PROTECTED]> wrote: 
> > On 6/25/05, Adam Bark <[EMAIL PROTECTED] > wrote:
> > > Is it possible to put controls into a shaped window in wxPython. I have
> > > tried putting a button on the demo and it becomes the exact size and
> shape
> > > of the window. Also when I tried to bind it to an action it wouldn't
> even 
> > > start.
> > >
> > >  Adam
> > >
> > 
> > I'm working through something similar myself at the moment.
> > 
> > Try adding a wx.Panel to the frame and then the button to the panel.
> > You can position them through pos parameter, but it should default to 
> > the top left of the panel and have a good size if you use
> > button.SetSize(button.GetBestSize())
> > 
> > HTH
> > 
> > Adam

Adam - how much code do you have? Why not post it either here or the
wxpython-users list (to which I'm also subscribed) and we can take a
look.

Adam

-- 
http://www.monkeez.org
PGP key: 0x7111B833
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MineSweeper

2005-06-26 Thread Alan G
> How do I know which button did I click when all buttons have the
same name?

Put them in a matrix.
ie a list of lists. Then refer to them by their position inthe lists
so that the top left button is "buttons[0][0]" etc

This is also how you dynamically create your screen,
just iterate over the list to create and pack/grid/place
each button.

HTH,

Alan G.

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


[Tutor] filtering a webpage for plucking to a Palm

2005-06-26 Thread Brian van den Broek
Hi all,

I have a Palm handheld, and use the excellent (and written in Python) 
Plucker  to spider webpages and format the 
results for viewing on the Palm.

One site I 'pluck' is the Daily Python URL 
. From the point of view of a daily 
custom 'newspaper' everything but the last day or two of URLs is so 
much cruft. (The cruft would be the total history of the last 
seven'ish days, the navigation links for www.pythonware.com, etc.)

Today, I wrote a script to parse the Daily URL, and create a minimal 
local html page including nothing but the last n items, n links, or 
last n days worth of links. (Which is employed is a user option.) 
Then, I pluck that, rather than the actual Daily URL site. Works 
great. :-)  (If anyone on the list is a fellow plucker'er and would be 
interested in my script, I'm happy to share.)

In anticipation of wanting to do the same thing to other sites, I've 
spent a bit of time abstracting it. I've made some real progress. But, 
before I finish up, I've a voice in the back of my head asking if 
maybe I'm re-inventing the wheel.

To my shame, I've not spent very much time at all exploring available 
frameworks and modules for any domain, and almost none for web-related 
tasks. So, does anyone know of any modules or frameworks which would 
make the sort of task I am describing easier?

The difficulty in making my routine general is that pretty much each 
site will need its own code for identifying what counts as a distinct 
item (such as a URL and its description in the Daily URL) and what 
counts as a distinct block of items (such as a days worth of Daily URL 
items). I can't imagine there's a way around that, but if someone else 
has done much of the work in setting up the general structure to be 
tweaked for each site, that'd be good to know. (Doesn't feel like one 
that would be googleable.)

Thanks for any suggestions, and best to all,

Brian vdB

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


Re: [Tutor] Alternative File I/O for Tuples

2005-06-26 Thread Kent Johnson
Don Parris wrote:
> When I pickle a SQL result into a file (ASCII mode), it lays out the data in
> an interesting format.  

pickle format is not intended for pretty-printing or readability for that 
matter. You have to write the file yourself in the format you want.

> When I send it to the printer, I'd like to see it
> arranged more like it is on the console screen - in tabbed columns.  None of
> the tutorial type stuff I've seen even mentions printing files, or accessing
> the files you create in a Python program.  I did manage to find an example
> of a print function.

It sounds like you want to write a file for later printing. Writing files 
should be covered in any Python tutorial; the standard tutorial talks about it 
here:
http://docs.python.org/tut/node9.html#SECTION00920

Danny has given you some hints about how to do the formatting. This recipe has 
a very complete solution for formatting tables. You could easily change the 
example to print to a file:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662

Kent

> 
> Here is some sample data from the resulting file:
> 
> ((S'Everybody'
> S'Anonymous'
> Nt(S'James'
> S'Austin'
> S'704-111-1234'
> t(S'Janet'
> S'Austin'
> S'704-111-1234'
> 
> I would like to see something more like when the file is printed:
> 
> AustinJames704-111-1234
> AustinJanet704-111-1234
> etc.
> 
> Is this a simple task, or am I jumping into deep water? :)
> 
> Don

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


Re: [Tutor] filtering a webpage for plucking to a Palm

2005-06-26 Thread Kent Johnson
Brian van den Broek wrote:
> Hi all,
> 
> I have a Palm handheld, and use the excellent (and written in Python) 
> Plucker  to spider webpages and format the 
> results for viewing on the Palm.
> 
> One site I 'pluck' is the Daily Python URL 
> . From the point of view of a daily 
> custom 'newspaper' everything but the last day or two of URLs is so 
> much cruft. (The cruft would be the total history of the last 
> seven'ish days, the navigation links for www.pythonware.com, etc.)
> 
> Today, I wrote a script to parse the Daily URL, and create a minimal 
> local html page including nothing but the last n items, n links, or 
> last n days worth of links. (Which is employed is a user option.) 
> Then, I pluck that, rather than the actual Daily URL site. Works 
> great. :-)  (If anyone on the list is a fellow plucker'er and would be 
> interested in my script, I'm happy to share.)
> 
> In anticipation of wanting to do the same thing to other sites, I've 
> spent a bit of time abstracting it. I've made some real progress. But, 
> before I finish up, I've a voice in the back of my head asking if 
> maybe I'm re-inventing the wheel.
> 
> To my shame, I've not spent very much time at all exploring available 
> frameworks and modules for any domain, and almost none for web-related 
> tasks. So, does anyone know of any modules or frameworks which would 
> make the sort of task I am describing easier?
> 
> The difficulty in making my routine general is that pretty much each 
> site will need its own code for identifying what counts as a distinct 
> item (such as a URL and its description in the Daily URL) and what 
> counts as a distinct block of items (such as a days worth of Daily URL 
> items). I can't imagine there's a way around that, but if someone else 
> has done much of the work in setting up the general structure to be 
> tweaked for each site, that'd be good to know. (Doesn't feel like one 
> that would be googleable.)

Beautiful Soup can help with parsing and accessing the web page. You could 
certainly write your plucker on top of it.
http://www.crummy.com/software/BeautifulSoup/

Alternately ElementTidy might help. It can parse web pages and it has limited 
XPath support. XPath might be a good language for expressing your plucking 
rules.
http://effbot.org/zone/element-tidylib.htm

An ideal package would be one that parses real-world HTML and has full XPath 
support, but I don't know of such a thing...maybe amara or lxml?

Kent

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


Re: [Tutor] Alternative File I/O for Tuples

2005-06-26 Thread Alan G
> arranged more like it is on the console screen - in tabbed columns.
None of
> the tutorial type stuff I've seen even mentions printing files,

One reason is that printing is one of those things that
is different on evry operating system. So tutorials
(including mine) tend to steer clear of it.

If you are on Unix its fairly easy to print stuff just by
piping stdout to the lpr or pr commands. On Windows I
tend to print by creating an HTML file and then using
os.system() to print the file using my browser...

On Mac tyou can use the Unix trick or convert to PDF.

To do proper formatted printing on windows is inordinately
difficult and involves effectively printing your page as
a graphic to a printer "device context". I seem to recall
someone pointing out a printer module which I meant to
investigate but never got round to it, maybe trawling the
archives would throw it up.

> Here is some sample data from the resulting file:
>
> ((S'Everybody'
> S'Anonymous'
> Nt(S'James'
> S'Austin'
> S'704-111-1234'
> t(S'Janet'
> S'Austin'
> S'704-111-1234'
>
> I would like to see something more like when the file is printed:
>
> AustinJames704-111-1234
> AustinJanet704-111-1234
> etc.

This is to do with formatting the data into strings before
you print it. You can use a format string to define the
layout(column widths, justification, number of decimal places etc)
andthen send those lines to the printer as described above.
If using the HTML trick you need to add the HTML codes too,
in this case you would format each row like:

fmt = "%10s%10s%3d-%3d-%4d"

And then print a table header followed by a loop printing
each line of data followed by a close table tag, something
like this:

text = '''


LastFirstPhone'''

for data in people:   #substitute your data here
  text += fmt % (data[0],data[1],data[2],data[3],data[4])

text += ''

prtfile = open('temp.html','w')
prtfile.write(text)
prtfile.close()

os.system('lynx -p ./temp.html')

> Is this a simple task, or am I jumping into deep water? :)
> evangelinuxGNU Evangelist

Given your signature its probably not too difficult,
you can just send the basic text string to lpr, or use the
html trick above.

You might even like to investigate the use of groff to
format the text instead of html - that's much nicer and
the technique I actually use on Unix.

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

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


[Tutor] Windows user variable ?

2005-06-26 Thread Dave S
Hi there,

Probably no one will remember but I had a problem porting a python
script to windows, I had a 'no such file error'

Turned out that I called the file 'memo.txt', Windows decided it was a
text file and it ended up as 'memo.txt.txt'. The windows display strips
anything after the '.', found the problem via dos :)

Anyhow - When logged into 2000 as an administrator or user is there a
system variable that I can read to let the script know who I am logged
in as ?

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


Re: [Tutor] Alternative File I/O for Tuples (fwd)

2005-06-26 Thread Danny Yoo


-- Forwarded message --
Date: Sun, 26 Jun 2005 14:29:22 -0400
From: Don Parris <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Alternative File I/O for Tuples

On Sat, 25 Jun 2005 22:52:08 -0700 (PDT)
Danny Yoo <[EMAIL PROTECTED]> wrote:

>
>
> > In your example, it looks like every row is ten characters long.  A
>^^^
> Hi Don,
>
> Gaa, that's why I'm so bad at matrix math.  I meant "column", not "row".
> Sorry about that.


I guess I should have used a different example - some names are longer than
others.  Williams is shorter than Vandenbosch, for example.  So the columns
will need to be formatted appropriately.  I'll play with this a bit.  I
should also have said that I need to work primarily with GNU/Linux -
printing with Windows can come a little later.


Kent is kind of on track.  I let the user view the report on the console
screen (nice to verify what you're about to print), and then give them the
choice of printing it, or returning to the menu for other tasks.  For
instance, they may simply want to look up a number, not print out the phone
list.

### Print or Return to Menu ###
if whatNext == 'p':
os.system("lpr mbrPhone.txt")# prints the pickled file.
elif whatNext == 'r':
pass# BTW, is this a good use of "pass"?

The screen print out is as it should be - nice, neat columns.  So, instead
of this:

print 'Phone List'
for record in Results:
print '%s\t%s\t%s' % record# prints to screen
mbrPhone = open('mbrPhone.txt', 'w')
cPickle.dump(Results, mbrPhone)# pickles the data into a file
mbrPhone.close()


I tried this:
mbrPhone = open('mbrPhone.txt', 'w')
mbrPhone.writelines(repr(Results))
mbrPhone.close()



Which produces this in the text file:
(('Everybody', 'Anonymous', None), ('James', 'Austin', '704-111-1234'),
('Janet', 'Austin', '704-111-1234'), ('James', 'Austin', '704-111-1234'),

This is an improvement over pickling the data into a file.  Still, it's not
quite the columnar layout I'd like to achieve.  I'll try that recipe that
was suggested to see if I can get it working with files.  If it's the one
I'm thinking of, it offers a fantastic layout ('bout as good as it gets with
ASCII text) for printing out to screen.

I guess I'm asking two closely-related questions:
(1) how to format the file so it can be readable, and
(2) how to send that file to the printer.  I used os.system('lpr, filename')
above.  Is there another way?


Don
-- 
evangelinuxGNU Evangelist
http://matheteuo.org/   http://chaddb.sourceforge.net/
"Free software is like God's love - you can share it with anyone anytime
anywhere."

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


Re: [Tutor] Alternative File I/O for Tuples (fwd)

2005-06-26 Thread Kent Johnson
> From: Don Parris <[EMAIL PROTECTED]>
> To: Danny Yoo <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Alternative File I/O for Tuples
> 
> I guess I'm asking two closely-related questions:
> (1) how to format the file so it can be readable, and

If you like the recipe I posted, this could be as simple as 
mbrPhone = open('mbrPhone.txt', 'w')
mbrPhone.write(indent(...appropriate args to indent...))
mbrPhone.close()

Kent

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


[Tutor] Improving printouts from IDLE

2005-06-26 Thread Richard Dybowski
The printing facility provided with IDLE is rather rudimentary. Is there 
any way of obtaining better quality printouts from IDLE?

Richard

---
Dr Richard Dybowski
143 Village Way
Pinner HA5 5AA, UK
Tel: 07976 250092 

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


Re: [Tutor] Windows user variable ?

2005-06-26 Thread jfouhy
Quoting Dave S <[EMAIL PROTECTED]>:

> Turned out that I called the file 'memo.txt', Windows decided it was a
> text file and it ended up as 'memo.txt.txt'. The windows display strips
> anything after the '.', found the problem via dos :)

I recomment going to Windows Explorer -> Folder Options and unchecking the "Hide
extensions for known file types" option :-)
 
> Anyhow - When logged into 2000 as an administrator or user is there a
> system variable that I can read to let the script know who I am logged
> in as ?

If you have the win32 extensions, try win32api.GetUserName().

-- 
John.


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