86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
from PySide6.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QHBoxLayout, QPushButton, QFileDialog, \
|
|
QGroupBox, QCheckBox
|
|
|
|
|
|
class ExportKontorDialog(QDialog):
|
|
def __init__(self, parent=None, kontor_db=None):
|
|
super().__init__(parent)
|
|
|
|
self.parent = parent
|
|
self.kontor_db = kontor_db
|
|
self.file_name = None
|
|
self.tables = []
|
|
self._table_options = {}
|
|
|
|
buttons = (QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
|
|
|
self.buttonBox = QDialogButtonBox(buttons)
|
|
self.buttonBox.accepted.connect(self.accept)
|
|
self.buttonBox.rejected.connect(self.reject)
|
|
|
|
self.label = QLabel()
|
|
self.label.setText("Export DB to data.json")
|
|
layout = QVBoxLayout()
|
|
file_layout = QHBoxLayout()
|
|
file_layout.addWidget(self.label)
|
|
file_button = QPushButton("Select file")
|
|
file_button.clicked.connect(self.select_file)
|
|
file_layout.addWidget(file_button)
|
|
layout.addLayout(file_layout)
|
|
|
|
for table_name in self.kontor_db.get_table_names():
|
|
check_box = QCheckBox(table_name)
|
|
self._table_options[table_name] = check_box
|
|
check_box.stateChanged.connect(self.change_selection)
|
|
layout.addWidget(check_box)
|
|
layout.addWidget(self.buttonBox)
|
|
self.setLayout(layout)
|
|
|
|
def change_selection(self):
|
|
self.tables.clear()
|
|
for (name, box) in self._table_options.items():
|
|
if box.isChecked():
|
|
self.tables.append(name)
|
|
|
|
def select_file(self):
|
|
file_dialog = QFileDialog()
|
|
file_dialog.setFileMode(QFileDialog.FileMode.AnyFile)
|
|
if file_dialog.exec():
|
|
self.file_name = file_dialog.selectedFiles()[0]
|
|
self.label.setText(f"Export DB to {self.file_name}")
|
|
|
|
def get_tables_to_export(self) -> list:
|
|
return self.tables
|
|
|
|
|
|
class ImportKontorDialog(QDialog):
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
|
|
self.file_name = None
|
|
|
|
QBtn = (QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
|
|
|
self.buttonBox = QDialogButtonBox(QBtn)
|
|
self.buttonBox.accepted.connect(self.accept)
|
|
self.buttonBox.rejected.connect(self.reject)
|
|
|
|
self.label = QLabel()
|
|
self.label.setText("Import DB from data.json")
|
|
layout = QVBoxLayout()
|
|
file_layout = QHBoxLayout()
|
|
file_layout.addWidget(self.label)
|
|
file_button = QPushButton("Select file")
|
|
file_button.clicked.connect(self.select_file)
|
|
file_layout.addWidget(file_button)
|
|
layout.addLayout(file_layout)
|
|
layout.addWidget(self.buttonBox)
|
|
self.setLayout(layout)
|
|
|
|
def select_file(self):
|
|
file_dialog = QFileDialog()
|
|
file_dialog.setFileMode(QFileDialog.FileMode.ExistingFile)
|
|
if file_dialog.exec():
|
|
self.file_name = file_dialog.selectedFiles()[0]
|
|
self.label.setText(f"Import DB from {self.file_name}")
|