Re: Set initial size in TKinter

2011-12-20 Thread Eric Brunel
In article ,
 Gabor Urban  wrote:
> Hi,
> 
> I am quite newbie with Tkinter and I could not find the way to set the
> size of the application. (I could find the method to make it
> resizeable, though :-)) ) Any ideas, suggestions or links to
> references are wellcome.

Usually, the best way is to use the geometry method on instances of Tk 
or Toplevel. For example, if you have a variable named root which is the 
instance of Tk, you can do:

root.geometry('500x400')

This will make the window 500 pixels wide and 400 pixels high.

> Here is my code:
> 
> from Tkinter import *
> 
> class Application(Frame):
> def say_hi(self):
>   self.db += 1
> print 'hi there, -->> UG everyone! db = %d'%self.db
> 
> ## TODO: meretezhetoseg
> def createWidgets(self):
>   top = self.winfo_toplevel()
>   top.rowconfigure(0,weight = 1)
>   top.columnconfigure(0,weight = 1)
>   self.rowconfigure(0,weight = 1)
>   self.columnconfigure(0,weight = 1)
>   self.QUIT = Button(self)
>   self.QUIT["text"] = "QUIT"
>   self.QUIT["fg"]   = "red"
>   self.QUIT["command"] =  self.quit
> 
>   self.QUIT.pack({"side": "left"})
> 
>   self.hi_there = Button(self)
>   self.hi_there["text"] = "Hello",
>   self.hi_there["command"] = self.say_hi
> 
>   self.hi_there.pack({"side": "left"})
> 
> def __init__(self, master=None):
> Frame.__init__(self, master)
> self.pack()
> self.createWidgets()
>   self.db = 0
> 
> app = Application()
> app.master.title('UG test')
> app.mainloop()

Where did you find an example code looking like this? This looks like 
veery old conventions for Tkinter programsŠ

For example, there's no need at all to do:

self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"]   = "red"
self.QUIT["command"] =  self.quit

This can be done in a single line:

self.QUIT = Button(self, text='QUIT', fg='red', command=self.quit)

The same goes for self.QUIT.pack({"side": "left"}). Nowadays, this is 
always written self.QUIT.pack(side="left").

And you should avoid creating only an instance of Frame. This actually 
creates a window, but it's a side-effect. Windows are created by 
instantiating Tk for the main one, and Toplevel for all others. Having 
only a Frame will cause problems later, for example if you want to add a 
menu to the window: You can do so on instances of Tk or Toplevel, but 
not on framesŠ

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


Re: Another related OO Python ?

2011-02-16 Thread Eric Brunel
In article 
<6849fd3f-5116-4b35-b274-dc76ae39f...@a11g2000pro.googlegroups.com>,
 RJB  wrote:

> On Feb 16, 12:48 am, Eric Brunel 
> wrote:
> > In article ,
> >  Doug Epling  wrote:
> >
> > > hey, does anyone find the UML useful during Python development of larger
> > > projects?
> >
> > Well, UML being very Java/C++ oriented, I found out that Python idioms
> > were really difficult to represent in the diagrams. So I'm using it to a
> > very small extent and for documentation only, just to give an idea about
> > how classes are organized. For the rest, and IMHO, it's really too
> > impractical to be of any use.
> 
> Which of the 13 diagrams have tried and rejected?-)

Diagrams that aren't too bound to the language like e.g the deployment 
diagram can still be used, of course. I was mainly talking about the 
class diagram, which is still the central point of a model. But I even 
found sequence diagrams quite hard to write for Python, unless they are 
very simplistic ones.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How does IDLE do it?

2011-02-16 Thread Eric Brunel
In article ,
 "Richard D. Moores"  wrote:

> I recently wrote some code that prints information about the 'jukugo'
> used in Japanese newspaper articles. A jukugo is a Japanese word
> written with at least 2 kanji. An example of a 2-kanji jukugo is 危機
> (kiki -- crisis). I found that I could not use my usual IDE to render
> the Japanese correctly in either the code or the output. But IDLE
> (version 3.1.2; Windows Vista) does a beautiful job! See screen shots
> 
> and
> .
> (The whole script plus output is at
> .)
> 
> I'd like to know how the IDLE developers did this. How can IDLE not
> have a problem with Japanese using Courier New, Calibri, even Fences
> or Windings! (For Wingdings, see
> .)

IDLE doesn't do anything, tk does. When a character is not available in a given 
font,
tk looks up for one containing it by itself and uses it automatically.

> Thanks,
> 
> Dick Moores
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another related OO Python ?

2011-02-16 Thread Eric Brunel
In article ,
 Doug Epling  wrote:

> hey, does anyone find the UML useful during Python development of larger 
> projects?

Well, UML being very Java/C++ oriented, I found out that Python idioms 
were really difficult to represent in the diagrams. So I'm using it to a 
very small extent and for documentation only, just to give an idea about 
how classes are organized. For the rest, and IMHO, it's really too 
impractical to be of any use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a window style in a Toplevel window

2010-12-09 Thread Eric Brunel
In article ,
 pyt...@bdurham.com wrote:

> Eric,
> 
> Besides style support, what are the advantages of ttk.Frame vs.
> Tkinter.Frame?

I'd say none. They are both just containers for other widgets, support 
the same layout managers, and so on. For me, using a ttk.Frame is really 
just for getting the correct theme, nothing else...

> Thanks,
> Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a window style in a Toplevel window

2010-12-09 Thread Eric Brunel
In article ,
 craf  wrote:

> Hi.
> 
> I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10.
> 
> CODE:
> 
> module:FMain.py
> 
> from tkinter import ttk
> from FSecondWindow import *
> 
> class App:
> def __init__(self,master):
> 
> button1 = ttk.Button(master,text='Show
> TopLevel',command=lambda:window())
> button1.pack()
> 
>
> master = Tk()
> app = App(master)
> style = ttk.Style()
> style.theme_use('clam')
> master.mainloop()
> 
> 
> module:FSecondWindow.py
> 
> from tkinter import *
> from tkinter import ttk
> 
> def window():
> t = Toplevel()
> button2 = Button(t,text='Hello').pack()
> 
> 
> CODE EXPLANATION:---
> 
> 1. From the main module FMain.py call the window function that is
> located in FSecondWindow module and create a toplevel window.
> 
> 2.I apply a theme called 'clam' to the master window to improve the
> appearance of their widgets.
> 
> QUERY:--
> 
> How I can make the toplevel window also take the theme 'clam'?

Short answer: you can't. No directly anyway.

Long answer: As you might be aware, there are 2 widget sets in 
tk/tkinter, the "old" one for which classes are directly in the tkinter 
module, and the new one that are in the ttk submodule. Only the second 
set supports theming, not the first one. Unfortunately, there are a few 
widgets that exist only in the first set, and Toplevel is one of those. 
So no theming is directly available for toplevels, and you can change 
whatever you want via style.theme_use, it won't be reflected on 
toplevels.

By the way, as you wrote the code above, it won't be reflected on your 
button either, since you used the Button class, which is taken in 
tkinter directly, so it is the "old" Button class, not the new one. To 
get the new one, use ttk.Button, not Button.

For your toplevel, there is however a simple workaround: Since there is 
a Frame widget in the new widget set, you can simply insert such a frame 
in your toplevel, make sure it will take the whole space, and then 
insert your widgets in this frame rather than in the toplevel directly. 
The code for your 'window' function would then become:

def window()
t = Toplevel()
frm = ttk.Frame(t)
frm.pack(fill=BOTH, expand=True)
button2 = ttk.Button(frm, text='Hello')
button2.pack()

(Note also that I have put the creation of the button and its packing in 
2 lines. You should never do variable = widget.pack(…) since pack does 
not return the widget. It always returns None, so doing so won't put 
your widget in the variable).

The code above should do what you're after.

> Thanks in advance.

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


Re: Decorate un Frame with window managers title bar, etc en Tkinter 8.5

2010-12-02 Thread Eric Brunel
In article ,
 craf  wrote:

> Hi.
> 
> I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 
> 
> I would like to turn a frame into a toolbox,
> ,and for that I read that you can use the command wm manage (window)
> 
> The information can be found  at:
> http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39
> 
> the explanation says:
> 
> wm manage widget:
> The widget specified will become a stand alone top-level window.
> The window will be decorated with the window managers title bar,
> etc. Only frame, labelframe and toplevel widgets can be used
> with this command. Attempting to pass any other widget type will
> raise an error. Attempting to manage a toplevel widget is benign
> and achieves nothing. See also GEOMETRY MANAGEMENT.
> 
> I have tried to use it in Tkinter but I can not know how is its
> structure.
> 
> In Tkinter should be:
> 
> ---TEST CODE---
> 
> from Tkinter import
> 
> master = Tk()
> frame = Frame(master)
> wm_manager(Frame)
> master.mainloop()
> 
> 
> 
> But this does not work.

If your version of Tkinter supports it, then the correct syntax is:
frame.wm_manage()
Please note you have to call it on the Frame instance (the one you named 
frame), and not on Frame with a big F which is the class.

If it says the method doesn't exist (AttributeError raised on the line 
frame.wm_manage()), you can also try to do it at tcl/tk level with the 
line:
master.tk.call('wm', 'manage', frame)

> I appreciate any of this item

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


Re: Unix-head needs to Windows-ize his Python script

2010-10-21 Thread Eric Brunel
In article ,
 Shawn Milochik  wrote:
> Also, wxPython automatically looks native Mac, Windows, and Linux.

And so do the recent versions of Tkinter/tcl-tk... In Python, you just 
have to use the widgets in the new ttk module. These widgets also have 
fewer options than their equivalent in Tkinter, so they probably are 
even more accessible to people who never wrote a GUI before. The 
documentation is here: http://docs.python.org/library/ttk.html#module-ttk

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


Re: PyRTF object model

2010-09-30 Thread Eric Brunel
In article ,
 Rustom Mody  wrote:

> I am trying to use PyRTF.
> 
> I gather that an RTF doc consists of a list of sections, a section
> consists of a list of paras,
> paras seem to be just text (not sure on that one)

They also include a style, not only text.

> Some questions:
> 
> When does one end one section and start another?

You don't 'end a section. You just create a new one and append it to 
your document's sections:

my_document = PyRTF.Document()
my_section1 = PyRTF.Section()
my_document.Sections.append(my_section1)
my_section2 = PyRTF.Section()
my_document.Sections.append(my_section2)

> How does one handle lists (as in numbered, bulleted etc)?

Not sure on this one. I've had to do it, but could handle it via regular 
paragraph style properties and insert the bullets or numbers 
explicitely, so I did it just like that. For example, your can create a 
PyRTF.ParagraphPropertySet with the options left_indent to 1133 twips = 
2cm, first_line_indent to -567 twips = -1cm and set a tab at 1cm with 
the option:
tabs=[PyRTF.TabPropertySet(width=567)]
Then you create a PyRTF.ParagraphStyle using this 
PyRTF.ParagraphPropertySet and pass it as the first argument when you 
create your PyRTF.Paragraph. Then, you just insert tour bullet or number 
in the paragraph explicitely, followed by a tab.
There might be a better way to do it.

BTW, as you might have noticed, the documentation for PyRTF is quite 
minimal to say the least, so the only way to figure out what can be done 
is by reading the PyRTF source codeŠ

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


Re: update of elements in GUI

2010-08-17 Thread Eric Brunel
(Top-post corrected; please don't do that, it makes messages very hard 
to read via usenetŠ)

In article 
<26c363c8-11d7-49b9-a1c1-251ab5ff9...@p22g2000pre.googlegroups.com>,
 Jah_Alarm  wrote:
> On Aug 17, 7:19 pm, Eric Brunel 
> wrote:
> > You have to call update_idletasks on a Tkinter *widget*, not a variable.
> > You can call it on your window (Tk or Toplevel instance) or on your
> > label for example. This way, it should work.
> >
> thanks. The thing is, the objects actually get updated without this
> command, but when I run the GUI outside of python shell (i.e. in
> command prompt as python filename.py or compile it to .exe file) the
> objects do not get updated. I tried
> Label(mainframe,textvariable=var).grid(column=1,row=1).update_idletasks()
> and mainframe.update_idletasks() but it still doesn't work.

I think you're really misunderstanding something here: the call to 
update_idletasks is a one shot call to the GUI to basically tell it to 
refresh itself. So each time you change anything that should be 
displayed, you have to call that method again, or your changes will only 
be seen when the control returns to the GUI, which is basically at the 
end of your processing.

The fact that it works when you're doing it interactively is normal. In 
this mode, you don't have a GUI event loop running, so the GUI updates 
itself all the time automatically. This is never true in programs you 
run the 'normal' way, i.e via: python filename.py

And by the way, Label(Š).grid(Š).update_idletasks() had no chance to 
work anyway: the grid method doesn't return anything, so you're trying 
to call the update_idletasks method on None hereŠ

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


Re: message box in Tkinter

2010-08-17 Thread Eric Brunel
In article 
<61cbd1cb-bd6d-49aa-818f-d28c46098...@x18g2000pro.googlegroups.com>,
 Jah_Alarm  wrote:

> I need to display a message box at the click of a button. I od the
> following:
> 
> from Tkinter import *
> 
> def msg1():
> messagebox.showinfo(message='Have a good day')
> 
> 
> Button(mainframe,text="About",command=msg1()).grid(column=360,row=36,sticky=W)
> 
> I get the error msg 'global name 'messagebox' is not defined'
> 
> When I try importing messagebox from Tkinter i get an error message
> that this module doesn't exist.
> 
> thanks

Where did you find any reference to something called messagebox? The 
actual module name is tkMessageBox and it should be imported separately:

import tkMessageBox
tkMessageBox.showinfo(message='Have a good day')

Should work that way.
HTH
 - Eric -
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Textvariable display in label (GUI design)

2010-08-17 Thread Eric Brunel
In article 
,
 Jah_Alarm  wrote:

> On Aug 17, 3:32 am, Eric Brunel 
> wrote:
> > In article
> > <993d9560-564d-47f0-b2db-6f0c6404a...@g6g2000pro.googlegroups.com>,
> >
> >  Jah_Alarm  wrote:
> > > hi,
> >
> > > pls help me out with the following issue: I wrote a function that uses
> > > a for loop that changes a value of a certain variable each iteration.
> > > What I want is by clicking a button in GUI (with the command bound to
> > > this function) this value each iteration is displayed in a textbox
> > > (label). So far only one (starting value) is displayed.
> >
> > > thanks,
> >
> > > Alex
> >
> > First, with posts like this, you're highly unlikely to get any useful
> > answer: please strip down your code to the smallest part that displays
> > the problem, post this code here, explaining what you're expecting and
> > what you're getting. Otherwise, people just won't know what you're
> > talking about unless they have a crystal ballÅ 
> >
> > Now using my own crystal ball: if you don't return the control to the
> > GUI each time your variable is increased, the GUI won't get a chance to
> > update itself. Since you seem to use Tkinter (another wild guessÅ ), you
> > probably need a call to the update_idletasks method on any Tkinter
> > widget each time you change your TextVariable.
> >
> > HTH
> >  - Eric -
> 
> Thanks, but where is this command used, in the button than runs the
> algorithm, the label or the function itself?

Wherever you want, the only requirement being that you should have a 
widget at hand, in a class attribute or a global variable or whatever. I 
would put it just after I do any my_variable.set(…) if possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: update of elements in GUI

2010-08-17 Thread Eric Brunel
In article 
<24dc97b3-a8b5-4638-9cf5-a397f1eae...@q16g2000prf.googlegroups.com>,
 Jah_Alarm  wrote:

> hi, I've already asked this question but so far the progress has been
> small.
> 
> I'm running Tkinter. I have some elements on the screen (Labels, most
> importantly) which content has to be updated every iteration of the
> algorithm run, e.g. "Iteration =" [i] for i in range(n), n=100. I'm
> using the update_idletasks() command in the function itself after the
> variable.set(...) command. The variable type is IntVar(), and the
> mistake I'm getting is 'IntVar instance has no attribute
> 'update_idletasks'. No updates are displayed, of course.

You have to call update_idletasks on a Tkinter *widget*, not a variable. 
You can call it on your window (Tk or Toplevel instance) or on your 
label for example. This way, it should work.

