HTMLParser can't read japanese

2010-04-13 Thread Dodo

Here's a small script to generate again the error
running windows 7 with python 3.1

FILE : parseShift.py

import urllib.request as url
from html.parser import HTMLParser

class myParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print("Start of %s tag : %s" % (tag, attrs))


test = myParser()   
handle = url.urlretrieve("http://localhost/shift.html";)
handleTemp = open( handle[0] , encoding="Shift-JIS" )
test.feed( handleTemp.read() )
handleTempl.close()

FILE : shift.html (encoded Shift-JIS)

Some 
random japanese
東方プロジェクト Link


OUTPUT

Start of p tag : [('class', 'thisisclass (not_in_japanese) 
reading_this_should_be_ok')]

Start of p tag : []
Start of strong tag : []
Traceback (most recent call last):
  File "D:\Dorian\Python\parseShift.py", line 12, in 
test.feed( handleTemp.read() )
  File "C:\Python31\lib\html\parser.py", line 108, in feed
self.goahead(0)
  File "C:\Python31\lib\html\parser.py", line 148, in goahead
k = self.parse_starttag(i)
  File "C:\Python31\lib\html\parser.py", line 268, in parse_starttag
self.handle_starttag(tag, attrs)
  File "D:\Dorian\Python\parseShift.py", line 6, in handle_starttag
print("Start of %s tag : %s" % (tag, attrs))
  File "C:\Python31\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 
44-52: c

haracter maps to 


any help?
Dorian
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser can't read japanese

2010-04-13 Thread Dodo

alright, it's just because of Windows cmd
in IDLE it works fine

any workaround?

Dorian

Le 13/04/2010 13:40, Dodo a écrit :

Here's a small script to generate again the error
running windows 7 with python 3.1

FILE : parseShift.py

import urllib.request as url
from html.parser import HTMLParser

class myParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print("Start of %s tag : %s" % (tag, attrs))


test = myParser()
handle = url.urlretrieve("http://localhost/shift.html";)
handleTemp = open( handle[0] , encoding="Shift-JIS" )
test.feed( handleTemp.read() )
handleTempl.close()

FILE : shift.html (encoded Shift-JIS)

Some
random japanese
東方プロジェクト Link

OUTPUT

Start of p tag : [('class', 'thisisclass (not_in_japanese)
reading_this_should_be_ok')]
Start of p tag : []
Start of strong tag : []
Traceback (most recent call last):
File "D:\Dorian\Python\parseShift.py", line 12, in 
test.feed( handleTemp.read() )
File "C:\Python31\lib\html\parser.py", line 108, in feed
self.goahead(0)
File "C:\Python31\lib\html\parser.py", line 148, in goahead
k = self.parse_starttag(i)
File "C:\Python31\lib\html\parser.py", line 268, in parse_starttag
self.handle_starttag(tag, attrs)
File "D:\Dorian\Python\parseShift.py", line 6, in handle_starttag
print("Start of %s tag : %s" % (tag, attrs))
File "C:\Python31\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position
44-52: c
haracter maps to 


any help?
Dorian


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


Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread Dodo

Hello,

I don't understand why this won't execute


import urllib.request as u
import socket
socket.setdefaulttimeout(10)

l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; # 
supposed to timeout

try:
h = u.urlretrieve(l)
except u.URLError, e: # I tried u.e too, no effect.
print(e)
except:
print("other error")

The error :

...\Python>err.py
  File "...\err.py", line 8
except u.URLError, e: # I tried u.e too, no effect.
 ^
SyntaxError: invalid syntax


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


Re: Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread Dodo

Le 20/04/2010 13:06, MRAB a écrit :

Dodo wrote:

Hello,

I don't understand why this won't execute


import urllib.request as u
import socket
socket.setdefaulttimeout(10)

l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; #
supposed to timeout
try:
h = u.urlretrieve(l)
except u.URLError, e: # I tried u.e too, no effect.
print(e)
except:
print("other error")

The error :

...\Python>err.py
File "...\err.py", line 8
except u.URLError, e: # I tried u.e too, no effect.
^
SyntaxError: invalid syntax


In Python 3 it's:

except u.URLError as e:

This a because in Python 2 people sometimes write:

except OSError, IOError:

thinking that it will catch both OSError and IOError.


thanks =D
--
http://mail.python.org/mailman/listinfo/python-list


chr(i) ASCII under Python 3

2010-04-26 Thread Dodo

Hi all,
Under python 2.6, chr() "Return a string of one character whose ASCII 
code is the integer i." (quoted from docs.python.org)
Under python 3.1, chr() "Return the string of one character whose 
Unicode codepoint is the integer i."


I want to convert a ASCII code back to a character under python 3, not 
Unicode.


How can I do that?

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


Re: chr(i) ASCII under Python 3

2010-04-26 Thread Dodo

Le 26/04/2010 22:26, Alf P. Steinbach a écrit :

On 26.04.2010 22:12, * Dodo:

Hi all,
Under python 2.6, chr() "Return a string of one character whose ASCII
code is the integer i." (quoted from docs.python.org)
Under python 3.1, chr() "Return the string of one character whose
Unicode codepoint is the integer i."

I want to convert a ASCII code back to a character under python 3, not
Unicode.

How can I do that?


Just use chr().

ASCII (7-bit) is a subset of ISO Latin-1 (7-bit), which is a subset of
Unicode's Basic Multilingual Plane (BMP, original Unicode, 16-bit) which
is a subset of Unicode (21-bit).


Cheers & hth.,

- Alf


Oh, I see... thanks

* just realize the problem doesn't come from here *
--
http://mail.python.org/mailman/listinfo/python-list


CGI python 3 write RAW BINARY

2010-04-28 Thread Dodo

Help! this is driving me crazy lol
I want to print raw binary data to display an image file
BUT
python3 outputs b'' instead of  so the 
browser can't read the image!!


 f = open("/some/path/%s" % x, 'rb')
 print(f.read())



any idea?
Dorian
--
http://mail.python.org/mailman/listinfo/python-list


Re: CGI python 3 write RAW BINARY

2010-04-29 Thread Dodo

Le 29/04/2010 01:45, Antoine Pitrou a écrit :

Le Wed, 28 Apr 2010 23:54:07 +0200, Dodo a écrit :


Help! this is driving me crazy lol
I want to print raw binary data to display an image file BUT
python3 outputs b'' instead of so the
browser can't read the image!!

   f = open("/some/path/%s" % x, 'rb')
   print(f.read())


print() implicitly converts its arguments to str (i.e. unicode strings)
and then writes them to sys.stdout, which is a text IO wrapper.
If you want to bypass the unicode layer, you have to use
sys.stdout.buffer instead.
That is:

sys.stdout.buffer.write(f.read())

Regards

Antoine.



@Gary : How do I reply to a http request then?

@Antoine : It not sys.stdout.buffer.write but sys.stdout.write() 
instead. But it still doesn't work, now I have empty content


#!/usr/bin/python3
import cgi, os, sys
form = cgi.FieldStorage()
all = os.listdir("/some/path/with/files/")
for x in all:
if x.find( form['id'].value ) != -1:
ext = x.split(".")[-1]
print("Content-type:image/%s\n\n" % ext)
f = open("/some/path/with/files/%s" % x, 'rb')
sys.stdout.write( f.read() )
f.close()
break

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


Re: CGI python 3 write RAW BINARY

2010-04-29 Thread Dodo

Le 29/04/2010 17:07, Antoine Pitrou a écrit :

Le Thu, 29 Apr 2010 12:53:53 +0200, Dodo a écrit :


@Antoine : It not sys.stdout.buffer.write but sys.stdout.write()
instead. But it still doesn't work, now I have empty content


Let me insist: please use sys.stdout.buffer.write().
You'll also have to call sys.stdout.flush() before doing so.


Oh, I tested on my windows machine avec sys.stdout.buffer.write() didn't 
work.

I just tested on my linux server, and it works

So, let's modify the script

sys.stdout.buffer.write( f.read() )
sys.stdout.flush()

Now I have:
malformed header from script. Bad header=ÿØÿà: show.py
and it tells me Internal Server error :(

I can't see the error messages (traceback)
any idea to do so?

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


Re: Python's regular expression help

2010-04-29 Thread Dodo

Le 29/04/2010 20:00, goldtech a écrit :

Hi,
Trying to start out with simple things but apparently there's some
basics I need help with. This works OK:

import re
p = re.compile('(ab*)(sss)')
m = p.match( 'absss' )
m.group(0)

'absss'

m.group(1)

'ab'

m.group(2)

'sss'
...
But two questions:

How can I operate a regex on a string variable?
I'm doing something wrong here:


f=r'abss'
f

'abss'

m = p.match( f )
m.group(0)

Traceback (most recent call last):
   File "", line 1, in
 m.group(0)
AttributeError: 'NoneType' object has no attribute 'group'

How do I implement a regex on a multiline string?  I thought this
might work but there's problem:


p = re.compile('(ab*)(sss)', re.S)
m = p.match( 'ab\nsss' )
m.group(0)

Traceback (most recent call last):
   File "", line 1, in
 m.group(0)
AttributeError: 'NoneType' object has no attribute 'group'




Thanks for the newbie regex help, Lee


for multiline, I use re.DOTALL

I do not know match(), findall is pretty efficient :
my = "LINK"
res = re.findall(">(.*?)<",my)
>>> res
['LINK']

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


Re: CGI python 3 write RAW BINARY

2010-04-29 Thread Dodo

Le 29/04/2010 22:21, Antoine Pitrou a écrit :

Le Thu, 29 Apr 2010 18:33:08 +0200, Dodo a écrit :

Oh, I tested on my windows machine avec sys.stdout.buffer.write() didn't
work.
I just tested on my linux server, and it works

So, let's modify the script

sys.stdout.buffer.write( f.read() )
sys.stdout.flush()


Sorry, I should have been clearer. You have to flush sys.stdout before
using sys.stdout.buffer, such that the unicode layer doesn't keep any
unwritten data. So this should be:

sys.stdout.flush()
sys.stdout.buffer.write( f.read() )

Regards

Antoine.



I don't get a thing.
Now with the fix :
All browsers shows a different thing, but not the image!
http://ddclermont.homeip.net/misc/python/

If I save it to computer :
* Windows image viewer won't read it
* Irfanview can read it without problems

Dorian

PS : ça commence sérieusement à m'énerver
--
http://mail.python.org/mailman/listinfo/python-list


Re: CGI python 3 write RAW BINARY

2010-04-29 Thread Dodo

Le 29/04/2010 18:33, Dodo a écrit :

Le 29/04/2010 17:07, Antoine Pitrou a écrit :

Le Thu, 29 Apr 2010 12:53:53 +0200, Dodo a écrit :


@Antoine : It not sys.stdout.buffer.write but sys.stdout.write()
instead. But it still doesn't work, now I have empty content


Let me insist: please use sys.stdout.buffer.write().
You'll also have to call sys.stdout.flush() before doing so.



Oh, I tested on my windows machine avec sys.stdout.buffer.write() didn't
work.
I just tested on my linux server, and it works

So, let's modify the script

sys.stdout.buffer.write( f.read() )
sys.stdout.flush()

Now I have:
malformed header from script. Bad header=ÿØÿà: show.py
and it tells me Internal Server error :(

I can't see the error messages (traceback)
any idea to do so?

Dorian


Ok, I just checked, the CRC of the file in the server is not the same 
the in the browser

I don't understand how the data could be modified...

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


Re: CGI python 3 write RAW BINARY

2010-05-01 Thread Dodo

Le 30/04/2010 17:52, Antoine Pitrou a écrit :

Le Thu, 29 Apr 2010 23:37:32 +0200, Dodo a écrit :

I don't get a thing.
Now with the fix :
All browsers shows a different thing, but not the image!
http://ddclermont.homeip.net/misc/python/

If I save it to computer :
* Windows image viewer won't read it
* Irfanview can read it without problems


Did you set the content-type and content-length in the HTTP headers?
Can you post your code?



I didn't know about content-lenght
Here's the new code (I used a fixed image patch to make sure this is not 
the source of the problem)



#!/usr/bin/python3
import cgi, sys, cgitb
cgitb.enable()

f = open("/home/dodo/54.jpg", "rb")
data = f.read()
l = len(data)
f.close()

print("Content-type:image/jpg\nContent-length:%d\n\n" % l)

sys.stdout.flush()
sys.stdout.buffer.write( data )



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


Re: CGI python 3 write RAW BINARY

2010-05-07 Thread Dodo

Le 01/05/2010 12:52, Dodo a écrit :

Le 30/04/2010 17:52, Antoine Pitrou a écrit :

Le Thu, 29 Apr 2010 23:37:32 +0200, Dodo a écrit :

I don't get a thing.
Now with the fix :
All browsers shows a different thing, but not the image!
http://ddclermont.homeip.net/misc/python/

If I save it to computer :
* Windows image viewer won't read it
* Irfanview can read it without problems


Did you set the content-type and content-length in the HTTP headers?
Can you post your code?






I didn't know about content-lenght
Here's the new code (I used a fixed image patch to make sure this is not
the source of the problem)


#!/usr/bin/python3
import cgi, sys, cgitb
cgitb.enable()

f = open("/home/dodo/54.jpg", "rb")
data = f.read()
l = len(data)
f.close()

print("Content-type:image/jpg\nContent-length:%d\n\n" % l)

sys.stdout.flush()
sys.stdout.buffer.write( data )



Dorian

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


Python3 buffer extra byte??

2010-05-17 Thread Dodo

Let's consider this code:

#!/usr/bin/python3
import cgi, sys
print("Content-type:image/jpeg\n\n")
f = open("img.jpg","rb")
sys.stdout.flush()
sys.stdout.buffer.write( f.read() )
f.close()

I receive the file with one padding byte at the start of the file (0x0a)
http://www.1pix.org/multi/images/wg7zg58gsgbhc9cppo5i.jpg

Any idea why?

Dorian
(yes, this is the continuation of "CGI python 3 write RAW BINARY")
--
http://mail.python.org/mailman/listinfo/python-list


Tkinter help - Why this behavior ? (py3)

2010-06-05 Thread Dodo

Hi,

let's consider this exemple :

from tkinter import *
from tkinter.ttk import *

class First:
def __init__(self):
self.root = Tk()
B = Button(self.root, command=self.op)
B.pack()

self.root.mainloop()

def op(self):
Second(self)
print("print")


class Second:
def __init__(self, parent):
root = Toplevel(parent.root)
root.grab_set()

root.mainloop()


First()



when I close the second window, the print is NOT executed. It's done 
when I close the first window.

Why do it "freeze" my function?

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


Re: Tkinter help - Why this behavior ? (py3)

2010-06-07 Thread Dodo

Le 05/06/2010 19:07, Alf P. Steinbach a écrit :

* Dodo, on 05.06.2010 15:46:

Hi,

let's consider this exemple :

from tkinter import *
from tkinter.ttk import *

class First:
def __init__(self):
self.root = Tk()
B = Button(self.root, command=self.op)
B.pack()

self.root.mainloop()

def op(self):
Second(self)
print("print")


class Second:
def __init__(self, parent):
root = Toplevel(parent.root)
root.grab_set()

root.mainloop()


First()



when I close the second window, the print is NOT executed. It's done
when I close the first window.
Why do it "freeze" my function?


First, sorry about Thunderbird 3.x messing up the quoting of the code.

Don't know what they did to introduce all those bugs, but anyway,
Thunderbird 3.x is an example that even seasoned programmers introduce
an unbelievable number of bugs, I think mostly just by repeating code
patterns blindly.

In your code above you're doing as the TB programmers presumably did,
repeating a code pattern that you've seen has worked, without fully
grokking it. The call to 'mainloop' enters a loop. A button press causes
your callback to be invoked from within that loop, but your code then
enters a new 'mainloop'.

Don't.

Except for modal dialogs the single top level 'mainloop' suffices (all
it does is to dispatch "messages" to "handlers", such as your button
press callback). So, just place a single call to 'mainloop' at the end
of your program. Remove the calls in 'First' and 'Second'.


Cheers & hth.,

- Alf




How do I create custom modal dialogs then?

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


Re: Tkinter help - Why this behavior ? (py3)

2010-06-09 Thread Dodo

Le 07/06/2010 15:26, Alf P. Steinbach a écrit :

* Dodo, on 07.06.2010 12:38:

Le 05/06/2010 19:07, Alf P. Steinbach a écrit :

* Dodo, on 05.06.2010 15:46:

Hi,

let's consider this exemple :

from tkinter import *
from tkinter.ttk import *

class First:
def __init__(self):
self.root = Tk()
B = Button(self.root, command=self.op)
B.pack()

self.root.mainloop()

def op(self):
Second(self)
print("print")


class Second:
def __init__(self, parent):
root = Toplevel(parent.root)
root.grab_set()

root.mainloop()


First()



when I close the second window, the print is NOT executed. It's done
when I close the first window.
Why do it "freeze" my function?


First, sorry about Thunderbird 3.x messing up the quoting of the code.

Don't know what they did to introduce all those bugs, but anyway,
Thunderbird 3.x is an example that even seasoned programmers introduce
an unbelievable number of bugs, I think mostly just by repeating code
patterns blindly.

In your code above you're doing as the TB programmers presumably did,
repeating a code pattern that you've seen has worked, without fully
grokking it. The call to 'mainloop' enters a loop. A button press causes
your callback to be invoked from within that loop, but your code then
enters a new 'mainloop'.

Don't.

Except for modal dialogs the single top level 'mainloop' suffices (all
it does is to dispatch "messages" to "handlers", such as your button
press callback). So, just place a single call to 'mainloop' at the end
of your program. Remove the calls in 'First' and 'Second'.




How do I create custom modal dialogs then?


I typed

tkinter modal dialog

in the Firefox address bar, and it landed me on

http://effbot.org/tkinterbook/tkinter-dialog-windows.htm


Cheers & hth.,

- Alf




Thanks,
I don't know why I didn't find effbot.org on the first place. But I 
__did__ googled about modal dialogs!


.wait_window() works great

Thanks for your time,
Dorian
--
http://mail.python.org/mailman/listinfo/python-list


[py3] Tkinter menu checkbutton not working

2010-06-09 Thread Dodo

Hello,

I trying to make this piece of code work (this is python3)

from tkinter import *
from tkinter.ttk import *

class Window:
 def __init__(self):
  self.root = Tk()

  self.menu = Menu(self.root)
  self.root['menu'] = self.menu

  self.submenu = Menu(self.menu)
  self.ck = 0
  self.submenu.add_checkbutton(label="My checkbutton", 
variable=self.ck, command=self.displayCK)

  self.menu.add_cascade(label="sub", menu=self.submenu )

 def displayCK(self):
  print( self.ck )


app = Window()
app.root.mainloop()


The self.ck will always be 0... why?

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


Re: Tkinter help - Why this behavior ? (py3)

2010-06-09 Thread Dodo

Le 09/06/2010 18:49, rantingrick a écrit :

On Jun 5, 8:46 am, Dodo  wrote:

Hi,

let's consider this exemple :

from tkinter import *
from tkinter.ttk import *

class First:
 def __init__(self):
 self.root = Tk()
 B = Button(self.root, command=self.op)
 B.pack()

 self.root.mainloop()

 def op(self):
 Second(self)
 print("print")

class Second:
 def __init__(self, parent):
 root = Toplevel(parent.root)
 root.grab_set()

 root.mainloop()




Please don't write code like this, it is very, very, very, very ugly.
Python is an OOP language do use that to your advantage and you will
make your life much easier! Here is a better alternative.


import Tkinter as tk
from Tkconstants import *
import tkSimpleDialog

class MyDialog(tkSimpleDialog.Dialog):
 def body(self, master):
 prompt = "Hello from my custom dialog!\nAlthough with
something this simple i should have used tkMessageBox."
 tk.Label(self, text=prompt).pack()

 def validate(self):
 print 'I need to put some code here, maybe'
 return True

 def apply(self):
 print 'I need to put some code here, maybe'


class App(tk.Tk):
 def __init__(self):
 tk.Tk.__init__(self)
 b=tk.Button(self, text='Show Dialog', command=self.showDialog)
 b.pack(padx=5, pady=5)

 def showDialog(self):
 d = MyDialog(self)

if __name__ == '__main__':
 app = App()
 app.mainloop()


Could you please explain to me what's the big difference?

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


Re: Tkinter menu checkbutton not working

2010-06-09 Thread Dodo

Le 09/06/2010 18:54, rantingrick a écrit :

On Jun 9, 11:26 am, Dodo  wrote:

Hello,

I trying to make this piece of code work (this is python3)

from tkinter import *
from tkinter.ttk import *

class Window:
   def __init__(self):
self.root = Tk()

self.menu = Menu(self.root)
self.root['menu'] = self.menu

self.submenu = Menu(self.menu)
self.ck = 0
self.submenu.add_checkbutton(label="My checkbutton",
variable=self.ck, command=self.displayCK)
self.menu.add_cascade(label="sub", menu=self.submenu )

   def displayCK(self):
print( self.ck )

app = Window()
app.root.mainloop()



see my recent post on your last question. The way you are writing
these classes is wrong. Always inherit from something, in this case
Tk. Fix that first and then pretty up this GUI. But to answer your
question "self.ck" needs to be an instance of tk.IntVar. Read more
about it here...

 http://infohost.nmt.edu/tcc/help/pubs/tkinter/checkbutton.html


I already tried with self.ck = IntVar()
and now it displays PY_VAR0

FYI, I'm using Thunderbird 3, which appears to have some bugs with 
indentation (according to Alf P. Steinbach). That's why I replaced \t by 
a single space

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


Re: Tkinter help - Why this behavior ? (py3)

2010-06-09 Thread Dodo

Le 09/06/2010 19:13, Dodo a écrit :

Le 09/06/2010 18:49, rantingrick a écrit :

On Jun 5, 8:46 am, Dodo wrote:

Hi,

let's consider this exemple :

from tkinter import *
from tkinter.ttk import *

class First:
def __init__(self):
self.root = Tk()
B = Button(self.root, command=self.op)
B.pack()

self.root.mainloop()

def op(self):
Second(self)
print("print")

class Second:
def __init__(self, parent):
root = Toplevel(parent.root)
root.grab_set()

root.mainloop()




Please don't write code like this, it is very, very, very, very ugly.
Python is an OOP language do use that to your advantage and you will
make your life much easier! Here is a better alternative.


import Tkinter as tk
from Tkconstants import *
import tkSimpleDialog

class MyDialog(tkSimpleDialog.Dialog):
def body(self, master):
prompt = "Hello from my custom dialog!\nAlthough with
something this simple i should have used tkMessageBox."
tk.Label(self, text=prompt).pack()

def validate(self):
print 'I need to put some code here, maybe'
return True

def apply(self):
print 'I need to put some code here, maybe'


class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
b=tk.Button(self, text='Show Dialog', command=self.showDialog)
b.pack(padx=5, pady=5)

def showDialog(self):
d = MyDialog(self)

if __name__ == '__main__':
app = App()
app.mainloop()


Could you please explain to me what's the big difference?

Dorian


I think I see it now. Seems good to be
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter menu checkbutton not working

2010-06-12 Thread Dodo

Le 09/06/2010 20:37, rantingrick a écrit :

On Jun 9, 12:20 pm, Dodo  wrote:

Le 09/06/2010 18:54, rantingrick a crit :






On Jun 9, 11:26 am, Dodowrote:

Hello,



I trying to make this piece of code work (this is python3)



from tkinter import *
from tkinter.ttk import *



class Window:
def __init__(self):
 self.root = Tk()



 self.menu = Menu(self.root)
 self.root['menu'] = self.menu



 self.submenu = Menu(self.menu)
 self.ck = 0
 self.submenu.add_checkbutton(label="My checkbutton",
variable=self.ck, command=self.displayCK)
 self.menu.add_cascade(label="sub", menu=self.submenu )



def displayCK(self):
 print( self.ck )



app = Window()
app.root.mainloop()



see my recent post on your last question. The way you are writing
these classes is wrong. Always inherit from something, in this case
Tk. Fix that first and then pretty up this GUI. But to answer your
question "self.ck" needs to be an instance of tk.IntVar. Read more
about it here...



  http://infohost.nmt.edu/tcc/help/pubs/tkinter/checkbutton.html


I already tried with self.ck = IntVar()
and now it displays PY_VAR0

FYI, I'm using Thunderbird 3, which appears to have some bugs with
indentation (according to Alf P. Steinbach). That's why I replaced \t by
a single space


IntVar is a class and self.ck is an instance of that class which is a
PY_VAR. Try print(dir(self.ck)) in your callback to see what methods
are available to this instance. Im just speculating here but somehow
there must be a way to "get" and "set" the IntVar's value... hmmm?

You're about to kick yourself when you realize it. ;-)


thanks I realised it eventually
--
http://mail.python.org/mailman/listinfo/python-list


Django 1.2.1 - stuck with CSRF verification

2010-08-19 Thread Dodo

Hi all,
I followed the tutorial but at page 4 I can't get rid of CSRF errors, 
even though I followed everything in this page :

http://docs.djangoproject.com/en/dev/ref/contrib/csrf/

Any idea?

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


Re: Django 1.2.1 - stuck with CSRF verification

2010-08-19 Thread Dodo

Le 19/08/2010 20:40, Thomas Jollans a écrit :

On Thursday 19 August 2010, it occurred to Dodo to exclaim:

Hi all,
I followed the tutorial but at page 4 I can't get rid of CSRF errors,
even though I followed everything in this page :
http://docs.djangoproject.com/en/dev/ref/contrib/csrf/



what kind of errors? Any exception tracebacks you can show us maybe?


Well I fill the form, submit via POST
then :


Forbidden (403)

CSRF verification failed. Request aborted.
Help

Reason given for failure:

No CSRF or session cookie.

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