[Tutor] Aug 1 & 16- Global VOIP Free SW HW Culture meeting, BerkeleyTIP, For Forwarding

2009-08-01 Thread john_re
Interested in joining the friendly global Free SW HW & Culture communities in a 
global Voice meeting?  You´re invited. :)

You can join from your home, or better: get a local meeting together. Tip: a 
college WiFi cafe could be a great local meeting place.  Make sure you have a 
VOIP headset!

For all details, see the website (I´m leaving out many sublinks to make this 
email smaller).
http://sites.google.com/site/berkeleytip

Start by joining #berkeleytip on IRC freenode.net.  We´ll help you get your 
VOIP connection working. :)

=  MARK YOUR CALENDARS: 1st Sat & 3rd Sunday each month. August 1 & 16.
10A - 6P Pacific US time (+7H GMT, IIRC)
= 1P-9P Eastern US time = 5P - 1A GMT ?

Or, come to the local meeting on the UC Berkeley campus.
NOTE: SPECIAL LOCATION AUG 1: SEE BTIP WEBSITE FOR LOCATION,
& RSVP TO ME OR THE BTIP LISTS.

AUG 1 MEETING WILL BE 12N - 3P AT THE BTIP VOIP SERVER LOCATION 
ON THE UCB CAMPUS.  SEE THE WEBSITE FOR ROOM LOCATION.
We´ll hack on the new BTIP Asterisk VOIP server, in its presence.

PLEASE RSVP TO ME (John) OR THE LIST IF YOU WANT TO MEET AT OUR
USUAL LOCATION, THE FREE SPEECH CAFE, 10A-12n, 3-6PM,
(otherwise i might not be there).

=  MEETING TOPICS FOR AUGUST:
1) Whatever _you_ want to work on - Email the BTIPGlobal list & 
let us know what your interests are.
2) Our VOIP conference server, using Asterisk.
3) Planning for year 2.

=  JOIN FOR THE START OF YEAR 2 GLOBAL MEETINGs:
We had a great first year.  We had local attendees from around the San 
Francisco Bay Area & Northern California.  High School, College, Grad Students, 
& working & retired people attended.

>From the US, people joined the meeting (IRC or VOIP) from Hawaii to Virgina, 
>Washington to Michigan to Florida. (+ California & other states.)

Globally, Sweden, Germany, England, Ireland, Iran & India (& maybe others I 
don´t recall right now.) :)

In May Richard Stallman joined the global meeting for Q & A about free SW & HW.

== YEAR 2 FOCUS: COLLEGE LOCAL MEETINGS, & AMERICAS´ ANNOUNCEMENTS.

Two main things I´ll focus on this year:
1) Inviting groups to join at colleges & universities - BTIP is educational.  
My hope: if more students learn about free SW hw & culture, some of them will 
then go on to become _contributors_. :)

2) I´ll try to get monthly announcements out to the biggest LUGs in the 10 
largest countries in the Americas.

== What would _YOU_ like to accomplish this year?  Email the BTIP mail list, 
say ¨hi¨, tell us about your interests, projects & desires.

=  FOR FORWARDING - You are invited to forward this announcement wherever 
you think it might be appreciated.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter

2009-08-01 Thread Robert Johansson
Dear all, I have a problem with Tkinter and swedish letters such as ä (or
'\xe4'). Here’s a small code example that counts the number of occurrences
of the letter ‘a’ is in a string given by the user:

 

from Tkinter import *

 

root=Tk()

 

def callback():

a=textLine.get()

print a.count('a')

 

textLine=Entry(root)

textLine.pack(side=LEFT)

searchButton=Button(root,command=callback,text='Search')

searchButton.pack(side=RIGHT)

 

root.mainloop()

 

This works fine for strings containing all letters in my alphabet. However
if I change it to count ä:s it works only for strings without our special
letters (line 5: print a.count('ä')):

 

in callback

print a.count('ä')

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0:
ordinal not in range(128)

 

The following works fine from command line:

 

'rät'.count('ä')

 

And if I change line 5 to just printing a it works fine to.

 

Anyone who knows how to fix this?

 

Robert

 

 

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


Re: [Tutor] flag to call methods on objects?

2009-08-01 Thread Dave Angel
(You replied off-list, so I'm copying your email, plus my response, to 
the list)


prasad rao wrote:

  >I still see four problems.


Hello Dave.I made modification as suggested by you.


  
You made the first three.  But the problem of zlib.compress() producing 
a string with an embedded (0a) still hasn't been addressed.  And I 
suspect this is your next problem.  If you don't give the whole string 
that zlib.compress() produced to zlib.uncompress(), then it'll fail as 
you saw here.



import mcript



Traceback (most recent call last):
  File "", line 1, in 
import mcript
  File "C:\Python26\mcript.py", line 84, in 
a.main()
  File "C:\Python26\mcript.py", line 65, in main
nl= self.__shorten(self.__undigi(self.__decompress(line.strip(+'\n'
  File "C:\Python26\mcript.py", line 47, in __decompress
astring=zlib.decompress(astring)
 error: Error -5 while decompressing data

on interactive mode it is(decompress())working well.

What should I do to rectifi this error?

I dont know java,know basics of c++

I started to lear python hardly onyear back.

This is my 1st program using classes.

Thanks for your time.



#! usr/bin/env python

import ast,random,os,zlib,string
key=5
class Cripto(object):
def __init__(self,afile):
self.afile=afile
def __digi(self,astring):
y=[]
for x in astring:
y.append(ord(x))
y=str(y)

return y
def __undigi(self,astring):

alist=ast.literal_eval(astring)
y=[]
for x in alist:
y.append(chr(x))
astring=''.join(y)
return astring
def __gen_string(self):
s=''
nl=random.sample(string.ascii_letters,key)
for x in nl:s+=x
return s

def __lengthen(self,astring):
 s=list(astring)
 ns=''
 for x in s:
 ns+=x
 ns+=self.__gen_string()
 return ns
def __shorten(self,astring):

 s=list(astring)
 ns=''
 for x in range(0,len(s),key+1):
 ns+=s[x]
 return ns
def __compress(self,astring):
astring=zlib.compress(astring)
return astring
def __decompress(self,astring):
astring=zlib.decompress(astring)
return astring
def main(self):
sorce=open(self.afile,'r')
data=(sorce.readlines())
dest=open((os.path.split(self.afile)[0]+os.sep+'temp'),'w')
if (data[0]).strip()=='flag1':

ns='flag0\n'
data=data[1:]
for line in data:
   nl=
self.__compress(self.__digi(self.__lengthen(line.strip(+'\n'
   ns+=nl
dest.write(ns)
elif data[0].strip()=='flag0':
ns='flag1\n'
data=data[1:]
for line in data:
nl=
self.__shorten(self.__undigi(self.__decompress(line.strip(+'\n'
ns+=nl
dest.write(ns)
else:
print 'File does not begin with the flag'
sorce.close()
dest.close()
os.remove(os.path.split(self.afile)[0]+os.sep+'temp')
return

sorce.close()
dest.close()

os.remove(self.afile)
os.rename((os.path.split(self.afile)[0]+os.sep+'temp'),self.afile)


#
a=Cripto('C:/pp.txt')
a.main()

  
There are a couple of places where indentation has been broken.  For 
example, in method __shorten(), the for loop body isn't indented.  Are 
you retyping these, or are you using tabs in your source, or is paste 
broken on your system?


What Python version are you using?  It's clear that you're using 
Windows, so you will need to store the encoded file as binary.   
Furthermore, something I didn't spot before is that strip() isn't safe 
on the compressed data.


You said you tested the lower-level functions manually.  But they're not 
correct, so clearly it's past time to put in place some form of test 
harness.


To properly test the code, you'll need to remove most of those 
double-underscores.  And I'd suggest factoring out two methods, encode() 
and decode(), as follows:


   def encode(self, unencoded):
   nl= 
self.__compress(self.digi(self.lengthen(unencoded.strip(+'\n'

   return nl
   def decode(self, encoded):
   nl= 
self.shorten(self.undigi(self.__decompress(encoded.strip(+'\n'

   return nl


I don't have your data file to test with, so I may not get exactly the 
same errors.  In fact, multiple runs with the same data give different 
results.  Sometimes I get bad data, and sometimes an exception like 
yours. Probably that's because of the random string you append in 
lengthen().  But the crash itself is probably caused by the bug I 
described in #4 of my previous message.  zlib.compress() produces binary 
data, and you're assuming leading and trailing whitespace is irrelevant, 
and that there are no embedded 0a codes.


So the first test I wrote was:

def test_lengthen(line):
   xx = a.lengthen(line)
 

Re: [Tutor] Tkinter

2009-08-01 Thread Kent Johnson
On Sat, Aug 1, 2009 at 5:05 AM, Robert
Johansson wrote:
> Dear all, I have a problem with Tkinter and swedish letters such as ä (or
>  '\xe4'). Here’s a small code example that counts the number of occurrences
> of the letter ‘a’ is in a string given by the user:
>
>
>
> from Tkinter import *
>
>
>
> root=Tk()
>
>
>
> def callback():
>
>     a=textLine.get()
>
>     print a.count('a')
>
>
>
> textLine=Entry(root)
>
> textLine.pack(side=LEFT)
>
> searchButton=Button(root,command=callback,text='Search')
>
> searchButton.pack(side=RIGHT)
>
>
>
> root.mainloop()
>
>
>
> This works fine for strings containing all letters in my alphabet. However
> if I change it to count ä:s it works only for strings without our special
> letters (line 5: print a.count('ä')):
>
>
>
> in callback
>
>     print a.count('ä')
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0:
> ordinal not in range(128)

The problem is that when you enter non-ascii characters into the
tkinter text box, it will return a unicode string. The count() method
then needs to convert it's argument from an encoded byte string to  a
unicode string. It does this with the default (ascii) encoder and
fails.

Try passing a unicode string to count() like this:
print a.count(u'ä')

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


[Tutor] [pygame] why does my window not close?

2009-08-01 Thread David
Dear Tutors,

I have written a simple pygame program:


import pygame, sys
pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255,255,255,255])
pygame.draw.circle(screen, [0,255,0], [150,200,], 30, 0)
my_rect = (250, 150, 300, 200)
pygame.draw.rect(screen, [0,0,255], my_rect, 0)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()


I am using Ubuntu Jaunty, Python 2.6.2:

When I try to quit the program (clicking on the windows' [X] button),
nothing happens.
When I press CTRL-C on the Python interpreter, triggering a
KeyboardInterrupt, the windows' content vanishes (turns black), but the
window itself remains and can't be killed except by killing the Python
interpreter from which I started my program.
What is going on? I obviously want the window to disappear once I hit
the [X] button!

Cheers for a hint,

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


[Tutor] Question about the FONT in Tkinter

2009-08-01 Thread Mohannad Mohammad


Hello all,

Kindly refer to the attached photo.
There are two sentences appearing when the user checked two checkbutton, I make 
it as a practice.
ok
I want to change the font of these two sentences. how?


This is the code I use to make this simple application:

from Tkinter import *

class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
self.font = ("tahoma", 10)

def create_widgets(self):
self.lbl1 = Label(self, text = "Choose your favorite movie types")
self.lbl1.grid(row = 0, column = 0, columnspan = 2, sticky = W)

self.lbl2 = Label(self, text = "Select all that apply:")
self.lbl2.grid(row = 1, column = 0, columnspan = 2, sticky = W)

self.likes_drama = BooleanVar()
Checkbutton(self, text = "Drama", variable = self.likes_drama, command 
= self.update_text).grid(row = 2, column = 0, sticky = W)

self.likes_comedy = BooleanVar()
Checkbutton(self, text = "Comedy", variable = self.likes_comedy, 
command = self.update_text).grid(row = 3, column = 0, sticky = W)

self.likes_sport = BooleanVar()
Checkbutton(self, text = "Sport", variable = self.likes_sport, command 
= self.update_text).grid(row = 4, column = 0, sticky = W)

self.box = Text(self, width = 400, height = 10, wrap = WORD)
self.box.grid(row = 5, column = 0, columnspan = 2, sticky = W)

def update_text(self):
likes = ""

if self.likes_drama.get():
likes += "You like Drama movies\n"
if self.likes_comedy.get():
likes += "You like Comedy movies\n"
if self.likes_sport.get():
likes += "You like Sport movies\n"

self.box.delete(0.0, END)
self.box.insert(0.0, likes)

win = Tk()
win.title("Choose any one..")
win.geometry("400x300")
app = Application(win)
win.mainloop()



_
Celebrate a decade of Messenger with free winks, emoticons, display pics, and 
more.
http://clk.atdmt.com/UKM/go/157562755/direct/01/<>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor