|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the parameters for a coverage JSON |
|
8 report. |
|
9 """ |
|
10 |
|
11 import os |
|
12 |
|
13 from PyQt6.QtCore import pyqtSlot |
|
14 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
15 |
|
16 from EricWidgets.EricPathPicker import EricPathPickerModes |
|
17 |
|
18 from .Ui_PyCoverageJsonReportDialog import Ui_PyCoverageJsonReportDialog |
|
19 |
|
20 |
|
21 class PyCoverageJsonReportDialog(QDialog, Ui_PyCoverageJsonReportDialog): |
|
22 """ |
|
23 Class implementing a dialog to enter the parameters for a coverage JSON |
|
24 report. |
|
25 """ |
|
26 def __init__(self, defaultDirectory, parent=None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param defaultDirectory default directory for selecting the output |
|
31 directory |
|
32 @type str |
|
33 @param parent reference to the parent widget (defaults to None) |
|
34 @type QWidget (optional) |
|
35 """ |
|
36 super().__init__(parent) |
|
37 self.setupUi(self) |
|
38 |
|
39 self.outputFilePicker.setMode( |
|
40 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE) |
|
41 self.outputFilePicker.setDefaultDirectory(defaultDirectory) |
|
42 self.outputFilePicker.setFilters( |
|
43 self.tr("JSON Files (*.json);;All Files (*)")) |
|
44 self.outputFilePicker.setText( |
|
45 os.path.join(defaultDirectory, "coverage.json")) |
|
46 |
|
47 msh = self.minimumSizeHint() |
|
48 self.resize(max(self.width(), msh.width()), msh.height()) |
|
49 |
|
50 @pyqtSlot(str) |
|
51 def on_outputFilePicker_textChanged(self, filename): |
|
52 """ |
|
53 Private slot handling a change of the output file. |
|
54 |
|
55 @param filename current text of the file picker |
|
56 @type str |
|
57 """ |
|
58 self.buttonBox.button( |
|
59 QDialogButtonBox.StandardButton.Ok).setEnabled(bool(filename)) |
|
60 |
|
61 def getData(self): |
|
62 """ |
|
63 Public method to get the entered data. |
|
64 |
|
65 @return tuple containing the output file and a flag indicating the |
|
66 creation of a compact JSON file |
|
67 |
|
68 @rtype tuple of (str, bool) |
|
69 """ |
|
70 return ( |
|
71 self.outputFilePicker.currentText(), |
|
72 self.compactCheckBox.isChecked(), |
|
73 ) |