Update release notes for 1.4.2.2
[git-cola.git] / cola / qt.py
blobfe4ef0030aed5a7b3d95c56f6530a6435646ebcc
1 from PyQt4 import QtGui
2 from PyQt4 import QtCore
4 def create_button(text, layout=None):
5 """Create a button, set its title, and add it to the parent."""
6 button = QtGui.QPushButton()
7 button.setText(text)
8 if layout:
9 layout.addWidget(button)
10 return button
13 class QFlowLayoutWidget(QtGui.QWidget):
15 _horizontal = QtGui.QBoxLayout.LeftToRight
16 _vertical = QtGui.QBoxLayout.TopToBottom
18 def __init__(self, parent=None):
19 QtGui.QWidget.__init__(self, parent)
20 self._direction = self._vertical
21 layout = QtGui.QBoxLayout(self._direction)
22 layout.setSpacing(2)
23 layout.setMargin(2)
24 self.setLayout(layout)
25 self.setContentsMargins(2, 2, 2, 2)
26 policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,
27 QtGui.QSizePolicy.Minimum)
28 self.setSizePolicy(policy)
29 self.setMinimumSize(QtCore.QSize(1, 1))
31 def resizeEvent(self, event):
32 size = event.size()
33 if size.width() * 0.8 < size.height():
34 dxn = self._vertical
35 else:
36 dxn = self._horizontal
38 if dxn != self._direction:
39 self._direction = dxn
40 self.layout().setDirection(dxn)