consolidator
/
GuidsWindowOld.py
125 строк · 5.1 Кб
1import os2import sys3from PySide6.QtCore import (Slot)4from PySide6.QtWidgets import (5QDialog
6,QListWidget7,QListWidgetItem8,QTextEdit9,QPushButton10,QLabel11)12from PySide6.QtUiTools import QUiLoader13import pandas as pd14from GuidsSync import GuidsSync,GuidDescr15import time16
17class GuidsWindowOld(QDialog):18
19normalButtonColor="background-color: rgb(236, 236, 236);"20warningButtonColor = "background-color: rgb(255, 179, 48);"21
22guids={}23
24def __init__(self, guidsDir:str, syncModule:GuidsSync=None) -> None:25super().__init__()26loader = QUiLoader()27self.local_dir = guidsDir28self.remote_dir = None29self.sync_module = syncModule30try:31if not os.path.isdir(guidsDir): raise Exception(f"Директория справочников '{guidsDir}' отсутсвует.")32self.files = [f for f in os.listdir(guidsDir) if "~$" not in f and ".xlsx" in f]33for file in self.files:34fullName = f"{guidsDir}\\{file}"35key = file.replace(".xlsx","")36self.guids[key]=fullName37try:38self.cur_path = sys._MEIPASS39except:40self.cur_path = os.path.dirname(os.path.realpath(__file__))41
42self.GuidsDialog:QDialog = loader.load(f"{self.cur_path}\\GuidsWindowOld.ui", None)43self.guidsList:QListWidget = self.GuidsDialog.guidsList44self.textGuid:QTextEdit = self.GuidsDialog.textGuid45self.remoteGuidsButton:QPushButton = self.GuidsDialog.remoteGuidsButton46self.localGuidsButton:QPushButton = self.GuidsDialog.localGuidsButton47self.syncWarningLabel:QLabel = self.GuidsDialog.syncWarningLabel48self.reload_guids_list()49self.guidsList.itemSelectionChanged.connect(self.list_item_selected)50self.guidsList.itemDoubleClicked.connect(self.list_item_dbl_click)51self.remoteGuidsButton.clicked.connect(self.remote_guids_button_clicked)52self.localGuidsButton.clicked.connect(self.local_guids_button_clicked)53self.check_guids_modified()54except : raise55
56def show(self):57self.GuidsDialog.exec()58
59def check_guids_modified(self):60try:61if self.sync_module is None:62self.remoteGuidsButton.setStyleSheet(self.normalButtonColor)63self.localGuidsButton.setStyleSheet(self.normalButtonColor)64self.remoteGuidsButton.setDisabled(True)65self.localGuidsButton.setDisabled(True)66# raise Exception("Модуль синхронизации справочников не инициализирован")67else:68self.syncWarningLabel.hide()69check_result=self.sync_module.check()70self.remoteGuidsButton.setStyleSheet(self.warningButtonColor if check_result[0] else self.normalButtonColor)71self.localGuidsButton.setStyleSheet(self.warningButtonColor if check_result[1] else self.normalButtonColor)72
73except: raise74
75def reload_guids_list(self):76""" Перезагрузка списка справочника """77try:78self.guidsList.addItems(self.guids.keys())79except: raise80
81@Slot()82def list_item_selected(self):83""" Обработчик выбора справочника из списка """84try:85list:QListWidget = self.sender()86selected:QListWidgetItem = list.selectedItems()[0]87key = selected.data(0)88# print(key)89df = pd.read_excel(self.guids[key])90table=df.to_html(index=False,header=True,justify="center",na_rep="",decimal=",")91html=f"""<html>92<head>
93<style>
94table, th, td {{font-size:11pt; font-family: sans-serif; border:1px solid black; border-collapse:collapse; text-align:left;}}
95th, td {{padding: 3px;}}
96</style>
97</head>
98<body>{table}</body>99</html>"""
100self.textGuid.setHtml(html)101except: raise102
103@Slot()104def list_item_dbl_click(self):105""" Обработчик двойного клика по названию справочника """106list:QListWidget = self.sender()107selected:QListWidgetItem = list.selectedItems()[0]108key = selected.data(0)109os.system(f'start EXCEL.exe "{self.guids[key]}"')110self.sync_module.reconnect()111self.check_guids_modified()112
113def remote_guids_button_clicked(self):114try:115self.sync_module.get_from_remote()116self.check_guids_modified()117self.sync_module.send_to_remote()118self.remoteGuidsButton.setStyleSheet(self.normalButtonColor)119except: raise120
121def local_guids_button_clicked(self):122try:123self.sync_module.send_to_remote()124self.localGuidsButton.setStyleSheet(self.normalButtonColor)125except: raise