/usr/share/pyshared/AIDE/viewer.py is in eficas 2.0.3-1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | # -*- coding: utf-8 -*-
import os
import Tkinter
import ScrolledText
import formatter
import htmllib
try :
from aideQT import Aide
from qt import *
except :
class Aide:
pass
class TkWriter(formatter.DumbWriter):
def __init__(self, text,viewer):
formatter.DumbWriter.__init__(self, self)
self.text=text
self.viewer=viewer
def write(self,data):
self.text.insert("insert", data)
def anchor_bgn(self, href, name, type):
if href:
self.anchor = (href, name, type)
self.anchor_mark = self.text.index("insert")
def anchor_end(self):
if self.anchor:
url = self.anchor[0]
tag = "href_" + url
self.text.tag_add(tag, self.anchor_mark, "insert")
def displayurl(event,v=self.viewer,u=url):
v.display(u)
self.text.tag_bind(tag, "<ButtonPress>", displayurl)
self.text.tag_config(tag, foreground="blue", underline=1)
self.anchor = None
class HTMLParser(htmllib.HTMLParser):
def anchor_bgn(self, href, name, type):
htmllib.HTMLParser.anchor_bgn(self, href, name, type)
# On signale directement au writer le debut d'une reference
self.formatter.writer.anchor_bgn(href, name, type)
def anchor_end(self):
if self.anchor:
self.formatter.writer.anchor_end()
self.anchor = None
import string
class DumbParser:
def __init__(self,fmt):
self.formatter=fmt
def feed(self,data):
self.formatter.writer.write(data)
def close(self):
pass
class Historique:
def __init__(self):
self.liste=[]
self.index=0
def add(self,url):
if self.index > 0:
old=self.liste[self.index-1]
if url == old :return
del self.liste[self.index:]
self.liste.append(url)
self.index=self.index+1
def getback(self):
if self.index > 1:
self.index=self.index-1
return self.liste[self.index-1]
else:
return None
def getforward(self):
if self.index < len(self.liste):
url=self.liste[self.index]
self.index=self.index+1
return url
else:
return None
class HTMLViewer:
def __init__(self,parent):
self.init_window(parent)
self.url=None
self.home=None
self.historique=Historique()
self.createWidgets()
self.init()
def init_window(self,parent):
self.parent=parent
self.fenetre=Tkinter.Toplevel()
self.fenetre.title("AIDE EFICAS")
if self.fenetre.winfo_screenwidth() < 800 or self.fenetre.winfo_screenheight() < 600:
self.fenetre.wm_minsize(300, 150)
else:
self.fenetre.wm_minsize(400, 200)
self.fenetre.protocol("WM_DELETE_WINDOW",self.destroy)
def createWidgets(self):
frame = self.frame = Tkinter.Frame(self.fenetre)
frame.pack(side="bottom", fill="x")
self.homeButton = Tkinter.Button(frame, text="Index",font="Helvetica 12 bold",
command=self.goHome)
self.homeButton.pack(side="left")
self.b_retour = Tkinter.Button(frame, text="Back",font="Helvetica 12 bold",
command=self.goBack)
self.b_retour.pack(side="left")
self.b_avance = Tkinter.Button(frame, text="Forward",font="Helvetica 12 bold",
command=self.goForward)
self.b_avance.pack(side="left")
self.b_close = Tkinter.Button(frame, text="Close",font="Helvetica 12 bold",
command=self.destroy)
self.b_close.pack(side="right")
self.config_boutons()
self.text=ScrolledText.ScrolledText(self.fenetre,bg='white',relief='sunken',font="Helvetica 12 bold")
self.text.pack(side="top", fill="both", expand=1)
self.text.bind("<Key-Prior>", self.page_up)
self.text.bind("<Key-Next>", self.page_down)
self.text.bind("<Key-Up>", self.unit_up)
self.text.bind("<Key-Down>", self.unit_down)
self.text.bind("<1>", self.clicked)
def clicked(self,event):
self.text.focus_set()
def page_up(self,event):
event.widget.yview_scroll(-1, "page")
def page_down(self,event):
event.widget.yview_scroll(1, "page")
def unit_up(self,event):
event.widget.yview_scroll(-1, "unit")
def unit_down(self,event):
event.widget.yview_scroll(1, "unit")
def config_boutons(self):
"""
Activation du bouton précédent s'il y a lieu
"""
if self.historique.index > 1 :
self.b_retour.config(state='normal')
else :
self.b_retour.config(state='disabled')
if self.historique.index < len(self.historique.liste) :
self.b_avance.config(state='normal')
else :
self.b_avance.config(state='disabled')
def openurl(self,url):
url=os.path.normpath(url)
if self.url and not os.path.isabs(url):
rep1,fich1=os.path.split(self.url)
rep2,fich2=os.path.split(url)
if rep1 != rep2 :
url=os.path.join(rep1,rep2,fich2)
url=os.path.normpath(url)
try:
f=open(url,'r')
data=f.read()
f.close()
except:
data="Impossible de trouver: "+url
self.url=url
if self.home is None:
self.home=self.url
return data
def display(self,url):
data=self.openurl(url)
ext=os.path.splitext(url)[1]
self.text.config(state="normal")
self.text.delete("1.0", "end")
writer=TkWriter(self.text,self)
fmt=formatter.AbstractFormatter(writer)
if ext == ".html":
parser=HTMLParser(fmt)
else:
#parser=DumbParser(fmt)
parser=HTMLParser(fmt)
parser.feed(data)
parser.close()
self.text.config(state="disabled")
self.historique.add(url)
self.config_boutons()
def init(self):
self.fenetre.bind("<KeyPress-BackSpace>", self.goBack)
def goHome(self,event=None):
if self.home and self.home != self.url:
self.display(self.home)
def goBack(self,event=None):
url=self.historique.getback()
if url:self.display(url)
def goForward(self,event=None):
url=self.historique.getforward()
if url:self.display(url)
def destroy(self):
try:
self.fenetre.destroy()
except:
pass
class HTMLQTViewer(Aide):
def __init__(self,parent,pathDoc):
Aide.__init__(self,parent=parent,fl=Qt.WType_Dialog)
self.pathDoc=pathDoc
self.parent=parent
self.url=None
self.home=None
self.historique=Historique()
self.TB1init()
self.TB1.setSource("index.html")
self.show()
def TB1init(self):
self.TB1.mimeSourceFactory().addFilePath(QString(self.pathDoc));
def PBIndexPushed(self):
self.TB1.setSource("index.html")
if __name__ == "__main__":
v=HTMLViewer(None)
v.display("fichiers/index.html")
v.fenetre.mainloop()
|