+class glRadioButton(glButton):
+ def __init__(self, parent, imageID, tooltip, pos, group, callback):
+ super(glRadioButton, self).__init__(parent, imageID, tooltip, pos, self._onRadioSelect)
+ self._group = group
+ self._radioCallback = callback
+ self._group.append(self)
+
+ def setSelected(self, value):
+ self._selected = value
+
+ def _onRadioSelect(self, button):
+ self._base._focus = None
+ for ctrl in self._group:
+ if ctrl != self:
+ ctrl.setSelected(False)
+ if self.getSelected():
+ self.setSelected(False)
+ else:
+ self.setSelected(True)
+ self._radioCallback(button)
+
+class glComboButton(glButton):
+ def __init__(self, parent, tooltip, imageIDs, tooltips, pos, callback):
+ super(glComboButton, self).__init__(parent, imageIDs[0], tooltip, pos, self._onComboOpenSelect)
+ self._imageIDs = imageIDs
+ self._tooltips = tooltips
+ self._comboCallback = callback
+ self._selection = 0
+
+ def _onComboOpenSelect(self, button):
+ if self.hasFocus():
+ self._base._focus = None
+ else:
+ self._base._focus = self
+
+ def draw(self):
+ if self._hidden:
+ return
+ self._selected = self.hasFocus()
+ super(glComboButton, self).draw()
+
+ bs = self._base._buttonSize / 2
+ pos = self._getPixelPos()
+
+ if not self._selected:
+ return
+
+ glPushMatrix()
+ glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
+ glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
+ for n in xrange(0, len(self._imageIDs)):
+ glTranslatef(0, bs, 0)
+ glColor4ub(255,255,255,255)
+ opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, 0)
+ opengl.glDrawTexturedQuad(-0.5*bs,-0.5*bs,bs,bs, self._imageIDs[n])
+ glDisable(GL_TEXTURE_2D)
+
+ glPushMatrix()
+ glTranslatef(-0.55*bs, 0.1*bs, 0)
+
+ glPushMatrix()
+ glColor4ub(60,60,60,255)
+ glTranslatef(-1, -1, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glTranslatef(0, 2, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glTranslatef(2, 0, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glTranslatef(0, -2, 0)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glPopMatrix()
+
+ glColor4ub(255,255,255,255)
+ opengl.glDrawStringRight(self._tooltips[n])
+ glPopMatrix()
+ glPopMatrix()
+
+ def getValue(self):
+ return self._selection
+
+ def setValue(self, value):
+ self._selection = value
+ self._imageID = self._imageIDs[self._selection]
+ self._comboCallback()
+
+ def OnMouseDown(self, x, y, button):
+ if self._hidden or self._disabled:
+ return False
+ if self.hasFocus():
+ bs = self._base._buttonSize / 2
+ pos = self._getPixelPos()
+ if 0 <= x - pos[0] <= bs and 0 <= y - pos[1] - bs <= bs * len(self._imageIDs):
+ self._selection = int((y - pos[1] - bs) / bs)
+ self._imageID = self._imageIDs[self._selection]
+ self._base._focus = None
+ self._comboCallback()
+ return True
+ return super(glComboButton, self).OnMouseDown(x, y, button)
+