|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2017 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to get the data for a submodule deinit operation. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_GitSubmodulesDeinitDialog import Ui_GitSubmodulesDeinitDialog |
|
14 |
|
15 |
|
16 class GitSubmodulesDeinitDialog(QDialog, Ui_GitSubmodulesDeinitDialog): |
|
17 """ |
|
18 Class implementing a dialog to get the data for a submodule deinit |
|
19 operation. |
|
20 """ |
|
21 def __init__(self, submodulePaths, parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param submodulePaths list of submodule paths |
|
26 @type list of str |
|
27 @param parent reference to the parent widget |
|
28 @type QWidget |
|
29 """ |
|
30 super().__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.submodulesList.addItems(sorted(submodulePaths)) |
|
34 |
|
35 self.buttonBox.button( |
|
36 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
37 |
|
38 def __updateOK(self): |
|
39 """ |
|
40 Private slot to update the state of the OK button. |
|
41 """ |
|
42 enable = ( |
|
43 self.allCheckBox.isChecked() or |
|
44 len(self.submodulesList.selectedItems()) > 0 |
|
45 ) |
|
46 self.buttonBox.button( |
|
47 QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
|
48 |
|
49 @pyqtSlot(bool) |
|
50 def on_allCheckBox_toggled(self, checked): |
|
51 """ |
|
52 Private slot to react on changes of the all checkbox. |
|
53 |
|
54 @param checked state of the checkbox |
|
55 @type bool |
|
56 """ |
|
57 self.__updateOK() |
|
58 |
|
59 @pyqtSlot() |
|
60 def on_submodulesList_itemSelectionChanged(self): |
|
61 """ |
|
62 Private slot to react on changes of the submodule selection. |
|
63 """ |
|
64 self.__updateOK() |
|
65 |
|
66 def getData(self): |
|
67 """ |
|
68 Public method to get the entered data. |
|
69 |
|
70 @return tuple containing a flag to indicate all submodules, a list of |
|
71 selected submodules and a flag indicating an enforced operation |
|
72 @rtype tuple of (bool, list of str, bool) |
|
73 """ |
|
74 submodulePaths = [] |
|
75 deinitAll = self.allCheckBox.isChecked() |
|
76 if not deinitAll: |
|
77 for itm in self.submodulesList.selectedItems(): |
|
78 submodulePaths.append(itm.text()) |
|
79 |
|
80 return all, submodulePaths, self.forceCheckBox.isChecked() |