3 """GUI interface to webchecker.
5 This works as a Grail applet too! E.g.
7 <APPLET CODE=wcgui.py NAME=CheckerWindow></APPLET>
9 Checkpoints are not (yet??? ever???) supported.
13 Enter a root to check in the text entry box. To enter more than one root,
14 enter them one at a time and press <Return> for each one.
16 Command buttons Start, Stop and "Check one" govern the checking process in
17 the obvious way. Start and "Check one" also enter the root from the text
18 entry box if one is present. There's also a check box (enabled by default)
19 to decide whether actually to follow external links (since this can slow
20 the checking down considerably). Finally there's a Quit button.
22 A series of checkbuttons determines whether the corresponding output panel
23 is shown. List panels are also automatically shown or hidden when their
24 status changes between empty to non-empty. There are six panels:
26 Log -- raw output from the checker (-v, -q affect this)
27 To check -- links discovered but not yet checked
28 Checked -- links that have been checked
29 Bad links -- links that failed upon checking
30 Errors -- pages containing at least one bad link
31 Details -- details about one URL; double click on a URL in any of
32 the above list panels (not in Log) will show details
35 Use your window manager's Close command to quit.
39 -m bytes -- skip HTML pages larger than this size (default %(MAXPAGE)d)
40 -q -- quiet operation (also suppresses external links report)
41 -v -- verbose operation; repeating -v will increase verbosity
43 Command line arguments:
45 rooturl -- URL to start checking
48 XXX The command line options (-m, -q, -v) should be GUI accessible.
50 XXX The roots should be visible as a list (?).
52 XXX The multipanel user interface is clumsy.
67 # Override some for a weaker platform
68 if sys
.platform
== 'mac':
69 webchecker
.DEFROOT
= "http://grail.cnri.reston.va.us/"
70 webchecker
.MAXPAGE
= 50000
71 webchecker
.verbose
= 4
75 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'm:qv')
76 except getopt
.error
, msg
:
77 sys
.stdout
= sys
.stderr
79 print __doc__
%vars(webchecker
)
83 webchecker
.maxpage
= string
.atoi(a
)
85 webchecker
.verbose
= 0
87 webchecker
.verbose
= webchecker
.verbose
+ 1
88 root
= Tk(className
='Webchecker')
89 root
.protocol("WM_DELETE_WINDOW", root
.quit
)
90 c
= CheckerWindow(root
)
94 c
.suggestroot(args
[-1])
98 class CheckerWindow(webchecker
.Checker
):
100 def __init__(self
, parent
, root
=webchecker
.DEFROOT
):
101 self
.__parent
= parent
103 self
.__topcontrols
= Frame(parent
)
104 self
.__topcontrols
.pack(side
=TOP
, fill
=X
)
105 self
.__label
= Label(self
.__topcontrols
, text
="Root URL:")
106 self
.__label
.pack(side
=LEFT
)
107 self
.__rootentry
= Entry(self
.__topcontrols
, width
=60)
108 self
.__rootentry
.pack(side
=LEFT
)
109 self
.__rootentry
.bind('<Return>', self
.enterroot
)
110 self
.__rootentry
.focus_set()
112 self
.__controls
= Frame(parent
)
113 self
.__controls
.pack(side
=TOP
, fill
=X
)
115 self
.__start
= Button(self
.__controls
, text
="Run", command
=self
.start
)
116 self
.__start
.pack(side
=LEFT
)
117 self
.__stop
= Button(self
.__controls
, text
="Stop", command
=self
.stop
,
119 self
.__stop
.pack(side
=LEFT
)
120 self
.__step
= Button(self
.__controls
, text
="Check one",
122 self
.__step
.pack(side
=LEFT
)
123 self
.__cv
= BooleanVar(parent
)
124 self
.__cv
.set(self
.checkext
)
125 self
.__checkext
= Checkbutton(self
.__controls
, variable
=self
.__cv
,
126 command
=self
.update_checkext
,
127 text
="Check nonlocal links",)
128 self
.__checkext
.pack(side
=LEFT
)
129 self
.__reset
= Button(self
.__controls
, text
="Start over", command
=self
.reset
)
130 self
.__reset
.pack(side
=LEFT
)
131 if __name__
== '__main__': # No Quit button under Grail!
132 self
.__quit
= Button(self
.__controls
, text
="Quit",
133 command
=self
.__parent
.quit
)
134 self
.__quit
.pack(side
=RIGHT
)
136 self
.__status
= Label(parent
, text
="Status: initial", anchor
=W
)
137 self
.__status
.pack(side
=TOP
, fill
=X
)
138 self
.__checking
= Label(parent
, text
="Idle", anchor
=W
)
139 self
.__checking
.pack(side
=TOP
, fill
=X
)
140 self
.__mp
= mp
= MultiPanel(parent
)
141 sys
.stdout
= self
.__log
= LogPanel(mp
, "Log")
142 self
.__todo
= ListPanel(mp
, "To check", self
.showinfo
)
143 self
.__done
= ListPanel(mp
, "Checked", self
.showinfo
)
144 self
.__bad
= ListPanel(mp
, "Bad links", self
.showinfo
)
145 self
.__errors
= ListPanel(mp
, "Pages w/ bad links", self
.showinfo
)
146 self
.__details
= LogPanel(mp
, "Details")
147 webchecker
.Checker
.__init
__(self
)
149 root
= string
.strip(str(root
))
151 self
.suggestroot(root
)
155 webchecker
.Checker
.reset(self
)
156 for p
in self
.__todo
, self
.__done
, self
.__bad
, self
.__errors
:
159 def suggestroot(self
, root
):
160 self
.__rootentry
.delete(0, END
)
161 self
.__rootentry
.insert(END
, root
)
162 self
.__rootentry
.select_range(0, END
)
164 def enterroot(self
, event
=None):
165 root
= self
.__rootentry
.get()
166 root
= string
.strip(root
)
168 self
.__checking
.config(text
="Adding root "+root
)
169 self
.__checking
.update_idletasks()
171 self
.__checking
.config(text
="Idle")
173 i
= self
.__todo
.items
.index(root
)
174 except (ValueError, IndexError):
177 self
.__todo
.list.select_clear(0, END
)
178 self
.__todo
.list.select_set(i
)
179 self
.__todo
.list.yview(i
)
180 self
.__rootentry
.delete(0, END
)
183 self
.__start
.config(state
=DISABLED
, relief
=SUNKEN
)
184 self
.__stop
.config(state
=NORMAL
)
185 self
.__step
.config(state
=DISABLED
)
191 self
.__stop
.config(state
=DISABLED
, relief
=SUNKEN
)
195 self
.__start
.config(state
=DISABLED
)
196 self
.__step
.config(state
=DISABLED
, relief
=SUNKEN
)
203 self
.__parent
.after_idle(self
.dosomething
)
205 self
.__checking
.config(text
="Idle")
206 self
.__start
.config(state
=NORMAL
, relief
=RAISED
)
207 self
.__stop
.config(state
=DISABLED
, relief
=RAISED
)
208 self
.__step
.config(state
=NORMAL
, relief
=RAISED
)
212 def dosomething(self
):
213 if self
.__busy
: return
216 l
= self
.__todo
.selectedindices()
221 self
.__todo
.list.select_set(i
)
222 self
.__todo
.list.yview(i
)
223 url
= self
.__todo
.items
[i
]
224 self
.__checking
.config(text
="Checking "+url
)
225 self
.__parent
.update()
232 def showinfo(self
, url
):
235 d
.put("URL: %s\n" % url
)
236 if self
.bad
.has_key(url
):
237 d
.put("Error: %s\n" % str(self
.bad
[url
]))
238 if url
in self
.roots
:
239 d
.put("Note: This is a root URL\n")
240 if self
.done
.has_key(url
):
241 d
.put("Status: checked\n")
243 elif self
.todo
.has_key(url
):
244 d
.put("Status: to check\n")
247 d
.put("Status: unknown (!)\n")
249 if self
.errors
.has_key(url
):
250 d
.put("Bad links from this page:\n")
251 for triple
in self
.errors
[url
]:
252 link
, rawlink
, msg
= triple
253 d
.put(" HREF %s" % link
)
254 if link
!= rawlink
: d
.put(" (%s)" %rawlink
)
256 d
.put(" error %s\n" % str(msg
))
257 self
.__mp
.showpanel("Details")
258 for source
, rawlink
in o
:
259 d
.put("Origin: %s" % source
)
261 d
.put(" (%s)" % rawlink
)
265 def setbad(self
, url
, msg
):
266 webchecker
.Checker
.setbad(self
, url
, msg
)
267 self
.__bad
.insert(url
)
270 def setgood(self
, url
):
271 webchecker
.Checker
.setgood(self
, url
)
272 self
.__bad
.remove(url
)
275 def newlink(self
, url
, origin
):
276 webchecker
.Checker
.newlink(self
, url
, origin
)
277 if self
.done
.has_key(url
):
278 self
.__done
.insert(url
)
279 elif self
.todo
.has_key(url
):
280 self
.__todo
.insert(url
)
283 def markdone(self
, url
):
284 webchecker
.Checker
.markdone(self
, url
)
285 self
.__done
.insert(url
)
286 self
.__todo
.remove(url
)
289 def seterror(self
, url
, triple
):
290 webchecker
.Checker
.seterror(self
, url
, triple
)
291 self
.__errors
.insert(url
)
295 self
.__status
.config(text
="Status: "+self
.status())
296 self
.__parent
.update()
298 def update_checkext(self
):
299 self
.checkext
= self
.__cv
.get()
304 def __init__(self
, mp
, name
, showinfo
=None):
307 self
.showinfo
= showinfo
308 self
.panel
= mp
.addpanel(name
)
309 self
.list, self
.frame
= tktools
.make_list_box(
310 self
.panel
, width
=60, height
=5)
311 self
.list.config(exportselection
=0)
313 self
.list.bind('<Double-Button-1>', self
.doubleclick
)
318 self
.list.delete(0, END
)
319 self
.mp
.hidepanel(self
.name
)
321 def doubleclick(self
, event
):
322 l
= self
.selectedindices()
324 self
.showinfo(self
.list.get(l
[0]))
326 def selectedindices(self
):
327 l
= self
.list.curselection()
329 return map(string
.atoi
, l
)
331 def insert(self
, url
):
332 if url
not in self
.items
:
334 self
.mp
.showpanel(self
.name
)
335 # (I tried sorting alphabetically, but the display is too jumpy)
337 self
.list.insert(i
, url
)
339 self
.items
.insert(i
, url
)
341 def remove(self
, url
):
343 i
= self
.items
.index(url
)
344 except (ValueError, IndexError):
347 was_selected
= i
in self
.selectedindices()
351 self
.mp
.hidepanel(self
.name
)
353 if i
>= len(self
.items
):
354 i
= len(self
.items
) - 1
355 self
.list.select_set(i
)
360 def __init__(self
, mp
, name
):
363 self
.panel
= mp
.addpanel(name
)
364 self
.text
, self
.frame
= tktools
.make_text_box(self
.panel
, height
=10)
365 self
.text
.config(wrap
=NONE
)
368 self
.text
.delete("1.0", END
)
369 self
.text
.yview("1.0")
372 self
.text
.insert(END
, s
)
377 self
.text
.insert(END
, s
)
385 def __init__(self
, parent
):
387 self
.frame
= Frame(self
.parent
)
388 self
.frame
.pack(expand
=1, fill
=BOTH
)
389 self
.topframe
= Frame(self
.frame
, borderwidth
=2, relief
=RAISED
)
390 self
.topframe
.pack(fill
=X
)
391 self
.botframe
= Frame(self
.frame
)
392 self
.botframe
.pack(expand
=1, fill
=BOTH
)
396 def addpanel(self
, name
, on
=0):
397 v
= StringVar(self
.parent
)
402 check
= Checkbutton(self
.topframe
, text
=name
,
403 offvalue
="", onvalue
=name
, variable
=v
,
404 command
=self
.checkpanel
)
405 check
.pack(side
=LEFT
)
406 panel
= Frame(self
.botframe
)
407 label
= Label(panel
, text
=name
, borderwidth
=2, relief
=RAISED
, anchor
=W
)
408 label
.pack(side
=TOP
, fill
=X
)
410 self
.panelnames
.append(name
)
411 self
.panels
[name
] = t
413 panel
.pack(expand
=1, fill
=BOTH
)
416 def showpanel(self
, name
):
417 v
, check
, panel
= self
.panels
[name
]
419 panel
.pack(expand
=1, fill
=BOTH
)
421 def hidepanel(self
, name
):
422 v
, check
, panel
= self
.panels
[name
]
426 def checkpanel(self
):
427 for name
in self
.panelnames
:
428 v
, check
, panel
= self
.panels
[name
]
430 for name
in self
.panelnames
:
431 v
, check
, panel
= self
.panels
[name
]
433 panel
.pack(expand
=1, fill
=BOTH
)
436 if __name__
== '__main__':