> Without the GUI the algorithm (it's a genetic algorithm) is working
> fine, but I need to make it available to other people via GUI
> 
> cheers,
> 
> Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Textvariable display in label (GUI design)

2010-08-16 Thread Eric Brunel
In article 
<993d9560-564d-47f0-b2db-6f0c6404a...@g6g2000pro.googlegroups.com>,
 Jah_Alarm  wrote:

> hi,
> 
> pls help me out with the following issue: I wrote a function that uses
> a for loop that changes a value of a certain variable each iteration.
> What I want is by clicking a button in GUI (with the command bound to
> this function) this value each iteration is displayed in a textbox
> (label). So far only one (starting value) is displayed.
> 
> thanks,
> 
> Alex

First, with posts like this, you're highly unlikely to get any useful 
answer: please strip down your code to the smallest part that displays 
the problem, post this code here, explaining what you're expecting and 
what you're getting. Otherwise, people just won't know what you're 
talking about unless they have a crystal ballŠ

Now using my own crystal ball: if you don't return the control to the 
GUI each time your variable is increased, the GUI won't get a chance to 
update itself. Since you seem to use Tkinter (another wild guessŠ), you 
probably need a call to the update_idletasks method on any Tkinter 
widget each time you change your TextVariable.

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


Re: how to switch image in tkinter? making it mutable? how?

2010-08-16 Thread Eric Brunel
In article 
<414ff6dd-73ef-48df-bd2b-080a2c710...@h17g2000pri.googlegroups.com>,
 ChrisChia  wrote:

> I have this:
> image1 = ImageTk.PhotoImage(file = "c:\\f1.jpg")
> image2 = ImageTk.PhotoImage(file = "c:\\f2.jpg")
> 
> imagelist.append(image1)
> imagelist.append(image2)
> 
> self.label  = tk.Label(image = imagelist[0])
> 
> is there a way that i can create a method to switch the display the
> image2 (imagelist 2nd element)
> without using label.bind?
> 
> can i make an image mutable?

Unfortunately, I don't know the package ImageTk you're using. But at tk 
level, images are mutable without problem. It seems however that the tcl 
commands allowing to read an existing image from a file are not exposed 
at Tkinter level. But it is still possible to send the command to the 
underlying tcl interpreter to do it:

from Tkinter import *
root = Tk()
image = PhotoImage(file='f1.gif')
label = Label(root, image=image)
## When you want to change the image:
root.tk.call(image, 'read', 'f2.gif', '-shrink')

This will only work with image formats supported in the tcl/tk core, 
which are basically only GIF so far.

BTW, I don't understand why you talk about label.bindŠ If you need to do 
anything when the label is clicked, you have to make a binding on the 
label whatever it is.

HTH anyway.
 - Eric -
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __class__ of what

2010-08-12 Thread Eric Brunel
In article 
<72151646-65cb-47bb-bd55-e7eb67577...@z10g2000yqb.googlegroups.com>,
 "Eric J. Van der Velden"  wrote:

> Hello,
> 
> I have,
> 
> class C:
> n=0
> def __init__(s):
> __class__.n+=1
> 
> 
> I do
> >>> C()
> 
> This is fine.

No it's not, at least in Python 2.x:
>>> C()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in __init__
NameError: global name '__class__' is not defined

> But of what thing I am taking the __class__ of?

Nothing, precisely. You should write s.__class__ (and replace s by self 
while you're at it).

> I can also do
> 
> @staticmethod
> def p():
> print(__class__.n)
> 
> >>> C.p()
> 1

No you can't, again in Python 2.x:
>>> C.p()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in p
NameError: global name '__class__' is not defined

Unless I'm missing something or something fundamental changed in Python 
3, your examples do not workŠ

> Thanks,
> 
> Eric J.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Tkinter Simple Qn

2010-08-12 Thread Eric Brunel
In article 
,
 ChrisChia  wrote:

> Hi i have the following problem with Python Tkinter.
> I switch to switch the image background (which i used Tkinter.Label
> with image arg to display on the GUI).
> 
> How can I do that? the callback function which i have created doesn't
> seem to work...

It is usually way better to post the actual error than just saying 
"doesn't seem to work"Š Here your problem is quite clear, but in most 
circumstances, it would be quite difficult to figure out what's 
happening.

> some advice?
> 
> below is my code:
> 
> 
> import Tkinter as tk
> from PIL import Image, ImageTk
> 
> root = tk.Tk()
> 
> # having problem with switching the image
> def callback(event):
> global root
> root.panel1.pack_forget()
> root.panel1.image = image2

The variable image2 is not known in this context, so no wonder the 
callback doesn't work. Let me guess: it says something like "NameError: 
name 'image2' is not defined"?

> root.panel1.pack()
> 
> 
> def app():
> 
> root.title('FIT 2022 Assignment 1')
> 
> # pick an image file you have .bmp .jpg .gif. .png
> # load the file and covert it to a Tkinter image object
> imageFile = "c:\\test1.jpg"
> image1 = ImageTk.PhotoImage(Image.open(imageFile))
> imageFile2 = "c:\\test2.jpg"
> image2 = ImageTk.PhotoImage(Image.open(imageFile2))

Here, you create image2 as a local variable in function app. So the 
variable name will not be known outside of app. If you want it to be 
global, you have to add a line:
global image2
at the beginning of your app function. Then it should work correctly.

By the way, I usually find it better to organize a GUI into classes 
rather than using functions. This way, you could store the images in 
object attributes and define your callback as a method, and not as a 
function.

> # get the image size
> w = image1.width()
> h = image1.height()
> 
> 
> # position coordinates of root 'upper left corner'
> x = 0
> y = 0
> 
> 
> # make the root window the size of the image
> root.geometry("%dx%d+%d+%d" % (w, h, x, y))
> 
> 
> # root has no image argument, so use a label as a panel
> panel1 = tk.Label(root, image=image1)
> panel1.pack(side='top', fill='both', expand='yes')
> panel1.image = image1
> panel1.bind("", callback)
> 
> 
> panel1.pack()
> root.mainloop()
> 
> 
> app()

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


Re: File Manager in Tkinter

2010-08-11 Thread Eric Brunel
In article <770366ta10gk98vgd5n2tapl7ag6ska...@4ax.com>, John wrote:
> My python is version 2.6.5.  Would you recomend I upgrade and if yes
> to which version?
> 
> 
> from tkinter import ttk
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> from tkinter import ttk
> ImportError: No module named tkinter

On Python 2.x, the module is called Tkinter with an uppercase T. It has 
been changed to tkinter with a lowercase t in Python 3.x for naming 
consistency reasons.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Manager in Tkinter

2010-08-10 Thread Eric Brunel
In article , John wrote:

> As a learning exercise in Tkinter I htought about making a very simple
> and basic file manager for my own use. I tried searching google for
> any sample project and could not find anything. Not exactly  sure how
> to start I tought I could ask here? 
> 
> I thought about making two listboxes one to list folders only the
> other files inside. I tried to make one listbox first but did not know
> how to list folders only.

You just have to filter them explicitely by using os.path.isdir on each 
file name.

> from Tkinter import *
> import os
> path = "D:\\"
> 
> 
> s = Scrollbar()
> L = Listbox()
> 
> s.pack(side=RIGHT, fill=Y)
> L.pack(side=LEFT, fill=Y)
> 
> s.config(command=L.yview)
> L.config(yscrollcommand=s.set)
> 
> for filename in os.listdir(path):

Add here:
   if os.path.isdir(os.path.join(path, filename)):
>   L.insert(END, filename)
> 
> mainloop()
> 
> 
> 
> Is there a way to list folders with images?

AFAIK, not with a Listbox. You can do it with a Canvas, but it's much 
more complicated than using a Listbox, so maybe you should try to make 
your Listbox-only version works first.

> Any suggestions or help how to proced would be appreciated.
> 
> Thank you

Good luck!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GNUstep and Python

2009-06-23 Thread Eric Brunel
Diez B. Roggisch wrote:
> Paul Watson schrieb:
>> Has anyone used GNUstep?
>>
>> In addition to Objective-C, there are Java and Ruby bindings.
>>
>> Has anyone created a Python binding to GNUstep?
>
> There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep.

Apparently, it's not: There was some compatibility in earlier versions, but
it's been officially removed in version 2.0. See
http://pyobjc.sourceforge.net/NEWS-2.0.html :
"GNUstep support has been removed because this has never worked properly,
nobody seems interested in fixing that and the internal APIs of PyObjC have
changed greatly."

I'd love to see that happen, but GNUStep seems to be disappearing little by
little. Too bad...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where to find options for add_command?

2009-04-16 Thread Eric Brunel
Muddy Coder wrote:
> Hi Folks,
>
> When I make Menu, and add in menu items, by using add_command, such
> as:
>
> menuObj.add_command(label='Open File', command=self.open_file)
>
> It works. But, I want to make the GUI looking better. So, I want to
> change color, font, size, background, for the label of Open File. I
> got clobbered. I tried relief, fg, color, no one worked. Can somebody
> points me a website to visit, to check out what options available for
> add_command? Thanks!

Assuming you're using Tkinter, the best resource for it are the tk manual
pages, that you can find here:
http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm
It requires a little adaptation to understand how to convert tcl syntax to
Python syntax, but it's quite straightforward and doesn't take long. You'll
find the answer to your question here:
http://www.tcl.tk/man/tcl8.5/TkCmd/menu.htm#M32

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


Re: PIL\Tkinter and Transparencies, Rubber Lines, and Dragging Image Objects

2009-04-07 Thread Eric Brunel
W. eWatson wrote:
> Basically, I'd like to know how one (broadly, e.g., references in Win-land)
> does IP (image processing) and drawing techniques such as rubber lines, and
> dragging image objects across the canvas. I know there are some pretty
> powerful toolkits out there, but I'd like to limit this to PIL and Tkinter.
> If it can't be done with them, then I'll consider other possibilities.  As a
> starter, on the topic of transparencies, consider this program that I pulled
> off the web and was posted in 1999. It purports to illustrate how one might
> produce a transparency.

OK, maybe I'm dumb but:

> #!/usr/bin/python
> # see http://mail.python.org/pipermail/python-list/1999-May/003388.html
> from Tkinter import *
> import Image, ImageTk
> import tkFileDialog
>
> class Transparency:
>  def __init__(self, parent):
>   self.canvas = Canvas(parent, bg='green')
>   self.canvas.pack()
>   b = Button(parent, command=self.open, text="Select graphics file")
>   b.pack()
>
>  def open(self):
>   self.canvas.delete(ALL)
>   filename = tkFileDialog.askopenfilename()
>   if filename != '':
>im = Image.open(filename)
>if im.mode != "RGBA":
> im = Image.open(filename).convert("RGBA")
> source = im.split()
> R, G, B, A = 0, 1, 2, 3
> mask = im.point(lambda i: i > 0 and 255) # use black as transparent
 

> source[A].paste(mask)
> im = Image.merge(im.mode, source)  # build a new multiband image
>
>self.graphic = ImageTk.PhotoImage(image=im)
>self.canvas.create_image(100, 100, image=self.graphic)
> if __name__ == "__main__":
>  root = Tk()
>  test = Transparency(root)
>  root.mainloop()
>
> It colors the canvas green, and produces a black background. An image is
> merged with the background. I tried out the program. It executes, but I
> do not see where the transparency is apparent. I used a gif with a
> picture of a telescope on a white background, and the result is what I
  

> would see if I pasted the telescope and white background onto the green
> canvas.

I have neither PIL, nor the image you're using so I can just guess. But if you
want to use a white background, maybe you should use a mask defined with:

mask = im.point(lambda i: 255 if i >= 255 else 0)

(if I understood the mask construction correctly...).

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


Re: How can I change size of GUI?

2009-04-07 Thread Eric Brunel
Muddy Coder wrote:
> Hi Folks,
>
> I copied code from book:
>
> class ScrolledText(Frame):
> def __init__(self, parent=None, text='', file=None):
> Frame.__init__(self, parent)
> self.pack(expand=YES, fill=BOTH)
> self.makeWidgets()
> self.settext(text, file)
> def makeWidgets(self):
> sbar = Scrollbar(self)
> text = Text(self, relief=SUNKEN, width=120)
> sbar.config(command=text.yview)
> text.config(yscrollcommand=sbar.set)
> sbar.pack(side=RIGHT, fill=Y)
> text.pack(side=LEFT, expand=YES, fill=BOTH)
> self.text = text
>
> It works, of course. But, the GUI is small, and I want to enlarge it.
> I tried to add in options of width=120 for Text(), but it did not
> work. Can somebody drop me a couple of lines for help? Thanks!

For what definition of 'did not work'? Seems perfectly fine to me. Just try to
add the lines:

root = Tk()
frm = ScrolledFrame(root)
frm.pack()
root.mainloop()

to the end of your code above, remove the line self.settext(text, file) which
calls a method that doesn't exist, then run it with your option width=120,
then without, and I can guarantee you'll see a difference (I do anyway...).

So I guess this code is part of a much bigger one, and that the problem lies
in the other part...

HTH anyway...
 - Eric -
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help for Toplevel

2009-04-02 Thread Eric Brunel
Muddy Coder wrote:
> Hi Folks,
>
> I have a problem of handling Toplevel window. Basically, I wrote a
> listbox viewer with scrollbars, and saved in file listbo.py. Then in
> my main GUI window, with menu, I need to launch the listbox viewer, in
> a new window. Obviously, a Toplevel window is needed. But, I failed at
> passing parameters over to Toplevel window. Please take a look at my
> code:
>
> Listbox viewer:
> class ScrolledList(Frame):
> def __init__(self, options, parent=None):

So the first parameter to the constructor is the scrolled list options, and
the second one is its parent widget, right?

> Frame.__init__(self, parent)
> self.pack(expand=YES, fill=BOTH)
> self.makeWidgets(options)
>
> In my main GUI:
> from XXX import ScrolledList
> class Foo:
>  def __init__(self):
>  
>  def call_listbox(self, params):
>new = Toplevel()
>alist = ['foor','bar']
>ScrolledList(new,alist)

So why are you passing the parent widget as first parameter and something else
as second...?


On a more general level, unless really needed, I try to avoid creating
subclasses of exisiting classes with a constructor with completely different
parameters than the super-class's one. I'm usually doing something like:

class ScrolledList(Frame):
  def __init__(self, *args, **options):
Frame.__init__(self, *args, **options)

The only thing I (rarely...) allow myself to do is to pass custom options and
getting/removing them with options.pop('my_option') before calling the
super-class's constructor. Otherwise, I just add specific methods; it's far
less confusing.

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-30 Thread Eric Brunel
Alan G Isaac wrote:
[snip]
> On 3/30/2009 3:37 AM Eric Brunel apparently wrote:
>> The Tk instance is registered in a hidden variable in the Tkinter module.
When
>> you don't specify a master, it'll use the latest created Tk instance one by
>> default. BTW, the latest should be the only one: it is quite unsafe to
create
>> several Tk instances in the same application.
>
> I have no desire to do this, but might you pin down "unsafe"?

It is not supposed to be unsafe at tcl level, as it supports several
interpreters side by side in the same application. It is unsafe at user level,
precisely because creating a StringVar might put it in the interpreter you
don't want, leading to weird errors and unexpected results.

So you *can* use several Tk instances in the same application, but then you
really should specify a master for absolutely everything, or you'll get bitten
at some point.

> Thanks!
> Alan Isaac

YW. HTH.
 - Eric -
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-30 Thread Eric Brunel
Alan G Isaac wrote:
> I'm a complete newbie to GUI.
> I have a couple questions about tkinter.
>
> 1. Where is the list of changes
> in Python 3's tkinter?

I'll let someone else answer this as I don't use Python 3 myself. I guess
there are not many.

> 2. What exactly is the role of the root object,
> traditionally created as ``root=tk.Tk()``?
> What is an example where one should create this
> before creating a Frame instance (which will
> otherwise implicitly create one as its master)?

The object traditionally called root is in fact an instance of the tcl
interpreter that will get the commands generated by the Tkinter module. Due to
tk architecture, creating this interpreter will also create a window, which is
inteneded to be your application's main window. This window is called '.' in
tcl/tk. The root object in Tkinter then represents this '.' window. So the
instance of Tk is actually 2 things:
- The interpreter itself;
- The main window for your application.

As for when you should create explicitely an instance of Tk, well, I'd say
always ;-) Creating an instance of Frame without creating a Tk instance first
will actually create one, but you'll have no direct access to it. And you
might want an access to it for quite a number of reasons: hiding it, make it
an icon, add menus to it, and so on... All these operations can be done on
actual windows, not on a Frame which is just a container widget.

> 2. Suppose I ``import tkinter as tk`` and
> then try ``s1=tk.StringVar()``.  This fails
> because no "master" is set. Why does a
> Variable need a master?

Because it needs a tcl interpreter to be created. All Tkinter widget actually
reference their interpreter in their tk attribute. The StringVar will probably
just use that.

> 3. Now suppose I set ``root = tk.TK()`` and
> then try ``s1=tk.StringVar()``.  This
> works fine but now seems a bit magical:
> how has the value of the "master" been
> set?

The Tk instance is registered in a hidden variable in the Tkinter module. When
you don't specify a master, it'll use the latest created Tk instance one by
default. BTW, the latest should be the only one: it is quite unsafe to create
several Tk instances in the same application.

> 4. Another bit of magic:
> Suppose I ``import tkinter as tk`` and
> then try ``f1=tk.Frame()``.  This works
> fine: apparently calling Frame also
> leads to implicit creation of a "master".
> Why is what is good for the gander (i.e.,
> implicit master creation for a Frame) not
> good for the goose (i.e., a Variable)?
> (Here I assume that there has been an
> answer to 2. above.)

Well, I personnally don't see any point on doing any master creation
implicitely, so I never use this master auto-creation for anything. I guess
that having a window automatically created when you just try to instantiate a
variable has been considered weird. But it's just a guess...

> 5. Reading around a bit,
> it seems common to recommend setting
> the values of Variables rather than initializing
> them.  Why?  I cannot see the reason to avoid
> ``s1=tk.StringVar(value="this works fine")``
> and it looks like ``tk.StringVar(()`` is in any
> case initialized (to an empty string).

I've never seen such a recommendation anywhere. I do tend to rely on the
variable's default values.

> 6. Why is str(s1) not its value?  More generally,
> why does a StringVar not behave more like a string?

Well, that's a question for the guys who made the Tkinter module. My guess
would be that StringVar's are supposed to be used only to communicate between
the Python layer and the tcl one. They are not intended to be used as actual
strings in your application. Don't forget anything you do on a StringVar is
actually done by tcl, not Python. So I guess there is also a performance
penalty to use StringVar's instead of Python strings.

> Thanks for any insights,
> Alan Isaac

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-30 Thread Eric Brunel
Alan G Isaac wrote:
[snip]
> PS If you were also offering an answer to the second question,
> I missed it altogether, but although it is perhaps slightly
> less obvious than with a StringVar, I would ask the same
> basic question of an IntVar: why does it not behave more
> like an int?  E.g., why is ``int(IntVar(value=5))`` an
> error, or at least, why is ``str(IntVar(value=5))`` the name
> of the IntVar instead of '5'?

The string representation of Tkinter objects seems to be a design principle in
this module: it'll always evaluate to the representation this object has at
tcl level. Since a XxxVar is represented by an actual variable at tcl level,
its string representation is the name of this variable. I guess it's quite
easier to build the commands that'll be passed to the tcl interpreter this
way: you don't have to check the type of the objects you handle, but pass them
through str and insert the result directly in the command.

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


Re: Threading and tkinter

2009-03-27 Thread Eric Brunel
(Sorry: replying to the wrong message here, but my newsreader somehow managed
to miss the former post...)

> On Mar 7, 9:40 am, Jani Hakala  wrote:
>> > After reading the docs and seeing a few examples i think this should
>> > work ?
>> > Am I forgetting something here or am I doing something stupid ?
>> > Anyway I see my yellow screen, that has to count for something :)
>>
>> I have been using the following scheme:
>>   - Pass the root object to the thread object when creating the object
>>   - Define a event_handler: root.bind('<>', evt_handler) in
>>     the main thread.
>>
>>   - When the thread has done something that the GUI part should now
>>     about, signal an event in the thread:
>>         root.event_generate('<>')    (no other arguments)
>>
>>   - Call a method of the thread object in the event handler e.g. to get
>>     some data from a queue object.
>>
>> This ensures that only the main thread accesses Tkinter-related things.

Are you sure about that? Last time I check, doing:
root.event_generate('<>')
without any other argument called the binding directly, in the context where
it is done, so in the secondary thread. To actually switch to the thread where
the bind was done, you had to do:
root.event_generate('<>', when='tail')
to force the event to get into the event queue... Maybe it has changed in the
latest tcl/tk version (I checked this quite a long time ago on tcl/tk 8.3).


BTW, with the newer tcl/tk versions this time, be sure to compile them with
thread support ('configure ... --enebale-threads' on Unices and 'nmake ...
OPTS=threads' on Windows) if you plan to do such things. We had a lot of
problems with this trick on a tcl/tk 8.5 version not compiled with thread
support, especially when a lot of events happened in a very short time:
crashes, weird errors apparently caused by memory corruption, and so on...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread Eric Brunel
Mr. Z wrote:
> I'm trying emulate a printf() c statement that does, for example
>
> char* name="Chris";
> int age=30;
> printf("My name is %s", name);
> printf("My name is %s and I am %d years old.", %s, %d);
>
> In other words, printf() has a variable arguement list the we
> all know.
>
> I'm trying to do this in Python...
>
> class MyPrintf(object):
> # blah, blah
>  def myprintf(object, *arg):
>   # Here I'll have to know I NEED 2 arguments in format string
> arg[0]
>   print arg[0] % (arg[1], arg[2])

No you don't: in Python, the % operator on strings expects a tuple as second
operand, and args is already a tuple. So:
print args[0] % arhgs[1:]
will do what you want.

Some stylistic issues:
- You don't have to put everything in a class in Python. Your myprintf looks a
lot like a function to me, so you'll probably want to define it as such.
- Don't use object as the first parameter to methods! object is the top-level
class for the whole class hierarchy, so you certainly don't want to obscure it
with a variable. For methods, use the traditional self as first parameter.
- In your function myprintf, the format string seems to be a required
argument. If it is, you might want to define as such too:

def myprintf(format_string, *args):
  print format_string % args

So now, as you can see, redefining printf in Python is not really
interesting...

HTH anyway.
 - Eric -
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: loading file before entering mainloop

2009-03-16 Thread Eric Brunel
Peter Billam wrote:
>> Peter Billam wrote:
>>   window = MainWindow(application)
>>   if (len(sys.argv) > 1) and os.path.exists(sys.argv[1]):
>>   window.loadFile(sys.argv[1])
>>   application.mainloop()
>>   File "./midimix", line 465, in loadFile
>> space0.grid(row=grid_row,
>>  pady=round(0.5*(ymid[track_num]-ymid[track_num-1]))-50)
>>   ...
>>   _tkinter.TclError: bad pad value "-50": must be positive screen distance
>> presumably because the window doesn't have dimensions before mainloop
>> is entered.  Can I force the window to be laid out before entering
>> mainloop? Or can I invoke loadFile() after mainloop has started ?
>
> On 2009-03-14, Peter Otten <__pete...@web.de> wrote:
>> The latter. Try
>> application.after_idle(window.loadFile, sys.argv[1])
>
> Thank you! That almost worked :-) It opened a window (which it didn't
> do last time), and it laid out the frames and so on apparently OK,
> and even posted a "Loaded v.mid" message on the StatusBar, but then
> just drew a couple of zero-thickness lines right at the top of the
> canvas, and failed with the same message:
>   File "./midimix", line 465, in loadFile
> space0.grid(row=grid_row,
>  pady=round(0.5*(ymid[track_num]-ymid[track_num-1]))-50)
>   File "/usr/local/lib/python3.0/tkinter/__init__.py",
>line 1845, in grid_configure
> + self._options(cnf, kw))
>   _tkinter.TclError: bad pad value "-50": must be positive screen distance
>
> but I say "almost" because I googled after_idle, and the very similar:
> application.after(500, window.loadFile, sys.argv[1])
> does work, exactly as intended :-) except of course that it's a
> race condition, and will fail for very impatient people or on very
> slow machines.  On my machine it still works with 20ms, but fails
> with 10ms.  Is there one extra magic trick I need to know?

I had the same kind of problems with the latest tcl/tk version (8.5):
apparently, the interface goes idle before all widgets are completely
displayed, and tricks like these - that used to work with former tcl/tk
version - now fail...

You may have a better chance with a binding on the '<>' virtual
event, which will trigger when your widget changes its size. You just have to
make sure it'll trigger only once, even if the user resizes the window while
your script is running... The binding should be set on the widget you query to
get its dimensions.

> I also tried invoking after_idle on the canvas widget:
>window.canvas.after_idle(window.loadFile, sys.argv[1])
> but that fails with the same message.
> (I am using python 3.0.1 in case that's, er, relevant.)

On tcl/tk level, 'after idle' is actually a command that doesn't act on a
widget, so calling after_idle on any widget will have exactly the same
behaviour.


On a more general level, if you want to have the same script that can be
called either from a GUI or from the command line, you might want to separate
your "functional" code from the GUI aspects, meaning have a module or a set of
modules containing the part that actually does something, and doesn't know
anything about from where it is called, and another module or set of modules
for the GUI and/or the CLI, which display things nicely and call the first
part when it has to actually do something. This would avoid problems like the
one you have.

> Thanks for your help,  Regards,  Peter

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


Re: tkinter icons as bytestrings, not files?

2009-02-24 Thread Eric Brunel
On Tue, 24 Feb 2009 05:56:12 +0100, Peter Billam   
wrote:



Greetings,

As a newbie, starting with Python3, I'm working my way through Mark
Summerfield's tkinter examples.  In the toolbar, there's lines like:
for image, command in (
('images/filenew.gif',  self.fileNew),
('images/fileopen.gif', self.fileOpen),
('images/filesave.gif', self.fileSave),
('images/editadd.gif',  self.editAdd),
('images/editedit.gif', self.editEdit),
('images/editdelete.gif', self.editDelete),):
image = os.path.join(os.path.dirname(__file__), image)
image = tkinter.PhotoImage(file=image)
self.toolbar_images.append(image)
button = tkinter.Button(toolbar, image=image, command=command)
button.grid(row=0, column=len(self.toolbar_images) -1)

which are always failing because the icons are in the wrong place
and I can't help but wonder if I can put all these little images
in the application itself, either as b'whatever' or uuencoded or
in svg etc, and then invoke some suitable variation of the
image = tkinter.PhotoImage(file=image)
or of the
button = tkinter.Button(toolbar, image=image, command=command)
command ?  (I did try help('tkinter.PhotoImage') but didn't spot a
magic key (unless it's "data=something, format=something")) ...


Just dump the contents of the file as a bytestring and use:
image = PhotoImage(data=the_byte_string)
With no extension, I guess it'll only work with GIF files, as it is the  
only natively supported image format in tcl/tk (AFAIK...).


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Thank you, Tkinter. (easy to use)

2009-02-12 Thread Eric Brunel

On Thu, 12 Feb 2009 06:06:06 +0100,  wrote:
[snip]

My only (minor) complaint is that Tk
doesn't draw text antialiased in the various widgets (menus, labels,
buttons, etc.).


From version 8.5 of tcl/tk, it's supposed to do it. See this page:
http://www.tcl.tk/software/tcltk/8.5.tml
under 'Highlights of Tk 8.5', item 'Font rendering'. It seems to talk only  
about X11 and Mac OS X; don't know if it works on Windows...

--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Possible bug in Tkinter - Python 2.6

2009-01-19 Thread Eric Brunel

On Sun, 18 Jan 2009 01:57:12 +0100, José Matos  wrote:


On Friday 16 January 2009 09:47:36 Eric Brunel wrote:

What do you mean by 'works'...?


The usual meaning, I think. :-)

Click "Yes" and the program prints True, click "No" and the programs  
prints

"False".


This is not the procedure I describe in the original post. The first time,  
it works for me too. It's only after I used the file dialog that it stops  
working.



You don't have the problem? It doesn't  
change a thing for me...


Notice that I am running the system python, that at least is different.


Well, unless you're on a platform where a modified Python version is  
installed, it shouldn't. If you have the same version as mine, the bug  
should be there too...

--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Possible bug in Tkinter - Python 2.6

2009-01-19 Thread Eric Brunel

On Fri, 16 Jan 2009 17:49:50 +0100, Terry Reedy  wrote:


Eric Brunel wrote:
On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy   
wrote:

Eric Brunel wrote:

[snip]>>  And BTW, if this is actually a bug, where can I report it?


bugs.python.org

 Thanks. I reported the problem.


When you report that you reported to problem to the tracker (a good  
idea), please include link so anyone reading this thread can jump there  
to continue with followup there.


Here it is:
http://bugs.python.org/issue4961

Thanks again!
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Possible bug in Tkinter - Python 2.6

2009-01-16 Thread Eric Brunel

On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy  wrote:

Eric Brunel wrote:

[snip]>>  And BTW, if this is actually a bug, where can I report it?


bugs.python.org


Thanks. I reported the problem.
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Possible bug in Tkinter - Python 2.6

2009-01-16 Thread Eric Brunel

On Thu, 15 Jan 2009 19:09:00 +0100, José Matos  wrote:


On Thursday 15 January 2009 15:28:36 r wrote:

First of all be very careful using from "module" import * or you will
have name conflicts. Tkinter is made to be imported this way and i do
it all the time. for the others do.

import tkMessageBox as MB
import tkFileDialog as FD
or whatever floats your boat.


Importing explicitly works for me in Fedora 11 (rawhide):
-
from Tkinter import *
from tkMessageBox import askyesno
from tkFileDialog import askopenfilename

[snip]

What do you mean by 'works'...? You don't have the problem? It doesn't  
change a thing for me...

--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Possible bug in Tkinter - Python 2.6

2009-01-15 Thread Eric Brunel

Hi all,

I found a behaviour that might be a bug in Tkinter for Python 2.6. Here is  
the script:


-
from Tkinter import *
from tkMessageBox import *
from tkFileDialog import *

root = Tk()

def ask_file():
  file_name = askopenfilename()
  print file_name

def ask_confirm():
  answer = askyesno()
  print answer

Button(root, text='Ask file', command=ask_file).pack()
Button(root, text='Ask confirm', command=ask_confirm).pack()

root.mainloop()
-

Scenario:
- Run the script.
- Click the 'Ask confirm' button and answer 'Yes'; it should print True,  
which is the expected answer.

- Click the 'Ask file' button, select any file and confirm.
- Click the 'Ask confirm' button and answer 'Yes'.

At the last step, the script prints 'False' for me, which is quite wrong.  
Can anybody confirm this?


I reproduced this problem on Linux Fedora Core 4 and Suse Enterprise  
Server 9, and on Solaris 8 for Sparc and Solaris 10 for Intel. However, it  
seems to work correctly on Windows 2000. I could only test with Python  
2.6, and not 2.6.1. But I didn't see any mention of this problem in the  
release notes.


And BTW, if this is actually a bug, where can I report it?

TIA
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: State of the art: Tkinter, Tk 8.5, Tix?

2009-01-08 Thread Eric Brunel

On Wed, 07 Jan 2009 20:31:23 +0100, excord80  wrote:


Does Python work with Tk 8.5? I'm manually installing my own Python
2.6.1 (separate from my system's Python 2.5.2), and am about to
install my own Tcl/Tk 8.5 but am unsure how to make them talk to
eachother. Should I install Tk first? If I put Tk into my home
directory (under "~/opt" most likely), is there some configure option
I need to pass Python to tell it where to find my Tk?


There's some important information missing here: the platform you're on...

Anyway, you should indeed install tcl/tk first. Then, assuming you're on  
Linux, you should edit the file named Setup in the Modules sub-directory  
of your Python installation, find the lines for the _tkinter module and  
edit them to match your installation. Then, you can build and install  
Python and it should work without problem.


As for Python 2.6 / tk 8.5 compatibility, it depends on what you want to  
do. Since tk 8.5 still offers the 'regular' tk widgets, these will work in  
Python 2.6. If you want the new widgets (aka ttk), I'm not sure there are  
official wrappers for them in the distro (there weren't any last time I  
checked). If there aren't, you can find the 'pre-official' ones here:  
http://pypi.python.org/pypi/pyttk



Also, I see that Python comes with Tix. Was Tix supposed to be
something to make up for what was lacking in Tk prior to its 8.5
release? Is Tix here to stay, or has it been eclipsed by what comes
with Tk 8.5 OOTB?


I've never worked with Tix myself, but I'd say the widget set offered by  
tk/ttk is now quite complete.


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Structure using whitespace vs logical whitespace

2008-12-16 Thread Eric Brunel
On Tue, 16 Dec 2008 10:00:32 +0100, Gabriel Genellina  
 wrote:


En Mon, 15 Dec 2008 14:29:31 -0200, cmdrrickhun...@yaho.com  
 escribió:



PS. In my opinion the solution would be to have the option of entering
a "whitespace insensitive" mode which uses C style {} and ;.  The
token to enter it could be as complicated as you want (in fact, it may
make sense to make it complicated to discourage use unless it's really
advantageous).  I'd sugest {{ and }} or something bigger like {={ }
=}.  Only two problems: 1) I'm sure it would offend Guido's sense of
language aesthetics  2) I'm sure the idea has been hashed over on this
newsgroup to death... hence prefering a workaround instead.


It's a hidden feature, already implemented. Try:

 from __future__ import braces


