Python para PDA
Andrés Ignacio Martínez Soto
al084070 en alumail.uji.es
Mar Ago 16 11:11:17 CEST 2005
#Aquí el código
#!/usr/bin/python
#-*-coding:UTF-8 -*-
import sys
#sys.path.append("\\Storage Card\\Python\\Lib\\python23.zip\\lib-tk")
#importa mòdul sys i verifica la plataforma sobre la que corre
import sys
if sys.platform!="Pocket PC":
try:
from Tkinter import *
from tkMessageBox import *
from time import localtime, strftime
except:
raise "No s'han pogut importar els mòduls\nSortint"
else:
try:
sys.path.append("\\Storage Card\\Python\\Lib\
\python23.zip\\lib-tk")
from Tkinter import *
from tkMessageBox import *
from time import localtime, strftime
except:
raise "No s'han pogut importar els mòduls\nSortint"
global lista
lista=[]
class Program(Frame):
"""PocketTrainSpotter"""
def __init__(self,master):
Frame.__init__(self,master)
self.grid()
self.frame1()
def frame1 (self):
frame1=Frame(self)
self.lpaisdata=Label(self,text="País i
data").grid(row=0,column=1,sticky=W)
self.lpais=Label(self,text="País").grid(row=1,sticky=W)
self.pais=Entry(self,width=14)
self.pais.grid(row=1,column=1,sticky=W)
self.llloc=Label(self,text="Lloc").grid(row=2,sticky=W)
self.lloc=Entry(self,width=14)
self.lloc.grid(row=2,column=1,sticky=W)
self.ldata=Label(self,text="Data").grid(row=3,column=0,sticky=W)
self.data=Entry(self,width=14)
self.data.grid(row=3,column=1,sticky=W)
self.ldades=Label(self,text="Dades del
tren").grid(row=4,column=1,sticky=W)
self.lcomp=Label(self,text="Companyia").grid(row=5,column=0,sticky=W)
self.comp=Entry(self,width=14)
self.comp.grid(row=5,column=1,sticky=W)
self.lnum=Label(self,text="Numeració").grid(row=6,column=0,sticky=W)
self.num=Entry(self,width=14)
self.num.grid(row=6,column=1,sticky=W)
self.ldades=Label(self,text="Tipus de
tren").grid(row=7,column=1,sticky=W)
self.lesq=Label(self,text="Esquema de
colors").grid(row=8,column=0,sticky=W)
self.esq=Entry(self,width=14)
self.esq.grid(row=8,column=1,sticky=W)
self.sep=Label(self,text="").grid(row=9,column=1,sticky=W)
self.bt=Button(self,text="Continua",command=self.dades1).grid(row=10,column=0,sticky=W)
self.sortir=Button(self,text="Sortir",command=self.surt,bd=3,bg="yellow",anchor="center").grid(row=10,column=1,sticky=W)
return frame1
def frame2 (self):
#esborra finestra1
self.sep=Label(self,width=16).grid(row=6,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=7,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=8,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=9,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=9,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=6,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=7,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=8,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=9,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=9,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=10,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=10,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=11,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=12,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=1,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=1,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=3,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=3,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=4,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=4,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=5,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=5,column=1,sticky=W)
self.lloc.destroy()
print "Frame 2 creada"
frame2=Frame(self)
self.update()
self.ltob=Label(self,text="Tipus
d'objecte").grid(row=0,column=0,sticky=W)
self.lista=Listbox(self,height=6,width=16)
llista=["Edifici","Locomotora","Automotor","Detall","Cotxe Viatgers","Vagó mercaderies"]
for item in llista:
self.lista.insert(END,item)
self.lista.grid(row=0,column=1,sticky=W)
self.lttren=Label(self,text="Dades del
tren").grid(row=1,column=1,sticky=W)
self.ltren=Label(self,text="Tipus de
tren").grid(row=2,column=0,sticky=W)
self.dtptren=Entry(self,width=14)
self.dtptren.grid(row=2,column=1,sticky=W)
self.ntren=Label(self,text="Numero de
tren").grid(row=3,column=0,sticky=W)
self.numtren=Entry(self,width=14)
self.numtren.grid(row=3,column=1,sticky=W)
self.lorigen=Label(self,text="Origen").grid(row=4,column=0,sticky=W)
self.origen=Entry(self,width=14)
self.origen.grid(row=4,column=1,sticky=W)
self.ldest=Label(self,text="Destinació").grid(row=5,column=0,sticky=W)
self.dest=Entry(self,width=14)
self.dest.grid(row=5,column=1,sticky=W)
self.bat=Button(self,text="Continua",command=self.dades2).grid(row=8,column=0,sticky=W)
self.sartir=Button(self,text="Sortir",command=self.surt,bd=3,bg="yellow",anchor="center").grid(row=8,column=1,sticky=W)
self.update()
return frame2
def frame3 (self):
frame3=Frame(self)
#esborra widgets finestra 2
self.lista.destroy()
self.sep=Label(self,width=16).grid(row=0,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=0,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=1,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=1,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=2,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=2,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=3,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=3,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=4,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=4,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=5,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=5,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=6,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=6,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=7,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=7,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=8,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=8,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=9,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=9,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=10,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=10,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=11,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=11,column=1,sticky=W)
self.sep=Label(self,width=16).grid(row=12,column=0,sticky=W)
self.sep=Label(self,width=16).grid(row=12,column=1,sticky=W)
self.update()
#widgets frame3:
self.lob=Label(self,text="Observacions").grid(row=0,column=0,sticky=W)
self.obs=Entry(self,width=30)
self.obs.grid(row=1,column=0,sticky=W)
self.btt=Button(self,text="Genera
fitxa",command=self.dades3).grid(row=2,column=0,sticky=W)
self.srtir=Button(self,text="Sortir",command=self.surt,bd=3,bg="yellow",anchor="center").grid(row=3,column=0,sticky=W)
print "Frame 3 creada"
self.update()
self.foo()
def foo(self):
print "Foo"
def dades1 (self):
lista.append(self.pais.get())
lista.append(self.lloc.get())
lista.append(self.data.get())
lista.append(self.comp.get())
lista.append(self.num.get())
lista.append(self.esq.get())
print lista
self.frame2()
def dades2 (self):
lista.append(self.lista.get(ACTIVE) )
lista.append(self.dtptren.get())
lista.append(self.numtren.get())
lista.append(self.esq.get())
lista.append(self.origen.get())
lista.append(self.dest.get())
print lista
self.frame3()
def dades3(self):
lista.append(self.obs.get())
print lista
self.procesa_xml(lista)
print "fitxa generada"
return lista
def conv_ui(self,cadena):
ul=unicode(cadena,"latin_1")
ul.encode("latin_1")
return ul
def procesa_sql (self,lista):
import os
file=""
if sys.platform=="linux2":
import commands
path = commands.getoutput("echo $HOME")
sep = os.sep
psep = os.pathsep
file="%s%sllista.htmlº"%(path,sep)
elif sys.platform=="win 32":
path = "c:\\llista.html"
file="%s"%(path)
elif sys.platform=="Pocket PC":
path = " \\ "
sep = os.sep
psep = os.pathsep
file="%sllista.html"%(path)
else:
pass
def procesa_xml(self,lista):
import os
file=""
if sys.platform=="linux2":
import commands
path = commands.getoutput("echo $HOME")
sep = os.sep
psep = os.pathsep
file="%s%sllista.htmlº"%(path,sep)
elif sys.platform=="win 32":
path = "c:\\llista.html"
file="%s"%(path)
elif sys.platform=="Pocket PC":
path = " \\ "
sep = os.sep
psep = os.pathsep
file="%sllista.html"%(path)
else:
file="llista.html"
buit="""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//CA"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ca" lang="ca">
<head>
<style>
div#foto {font-weight : ligther;
border: medium groove #aba1a1;
background:#eeeeee;
overflow: auto;
}
div#num {background:#A1BBFF }
div#pais {font-weigth: ligther; font-style: italic;}
div#lloc { font-weight : bold;
font-style : italic;
height : 20 }
</style>
<nm><!--%d--></nm>
<title>Fotos trens</title>
</head>
<body>
<b> Dades de les fotos </b>
<p></p>
</body>
</html>
<eof></eof>"""
try:
f=open(file,"r")
except IOError:
try:
#Si deixa el sistema operatiu/no es troba
llista.html, es crea una llista buida
f=open(file,"w")
f.write(buit)
f.close()
f=open(file,"r")
except:
print "No s'ha pogut obrir el fitxer"
raw_input("")
def copia(f):
try:
fold="%s.old"%(file)
g=open(fold,"w")
except IOError:
try:
#Si deixa el sistema operatiu/no es troba llista.html, es crea
una llista buida
g=open(fold,"w")
g.write(buit)
g.close()
g=open(fold,"r")
except:
print "No s'ha pogut obrir el
fitxer"
raw_input("")
return -1
dades=f.read()
g.write(dades)
g.close()
return 0
def llig(f):
lista=f.read()
lista=lista[:-29]
return lista
copia(f)
ls=llig(f)
f.close()
f=open(file,"a")
def escriu(f,dades):
bloc="""
<title>Fotos trens</title>
</head>
<body>
<b> Dades de les fotos </b>
<div style="width: 230px; height: 320px;" id="foto">
<foto>
<dades>
<p><b><i> Lloc i data</i></b></p>
<lloc>
<pais><b> País: </b> %s </pais><br></br>
<indret><b> Lloc: </b>%s </indret><br></br>
</lloc>
<data><b>Data:</b> %s </data><br></br>
</dades>
<p><b><i> Dades del tren </i></b></p>
<tren>
<companyia>
<propietari><b> Companyia:</b> %s </propietari><br></br>
<numeracio><b> Numeració: </b>%s </numeracio><br></br>
<tipus><b>Tipus d'objecte: </b>%s</tipus><br></br>
<esquema_colors><b>Esquema de colors:</b> %s
</esquema_colors><br></br>
</companyia>
<p><b><i> Tipus tren </i></b></p>
<tipus_tren>
<tipus><b>Tipus de tren:</b> %s </tipus><br></br>
<numtren><b>Número de tren: </b>%s </numtren><br></br>
<origen><b>Origen:</b> %s </origen><br></br>
<destinacio><b>Destinació: </b> %s </destinacio><br></br>
</tipus_tren>
</tren><p></p>
<observacions><b>Observacions:</b> %s</observacions><br></br>
</foto>
</div>"""%(dades[0],dades[1],dades[2],dades[3],dades[4],dades[6],dades[5],dades[7],dades[8],dades[9],dades[10],dades[11])
f.write(bloc)
return 0
escriu(f,lista)
f.write("</body></html><eof></eof>")
f.close()
self.info()
def surt (self):
if askyesno("Sortint","Surt?"):
sys.exit(0)
else:
return
def info (self):
showinfo("Avís","Fitxa generada\nPremi ok per sortir")
self.surt()
root=Tk()
print sys.platform
if sys.platform=="linux2":
root.title("LinPyTrainspotter")
root.geometry("450x320")
elif sys.platform=="win 32":
root.title("WinPyTrainspotter")
root.geometry("450x320")
elif sys.platform=="Pocket PC":
root.title("PocketPyTrainspotter")
root.geometry("240x320")
else:
root.title("PyTrainspotter")
root.geometry("450x320")
app=Program(root)
root.mainloop()
#/Fin del código
¿Alguien podría decirme como envíar un post a la lista y que quede en el
mismo hilo que el otro? -> gracias, para mi es raro o imposible ;).
Saludos
------------ próxima parte ------------
_______________________________________________
Python-es mailing list
Python-es en aditel.org
http://listas.aditel.org/listinfo/python-es
Más información sobre la lista de distribución Python-es