Re: [Tutor] Help with Tkinter teachers' report program?

2005-06-25 Thread Adam Cripps
On 6/25/05, Michael P. Reilly <[EMAIL PROTECTED]> wrote:
> On 6/24/05, Adam Cripps <[EMAIL PROTECTED]> wrote:
> > On 6/24/05, Michael P. Reilly <[EMAIL PROTECTED]> wrote:
> > > On 6/24/05, Adam Cripps <[EMAIL PROTECTED]> wrote:
> > > > I hadn't thought about a scrollbar - that would be very useful, 
> > > > although doesn't add to the management side of the statement (i.e.
> > > > organising them according to subjects).
> > > >
> > > > The user can load a text file and adapt that - so they don't have to 
> > > > enter them by hand if they have them in a .txt file. Typing them in by
> > > > hand once is better than typing them in by hand for every child that
> > > > you have in your class, which is the whole aim of the software. 
> > > >
> > >
> > >  I could try to whip up an example a little later if you like.  I
> probably
> > > wouldn't be large, but it could demonstrate tabbed frames with
> scrolling.
> > >
> > >   -Arcege
> > > -- 
> > 
> > Michael,
> > 
> > That would be much appreciated.
> > 
> > Thanks
> > Adam
> > 
> 
>  Here you go, Adam.  It's not full and complete, but it's working and you
> can customize it how you like.
>   -Michael

Many thanks Michael, just studying it now. 

Adam

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


Re: [Tutor] fileinput problem