I was almost shocked so I tried it. It's much clearer now... ;-)
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Tkinter and asyncronous socket

2008-11-27 Thread Eric Brunel
On Fri, 28 Nov 2008 04:20:22 +0100, Hendrik van Rooyen  
<[EMAIL PROTECTED]> wrote:

If you are not already doing it, you need to make a "stutter thread"
by using the after() call on some gui object to periodically check for
input on the queue.


You don't need to in fact: from the secondary thread, it seems to be safe  
to post a user-defined event in the GUI event loop on which you can set a  
binding in the GUI thread. This allows a thread switch without having to  
do a periodical check.


Here is an example:


import time
from threading import Thread
from Tkinter import *

root = Tk()

v = IntVar()
v.set(0)

Label(root, width=8, textvariable=v).pack()

def incr_counter(event=None):
  v.set(v.get() + 1)

root.bind('<>', incr_counter)

def heartbeat():
  while 1:
time.sleep(1)
root.event_generate('<>', when='tail')

th = Thread(None, heartbeat)
th.setDaemon(True)
th.start()

root.mainloop()


The custom event '<>' is posted in the event loop from the  
secondary thread. Note the when='tail' option, which is absolutely  
necessary or the binding might be called immediatly without even an actual  
event posting. The binding on this event will then be executed in the  
thread that launched the mainloop.


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Build of extension module depending on external lib fails on Solaris 10

2008-11-21 Thread Eric Brunel

Hello all,

I've got a brand new Solaris 10 computer and I'm trying to build Python  
and extension modules for it. The Python build didn't have any problem and  
I have a working Python interpreter. But I can't succeed to build  
extension modules depending on external libraries: The compilation works,  
and object files are produced, but the link always fails.


Here is an example of a failing setup.py file:

from distutils.core import setup, Extension

setup(
  name='spam',
  version='1.0',
  ext_modules=[
Extension('spam', ['spam.c'], library_dirs=['.'], libraries=['spam'])
  ]
)


The 'spam' external module is basically a copy of the one appearing in the  
'Extending and Embedding' manual, except it also contains a call to a  
function in libspam.a, which just does a printf.


Here is the result of the command 'python setup.py build':

running build
running build_ext
building 'spam' extension
gcc -shared build/temp.solaris-2.10-i86pc-2.6/spam.o -L. -lspam -o  
build/lib.solaris-2.10-i86pc-2.6/spam.so

Text relocation remains referenced
against symbol  offset  in file
   0xa ./libspam.a(spamlib.o)
printf  0xf ./libspam.a(spamlib.o)
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1


It seems the problem lies in the order on which the object files and  
libraries appear in the link command line, because if I run the same  
command with the libraries before the object files:
gcc -shared -L. -lspam build/temp.solaris-2.10-i86pc-2.6/spam.o -o  
build/lib.solaris-2.10-i86pc-2.6/spam.so
the link works without problem and a working shared object file is  
produced.


Did anybody have this kind of problem? Is it a bug, or am I doing  
something wrong? And is there a workaround?


Thanks in advance.
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Possible bug in Tkinter for Python 2.6

2008-11-20 Thread Eric Brunel

On Wed, 19 Nov 2008 18:51:03 +0100, Terry Reedy <[EMAIL PROTECTED]> wrote:


Anton Vredegoor wrote:

On Wed, 19 Nov 2008 10:57:53 +0100
"Eric Brunel" <[EMAIL PROTECTED]> wrote:


I'm trying out Python 2.6 and I found what might be a bug in the
Tkinter module. How can I report it?

 maybe here:
http://bugs.python.org/issue3774


The fix will be in 2.6.1, which might be in December.


Thanks! Quite easy to fix anyway, but I prefer having an official version.
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Possible bug in Tkinter for Python 2.6

2008-11-19 Thread Eric Brunel

Hello all,

I'm trying out Python 2.6 and I found what might be a bug in the Tkinter  
module. How can I report it?


The possible bug is a traceback when trying to delete a menu item in a  
menu where no items have associated commands.


For example:
--
from Tkinter import *

root = Tk()

mb = Menu(root)
root.configure(menu=mb)

fm = Menu(mb)
mb.add_cascade(label='File', menu=fm)

fm.add_command(label='Open')
fm.add_command(label='Quit')

def remove_menu_item():
  fm.delete(1)

Button(root, text='Remove menu item',  
command=remove_menu_item).pack(padx=12, pady=24)


root.mainloop()
--

Clicking on the button should remove the 'Open' item in the 'File' menu,  
but ends up in a traceback:
  File "/opt/Python2.6+Tk8.5/bin/Linux/lib/python2.6/lib-tk/Tkinter.py",  
line 1410, in __call__

return self.func(*args)
  File "menu.py", line 15, in remove_menu_item
fm.delete(1)
  File "/opt/Python2.6+Tk8.5/bin/Linux/lib/python2.6/lib-tk/Tkinter.py",  
line 2670, in delete

if c in self._tclCommands:

It just seems the _tclCommands attribute on menus is initialized to None  
and never changed if none of the items actually have a command.


Thanks!
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: tkinter textwidget problem

2008-10-03 Thread Eric Brunel

On Thu, 02 Oct 2008 21:57:01 +0200, kib2 <[EMAIL PROTECTED]> wrote:

Hi,

In a tkinter TextWidget I would like to retrieve the last typed word.

I've tried this with the 'wordstart' Expression [From the effbot site,  
"wordstart" and "wordend" moves the index to the beginning (end) of the  
current word. Words are sequences of letters, digits, and underline, or  
single non-space characters.], but it fails :


#!/usr/bin/env python
# -*- coding: utf-8 -*-

from Tkinter import *
root = Tk()
text = Text(root, font=("Calibri"))
text.pack()

# Insert some text inside (13 chars long)
text.insert(INSERT, "one two three")

# idx_st : the position of the cursor
# idx_ed : same but translated to the beginning of the last word ?
idx_st = text.index( "insert" ) # returns 1.13
idx_ed = text.index( "insert wordstart" ) # returns 1.13 too : why ?


Tk/Tkinter apparently considers the position 1.13 to be after the last  
word in the text. You get the same problem if you set the insertion point  
just after the word 'two' for example: text.index('insert') returns 1.7  
and text.index('insert wordstart') returns 1.7 too...


My solution would simply be to go back one character before asking the  
word start: text.index('insert - 1 chars wordstart') Don't know if that'll  
do what you want if there are spaces at the end of the text. And BTW, if  
you actually want the *last* word in the text, you may want to use  
text.index('end - 2 chars wordstart'). Here, you have to use '- 2 chars'  
because end points to the first non-existent index (2.0 in your case...).


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Python is slow?

2008-09-24 Thread Eric Brunel
On Tue, 23 Sep 2008 15:23:12 +0200, sturlamolden <[EMAIL PROTECTED]>  
wrote:

[...]

Would it be possible to post this text to some "persistent" web page with  
(links to) the code you wrote in both languages? This would be a very  
interesting resource for people experiencing some resistence when they  
suggest Python as a possible language because of the 'Python is slow'  
myth...

--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Tkinter Unix and Windows incompatibility

2008-08-27 Thread Eric Brunel

On Wed, 27 Aug 2008 06:50:30 +0200, akineko <[EMAIL PROTECTED]> wrote:

Hello everyone,

I'm trying to create custom Tkinter/Pmw widgets for my project.
After testing my widgets under Unix (Solaris), I have tried them under
Windows and I got a surprise.

The widgets came out differently.
The following simple code snippet demonstrates the difference:

root = Tk()

w = Canvas(root, width=12, height=12, bd=4, relief=RAISED,
bg='cyan')
w.create_rectangle(5,5,16,16,fill='blue', outline='black')
w.pack()

w2 = Canvas(root, width=12, height=12, bd=0, relief=RAISED,
bg='purple')
w2.create_oval(0,0,12+1,12+1,fill='blue', outline='')
w2.pack()

w3 = Canvas(root, width=32, height=32, bd=4, relief=RAISED,
bg='purple')
w3.create_oval(4+0,4+0,4+32+1,4+32+1,fill='blue', outline='')
w3.pack()

root.mainloop()

//

I noticed the difference because rectangle (or oval) object on the
canvas covers the entire canvas such that small differences in size
are very noticeable.
As Tkinter is a thin wrapper layer for Tk, I'm suspecting the
differences are rooted in Tk.
I'm using TK8.5 under Unix while Python under Windows uses TK8.4.

As I don't have any access to Python under Windows with TK8.5, I
cannot verify if this problem is fixed under TK8.5 for Windows.

//

So, here are my questions:
(1) Can anybody who has access to Python under Windows with TK8.5 to
verify if the problem is fixed.
If the problem is fixed, rectangle and ovals are inscribed to the
canvas boundary nicely.
If not, you see the rectangle is off by one pixel and the radius is
one pixel larger, I think. The boundary width is also not correct
(right side is one pixel wider).
(2) As the official distribution of Python under Windows uses TK8.4,
what is the best approach to make my widgets to work correctly under
both environment?
 - I could use sys.platform to code differently so that they look the
same.
  - I'm afraid this creates a problem when TK8.5 is finally introduced
to Python under Windows.

Any suggestions?


I didn't really test your code, but I know there have been a few problems  
with the Canvas relief and border for quite a while now. For example, the  
Canvas border has a tendency to disappear when the Canvas is scrolled.  
Don't know if it's fixed in the latest version.


The usual workaround is to create canvases with a flat relief and 0  
border, and add the relief if you want one via a surrounding Frame. In  
your example, for the first Canvas, that would be:


f = Frame(root, bd=4, relief=RAISED)
f.pack()
w = Canvas(f, width=12, height=12, bg='cyan')
w.create_rectangle(1, 1, 12, 12, fill='blue', outline='black')
w.pack()

This may solve your problem.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Handling Property and internal ('__') attribute inheritance and creation

2008-08-19 Thread Eric Brunel

On Fri, 15 Aug 2008 20:02:36 +0200, Rafe <[EMAIL PROTECTED]> wrote:
[snip]

1) 'Declaring' attributes - I always felt it was good code practice to
declare attributes in a section of the class namespace. I set anything
that is constant but anything variable is set again  in __init__():

Class A(object):
name = "a name"
type = "a typee"
childobject = None

def __init__(self, obj):
self.childobject = object

This makes it easy to remember and figure out what is in the class.
Granted there is nothing to enforce this, but that is why I called it
'code practice'. Do you agree or is this just extra work?


To add to what others have already said, it is not only 'just extra work',  
it is also quite dangerous. See:


class A(object):
  children = []

Now *all* A instances share the *same* list, as it was defined as a class  
attribute. If you ever forget to set it to something else in __init__,  
you're in for big surprises.


What I'm doing is set all instance attributes right at the beginning of  
the __init__ with a huge comment before them, like:


class A(object):
  def __init__(self):
## INSTANCE ATTRIBUTES:
## 
self.children = []

This way, you still can 'figure out what is in the class' quite quickly,  
without the drawbacks of declaraing class attributes.


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Tkinter tab focus traversal causes listbox selection to clear, ie, lose the selected item

2008-08-14 Thread Eric Brunel
On Thu, 14 Aug 2008 04:49:51 +0200, Gerardo ARnaez <[EMAIL PROTECTED]>  
wrote:



Hi.
I am writing a program to help determine coumadin regimens
to look at the code: http://sourceforge.net/projects/coumadinregimen/

The issue is that I have a variable that I want the use to select if
they don't like the default.
I have made this as a listbox widget

The rest of the gui is just entry widgets

What I noticed is that when I tab to through the entry  widgets, I
lose the listbox selection: the item selected, gets unselected.

Not sure what is happening,hope I have explained it.


Usual tk/Tkinter pitfall: the selected item in a list box is by default  
considered as a text selection. Since you can only have one text selected  
at a time, selecting anything anywhere will unselect the item in the list.  
To avoid this, use the exportselection=0 option when you're creating your  
Listbox.



Thanks,
G


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Tkinter updates - Easiest way to install/use Tile?

2008-08-14 Thread Eric Brunel

On Wed, 13 Aug 2008 19:10:47 +0200, Mudcat <[EMAIL PROTECTED]> wrote:
[snip]

I was reading about Tile, and it sounds like I should be able to wrap
a style around my current code to give it a different look. However it
doesn't sound like it's quite ready for prime time yet. I downloaded
the latest stable version of Python 2.5 which apparently still uses
Tcl 8.4. So my options at this point appear to be:

1) Download beta version of Python 2.6 which has Tcl 8.5.
Tile is supposed to be included with Tcl 8.5, but there's not much
information on how to use it with older code. Do I still need wrapper
code, or if I install 2.6 will it be available already.


Well, if you do it today and look in the Lib/lib-tk directory, you'll see  
that there is nothing specific to Tile/ttk in any of the module. So ATM,  
new wrappers are needed indeed. If I had to say which wrappers have the  
best chance to actually become "official", I'd bet on Guilherme Polo's  
ones here:

http://gpolo.ath.cx:81/projects/ttk_to_tkinter/
These seem to be the most complete, and somebody's actually working on  
them.



2) Install Tcl 8.5 to use with Python 2.5.
How do you do this? In other posts it mentions recompiling source tcl
code with Python. If that's the case it doesn't sound like something I
want to mess with. If I stray too far from default configurations I
start to have problems with py2exe.


I guess it would probably be better to at least recompile the _tkinter.c  
module to get the new tcl/tk header files. I think I also read somewhere  
that there were API incompatibilities between tcl/tk 8.4 and 8.5. Don't  
know if it has any impact on Tkinter.



3) Install Tile with Python 2.5 and Tcl 8.4 and use wrapper code to
make it work.
However all the posts concerning this approach assume that Tile is
already installed. I downloaded the code for the latest version of
Tile which was a .kit extension. This also may need to be compiled,
and if that's the case I again start to have problems with freezing my
application.


This doesn't look like the way to go for me: you'll add the burden of  
having to install the Tile package at tcl/tk level while not gaining  
anything, since you'll still have to use wrappers that may or may not be  
official in the end.



What's the easiest way to do this? I really couldn't find a place that
gave instructions for any of the current release configurations. It
sounds if it's available already in Python 2.6 that it would be the
easiest way, but I couldn't find any threads talking about the
availability of it for that release yet.


As I said above, if I had to choose today, I'd go Python 2.6 + tcl/tk 8.5  
+ Guilherme Polo's ttk wrappers.


But if you can do it, I'd say: just wait. Things are moving fast: the  
latest Python 2.6 beta release is less than a month old, and Guilherme  
Polo has marked his ttk wrappers project as complete only 3 days ago. So  
maybe the next Python beta will actually include them... And BTW, the  
final release for Python 2.6 is planned at the beginning of October, so  
this is not that far away.


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Second python program: classes, sorting

2008-08-11 Thread Eric Brunel
Others have replied to your original question. As an aside, just a few  
stylistic notes:



class Score:
 def __init__(self, name_, score_):
 self.name = name_
 self.score = score_


These trailing underscores look like a habit from another language. They  
are unneeded in Python; you can write:

class Score:
 def __init__(self, name, score):
 self.name = name
 self.score = score
That's an advantage of the explicit self: no ambiguity between local  
variables and attributes.



try:
 infile = open(filename, "r")
except IOError, (errno, strerror):
 print "IOError caught when attempting to open file %s. errno = %d,  
strerror = %s" % (filename, errno, strerror)

 exit(1)


This try/except block is unneeded too: what you do with the exception is  
more or less the same as the regular behaviour (print an error message and  
exit), except your error message is far less informative than the default  
one, and printed to stdout instead of stderr. I would remove the entire  
try/except block and just write:

infile = open(filename, "r")

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Tkinter Entry widgets 'font' property (API ?) changed in Python 2.5.2 ?

2008-08-06 Thread Eric Brunel

On Wed, 06 Aug 2008 06:01:59 +0200, Atul <[EMAIL PROTECTED]> wrote:


Hi,

The snippet :

entryFontDescr = Entry()["font"]
print self.entryFontDescr

On Windows XP it displays

{MS Sans Serif} 8

On Suse Linux 10.2 it used to display

TkTextFont 10

I upgraded to OpenSuse 11 and now it shows

TkTextFont

I used this snippet to obtain the default font size for an Entry
widget. Now with an OS upgrade, my code is broken.

The python version on the upgraded box is

~> python
Python 2.5.2 (r252:60911, Jun  6 2008, 23:32:27)
[GCC 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]] on
linux2
Type "help", "copyright", "credits" or "license" for more information.




I dont remember the exact version of Python on the earlier Suse 10.2
box

My questions:

1. Is this not an API change ? I looked up Python's release
documentation and didn't find any mention of the same.


