Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

qtlib: add PMButton class

PMButton is a toggle button with plus/minus icon images,
which can be used for a part of expander widget.

Changeset 5d47fa12d6fc

Parent 44a951eef813

by Yuki KODAMA

Changes to one file · Browse files at 5d47fa12d6fc Showing diff from parent 44a951eef813 Diff from another changeset...

 
14
15
16
 
17
18
19
 
166
167
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
15
16
17
18
19
20
 
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
@@ -14,6 +14,7 @@
   from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _ +from tortoisehg.hgqt import icon as geticon  from hgext.color import _styles    tmproot = None @@ -166,3 +167,30 @@
   def setup_font_substitutions():   QtGui.QFont.insertSubstitutions('monospace', ['monaco', 'courier new']) + +class PMButton(QtGui.QPushButton): + """Toggle button with plus/minus icon images""" + + def __init__(self, expanded=True, parent=None): + QtGui.QPushButton.__init__(self, parent) + + size = QtCore.QSize(11, 11) + self.setIconSize(size) + self.setMaximumSize(size) + self.setFlat(True) + + self.plus = geticon('plus') + self.minus = geticon('minus') + icon = expanded and self.minus or self.plus + self.setIcon(icon) + + def clicked(): + icon = self.is_expanded() and self.plus or self.minus + self.setIcon(icon) + self.clicked.connect(clicked) + + def is_expanded(self): + return self.icon().serialNumber() == self.minus.serialNumber() + + def is_collapsed(self): + return not self.is_expanded()