# This Python file uses the following encoding: utf-8
import sqlite3
import traceback
from PyQt5.QtGui import QMouseEvent, QCursor, QIcon, QBrush, QColor
from LoginUi import *
from IntermainUI import *
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QAbstractItemView, QMessageBox, QHeaderView, QTableWidgetItem, \
QAction, QMenu, QComboBox
from PyQt5.QtCore import Qt, QPoint
import pandas as pd
from pandas.core.frame import DataFrame
open_path = '/share/project/share/GUI/ECD.csv'
save_path = '/share/project/share/GUI/ECD.csv'
# 禁止滑轮滚动进行选择
class CustomComboBox(QComboBox):
def wheelEvent(self, event):
event.ignore()
class LoginWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_LoginWindow()
self.ui.setupUi(self)
# 设置为无边框的界面
# self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.ui.pushButton_L_ok.clicked.connect(self.login_in)
self.ui.pushButton_L_ok.setShortcut('Return') # 设置快捷键
self.show()
def login_in(self):
# 获取登录用户和密码
username = self.ui.lineEdit_L_username.text()
password = self.ui.lineEdit_L_password.text()
# # sql语句,判断数据库中是否拥有这账号和密码
# sql = 'select user_id, password, authority from user where user_id=? and password=? and authority=?'
# cursor.execute(sql, (username, password, self.authority))
# # 获取一致的部分,存在表示输入正确,不存在提示错误
# data = cursor.fetchall()
# # 账号和密码不为空时候,才进入
# if username == "znchen" and password =="znchen":
if username == "123456" and password == "123456":
self.win = MainWindow()
self.close()
else:
print("wrong!")
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.m_flag = True
self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置
event.accept()
self.setCursor(QCursor(Qt.OpenHandCursor)) # 更改鼠标图标
def mouseMoveEvent(self, QMouseEvent):
if Qt.LeftButton and self.m_flag:
self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_flag = False
self.setCursor(QCursor(Qt.ArrowCursor))
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton_Save.clicked.connect(self.Saveinfos)
# # 禁止双击编辑单元格
# self.ui.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
# # 选择一行
# self.ui.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
# 添加右击菜单
self.ui.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu)
self.ui.tableWidget.customContextMenuRequested.connect(self.create_rightmenu)
self.show_info()
# self.ui.tableWidget.itemClicked.connect(self.chooseInfo)
# 设置为无边框的界面
self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
# self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.show()
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.m_flag = True
self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置
event.accept()
self.setCursor(QCursor(Qt.OpenHandCursor)) # 更改鼠标图标
def mouseMoveEvent(self, QMouseEvent):
if Qt.LeftButton and self.m_flag:
self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_flag = False
self.setCursor(QCursor(Qt.ArrowCursor))
def Saveinfos(self):
# path = '/share/project/share/GUI/ECD.csv'
data = pd.read_csv(open_path, dtype = {'Num':str})
self.ui.tableWidget.setColumnCount(data.shape[1])
self.ui.tableWidget.setRowCount(data.shape[0])
for i in range(data.shape[0]):
for j in range(data.shape[1]):
# self.ui.tableWidget.setItem(i, j, QTableWidgetItem(str(data.iloc[i, j])))
infosss = self.ui.tableWidget.item(i, j).text()
print(infosss)
data.iat[i, j] = infosss
print(data)
data.to_csv(save_path, encoding='utf-8', index=False)
self.reload_all_infos()
QMessageBox.information(self, '提示', 'Save Successfully')
def add_newinfo(self):
# path = '/share/project/share/GUI/ECD.csv'
data = pd.read_csv(open_path, dtype={'Num': str})
new_row = pd.Series({}, dtype=object)
data1 = pd.concat([data, new_row], ignore_index=True)
data1.to_csv(save_path, encoding='utf-8', index=False)
self.reload_all_infos()
def show_info(self):
# file_path = '/share/project/share/GUI/ECD Engagement Tracking.xlsx'
# data = pd.read_excel(file_path, sheet_name='0605')
# excel_path = '/share/project/share/GUI/ECD.xlsx'
# data = pd.read_excel(excel_path, sheet_name='0605')
# path = '/share/project/share/GUI/ECD.csv'
data = pd.read_csv(open_path, dtype = {'Num':str})
self.ui.tableWidget.setColumnCount(data.shape[1])
self.ui.tableWidget.setRowCount(data.shape[0])
self.ui.tableWidget.setAlternatingRowColors(True)
self.ui.tableWidget.setStyleSheet("QTableView::item:alternate { background-color: #e0ebff; }")
for i in range(data.shape[0]):
for j in range(data.shape[1]):
self.ui.tableWidget.setItem(i, j, QTableWidgetItem(str(data.iloc[i, j])))
if j == 2:
infosss = self.ui.tableWidget.item(i, j).text()
items1 = ["Service", "AmazeFP", "AmazeSys-Physical", "Tweaker", "AmazeDRCLite", "IndustrialLM", " "]
p = items1.index(infosss)
self.combo_box = CustomComboBox(self)
self.combo_box.addItems(items1)
self.combo_box.setCurrentIndex(p)
self.ui.tableWidget.setCellWidget(i, j, self.combo_box)
self.ui.tableWidget.setItem(i, j, )
if j == 3:
infosss = self.ui.tableWidget.item(i, j).text()
items2 = ["Kick-off", "Accomplished", "On going", "Not Started", " "]
p = items2.index(infosss)
self.combo_box = CustomComboBox(self)
self.combo_box.addItems(items2)
self.combo_box.setCurrentIndex(p)
self.ui.tableWidget.setCellWidget(i, j, self.combo_box)
if j == 4:
infosss = self.ui.tableWidget.item(i, j).text()
items3 = ["Normal", "Good", "Need Attention", "Not Good", "-", " "]
p = items3.index(infosss)
self.combo_box = CustomComboBox(self)
self.combo_box.addItems(items3)
self.combo_box.setCurrentIndex(p)
self.ui.tableWidget.setCellWidget(i, j, self.combo_box)
# if infosss == "Need Attention":
# item = self.ui.tableWidget.item(i, j)
# print(item)
# item.setBackground(QBrush(QColor(255,0,0)))
# 展示列表行索引
self.ui.tableWidget.setHorizontalHeaderLabels(data.columns)
def reload_all_infos(self):
self.show_info()
# 右键菜单
def create_rightmenu(self):
# 菜单对象
self.groupBox_menu = QMenu(self)
self.actionA = QAction(QIcon(), u'添加数据', self)
self.actionA.setShortcut('Ctrl+S') # 设置快捷键
self.groupBox_menu.addAction(self.actionA)
self.actionB = QAction(QIcon(), u'删除数据', self)
self.groupBox_menu.addAction(self.actionB)
self.actionA.triggered.connect(self.button) # 将动作A触发时连接到槽函数 button
self.actionB.triggered.connect(self.button_2)
self.groupBox_menu.popup(QCursor.pos()) # 声明当鼠标在groupBox控件上右击时,在鼠标位置显示右键菜单
def button(self):
# 按钮1槽函数,进行数据保存
# 添加数据
Num = ' '
Account = ' '
EngageContent = ' '
TechnicalStatus = ' '
TechnicalTrend = ' '
StartDate = ' '
EndDateEstimated = ' '
EndDateActual = ' '
Sales = ' '
ECDname = ' '
Comment = ' '
infos = pd.DataFrame({'Num': [Num], 'Account': [Account], 'Engage Content': [EngageContent],
'Technical Status': [TechnicalStatus],
'Technical Trend': [TechnicalTrend], 'Start Date': [StartDate],
'Estimated \nEnd Date': [EndDateEstimated],
'Actual\nEnd Date': [EndDateActual], 'Sales': [Sales], 'ECD Engineer(s) Name': [ECDname],
'Comment': [Comment]
})
if "" in infos:
print('Wrong')
QMessageBox.information(self, '提示', '输入信息不能为空')
else:
infos = DataFrame(infos)
# path = '/share/project/share/GUI/ECD.csv'
data = pd.read_csv(open_path, dtype={'Num': str})
data1 = pd.concat([data, infos], ignore_index=True)
# print(data1)
data1.to_csv(save_path, encoding='utf-8', index=False)
self.reload_all_infos()
QMessageBox.information(self, '提示', 'Add Successfully')
def button_2(self):
# 按钮2槽函数,删除数据
# file_path = '/share/project/share/GUI/ECD.csv'
data1 = pd.read_csv(open_path, dtype = {'Num':str})
info_index = self.ui.tableWidget.currentIndex().row()
infos_delete = data1.drop(data1.index[info_index])
infos_delete.to_csv(save_path, encoding='utf-8', index = False)
self.reload_all_infos()
QMessageBox.information(self, '提示', 'Delete Successfully')
if __name__ == '__main__':
app = QApplication(sys.argv)
main = LoginWindow()
sys.exit(app.exec_())