2005-06-25 Thread Kent Johnson
Kevin Reeder wrote:
> I'm getting unexpected behaviour from this module. My script is
> meant to count the number of occurences of a term in one or more
> files.
> 
> ---
> 
> import sys, string, fileinput
> 
> searchterm, sys.argv[1:] = sys.argv[1], sys.argv[2:]
> 
> for line in fileinput.input():
>   num_matches = string.count(line, searchterm)
>   if num_matches:
>   print "found '%s' %i times in %s on line %i." % (searchterm,
>   num_matches, fileinput.filename(), 
> fileinput.filelineno())
> 
> ---
> 
> When I run at the command line, this error message appears:
> 
> $ python ./Python/fileinput.py for ./Python/*.py
> 
> Traceback (most recent call last):
>   File "./Python/fileinput.py", line 1, in ?
> import sys, string, fileinput
>   File "./Python/fileinput.py", line 6, in ?
> for line in fileinput.input():
> AttributeError: 'module' object has no attribute 'input'
> 
> ---
> 
> I'm stumped. Any ideas?

You named your program fileinput.py, so when you import fileinput you are 
getting your own program again instead of the library module. Change the name 
of your program and try again.

Kent

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


Re: [Tutor] fileinput problem

2005-06-25 Thread Alan G
> Traceback (most recent call last):
>   File "./Python/fileinput.py", line 1, in ?
> import sys, string, fileinput

You are importing fileinput from a file called fileinput.
It therefore reads your file and notices that you have 
no input method...

Don't call your program the same name as the module!

HTH,

Alan G.

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


Re: [Tutor] fileinput problem

2005-06-25 Thread Kevin Reeder
On Sat, 25 Jun 2005 06:41:01 -0400
Kent Johnson <[EMAIL PROTECTED]> wrote:

> You named your program fileinput.py, so when you import fileinput
> you are getting your own program again instead of the library
> module. Change the name of your program and try again.

Doh! I do remember reading that somewhere before. Lesson learnt.

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


[Tutor] MineSweeper

2005-06-25 Thread Alberto Troiano
Hey Tutors
I have a question
I want to make a minesweeper (just for practice) but I don't what can I use 
to make the GUI
I was thinking about buttons (click event you know) and change the 
background image on change
Maybe there's another widget to use
My doubt is that I want to be able to allow the user to put how many bombs 
they want and how any spaces (how big is the board) so I will have to create 
buttons dinamically, but in doing this the reference to the buttons will be 
lost
How do I know which button did I click when all buttons have the same name?
Does this make sense?
I recall in VB.6.0 the control matrix but I never knew how to use it

Any help?

Thanks in advanced

Alberto


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


Re: [Tutor] MineSweeper

2005-06-25 Thread Adam Cripps
On 6/25/05, Alberto Troiano <[EMAIL PROTECTED]> wrote:
> Hey Tutors
> I have a question
> I want to make a minesweeper (just for practice) but I don't what can I use
> to make the GUI
> I was thinking about buttons (click event you know) and change the
> background image on change
> Maybe there's another widget to use
> My doubt is that I want to be able to allow the user to put how many bombs
> they want and how any spaces (how big is the board) so I will have to create
> buttons dinamically, but in doing this the reference to the buttons will be
> lost
> How do I know which button did I click when all buttons have the same name?
> Does this make sense?
> I recall in VB.6.0 the control matrix but I never knew how to use it
> 
> Any help?
> 
> Thanks in advanced
> 
> Alberto

I have written some similar code to this - you give each button a
different name through an interator.

You can see my code at:

http://www.sf.net/projects/jiletters and follow the links to the CVS
code repository.

For that, I used wxPython, but it's up to you what you go for. 

The main part that may be useful to you is:

for i in noduplicatesalphabet:
identity = int(D[i]) + 29 # It's quicker to add 29 than go
through and edit the dictionary by hand
bmp = wxBitmap('alphabet_graphics/' + i + '.bmp', wxBITMAP_TYPE_BMP)
self.grafic =wxBitmapButton(self,
identity,bmp,wxPoint(160,20),
wxSize(bmp.GetWidth()+10,bmp.GetHeight()+10))
self.sizer2.Add(self.grafic,1,wxEXPAND)
EVT_BUTTON(self, identity, self.ButtonPushed)

The noduplicates is a list that I generated by hand, but you could do
this in a range(a,b) way if it's not attached to any particular data
or meaning.

The EVT_BUTTON passes the id to the function self.ButtonPushed, which
then can tell which button was pushed.

HTH
Adam


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


[Tutor] wxPython shaped window

2005-06-25 Thread Adam Bark
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
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxPython shaped window

2005-06-25 Thread Adam Cripps
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
-- 
http://www.monkeez.org
PGP key: 0x7111B833
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxPython shaped window

2005-06-25 Thread Adam Bark
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 usebutton.SetSize(button.GetBestSize())HTHAdam--http://www.monkeez.orgPGP key: 0x7111B833

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


Re: [Tutor] MineSweeper

2005-06-25 Thread Danny Yoo


On Sat, 25 Jun 2005, Alberto Troiano wrote:

> My doubt is that I want to be able to allow the user to put how many
> bombs they want and how any spaces (how big is the board) so I will have
> to create buttons dinamically, but in doing this the reference to the
> buttons will be lost How do I know which button did I click when all
> buttons have the same name? Does this make sense?


Hi Alberto,

[The following is a tutorial about using functions as values; it's a bit
long, so if you have any questions at all, ask!]


In Tkinter, each button can be associated with a "command" that gets
called when we press a button.

### Example One ###
from Tkinter import *

def sayRefrain():
print "... for the rain, it raineth every day"

root = Tk()
button = Button(root, text="hey ho the wind and the rain",
command=sayRefrain)
button.pack()
root.mainloop()
###


Note that when we say that our 'button' should use 'sayRefrain', not
'sayRefrain()'.  We're using a function as a value that the button will
remember.  Just as the button knows what text it should show, it also
knows which function it should call when we press it.



So that's a quick and dirty example of a window with one button.  But
let's say that we have two buttons, now.  How can we distinguish one
button from another button?  We can do this by attaching two separate
commands to the individual buttons:

### Example Two ###
from Tkinter import *
def sayRefrain1():
print "... for the rain, it raineth every day"

def sayRefrain2():
print "... and we'll strive to please you every day"
root = Tk()
button1 = Button(root, text="hey ho the wind and the rain",
command=sayRefrain1)
button2 = Button(root, text="hey ho the wind and the rain",
command=sayRefrain2)
button1.pack()
button2.pack()
root.mainloop()
##

Ok, now we have two buttons in our example.  We can distinguish between
buttons by associating different commands to them: they have the same
text, but they do different things.



By the way, just to make sure this point is clear: we're just passing the
function values of sayRefrain1 and sayRefrain2 instead of calling them
directly.  If we just ask Python what the value of sayRefrain1 is:

###
>>> sayRefrain1

###

it's just a value, just as:

###
>>> "hey ho the wind and the rain"
'hey ho the wind and the rain'
###

is just a value, just like the familiar numbers and strings that you've
been using before.

Function values are a little special in one regard:  they do things if we
put parens after them, as you know:

###
>>> sayRefrain2()
... and we'll strive to please you every day
###

but being able to call a function value is pretty much all that
distinguish a function value from other Python values.



Ok, let's get back to our examples.  We went from an example with one
button, to an example with two.  I think you can guess where we're about
to go.  *grin*

Now let's say that we have a few more buttons that we'd like to use.  We
know what we'd like each button should say:

###
buttonMessages = ["When that I was and a little tiny boy,",
  "But when I came to main's estate,",
  "But when I came alas to wive,",
  "But when I came unto my beds,"]
###

But let's wait for a moment before plunging forward.  If we go along the
path that our other examples have been going through, it might be a little
tedious to define a separate sayRefrainX for every message in our list.


But we can do a little better.  Let's try something new:

##
def makeRefrainPrinter(message):
"""Given a message, returns a new function that'll say the message."""
def sayRefrain():
print message
return sayRefrain
##


What does makeRefrainPrinter() do?  Let's try playing with it:

##
>>> makeRefrainPrinter("as I am an honest puck")

##


If we call makeRefrainPrinter(), it gives us back a function value.  Let's
see what happens if we call that function value:

##
>>> someFunctionValue = makeRefrainPrinter("as I am an honest puck")
>>> someFunctionValue()
as I am an honest puck
##

makeRefrainPrinter() makes up function values, on the fly, so that we can
make any kind of sayRefrainX function value with relative ease.



If we have this makeRefrainPrinter function, now our example code can look
like this:

### Example Three ###
from Tkinter import *
buttonMessages = ["When that I was and a little tiny boy,",
  "But when I came to main's estate,",
  "But when I came alas to wive,",
  "But when I came unto my beds,"]

def makeRefrainPrinter(message):
"""Given a message, returns a new function that'll say the message."""
def sayRefrain():
print message
return sayRefrain

root = Tk()
for msg in buttonMessages:
someFunctionValue = makeRefrainPrinter(msg)
button = Button(root,
text="hey, ho,

Re: [Tutor] wxPython shaped window

2005-06-25 Thread Danny Yoo


On Sat, 25 Jun 2005, Adam Bark 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.

Hi Adam,

You might want to ask this on the wxPython-users mailing list:

http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi/11

They're more focused on wxPython GUI stuff than the folks on Tutor, and
they appear pretty active too.


Best of wishes!

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


[Tutor] clob and string conversion

2005-06-25 Thread Ming Xue

Hello, 
 

I am trying to access oracle9i with cx_Oracle package. One of the column is clob and when I tried clob.read() I got non-text output. I know the real data is text. Can somebody show me how to convert clob to string in python?
Thank,
Ming 

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


[Tutor] Alternative File I/O for Tuples

2005-06-25 Thread Don Parris
When I pickle a SQL result into a file (ASCII mode), it lays out the data in
an interesting format.  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.

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
-- 
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] clob and string conversion

2005-06-25 Thread Danny Yoo


On Sat, 25 Jun 2005, Ming Xue wrote:

> I am trying to access oracle9i with cx_Oracle package. One of the column
> is clob and when I tried clob.read() I got non-text output. I know the
> real data is text. Can somebody show me how to convert clob to string in
> python?

Hi Ming,

This seems really specialized to the cx_Oracle database module; you may
want to see if the folks at the Database Special Interest Group (DB-SIG):

http://www.python.org/sigs/db-sig/

because the folks there are probably more aware of some issues one needs
to think about with CLOBs: we at Tutor might not necessary have the
special experience that we need to give you the best help.


I've been looking at the definition of the LOB object interface,

http://starship.python.net/crew/atuining/cx_Oracle/html/lobobj.html

and it does seem like clob.read() should do the trick.  Without seeing
what you're doing, it's very difficult to know what's going on.  Do you
mind showing us an example of the text that you're getting back from the
CLOB, and what you're expecting to see?


You do mention that you're getting something back, but it doesn't look
like text to you... Ok, my best guess so far is that you may be seeing a
text encoding that you're not expecting.  I'll go with that guess until we
know more information.  *grin* If you can show us that example, we'll have
a better basis for testing the hypothesis.


Do you know what text encoding the strings in your database are in?  Are
they in Latin-1, or perhaps in a Unicode format such as UTF-8 or UTF-16?

The reason I ask is because it's not at all obvious from looking at bytes
alone how to interpret them, so it's possible that you may need to
"decode" those bytes by telling Python explicitely what encoding to use.
CLOBs are binary streams, so Python will never impose an interpretation on
those bytes until we tell it to.


For example, if one were to give us the byte string:

##
secret = '\xfe\xff\x00h\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d'
##

then we'd probably be quite unhappy until we also knew that those bytes
represented a string in utf-16 encoding:

##
>>> secret.decode('utf-16')
u'hello world'
##


For a more general introduction to unicode encodings, you may want to look
at Joel Spolsky's amusing article on "The Absolute Minimum Every Software
Developer Absolutely, Postitively Must Know About Unicode and Character
Sets (No Excuses!)":

http://www.joelonsoftware.com/articles/Unicode.html

Python's supported list of encodings are listed here:

http://www.python.org/doc/lib/standard-encodings.html


Best of wishes to you!

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


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

2005-06-25 Thread Danny Yoo


> 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? :)


Hi Don,

Not too bad; I think you'll looking for "String Formatting":

http://www.python.org/doc/lib/typesseq-strings.html

The idea is that we use a template to lay out the rows.  This template
gives the general shape of what we want.

In your example, it looks like every row is ten characters long.  A
template that can lay out two values as two columns might looks something
like this:

##
>>> "%10s%10s" % ("Curious", "George")
'   CuriousGeorge'
##


Oh, it's justified right.  Let me switch that over:

##
>>> "%-10s%-10s" % ("Curious", "George")
'Curious   George'
##

Ok, that's better.  *grin*  So you should be able to generalize this to
build up these nicely formatted lines that can be printed at once.


There are some other sophisticated string-formatting tools in Python, many
of which live in strings themselves.

http://www.python.org/doc/lib/string-methods.html

For example, strings even know how to "center" themselves:

##
>>> 'I am a centered sentence.'.center(40)
'   I am a centered sentence.'
##



If you have more questions, please feel free to ask.

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


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

2005-06-25 Thread Danny Yoo


> 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.

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