annotate Tools/webchecker/wsgui.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 9acb314b9072
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #! /usr/bin/env python
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 """Tkinter-based GUI for websucker.
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 Easy use: type or paste source URL and destination directory in
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 their respective text boxes, click GO or hit return, and presto.
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 """
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 from Tkinter import *
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 import websucker
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 import os
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
12 import threading
47248
9acb314b9072 Queue renaming reversal part 3: move module into place and
Georg Brandl <georg@python.org>
parents: 46897
diff changeset
13 import Queue
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
14 import time
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
16 VERBOSE = 2
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 try:
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
20 class Canceled(Exception):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
21 "Exception used to cancel run()."
17802
7eb3288c81e3 Only catch NameError and TypeError when attempting to subclass an
Fred Drake <fdrake@acm.org>
parents: 11480
diff changeset
22 except (NameError, TypeError):
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
23 Canceled = __name__ + ".Canceled"
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
26 class SuckerThread(websucker.Sucker):
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
28 stopit = 0
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
29 savedir = None
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
30 rootdir = None
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
31
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
32 def __init__(self, msgq):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
33 self.msgq = msgq
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
34 websucker.Sucker.__init__(self)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
35 self.setflags(verbose=VERBOSE)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
36 self.urlopener.addheaders = [
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
37 ('User-agent', 'websucker/%s' % websucker.__version__),
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
38 ]
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
39
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
40 def message(self, format, *args):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
41 if args:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
42 format = format%args
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
43 ##print format
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
44 self.msgq.put(format)
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
46 def run1(self, url):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
47 try:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
48 try:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
49 self.reset()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
50 self.addroot(url)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
51 self.run()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
52 except Canceled:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
53 self.message("[canceled]")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
54 else:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
55 self.message("[done]")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
56 finally:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
57 self.msgq.put(None)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
58
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
59 def savefile(self, text, path):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
60 if self.stopit:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
61 raise Canceled
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
62 websucker.Sucker.savefile(self, text, path)
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
63
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
64 def getpage(self, url):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
65 if self.stopit:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
66 raise Canceled
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
67 return websucker.Sucker.getpage(self, url)
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
68
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
69 def savefilename(self, url):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
70 path = websucker.Sucker.savefilename(self, url)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
71 if self.savedir:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
72 n = len(self.rootdir)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
73 if path[:n] == self.rootdir:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
74 path = path[n:]
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
75 while path[:1] == os.sep:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
76 path = path[1:]
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
77 path = os.path.join(self.savedir, path)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
78 return path
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
79
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
80 def XXXaddrobot(self, *args):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
81 pass
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
82
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
83 def XXXisallowed(self, *args):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
84 return 1
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
85
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
86
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
87 class App:
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
88
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
89 sucker = None
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
90 msgq = None
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
91
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
92 def __init__(self, top):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
93 self.top = top
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
94 top.columnconfigure(99, weight=1)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
95 self.url_label = Label(top, text="URL:")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
96 self.url_label.grid(row=0, column=0, sticky='e')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
97 self.url_entry = Entry(top, width=60, exportselection=0)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
98 self.url_entry.grid(row=0, column=1, sticky='we',
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
99 columnspan=99)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
100 self.url_entry.focus_set()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
101 self.url_entry.bind("<Key-Return>", self.go)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
102 self.dir_label = Label(top, text="Directory:")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
103 self.dir_label.grid(row=1, column=0, sticky='e')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
104 self.dir_entry = Entry(top)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
105 self.dir_entry.grid(row=1, column=1, sticky='we',
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
106 columnspan=99)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
107 self.go_button = Button(top, text="Go", command=self.go)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
108 self.go_button.grid(row=2, column=1, sticky='w')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
109 self.cancel_button = Button(top, text="Cancel",
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
110 command=self.cancel,
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
111 state=DISABLED)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
112 self.cancel_button.grid(row=2, column=2, sticky='w')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
113 self.auto_button = Button(top, text="Paste+Go",
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
114 command=self.auto)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
115 self.auto_button.grid(row=2, column=3, sticky='w')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
116 self.status_label = Label(top, text="[idle]")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
117 self.status_label.grid(row=2, column=4, sticky='w')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
118 self.top.update_idletasks()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
119 self.top.grid_propagate(0)
8505
e82d0277e653 # This is a new module I wrote over the weekend. Again, you missed the
Guido van Rossum <guido@python.org>
parents: 8503
diff changeset
120
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
121 def message(self, text, *args):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
122 if args:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
123 text = text % args
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
124 self.status_label.config(text=text)
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
126 def check_msgq(self):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
127 while not self.msgq.empty():
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
128 msg = self.msgq.get()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
129 if msg is None:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
130 self.go_button.configure(state=NORMAL)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
131 self.auto_button.configure(state=NORMAL)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
132 self.cancel_button.configure(state=DISABLED)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
133 if self.sucker:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
134 self.sucker.stopit = 0
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
135 self.top.bell()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
136 else:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
137 self.message(msg)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
138 self.top.after(100, self.check_msgq)
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
139
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
140 def go(self, event=None):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
141 if not self.msgq:
47248
9acb314b9072 Queue renaming reversal part 3: move module into place and
Georg Brandl <georg@python.org>
parents: 46897
diff changeset
142 self.msgq = Queue.Queue(0)
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
143 self.check_msgq()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
144 if not self.sucker:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
145 self.sucker = SuckerThread(self.msgq)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
146 if self.sucker.stopit:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
147 return
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
148 self.url_entry.selection_range(0, END)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
149 url = self.url_entry.get()
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 17802
diff changeset
150 url = url.strip()
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
151 if not url:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
152 self.top.bell()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
153 self.message("[Error: No URL entered]")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
154 return
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
155 self.rooturl = url
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 17802
diff changeset
156 dir = self.dir_entry.get().strip()
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
157 if not dir:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
158 self.sucker.savedir = None
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
159 else:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
160 self.sucker.savedir = dir
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
161 self.sucker.rootdir = os.path.dirname(
29708
e38164aa5be5 SF bug 753592, websucker bug
Neal Norwitz <nnorwitz@gmail.com>
parents: 25219
diff changeset
162 websucker.Sucker.savefilename(self.sucker, url))
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
163 self.go_button.configure(state=DISABLED)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
164 self.auto_button.configure(state=DISABLED)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
165 self.cancel_button.configure(state=NORMAL)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
166 self.message( '[running...]')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
167 self.sucker.stopit = 0
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
168 t = threading.Thread(target=self.sucker.run1, args=(url,))
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
169 t.start()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
170
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
171 def cancel(self):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
172 if self.sucker:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
173 self.sucker.stopit = 1
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
174 self.message("[canceling...]")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
175
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
176 def auto(self):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
177 tries = ['PRIMARY', 'CLIPBOARD']
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
178 text = ""
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
179 for t in tries:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
180 try:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
181 text = self.top.selection_get(selection=t)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
182 except TclError:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
183 continue
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 17802
diff changeset
184 text = text.strip()
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
185 if text:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
186 break
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
187 if not text:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
188 self.top.bell()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
189 self.message("[Error: clipboard is empty]")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
190 return
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
191 self.url_entry.delete(0, END)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
192 self.url_entry.insert(0, text)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
193 self.go()
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
196 class AppArray:
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
197
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
198 def __init__(self, top=None):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
199 if not top:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
200 top = Tk()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
201 top.title("websucker GUI")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
202 top.iconname("wsgui")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
203 top.wm_protocol('WM_DELETE_WINDOW', self.exit)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
204 self.top = top
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
205 self.appframe = Frame(self.top)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
206 self.appframe.pack(fill='both')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
207 self.applist = []
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
208 self.exit_button = Button(top, text="Exit", command=self.exit)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
209 self.exit_button.pack(side=RIGHT)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
210 self.new_button = Button(top, text="New", command=self.addsucker)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
211 self.new_button.pack(side=LEFT)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
212 self.addsucker()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
213 ##self.applist[0].url_entry.insert(END, "http://www.python.org/doc/essays/")
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
214
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
215 def addsucker(self):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
216 self.top.geometry("")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
217 frame = Frame(self.appframe, borderwidth=2, relief=GROOVE)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
218 frame.pack(fill='x')
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
219 app = App(frame)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
220 self.applist.append(app)
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
221
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
222 done = 0
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
223
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
224 def mainloop(self):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
225 while not self.done:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
226 time.sleep(0.1)
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
227 self.top.update()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
228
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
229 def exit(self):
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
230 for app in self.applist:
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
231 app.cancel()
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
232 app.message("[exiting...]")
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
233 self.done = 1
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
234
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
235
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
236 def main():
11480
a97e625ed5d0 # *NOT* by Sam Bayer: reindented to use 4 spaces like the rest here,
Guido van Rossum <guido@python.org>
parents: 8648
diff changeset
237 AppArray().mainloop()
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
238
8503
85e6820482ff Primitive GUI for websucker.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 if __name__ == '__main__':
8648
775188140fe1 Rewrite to support multiple suckers, each with their own thread.
Guido van Rossum <guido@python.org>
parents: 8505
diff changeset
240 main()