Tkinter is a very thin wrapper over an embedded tcl/tk interpreter. So I  
guess the API change is caused by a tcl/tk version change, not by a Python  
one. You can check the version of the tcl/tk interpreter you're using from  
Python via:


root = Tkinter.Tk()
root.tk.eval('puts $tcl_patchLevel')
root.tk.eval('puts $tk_patchLevel')


2. How can I achieve what I want alternatively ?


I'd use this way:

import tkFont
entryFontDescr = Entry()["font"]
entry_font = tkFont.Font(font=entryFontDescr)
print entry_font.actual()


Regards,
-- Atul


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: tkinter, loading image error, TclError: couldn't recognize data in image file "C:/users/me/desktop/images/blob4.jpg"

2008-06-30 Thread Eric Brunel
On Sun, 29 Jun 2008 13:34:37 +0200, defn noob <[EMAIL PROTECTED]>  
wrote:



from Tkinter import *
import os

master = Tk()
w = Canvas(master, width=800, height=600)

print os.path.exists('C:/me/saftarn/desktop/images/blob4.jpg')

im = PhotoImage(file = 'C:/users/saftarn/desktop/images/blob4.jpg')

[snip]



True

Traceback (most recent call last):
  File "C:/Python25/Progs/ImageVideoSearch/imId.py", line 9, in

im = PhotoImage(file = 'C:/users/me/desktop/images/blob4.jpg')
  File "C:\Python25\lib\lib-tk\Tkinter.py", line 3270, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Python25\lib\lib-tk\Tkinter.py", line 3226, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't recognize data in image file "C:/users/me/desktop/
images/blob4.jpg"






it has worked before opening and displaying a file like this, anything
to do with python 2.52, upgraded from 2.5.1


Did it? Because AFAIK, tcl/tk has never natively recognized any other  
image format than PPM/PGM and GIF... No JPG, no PNG...

--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: inheritance question...

2008-06-23 Thread Eric Brunel
Preamble: when posting a brand new question, you'd better not replying to  
an existing completely unrelated message. In most viewers, this will cause  
your message to appear in the thread for the original question and far  
less people will see it. So better create a brand new thread.


On Fri, 20 Jun 2008 23:19:37 +0200, Hamish McKenzie  
<[EMAIL PROTECTED]> wrote:

I have this class:

class Vector(object):
 TOL = 1e-5
 def __eq__( self, other, tolerance=TOL ):
   print tolerance


shortened for clarity obviously.  so I want to subclass this class like
so:

class BigVector(Vector)
 TOL = 100


for example if I was working with large vectors which I knew would never
be very close hence the large tolerance.  this doesn't work however -
the TOL class variable, while overridden in BigVector, is still using
the Vector.TOL variable in the __eq__ method.


which kinda makes sense to a certain degree, but how do I get the
behaviour where doing:

BigVector().__eq__( otherVec )


prints 100 instead of 1e-5?

does this question make sense?  not sure how clearly I'm phrasing my
question...  any of you guys python experts?


There's just no way. The default values for function/method arguments are  
evaluated when the function definition is interpreted. When the __eq__  
method is defined, TOL is 1e-5, so that will be the value used in the  
method, whatever you may do afterwards.




I *could* do this, but its ugly:

class Vector(object):
 TOL = 1e-5
 def __eq__( self, other, tolerance=None ):
   if tolerance is None: tolerance = self.TOL
   print tolerance


Well, ugliness is in the eye of the beholder... ;-) Even if you find it  
ugly, that's the Python way to do it.


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Python is slow

2008-05-23 Thread Eric Brunel

On Fri, 23 May 2008 12:48:56 +0200, > wrote:


"inhahe" <[EMAIL PROTECTED]> writes:

planets are spherical (all implementations of Python are not natively
compiled (and you said for whatever definition)), and b) It's a far cry  
to

imagine a planet coming into being that's not spherical (a language as
dynamic as Python, or most other scripting languages, would be either
extremely difficult or impossible to make a native compiler for).


There are native Python compilers, see psyco and pypy.


... and C/C++ interpreters; see:
http://root.cern.ch/twiki/bin/view/ROOT/CINT
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Simple TK Question - refreshing the canvas when not in focus

2008-05-02 Thread Eric Brunel

On Wed, 30 Apr 2008 20:19:32 +0200, blaine <[EMAIL PROTECTED]> wrote:


On Apr 30, 10:41 am, Peter Otten <[EMAIL PROTECTED]> wrote:

blaine wrote:
> Still doesn't work.  I'm looking into using wx instead...

> This is the full code - does it work for anyone else? Just do a echo
> 'line 0 0 10 10' > dev.file

Haven't tried it, but I think that the problem is that you are updating  
the
UI from the "readthread". A good example to model your app after is  
here:


http://effbot.org/zone/tkinter-threads.htm

Peter


Update: Not only is that a good model, its exactly what I'm trying to
do.  Thanks again!


BTW, instead of reading the queue periodically, you can also use the event  
loop for that: in the secondary thread, generate a custom event using the  
event_generate method. Custom events are enclosed in '<<...>>', the '...'  
can be whatever you like. Be sure to generate the event with the  
when='tail' option or the event might get handled immediatly. To treat the  
event, do a binding on it: it will be called in your main thread. It's a  
common trick to switch threads so that GUI events are treated in the main  
thread and not in secondary ones.


Example:

--
import threading
import time
import Queue
from Tkinter import *

root = Tk()

q = Queue.Queue()

def thread_action():
  i = 1
  while 1:
time.sleep(1)
q.put(i)
root.event_generate('<>', when='tail')
i += 1

v = StringVar()

def ping_received(event):
  v.set(q.get())

Label(root, textvariable=v, width=10).pack()
root.bind('<>', ping_received)

th = threading.Thread(target=thread_action)
th.setDaemon(1)
th.start()

root.mainloop()
--

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Simple TK Question - refreshing the canvas when not in focus

2008-04-30 Thread Eric Brunel
On Wed, 30 Apr 2008 10:58:06 +0200, Robert.Spilleboudt   
<[EMAIL PROTECTED]> wrote:



blaine wrote:

Hey everyone!
  I'm not very good with Tk, and I am using a very simple canvas to
draw some pictures (this relates to that nokia screen emulator I had a
post about a few days ago).
 Anyway, all is well, except one thing.  When I am not in the program,
and the program receives a draw command (from a FIFO pipe), the canvas
does not refresh until I click into the program. How do I force it to
refresh, or force the window to gain focus?  It seems like pretty
common behavior, but a few things that I've tried have not worked.
 Class screen():
def __init__(self):
self.root = Tkinter.Tk()
self.root.title('Nokia Canvas')
self.canvas = Tkinter.Canvas(self.root, width =130,
height=130)
self.canvas.pack()
self.root.mainloop()
 Then somewhere a long the line I do:
self.canvas.create_line(args[0], args[1], args[2],
args[3], fill=color)
self.canvas.pack()
 I've tried self.root.set_focus(), self.root.force_focus(),
self.canvas.update(), etc. but I can't get it.
Thanks!
Blaine
When you read the pipe,  do you generate an event? Probably not , and Tk  
is event-driven and should never update the canvas if there is no event.

This is how I understand Tk.

I have a Tk program who reads a audio signal (from an RC transmitter) .  
I generate a event every 100 msec , and "process" refresh the canvas.

Starting the sequence:
id = root.after(100,process)  will call "process" after 100 msec
At the end of "process", repeat:
id = root.after(100,process)
Robert


Your method actually works and is in fact even clearer: you explicitely  
give back the control to the main event loop by sending the event. But the  
call to 'update' should also work, since it also gives back the control to  
the main event loop, implicitely however. BTW, the pending events *are*  
treated by a call to update, which can cause some surprises...

--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Simple TK Question - refreshing the canvas when not in focus

2008-04-30 Thread Eric Brunel

On Tue, 29 Apr 2008 17:09:18 +0200, blaine <[EMAIL PROTECTED]> wrote:
[snip]

I'll try the update() again.  I would want to use that on the canvas
itself right? Not the root window?


Well, in fact, there is no difference at all... In tcl/tk, update is a  
function, and isn't applied to a particular widget. Any call to the update  
method on any widget should refresh the whole GUI.


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Simple TK Question - refreshing the canvas when not in focus

2008-04-29 Thread Eric Brunel

On Tue, 29 Apr 2008 15:22:12 +0200, blaine <[EMAIL PROTECTED]> wrote:


Hey everyone!
  I'm not very good with Tk, and I am using a very simple canvas to
draw some pictures (this relates to that nokia screen emulator I had a
post about a few days ago).

Anyway, all is well, except one thing.  When I am not in the program,
and the program receives a draw command (from a FIFO pipe), the canvas
does not refresh until I click into the program. How do I force it to
refresh, or force the window to gain focus?  It seems like pretty
common behavior, but a few things that I've tried have not worked.

Class screen():
def __init__(self):
self.root = Tkinter.Tk()
self.root.title('Nokia Canvas')
self.canvas = Tkinter.Canvas(self.root, width =130,
height=130)
self.canvas.pack()
self.root.mainloop()

Then somewhere a long the line I do:
self.canvas.create_line(args[0], args[1], args[2],
args[3], fill=color)
self.canvas.pack()


Unrelated question: why are you doing a .pack() again here? Packing the  
widget just inserts it at the right place in its container, so you only  
have to do it once. So the one you did in __init__ is enough.



I've tried self.root.set_focus(), self.root.force_focus(),
self.canvas.update(), etc. but I can't get it.


IIRC:
- self.root.set_focus() will only work if your application already has the  
focus, so it's not what you need here.
- self.root.force_focus() is usually considered as evil: it'll give the  
focus to your application whatever the user is doing, which is usually  
*really* annoying. So I guess a lot of window managers just refuse to do  
it; this may be what happens here.


But self.canvas.update() should work. If it doesn't, then there are  
probably limitations on your platform that prevents it to work... Do you  
happen to have other applications that can update their display while they  
don't have the focus? Do they have the same problem? If they do, it's  
probably a limitation on the platform and I guess you won't be able to do  
anything about it... BTW, what platform are you on?



Thanks!
Blaine


HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Learning Tkinter

2008-04-17 Thread Eric Brunel
On Wed, 16 Apr 2008 14:46:13 +0200, Doran, Harold <[EMAIL PROTECTED]> wrote:
[snip]
> Second, I am trying to work through a couple of the examples and make
> some small tweaks as I go to see how new things can work. In the first
> case, I have copied the code in the book to see how the menu works and
> are created as in the example menu.py below. I see how menus are created
> and how the command option is used to call the function callback.
>
> # menu.py
> from Tkinter import *
>
> def callback():
> print "called the callback!"
>
> root = Tk()
>
> # create a menu
> menu = Menu(root)
> root.config(menu=menu)
>
> filemenu = Menu(menu)
> menu.add_cascade(label="File", menu=filemenu)
> filemenu.add_command(label="New", command=harold)
> filemenu.add_command(label="Open...", command=callback)
> filemenu.add_separator()
> filemenu.add_command(label="Exit", command=callback)
>
> helpmenu = Menu(menu)
> menu.add_cascade(label="Help", menu=helpmenu)
> helpmenu.add_command(label="About...", command=callback)
>
> mainloop()
>
> However, I now want to incorporate a basic python program with a
> command. Say I have a simple program called test.py
>
> # test.py
> filename = raw_input("Please enter the file you want to open: ")
> new_file = raw_input("Save the output file as: ")
>
> f = open(new_file, 'w')
> new = open(filename, 'r')
>
> for line in new:
>   x = line.split('\t')
>   print >> f, x[0],':', x[1]
> f.close()
>
> To make this example complete assume I have a text file like this
>
> # data.txt
> 1 one
> 2 two
> 3 three
> 4 four
>
> So, the user currently just follows directions on the screen, enters the
> file names, and I get what I want. I'd like to try experimenting with
> gui programming to see if the python programs I have written can be made
> even more user friendly. I currently use py2exe to create executables so
> that others in my organization can use these programs.
> In that spirit, say I want to have a menu option that allows the user to
> search their computer for this file, execute the python code and then
> save the result as a user-defined filename. So, I guess my questions are
> how do I associate the portion of code in menu.py
> "filemenu.add_command(label="Open...", command=callback)" with an
> operation that gives the user the ability to search the drives on their
> machine and then once they do let python execute the code in test.py?

The way it's written, you'll have a hard time doing it... Since test.py  
already includes a "user interface" via the raw_input calls, executing  
test.py will always ask the user for the file names, and there's no simple  
way to pass them otherwise as the module is written.

Considering how you asked the question, I'll assume you don't know Python  
very much; my apologies in advance if it's not the case...

So, what I would do is rewrite the test.py script as follows:

--- test.py ---
def convert_file(filename, new_file):
   f = open(new_file, 'w')
   new = open(filename, 'r')

   for line in new:
 x = line.split('\t')
 print >> f, x[0],':', x[1]
   f.close()

if __name__ == '__main__':
   filename = raw_input("Please enter the file you want to open: ")
   new_file = raw_input("Save the output file as: ")
   convert_file(filename, new_file)
---

This is basically the same as yours in another order, and defining a  
function that actually does the 'functional' part without asking the user  
anything. The last block - starting with this weird 'if __name__ ==  
'__main__':' - ensures the script will work as you expect when you run it  
alone on the command line (with 'python test.py'). This is the meaning of  
the test on __name__: this magical variable is set to the string  
'__main__' if and only if the current script is the top-most one, i.e the  
one you ran python on. So basically, the script now defines a function,  
then asks for the function parameters and calls it _only if run as the  
main script_. Try it; it should have the same behaviour as the script  
you've written.

But the test on __name__ also allows to *import* this script as a module  
in another script without nasty side effects. This is done via the  
statement:

import test

in the other script. If test.py is written as above, this will execute the  
function definition, but not the body of the 'if', since test.py is no  
more run from the command line, but used in an import. If you didn't have  
this test, the module would have been *executed* by the import, and is  
would have asked the file names immediatly.

Once you've done the import, you can then use the function it defines by  
calling test.convert_file. So now, in your GUI part, you can now write  
something like:


--- menu.py --
## NEW! the next line gets the 'convert_file' function
import test
 from Tkinter import *
## NEW! the next line gets the functions used to get file names via

Re: 答复: how to remove \n in the list

2008-04-14 Thread Eric Brunel
(please avoid top-posting... corrected)
On Mon, 14 Apr 2008 09:08:06 +0200, Penny Y. <[EMAIL PROTECTED]> wrote:
> -邮件原件-
> 发件人: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] 代表 Gabriel
> Genellina
> 发送时间: 2008年4月14日 12:59
> 收件人: python-list@python.org
> 主题: Re: how to remove \n in the list
>
> En Mon, 14 Apr 2008 01:41:55 -0300, reetesh nigam
> <[EMAIL PROTECTED]> escribió:
>
>> hi,
>> l=['5\n', '2\n', '7\n', '3\n', '6\n']
>>
>> how to remove \n from the given list
>
> l is is very poor name... I'll use lines instead:
>
> lines[:] = [line.rstrip('\n') for line in lines]
> ---
>
> why not just:
>
> lines = [line.rstrip('\n') for line in lines]
>
>
> what's the difference between lines[:] and lines here? Thanks.

Compare:

>>> lines = ['5\n', '2\n', '7\n', '3\n', '6\n']
>>> lines2 = lines
>>> lines = [line.rstrip('\n') for line in lines]
>>> lines
['5', '2', '7', '3', '6']
>>> lines2
['5\n', '2\n', '7\n', '3\n', '6\n']

with:

>>> lines = ['5\n', '2\n', '7\n', '3\n', '6\n']
>>> lines2 = lines
>>> lines[:] = [line.rstrip('\n') for line in lines]
>>> lines
['5', '2', '7', '3', '6']
>>> lines2
['5', '2', '7', '3', '6']

Assigning to lines[:] changes the original list. Assigning to lines  
rebinds the name to the result of the list comprehension, but doesn't  
affect the original list.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter menus from keyboard

2008-03-26 Thread Eric Brunel
On Wed, 26 Mar 2008 13:45:29 +0100, Guilherme Polo <[EMAIL PROTECTED]>  
wrote:

> 2008/3/26, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>> Tkinter defaults to, for example, Alt+f = File (if File is your first
>>  menu name starting with "f").
>>
>>  I'd like to assign my own letters and have them underscored, per the
>>  universal standard. Can this be done?
>>
>
> Set the underline option to the index of the desired letter

BTW, this "standard" is not universal at all: e.g, there is no such  
convention on Macs. Not (only...) nitpicking: if your application has to  
run on a Mac, it may look weird if you use this option... But I never  
tested how it was handled on Macs.

My $0.02...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritance question

