Re: [Tutor] Tkinter, how to retrieve information about an object on canvas

2012-11-15 Thread Alan Gauld

On 15/11/12 02:32, Matheus Soares da Silva wrote:


Hello, I would like to be able to get information from a Tkinter canvas
object. (color, width, tags, root points, etc),

  I wrote the following function that, with a canvas bind, returns me
the widget that has been clicked on, the widget is returned as a tuple
by the find_overlapping method.

# detecting click
def Hasclicked(e):
 global obj
 global lastClick
 lastClick = [e.x, e.y]
 obj = e.widget.find_overlapping(e.x, e.y, e.x, e.y)

   So, there's any method I can use on 'obj' to get the attributes?


Do you want to get the attributes of the object within the canvas or of 
the canvas itself?

I'm not quite clear from your description?

In either case you can access an attribute of an object using standard 
Tkinter attribute access mechanism: obj['attributeName']


>>> import Tkinter as tk
>>> top = Tk()
>>> top = tk.Tk()
>>> l = tk.Label(top,text='hello')
>>> l.pack()
>>> l['text']
'hello'
>>>

HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Plot multiple lines using python / basemap

2012-11-15 Thread Boris Vladimir Comi


Hi all:

I have begun to learn about python / matplolib / basemap and really need some 
help.

  My data is in an Excel workbook with the following structure:

Evento FechaLatitud 
Longitud  Hora (UTC)
1  02/mayo 19,7 
   -95,2  0045
   19,3 
  -95.3  0115
   19,8 
  -95,6   0145
   19,9 
  -96,6   0215
 

2   03/mayo 20,2
   -99,6 0815
21,5
   -99,80845
22,5
   -99,90915
23,5
   -100,0   0945

3  15/mayo  21,3
-118,92215
21,5
 -118,7  2245
22,8
 -120,3   2315
 
 .  ..  
 .  
 .
 .  ..  
 .  
 .
 .  ..  
 .  
 .






How to open excel file in python?

I would like to plot multiple line joining the positions of each of the events, 
it is possible to do this? Have any idea how to do it?

The idea is to plot the trajectories on a particular region, for my case is 
Mexico.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter, how to retrieve information about an object on canvas

2012-11-15 Thread Peter Otten
Matheus Soares da Silva wrote:

> Hello, I would like to be able to get information from a Tkinter canvas
> object. (color, width, tags, root points, etc),
> 
>  I wrote the following function that, with a canvas bind, returns me the
> widget that has been clicked on, the widget is returned as a tuple by the
> find_overlapping method.
> 
> # detecting click
> def Hasclicked(e):
> global obj
> global lastClick
> lastClick = [e.x, e.y]
> obj = e.widget.find_overlapping(e.x, e.y, e.x, e.y)
> 
>   So, there's any method I can use on 'obj' to get the attributes?

obj is a tuple of ids. You can use canvas.itemcget(id, attribute) to explore 
the properties of the underlying objects

To get (for example) their fill-color:

for id in e.widget.find_overlapping(e.x, e.y, e.x, e.y):
print canvas.itemcget(id, "fill")

A complete example:

from __future__ import division
import Tkinter as tk
from math import cos, sin, pi

WIDTH = 640
HEIGHT = 480

root = tk.Tk()
canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT)
canvas.pack()

var = tk.StringVar()
label = tk.Label(root, textvariable=var)
label.pack()

def canvas_click(event):
x, y = event.x, event.y
ids = canvas.find_overlapping(x, y, x, y)
clicked_colors = ", ".join(canvas.itemcget(id, "fill") for id in ids)
var.set(clicked_colors)

RADIUS = 100
R = 80
CX = WIDTH // 2
CY = HEIGHT // 2

phi = pi/2 # 90 degree
for color in "red", "green", "blue":
x = int(CX + R*cos(phi))
y = int(CY - R*sin(phi))
phi += pi*2/3 # 120 degree

canvas.create_oval(x-RADIUS, y-RADIUS, x+RADIUS, y+RADIUS, fill=color)

canvas.bind("", canvas_click)
root.mainloop()


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Plot multiple lines using python / basemap

2012-11-15 Thread Dave Angel
On 11/15/2012 04:20 AM, Boris Vladimir Comi wrote:
>
> Hi all:
>
> I have begun to learn about python / matplolib / basemap and really need some 
> help.
>
>   My data is in an Excel workbook with the following structure:
>
> Evento FechaLatitud   
>   Longitud  Hora (UTC)
> 1  02/mayo 19,7   
>  -95,2  0045
>19,3   
> -95.3  0115
>19,8   
> -95,6   0145
>19,9   
> -96,6   0215
>  
>
> 2   03/mayo 20,2  
>  -99,6 0815
> 21,5  
>  -99,80845
> 22,5  
>  -99,90915
> 23,5  
>  -100,0   0945
>
> 3  15/mayo  21,3  
>   -118,92215
> 21,5  
>-118,7  2245
> 22,8  
>-120,3   2315
>  
>  .  ..
>.  
>  .
>  .  ..
>.  
>  .
>  .  ..
>.  
>  .
>
>
>
>
>
>
> How to open excel file in python?

>From Excel, save the file as a csv file, rather than a proprietary
format.  Then, within Python program, use the csv module,
http://docs.python.org/2/library/csv.html


The essential parts:
import csv
def  getdata(filename):
with open(filename, "rb") as infile:
csvreader = csv.reader(infile, delimiter ="\t", quotechar='"')
for row in csvreader:
 process row 

where row comes back as a list of items.

