views.mainwindow: Remove unused import
[git-cola.git] / cola / qt.py
blob8de9fd798bb1471c06b6b9973f04ed0bb95cbd40
1 from PyQt4 import QtGui
2 from PyQt4 import QtCore
4 from cola import i18n
7 def create_button(text, layout=None):
8 """Create a button, set its title, and add it to the parent."""
9 button = QtGui.QPushButton()
10 button.setText(i18n.gettext(text))
11 if layout is not None:
12 layout.addWidget(button)
13 return button
16 class QFlowLayoutWidget(QtGui.QWidget):
18 _horizontal = QtGui.QBoxLayout.LeftToRight
19 _vertical = QtGui.QBoxLayout.TopToBottom
21 def __init__(self, parent=None):
22 QtGui.QWidget.__init__(self, parent)
23 self._direction = self._vertical
24 self._layout = layout = QtGui.QBoxLayout(self._direction)
25 layout.setSpacing(2)
26 layout.setMargin(2)
27 self.setLayout(layout)
28 self.setContentsMargins(2, 2, 2, 2)
29 policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,
30 QtGui.QSizePolicy.Minimum)
31 self.setSizePolicy(policy)
32 self.setMinimumSize(QtCore.QSize(1, 1))
34 def resizeEvent(self, event):
35 size = event.size()
36 if size.width() * 0.8 < size.height():
37 dxn = self._vertical
38 else:
39 dxn = self._horizontal
41 if dxn != self._direction:
42 self._direction = dxn
43 self.layout().setDirection(dxn)