forked from huzhicheng/BaiduMusicSpider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
142 lines (103 loc) · 4.96 KB
/
settings.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#-*- coding:utf-8 -*-
__author__ = 'huzhicheng'
from PyQt4.QtGui import *
from PyQt4 import QtCore
from PyQt4 import QtGui
import codecs,sys,os
import time
username = "your baidu acount" #配置你的百度账号
password = "your baidu password" #配置你的百度密码
musiclistUrl = "http://music.baidu.com/top/new" # http://music.baidu.com/top/new
root = os.path.dirname(__file__)+"/"
def translate(text):
_encoding = QApplication.UnicodeUTF8
return QApplication.translate("MainWindow", text, None, _encoding)
def lastModifyTimeIsToday(filename):
'''
判断最后修改时间是不是今天
'''
lastModifytime = time.strftime("%Y%m%d",time.localtime(os.stat(filename).st_mtime))
timenow=time.strftime("%Y%m%d",time.localtime(time.time()))
return lastModifytime==timenow
def recordsExistAndLasted():
'''
判断需要的文件是不是存在 并且是今天产生的
'''
listFile = root+"list.txt"
if os.path.exists(listFile) and \
lastModifyTimeIsToday(listFile):
return True
else:
return False
class settingDig(QtGui.QDialog):
def __init__(self,argv='',parent=None):
super(settingDig,self).__init__(parent)
self.resize(QtCore.QSize(378,292))
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Dialog)
self.btn_close = QtGui.QPushButton()
self.btn_close.setStyleSheet("""QPushButton{background-image:url(./img/btn_close_normal.png);width:39px;height:18px;padding-top:0px;border:0px;}
QPushButton:hover{background-image:url(./img/btn_close_highlight.png);}
QPushButton:pressed{background-image:url(./img/btn_close_down.png);}""")
self.layout_top = QtGui.QHBoxLayout() #顶部栏
#self.layout_top.addWidget(self.label_title,1,QtCore.Qt.AlignLeft)
self.layout_top.addWidget(self.btn_close,0,QtCore.Qt.AlignRight | QtCore.Qt.AlignTop)
self.label_loginname = QtGui.QLabel(u"存储路径:")
self.label_loginname.setMargin(10)
self.text_storage = QtGui.QLineEdit()
self.text_storage.setText(argv)
self.text_storage.setFixedSize(230,30)
self.btn_settingStoragePath = QtGui.QPushButton(u"请选择")
self.btn_settingStoragePath.setStyleSheet("""QPushButton{background-image:url(./img/btn_ok.png);width:90px;height:25px;padding-top:0px;border:0px;}
""")
self.connect(self.btn_settingStoragePath,QtCore.SIGNAL("clicked()"),self.settingStorage_click)
self.layout_loginname = QtGui.QVBoxLayout()
self.layout_title = QtGui.QHBoxLayout()
self.layout_loginname.addStretch()
self.layout_loginname.addWidget(self.label_loginname)
self.layout_title.addWidget(self.text_storage)
self.layout_loginname.addStretch()
self.layout_title.addWidget(self.btn_settingStoragePath)
self.layout_loginname.addLayout(self.layout_title)
self.btnOk = QtGui.QPushButton(u"保存")
self.btnOk.setFixedSize(120,30)
self.layout_button = QtGui.QHBoxLayout()
self.layout_button.addStretch(1)
self.layout_button.addWidget(self.btnOk)
self.layout_button.addStretch(1)
self.layout_main = QtGui.QVBoxLayout() #整个布局外框
self.layout_main.addLayout(self.layout_top)
self.layout_main.addStretch() #平均分配空间
self.layout_main.addLayout(self.layout_loginname)
self.layout_main.addStretch() #平均分配空间
self.layout_main.addLayout(self.layout_button)
self.layout_main.addStretch() #平均分配空间
self.setLayout(self.layout_main)
self.layout_main.setContentsMargins(0,0,0,0)
self.layout_main.setSpacing(0)
self.connect(self.btn_close, QtCore.SIGNAL("clicked()"),self.LoginExit)
self.connect(self.btnOk, QtCore.SIGNAL("clicked()"),self.setStorePath)
def paintEvent(self,event):
self.painter = QtGui.QPainter()
self.painter.begin(self)
self.painter.drawPixmap(self.rect(), QtGui.QPixmap("./img/show_con_bg.jpg"))
self.painter.end()
def settingStorage_click(self):
folder = QtGui.QFileDialog.getExistingDirectory(None,u"默认存储",os.getcwd())
self.text_storage.setText(folder)
def LoginExit(self):
self.close()
def setStorePath(self):
storagepath = self.text_storage.text()
storagepath = unicode(storagepath).encode("utf-8")
print(storagepath)
if not os.path.exists(storagepath):
try:
os.mkdir(storagepath)
except:
QtGui.QMessageBox.warning(self, u'路径错误', u'非法路径')
return
iniconfig = codecs.open(os.getcwd()+"\config"+"\config.ini","w")
iniconfig.write(storagepath)
iniconfig.close()
self.parent().stroagePath = storagepath
self.close()