More cleanup, render.py and pixmapdial.py seem ok
[cadence-nykeej.git] / src / pixmapdial.py
blob10d4cc520fc2949307af38a5fa4615c68872739f
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Imports (Global)
5 from PyQt4.QtCore import QRectF
6 from PyQt4.QtGui import QDial, QPainter, QPixmap
8 # Imports (Custom Stuff)
9 import icons_rc
11 # Custom Dial, using a pixmap for paiting
12 class PixmapDial(QDial):
13 def __init__(self, parent=None):
14 super(PixmapDial, self).__init__(parent)
16 self.p_width = 1
17 self.p_height = 1
18 self.p_count = 1
19 self.use_pixmap = True
20 self.setPixmap(1)
22 def setPixmap(self, n):
23 if (n < 1):
24 self.use_pixmap = False
25 else:
26 self.use_pixmap = True
28 if (n > 6):
29 n = 6
31 self.pixmap = QPixmap(":/bitmaps/dial_%i.png" % (n))
32 self.updateSizes()
34 def getSize(self):
35 return p_width
37 def updateSizes(self):
38 self.p_width = self.pixmap.width()
39 self.p_height = self.pixmap.height()
41 if (self.p_width < 1):
42 self.p_width = 1
44 if (self.p_height < 1):
45 self.p_height = 1
47 self.p_count = self.p_height/self.p_width
49 self.setMinimumSize(self.p_width, self.p_width)
50 self.setMaximumSize(self.p_width, self.p_width)
52 def paintEvent(self, event):
53 if (self.use_pixmap):
54 current = float(self.value()-self.minimum())
55 divider = float(self.maximum()-self.minimum())
57 if (divider == 0.0):
58 return
60 yper = int((self.p_count-1)*(current/divider))
61 ypos = self.p_width*yper
63 target = QRectF(0.0, 0.0, self.p_width, self.p_width)
64 source = QRectF(0.0, ypos, self.p_width, self.p_width)
66 painter = QPainter(self)
67 painter.drawPixmap(target, self.pixmap, source)
69 else:
70 return QDial.paintEvent(self, event)
72 def resizeEvent(self, event):
73 if (self.use_pixmap):
74 self.updateSizes()
76 return QDial.resizeEvent(self, event)