Merge lp:~diegosarmentero/ubuntu-sso-client/improve-EnhancedLineEdit into lp:ubuntu-sso-client

Proposed by Diego Sarmentero
Status: Merged
Approved by: Diego Sarmentero
Approved revision: 764
Merged at revision: 761
Proposed branch: lp:~diegosarmentero/ubuntu-sso-client/improve-EnhancedLineEdit
Merge into: lp:ubuntu-sso-client
Diff against target: 137 lines (+89/-11)
2 files modified
ubuntu_sso/qt/gui.py (+12/-11)
ubuntu_sso/qt/tests/test_enchanced_line_edit.py (+77/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntu-sso-client/improve-EnhancedLineEdit
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+72064@code.launchpad.net

Commit message

Improves in EnhancedLineEdit

Description of the change

Improves in EnhancedLineEdit

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

Good, simple change.

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

(12:48:55 PM) nessita: gatox: teeeeessssstsssss :-)
(12:49:11 PM) nessita: gatox: we would like to cover the foillowing:
(12:49:24 PM) ***gatox reading...
(12:49:52 PM) nessita: show_button behaves in a given way (if the string is valid, X buttons is visible, Y is not, otherwise, X button is not visible, Y is)
(12:50:01 PM) nessita: or label*
(12:50:34 PM) nessita: gatox: and you may wanna assert over some of the things you're setting to self.clear_label, the most important ones
(12:50:53 PM) nessita: by important I mean those that are key pieces to the user experience
(12:50:54 PM) gatox: nessita, ok... copy that! :P
(12:51:02 PM) nessita: such as setProperty("lineEditWarning", True)
(12:51:13 PM) nessita: but the margin is not required to be tested
(12:51:15 PM) nessita: makes sense?

review: Needs Fixing
761. By Diego Sarmentero

adding tests for enchaned line edit

762. By Diego Sarmentero

adding missing docstrings

763. By Diego Sarmentero

fixing pep8 issues

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

Can we please use the constant for the mouse pointer instead of 0?

Thanks!

review: Approve
764. By Diego Sarmentero

