-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInterface.py
67 lines (58 loc) · 2.97 KB
/
Interface.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
import os
import sys
import time
import PyQt5
from PyQt5.uic import loadUi
from PyQt5 import QtCore, QtWidgets
from pyomo_piecewise import OptimizationRoutes
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
loadUi(os.curdir + '\\support_files\\Interface.ui', self)
self.folderText.setPlaceholderText(os.path.abspath(os.path.curdir) + '\\support_files\\ТПС_Тест.xlsx')
self.browseButton.clicked.connect(self.browseFiles)
self.acceptButton.clicked.connect(self.acceptParams)
def acceptParams(self):
indexmaps = [self.mapsGroup.buttons()[x].isChecked() for x in range(len(self.mapsGroup.buttons()))].index(True)
indexsolvers = [
self.solversGroup.buttons()[x].isChecked() for x in range(len(self.solversGroup.buttons()))].index(True)
file_path = self.folderText.toPlainText() if self.folderText.toPlainText() != '' \
else os.path.abspath(os.path.curdir) + '\\support_files\\ТПС_Тест.xlsx'
filename = os.path.basename(file_path)
add_to_capex = self.capexBox.value()
self.hide()
print(f'Работаем с файлом {filename}')
try:
start_time = time.time()
task = OptimizationRoutes(file_path, filename, add_to_capex)
task.read_data()
task.create_model()
task.solve_problem(indexsolvers)
task.create_answer()
task.save_answer()
if indexmaps == 0 and filename != 'ТПС_Тест.xlsx':
task.routes_map()
else:
pass
print('Время, за которое была решена задача: ', round((time.time() - start_time)))
except Exception as error:
exc_type, exc_obj, exc_tb = sys.exc_info()
fName = os.path.split(exc_tb.tb_frame.ff_code.co_filename)[1]
print(exc_type, fName, exc_tb.tb_lineno)
print("Что-то пошло не так. Проверьте, нет ли ошибок в считываемом файле, "
"либо обратитесь к автору для исправления багов, если проблема в коде.")
self.show()
def browseFiles(self):
fpath = QFileDialog.getOpenFileName(self, "Select Excel file to import",
os.path.abspath(os.path.curdir), "Excel (*.xls *.xlsx)")[0]
self.folderText.setText(fpath)
if __name__ == '__main__':
app = QApplication(sys.argv)
mood_example = MainWindow()
mood_example.show()
sys.exit(app.exec_())