text: #/usr/bin/python3
  
  from PyQt5 import QtGui
  from PyQt5 import QtCore
  from PyQt5 import QtWidgets
  
  from PyQt5.QtWidgets import *
  from PyQt5.QtGui import *
  from PyQt5.QtCore import *
  
  from .simpledebug import info
  from .canvas import Canvas
  
  class RotatableCanvas(Canvas):
  
      xRotationChanged = pyqtSignal(int)
      yRotationChanged = pyqtSignal(int)
      zRotationChanged = pyqtSignal(int)
  
      def __init__(self, parent=None, app=None, requestedGLVersion=(2,1)):
  
          super(RotatableCanvas, self).__init__(parent,app,requestedGLVersion)
  
          self.xRot = 0
          self.yRot = 180 * 16;
          self.zRot = 0
  
          self.lastPos = QPoint()
  
      def setXRotation(self, angle):
          angle = self.normalizeAngle(angle)
          if angle != self.xRot:
              self.xRot = angle
              self.xRotationChanged.emit(angle)
              self.update()
  
      def setYRotation(self, angle):
          angle = self.normalizeAngle(angle)
          if angle != self.yRot:
              self.yRot = angle
              self.yRotationChanged.emit(angle)
              self.update()
  
      def setZRotation(self, angle):
          angle = self.normalizeAngle(angle)
          if angle != self.zRot:
              self.zRot = angle
              self.zRotationChanged.emit(angle)
              self.update()
  
      def mousePressEvent(self, event):
          self.lastPos = event.pos()
  
      def mouseMoveEvent(self, event):
          dx = event.x() - self.lastPos.x()
          dy = event.y() - self.lastPos.y()
  
          if event.buttons() & Qt.LeftButton:
              self.setXRotation(self.xRot + 8 * dy)
              self.setYRotation(self.yRot + 8 * dx)
          elif event.buttons() & Qt.RightButton:
              self.setXRotation(self.xRot + 8 * dy)
              self.setZRotation(self.zRot + 8 * dx)
  
          self.lastPos = event.pos()
  
      def normalizeAngle(self, angle):
          while angle < 0:
              angle += 360 * 16
          while angle > 360 * 16:
              angle -= 360 * 16
          return angle
  
  
  