2008-03-25 Thread Eric Brunel
On Tue, 25 Mar 2008 16:37:00 +0100, Brian Lane <[EMAIL PROTECTED]> wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Gerard Flanagan wrote:
>
>> Use the child class when calling super:
>>
>> --
>> class Foo(object):
>> def __init__(self):
>> self.id = 1
>>
>> def getid(self):
>> return self.id
>>
>> class FooSon(Foo):
>> def __init__(self):
>> Foo.__init__(self)
>> self.id = 2
>>
>> def getid(self):
>> a = super(FooSon, self).getid()
>> b = self.id
>> return '%d.%d' % (a,b)
>>
>> print FooSon().getid()
>> --
>
> That still doesn't do what he's trying to do.
>
> The problem here is that you only have one instance. self refers to it,
> so when you set self.id in the super you have set the instance's id to
> 1. When you set it to 2 after calling the super's __init__ you are now
> setting the *same* variable to a 2.
>
> Basically, you can't do what you are trying to do without using a
> different variable, or keeping track of a separate instance for the
> super instead of sub-classing it.

If for any reason it's better to have the same attribute name, it might be  
a case where a "pseudo-private" attribute - i.e. prefixed with __ - can be  
handy:

--
class Foo(object):
 def __init__(self):
 self.__id = 1
 def getid(self):
 return self.__id

class FooSon(Foo):
 def __init__(self):
 Foo.__init__(self)
 self.__id = 2
 def getid(self):
 a = super(FooSon, self).getid()
 b = self.__id
 return '%d.%d' % (a,b)

print FooSon().getid()
--

For an explanation, see here:  
http://docs.python.org/ref/atom-identifiers.html

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Menu Item Activation

2008-02-26 Thread Eric Brunel
On Fri, 22 Feb 2008 13:30:06 +0100, <[EMAIL PROTECTED]> wrote:
[snip]
> Sub problems: how to change state of menu item? how to detect changes
> in Text widget?

If you have a reasonably recent tcl/tk version (>= 8.4), you should have a  
edit_modified() method on your Text telling you if it has been modified  
since you last called edit_modified(False).

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter OSX and "lift"

2008-02-22 Thread Eric Brunel
On Thu, 21 Feb 2008 16:53:14 +0100, Kevin Walzer <[EMAIL PROTECTED]>  
wrote:
> Miki wrote:
>> Hello Kevin,
>>
>>> Tk.lift doesn't seem to work on OSX (Python 2.5.1).
 If you click on the PythonLauncher application that runs in your dock
 when this script is executed, the window comes into focus fine.
>> You're right, but I want to window to be initially in focus (without
>> the user clicking on the python launcher icon).
>
> "Lift" (which calls the Tk command "raise") doesn't work this way, at  
> least not under Aqua. If your application has focus, "lift" will raise  
> the widget being called to the top of the stacking order. However, it  
> will not make the application frontmost. To do this you'd have to use  
> Carbon calls (look at Carbon.CarbonEvt) or use a Tk extension and call  
> it from Python. Of course, this is pretty much a non-issue if your  
> application is wrapped as a standard Mac application bundle via  
> py2app--most Mac users don't run Python apps from the Terminal but  
> instead double-click an application icon. In that event, "lift" should  
> work fine, because the application will already have focus.

There is a trick that sometimes works even for interpreted application:

import Tkinter as tk
root = tk.Tk()
root.withdraw()
# Code building the window...
root.lift()
root.deiconify()
root.mainloop()

This sometimes forces the window to be top-most. If this doesn't work, you  
can also try:

import Tkinter as tk
root = tk.Tk()
root.withdraw()
# Code building the window...
root.lift()
root.after_idle(root.deiconify)
root.mainloop()

This was a trick that had to be done on Windows a few years back to force  
the main window to be created on top of this others. It deosn't seem to be  
needed anymore now, but maybe the trick can be used on a Mac... Don't know  
if this will work the same, though...

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter. Why the Need for a Frame, or no Frame?

2008-02-18 Thread Eric Brunel
On Sun, 17 Feb 2008 13:31:47 +0100, W. Watson <[EMAIL PROTECTED]>  
wrote:
> Thanks very much. I'm somewhat new to this, but I would think that Frame  
> might carry some properties not available to the root. If so, then there  
> might be some advantage to it.

(Please don't top-post... It makes the individual messages very hard to  
read. Thanks.)

In fact, it's exactly the reverse: the root or the instances of Toplevel  
have some properties that are not available to frames, for example the  
ability to have a menu bar. As already said, frames are only used to group  
widgets to do complicated layouts. In the example you gave, the frame is  
unneeded, and I'd say it should not be there (the only thing it achieved  
was just to confuse you...).

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python GUI toolkit

2008-02-04 Thread Eric Brunel
On Sun, 03 Feb 2008 20:38:41 +0100, Thomas Dybdahl Ahle <[EMAIL PROTECTED]>  
wrote:
[snip]
> Another toolkit you might look into is Tkinter. I think it is something
> like the "official" toolkit for python. I also think it is an adapter
> for other toolkits, so it will use gtk widgets on gnome, qt widgets on
> kde and some other strange widgets on windows.

No. Tkinter doesn't use any other library and draws its own widgets, which  
until now look like very old-style Motif widgets on Unix. There's a new  
version of tcl/tk (on which Tkinter is based) that has a new look for  
widgets, basically looking like gtk's default theme, but it doesn't use  
gtk at all.

This can be seen as an advantage or a drawback depending on what you're  
looking for:
- this keeps the toolkit very small and independent (no dependency hell)
- this basically ensures that the look won't be "native"

And BTW, the new version of tcl/tk is supposed to look native on Windows &  
MacOS too. Unfortunately, this version is very new and the Tkinter module  
has not been adapted for it yet.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What should I use under *nix instead of freeze?

2008-02-04 Thread Eric Brunel
On Sat, 02 Feb 2008 00:08:21 +0100, Mike Kent <[EMAIL PROTECTED]> wrote:

> In a comment Guido made on a recent bug report for the 'freeze'
> utility, he stated:
>
> "I think nobody really cares about freeze any more -- it isn't
> maintained."
>
> That being the case, what is the preferred/best replacement for freeze
> on a *nix platform?  I'm looking for something that, like freeze,
> turns my application into a single-file executable, of the smallest
> size possible, that can be executed on a machine with no Python
> installation or development system.

Never used it, but it seems cx_Freeze  
(http://python.net/crew/atuining/cx_Freeze/) does just that... Don't know  
if it's maintained anymore, but versions are available for the latest  
Python version (2.5).

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter - incremental input ?

2008-01-30 Thread Eric Brunel
On Wed, 30 Jan 2008 13:32:00 +0100, Helmut Jarausch  
<[EMAIL PROTECTED]> wrote:
[snip]
> While I can bind '' to a callback, I haven't figured out how
> to get (and later on set) the cursor within the Entry widget.
> In other words I need to know at which character position the last
> character was entered.

You can get the position of the insertion point with  
entry.index('insert'), and set it via entry.icursor(index). If you want to  
do this as the user types, take care to bind to KeyRelease; this way, the  
character corresponding to the key has already been entered in the entry.

BTW, you may also want to automatically select the part that the user  
hasn't actually typed. This can be done with entry.selection_clear(), then  
entry.selection_range(start_position, end_position).

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Text widget updates only after calling method exits (threading issue?)

2007-12-12 Thread Eric Brunel
On Wed, 12 Dec 2007 02:58:37 +0100, mariox19 <[EMAIL PROTECTED]> wrote:

> Are Tkinter widgets running on their own thread?

No. And usually, GUI toolkits and threads don't mix well...

> If I try to make a simple application that will print the letters A to
> Z to a Tkinter Text widget, and I space the printing of each letter by
> 1 second, it seems no text will appear in the Text widget until the
> method exits.
>
> Take a look at this snippet:
>
> # Assume I have created no threads other than the one that comes
> with Main
>
> def printToTkinterTextWidget(text):
> """
> Prints A-Z to the Text widget, 1 letter per second.
> """
> # Problem: no text appears in the widget until 26 seconds has
> elapsed
> for aNumber in range(65, 91):
> self.textWidget.insert(END, text)
> time.sleep(1)

time.sleep will not give back the control to the Tkinter mainloop, so your  
text widget won't be refreshed on screen. Try:
self.textWidget.update_idletasks()
before the sleep.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie:this program stops responding after pressing quit button

2007-12-04 Thread Eric Brunel
On Tue, 04 Dec 2007 14:32:34 +0100, Boris <[EMAIL PROTECTED]> wrote:
> I am using windows vista and python 2.5 .This program stops responding
> after pressing quit button. I am not able to figure the problem out.
> please help.
>
> from Tkinter import *
>
> def greeting( ):
> print 'Hello stdout world!...'
>
> win = Frame(
>  )
> win.pack( )

While I can't reproduce the problem you have since I'm on an older  
Python/Tkinter version, I'd say these last two lines are the problem: in  
Tkinter, Frame instances are not windows, but generic containers. Creating  
a Frame instance without having a window implicitly creates one, but you  
have to use some Tkinter internals to manipulate it, which is never a good  
idea. I'd replace these two lines with this one:

win = Tk()

which actually create the main window for the application as well as the  
underlying tcl interpreter, required by Tkinter.

Please note this must be done only for the main window, i.e exactly once  
in your application; other ones must be created as Toplevel instances, not  
Tk ones.

> Label(win,  text='Hello container world').pack(side=TOP)
> Button(win, text='Hello', command=greeting).pack(side=LEFT)
> Button(win, text='Quit',  command=win.quit).pack(side=RIGHT)
>
> win.mainloop( )

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's coming... from unexpected angles.

2007-10-17 Thread Eric Brunel
On Tue, 16 Oct 2007 13:19:26 +0200, Ben Finney  
<[EMAIL PROTECTED]> wrote:

> "Eric Brunel" <[EMAIL PROTECTED]> writes:
>
>> Well, I'd definetely vote for a name change for PyPy, as in french,
>> it's pronounced "pee-pee", and yes, it means what you think it
>> means... ;-)
>
> Does that mean you pronounce the word for the serpent as "pee-thon"?

Yes.

> Anyway, the pronunciation of "Python" (and hence the "Py" in "PyPy")
> is however you pronounce that word in the name of the comedy troupe,
> Monty Python. That's where the name originates, after all.

But the average frenchman will also pronounce "monty pee-thon" (I know:  
that's weird...).
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's coming... from unexpected angles.

2007-10-16 Thread Eric Brunel
On Tue, 16 Oct 2007 11:14:57 +0200, Ben Finney  
<[EMAIL PROTECTED]> wrote:

> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>
>> Just found this:
>
> The direct link to the article is
> http://www.boingboing.net/2007/10/16/french-lady-finds-py.html>.
>
>> I do believe that Python should be somewhat more upfront to brandish
>> it's merits - but then, sneaky ways are ok with me to...
>
> Well, it seems like she's an early adopter: she's eager to use PyPy
> all the time (though she has aliased it to 'pipi').

Well, I'd definetely vote for a name change for PyPy, as in french, it's  
pronounced "pee-pee", and yes, it means what you think it means... ;-)
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform GUI development

2007-10-15 Thread Eric Brunel
On Sat, 13 Oct 2007 06:34:14 +0200, Michael L Torrie  
<[EMAIL PROTECTED]> wrote:
[snip]
> You do have
> to take pains to make the app "feel" native, though.  Like follow the UI
> guidelines of the platform,  etc.

You're absolutely right; I just wanted to add a precision: it's true for  
every toolkit, not only Qt...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform GUI development

2007-10-12 Thread Eric Brunel
On Fri, 12 Oct 2007 10:13:29 +0200, [EMAIL PROTECTED]  
<[EMAIL PROTECTED]> wrote:
> I've been programming in Python for 5 or more years now and whenever I
> want a quick-n-dirty GUI, I use Tkinter. This is partly because it's
> the first toolkit I learnt, but also because it's part of the standard
> Python distribution and therefore easy to get Python apps to work
> cross platform - it usually requires almost no porting effort.
>
> However, when I need a little bit more grunt, I tend to turn to Tix,
> which I thought was also fairly standard. However, this week, I wrote
> a Tix application under Linux which I'd really like to work on Mac OS
> and it's proving fairly painful to get it going. There is no Tix in
> the standard fink or apt repositories and when I download a tar-ball,
> it wouldn't build because it had a lot of unmet dependencies. I then
> read a post which said that only Tkinter/Python people really use Tix
> anymore and people in tcl/tk moved onto better toolkits long ago.
>
> My question is if Tix is old hat, what is the GUI toolkit I *should*
> be using for quick-n-dirty cross platform GUI development?

Since you're already used to Tkinter, I'd say: just wait... tcl/tk 8.5 is  
on the way and it will bring a lot of new and long-awaited widgets, along  
with native look on most platforms. See here:
http://wiki.tcl.tk/14796
and here for the look:
http://tktable.sf.net/tile/

Note that there are already Tkinter wrappers for these widgets, but they  
may not be the ones that'll end up in the official distribution. If you  
want to play with them, you can find them here:
https://sourceforge.net/project/showfiles.php?group_id=165637
(download tkinter-wrappers)

If you want to use these, you'll of course also need the latest beta of  
tcl/tk 8.5, downloadable from here:
http://www.tcl.tk/software/tcltk/8.5.html

> I hope this isn't a stupid question. I'm wearing flame retardant
> underwear.

You won't need these much around here... ;-)

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter question

2007-10-08 Thread Eric Brunel
On Sun, 07 Oct 2007 18:09:16 +0200, Kevin Walzer <[EMAIL PROTECTED]>  
wrote:
> Hendrik van Rooyen wrote:
>> "Kevin Walzer" <[EMAIL PROTECTED]> wrote:
>>
>>> I find "pack" to be more flexible than "grid," so I prefer it for  
>>> complex layouts. "grid" is better for simple layouts.
>>  *does a double take*  are you serious? - my experience is that
>> pack is only good for simple single row or single column stuff.

I agree with Hendrik, here...

> Well, I guess it depends on your viewpoint. I find "pack" flexible  
> because it allows me to think in terms of top, bottom, right, and left  
> in terms of arranging UI elements--it's an elegant way to do it in my  
> view. I tend to use "grid" if I have, say, a window with several  
> preference items: a label, an entry field, and a button, all arranged in  
> rows. "grid" is better for stuff like that, I agree.
>
> See http://www.codebykevin.com/blosxom/business/phynchronicity-new.png:  
> this is an application I develop. The layout is all handled by "pack"  
> and paned windows. Where you you use "grid" in a layout like this?

I personally use grid almost everywhere, except for basic rows or columns  
of widgets with no resizing policy. I find pack confusing, for the very  
same reason you find it flexible apparently; for me, this  
top/bottom/left/right stuff is not clear at all, and even after all the  
explanations I read (including yours), I still don't get the resize policy  
with pack. The single 'sticky' option with the row & column weights with  
grid is just clearer for me. And there are layouts that you just can't do  
with pack (canvas or text with vertical and horizontal scrollbars, for  
example...).

But apparently, even this is - again - a matter of taste. So I guess I'll  
have to stop telling everyone that grid is better... ;-)
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter question

2007-10-05 Thread Eric Brunel
On Fri, 05 Oct 2007 14:10:57 +0200, Kevin Walzer <[EMAIL PROTECTED]>  
wrote:
> "expand = 1" ==  "expand=TRUE"--that means the widget resizes itself  
> when the window is re-sized.

That's the theory... But what does fill=BOTH means then? And why does  
expand=1 (or TRUE, or True) is only needed in some cases and not others?  
And I'm quite sure that sometimes, I use expand=1 and it does exactly what  
I don't want, and removing it gives the behaviour I want. I've been doing  
tk/Tkinter stuff for quite a few years now, and I still haven't understood  
exactly when I should use this option... Quite counter-intuitive, IMHO.

But then, since I almost never use pack for this kind of layout, I guess  
it's not really important...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter question

2007-10-05 Thread Eric Brunel
On Fri, 05 Oct 2007 05:16:14 +0200, goldtech <[EMAIL PROTECTED]>  
wrote:

> This works OK. But I notice that if I enlarge the window after the
> script has run, the white listbox only gets "so" big while the grey
> background enlarges.
>
> Is there a way to have it all white when I enlarge a window - like
> what normally happens?
>
>
>
> from Tkinter import *
> root = Tk()
> root.title("Dirty Words")
> scrollbar = Scrollbar(root)
> scrollbar.pack(side=RIGHT, fill=Y)
> listbox = Listbox(root, bg='white', font = "Courier 16", width=60)
> listbox.pack()

=> listbox.pack(fill=BOTH, expand=1)

