# -*- coding: cp1252 -*- """A faire : - améliorer l'automatisme de positionnement des uiobjects - gérer les valeurs par défaut (boutons, champs, memo) - gérer le mapping - gérer un autre emplacement alternatif pour les fichiers de fiche - séparer le code, des librairies, et de la définition des uiobjects ? - gérer les 'fenêtres à la volée' - mieux gérer les w=open """ GlobalPVersion='1.02' try: import ponx except: pass import re,time,sys,os,string def OLD_remplacerchlst(st, listeremplacement): # dans la chaine (st), on remplace X fois [chaine par remplacement] newdata=st for chaine,remplacement in listeremplacement: newdata = re.sub(chaine, remplacement, newdata) return(newdata) import dico def defconstantes(): """Définition de constantes globales à iPONX """ global clic,depart,focus,blur global right,left,center global champ,uiobject global UIfil clic='clic' depart='depart' focus='focus' blur='blur' right='right' left='left' center='center' champ='champ' uiobject='uiobject' defconstantes() #global UI,DFORM #UI=dico.dico() #DFORM=dico.dico() GlobalBuffer={} GlobalGroupHTML={} GlobalGroupageHT=False def dicoDeplDer(avantle=None): global UI nb=0 st="" DERKEY=ponx.UI.keys()[len(ponx.UI)-1] #msginfo("dernier",DERKEY) TMP=dico.dico() DER=ponx.UI[DERKEY] for i in ponx.UI.keys(): st=st+str(i)+" " if i==DERKEY: continue if i==avantle: TMP[DERKEY]=ponx.UI[DERKEY] TMP[i]=ponx.UI[i] nb=nb+1 ponx.UI=TMP #msginfo(str(nb),st) ''' st="" for i in ponx.UI.keys(): st=st+str(i)+" " msginfo(str(nb),st) ''' def iif(cond,*a): return a[not cond] def UIcrlf(m): #return re.sub('\r\n',r'\\r\\n', m) return re.sub('\n',r'\\r\\n', m) def UIlf(m): mm=re.sub('\r\n','\n', m) return re.sub('\n',r'\\n', mm) def UIguisimple(m): return re.sub('"',""", m) #return re.sub('"',"'", m) def UIguiquote(m): return re.sub(""",'"', m) def UInocrlf(m): mm=re.sub('\r','', m) mm=re.sub('\n','', mm) return(mm) def listDeroulData(lvaleurs, selection=None): sret="" for item in lvaleurs: sret+=" " for lig in item[1:]: if str(lig)==selection: sret+="" else: sret+="" sret+=" " pass return(sret) def strlstlst(a): """Convertit une chaine en liste de liste, à utiliser dans une liste déroulante @return: une liste de liste """ #msginfo("chaine",a) c=a.replace(r'[[', '') c=c.replace(r']]', '') b=string.split(c,'],[') ls=[] for i in b: ls.append(list(string.split(i,','))) #msginfo('ls',ls) return ls def finspace(txt): if txt[-1:]==' ': return('') else: return(' ') class form(object): def __init__(self): self.name='' self.form='' self.method={} self.derUI='' self.derCH='' # dernier champ (pour positionnement automatique) self.derBT='' # dernier bouton (pour positionnement automatique) self.derCHx=0 # dernière position X champ self.derCHy=0 # dernière position Y champ self.derBTx=0 # dernière position X bouton self.derBTy=0 # dernière position Y bouton self.defBTw=100 # largeur par défaut des boutons self.defBTh=25 # hauteur par défaut des boutons self.derBoutonTailleVerti=25 # dernière taille verticale des boutons self.derBoutonTailleHoriz=100 # dernière taille horizontale des boutons self.derAutreTailleVerti=20 # dernière taille verticale autre que boutons self.defCHw=60 # largeur par défaut des champs self.defCHh=20 # hauteur par défaut des champs self.chainecreation='' self.chaineliens='' self.UIlien=None self.fWidth=400 # largeur de la fiche self.fHeight=300 # hauteur de la fiche def setsize(self,w,h): self.fWidth=w self.fHeight=h def setname(self,name): self.name=name self.form=name self.chaineliens='defFORMlien("'+self.name+'")' #ponx.UI[self.name]=[] def htexec(self,chaine): #ponx.msginfo(self.UIlien.innerText,chaine) self.UIlien.innerText=chaine time.sleep(0.1) class propertyui(object): def __init__(self,nomprop,doc,lannul=[]): self.nom=nomprop self.doc=doc self.annul=lannul def htproto(typ): if typ=='Button': proto=''' ''' elif typ=='Field': proto='''
''' elif typ=='ChampCheck': proto='''
TTTTT
''' elif typ=='ChampRadio': proto='''
TTTTT IIIII
''' elif typ=='ListDeroul': proto='''TTTTT IIIII ''' elif typ=='Tableau': proto='''TTTTT IIIII ''' elif typ=='Text': proto='''TTTTT ''' elif typ=='Memo': proto='''
TTTTT
''' elif typ=='ActiveX': proto=''' ''' return proto class uiobject(object): def __init__(self,typ,form,name=None): self.typ=typ # Button Field ChampCheck ChampRadio ListDeroul Tableau Text Memo ActiveX self.manager=form.name # nom de la fiche self.form=form.name # nom de la fiche self.parentobject=form # objet (pointeur) sur le fiche self.method={} # dictionnaire des méthodes self.labeltext='' # Libellé self.x=None # Position X self.y=None # Position Y self.typosition=None # 'default' None ; utilisé pour le positionnement automatique, voir form( self.soutyp=None # number date ; utilisé pour décodage de la valeur, dans UIread (Field ChampCheck ChampRadio Memo ActiveX) self.style=None # style Html, pour surcharger le CSS self.width=None # largeur self.height=None # hauteur self.typsize=None # 'défault' None self.value='' # valeur initiale (Field ChampCheck Memo) self.valuecurrent='' # valeur courante (buffer) (Field ChampCheck ListDeroul Memo) self.valselected=None # valeur sélectionnée (ListDeroul) self.listevaleurs=[] # valeurs initiales (ListDeroul ChampRadio) self.align='' # left right center (Field ChampCheck Text Memo) self.nbchar=None # nb caractères par défaut (Field ChampCheck Text Memo) self.nbligs=None # nb lignes par défaut (Tableau Memo) self.nbcols=None # nb colonnes par défaut (Tableau) self.UIlien=None # lien COM entre iPonx et l'interface self.HTML='' # buffer du source-HTML self.AccrocheHoriz=None # accrochage horizontal ('FORM' pour la fiche) self.AccrocheVerti=None # accrochage vertical ('FORM' pour la fiche) if name!=None: self.setname(name) def setaccroche(self, AccrocheHoriz=None, AccrocheVerti=None): if AccrocheHoriz!=None: self.AccrocheHoriz=AccrocheHoriz if AccrocheVerti!=None: self.AccrocheVerti=AccrocheVerti else: if AccrocheHoriz!=None: self.AccrocheVerti=AccrocheHoriz def setaccrocheH(self, AccrocheHoriz=None): if AccrocheHoriz!=None: self.AccrocheHoriz=AccrocheHoriz def setaccrocheV(self, AccrocheVerti=None): if AccrocheVerti!=None: self.AccrocheVerti=AccrocheVerti else: if AccrocheHoriz!=None: self.AccrocheVerti=AccrocheHoriz def setposition(self,x=None,y=None): if x==None: self.typosition='default' if self.AccrocheHoriz==None: if self.typ=='Button': x=self.parentobject.derBTx else: x=self.parentobject.derCHx else: if self.AccrocheHoriz=='FORM': x=0 else: x=ponx.UI[self.AccrocheHoriz].x if y==None: self.typosition='default' if self.typ=='Field': y=self.parentobject.derCHy+25 if self.typ=='Button': y=self.parentobject.derBTy+self.parentobject.derBoutonTailleVerti if self.AccrocheHoriz==None: self.x=x else: self.x=ponx.UI[self.AccrocheHoriz].x+x if self.AccrocheVerti==None: self.y=y else: self.y=ponx.UI[self.AccrocheVerti].y+y self.position=(self.x,self.y) if self.typ=='Field': self.parentobject.derCHx=self.x self.parentobject.derCHy=self.y if self.typ=='Button': self.parentobject.derBTx=self.x self.parentobject.derBTy=self.y def setpositionX(self,x=None): if x==None: self.typosition='default' if self.AccrocheHoriz==None: if self.typ=='Button': x=self.parentobject.derBTx else: x=self.parentobject.derCHx else: if self.AccrocheHoriz=='FORM': x=0 else: x=ponx.UI[self.AccrocheHoriz].x if self.AccrocheHoriz==None: self.x=x else: self.x=ponx.UI[self.AccrocheHoriz].x+x self.position=(self.x,self.y) if self.typ=='Field': self.parentobject.derCHx=self.x if self.typ=='Button': self.parentobject.derBTx=self.x def setpositionY(self,y=None): if y==None: self.typosition='default' if self.typ=='Field': y=self.parentobject.derCHy+25 if self.typ=='Button': y=self.parentobject.derBTy+self.parentobject.derBoutonTailleVerti if self.AccrocheVerti==None: self.y=y else: self.y=ponx.UI[self.AccrocheVerti].y+y self.position=(self.x,self.y) if self.typ=='Field': self.parentobject.derCHy=self.y if self.typ=='Button': self.parentobject.derBTy=self.y def setlig(self,nb=1): self.nbligs=nb def setcol(self,nb=1): self.nbcols=nb def setsize(self,x=None,y=None): if x==None: self.typsize='default' if self.typ=='Field': x=self.parentobject.defCHw if self.typ=='Button': x=self.parentobject.defBTw if y==None: self.typsize='default' if self.typ=='Field': y=self.parentobject.defCHh if self.typ=='Button': y=self.parentobject.defBTh self.width=x self.height=y self.size=(self.width,self.height) if self.typ=='Button': self.parentobject.derBoutonTailleVerti=self.height else: self.parentobject.derAutreTailleVerti=self.height def setwidth(self,x=None): if x==None: self.typsize='default' if self.typ=='Field': x=self.parentobject.defCHw if self.typ=='Button': x=self.parentobject.defBTw self.width=x self.size=(self.width,self.height) def setheight(self,y=None): if y==None: self.typsize='default' if self.typ=='Field': y=self.parentobject.defCHh if self.typ=='Button': y=self.parentobject.defBTh self.height=y self.size=(self.width,self.height) if self.typ=='Button': self.parentobject.derBoutonTailleVerti=self.height else: self.parentobject.derAutreTailleVerti=self.height def setname(self,name): self.name=name self.parentobject.derUI=name if self.typ=='Field': self.parentobject.derCH=name if self.typ=='Button': self.parentobject.derBT def setsoutyp(self,typ): self.soutyp=typ def setstyle(self,sty): self.style=sty def setlabeltext(self,text): self.labeltext=text def setdoc(self,text): self.doc=text def setlistevaleurs(self, lst, selected=None): self.listevaleurs=lst self.valselected=selected def setvalselected(self, selected=None): self.valselected=selected def setvalue(self,anyt): self.value=anyt def setalign(self,salign): self.align=salign def setnbchar(self,nb): self.nbchar=nb def setnbligs(self,nb): self.nbligs=nb def generate(self, mod='all'): """ génère le HTML de l'UIobject mod peut être : 'all' création complète d'une fiche, depuis rien 'restreint' ne traite que la partie purement UIobject, en non l'ensemble de la fiche. """ if self.x==None or self.y==None: self.setposition() if self.width==None or self.height==None: self.setsize() if self.typ=='Button': self.fonction='' proto=htproto('Button') if self.style==None: sty='' else: sty="class='"+self.style+"'" rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('333',str(self.width)), ('444',str(self.height)), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('FFFFF',self.fonction), ('KLASS',sty), ] tmpstr=ponx.remplacerchlst(proto,rpl) #uniw32dia(tmpstr,'Chaine') self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr if self.typ=='Field': self.fonction='' proto=htproto('Field') if(self.nbchar==None): buf333=str(8*8) else: buf333=str(self.nbchar*8) rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('333',buf333), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('FFFFF',self.fonction), ('VVVVV',str(self.value)), ('text-align:left','text-align:'+self.align), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr if self.typ=='ChampCheck': self.fonction='' proto=htproto('ChampCheck') if(self.nbchar==None): buf333=str(8*8) else: buf333=str(self.nbchar*8) rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('333',buf333), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('FFFFF',self.fonction), ('VVVVV',str(self.value)), ('text-align:left','text-align:'+self.align), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr if self.typ=='ChampRadio': self.fonction='' proto=htproto('ChampRadio') sinput='' for item in self.listevaleurs: sinput+= " "+str(item)+" " rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('FFFFF',self.fonction), ('IIIII',sinput), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr if self.typ=='ListDeroul': self.fonction='' proto=htproto('ListDeroul') sinput=" ' rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('FFFFF',self.fonction), ('IIIII',sinput), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr if self.typ=='Tableau': self.fonction='' proto=htproto('Tableau') sinput=" " s1=" " sst=[] for i in xrange(self.nbligs): #sinput=sinput+' ' sst.append(' ') for c in xrange(self.nbcols): #sinput=sinput+s1+str(i)+"C"+str(c)+s2+str(i)+"."+str(c)+s3 sst.append(s1+str(i)+"C"+str(c)+s2+str(i)+"."+str(c)+s3) #sst.append(s1,str(i),"C",str(c),s2,str(i),".",str(c),s3]) #sinput=sinput+""" " #sinput=sinput+' ' sst.append(' ') sinput=sinput+string.join(sst) sinput=sinput+'
 
 
' rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('444',str(self.height)), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('FFFFF',self.fonction), ('IIIII',sinput), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr for cl in xrange(self.nbcols): nom=self.name+'.'+str(cl) ponx.UI[nom]=uiobject('TField',ponx.DFORM[self.form],nom) return tmpstr if self.typ=='Text': self.fonction='' proto=htproto('Text') if(self.nbchar==None): buf333=str(8*8) else: buf333=str(self.nbchar*8) rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('333',buf333), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('text-align:left','text-align:'+self.align), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr if self.typ=='Memo': self.fonction='' proto=htproto('Memo') if(self.nbchar==None): buf333=str(20) else: buf333=str(self.nbchar) rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('333',buf333), ('444',str(self.nbligs)), ('NNNNN',self.name), ('TTTTT',self.labeltext), ('FFFFF',self.fonction), ('VVVVV',str(self.value)), ('text-align:left','text-align:'+self.align), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr if self.typ=='ActiveX': self.fonction='' proto=htproto('ActiveX') rpl=[ ('111',str(self.x)), ('222',str(self.y)), ('333',str(self.width)), ('444',str(self.height)), ('NNNNN',self.name), ] tmpstr=ponx.remplacerchlst(proto,rpl) self.HTML=tmpstr if mod!='restreint': tmpstr='''document.body.innerHTML = document.body.innerHTML+" '''+tmpstr+'"; \r\n' self.parentobject.chaineliens = self.parentobject.chaineliens + '\r\nUIlienPonx("'+self.name+'");' self.parentobject.chainecreation=self.parentobject.chainecreation+tmpstr return tmpstr def finalizeliens(self): """ lance la mémorisation des liens COM """ return self.parentobject.chaineliens def sourcemethod(self): """ retourne la liste des méthodes d'un UIobject """ method={} for m in self.method: method[self.name+"."+m]=self.method[m] return method def gsource(self,formcurrent): """ Génère le code-source d'une fiche - retourne un string - n'écrit pas le fichier """ txt=[''] #d'abord, cas du 'champlabeltext' if self.typ=='Text' and self.AccrocheHoriz!=None: parenTyp=ponx.UI[self.AccrocheHoriz].typ if parenTyp=='Field' or parenTyp=='ListDeroul' or parenTyp=='ChampCheck' or parenTyp=='ChampRadio' or parenTyp=='Memo': if self.AccrocheVerti==None: ydiff=self.y-ponx.UI[self.AccrocheHoriz].y else: ydiff=self.y-ponx.UI[self.AccrocheVerti].y xdiff=self.x-ponx.UI[self.AccrocheVerti].x if xdiff<-80.5 or xdiff>-79.5: xdecal=","+str(xdiff) else: xdecal="" if ydiff==3: if self.labeltext.endswith(' '): txt.append("st=st+ui.champlabeltext(nom,'''"+self.labeltext+"'''"+xdecal+")") else: txt.append("st=st+ui.champlabeltext(nom,'''"+self.labeltext+" '''"+xdecal+")") return(string.join(txt,'\n ')) txt.append("nom='"+self.name+"'") txt.append("UI[nom]=ui.uiobject('"+self.typ+"',CURRFORM,nom)") if self.labeltext!='': txt.append("UI[nom].setlabeltext('"+self.labeltext+"')") if self.AccrocheHoriz==None: if self.AccrocheVerti!=None : txt.append("UI[nom].setaccroche(None,"+self.AccrocheVerti+")") else: if self.AccrocheVerti!=None and self.AccrocheVerti!=self.AccrocheHoriz: txt.append("UI[nom].setaccroche('"+self.AccrocheHoriz+"','"+self.AccrocheVerti+"')") else: txt.append("UI[nom].setaccroche('"+self.AccrocheHoriz+"')") if self.typosition!='default': if self.AccrocheHoriz!=None: bufx=self.x-ponx.UI[self.AccrocheHoriz].x else: bufx=self.x if self.AccrocheVerti!=None: bufy=self.y-ponx.UI[self.AccrocheVerti].y else: bufy=self.y txt.append("UI[nom].setposition("+str(bufx)+","+str(bufy)+")") if self.soutyp!=None: txt.append("UI[nom].setsoutyp('"+self.soutyp+"')") if self.style!=None: txt.append("UI[nom].setstyle('"+self.style+"')") if self.typsize!='default': txt.append("UI[nom].setsize("+str(self.width)+","+str(self.height)+")") if self.nbchar!=None: txt.append("UI[nom].setnbchar("+str(int(self.nbchar))+")") if self.nbligs!=None: txt.append("UI[nom].setnbligs("+str(self.nbligs)+")") if self.nbcols!=None: txt.append("UI[nom].setcol("+str(self.nbcols)+")") if self.align!='': txt.append("UI[nom].setalign("+self.align+")") if self.listevaleurs!=[] : if self.typ=='ChampRadio': buf='' for m in self.listevaleurs: buf=buf+"'"+m+"'," txt.append("UI[nom].setlistevaleurs(["+buf[:-1]+"])") for m in self.method: txt.append("UI[nom].setmethod(ui."+m+",\"\"\"ui."+self.method[m]+finspace(self.method[m])+"\"\"\")") if self.typ=='ListDeroul': buf='[' for group in self.listevaleurs: buf+='[' for item in group: buf+="'"+item+"'," buf=buf[:-1]+'],' buf=buf[:-1]+']' txt.append("UI[nom].setlistevaleurs("+buf+")") for m in self.method: try: st='''UI[nom].setmethod('''+m+''',\"\"\"'''+self.method[m]+finspace(self.method[m])+'''\"\"\")''' try: st=unicode(st.decode('cp1252')) except: try: st=unicode(st) except: st=str(st) #msginfo(str(type(st)),st) txt.append(st) #msginfo(str(type(st)),str(type(txt[len(txt)-1]))) except: msginfo("Erreur gsource (accent ?)",nom) txt.append("st=st+UI[nom].generate()") return(string.join(txt,'\n ')) def setmethod(self, typ, source): src=re.sub('\r\n', '\n', source) if src[-3:]==' ': src=src[:-3] if src[-2:]==' ': src=src[:-2] if typ==clic: self.method[typ]=src if typ==depart: self.method[typ]=src if typ==focus: self.method[typ]=src def champlabeltext(champcourant, txt='', xdecal=-80): nom=champcourant+'TC' ponx.UI[nom]=uiobject('Text',ponx.DFORM[ponx.UI[champcourant].form], nom) ponx.UI[nom].setaccroche(champcourant) ponx.UI[nom].setlabeltext(txt) ponx.UI[nom].setposition(xdecal,3) return(ponx.UI[nom].generate()) def enumUI(formname, typ=None, callback=None, *args, **kw): """traite en ensemble d' UIobjects @param:forname: nom de la fiche à analyser @param:typ: type d'objet ('Field','Button','Text') si None, prend tout @param:callback: nom d'une fonction à appliquer, le premier paramètre sera l'UIobject (si None, retourne une liste) """ lst=[] for item in ponx.UI.keys(): #msginfo(ponx.UI[item].manager,formname) if ponx.UI[item].manager==formname: #msginfo(formname,str(args[0])) if typ==None or typ==ponx.UI[item].typ: if callback==None: lst.append(item) else: #msginfo("callback",item) callback(ponx.UI[item],*args,**kw) return(lst) def enumForms(fpath=''): """retourne la liste des fiches (Forms) d'un directory @param: 1: par défaut, il s'agit du répertoire courant """ lstf=os.listdir(fpath) lform=[] for fich in lstf: if string.upper(fich[-4:])=='.HTM' or string.upper(fich[-4:])=='.HTA': f=fich[:-4] #print f,fpath+'\\'+f, if os.path.isdir(f): if f.upper() not in lform: lform.append(f.upper()) #print "True" else: #print "NON" pass return(lform) def UIsources(fichier=None, frm=''): """ génère le code source de définition des objets (écrit/génère UI.F dans le sous-répertoire frm, si fichier=True) """ txt="\ndef PUIforminit():\n" txt+=" global chaineretour,DFORM,UI\n" txt+=" FormNom='"+frm+"'\n" txt+=" DFORM[FormNom]=ui.form()\n" txt+=" DFORM[FormNom].setsize("+str(ponx.DFORM[frm].fWidth)+","+str(ponx.DFORM[frm].fHeight)+")\n" txt+=" DFORM[FormNom].setname(FormNom)\n" txt+=" CURRFORM=DFORM[FormNom]\n" txt+=" st=''\n" for uio in ponx.UI.keys(): if ponx.UI[uio].form==frm: try: st=ponx.UI[uio].gsource(frm)+'\n' txt=txt+st except: msginfo('Erreur (accent ?)',uio) txt=txt+'\n\n st=st+ponx.UI[nom].finalizeliens()\n' txt=txt+'\n chaineretour=st\nPUIforminit()\n' if fichier==True: f=open(frm+'\\UI.F','w') f.write(txt) f.close() return(txt) def getmethodlist(uio): return(ponx.UI[uio].method.keys()) def enummethods(fichier=None, frm=''): """ génère les fichiers source des méthodes des UIobject+évènements d'une fiche cela se fait par appel de la méthode sourcemethod de la classe uiobject """ meth={} txt='' for uio in ponx.UI.keys(): txt=txt+'\r\n' #txt=txt+'#UI: '+ponx.UI[uio].name+'\r\n' dt=ponx.UI[uio].sourcemethod() for met in dt: meth[met]=dt[met] txt=txt+'# '+met+'\r\n'+dt[met]+'\r\n' if fichier!=None: f=open(frm+'\\'+met,'w') f.write('# '+met+'\r\n'+dt[met]) f.close() return(txt) def UIScharge(frm='', uio='', evt=''): """charge un code-source dans la fenêtre source.htm S'il n'y a pas de paramètres, charge 'Proc.F' """ global GlobalU if frm=='': f=open('Proc.F','rb') GlobalU=f.read() f.close() st="""var w = window.open('source.htm', '', '"toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=350, top=400, left=200');""" ponx.chaineretour=st else: GlobalU=""+ponx.UI[uio].method[evt] st="""var w = window.open('source.htm', '', '"toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=350, top=400, left=200');""" #GlobalU=""+GlobalU ponx.chaineretour=st def UIrerunproc(): """ recharge proc.F """ execfile("proc.F",globals(),globals()) #f=open('proc.F','r') #procf=f.read() #f.close() #exec(procf,globals(),globals()) def UImethodsavexe(uio='', evt='', source=''): """affecte une méthode à un uiobject+évènement Attention, les fichiers-sources ne sont pas affectés (pas de persistance). @param: uio: nom de l'UIobject ; si '' alors, on traite Proc.F @param: evt: nom de l'évènement ('clic', etc.) """ if uio=='': f=open('proc.F','w') f.write(source) f.close() #exec(source,globals(),globals()) UIrerunproc() else: #src=re.sub('\r\n', '\n', source.encode('cp1252','replace')) #src=re.sub('\r\n', '\n', unicode(source).encode('cp1252','replace')) #src=re.sub('\r\n', '\n', source.encode(CodingParDefaut,'replace')) src=re.sub('\r\n', '\n', source) #msginfo(evt,src) ponx.UI[uio].setmethod(evt,src) def UIcurmethodsavexe(): frm=UIread('UICHOIXCHF') uio=UIread('UICHOIXCH1') #msginfo(frm,uio) uio=string.split(uio,' : ')[0] evt=string.lower(UIread('UICHOIXCH2')) source=UIread('SOURCEMEM1') UImethodsavexe(uio, evt, source) def niveausup(nomform): ch='DFORM['+nomform+'''].UIlien.innerText="ponx.PRun('','AAA','BBB','CCC');"''' ccod=compile(ch,'iponx:niveausup','exec') exec(ccod,globals(),globals()) time.sleep(0.2) def initlienfield(nom): ponx.chaineretour="eFieldPonx('CH02');" def prefixedclic(cible): #uniw32dia('cible: '+str(cible), titre='Prefixed Clic') pass def uiobjectclic(cible): import inspect,traceback,cStringIO global clic #uniw32dia('cible: '+str(cible)+' '+str(ponx.UI.has_key(cible)), titre='UIobject Clic') if ponx.UI.has_key(cible): try: #ponx.uniw32dia(ponx.UI[cible].method[clic],'methoddd.clic') ##ccod=compile(ponx.UI[cible].method[clic],'iponx:clic.'+cible,'exec') #ponx.msginfo(cible,ponx.UI[cible].method[clic]) ccod=compile(ponx.UI[cible].method[clic],'iponxclic','exec') #msginfo(cible,inspect.iscode(ccod)) exec(ccod,globals(),globals()) #msginfo(cible,ponx.UI[cible].method[clic]) #uniw32dia(ponx.chaineretour,'chaineretour') #uniw32dia('XXX'+str(ponx.GlobalPARAM[0]), str(ponx.GlobalPARAM[1])) except: #msginfo("pb avec iponx:clic.'+cible,ccod) #msginfo("Type_erreur: ",str(sys.exc_info()[0])) #msginfo("Valeur erronnée: ",str(sys.exc_info()[1])) tb=sys.exc_info()[2] #traceback ponx.msginfo(str(sys.exc_info()[0]),traceback.format_exc()) def postfixedclic(cible): #uniw32dia('cible: '+str(cible), titre='Postfixed Clic') pass def PUIFclic(): global clic ponx.chaineretour="" bouton=ponx.GlobalPARAM[0] mousex=ponx.GlobalPARAM[1] mousey=ponx.GlobalPARAM[2] cible=ponx.GlobalPARAM[3] dkey=ponx.GlobalPARAM[4] sbouton="" if bouton==1: sbouton="clic gauche" if bouton==2: sbouton="clic droit" if dkey!='': #dkey = Shift Ctrl Alt #msginfo("cible",cible) ponx.chaineretour="" if dkey=='Ctrl' and sbouton=="clic droit": GlobalBuffer['UIcible']=cible ponx.chaineretour="""var w = window.open('UICHOIX.htm', '', '"menubar=no, titlebar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, copyhistory=no, width=460, height=420, top=300, left=10'); """ return prefixedclic(cible) #uniw32dia(cible,'cible') flag=False if cible!='': if ponx.UI.has_key(cible): #uniw32dia(str(ponx.UI[cible].method),cible) if ponx.UI[cible].method.has_key(clic): flag=True #uniw32dia(str(flag),'Flag') if flag==True: uiobjectclic(cible) #uniw32dia(ponx.chaineretour,'chaineretourA') else: postfixedclic(cible) #uniw32dia(sbouton+'\r\nmousex '+str(mousex)+'\r\nmousey '+str(mousey)+'\r\n cible: '+str(cible), titre='Clic form') def prefixedfocus(cible): #uniw32dia('cible: '+str(cible), titre='Prefixed Focus') pass def uiobjectfocus(cible): global focus #uniw32dia('cible: '+str(cible)+' '+str(ponx.UI.has_key(cible)), titre='UIobject focus') if ponx.UI.has_key(cible): #uniw32dia(ponx.UI[cible].method[focus],'method.focus') exec(ponx.UI[cible].method[focus],globals(),globals()) #uniw32dia(ponx.chaineretour,'chaineretour') #uniw32dia('XXX'+str(ponx.GlobalPARAM[0]), str(ponx.GlobalPARAM[1])) def postfixedfocus(cible): #uniw32dia('cible: '+str(cible), titre='Postfixed Focus') pass def PUIFfocus(): global focus ponx.chaineretour="" cible=ponx.GlobalPARAM[0] #uniw32dia(cible,'cible') prefixedfocus(cible) flag=False if cible!='': if ponx.UI.has_key(cible): #uniw32dia(str(ponx.UI[cible].method),cible) if ponx.UI[cible].method.has_key(focus): flag=True #uniw32dia(str(flag),'Flag') if flag==True: uiobjectfocus(cible) #uniw32dia(ponx.chaineretour,'chaineretourA') else: postfixedfocus(cible) def prefixedblur(cible): #msginfo('Prefixed Focus',cible) pass def uiobjectblur(cible): global blur #msginfo('UIobject blur',str(cible)+' '+str(ponx.UI.has_key(cible))) if ponx.UI.has_key(cible): #uniw32dia(ponx.UI[cible].method[depart],'method.depart') exec(ponx.UI[cible].method[depart],globals(),globals()) #uniw32dia(ponx.chaineretour,'chaineretour') #uniw32dia('XXX'+str(ponx.GlobalPARAM[0]), str(ponx.GlobalPARAM[1])) def postfixedblur(cible): #msginfo('Posted Focus',cible) pass def PUIFblur(): cible=ponx.GlobalPARAM[0] #msginfo('blur cible', cible) ponx.chaineretour="" prefixedblur(cible) flag=False if cible!='': if ponx.UI.has_key(cible): #msginfo(cible,str(ponx.UI[cible].method)) if ponx.UI[cible].method.has_key(focus): flag=True #msginfo('Flag blur',str(flag)) if flag==True: uiobjectblur(cible) #uniw32dia(ponx.chaineretour,'chaineretourA') else: postfixedblur(cible) def UIhtexec(frm,chaine): #msginfo(frm,chaine) ponx.DFORM[frm].htexec(chaine) def UIalert(frm,chaine): UIhtexec(frm,'alert("'+chaine+'");') def UImoveto(frm,nomchamp): UIhtexec(frm,'moveto("'+nomchamp+'")') def UImodif(nom,callback=None,*args): if callback!=None: callback(ponx.UI[nom],*args) st=ponx.UI[nom].generate(mod='restreint') #msginfo(nom,st) return('majUI("'+nom+'","'+st+'");\r\n') def UImodifht(nom,callback=None,*args): """Permet de modifier le Html 'descriptif' d'un UIobject, à la volée (innerHTML) @param nom: nom de l'UIobject @param callback: [facultatif] fonction à appliquer à l'uiobject. Il s'agit le plus souvent d'une fonction de la class uiobject (par exemple 'uiobject.setposition') @param *args: [facultatif] paramètres pour la fonction callback """ if callback!=None: callback(ponx.UI[nom],*args) st=ponx.UI[nom].generate(mod='restreint') #msginfo(nom,st) ponx.DFORM[ponx.UI[nom].form].htexec('majUI("'+nom+'","'+st+'");') time.sleep(0.2) def UIcreeht(nom,callback=None,*args): """Permet de modifier le Html 'descriptif' d'un UIobject, à la volée (innerHTML) @param nom: nom de l'UIobject @param callback: [facultatif] fonction à appliquer à l'uiobject. Il s'agit le plus souvent d'une fonction de la class uiobject (par exemple 'uiobject.setposition') @param *args: [facultatif] paramètres pour la fonction callback """ if callback!=None: callback(ponx.UI[nom],*args) st=ponx.UI[nom].generate(mod='restreint') #msginfo(nom,st) ponx.DFORM[ponx.UI[nom].form].htexec('creeUI("'+nom+'","'+st+'");') time.sleep(0.2) def UImodifApply(form,st): if GlobalGroupageHT==False: ponx.DFORM[form].htexec(st) else: GlobalGroupHTML[form]=GlobalGroupHTML[form]+'\n'+st def GlobalGroupagesStart(form): global GlobalGroupageHT GlobalGroupageHT=True GlobalGroupHTML[form]='' def GlobalGroupagesEnd(form): global GlobalGroupageHT #ponx.msginfo("DFORM",repr(ponx.DFORM)) st=GlobalGroupHTML[form] GlobalGroupHTML[form]='' GlobalGroupageHT=False #ponx.msginfo("st",repr(st)) if st!='': ponx.DFORM[form].htexec(st) def UImessage(frm, txt="Message",num=1, mode="show"): if mode=="show": st="popmsg("+str(num)+",\""+txt+"\"); " else: st="popvisuanim("+str(num)+",GecranX/2-100,12); " if txt=="": st="popcache("+str(num)+"); " #msginfo(st) ponx.DFORM[frm].htexec(st) def UIopenW(frm=''): if frm!='': ponx.chaineretour="""var w = window.open('"""+frm+""".htm', '', '"toolbar=no, location=no, directories=no, status=no, scrollbars=no');""" def PUIFkey(): """ évènement touche du clavier """ global GlobalU tch=ponx.GlobalPARAM[0] dkey=ponx.GlobalPARAM[1] cible=ponx.GlobalPARAM[2] ponx.chaineretour="" if tch==119: #F8 if dkey=='Shift': f=open('proc.F','r') GlobalU=f.read() f.close() st="""var w = window.open('source.htm', '', '"toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=350, top=400, left=200');""" ponx.chaineretour=st #UIwrite("SOURCEMEM1",UIcrlf(GlobalU.decode('cp1252','replace'))) else: #ponx.chaineretour="""var w = window.open('mur1.htm', '', '"toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=350, top=300, left=700');""" ponx.chaineretour="""var w = window.open('UICHOIX.htm', '', '"menubar=no, titlebar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, copyhistory=no, width=460, height=420, top=300, left=10'); """ if tch==120: #F9 - pour test chai=UImodif('CH01',uiobject.setposition,145,25) chai=chai+UImodif('TC05',uiobject.setlabeltext,'555555555') ponx.UI['CH02'].setposition(150,50) chai=chai+UImodif('CH02') UImodifApply('F01',chai) if tch==121: #F10 - pour test ponx.chaineretour="tototo()" #@@@ #msginfo('Clavier form', str(tch)+'\r\n'+dkey+'\r\n'+cible) def PUICkey(): tch=ponx.GlobalPARAM[0] dkey=ponx.GlobalPARAM[1] cible=ponx.GlobalPARAM[2] #uniw32dia(str(tch)+'\r\n'+dkey+'\r\n'+cible, titre='Clavier champ') ponx.chaineretour="" def PUIrecept(): msginfo('UIrecept','Champ : '+ponx.GlobalPARAM[0]+'\r\nAction: '+ponx.GlobalPARAM[1]+'\r\nValeur: '+str(type(ponx.GlobalPARAM[2]))) pass def UIformClose(frm=''): """Ferme une fenêtre """ UImodifApply(frm,'self.close()') def UIlistread(nom): st=UIread(nom) ls=string.split(st,'[],\t') msginfo("ls",str(ls)) return(ls) def UIreadu(nom): #retourne une chaine unicode if ponx.UI[nom].typ=='ListDeroul': st=ponx.UI[nom].UIlien.innerHTML i=string.find(st,'selected>')+9 j=string.find(st,'-1 and k>-1: j=min(j,k) if j<0 and k>-1: j=k val=string.upper(st[i:j]) return(val) else: return ponx.UI[nom].UIlien.value def UIread(nom): """Lecture du contenu d'un UIobject (normalement un champ) @param:nom: nom de l'UIobject """ #msginfo("nom.Value",str(ponx.UI[nom].UIlien.outerHTML)) if ponx.UI[nom].typ=='ListDeroul': st=ponx.UI[nom].UIlien.innerHTML i=string.find(st,'selected>')+9 j=string.find(st,'-1 and k>-1: j=min(j,k) if j<0 and k>-1: j=k val=string.upper(st[i:j]) return(val) else: sui=ponx.UI[nom].UIlien.value.encode('cp1252','replace') if ponx.UI[nom].soutyp=='number': ret=decodenumber(sui) elif ponx.UI[nom].soutyp=='date': ret=decodedate(sui).strftime("%d.%m.%Y") else: ret=sui if sui!=ret: ponx.UI[nom].UIlien.value=unicode(ret) return(ret) def UIreadpropertie(nom,prop): """Lecture d'une propriété Html d'un UIobject @param nom: nom de l'UIobject @param prop: nom de la propriété Html """ try: st="UI['"+nom+"'].UIlien."+prop+".encode('cp1252','replace')" ret=eval(st,globals(),globals()) return(ret) except: msginfo("Impossible de lire la propriété ",str(prop)) def UIwrite(nom,valeur): """écrit une valeur dans un UIobject (normalement un champ) Ne gère pas les ListeDeroul @param nom: nom de l'UIobject @valeur valeur à affecter """ try: ust=unicode(valeur) except: ust=str(valeur) try: ponx.UI[nom].UIlien.value=ust except: msginfo("Impossible d'écrire",str(valeur)) def UItabwrite(nom,col,valeur): """écrit une valeur dans un UIobject tableau @param nom: nom de l'UIobject @param col: numero de la colonne @valeur valeur à affecter """ nomcomplet ponx.UI[nom].UIlien.value=unicode(valeur) def UIwritepropertie(nom,prop,valeur): """écrit une valeur dans une propriété d'un UIobject (plutôt pour un activeX) @param nom: nom de l'UIobject @param prop: nom de la propriété (exemple: ) @valeur valeur à affecter """ #st="UI['"+nom+"'].UIlien."+prop+"=unicode('''"+valeur+" ''')" try: ust=u1252(valeur) except: ust=str(valeur) try: st="UI['"+nom+"'].UIlien."+prop+"='''"+ust+" '''" #msginfo("st",st) exec(st,globals(),globals()) except: msginfo("Impossible d'écrire lire la propriété "+str(prop),valeur) def UIchgListDeroul(nom, ls, selected): """Change la liste des choix possibles d'une liste déroulante @param:nom: nom de lUIobject @param:ls: liste des choix (liste de liste, chaque 'sous'-liste commençant par le titre du groupe) Attention: vérifier que la fiche ne soit pas en attente (de 'chaineretour') """ #msginfo(selected,str(ls)) ponx.UI[nom].setlistevaleurs(ls, selected) chai=UImodif(nom) #msginfo(ponx.UI[nom].form,chai) UImodifApply(ponx.UI[nom].form,chai) if GlobalGroupageHT==False: time.sleep(0.1) def readUI(chaine): a=string.split(chaine[:-1],'\t') #msginfo("a",a) for i in range(0,len(a),2): ponx.UI[a[i]].value=a[i+1] #msginfo(ponx.UI[a[i]].name,ponx.UI[a[i]].value) def readUIpre(*champs): chaine='readUI("' for ch in champs: chaine=chaine+ch+'\t' chaine=chaine[:-1]+'")' ponx.chaineretour=chaine def writeUI(*arg): chaine='writeUI("' for i in range(0,len(arg),2): chaine=chaine+arg[i]+'\t'+str(arg[i+1])+'\t' chaine=chaine[:-1]+'")' #msginfo("chaine",chaine) ponx.chaineretour=chaine def writeUIsuite(): #msginfo("write","suite") pass def test(): return 12345