]> www.wagner.pp.ru Git - oss/ljdump.git/blob - ljdump-gui.py
added license text
[oss/ljdump.git] / ljdump-gui.py
1 #!/usr/bin/python
2 #
3 # ljdump-gui.py - gui interface to ljdump
4 # Greg Hewgill <greg@hewgill.com> http://hewgill.com
5 #
6 # NOTE: This is a work in progress and is probably not suitable for
7 #       general release just yet.
8 #
9 # LICENSE
10 #
11 # This software is provided 'as-is', without any express or implied
12 # warranty.  In no event will the author be held liable for any damages
13 # arising from the use of this software.
14 #
15 # Permission is granted to anyone to use this software for any purpose,
16 # including commercial applications, and to alter it and redistribute it
17 # freely, subject to the following restrictions:
18 #
19 # 1. The origin of this software must not be misrepresented; you must not
20 #    claim that you wrote the original software. If you use this software
21 #    in a product, an acknowledgment in the product documentation would be
22 #    appreciated but is not required.
23 # 2. Altered source versions must be plainly marked as such, and must not be
24 #    misrepresented as being the original software.
25 # 3. This notice may not be removed or altered from any source distribution.
26 #
27 # Copyright (c) 2005-2009 Greg Hewgill
28
29 import sys
30 import threading
31
32 from Tkinter import *
33
34 import ljdump
35
36 gWorkerThread = None
37
38 def poll():
39     global gWorkerThread
40     if gWorkerThread.isAlive():
41         root.after(100, poll)
42     else:
43         gWorkerThread = None
44         status['text'] = "Completed."
45         ok['state'] = NORMAL
46         cancel['state'] = NORMAL
47
48 def do_ok(event = None):
49     print "ok"
50     #root.withdraw()
51     status['text'] = "Running..."
52     ok['state'] = DISABLED
53     cancel['state'] = DISABLED
54     global gWorkerThread
55     gWorkerThread = threading.Thread(None, ljdump.ljdump, args=("http://livejournal.com", username.get(), password.get()))
56     gWorkerThread.start()
57     poll()
58
59 def do_cancel(event = None):
60     print "cancel", event
61     root.destroy()
62
63 root = Tk()
64 root.title("ljdump")
65
66 body = Frame(root)
67 Label(body, text="Username:").grid(row=0, sticky=W)
68 Label(body, text="Password:").grid(row=1, sticky=W)
69 Label(body, text="Status:").grid(row=2, sticky=W)
70 username = Entry(body)
71 password = Entry(body, show="*")
72 status = Label(body, text="Waiting")
73 username.grid(row=0, column=1)
74 password.grid(row=1, column=1)
75 status.grid(row=2, column=1, sticky=W)
76 body.pack(padx=5, pady=5)
77
78 box = Frame(root)
79
80 ok = Button(box, text="OK", width=10, command=do_ok, default=ACTIVE)
81 ok.pack(side=LEFT, padx=5, pady=5)
82 cancel = Button(box, text="Cancel", width=10, command=do_cancel)
83 cancel.pack(side=LEFT, padx=5, pady=5)
84
85 root.bind("<Return>", do_ok)
86 root.bind("<Escape>", do_cancel)
87
88 box.pack()
89
90 username.focus_set()
91 root.mainloop()