changing cursor value to use the proper constant instead a number.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/qt/gui.py'
2--- ubuntu_sso/qt/gui.py 2011-08-11 15:19:29 +0000
3+++ ubuntu_sso/qt/gui.py 2011-08-19 17:15:36 +0000
4@@ -17,6 +17,7 @@
5 """Qt implementation of the UI."""
6
7 from PyQt4.QtCore import pyqtSignal
8+from PyQt4.QtCore import Qt
9 from PyQt4.QtGui import (
10 QApplication,
11 QWidget,
12@@ -24,7 +25,6 @@
13 QHBoxLayout,
14 QVBoxLayout,
15 QPixmap,
16- QPushButton,
17 QStyle,
18 QWizard,
19 QWizardPage,
20@@ -148,14 +148,15 @@
21 self._line_edit.setLayout(layout)
22 self.valid_cb = valid_cb
23 layout.addStretch()
24- self.clear_button = QPushButton(self._line_edit)
25- layout.addWidget(self.clear_button)
26- self.clear_button.setMinimumSize(16, 16)
27- self.clear_button.setVisible(False)
28- self.clear_button.setFlat(True)
29- self.clear_button.setCursor(QCursor(0))
30- self.clear_button.setIcon(QApplication.style().standardIcon(
31- QStyle.SP_MessageBoxWarning))
32+ self.clear_label = QLabel(self._line_edit)
33+ self.clear_label.setMargin(2)
34+ self.clear_label.setProperty("lineEditWarning", True)
35+ layout.addWidget(self.clear_label)
36+ self.clear_label.setMinimumSize(16, 16)
37+ self.clear_label.setVisible(False)
38+ self.clear_label.setCursor(QCursor(Qt.ArrowCursor))
39+ self.clear_label.setPixmap(QApplication.style().standardIcon(
40+ QStyle.SP_MessageBoxWarning).pixmap(16, 16))
41 # connect the change of text to the cation that will check if the
42 # text is valid and if the icon should be shown.
43 self._line_edit.textChanged.connect(self.show_button)
44@@ -163,9 +164,9 @@
45 def show_button(self, string):
46 """Decide if we show the button or not."""
47 if not self.valid_cb(string):
48- self.clear_button.setVisible(True)
49+ self.clear_label.setVisible(True)
50 else:
51- self.clear_button.setVisible(False)
52+ self.clear_label.setVisible(False)
53
54
55 class SSOWizardEnhancedEditPage(SSOWizardPage):
56
57=== added file 'ubuntu_sso/qt/tests/test_enchanced_line_edit.py'
58--- ubuntu_sso/qt/tests/test_enchanced_line_edit.py 1970-01-01 00:00:00 +0000
59+++ ubuntu_sso/qt/tests/test_enchanced_line_edit.py 2011-08-19 17:15:36 +0000
60@@ -0,0 +1,77 @@
61+# -*- coding: utf-8 -*-
62+# Author: Diego Sarmentero <diego.sarmentero@canonical.com>
63+#
64+# Copyright 2011 Canonical Ltd.
65+#
66+# This program is free software: you can redistribute it and/or modify it
67+# under the terms of the GNU General Public License version 3, as published
68+# by the Free Software Foundation.
69+#
70+# This program is distributed in the hope that it will be useful, but
71+# WITHOUT ANY WARRANTY; without even the implied warranties of
72+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
73+# PURPOSE. See the GNU General Public License for more details.
74+#
75+# You should have received a copy of the GNU General Public License along
76+# with this program. If not, see <http://www.gnu.org/licenses/>.
77+"""Test the EnhancedLineEdit."""
78+
79+from twisted.trial.unittest import TestCase
80+
81+from PyQt4 import QtGui
82+from PyQt4 import QtCore
83+
84+from ubuntu_sso.qt.gui import EnhancedLineEdit
85+
86+
87+class EnhancedLineEditTestCase(TestCase):
88+ """Tests EnhancedLineEdit for valid and invalid states."""
89+
90+ def get_pixmap_data(self, pixmap):
91+ """Get the raw data of a QPixmap."""
92+ byte_array = QtCore.QByteArray()
93+ array_buffer = QtCore.QBuffer(byte_array)
94+ pixmap.save(array_buffer, "PNG")
95+ return byte_array
96+
97+ # pylint: disable=C0103
98+ def assertEqualPixmaps(self, pixmap1, pixmap2):
99+ """Compare two Qt pixmaps."""
100+ d1 = self.get_pixmap_data(pixmap1)
101+ d2 = self.get_pixmap_data(pixmap2)
102+ self.assertEqual(d1, d2)
103+ # pylint: enable=C0103
104+
105+ def test_enhanced_line_edit_init(self):
106+ """Tests the initial state of the enchanced line edit."""
107+ line_edit = QtGui.QLineEdit()
108+ line_edit.show()
109+ enhanced = EnhancedLineEdit(line_edit)
110+ self.assertEqual(type(enhanced.valid_cb), type(lambda x: False))
111+ self.assertEqual(enhanced.clear_label.property("lineEditWarning"),
112+ True)
113+ self.assertEqual(enhanced.clear_label.isVisible(), False)
114+ self.assertEqual(enhanced.clear_label.cursor().shape(),
115+ QtCore.Qt.ArrowCursor)
116+ self.assertEqual(enhanced.clear_label.isVisible(), False)
117+ self.assertEqualPixmaps(enhanced.clear_label.pixmap(),
118+ QtGui.QApplication.style().standardIcon(
119+ QtGui.QStyle.SP_MessageBoxWarning).pixmap(16, 16))
120+
121+ def test_enhanced_line_edit_function_show_true(self):
122+ """Tests the EnchancedLineEdit show method with validation = True."""
123+ line_edit = QtGui.QLineEdit()
124+ line_edit.show()
125+ func = lambda x: False
126+ enhanced = EnhancedLineEdit(line_edit, valid_cb=func)
127+ line_edit.setText("testing")
128+ self.assertEquals(enhanced.clear_label.isVisible(), True)
129+
130+ def test_enhanced_line_edit_function_show_false(self):
131+ """Tests the EnchancedLineEdit show method with validation = False."""
132+ line_edit = QtGui.QLineEdit()
133+ line_edit.show()
134+ func = lambda x: True
135+ enhanced = EnhancedLineEdit(line_edit, valid_cb=func)
136+ line_edit.setText("testing")
137+ self.assertEquals(enhanced.clear_label.isVisible(), False)

Subscribers

People subscribed via source and target branches