Skip to content

Commit

Permalink
mainwindow: Simplify the 'Actions' widget
Browse files Browse the repository at this point in the history
PyQt4 4.7.4 loses its bearings when a widget modifies the
direction of its QBoxLayout in a resize event.

We depended on this behavior to allow the actions widget to
automatically switch between vertical and horizontal layouts.

Simplify the code by just sticking to a vertical layout.
All of the actions on the 'Actions' widget are also
available in the menus these days.

Closes #62

Reported-by: alyst via github.com
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Jul 31, 2010
1 parent 901a8a2 commit 73acd20
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
32 changes: 1 addition & 31 deletions cola/qt.py
@@ -1,5 +1,5 @@
from PyQt4 import QtGui
from PyQt4 import QtCore


from cola import i18n

Expand All @@ -11,33 +11,3 @@ def create_button(text, layout=None):
if layout:
layout.addWidget(button)
return button


class QFlowLayoutWidget(QtGui.QWidget):

_horizontal = QtGui.QBoxLayout.LeftToRight
_vertical = QtGui.QBoxLayout.TopToBottom

def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self._direction = self._vertical
layout = QtGui.QBoxLayout(self._direction)
layout.setSpacing(2)
layout.setMargin(2)
self.setLayout(layout)
self.setContentsMargins(2, 2, 2, 2)
policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,
QtGui.QSizePolicy.Minimum)
self.setSizePolicy(policy)
self.setMinimumSize(QtCore.QSize(1, 1))

def resizeEvent(self, event):
size = event.size()
if size.width() * 0.8 < size.height():
dxn = self._vertical
else:
dxn = self._horizontal

if dxn != self._direction:
self._direction = dxn
self.layout().setDirection(dxn)
5 changes: 2 additions & 3 deletions cola/views/mainwindow.py
Expand Up @@ -27,9 +27,8 @@ def __init__(self, parent=None):

# "Actions" widget
self.actiondockwidget = self.create_dock('Actions')
self.actiondockwidgetcontents = qt.QFlowLayoutWidget(parent=self)

layout = self.actiondockwidgetcontents.layout()
self.actiondockwidgetcontents = QtGui.QWidget()
layout = QtGui.QVBoxLayout(self.actiondockwidgetcontents)
self.rescan_button = qt.create_button('Rescan', layout)
self.stage_button = qt.create_button('Stage', layout)
self.unstage_button = qt.create_button('Unstage', layout)
Expand Down

0 comments on commit 73acd20

Please sign in to comment.