Freitag, 18. Juli 2008

Dockable dialogs - manipulate the GUI with PyQt and ScripterNG

With ScripterNG and PyQt you have access to the GUI and you can test new stuff easily.

Here is an example with dockwidgets, which are curently not used inside Scribus:

If you look in the lower left you can see that overlapping dockwidgets get tabbed. This is a new feature in Qt4.


This is done by the following code:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class DockDialog(QDockWidget):

def __init__(self, dlg, area=Qt.RightDockWidgetArea):
QDockWidget.__init__(self, dlg.windowTitle())
self.setObjectName(dlg.objectName() or i18n(dlg.windowTitle()))
self.resize(dlg.size())
dlg.parent().addDockWidget(area, self)
dlg.setParent(self)
dlg.move(0, 0)
self.setWidget(dlg)
self.show()
dlg.installEventFilter(self)

def eventFilter(self, obj, event):
return False
if isinstance(event, QCloseEvent) or isinstance(event, QHideEvent):
obj.hide()
self.hide()
return True
elif isinstance(event, QShowEvent):
self.show()
return QDockWidget.eventFilter(self, obj, event)


dockables = ["Properties", "Outline", "Layers", "Arrange Pages",
"Scrapbook", "Bookmarks", "Align and Distribute"]
docks = qApp.docks = {}

for tlw in qApp.topLevelWidgets():
if isinstance(tlw, QDialog):
title = str(tlw.windowTitle())
if i18n(title) in dockables:
docks[title] = DockDialog(tlw)


This is more a proof of concept and the code should not be used in production, of course. But you can see what is possible with a few lines. And it might be an inspiration how to improve the GUI of Scribus.

Keine Kommentare: