[PyQt] QDockWidget sizing behavior

2010-10-11 Thread John Wiggins
Hello,

I'm laying out part of the UI for my app using a QMainWindow with no central
widget and 4 dock widgets. I'd like the dock widgets to be sized
proportionally to each other but they seem to ignore the value returned by
sizeHint(). Am I missing something?

- John

Here's a concrete example illustrating my problem:

import cPickle
import os.path
import sys
from PyQt4 import QtGui, QtCore

class _ViewContainer(QtGui.QMainWindow):
""" This class is a container for a view that allows an initial size
(specified as a tuple) to be set.
"""
def __init__(self, size, main_window):
QtGui.QMainWindow.__init__(self)
# Save the size and main window.
self._width, self._height = size
self._main_window = main_window
# set a minimum size to quiet Qt
self.setMinimumSize(100, 100)
self.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Preferred)

def minimumSizeHint(self):
try:
return self.centralWidget().minimumSizeHint()
except AttributeError:
return super(_ViewContainer, self).minimumSizeHint()

def sizeHint(self):
sh = self.centralWidget().sizeHint()
if self._width > 0:
if self._width > 1:
w = self._width
else:
w = self._main_window.width() * self._width
sh.setWidth(int(w))
if self._height > 0:
if self._height > 1:
h = self._height
else:
h = self._main_window.height() * self._height
sh.setHeight(int(h))
return sh


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")

MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,800,600).size()).expandedTo(MainWindow.minimumSizeHint()))

self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0,0,800,21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)

self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"MainWindow",
None,
QtGui.QApplication.UnicodeUTF8))


class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.createDockWindows()

def closeEvent(self, event):
self.saveLayout()
super(MainWindow, self).closeEvent(event)

def createDockWidget(self, name, size):
dock = QtGui.QDockWidget(name, self)
child = QtGui.QLabel(name)
vc = _ViewContainer(size, self)
dock.setWidget(vc)
dock.setObjectName(name)
self._qt4_adjust_widget_layout(child)
dock.widget().setCentralWidget(child)

return dock;

def createDockWindows(self):
dock1 = self.createDockWidget("Dock1", (0.5, 0.75))
self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock1)
dock2 = self.createDockWidget("Dock2", (0.5, 0.75))
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dock2)
dock3 = self.createDockWidget("Dock3", (0.5, 0.25))
self.splitDockWidget(dock2, dock3, QtCore.Qt.Horizontal)
dock4 = self.createDockWidget("Dock4", (0.5, 0.25))
self.splitDockWidget(dock1, dock4, QtCore.Qt.Horizontal)

def saveLayout(self):
filename = './layout.dat'
f = file(filename, 'w')
state = str(self.saveState())
cPickle.dump((0,state), f)
f.close()

def restoreLayout(self):
filename = './layout.dat'
if os.path.exists(filename):
f = file(filename, 'r')
vers, state = cPickle.load(f)
f.close()
self.restoreState(state)

@staticmethod
def _qt4_adjust_widget_layout(w):
lay = w.layout()
if lay is not None:
lay.setAlignment(QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
lay.setContentsMargins(0, 0, 0, 0)


def main():
app = QtGui.QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.restoreLayout()
mainwindow.show()
sys.exit(app.exec_())

if __name__ == '__main__':
main()
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QDockWidget sizing behavior

2010-10-11 Thread John Wiggins
On Mon, Oct 11, 2010 at 10:33 AM, Hans-Peter Jansen  wrote:

> On Monday 11 October 2010, 16:17:21 John Wiggins wrote:
> > Hello,
> >
> > I'm laying out part of the UI for my app using a QMainWindow with no
> > central widget and 4 dock widgets. I'd like the dock widgets to be
> > sized proportionally to each other but they seem to ignore the value
> > returned by sizeHint(). Am I missing something?
>
> Without looking deeper into your code, there's something you should note
> (from the Qt QDockWidget documentation):
>
> Appearance
> [...]
> A QDockWidget acts as a wrapper for its child widget, set with
> setWidget(). Custom size hints, minimum and maximum sizes and size
> policies should be implemented in the child widget.
>
> Hth,
> Pete
>

Hello Pete,

 I've done all those things except setting a maximum size.

Also, I didn't post this useful info before:
python - 2.5.4
qt - 4.5.4
pyqt - 4.6.2

- John
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QDockWidget sizing behavior

2010-10-11 Thread John Wiggins
On Mon, Oct 11, 2010 at 2:21 PM, Hans-Peter Jansen  wrote:

> On Monday 11 October 2010, 17:58:35 John Wiggins wrote:
> > On Mon, Oct 11, 2010 at 10:33 AM, Hans-Peter Jansen 
> wrote:
> > > On Monday 11 October 2010, 16:17:21 John Wiggins wrote:
> > > > Hello,
> > > >
> > > > I'm laying out part of the UI for my app using a QMainWindow with
> > > > no central widget and 4 dock widgets. I'd like the dock widgets
> > > > to be sized proportionally to each other but they seem to ignore
> > > > the value returned by sizeHint(). Am I missing something?
>
> You could try to subclass the QLabels and implement sizeHint for them,
> leaving _ViewContainer alone (size wise).. Let us know, if that helps.
>
> Since you have QMainWindows in each of your dock widgets, the outcome is
> still hard to predict. You may want to reduce your example to the bare
> minimum, e.g. with a single QMainWindow, if the above does not appear
> to work.
>
> Pete
>

It's still not working. Here's my QLabel:

class _Label(QtGui.QLabel):
def __init__(self, name, size, main_window):
QtGui.QLabel.__init__(self, name)

# Save the size and main window.
self._width, self._height = size
self._main_window = main_window
# set a minimum size to quiet Qt
self.setMinimumSize(100, 100)
self.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Preferred)

