1 from PyQt4
import QtGui
4 def create_standard_widget(qtclass
):
5 """Create a standard widget derived from a qt class.
7 class StandardWidget(qtclass
):
8 # Mix-in for standard view operations
9 def __init__(self
, parent
=None):
10 self
._qtclass
= qtclass
11 self
._qtclass
.__init
__(self
, parent
)
14 """Automatically centers dialogs"""
16 left
= self
.parent().x()
17 width
= self
.parent().width()
18 center_x
= left
+ width
/2
20 x
= center_x
- self
.width()/2
24 # Call the base Qt show()
25 self
._qtclass
.show(self
)
28 """Returns the name of the view class"""
29 return self
.__class
__.__name
__.lower()
31 def apply_state(self
, state
):
32 """Imports data for view save/restore"""
34 self
.resize(state
['width'], state
['height'])
38 self
.move(state
['x'], state
['y'])
42 def export_state(self
):
43 """Exports data for view save/restore"""
47 'width': self
.width(),
48 'height': self
.height(),
54 # The base class for all cola QDialogs.
55 Dialog
= create_standard_widget(QtGui
.QDialog
)
56 MainWindow
= create_standard_widget(QtGui
.QMainWindow
)