1 from PyQt4
import QtGui
2 from PyQt4
import QtCore
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
)
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
)
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
):
36 if size
.width() * 0.8 < size
.height():
39 dxn
= self
._horizontal
41 if dxn
!= self
._direction
:
43 self
.layout().setDirection(dxn
)