def sizeHint(self):
sh = QtCore.QSize(100, 100)

if self._width > 0:
if self._width > 1:
w = self._width
else:
w = self._main_window.width() * self._width
sh.setWidth(int(w))
if self._height > 0:
if self._height > 1:
h = self._height
else:
h = self._main_window.height() * self._height
sh.setHeight(int(h))
return sh

And since that didn't change the behavior at all, I took the extra
QMainWindow instances out of the picture by modifying the createDockWidget()
method in MainWindow:


def createDockWidget(self, name, size):
dock = QtGui.QDockWidget(name, self)
child = _Label(name, size, self)
dock.setWidget(child)

dock.setObjectName(name)
self._qt4_adjust_widget_layout(child)
return dock

That still has no effect on the original behavior. sizeHint() is called on
the _Label instances and ignored.

- John
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QDockWidget sizing behavior

2010-10-11 Thread John Wiggins
Wow, I feel daft now :) Thanks for the sharp gaze Baz. I'll look through the
more complicated code that this example is based on and see if the problem
was really this dumb...

- John

On Mon, Oct 11, 2010 at 6:04 PM, Baz Walter  wrote:

> On 11/10/10 15:17, John Wiggins wrote:
>
>> Hello,
>>
>> I'm laying out part of the UI for my app using a QMainWindow with no
>> central
>> widget and 4 dock widgets. I'd like the dock widgets to be sized
>> proportionally to each other but they seem to ignore the value returned by
>> sizeHint(). Am I missing something?
>>
>> - John
>>
>> Here's a concrete example illustrating my problem:
>>
>
> [snip]
>
>
>  def createDockWindows(self):
>> dock1 = self.createDockWidget("Dock1", (0.5, 0.75))
>> self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock1)
>> dock2 = self.createDockWidget("Dock2", (0.5, 0.75))
>> self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dock2)
>> dock3 = self.createDockWidget("Dock3", (0.5, 0.25))
>> self.splitDockWidget(dock2, dock3, QtCore.Qt.Horizontal)
>> dock4 = self.createDockWidget("Dock4", (0.5, 0.25))
>> self.splitDockWidget(dock1, dock4, QtCore.Qt.Horizontal)
>>
>
> this makes no sense: how can the top dock area and the bottom dock area
> *both* have 75% of the height?
>
> change dock2 to (0.5, 0.25), and dock4 to (0.5, 0.75), and it should work
> correctly (well, it does for me using qt4.7, anyway).
>
> (nb: and don't forget to disable your restoreLayout method before trying :)
>
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] PyQt and MPI

2010-10-29 Thread John Wiggins
I would recommend something based around QProcess or the python builtin
subprocess module. Your GUI would set all the parameters as it does now, and
when you hit the OK button it starts the mpirun command using one of the
previously mentioned APIs.

I suggest doing it this way because MPI doesn't really lend itself to
interactive programs. I suppose it would be possible to block all the slave
nodes with an MPI_recv() and then unblock them with a send on the master
when things are ready but that would probably make your code nightmarishly
complicated.

HTH,
- John

On Fri, Oct 29, 2010 at 11:37 AM, dizou  wrote:

>
> I have some code that uses Open MPI to do some pretty intense calculations
> (KDEs). I made a GUI to set some parameters for the calculations. Is there
> any way to integrate these two applications?
> So what I would like to have is my GUI to my on one processor, and then
> when
> I click a button to do the calculations, the MPI stuff starts.
> --
> View this message in context:
> http://old.nabble.com/PyQt-and-MPI-tp30087634p30087634.html
> Sent from the PyQt mailing list archive at Nabble.com.
>
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] QMenu.setTitle on OS X

2011-09-30 Thread John Wiggins
Hello,
I've run into some strange behavior with QMenu's setTitle function
failing on OS X, but only when called on the Help menu. Here's what
I'm running:
OS X 10.5.8; Qt 4.5.3(Carbon); PyQt 4.6; sip 4.9.3
If you run the attached program, select the "Change menu titles" item
in the Options menu and note that Help menu title will not change.
So I guess my questions are: Has anybody else run into this and found
a workaround? Is it still happening in newer versions of Qt/OS X? Is
this a Qt bug or a Carbon bug?

- John


qt_sandbox.py
Description: Binary data
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QMenu.setTitle on OS X

2011-10-03 Thread John Wiggins
Thanks for checking. Is it safe to assume this was a bug in Qt that
was fixed sometime between 4.5.3 and 4.7.x?
- John

On Sat, Oct 1, 2011 at 4:04 AM, Phil Thompson
 wrote:
> On Fri, 30 Sep 2011 16:52:18 -0500, John Wiggins 
> wrote:
>> Hello,
>> I've run into some strange behavior with QMenu's setTitle function
>> failing on OS X, but only when called on the Help menu. Here's what
>> I'm running:
>> OS X 10.5.8; Qt 4.5.3(Carbon); PyQt 4.6; sip 4.9.3
>> If you run the attached program, select the "Change menu titles" item
>> in the Options menu and note that Help menu title will not change.
>> So I guess my questions are: Has anybody else run into this and found
>> a workaround? Is it still happening in newer versions of Qt/OS X? Is
>> this a Qt bug or a Carbon bug?
>>
>> - John
>
> Works fine for me with current versions of everything.
>
> Phil
>
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt