-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathGUI.py
123 lines (105 loc) · 5.51 KB
/
GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
#encoding:utf-8
from Tkinter import *
from ImageTk import PhotoImage
import os
import threading
import webbrowser
class ToolGUI():
def __init__(self):
self.root = root = Tk()
root.withdraw()
root.title('吉敏豆瓣音乐下载工具 4.0')
self.screen_width = screen_width = root.winfo_screenwidth()
self.screen_height = screen_height = root.winfo_screenheight() - 100 #a taskbar may lie under the screen
root.resizable(False,False)
self.icon = icon = PhotoImage(file='icon.gif')
root.tk.call('wm', 'iconphoto', root._w, icon)
Label(root, text='请悉知:', foreground='brown'
).grid(row=0, sticky=E, padx=5, pady=10)
Label(root, text='这是一个收费工具,试用期间您可以下载前50首.', foreground='brown'
).grid(row=0, column=1, sticky=W, pady=10)
Label(root, text='程序需要访问您的红心歌曲,请登录豆瓣 ...').grid(row=1, column=1, sticky=W, pady=0)
Label(root, text='用户名').grid(row=2, column=0, sticky=NW, padx=10, pady=10)
self.txtUser = Entry(width=30)
self.txtUser.grid(row=2, column=1, sticky=W, pady=10)
self.txtUser.focus_set()
Label(root, text='密 码').grid(row=3, column=0, sticky=NW, padx=10, pady=5)
self.txtPass = Entry(width=30, show='*')
self.txtPass.grid(row=3, column=1, sticky=W, pady=10)
Label(root, text='验证码').grid(row=4, column=0, sticky=NW, padx=10, pady=5)
self.txtCAPTCHA = Entry(width=30)
self.txtCAPTCHA.grid(row=4, column=1, sticky=W, pady=5)
self.txtCAPTCHA.bind('<Return>', self.cmd_login)
self.lbl_CAPTCHA = Label(text='正在加载 ...', width=20, height=4, justify=LEFT)
self.lbl_CAPTCHA.grid(row=5, column=1, sticky=NW, pady=5)
self.cmdLogin = Button(root, text='登 录', state=DISABLED, width=5,
command=threading.Thread(target=lambda: self.cmd_login(self)).start)
self.cmdLogin.grid(row=6, column=1, sticky=W, pady=5)
self.cmdLogin.bind('<Return>', self.cmd_login)
self.cmdBuy = Button(root, text='购 买', width=5, justify=RIGHT, command=lambda: self.cmd_buy(self))
self.cmdBuy.grid(row=6, column=1, sticky=E, padx=30, pady=10)
root.update_idletasks()
root.deiconify()
root.withdraw()
root.geometry('%sx%s+%s+%s' % (root.winfo_width() + 10, root.winfo_height(),
(screen_width - root.winfo_width())/2, (screen_height - root.winfo_height())/2) )
root.deiconify()
root.wm_protocol('WM_DELETE_WINDOW', self.on_quit)
self.DEAD = False
def mainWindow(self):
self.mainform = mainform = Toplevel(self.root)
mainform.tk.call('wm', 'iconphoto', mainform._w, self.icon)
mainform.resizable(False,False)
Label(mainform, text=u'文件保存路径:',
foreground='brown', justify=LEFT).grid(row=0, column=0, padx=10, pady=10, sticky=W)
self.path_var = StringVar()
self.path_var.set(os.getcwd())
self.txtPath = Entry(mainform, width=50, textvariable=self.path_var)
self.txtPath.grid(row=0, column=1, pady=10, sticky=EW)
info = u'%s, 您已加红心 %s 首' % (self.douban_user, self.douban_liked_count)
if self.vip_1 or self.vip_2:
info += u' 感谢您购买本程序.'
else:
info += u' 当前为免费试用版.'
Label(mainform, text=info,
foreground='brown').grid(row=1, columnspan=2, padx=10, pady=5, sticky=W)
self.cmdDown = Button(mainform, text=u'下载红心音乐', command=lambda: self.cmd_down(self))
self.cmdDown.grid(row=2, column=0, sticky=EW, padx=10, pady=10)
self.cmdDownAlbum = Button(mainform, text=u'下载专辑',
command=self.create_down_thread)
self.cmdDownAlbum.grid(row=3, column=0, sticky=EW, padx=10, pady=10)
self.album_url = StringVar()
self.album_url.set('http://music.douban.com/subject/1415369/')
self.txtAlbum = Entry(mainform, textvariable=self.album_url)
self.txtAlbum.grid(row=3, column=1, sticky=EW, pady=10)
self.lbl_status = Label(mainform, text='...', height=4, justify=LEFT, foreground='purple', wraplength=400)
self.lbl_status.grid(row=4, column=1, columnspan=1, sticky=W, padx=0)
mainform.update_idletasks()
mainform.deiconify()
mainform.withdraw()
mainform.geometry('%sx%s+%s+%s' % (mainform.winfo_width() + 10, mainform.winfo_height(),
(self.screen_width - mainform.winfo_width())/2,
(self.screen_height - mainform.winfo_height())/2) )
mainform.deiconify()
mainform.wm_protocol('WM_DELETE_WINDOW', self.on_quit)
self.cmdDown.focus_set()
mainform.mainloop()
def on_quit(self):
self.DEAD = True #let download thread quit
try:
self.root.destroy()
self.mainform.destroy()
except:
pass
def cmd_login(self, event):
pass
def cmd_buy(self, event):
browser = webbrowser.get()
browser.open('http://xigongda.org/douban/')
def cmd_down(self, event):
pass
def cmd_down_album(self, event):
pass
def create_down_thread(self):
threading.Thread(target=self.cmd_down_album, args=(self,)).start()