Mercurial > cpython-lru_cache-weakref
annotate Tools/webchecker/wcgui.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | f6785bce54b5 |
| children |
| rev | line source |
|---|---|
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 """GUI interface to webchecker. |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 This works as a Grail applet too! E.g. |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
7 <APPLET CODE=wcgui.py NAME=CheckerWindow></APPLET> |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
9 Checkpoints are not (yet??? ever???) supported. |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 User interface: |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
25219
diff
changeset
|
13 Enter a root to check in the text entry box. To enter more than one root, |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
14 enter them one at a time and press <Return> for each one. |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
15 |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
25219
diff
changeset
|
16 Command buttons Start, Stop and "Check one" govern the checking process in |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
25219
diff
changeset
|
17 the obvious way. Start and "Check one" also enter the root from the text |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
18 entry box if one is present. There's also a check box (enabled by default) |
|
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
19 to decide whether actually to follow external links (since this can slow |
|
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
20 the checking down considerably). Finally there's a Quit button. |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
21 |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
25219
diff
changeset
|
22 A series of checkbuttons determines whether the corresponding output panel |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
25219
diff
changeset
|
23 is shown. List panels are also automatically shown or hidden when their |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
24 status changes between empty to non-empty. There are six panels: |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 Log -- raw output from the checker (-v, -q affect this) |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
27 To check -- links discovered but not yet checked |
|
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
28 Checked -- links that have been checked |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 Bad links -- links that failed upon checking |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
30 Errors -- pages containing at least one bad link |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 Details -- details about one URL; double click on a URL in any of |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
32 the above list panels (not in Log) will show details |
|
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
33 for that URL |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
34 |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 Use your window manager's Close command to quit. |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 Command line options: |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 -m bytes -- skip HTML pages larger than this size (default %(MAXPAGE)d) |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 -q -- quiet operation (also suppresses external links report) |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 -v -- verbose operation; repeating -v will increase verbosity |
| 11478 | 42 -t root -- specify root dir which should be treated as internal (can repeat) |
| 43 -a -- don't check name anchors | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 Command line arguments: |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 rooturl -- URL to start checking |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 (default %(DEFROOT)s) |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
50 XXX The command line options (-m, -q, -v) should be GUI accessible. |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
52 XXX The roots should be visible as a list (?). |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
54 XXX The multipanel user interface is clumsy. |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 """ |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 # ' Emacs bait |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 import sys |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 import getopt |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 from Tkinter import * |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 import tktools |
|
11482
0680e67a0d49
Changed fron importing wcnew back to webchecker.
Guido van Rossum <guido@python.org>
parents:
11478
diff
changeset
|
65 import webchecker |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 def main(): |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 try: |
| 11478 | 69 opts, args = getopt.getopt(sys.argv[1:], 't:m:qva') |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 except getopt.error, msg: |
| 7887 | 71 sys.stdout = sys.stderr |
| 72 print msg | |
| 73 print __doc__%vars(webchecker) | |
| 74 sys.exit(2) | |
| 11478 | 75 webchecker.verbose = webchecker.VERBOSE |
| 76 webchecker.nonames = webchecker.NONAMES | |
| 77 webchecker.maxpage = webchecker.MAXPAGE | |
| 78 extra_roots = [] | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 for o, a in opts: |
| 7887 | 80 if o == '-m': |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
11482
diff
changeset
|
81 webchecker.maxpage = int(a) |
| 7887 | 82 if o == '-q': |
| 83 webchecker.verbose = 0 | |
| 84 if o == '-v': | |
| 85 webchecker.verbose = webchecker.verbose + 1 | |
| 11478 | 86 if o == '-t': |
| 87 extra_roots.append(a) | |
| 88 if o == '-a': | |
| 89 webchecker.nonames = not webchecker.nonames | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 root = Tk(className='Webchecker') |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 root.protocol("WM_DELETE_WINDOW", root.quit) |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
92 c = CheckerWindow(root) |
| 11478 | 93 c.setflags(verbose=webchecker.verbose, maxpage=webchecker.maxpage, |
| 94 nonames=webchecker.nonames) | |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
95 if args: |
| 7887 | 96 for arg in args[:-1]: |
| 97 c.addroot(arg) | |
| 98 c.suggestroot(args[-1]) | |
| 11478 | 99 # Usually conditioned on whether external links |
| 100 # will be checked, but since that's not a command | |
| 101 # line option, just toss them in. | |
| 102 for url_root in extra_roots: | |
| 103 # Make sure it's terminated by a slash, | |
| 104 # so that addroot doesn't discard the last | |
| 105 # directory component. | |
| 106 if url_root[-1] != "/": | |
| 107 url_root = url_root + "/" | |
| 108 c.addroot(url_root, add_to_do = 0) | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 root.mainloop() |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 class CheckerWindow(webchecker.Checker): |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
114 def __init__(self, parent, root=webchecker.DEFROOT): |
| 7887 | 115 self.__parent = parent |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
116 |
| 7887 | 117 self.__topcontrols = Frame(parent) |
| 118 self.__topcontrols.pack(side=TOP, fill=X) | |
| 119 self.__label = Label(self.__topcontrols, text="Root URL:") | |
| 120 self.__label.pack(side=LEFT) | |
| 121 self.__rootentry = Entry(self.__topcontrols, width=60) | |
| 122 self.__rootentry.pack(side=LEFT) | |
| 123 self.__rootentry.bind('<Return>', self.enterroot) | |
| 124 self.__rootentry.focus_set() | |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
125 |
| 7887 | 126 self.__controls = Frame(parent) |
| 127 self.__controls.pack(side=TOP, fill=X) | |
| 128 self.__running = 0 | |
| 129 self.__start = Button(self.__controls, text="Run", command=self.start) | |
| 130 self.__start.pack(side=LEFT) | |
| 131 self.__stop = Button(self.__controls, text="Stop", command=self.stop, | |
| 132 state=DISABLED) | |
| 133 self.__stop.pack(side=LEFT) | |
| 134 self.__step = Button(self.__controls, text="Check one", | |
| 135 command=self.step) | |
| 136 self.__step.pack(side=LEFT) | |
| 137 self.__cv = BooleanVar(parent) | |
| 138 self.__cv.set(self.checkext) | |
| 139 self.__checkext = Checkbutton(self.__controls, variable=self.__cv, | |
| 140 command=self.update_checkext, | |
| 141 text="Check nonlocal links",) | |
| 142 self.__checkext.pack(side=LEFT) | |
| 143 self.__reset = Button(self.__controls, text="Start over", command=self.reset) | |
| 144 self.__reset.pack(side=LEFT) | |
| 145 if __name__ == '__main__': # No Quit button under Grail! | |
| 146 self.__quit = Button(self.__controls, text="Quit", | |
| 147 command=self.__parent.quit) | |
| 148 self.__quit.pack(side=RIGHT) | |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
149 |
| 7887 | 150 self.__status = Label(parent, text="Status: initial", anchor=W) |
| 151 self.__status.pack(side=TOP, fill=X) | |
| 152 self.__checking = Label(parent, text="Idle", anchor=W) | |
| 153 self.__checking.pack(side=TOP, fill=X) | |
| 154 self.__mp = mp = MultiPanel(parent) | |
| 155 sys.stdout = self.__log = LogPanel(mp, "Log") | |
| 11478 | 156 self.__todo = ListPanel(mp, "To check", self, self.showinfo) |
| 157 self.__done = ListPanel(mp, "Checked", self, self.showinfo) | |
| 158 self.__bad = ListPanel(mp, "Bad links", self, self.showinfo) | |
| 159 self.__errors = ListPanel(mp, "Pages w/ bad links", self, self.showinfo) | |
| 7887 | 160 self.__details = LogPanel(mp, "Details") |
| 11478 | 161 self.root_seed = None |
| 7887 | 162 webchecker.Checker.__init__(self) |
| 163 if root: | |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
11482
diff
changeset
|
164 root = str(root).strip() |
| 7887 | 165 if root: |
| 166 self.suggestroot(root) | |
| 167 self.newstatus() | |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
168 |
|
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
169 def reset(self): |
| 7887 | 170 webchecker.Checker.reset(self) |
| 171 for p in self.__todo, self.__done, self.__bad, self.__errors: | |
| 172 p.clear() | |
| 11478 | 173 if self.root_seed: |
| 174 self.suggestroot(self.root_seed) | |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
175 |
|
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
176 def suggestroot(self, root): |
| 7887 | 177 self.__rootentry.delete(0, END) |
| 178 self.__rootentry.insert(END, root) | |
| 179 self.__rootentry.select_range(0, END) | |
| 11478 | 180 self.root_seed = root |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
181 |
|
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
182 def enterroot(self, event=None): |
| 7887 | 183 root = self.__rootentry.get() |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
11482
diff
changeset
|
184 root = root.strip() |
| 7887 | 185 if root: |
| 186 self.__checking.config(text="Adding root "+root) | |
| 187 self.__checking.update_idletasks() | |
| 188 self.addroot(root) | |
| 189 self.__checking.config(text="Idle") | |
| 190 try: | |
| 191 i = self.__todo.items.index(root) | |
| 192 except (ValueError, IndexError): | |
| 193 pass | |
| 194 else: | |
| 195 self.__todo.list.select_clear(0, END) | |
| 196 self.__todo.list.select_set(i) | |
| 197 self.__todo.list.yview(i) | |
| 198 self.__rootentry.delete(0, END) | |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
199 |
|
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
200 def start(self): |
| 7887 | 201 self.__start.config(state=DISABLED, relief=SUNKEN) |
| 202 self.__stop.config(state=NORMAL) | |
| 203 self.__step.config(state=DISABLED) | |
| 204 self.enterroot() | |
| 205 self.__running = 1 | |
| 206 self.go() | |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
207 |
|
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
208 def stop(self): |
| 7887 | 209 self.__stop.config(state=DISABLED, relief=SUNKEN) |
| 210 self.__running = 0 | |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
211 |
|
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
212 def step(self): |
| 7887 | 213 self.__start.config(state=DISABLED) |
| 214 self.__step.config(state=DISABLED, relief=SUNKEN) | |
| 215 self.enterroot() | |
| 216 self.__running = 0 | |
| 217 self.dosomething() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 def go(self): |
| 7887 | 220 if self.__running: |
| 221 self.__parent.after_idle(self.dosomething) | |
| 222 else: | |
| 223 self.__checking.config(text="Idle") | |
| 224 self.__start.config(state=NORMAL, relief=RAISED) | |
| 225 self.__stop.config(state=DISABLED, relief=RAISED) | |
| 226 self.__step.config(state=NORMAL, relief=RAISED) | |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
227 |
|
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
228 __busy = 0 |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 def dosomething(self): |
| 7887 | 231 if self.__busy: return |
| 232 self.__busy = 1 | |
| 233 if self.todo: | |
| 234 l = self.__todo.selectedindices() | |
| 235 if l: | |
| 236 i = l[0] | |
| 237 else: | |
| 238 i = 0 | |
| 239 self.__todo.list.select_set(i) | |
| 240 self.__todo.list.yview(i) | |
| 241 url = self.__todo.items[i] | |
| 11478 | 242 self.__checking.config(text="Checking "+self.format_url(url)) |
| 7887 | 243 self.__parent.update() |
| 244 self.dopage(url) | |
| 245 else: | |
| 246 self.stop() | |
| 247 self.__busy = 0 | |
| 248 self.go() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 def showinfo(self, url): |
| 7887 | 251 d = self.__details |
| 252 d.clear() | |
| 11478 | 253 d.put("URL: %s\n" % self.format_url(url)) |
| 7887 | 254 if self.bad.has_key(url): |
| 255 d.put("Error: %s\n" % str(self.bad[url])) | |
| 256 if url in self.roots: | |
| 257 d.put("Note: This is a root URL\n") | |
| 258 if self.done.has_key(url): | |
| 259 d.put("Status: checked\n") | |
| 260 o = self.done[url] | |
| 261 elif self.todo.has_key(url): | |
| 262 d.put("Status: to check\n") | |
| 263 o = self.todo[url] | |
| 264 else: | |
| 265 d.put("Status: unknown (!)\n") | |
| 266 o = [] | |
| 11478 | 267 if (not url[1]) and self.errors.has_key(url[0]): |
| 7887 | 268 d.put("Bad links from this page:\n") |
| 11478 | 269 for triple in self.errors[url[0]]: |
| 7887 | 270 link, rawlink, msg = triple |
| 11478 | 271 d.put(" HREF %s" % self.format_url(link)) |
| 272 if self.format_url(link) != rawlink: d.put(" (%s)" %rawlink) | |
| 7887 | 273 d.put("\n") |
| 274 d.put(" error %s\n" % str(msg)) | |
| 275 self.__mp.showpanel("Details") | |
| 276 for source, rawlink in o: | |
| 277 d.put("Origin: %s" % source) | |
| 11478 | 278 if rawlink != self.format_url(url): |
| 7887 | 279 d.put(" (%s)" % rawlink) |
| 280 d.put("\n") | |
| 281 d.text.yview("1.0") | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 def setbad(self, url, msg): |
| 7887 | 284 webchecker.Checker.setbad(self, url, msg) |
| 285 self.__bad.insert(url) | |
| 286 self.newstatus() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 def setgood(self, url): |
| 7887 | 289 webchecker.Checker.setgood(self, url) |
| 290 self.__bad.remove(url) | |
| 291 self.newstatus() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
293 def newlink(self, url, origin): |
| 7887 | 294 webchecker.Checker.newlink(self, url, origin) |
| 295 if self.done.has_key(url): | |
| 296 self.__done.insert(url) | |
| 297 elif self.todo.has_key(url): | |
| 298 self.__todo.insert(url) | |
| 299 self.newstatus() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 def markdone(self, url): |
| 7887 | 302 webchecker.Checker.markdone(self, url) |
| 303 self.__done.insert(url) | |
| 304 self.__todo.remove(url) | |
| 305 self.newstatus() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
307 def seterror(self, url, triple): |
| 7887 | 308 webchecker.Checker.seterror(self, url, triple) |
| 11478 | 309 self.__errors.insert((url, '')) |
| 7887 | 310 self.newstatus() |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
311 |
|
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
312 def newstatus(self): |
| 7887 | 313 self.__status.config(text="Status: "+self.status()) |
| 314 self.__parent.update() | |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
315 |
|
7568
e15e85d987af
Use a better way to bind the checkext instance variable to a check
Guido van Rossum <guido@python.org>
parents:
5473
diff
changeset
|
316 def update_checkext(self): |
| 7887 | 317 self.checkext = self.__cv.get() |
|
7568
e15e85d987af
Use a better way to bind the checkext instance variable to a check
Guido van Rossum <guido@python.org>
parents:
5473
diff
changeset
|
318 |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 class ListPanel: |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 |
| 11478 | 322 def __init__(self, mp, name, checker, showinfo=None): |
| 7887 | 323 self.mp = mp |
| 324 self.name = name | |
| 325 self.showinfo = showinfo | |
| 11478 | 326 self.checker = checker |
| 7887 | 327 self.panel = mp.addpanel(name) |
| 328 self.list, self.frame = tktools.make_list_box( | |
| 329 self.panel, width=60, height=5) | |
| 330 self.list.config(exportselection=0) | |
| 331 if showinfo: | |
| 332 self.list.bind('<Double-Button-1>', self.doubleclick) | |
| 333 self.items = [] | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
335 def clear(self): |
| 7887 | 336 self.items = [] |
| 337 self.list.delete(0, END) | |
| 338 self.mp.hidepanel(self.name) | |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
339 |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
340 def doubleclick(self, event): |
| 7887 | 341 l = self.selectedindices() |
| 342 if l: | |
| 11478 | 343 self.showinfo(self.items[l[0]]) |
|
5084
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
344 |
|
afc3e4e08740
Add root URL entry box, separate start/stop/step buttons.
Guido van Rossum <guido@python.org>
parents:
5081
diff
changeset
|
345 def selectedindices(self): |
| 7887 | 346 l = self.list.curselection() |
| 347 if not l: return [] | |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
11482
diff
changeset
|
348 return map(int, l) |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 def insert(self, url): |
| 7887 | 351 if url not in self.items: |
| 352 if not self.items: | |
| 353 self.mp.showpanel(self.name) | |
| 354 # (I tried sorting alphabetically, but the display is too jumpy) | |
| 355 i = len(self.items) | |
| 11478 | 356 self.list.insert(i, self.checker.format_url(url)) |
| 7887 | 357 self.list.yview(i) |
| 358 self.items.insert(i, url) | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 def remove(self, url): |
| 7887 | 361 try: |
| 362 i = self.items.index(url) | |
| 363 except (ValueError, IndexError): | |
| 364 pass | |
| 365 else: | |
| 366 was_selected = i in self.selectedindices() | |
| 367 self.list.delete(i) | |
| 368 del self.items[i] | |
| 369 if not self.items: | |
| 370 self.mp.hidepanel(self.name) | |
| 371 elif was_selected: | |
| 372 if i >= len(self.items): | |
| 373 i = len(self.items) - 1 | |
| 374 self.list.select_set(i) | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 class LogPanel: |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 def __init__(self, mp, name): |
| 7887 | 380 self.mp = mp |
| 381 self.name = name | |
| 382 self.panel = mp.addpanel(name) | |
| 383 self.text, self.frame = tktools.make_text_box(self.panel, height=10) | |
| 384 self.text.config(wrap=NONE) | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 def clear(self): |
| 7887 | 387 self.text.delete("1.0", END) |
| 388 self.text.yview("1.0") | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
390 def put(self, s): |
| 7887 | 391 self.text.insert(END, s) |
| 392 if '\n' in s: | |
| 393 self.text.yview(END) | |
|
5086
aa73da661cdf
Restructured Checker class to get rid of 'ext' table.
Guido van Rossum <guido@python.org>
parents:
5084
diff
changeset
|
394 |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 def write(self, s): |
| 7887 | 396 self.text.insert(END, s) |
| 397 if '\n' in s: | |
| 398 self.text.yview(END) | |
| 399 self.panel.update() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 class MultiPanel: |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 def __init__(self, parent): |
| 7887 | 405 self.parent = parent |
| 406 self.frame = Frame(self.parent) | |
| 407 self.frame.pack(expand=1, fill=BOTH) | |
| 408 self.topframe = Frame(self.frame, borderwidth=2, relief=RAISED) | |
| 409 self.topframe.pack(fill=X) | |
| 410 self.botframe = Frame(self.frame) | |
| 411 self.botframe.pack(expand=1, fill=BOTH) | |
| 412 self.panelnames = [] | |
| 413 self.panels = {} | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 def addpanel(self, name, on=0): |
| 7887 | 416 v = StringVar(self.parent) |
| 417 if on: | |
| 418 v.set(name) | |
| 419 else: | |
| 420 v.set("") | |
| 421 check = Checkbutton(self.topframe, text=name, | |
| 422 offvalue="", onvalue=name, variable=v, | |
| 423 command=self.checkpanel) | |
| 424 check.pack(side=LEFT) | |
| 425 panel = Frame(self.botframe) | |
| 426 label = Label(panel, text=name, borderwidth=2, relief=RAISED, anchor=W) | |
| 427 label.pack(side=TOP, fill=X) | |
| 428 t = v, check, panel | |
| 429 self.panelnames.append(name) | |
| 430 self.panels[name] = t | |
| 431 if on: | |
| 432 panel.pack(expand=1, fill=BOTH) | |
| 433 return panel | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 def showpanel(self, name): |
| 7887 | 436 v, check, panel = self.panels[name] |
| 437 v.set(name) | |
| 438 panel.pack(expand=1, fill=BOTH) | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 def hidepanel(self, name): |
| 7887 | 441 v, check, panel = self.panels[name] |
| 442 v.set("") | |
| 443 panel.pack_forget() | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 def checkpanel(self): |
| 7887 | 446 for name in self.panelnames: |
| 447 v, check, panel = self.panels[name] | |
| 448 panel.pack_forget() | |
| 449 for name in self.panelnames: | |
| 450 v, check, panel = self.panels[name] | |
| 451 if v.get(): | |
| 452 panel.pack(expand=1, fill=BOTH) | |
|
5081
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 if __name__ == '__main__': |
|
1b619b811c10
Tk interface to webchecker. Not fully featured yet, but usable.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 main() |