> i='123456789abcdefghijklmnopqrstuvwxyz'
> for x in range(10):
> listbox.insert(END, i)
> listbox.config(yscrollcommand=scrollbar.set)
> scrollbar.config(command=listbox.yview)
> mainloop()

BTW, even for something that simple, using the grid geometry manager may  
be easier... It is at least easier to explain: don't ask me what the  
expand=1 option means, I never understood it... I just add or remove it  
when the pack doesn't do what I want. The sticky option with grid is  
easier to handle.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter / Tk 8.5

2007-09-27 Thread Eric Brunel
On Thu, 27 Sep 2007 04:41:48 +0200, Scott David Daniels  
<[EMAIL PROTECTED]> wrote:

> Michal Bozon wrote:
>> Today has been released a first beta of Tk 8.5, including a Ttk
>> (tile) style engine, which makes possible the native look
>> of widgets on MS platform, without having to install any extension.
>>  Is there a chance it will be included in 2.5.x, 2.6 or 3.0 ?
>
> This is just a guess, but:
> The beta: no way for anything.
> 2.5.x: also very unlikely
> 2.6: unlikely unless release is _soon_ (first alpha of 2.6 is out)

It won't be: tcl/tk development is quite slow. There have been several  
months between each 5 or 6 alpha release and between the last alpha and  
the beta. So don't expect the official release to come soon...

> 3.0: much more likely, 3.0 won't be out for some time.

This would be my guess too...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multi Heritage with slots

2007-09-05 Thread Eric Brunel
On Wed, 05 Sep 2007 11:01:56 +0200, Alexandre Badez  
<[EMAIL PROTECTED]> wrote:

> Hye,
>
> I'm developing a little app, and I want to make multi heritage.
> My problem is that my both parent do have __slots__ define.
>
> So I've got something like:
>
> class foo(object):
> __slots__ = ['a', 'b']
> pass
>
> class foo2(object):
> __slots__ = ['c', 'd']
> pass
>
> class crash(foo, foo2):
> pass
>
> If you write only that in a sample file or in python console (as I
> did), python refuse to load the module and report something like:
>
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: Error when calling the metaclass bases
> multiple bases have instance lay-out conflict
>
> Do you know why it append? And how could I make this work?

See http://mail.python.org/pipermail/python-list/2006-December/418768.html

Basically, the general advice you're likely to get here is: don't use  
__slots__, or at least don't use __slots__ with inheritance.

BTW, what are you trying to do? Is it really a memory footprint  
optimization, which is the intended use case for __slots__, or are you  
just doing Java in Python?
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter(2)

2007-09-05 Thread Eric Brunel
On Tue, 04 Sep 2007 15:42:09 +0200, vijayca <[EMAIL PROTECTED]> wrote:

> my python installation is:Active python 2.5.1
> i am using Red Hat Linux
> i have the Tkinter module installed but any simple script produces an
> error
>
> script:
> from Tkinter import Label
> widget = Label(None, text='Hello GUI world!')
> widget.pack()
> widget.mainloop()
>
>
> error:
> Traceback (most recent call last):
>   File "guy.py", line 2, in 
> widget = Label(None, text='Hello GUI world!')
>   File "/root/Desktop/pythonall/ActivePython-2.5.1.1-linux-x86/
> INSTALLDIR/lib/python2.5/lib-tk/Tkinter.py", line 2464, in __init__
> Widget.__init__(self, master, 'label', cnf, kw)
>   File "/root/Desktop/pythonall/ActivePython-2.5.1.1-linux-x86/
> INSTALLDIR/lib/python2.5/lib-tk/Tkinter.py", line 1923, in __init__
> BaseWidget._setup(self, master, cnf)
>   File "/root/Desktop/pythonall/ActivePython-2.5.1.1-linux-x86/
> INSTALLDIR/lib/python2.5/lib-tk/Tkinter.py", line 1898, in _setup
> _default_root = Tk()
>   File "/root/Desktop/pythonall/ActivePython-2.5.1.1-linux-x86/
> INSTALLDIR/lib/python2.5/lib-tk/Tkinter.py", line 1636, in __init__
> self.tk = _tkinter.create(screenName, baseName, className,
> interactive, wantobjects, useTk, sync, use)
> _tkinter.TclError: no display name and no $DISPLAY environment
> variable

Basically, this error has nothing to do with Python or Tkinter. If you  
tried to launch any GUI application, you should get the same error.

How are you logged in to your computer? Did you do any remote connection  
via telnet, or rlogin/rsh, or ssh? This error usually happens when you're  
logged in on a remote machine, and you didn't tell the remote machine  
where you wanted to display the windows you open. It may also happen when  
you're logged in as a user, but did a 'su' to change your identity.

In any case, solving the problem is quite easy: define the DISPLAY  
environment variable with the value :0  
and it should work. If you're using a remote machine, you may also have to  
issue a 'xhost + ' on the local machine  
(the one where the display should occur).

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter

2007-09-04 Thread Eric Brunel
On Tue, 04 Sep 2007 07:12:00 +0200, vijayca <[EMAIL PROTECTED]> wrote:

> i tried to use python gui module Tkinter in solaris,aix,hpux.
> while importing the module it  shows an error...
>
> import Tkinter
> error says that your python may not be configured for Tk()...
> how to get out of this...

Did you compile the Python interpreter yourself, or did it come in a sort  
of package?

In the first case, you have to install tcl/tk yourself if it's not already  
there, then tweak the build options for Python to make it use the tcl/tk  
installation you've done. How to tweak these options depends on the Python  
version you use, so please tell us what it is.

In the second case, Tkinter may be provided as a separate package, that  
you also need to install.

And BTW, Wildemar's comment still holds: please copy/paste the exact  
traceback you get if it doesn't work. I'm only guessing here...

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File handle not being released by close

2007-07-30 Thread Eric Brunel
On Mon, 30 Jul 2007 16:36:00 +0200, <[EMAIL PROTECTED]> wrote:

> Hi,
>
> I'm in the process of writing some code and noticed a strange problem
> while doing so. I'm working with PythonWin 210 built for Python 2.5. I
> noticed the problem for the last py file processed by this script,
> where the concerned tmp file is only actually written to when
> PythonWin is closed. In other words, after I run this script, one of
> the generated tmp files has a size of 0kB. I then close PythonWin and
> it is then written to.
>
> I'm guessing the garbage collector is causing the file to be written,
> but shouldn't close do this?
>
> /Barry
>
> import os, time, string
>
> dir = 'c:\\temp1'
>
> def listAllFile(fileNames,dir,files):
>   def f1(a,dir=dir): return os.path.join(dir,a)
>   files2 = map(f1, files)
>   fileNames.extend(files2)
>
> fileNames = []
> os.path.walk(dir,listAllFile,fileNames)
>
> for fileName in fileNames:
>   fileBeginning = os.path.splitext(fileName)[0]
>   fileEnd   = os.path.splitext(fileName)[1]
>
>   if fileEnd == ".py":
> print fileName
> f=open(fileBeginning+".tmp", 'w')
> f.write("Hello")
> f.close

f.close()

HTH...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making Gridded Widgets Expandable

2007-07-30 Thread Eric Brunel
On Mon, 30 Jul 2007 15:59:21 +0200, Jim <[EMAIL PROTECTED]> wrote:

> Hi,
> I'm looking at page 548 of Programming Python (3rd Edition) by Mark
> Lutz.
> The following GUI script works with no problem, i.e., the rows and
> columns expand:
> =
> # Gridded Widgets Expandable page 548
>
> from Tkinter import *
> colors = ["red", "white", "blue"]
>
> def gridbox(root):
> Label(root, text = 'Grid').grid(columnspan = 2)
> r = 1
> for c in colors:
> l = Label(root, text=c, relief=RIDGE, width=25)
> e = Entry(root, bg=c,   relief=SUNKEN, width=50)
> l.grid(row=r, column=0, sticky=NSEW)
> e.grid(row=r, column=1, sticky=NSEW)
> root.rowconfigure(r, weight=1)
> r += 1
> root.columnconfigure(0, weight=1)
> root.columnconfigure(1, weight=1)
>
> root = Tk()
> gridbox(Toplevel(root))
> Button(root, text="Quit", command=root.quit).grid()
> mainloop()
> =
> However, the following GUI script using class does not expand rows and
> columns:
> =
> # Gridded Widgets Expandable 2
>
> from Tkinter import *
> colors = ["red", "white", "blue"]
>
> class GUI(Frame):
> def __init__(self,master):
> Frame.__init__(self,master)
> self.grid()
> self.gridbox()
>
> def gridbox(self):
> Label(self, text = 'Grid').grid(columnspan = 2)
> r = 1
> for c in colors:
> l = Label(self, text=c, relief=RIDGE, width=25)
> e = Entry(self, bg=c,   relief=SUNKEN, width=50)
> l.grid(row=r, column=0, sticky=NSEW)
> e.grid(row=r, column=1, sticky=NSEW)
> self.rowconfigure(r, weight=1)
> r += 1
> self.columnconfigure(0, weight=1)
> self.columnconfigure(1, weight=1)
>
> root = Tk()
> root.title("Gridded Widgets Expandable")
> app = GUI(root)
> Button(root, text="Quit", command=root.quit).grid()
> root.mainloop()
> =
> What am I missing?

Hint: when you get this kind of problem, the problem is usually that an  
intermedaite Frame does not expand as it does. Since you have only one  
Frame here (your GUI instance), you should already have the solution. If  
you don't, or in case you get this kind of problem later with a more  
complex layout, adding a visible border on all Frame's usually helps.  
Here, for example, you can't do:
Frame.__init__(self,master, border=2, bg='green')
in GUI.__init__, and this will definitely show that the Frame does not  
resize itself when you resize the window. So the solution is clear: you  
should add a sticky option to your self.grid in GUI.__init__ and the  
corresponding (row|column)_configure(..., weight=1) on the window.

BTW, why do you create a sub-class of Frame (yes: this is a trick  
question)?

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing Tkinter over wxPython...

2007-07-10 Thread Eric Brunel
On Mon, 09 Jul 2007 23:08:20 +0200, Kevin Walzer <[EMAIL PROTECTED]>  
wrote:
> I've spent some time playing with both, and while wxPython is nice,  
> Tkinter just seems to fit my head better, and with appropriate selection  
> of widgets and interface design, seems to yield up perfectly usable  
> GUI's.
>
> Can anyone else who finds Tkinter better for them than wxPython (or the  
> other toolkits) explain why it works for them?

I am, for more or less the same reasons as you. At the time I started -  
which is quite some time ago -, there was also no serious alternative to  
Tkinter's Canvas and Text widgets in the other toolkits. This has changed  
today, at least for the Text widget. But now, I'm used to Tkinter's way of  
doing things and I find working with other toolkits weird...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter toggle a Label Widget based on checkbutton value

2007-07-05 Thread Eric Brunel
On Wed, 04 Jul 2007 21:51:34 +0200, O.R.Senthil Kumaran  
<[EMAIL PROTECTED]> wrote:
> Following is a tk code, which will display a checkbutton, and when  
> checkbox is
> enabled, it will show the below present Label.
>
> What I was trying is, when checkbox is enabled the Label should be shown  
> and
> when checkbox is disabled, the window should look like before.
>
> But, I am finding that once enabled (shown), its not  
> very-straightforward to
> hide it from the window.
>
> Any suggestions on  how can i make this checkbutton effect.
> 1) Press Enable IP, the Label IP should be shown.
> 2) Toggle Enable IP (So that its unset). the Label IP should not be  
> shown.
>
> #!/usr/bin/python
> from Tkinter import *
> root = Tk()
> root.title('something')
> x = StringVar()
> def display():
> if x.get():
> ip = Label(root,text="IP:")
> ip.grid(row=3,column=0)
>
> proxy = Checkbutton(root, text="Enable IP:", variable =  
> x,onvalue="proxy",
> offvalue="",command=display)
> proxy.grid(row=2,column=0)
> root.mainloop()

Wojciech gave a perfectly valid answer that'll work in all cases.

Here is another one, that you may or may not be able to use, which  
consists in using the same Tkinter variable for your check-button's value  
and your label's text:
--
 from Tkinter import *

root = Tk()

labelString = StringVar()

b = Checkbutton(root, text="Enable IP:", variable=labelString,
   onvalue='IP:', offvalue='')
b.grid(row=2, column=0)

Label(root, textvariable=labelString).grid(row=3, column=0)

root.mainloop()
--

This doesn't really make the label "disappear" when the check-button is  
off, but simply sets its text to the empty string.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter pack_forget() and destroy()

2007-06-28 Thread Eric Brunel
On Thu, 28 Jun 2007 07:45:08 +0200, Rajendran Appavu <[EMAIL PROTECTED]>  
wrote:

> When I am done with a widget that is packed in a Frame, is it safe to
> call destroy() method on the widget after calling its pack_forget() or
> grid_forget() method?

Since I do that all the time, I'd say yes... Did you have a problem? Or do  
you ask just to be sure?

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tamil/Indian Languages Support in Tkinter

