eric6/Helpviewer/Passwords/PasswordsDialog.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show all saved logins.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, QSortFilterProxyModel
13 from PyQt5.QtGui import QFont, QFontMetrics
14 from PyQt5.QtWidgets import QDialog
15
16 from E5Gui import E5MessageBox
17
18 from .Ui_PasswordsDialog import Ui_PasswordsDialog
19
20
21 class PasswordsDialog(QDialog, Ui_PasswordsDialog):
22 """
23 Class implementing a dialog to show all saved logins.
24 """
25 def __init__(self, parent=None):
26 """
27 Constructor
28
29 @param parent reference to the parent widget (QWidget)
30 """
31 super(PasswordsDialog, self).__init__(parent)
32 self.setupUi(self)
33
34 self.__showPasswordsText = self.tr("Show Passwords")
35 self.__hidePasswordsText = self.tr("Hide Passwords")
36 self.passwordsButton.setText(self.__showPasswordsText)
37
38 self.removeButton.clicked.connect(
39 self.passwordsTable.removeSelected)
40 self.removeAllButton.clicked.connect(self.passwordsTable.removeAll)
41
42 import Helpviewer.HelpWindow
43 from .PasswordModel import PasswordModel
44
45 self.passwordsTable.verticalHeader().hide()
46 self.__passwordModel = PasswordModel(
47 Helpviewer.HelpWindow.HelpWindow.passwordManager(), self)
48 self.__proxyModel = QSortFilterProxyModel(self)
49 self.__proxyModel.setSourceModel(self.__passwordModel)
50 self.searchEdit.textChanged.connect(
51 self.__proxyModel.setFilterFixedString)
52 self.passwordsTable.setModel(self.__proxyModel)
53
54 fm = QFontMetrics(QFont())
55 height = fm.height() + fm.height() // 3
56 self.passwordsTable.verticalHeader().setDefaultSectionSize(height)
57 self.passwordsTable.verticalHeader().setMinimumSectionSize(-1)
58
59 self.__calculateHeaderSizes()
60
61 def __calculateHeaderSizes(self):
62 """
63 Private method to calculate the section sizes of the horizontal header.
64 """
65 fm = QFontMetrics(QFont())
66 for section in range(self.__passwordModel.columnCount()):
67 header = self.passwordsTable.horizontalHeader()\
68 .sectionSizeHint(section)
69 if section == 0:
70 header = fm.width("averagebiglongsitename")
71 elif section == 1:
72 header = fm.width("averagelongusername")
73 elif section == 2:
74 header = fm.width("averagelongpassword")
75 buffer = fm.width("mm")
76 header += buffer
77 self.passwordsTable.horizontalHeader()\
78 .resizeSection(section, header)
79 self.passwordsTable.horizontalHeader().setStretchLastSection(True)
80
81 @pyqtSlot()
82 def on_passwordsButton_clicked(self):
83 """
84 Private slot to switch the password display mode.
85 """
86 if self.__passwordModel.showPasswords():
87 self.__passwordModel.setShowPasswords(False)
88 self.passwordsButton.setText(self.__showPasswordsText)
89 else:
90 res = E5MessageBox.yesNo(
91 self,
92 self.tr("Saved Passwords"),
93 self.tr("""Do you really want to show passwords?"""))
94 if res:
95 self.__passwordModel.setShowPasswords(True)
96 self.passwordsButton.setText(self.__hidePasswordsText)
97 self.__calculateHeaderSizes()

eric ide

mercurial