"""
Created on Wed Aug 26 13:48:46 2020
@author: 19749
"""
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import w2_fin
data = w2_fin.data().data_all()
list_add1 = []
list_add2 = []
s_text = ''
path_text = ''
class dialog_1(QWidget):
def __init__(self):
super(dialog_1, self).__init__()
self.setWindowTitle('单只基金选择')
self.resize(500, 450)
self.hlt = QHBoxLayout(self)
self.left()
self.right()
def left(self):
self.vlt1 = QSplitter()
self.hlt.addWidget(self.vlt1)
self.vlt1.setOrientation(Qt.Vertical)
self.l1 = QLabel('输入Wind基金代码:')
self.l1.setFixedHeight(35)
self.le = QLineEdit()
self.le.setFixedHeight(35)
self.le.textChanged.connect(self.in_put)
self.l3 = QLabel('')
self.l3.setFixedHeight(17)
self.btn = QPushButton('选择 >>')
self.btn.setFixedHeight(35)
self.btn.clicked.connect(self.sel)
self.btn_op1 = QPushButton()
op1 = QGraphicsOpacityEffect()
op1.setOpacity(0)
self.btn_op1.setGraphicsEffect(op1)
self.vlt1.addWidget(self.l1)
self.vlt1.addWidget(self.le)
self.vlt1.addWidget(self.l3)
self.vlt1.addWidget(self.btn)
self.vlt1.addWidget(self.btn_op1)
def right(self):
self.vlt2 = QVBoxLayout()
self.hlt.addLayout(self.vlt2)
self.l4 = QLabel('已选单只基金(点击删除):')
self.te = QListWidget()
self.btn2 = QPushButton('确认')
self.btn2.clicked.connect(self.hide)
self.vlt2.addWidget(self.l4)
self.vlt2.addWidget(self.te)
self.vlt2.addWidget(self.btn2)
def in_put(self, text):
global d_text, data
d_text = text
try:
a = data.loc[data['基金代码'] == d_text]['基金简称'].to_string().split(' ')
self.l3.setText(a[1])
except:
if text == '':
self.l3.setText('')
else:
self.l3.setText('该基金不存在')
def sel(self):
global list_add1, list_add2
if (self.l3.text() == '') or (self.l3.text() == '该基金不存在'):
pass
else:
if d_text in list_add1:
self.le.setText('')
else:
list_add1.append(d_text)
list_add2.append(self.l3.text())
item = QListWidgetItem()
btn = QPushButton(d_text + '\n' + self.l3.text())
btn.clicked.connect(self.btn_del)
btn.setObjectName(d_text +','+ self.l3.text())
self.te.addItem(item)
self.te.setItemWidget(item, btn)
item.setSizeHint(QSize(50,50))
self.le.setText('')
print(list_add1, list_add2)
def btn_del(self):
global list_add1, list_add2
button = self.sender()
l = button.objectName().split(',')
row = self.te.indexAt(button.pos()).row()
list_add1.remove(l[0])
list_add2.remove(l[1])
self.te.takeItem(row)
print(list_add1, list_add2)
class dialog_2(QWidget):
def __init__(self):
super(dialog_2, self).__init__()
self.setWindowTitle('命名自定义基金类别')
self.resize(100, 150)
self.vlt = QVBoxLayout(self)
self.l = QLabel('命名自定义基金类别:')
self.le = QLineEdit()
self.btn = QPushButton('确认')
self.btn.clicked.connect(self.p)
self.vlt.addWidget(self.l)
self.vlt.addWidget(self.le)
self.vlt.addWidget(self.btn)
def p(self):
global s_text
s_text = self.le.text()
self.le.setText('')
self.hide()
class dialog_3(QWidget):
def __init__(self):
super(dialog_3, self).__init__()
self.setWindowTitle('保存路径:')
self.resize(600, 150)
self.vlt = QVBoxLayout(self)
self.l = QLabel('保存路径:')
self.le = QLineEdit()
self.btn_op1 = QPushButton()
op1 = QGraphicsOpacityEffect()
op1.setOpacity(0)
self.btn_op1.setGraphicsEffect(op1)
self.btn = QPushButton('确认')
self.btn.setMaximumWidth(100)
self.btn.clicked.connect(self.p)
self.vlt.addWidget(self.l)
self.vlt.addWidget(self.le)
self.hlt = QHBoxLayout()
self.vlt.addLayout(self.hlt)
self.hlt.addWidget(self.btn_op1)
self.hlt.addWidget(self.btn)
def p(self):
global path_text
path_text = self.le.text()
self.le.setText('')
a = path_text.split('\\')
b = '\\'.join(a)
path_text = b
self.hide()
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
w1 = dialog_3()
w1.show()
sys.exit(app.exec())