import export dialog by adding selection of export type
This commit is contained in:
+23
-2
@@ -1,5 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QHBoxLayout, QPushButton, QFileDialog, \
|
||||
QGroupBox, QCheckBox
|
||||
QGroupBox, QCheckBox, QComboBox
|
||||
|
||||
|
||||
class ExportKontorDialog(QDialog):
|
||||
@@ -12,17 +14,26 @@ class ExportKontorDialog(QDialog):
|
||||
self.tables = []
|
||||
self._table_options = {}
|
||||
|
||||
self.export_options = {"JSON": {"ext": ".json"}, "YAML": {"ext": ".yaml"}, "SQLite": {"ext": ".db"}}
|
||||
self.current_export_type = "JSON"
|
||||
|
||||
buttons = (QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||
|
||||
self.buttonBox = QDialogButtonBox(buttons)
|
||||
self.buttonBox.accepted.connect(self.accept)
|
||||
self.buttonBox.rejected.connect(self.reject)
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
self.label = QLabel()
|
||||
self.label.setText("Export DB to data.json")
|
||||
layout = QVBoxLayout()
|
||||
|
||||
self.combo_box = QComboBox()
|
||||
self.combo_box.addItems(["JSON", "YAML", "SQLite"])
|
||||
self.combo_box.currentTextChanged.connect(self.change_export_type)
|
||||
file_layout = QHBoxLayout()
|
||||
file_layout.addWidget(self.label)
|
||||
file_layout.addWidget(self.combo_box)
|
||||
file_button = QPushButton("Select file")
|
||||
file_button.clicked.connect(self.select_file)
|
||||
file_layout.addWidget(file_button)
|
||||
@@ -30,6 +41,8 @@ class ExportKontorDialog(QDialog):
|
||||
|
||||
for table_name in self.kontor_db.get_table_names():
|
||||
check_box = QCheckBox(table_name)
|
||||
check_box.setChecked(True)
|
||||
self.tables.append(table_name)
|
||||
self._table_options[table_name] = check_box
|
||||
check_box.stateChanged.connect(self.change_selection)
|
||||
layout.addWidget(check_box)
|
||||
@@ -42,11 +55,19 @@ class ExportKontorDialog(QDialog):
|
||||
if box.isChecked():
|
||||
self.tables.append(name)
|
||||
|
||||
def change_export_type(self, text):
|
||||
self.current_export_type = text
|
||||
self.label.setText(f"Export DB to data.{self.export_options[text]["ext"]}")
|
||||
|
||||
def select_file(self):
|
||||
file_dialog = QFileDialog()
|
||||
file_dialog.setFileMode(QFileDialog.FileMode.AnyFile)
|
||||
file_dialog.setDefaultSuffix(self.export_options[self.current_export_type]["ext"])
|
||||
file_dialog.setNameFilter(f"*{self.export_options[self.current_export_type]["ext"]}")
|
||||
if file_dialog.exec():
|
||||
self.file_name = file_dialog.selectedFiles()[0]
|
||||
export_file = Path(self.file_name)
|
||||
self.file_name = export_file.with_suffix(self.export_options[self.current_export_type]["ext"])
|
||||
self.label.setText(f"Export DB to {self.file_name}")
|
||||
|
||||
def get_tables_to_export(self) -> list:
|
||||
|
||||
@@ -114,6 +114,7 @@ class MainWindow(QMainWindow):
|
||||
export_dlg = ExportKontorDialog(self, self.kontor_db)
|
||||
if export_dlg.exec():
|
||||
print(export_dlg.get_tables_to_export())
|
||||
print(f"export DB to {export_dlg.file_name}")
|
||||
self.statusBar.showMessage(f"export DB to {export_dlg.file_name}", 3000)
|
||||
else:
|
||||
self.statusBar.showMessage("Export cancelled", 3000)
|
||||
|
||||
Reference in New Issue
Block a user