|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to edit a list of history entries. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, Qt |
|
13 from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit |
|
14 |
|
15 from E5Gui import E5MessageBox |
|
16 |
|
17 from .Ui_StartHistoryEditDialog import Ui_StartHistoryEditDialog |
|
18 |
|
19 |
|
20 class StartHistoryEditDialog(QDialog, Ui_StartHistoryEditDialog): |
|
21 """ |
|
22 Class implementing a dialog to edit a list of history entries. |
|
23 """ |
|
24 def __init__(self, history, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param history list of history entries to be edited |
|
29 @type list of str |
|
30 @param parent reference to the parent widget |
|
31 @type QWidget |
|
32 """ |
|
33 super(StartHistoryEditDialog, self).__init__(parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.historyList.addItems(history) |
|
37 for row in range(self.historyList.count()): |
|
38 itm = self.historyList.item(row) |
|
39 flags = itm.flags() | Qt.ItemIsEditable |
|
40 itm.setFlags(flags) |
|
41 |
|
42 self.__updateEditButtons() |
|
43 |
|
44 def __updateEditButtons(self): |
|
45 """ |
|
46 Private method to set the state of the edit buttons. |
|
47 """ |
|
48 selectedCount = len(self.historyList.selectedItems()) |
|
49 self.editButton.setEnabled(selectedCount == 1) |
|
50 self.deleteButton.setEnabled(selectedCount > 0) |
|
51 self.deleteAllButton.setEnabled(self.historyList.count() > 0) |
|
52 |
|
53 @pyqtSlot() |
|
54 def on_historyList_itemSelectionChanged(self): |
|
55 """ |
|
56 Private slot to handle the selection of entries. |
|
57 """ |
|
58 self.__updateEditButtons() |
|
59 |
|
60 @pyqtSlot() |
|
61 def on_editButton_clicked(self): |
|
62 """ |
|
63 Private slot to edit the selected entry. |
|
64 """ |
|
65 itm = self.historyList.selectedItems()[0] |
|
66 historyText, ok = QInputDialog.getText( |
|
67 self, |
|
68 self.tr("Edit History Entry"), |
|
69 self.tr("Enter the new text:"), |
|
70 QLineEdit.Normal, |
|
71 itm.text()) |
|
72 if ok: |
|
73 itm.setText(historyText) |
|
74 |
|
75 @pyqtSlot() |
|
76 def on_deleteButton_clicked(self): |
|
77 """ |
|
78 Private slot to delete the selected entries. |
|
79 """ |
|
80 yes = E5MessageBox.yesNo( |
|
81 self, |
|
82 self.tr("Delete Selected Entries"), |
|
83 self.tr("""Do you really want to delete the selected""" |
|
84 """ history entries?""")) |
|
85 if yes: |
|
86 for itm in self.historyList.selectedItems(): |
|
87 row = self.historyList.row(itm) |
|
88 self.historyList.takeItem(row) |
|
89 del itm |
|
90 |
|
91 @pyqtSlot() |
|
92 def on_deleteAllButton_clicked(self): |
|
93 """ |
|
94 Private slot to delete all entries. |
|
95 """ |
|
96 yes = E5MessageBox.yesNo( |
|
97 self, |
|
98 self.tr("Delete All Entries"), |
|
99 self.tr("""Do you really want to delete the shown history?""")) |
|
100 if yes: |
|
101 self.historyList.clear() |
|
102 |
|
103 def getHistory(self): |
|
104 """ |
|
105 Public method to get the new list of history entries. |
|
106 |
|
107 @return list of history entries |
|
108 @rtype list of str |
|
109 """ |
|
110 history = [] |
|
111 for row in range(self.historyList.count()): |
|
112 entry = self.historyList.item(row).text() |
|
113 history.append(entry) |
|
114 |
|
115 return history |