2007-06-13 Thread Eric Brunel
On Tue, 12 Jun 2007 19:32:38 +0200, reverse_gear <[EMAIL PROTECTED]>  
wrote:
> hi,
> Does Tkinter has support for tamil/Indian Languages??
> I tried this code
> it is able to print both tamil and german text on console.. but on
> Tkinter Label it is printing only the german code
> Plz help
> from Tkinter import *
> import codecs
>
> german_ae = unicode('\xc3\xa4','utf-8')
> tamil_text = unicode('\xe0\xae\xb9\xe0\xae\xbf \xe0\xae\xae\xe0\xaf
> \x81\xe0\xae\x95\xe0\xaf\x81\xe0\xae\xa9\xe0\xaf\x8d\xe0\xae\x9f
> \xe0\xaf\x8d','utf-8')
> root = Tk()
> print tamil_text
> print german_ae
> label = Label(root, text = german_ae)
> label2= Label(root, text = tamil_text)
> label.pack()
> label2.pack()
> mainloop()

If you have a recent version of tcl/tk, it should work as long as you have  
the proper fonts installed.BTW, I tried it and the tamil text didn't show  
at all on my Linux box: no text on the console (just squares) and nothing  
in the Tkinter label. But I certainly don't have any font able to display  
these characters.

This is apparently not your problem since if it works on the console, you  
should have a usable font. So my guess would be that some font installed  
on your system claims to be able to display these characters, but actually  
isn't. Since you didn't specify a font to use in your labels and the  
default font probably can't display tamil, tk looks for a font that can.  
When it finds one, it stops and uses it. So if a font claims to have these  
characters, but actually can't display them, you end up with a blank text.

Did you try to specify the font to use in the labels? A good candidate  
would obviously be the font used by the console.

And you didn't specify on which platform you were, or your Python and  
tcl/tk version. This may help...

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pasting an image from clipboard in Tkinter?

2007-06-12 Thread Eric Brunel
On Mon, 11 Jun 2007 14:23:48 +0200, exhuma.twn <[EMAIL PROTECTED]> wrote:
> As many might know, windows allows to copy an image into the clipboard
> by pressing the "Print Screen" button on the keyboard. Is it possible
> to paste such an image from the clipboard into a "Text" widget in
> Tkinter? Here is my first attempt with just trying to print out the
> image data:
>
> -
> def pasteImg(tgt):
>global clipboardEnabled
>if not clipboardEnabled: return
>
>win32clipboard.OpenClipboard(0)
>print win32clipboard.GetClipboardData()
>win32clipboard.CloseClipboard()
> -
>
> This works fine with selecting text, but comes up with the following
> error when trying to paste an image:
>
> -
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
> return self.func(*args)
>   File "X:\development\testing\tkwiki\tkwiki.py", line 52, in 
> Button( root, command=lambda: pasteImg(txt) ).pack()
>   File "X:\development\testing\tkwiki\tkwiki.py", line 38, in pasteImg
> print win32clipboard.GetClipboardData()
> TypeError: Specified clipboard format is not available
> -
>
> Obviously the clipboard does not know about that format. Does that
> mean I have to wait until it's implemented or are there other ways to
> access the image data?

According to http://msdn2.microsoft.com/en-us/library/ms649039.aspx, there  
is format that you should pass to GetClipboardData telling the data type  
you expect to get. The format you should specify to get a bitmap image is  
named CF_BITMAP in the Windows API. AFAIK, this constant is not exposed in  
the Python world, so you have to pass directly the numeric value, which is  
2.

But even if you do get the clipboard contents, you'll get it in BMP  
format, that tk/Tkinter does not understand by default. So you'll need a  
means to convert it to the only format known to tk/Tkinter by default,  
which is GIF. PIL is certainly able to do that (I don't use it myself);  
you may also rely on an external conversion utility.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter, tkMessagebox and overrideredirect

2007-06-07 Thread Eric Brunel
On Thu, 07 Jun 2007 09:04:24 +0200, <[EMAIL PROTECTED]> wrote:
[snip]
> I can't believe there isn't an easier way to make a kiosk application
> without titlebar.

That's not the problem: there *is* an easy way, and you found it:  
overrideredirect(1). But now you're trying to mix windows ignored by the  
window manager - as you've told it to - and windows that *are* managed by  
the window manager. This is where the problem is.

> Perhaps to create a normal window bigger than screen with title bar
> outside it?

This won't work on some platforms and/or with some window managers... And  
there's no portable way to do that, as sometimes, the dimensions you give  
for the window includes the window decorations, and sometimes they don't.

> And after how can I ignore titlebar menu command or "x" and "-"
> button?

For the 'X' button, it's quite simple:  
myToplevel.protocol('WM_DELETE_WINDOW', lambda: None)

For the '-' button, I don't know any way.

> Or is it possible to create a main Toplevel without "x" and "-"?

Apart from overrideredirect(1), I don't think there's any.


BTW, what are you trying to do here? Will your application run on a  
"normal" desktop computer? Or will it run on special devices such as  
vending machines or similar? If in the first case, my advice would be to  
give up this design (which many people hate, BTW) and use normal windows.  
You'll have far less trouble and will probably make your users happier. If  
in the second case, you shouldn't rely on an existing window manager, and  
try to design your GUI so that doing things "manually" will be easier. For  
example, instead of displaying a dialog for a message, maybe you should  
just reserve a screen zone to display the message, optionally displaying  
it in a special color or making it blink so that the user can't miss it.  
You may also consider using the "place" layout method to display things at  
random coordinates in your application window. For example:


 from Tkinter import *

class App:
 def __init__(self):
 self.root = Tk()
 self.root.overrideredirect(1)
 frm = Frame(self.root, width=320, height=200,
borderwidth=5, relief=RAISED)
 frm.pack_propagate(0)
 frm.pack()
 Button(frm, text="Quit", command=self.root.quit).pack(pady=20)
 Button(frm, text="Hello", command=self.hello).pack(pady=20)

 def hello(self):
 self.dialogWdw = Frame(self.root, borderwidth=2, relief=RAISED)
 Label(self.dialogWdw, text='Hello!').pack(side=TOP, padx=20,  
pady=4)
 Button(self.dialogWdw, text='OK',  
command=self.destroyDialog).pack(side=TOP, padx=20, pady=4)
 self.dialogWdw.place(x=170, y=100, anchor='center')

 def destroyDialog(self):
 self.dialogWdw.place_forget()
 self.dialogWdw.destroy()


app = App()
app.root.mainloop()


HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter, tkMessagebox and overrideredirect

2007-06-06 Thread Eric Brunel
On Wed, 06 Jun 2007 14:26:12 +0200, <[EMAIL PROTECTED]> wrote:
>> As an aside, having a window with overrideredirect(1) creating "normal"
>> windows such as the one created via tkMessageBox.showinfo is asking for
>> problems. What are you trying to do here?
>
> I just need a window without the titlebar as my main window (think of
> it as a kiosk application). No titlebar is mandatory :-(
> I place controls on it and I open popup dialog windows.
> If there is a better way to do it, I would be happy to know it.

My only advice would then be to avoid using the standard functions to  
create dialog boxes, and to create them yourself. For example:
--
 from Tkinter import *

class App:
 def __init__(self):
 self.root = Tk()
 self.root.overrideredirect(1)
 frm = Frame(self.root, width=320, height=200, borderwidth=5,  
relief=RAISED)
 frm.pack_propagate(0)
 frm.pack()
 Button(frm, text="Quit", command=self.root.quit).pack(pady=20)
 Button(frm, text="Hello", command=self.hello).pack(pady=20)

 def hello(self):
 dialogWdw = Toplevel()
 dialogWdw.title('Popup')
 Label(dialogWdw, text='Hello!').pack(side=TOP)
 Button(dialogWdw, text='OK',  
command=dialogWdw.destroy).pack(side=TOP)
 dialogWdw.tkraise(self.root)
 self.root.wait_window(dialogWdw)

app = App()
app.root.mainloop()
--

But even with this, you may run into problems. For example, on my Linux  
box with my window manager, the main window goes behind all other windows  
once the button in the dialog is clicked. So I'd say that if you want to  
bypass the window manager, bypass it for everything and do  
overrideredirect(1) on all the windows you create. But this means that  
you'll have to do everything "manually", especially window stacking.
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter, tkMessagebox and overrideredirect

2007-06-06 Thread Eric Brunel
On Tue, 05 Jun 2007 18:18:51 +0200, <[EMAIL PROTECTED]> wrote:

> Hi everybody.
>
> I have this code snippet that shows a window without a titlebar (using
> overrideredirect) and two buttons on it: one quits and the other one
> brings up a simple tkMessageBox.
> On Windows (any flavour) the tkMessagebox brings up over the
> underlying window.
> On Linux (apparently any flavour) the tkMessagebox brings up under the
> underlying window.
> You can drag the popup window near the main window to discover if it's
> over or under it.
> Obviously I would like to show a popup that is over the main window!
> Before asking I tried, I read, I googled, I pulled my hair off, but no
> avail...
> Any hints?

Apparently:

def hello(self):
 self.root.after_idle(self.root.lower)
 tkMessageBox.showinfo("Popup", "Hello!")

does something looking like what you want. I don't know of any way to get  
the identifier for the window created by tkMessageBox.showinfo, so if  
there's a way to do better than that, I don't know it.

As an aside, having a window with overrideredirect(1) creating "normal"  
windows such as the one created via tkMessageBox.showinfo is asking for  
problems. What are you trying to do here?

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pack() and the division of vertical space

2007-06-01 Thread Eric Brunel
On Thu, 31 May 2007 19:45:04 +0200, [EMAIL PROTECTED]  
<[EMAIL PROTECTED]> wrote:

> I am trying to figure out how to stack two widgets in a frame
> vertically so that they both expand horizontally and during vertical
> expansion, the top one sticks to the top of the frame and the bottom
> one consumes the remaining vertical space.  I thought this would do it
> but it doesn't.  What am I missing?
[snip code]

For this kind of stuff, don't use pack; use grid. It will be far easier to  
get it working, to read afterwards and to maintain, even if it's slightly  
more verbose. IMHO, pack should only be used to create rows or columns of  
widgets, without any resizing policy, or to put an entire widget into a  
container. If you do anything more complicated than that, you'll find grid  
much easier to handle.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Listbox - Different Text colors in one listbox

2007-05-30 Thread Eric Brunel
On Tue, 29 May 2007 19:02:03 +0200, <[EMAIL PROTECTED]> wrote:

> Hi,
> Is it possible to have different items in a listbox in different
> colors? Or is it just one color for all items in a listbox?
> Thanks
> Rahul
>

AFAIK, this is not possible with a listbox. You can however quite easily  
emulate the behaviour of a listbox with a text widget, which allows to mix  
fonts and colors in any way you like.

I did it once by creating a sub-class of Tkinter.Text (cannot post the  
code here - closed source, sorry...) and all I had to do was:
- make sure the text widget had its state to DISABLED all the time, except  
when modifying it;
- removing all the bindings defined in the text widgets (use  
widget.bind_class('Text') to get all the events, then widget.bind(event,  
lambda e: 'break') to remove them);
- define a new binding for a button click selecting the line under the  
cursor;
- define the insert, delete and getcurselection methods, taking care of  
treating the special index END.

All in all, this was just a few dozen lines.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter button state = DISABLED

2007-05-18 Thread Eric Brunel
On Thu, 17 May 2007 09:30:57 +0200, Hendrik van Rooyen  
<[EMAIL PROTECTED]> wrote:
>  "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>> En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
>>> I have never seen this working in Tkinter, unless the button was  
>>> pressed
>>> on the
>>> widget
>>> in question - and worse, once you have clicked down on a ButtonRelease
>>> binding
>>> you can move the mouse pointer anywhere you like, even out of the
>>> application
>>> and when you release it, the bound function is called...
>>>
>>> Its either a bug or a feature, I don't know.
>>
>> Uhmm... I'm not sure I understand you completely. I only said that the
>> "command" is fired only when the mouse button is pressed on the widget,
>> AND released inside the same widget. If both events don't happen in the
>> same widget, "command" won't fire. Maybe you are saying the same  
>> thing...
>> anyway I'm not a Tk expert.
>
> No command is ok and you have described it right - its ButtonRelease that
> seems broken to me

Apparently, this behaviour is the intended one, at least for buttons; see:
http://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm#M11

As for the question "why?", maybe you should ask it on the c.l.tcl  
newsgroup?
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Eric Brunel
On Wed, 16 May 2007 17:14:32 +0200, Gregor Horvath <[EMAIL PROTECTED]>  
wrote:

> Eric Brunel schrieb:
>
>> Highly improbable in the general context. If I stumble on a source code  
>> in Chinese, Russian or Hebrew, I wouldn't be able to figure out a  
>> single sound.
>
> If you get source code in a programming language that you don't know you  
> can't figure out a single sound too.
> How is that different?

What kind of argument is that? If it was carved in stone, I would not be  
able to enter it in my computer without rewriting it. So what?

The point is that today, I have a reasonable chance of being able to read,  
understand and edit any Python code. With PEP 3131, it will no more be  
true. That's what bugs me.

> If someone decides to make *his* identifiers in Russian he's taking into  
> account that none-Russian speakers are not going to be able to read the  
> code.

Same question again and again: how does he know that non-Russian speakers  
will *ever* get in touch with his code and/or need to update it?
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Eric Brunel
On Wed, 16 May 2007 16:29:27 +0200, Neil Hodgson  
<[EMAIL PROTECTED]> wrote:

> Eric Brunel:
>
>> Have you ever tried to enter anything more than 2 or 3 characters like  
>> that?
>
> No, only for examples. Lengthy texts are either already available  
> digitally or are entered by someone skilled in the language.
>
>  > I did. It just takes ages. Come on: are you really serious about
>> entering *identifiers* in a *program* this way?
>
> Are you really serious about entry of identifiers in another  
> language  being a problem?

Yes.

> Most of the time your identifiers will be available by selection  
> from an autocompletion list or through cut and paste.

Auto-completion lists have always caused me more disturbance than help.  
Since - AFAIK - you have to type some characters before they can be of any  
help, I don't think they can help much here. I also did have to copy/paste  
identifiers to program (because of a broken keyboard, IIRC), and found it  
extremely difficult to handle. Constant movements to get every identifier  
- either by keyboard or with the mouse - are not only unnecessary, but  
also completely breaks my concentration. Programming this way takes me 4  
or 5 times longer than being able to type characters directly.

> Less commonly, you'll know what they sound like.

Highly improbable in the general context. If I stumble on a source code in  
Chinese, Russian or Hebrew, I wouldn't be able to figure out a single  
sound.

> Even more rarely you'll only have a printed document.

I wonder how that could be of any help.

> Each of these can be handled reasonably considering their frequency of  
> occurrence. I have never learned Japanese but have had to deal with  
> Japanese text at a couple of jobs and it isn't that big of a problem.  
> Its certainly not "virtually impossible" nor is there "absolutely no way  
> of entering the word" (売り場). I think you should moderate your  
> exaggerations.

I do admit it was a bit exaggerated: there actually are ways. You know it,  
and I know it. But what about the average guy, not knowing anything about  
Japanese, kanji, radicals and stroke counts? How will he manage to enter  
these funny-looking characters, perhaps not even knowing it's Japanese?  
And does he have to learn a new input method each time he stumbles across  
identifiers written in a character set he doesn't know? And even if he  
finds a way, the chances are that it will be terribly inefficient. Having  
to pay attention on how you can type the things you want is a really big  
problem when it comes to programming: you have a lot of other things to  
think about.
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Eric Brunel
On Wed, 16 May 2007 15:46:10 +0200, Neil Hodgson  
<[EMAIL PROTECTED]> wrote:

> Eric Brunel:
>
>> Funny you talk about Japanese, a language I'm a bit familiar with and  
>> for which I actually know some input methods. The thing is, these only  
>> work if you know the transcription to the latin alphabet of the word  
>> you want to type, which closely match its pronunciation. So if you  
>> don't know that 売り場 is pronounced "uriba" for example, you have  
>> absolutely no way of entering the word. Even if you could choose among  
>> a list of characters, are you aware that there are almost 2000 "basic"  
>> Chinese characters used in the Japanese language? And if I'm not  
>> mistaken, there are several tens of thousands characters in the Chinese  
>> language itself. This makes typing them virtually impossible if you  
>> don't know the language and/or have the correct keyboard.
>
> It is nowhere near that difficult. There are several ways to  
> approach this, including breaking up each character into pieces and  
> looking through the subset of characters that use that piece (the  
> Radical part of the IME). For 売, you can start with the cross with a  
> short bottom stroke (at the top of the character) 士, for 場 look for  
> the crossy thing on the left 土. The middle character is simple looking  
> so probably not Chinese so found it in Hiragana. Another approach is to  
> count strokes (Strokes section of the IME) and look through the  
> characters with that number of strokes. Within lists, the characters are  
> ordered from simplest to more complex so you can get a feel for where to  
> look.

Have you ever tried to enter anything more than 2 or 3 characters like  
that? I did. It just takes ages. Come on: are you really serious about  
entering *identifiers* in a *program* this way?
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Eric Brunel
On Wed, 16 May 2007 12:22:01 +0200, Neil Hodgson  
<[EMAIL PROTECTED]> wrote:

> Eric Brunel:
>
>> ... there is no keyboard *on Earth* allowing to type *all* characters  
>> in the whole Unicode set.
>
> My keyboard in conjunction with the operating system (US English  
> keyboard on a Windows XP system) allows me to type characters from any  
> language. I haven't learned how to type these all quickly but I can get  
> through a session of testing Japanese input by myself. Its a matter of  
> turning on different keyboard layouts through the "Text Services and  
> Input Languages" control panel. Then there are small windows called  
> Input Method Editors that provide a mapping from your input to the  
> target language. Other platforms provide similar services.

Funny you talk about Japanese, a language I'm a bit familiar with and for  
which I actually know some input methods. The thing is, these only work if  
you know the transcription to the latin alphabet of the word you want to  
type, which closely match its pronunciation. So if you don't know that 売り 
場 is pronounced "uriba" for example, you have absolutely no way of  
entering the word. Even if you could choose among a list of characters,  
are you aware that there are almost 2000 "basic" Chinese characters used  
in the Japanese language? And if I'm not mistaken, there are several tens  
of thousands characters in the Chinese language itself. This makes typing  
them virtually impossible if you don't know the language and/or have the  
correct keyboard.
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Eric Brunel
On Wed, 16 May 2007 02:14:58 +0200, Steven D'Aprano  
<[EMAIL PROTECTED]> wrote:

> On Tue, 15 May 2007 09:09:30 +0200, Eric Brunel wrote:
>
>> Joke aside, this just means that I won't ever be able to program math in
>> ADA, because I have absolutely no idea on how to do a 'pi' character on
>> my keyboard.
>
> Maybe you should find out then? Personal ignorance is never an excuse for
> rejecting technology.

My "personal ignorance" is fine, thank you; how is yours?: there is no  
keyboard *on Earth* allowing to type *all* characters in the whole Unicode  
set. So my keyboard may just happen to provide no means at all to type a  
greek 'pi', as it doesn't provide any to type Chinese, Japanese, Korean,  
Russian, Hebrew, or whatever character set that is not in usage in my  
country. And so are all keyboards all over the world.

Have I made my point clear or do you require some more explanations?
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Eric Brunel
On Tue, 15 May 2007 21:07:30 +0200, Pierre Hanser  
<[EMAIL PROTECTED]> wrote:
> hello
>
> i work for a large phone maker, and for a long time
> we thought, very arrogantly, our phones would be ok
> for the whole world.
>
> After all, using a phone uses so little words, and
> some of them where even replaced with pictograms!
> every body should be able to understand appel, bis,
> renvoi, mévo, ...
>
> nowdays we make chinese, corean, japanese talking
> phones.
>
> because we can do it, because graphics are cheaper
> than they were, because it augments our market.
> (also because some markets require it)
>
> see the analogy?

Absolutely not: you're talking about internationalization of the  
user-interface here, not about the code. There are quite simple ways to  
ensure users will see the displays in their own language, even if the  
source code is the same for everyone. But your source code will not  
automagically translate itself to the language of the guy who'll have to  
maintain it or make it evolve. So the analogy actually seems to work  
backwards: if you want any coder to be able to read/understand/edit your  
code, just don't write it in your own language...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   3   >