cola: Remove the 'cola.views' package
[git-cola.git] / cola / widgets / standard.py
bloba5805cc35368b7585f6262c85fa9056fcbb402e4
1 from PyQt4 import QtGui
4 def create_standard_widget(qtclass):
5 """Create a standard widget derived from a qt class.
6 """
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)
13 def show(self):
14 """Automatically centers dialogs"""
15 if self.parent():
16 left = self.parent().x()
17 width = self.parent().width()
18 center_x = left + width/2
20 x = center_x - self.width()/2
21 y = self.parent().y()
23 self.move(x, y)
24 # Call the base Qt show()
25 self._qtclass.show(self)
27 def name(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"""
33 try:
34 self.resize(state['width'], state['height'])
35 except:
36 pass
37 try:
38 self.move(state['x'], state['y'])
39 except:
40 pass
42 def export_state(self):
43 """Exports data for view save/restore"""
44 return {
45 'x': self.x(),
46 'y': self.y(),
47 'width': self.width(),
48 'height': self.height(),
51 return StandardWidget
54 # The base class for all cola QDialogs.
55 Dialog = create_standard_widget(QtGui.QDialog)
56 MainWindow = create_standard_widget(QtGui.QMainWindow)