You may have to play with the delimiter and quotechar, as I don't use
Excel itself, to know what it defaults to.  But a csv file is a text
file, so it should be pretty obvious if you just look at the file with a
text editor or viewer, what the separator and quote characters are.  The
quote character generally only matters if some field has an embedded
separator or newline in it.

>
> I would like to plot multiple line joining the positions of each of the 
> events, it is possible to do this? Have any idea how to do it?

Try matplotlib:http://pypi.python.org/pypi/matplotlib/1.1.0
It depends on numpy:   http://numpy.scipy.org/


>
> The idea is to plot the trajectories on a particular region, for my case is 
> Mexico.
>

-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Plot multiple lines using python / basemap

2012-11-15 Thread Mark Lawrence

On 15/11/2012 09:20, Boris Vladimir Comi wrote:



Hi all:

I have begun to learn about python / matplolib / basemap and really need some 
help.

How to open excel file in python?


As Dave Angel has suggested save your data in csv format or use this 
http://www.python-excel.org/




I would like to plot multiple line joining the positions of each of the events, 
it is possible to do this? Have any idea how to do it?


The matplotlib documentation is here http://matplotlib.org/contents.html 
and it's superb.  As an added bonus matplotlib 1.2.0 has just been 
released and it supports Python 3, yee haa :)  You might consider using 
matplotlib with IPython see http://ipython.org/, together they make a 
very powerful working environment.




The idea is to plot the trajectories on a particular region, for my case is 
Mexico.




--
Cheers.

Mark Lawrence.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PostreSQL

2012-11-15 Thread Válas Péter
Hi folks,

Here are to listings of Python interfaces to PostgreSQL:
Postgres wiki: http://wiki.postgresql.org/wiki/Python
Python wiki: http://wiki.python.org/moin/PostgreSQL

I have Python 3.2.3.
Does anybody have experiences with these modules? Which is worth to use?
Any point of view to compare them?

Thanks, Péter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PostreSQL

2012-11-15 Thread Válas Péter
Two listings, of course. :-)
I failed to tell that my PG version is "PostgreSQL 8.1.2" (and my client
uses Windows 7, if this has relevance).

2012/11/15 Válas Péter 

> Hi folks,
>
> Here are to listings of Python interfaces to PostgreSQL:
> Postgres wiki: http://wiki.postgresql.org/wiki/Python
> Python wiki: http://wiki.python.org/moin/PostgreSQL
>
> I have Python 3.2.3.
> Does anybody have experiences with these modules? Which is worth to use?
> Any point of view to compare them?
>
> Thanks, Péter
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter, how to retrieve information about an object on canvas

2012-11-15 Thread Matheus Soares da Silva
2012/11/15 Peter Otten <__pete...@web.de>

> Matheus Soares da Silva wrote:
>
> > Hello, I would like to be able to get information from a Tkinter canvas
> > object. (color, width, tags, root points, etc),
> >
> >  I wrote the following function that, with a canvas bind, returns me the
> > widget that has been clicked on, the widget is returned as a tuple by the
> > find_overlapping method.
> >
> > # detecting click
> > def Hasclicked(e):
> > global obj
> > global lastClick
> > lastClick = [e.x, e.y]
> > obj = e.widget.find_overlapping(e.x, e.y, e.x, e.y)
> >
> >   So, there's any method I can use on 'obj' to get the attributes?
>
> obj is a tuple of ids. You can use canvas.itemcget(id, attribute) to
> explore
> the properties of the underlying objects
>
> To get (for example) their fill-color:
>
> for id in e.widget.find_overlapping(e.x, e.y, e.x, e.y):
> print canvas.itemcget(id, "fill")
>
> A complete example:
>
> from __future__ import division
> import Tkinter as tk
> from math import cos, sin, pi
>
> WIDTH = 640
> HEIGHT = 480
>
> root = tk.Tk()
> canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT)
> canvas.pack()
>
> var = tk.StringVar()
> label = tk.Label(root, textvariable=var)
> label.pack()
>
> def canvas_click(event):
> x, y = event.x, event.y
> ids = canvas.find_overlapping(x, y, x, y)
> clicked_colors = ", ".join(canvas.itemcget(id, "fill") for id in ids)
> var.set(clicked_colors)
>
> RADIUS = 100
> R = 80
> CX = WIDTH // 2
> CY = HEIGHT // 2
>
> phi = pi/2 # 90 degree
> for color in "red", "green", "blue":
> x = int(CX + R*cos(phi))
> y = int(CY - R*sin(phi))
> phi += pi*2/3 # 120 degree
>
> canvas.create_oval(x-RADIUS, y-RADIUS, x+RADIUS, y+RADIUS, fill=color)
>
> canvas.bind("", canvas_click)
> root.mainloop()
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


 Thank you, just what I needed.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PostreSQL

2012-11-15 Thread James Reynolds
Psycopg2 is the driver for postgres. Not sure if it is py3k compliant
On Nov 15, 2012 6:13 AM, "Válas Péter"  wrote:

> Two listings, of course. :-)
> I failed to tell that my PG version is "PostgreSQL 8.1.2" (and my client
> uses Windows 7, if this has relevance).
>
> 2012/11/15 Válas Péter 
>
>> Hi folks,
>>
>> Here are to listings of Python interfaces to PostgreSQL:
>> Postgres wiki: http://wiki.postgresql.org/wiki/Python
>> Python wiki: http://wiki.python.org/moin/PostgreSQL
>>
>> I have Python 3.2.3.
>> Does anybody have experiences with these modules? Which is worth to use?
>> Any point of view to compare them?
>>
>> Thanks, Péter
>>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor