Exemple #1
0
    def __init__(self, fmt: QSurfaceFormat, parent=None, *args, **kwargs):
        QOpenGLWidget.__init__(self, parent, *args, **kwargs)
        QOpenGLExtraFunctions.__init__(self, *args, **kwargs)
        self.width, self.height = 1280, 720

        self.program = QOpenGLShaderProgram()
        self.vbo = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)
        self.ebo = QOpenGLBuffer(QOpenGLBuffer.IndexBuffer)
        self.vao = QOpenGLVertexArrayObject()

        self.model_loc = None
        self.projection_loc = None
        self.camera_loc = None
        self.attrib_loc = None

        self.shape = Cube()
        self.models = []
        self.model = None
        self.projection = None

        self.camera = Camera()
        self.last_pos = QPoint(self.width / 2.0, self.height / 2.0)

        self.setFormat(fmt)
        self.context = QOpenGLContext(self)
        if not self.context.create():
            raise RuntimeError("Unable to create GL context")

        self.timer = QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(1000.0/FPS)
Exemple #2
0
    def __init__(self, parent=None):
        QOpenGLWidget.__init__(self, parent)
        QOpenGLFunctions.__init__(self)

        self.core = "--coreprofile" in QCoreApplication.arguments()
        self.xRot = 0
        self.yRot = 0
        self.zRot = 0
        self.lastPos = 0
        self.logo = Logo()
        self.vao = QOpenGLVertexArrayObject()
        self.logoVbo = QOpenGLBuffer()
        self.program = QOpenGLShaderProgram()
        self.projMatrixLoc = 0
        self.mvMatrixLoc = 0
        self.normalMatrixLoc = 0
        self.lightPosLoc = 0
        self.proj = QMatrix4x4()
        self.camera = QMatrix4x4()
        self.world = QMatrix4x4()
        self.transparent = "--transparent" in QCoreApplication.arguments()
        if self.transparent:
            fmt = self.format()
            fmt.setAlphaBufferSize(8)
            self.setFormat(fmt)
Exemple #3
0
 def __init__(self,
              scene,
              updateFpsDisplay,
              renderSettings=Rendersettings(),
              parent=None):
     View.__init__(self, scene)
     QOpenGLWidget.__init__(self, parent)
     self.renderImage = QImage()
     self.renderSettings = renderSettings
     self.updateFpsDisplay = updateFpsDisplay
     self.shaderProgram = QOpenGLShaderProgram()
     self.viewPortShaderProgram = QOpenGLShaderProgram()
     self.lightShaderProgram = QOpenGLShaderProgram()
     self.eyeLoc = QVector3D(0.0, 0.0, 5.0)
     self.pressLoc = QVector2D()
     self.isRendering = False
     self.viewportPlane = ViewportPlane()
     self.viewportTexture = None
     self.timer = QTimer()
     self.timer.setSingleShot(True)
     self.timer.timeout.connect(self.checkRender)
     self.scene.registerView(self, [
         UpdateType.MATERIAL_CHANGE, UpdateType.MATERIAL_CREATE,
         UpdateType.MATERIAL_DELETE, UpdateType.OBJECT_CREATE,
         UpdateType.OBJECT_DELETE, UpdateType.OBJECT_TRANSFORM,
         UpdateType.CAMERA_CHANGE, UpdateType.LIGHT_CHANGE,
         UpdateType.SCENE_LOAD
     ])
     self.timestamps = None
     self.fpsWindow = 10
     self.renderer = None
     self.renderStartTime = None
Exemple #4
0
    def __init__(self, parent=None):
        QOpenGLWidget.__init__(self, parent)
        QOpenGLFunctions.__init__(self)

        self.core = "--coreprofile" in QCoreApplication.arguments()
        self.xRot = 0
        self.yRot = 0
        self.zRot = 0
        self.lastPos = 0
        self.logo = Logo()
        self.vao = QOpenGLVertexArrayObject()
        self.logoVbo = QOpenGLBuffer()
        self.program = QOpenGLShaderProgram()
        self.projMatrixLoc = 0
        self.mvMatrixLoc = 0
        self.normalMatrixLoc = 0
        self.lightPosLoc = 0
        self.proj = QMatrix4x4()
        self.camera = QMatrix4x4()
        self.world = QMatrix4x4()
        self.transparent = "--transparent" in QCoreApplication.arguments()
        if self.transparent:
            fmt = self.format()
            fmt.setAlphaBufferSize(8)
            self.setFormat(fmt)
Exemple #5
0
    def __init__(self, parent=None):
        QOpenGLWidget.__init__(self, parent)
        QOpenGLFunctions.__init__(self)
        self.setMinimumSize(32, 32)

        self.info = ""
        self._supported_images = [
            "TGA", "PNG", "JPG", "JPEG", "TIF", "TIFF", "BMP", "DDS"
        ]

        # indices
        indices = [0, 1, 3, 1, 2, 3]
        self._indices = array('I', indices)

        # vertices
        # 3 position | 2 texture coord
        vertex = [
            1.0,
            1.0,
            0.0,
            1.0,
            1.0,  # top right
            1.0,
            -1.0,
            0.0,
            1.0,
            0.0,  # bottom right
            -1.0,
            -1.0,
            0.0,
            0.0,
            0.0,  # bottom left
            -1.0,
            1.0,
            0.0,
            0.0,
            1.0  # top left
        ]
        self._vertex = array('f', vertex)

        # opengl data related
        self._program = QOpenGLShaderProgram()
        self._program_bg = QOpenGLShaderProgram()
        self._vao = QOpenGLVertexArrayObject()
        self._vbo = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)
        self._texture = None
        self._texture_size = (1, 1)
        self._location = ()

        self._colors_default = (QColor.fromRgbF(0.65, 0.65, 0.65, 1.0),
                                QColor.fromRgbF(0.90, 0.90, 0.90, 1.0))
        self._u_colors = self._colors_default
        self._height = QVector4D(0, self.height(), 0, 0)

        self._u_channels = QMatrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
                                      0, 0)
Exemple #6
0
    def __init__(self, parent=None):
        "Constructor"
        QOpenGLWidget.__init__(self, parent)
        tutoTutoDir = os.path.dirname(__file__)
        tutoPardir = os.path.join(tutoTutoDir, os.pardir)
        tutoPardir = os.path.realpath(tutoPardir)
        mediaDir = os.path.join(tutoPardir, "media")
        shaderDir = os.path.join(mediaDir, "shaders")
        #
        availableShaders = ["rectangle", "triangle"]
        self.shaders = {
            name: {
                "fragment": os.path.join(shaderDir, name + ".frag"),
                "vertex": os.path.join(shaderDir, name + ".vert")
            }
            for name in availableShaders
        }
        self.core = "--coreprofile" in QCoreApplication.arguments()

        # opengl data related
        self.context = QOpenGLContext()
        self.program = QOpenGLShaderProgram()
        self.vao = QOpenGLVertexArrayObject()
        self.vbo = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)
        self.indices = np.array(
            [
                0,
                1,
                3,  # first triangle
                1,
                2,
                3  # second triangle
            ],
            dtype=ctypes.c_uint)

        # vertex data of the panel that would hold the image
        self.vertexData = np.array(
            [
                # viewport position || colors           ||   texture coords
                0.5,
                0.5,
                0.0,  # top right
                0.5,
                -0.5,
                0.0,  # bottom right
                -0.5,
                -0.5,
                0.0,  # bottom left
                -0.5,
                0.5,
                0.0,  # top left
            ],
            dtype=ctypes.c_float)

        self.rectColor = QVector4D(0.0, 1.0, 1.0, 0.0)
Exemple #7
0
 def __init__(self, parent=None):
     QOpenGLWidget.__init__(self, parent)
     self.gl_format = QSurfaceFormat()
     self.gl_format.setRenderableType(QSurfaceFormat.OpenGL)
     self.gl_format.setProfile(QSurfaceFormat.CoreProfile)
     self.gl_format.setVersion(4, 1)
     self.setFormat(self.gl_format)
     self.mouse_x = 0
     self.mouse_y = 0
     self.mouse_init = False
     self.mouse_pressed = False
Exemple #8
0
 def create_gl_widget():
     # QGLWidget Not currently available in pyside2.
     # It has actually been deprecated and we should use
     # QtGui.QGLFormat and other related classes instead.
     from PyQt5.QtWidgets import QOpenGLWidget
     from PyQt5.QtGui import QSurfaceFormat
     from PyQt5 import QtOpenGL
     QGLFormat = QtOpenGL.QGLFormat
     QGL = QtOpenGL.QGL
     open_gl_widget = QOpenGLWidget()
     fmt = QSurfaceFormat.defaultFormat()
     fmt.setSamples(8)
     open_gl_widget.setFormat(fmt)
     return open_gl_widget
    def __init__(self, parent=None):
        QOpenGLWidget.__init__(self, parent)

        # shaders etc
        triangleTutoDir = os.path.dirname(__file__)
        trianglePardir = os.path.join(triangleTutoDir, os.pardir)
        mediaDir = os.path.join(trianglePardir, "media")
        shaderDir = os.path.join(mediaDir, "shaders")
        availableShaders = ["triangle", "triangle2"]
        self.shaders = {
            name: {
                "fragment": os.path.join(shaderDir, name + ".frag"),
                "vertex": os.path.join(shaderDir, name + ".vert")
            } for name in availableShaders
        }
        self.core = "--coreprofile" in QCoreApplication.arguments()

        # opengl data related
        self.context = QOpenGLContext()
        self.vao1 = QOpenGLVertexArrayObject()
        self.vbo1 = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)
        self.vao2 = QOpenGLVertexArrayObject()
        self.vbo2 = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)

        self.program1 = QOpenGLShaderProgram()
        self.program2 = QOpenGLShaderProgram()

        # some vertex data for corners of triangle
        self.vertexData1 = np.array(
            [0.9, 0.9, 0.0,  # x, y, z
             0.9, 0.7, 0.0,  # x, y, z
             0.7, 0.9, 0.0],  # x, y, z
            dtype=ctypes.c_float
        )
        self.vertexData2 = np.array(
            [-0.9, -0.9, 0.0,  # x, y, z
             -0.9, -0.7, 0.0,  # x, y, z
             -0.7, -0.9, 0.0],  # x, y, z
            dtype=ctypes.c_float
        )
        # triangle color
        self.triangleColor1 = QVector4D(1.0, 0.0, 0.0, 0.0)  # yellow triangle
        self.triangleColor2 = QVector4D(
            0.0, 0.0, 0.5, 0.0)  # not yellow triangle
Exemple #10
0
 def use_OpenGL(self):
     """
     Use QOpenGLWidget as the viewer.
     """
     # use QOpenGLWidget instead of the deprecated QGLWidget to avoid
     # problems with Wayland.
     import Qt
     if Qt.IsPySide2:
         from PySide2.QtWidgets import QOpenGLWidget
     elif Qt.IsPyQt5:
         from PyQt5.QtWidgets import QOpenGLWidget
     self.setViewport(QOpenGLWidget())
    def __init__(self):
        super(WorldView, self).__init__()
        self.setupViewport(QOpenGLWidget())
        self._canvas = None
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self._drag = False

        self._start_x = -1
        self._start_y = -1
        self._last_x = -1
        self._last_y = -1
        self._mouse_direction = MD.NONE
        self._last_mouse_direction = MD.NONE
        self._erase = False
        self._paint = False
        self.setMouseTracking(True)
        self.setAttribute(Qt.WA_Hover)
Exemple #12
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui_main = Ui_MainWindow()
        self.ui_main.setupUi(self)
        self.setWindowTitle("Sweep Measure System (SMS)")

        self.ui_serial = Ui_SerialWindow()
        self.ui_serial.setupUi(
            self.ui_main.tabSerial
        )  # register the serial page into tabwidget.tabSerial
        self.ui_main.tabWidget.setCurrentIndex(0)

        # matplot setting
        self.fig = Figure(figsize=(8, 4.5), dpi=100)
        self.static_canvas = FigureCanvas(self.fig)
        self.static_canvas.setParent(self.ui_main.tabPlot)

        self.axes = self.fig.add_subplot(211)
        self.axes_dynamic = self.fig.add_subplot(212)

        data = [random.random() for i in range(25)]

        self.axes.plot(data, '-r', linewidth=2.0)
        self.static_canvas.draw()
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_figure)
        self.timer.start(20)
        # self.timer.stop()  # shutdown

        # serial settings
        self.ser = serial.Serial()
        self.Com_Dict = {}

        # counting
        self.data_bytes_sent = 0
        self.ui_serial.leSerialPortDataBytesSent.setText(
            str(self.data_bytes_sent))
        self.ui_serial.leSerialPortDataBytesSent.setEnabled(False)
        self.data_bytes_received = 0
        self.ui_serial.leSerialPortDataBytesReceived.setText(
            str(self.data_bytes_received))
        self.ui_serial.leSerialPortDataBytesReceived.setEnabled(False)

        # ui_serial serial default settings
        default_index = self.ui_serial.cbbSerialPortBaudrate.findText(
            "9600")  # baudrate
        if default_index == -1:
            self.ui_serial.cbbSerialPortBaudrate.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortBaudrate.setCurrentIndex(default_index)
        default_index = self.ui_serial.cbbSerialPortDatabit.findText(
            "8")  # Databit
        if default_index == -1:
            self.ui_serial.cbbSerialPortDatabit.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortDatabit.setCurrentIndex(default_index)
        default_index = self.ui_serial.cbbSerialPortParity.findText(
            "N")  # Parity
        if default_index == -1:
            self.ui_serial.cbbSerialPortParity.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortParity.setCurrentIndex(default_index)
        default_index = self.ui_serial.cbbSerialPortStopbit.findText(
            "1")  # Stopbit
        if default_index == -1:
            self.ui_serial.cbbSerialPortStopbit.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortStopbit.setCurrentIndex(default_index)

        self.ui_serial.btnSerialCLose.setEnabled(False)

        # Receive Timer
        self.receive_timer = QTimer(self)
        self.receive_timer.timeout.connect(self.receive_data)

        # ui_serial slot connection
        self.ui_serial.btnCheckSerialPort.clicked.connect(
            self.check_serial_port)
        self.ui_serial.btnSerialOpen.clicked.connect(self.open_serial_port)
        self.ui_serial.btnSerialCLose.clicked.connect(self.close_serial_port)
        self.ui_serial.btnSerialPortSend.clicked.connect(self.send_data)
        self.ui_serial.btnSerialPortSendClear.clicked.connect(
            self.clear_send_data)
        self.ui_serial.btnSerialPortReceiveClear.clicked.connect(
            self.clear_receive_data)

        # OpenGL setup
        self.openGL = QOpenGLWidget()
        self.openGL.setParent(self.ui_main.tabOpenGL)
        self.openGL.initializeGL = self.init_gl
        self.openGL.initializeGL()
        self.openGL.resizeGL(851, 651)
        self.openGL.paintGL = self.paint_gl
        self.update_times = 0

        self.timer_gl = QTimer()
        self.timer_gl.timeout.connect(self.openGL.update)
        self.timer_gl.start(20)

    def init_gl(self):
        gluPerspective(45, 851 / 651, 0.1, 50.0)
        gluLookAt(8.0, 8.0, 4.0, 0.0, 0.0, 0.0, -1, -1, 1)

    def paint_gl(self):
        glClear(GL_COLOR_BUFFER_BIT)
        line_length = 4
        cur_line_size = 5
        cube_length = 2.0
        glPushMatrix()
        glPushMatrix()
        glRotatef(self.update_times * 10, 0.0, 0.0, 1.0)

        glLineWidth(cur_line_size)
        glColor3f(1, 0, 0)
        glBegin(GL_LINES)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(line_length, 0.0, 0.0)
        glEnd()
        glColor3f(0, 1, 0)
        glBegin(GL_LINES)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(0.0, line_length, 0.0)
        glEnd()
        glColor3f(0, 0, 1)
        glBegin(GL_LINES)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(0.0, 0.0, line_length)
        glEnd()
        glPopMatrix()

        glTranslate(-0.5 * cube_length, -0.5 * cube_length, -0.5 * cube_length)
        glColor3f(1, 1, 0)
        glBegin(GL_QUAD_STRIP)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(0.0, cube_length, 0.0)
        glVertex3f(cube_length, 0.0, 0.0)
        glVertex3f(cube_length, cube_length, 0.0)
        glVertex3f(cube_length, 0.0, -cube_length)
        glVertex3f(cube_length, cube_length, -cube_length)
        glVertex3f(0.0, 0.0, -cube_length)
        glVertex3f(0.0, cube_length, -cube_length)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(0.0, cube_length, 0.0)
        glEnd()
        glBegin(GL_QUAD_STRIP)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(cube_length, 0.0, 0.0)
        glVertex3f(0.0, 0.0, -cube_length)
        glVertex3f(cube_length, 0.0, -cube_length)
        glVertex3f(0.0, cube_length, 0.0)
        glVertex3f(cube_length, cube_length, 0.0)
        glVertex3f(0.0, cube_length, -cube_length)
        glVertex3f(cube_length, cube_length, -cube_length)
        glEnd()
        glPopMatrix()
        self.update_times += 1

    def check_serial_port(self):
        # check virtual seiral port
        for port, desc, hwid in sorted(comports()):
            print("%s: %s [%s]" % (port, desc, hwid))
        port_list = list(sorted(comports()))
        self.ui_serial.cbbSerialPorts.clear()
        for port in port_list:
            self.Com_Dict["%s" % port[0]] = "%s" % port[1]
            # print(self.Com_Dict)
            self.ui_serial.cbbSerialPorts.addItem(port[0])
        if len(port_list) == 0:
            print("No serial port found")

    def open_serial_port(self):
        data_bits = {
            '5': serial.FIVEBITS,
            '6': serial.SIXBITS,
            '7': serial.SEVENBITS,
            '8': serial.EIGHTBITS
        }
        parity = {
            'N': serial.PARITY_NONE,
            'Odd': serial.PARITY_ODD,
            'Even': serial.PARITY_EVEN
        }
        stop_bits = {
            '1': serial.STOPBITS_ONE,
            '1.5': serial.STOPBITS_ONE_POINT_FIVE,
            '2': serial.STOPBITS_TWO
        }
        self.ser.port = self.ui_serial.cbbSerialPorts.currentText()
        self.ser.baudrate = int(
            self.ui_serial.cbbSerialPortBaudrate.currentText())
        self.ser.bytesize = data_bits[
            self.ui_serial.cbbSerialPortDatabit.currentText()]
        self.ser.parity = parity[
            self.ui_serial.cbbSerialPortParity.currentText()]
        self.ser.stopbits = stop_bits[
            self.ui_serial.cbbSerialPortStopbit.currentText()]
        print("Serial Port: {0} {1} {2} {3}".format(self.ser.port,
                                                    self.ser.baudrate,
                                                    self.ser.parity,
                                                    self.ser.stopbits))
        try:
            self.ser.open()
        except:
            QMessageBox.critical(self, "Port Error", "Cannot open this port")
        if self.ser.isOpen():
            self.receive_timer.start(100)
            print("{0} opened".format(self.ser.port))
            self.ui_serial.btnSerialOpen.setEnabled(False)
            self.ui_serial.btnSerialCLose.setEnabled(True)
        pass

    def close_serial_port(self):
        if self.ser.is_open:
            try:
                self.receive_timer.stop()
                self.ser.close()
                self.ui_serial.btnSerialOpen.setEnabled(True)
                self.ui_serial.btnSerialCLose.setEnabled(False)
                print("{0} closed".format(self.ser.port))
            except:
                pass

    def send_data(self):
        if self.ser.is_open:
            input_s = self.ui_serial.pteSerialPortInput.toPlainText()
            if input_s != '':
                if self.ui_serial.cbSerialPortSendHex.isChecked():
                    input_s = input_s.strip()
                    send_list = []
                    while input_s != '':
                        try:
                            num = int(input_s[0:2], 16)
                        except ValueError:
                            QMessageBox.critical(self, "Wrong Data",
                                                 "Please input Hex Number")
                            return None
                        input_s = input_s[2:].strip()
                        send_list.append(num)
                    input_s = bytes(send_list)
                else:
                    input_s = (input_s + "\n").encode('utf-8')
                num = self.ser.write(input_s)
                self.data_bytes_sent += num
                self.ui_serial.leSerialPortDataBytesSent.setText(
                    str(self.data_bytes_sent))

    def receive_data(self):
        if not self.ser.is_open:
            return
        try:
            num = self.ser.in_waiting
        except:
            self.ser.close()
            return
        if num > 0:
            data = self.ser.read(num)
            num = len(data)
            if self.ui_serial.cbSerialPortReceiveHex.isChecked():
                out_s = ''
                for i in range(len(data)):
                    out_s = out_s + '{:02X}'.format(data[i]) + ' '
                self.ui_serial.pteSerialPortReceive.insertPlainText(out_s)
            else:
                self.ui_serial.pteSerialPortReceive.insertPlainText(
                    data.decode('utf-8'))  # unicode
            text_cursor = self.ui_serial.pteSerialPortReceive.textCursor()
            text_cursor.movePosition(QTextCursor.EndOfLine)
            self.ui_serial.pteSerialPortReceive.setTextCursor(text_cursor)
            self.data_bytes_received += num
            self.ui_serial.leSerialPortDataBytesReceived.setText(
                str(self.data_bytes_received))
        else:
            pass

    def clear_send_data(self):
        self.ui_serial.pteSerialPortInput.setPlainText("")
        self.data_bytes_sent = 0
        self.ui_serial.leSerialPortDataBytesSent.setText(
            str(self.data_bytes_sent))

    def clear_receive_data(self):
        self.ui_serial.pteSerialPortReceive.setPlainText("")
        self.data_bytes_received = 0
        self.ui_serial.leSerialPortDataBytesReceived.setText(
            str(self.data_bytes_received))

    def update_figure(self):
        t = np.linspace(0, 10, 101)
        self.axes_dynamic.cla()
        self.axes_dynamic.plot(t, np.sin(t + time.time()), 'r', linewidth=2.0)
        self.static_canvas.draw()
Exemple #13
0
from PySide2.QtGui import *
from PySide2.QtWidgets import QApplication, QOpenGLWidget

from game import Game
from game_window import GameWindow

if __name__ == "__main__":
    app = QApplication([])
    palette = app.palette()
    color = QColor()
    palette.setColor(QPalette.Background, color.red())
    app.setPalette(palette)
    opengl_widget = QOpenGLWidget()
    game_widget = Game(opengl_widget)
    main_window = GameWindow(game_widget)

    exit(app.exec_())

Exemple #14
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui_main = Ui_MainWindow()
        self.ui_main.setupUi(self)
        self.setWindowTitle("Sweep Measure System (SMS)")

        self.ui_serial = Ui_SerialWindow()
        self.ui_serial.setupUi(
            self.ui_main.tabSerial
        )  # register the serial page into tabwidget.tabSerial
        self.ui_main.tabWidget.setCurrentIndex(0)

        # matplot setting
        self.fig = Figure(figsize=(8, 4.5), dpi=100)
        self.static_canvas = FigureCanvas(self.fig)
        self.static_canvas.setParent(self.ui_main.tabPlot)

        self.axes = self.fig.add_subplot(211)
        self.axes_dynamic = self.fig.add_subplot(212)

        data = [random.random() for i in range(25)]

        self.axes.plot(data, '-r', linewidth=2.0)
        self.static_canvas.draw()
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_figure)
        self.timer.start(20)
        # self.timer.stop()  # shutdown

        # serial settings
        self.ser = serial.Serial()
        self.Com_Dict = {}

        # counting
        self.data_bytes_sent = 0
        self.ui_serial.leSerialPortDataBytesSent.setText(
            str(self.data_bytes_sent))
        self.ui_serial.leSerialPortDataBytesSent.setEnabled(False)
        self.data_bytes_received = 0
        self.ui_serial.leSerialPortDataBytesReceived.setText(
            str(self.data_bytes_received))
        self.ui_serial.leSerialPortDataBytesReceived.setEnabled(False)

        # ui_serial serial default settings
        default_index = self.ui_serial.cbbSerialPortBaudrate.findText(
            "9600")  # baudrate
        if default_index == -1:
            self.ui_serial.cbbSerialPortBaudrate.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortBaudrate.setCurrentIndex(default_index)
        default_index = self.ui_serial.cbbSerialPortDatabit.findText(
            "8")  # Databit
        if default_index == -1:
            self.ui_serial.cbbSerialPortDatabit.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortDatabit.setCurrentIndex(default_index)
        default_index = self.ui_serial.cbbSerialPortParity.findText(
            "N")  # Parity
        if default_index == -1:
            self.ui_serial.cbbSerialPortParity.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortParity.setCurrentIndex(default_index)
        default_index = self.ui_serial.cbbSerialPortStopbit.findText(
            "1")  # Stopbit
        if default_index == -1:
            self.ui_serial.cbbSerialPortStopbit.setCurrentIndex(0)
        else:
            self.ui_serial.cbbSerialPortStopbit.setCurrentIndex(default_index)

        self.ui_serial.btnSerialCLose.setEnabled(False)

        # Receive Timer
        self.receive_timer = QTimer(self)
        self.receive_timer.timeout.connect(self.receive_data)

        # ui_serial slot connection
        self.ui_serial.btnCheckSerialPort.clicked.connect(
            self.check_serial_port)
        self.ui_serial.btnSerialOpen.clicked.connect(self.open_serial_port)
        self.ui_serial.btnSerialCLose.clicked.connect(self.close_serial_port)
        self.ui_serial.btnSerialPortSend.clicked.connect(self.send_data)
        self.ui_serial.btnSerialPortSendClear.clicked.connect(
            self.clear_send_data)
        self.ui_serial.btnSerialPortReceiveClear.clicked.connect(
            self.clear_receive_data)

        # OpenGL setup
        self.openGL = QOpenGLWidget()
        self.openGL.setParent(self.ui_main.tabOpenGL)
        self.openGL.initializeGL = self.init_gl
        self.openGL.initializeGL()
        self.openGL.resizeGL(851, 651)
        self.openGL.paintGL = self.paint_gl
        self.update_times = 0

        self.timer_gl = QTimer()
        self.timer_gl.timeout.connect(self.openGL.update)
        self.timer_gl.start(20)
        game_over("Você saiu da tela!")

    apples_counter -= 1
    timeout -= 1

    if (timeout == 0):
        game_over("O tempo acabou !")

    timeout_label.setText("Tempo restante: " + str(timeout))
    game_widget.update()


if __name__ == "__main__":

    app = QApplication([])
    opengl_widget = QOpenGLWidget()
    opengl_widget.setFocusPolicy(Qt.StrongFocus)
    game_widget = GameWidget(opengl_widget)
    score_label = QLabel()
    score_label.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
    score_label.setStyleSheet('color: white')
    timeout_label = QLabel()
    timeout_label.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
    timeout_label.setStyleSheet('color: white')
    main_window = MainWindow(game_widget, score_label, timeout_label)

    timer = QTimer()
    timer.timeout.connect(update_scene)
    timer.start(100 / game_speed)

    exit(app.exec_())
 def __init__(self):
     super(GalleryView, self).__init__()
     self.setupViewport(QOpenGLWidget())
     self._gallery = None
Exemple #17
0
 def use_OpenGL(self):
     self.setViewport(QOpenGLWidget())
Exemple #18
0
    def __init__(self, parent=None):
        QOpenGLWidget.__init__(self, parent)

        # camera
        self.camera = QtCamera()
        self.camera.position = QVector3D(0.0, 0.0, 3.0)
        self.camera.front = QVector3D(0.0, 0.0, -1.0)
        self.camera.up = QVector3D(0.0, 1.0, 0.0)
        self.camera.movementSensitivity = 0.05

        # shaders etc
        tutoTutoDir = os.path.dirname(__file__)
        tutoPardir = os.path.join(tutoTutoDir, os.pardir)
        tutoPardir = os.path.realpath(tutoPardir)
        mediaDir = os.path.join(tutoPardir, "media")
        shaderDir = os.path.join(mediaDir, "shaders")

        availableShaders = ["cube"]
        self.shaders = {
            name: {
                "fragment": os.path.join(shaderDir, name + ".frag"),
                "vertex": os.path.join(shaderDir, name + ".vert")
            }
            for name in availableShaders
        }
        self.core = "--coreprofile" in QCoreApplication.arguments()
        imdir = os.path.join(mediaDir, "images")
        imFName = "im"
        imageFile1 = os.path.join(imdir, imFName + "0.png")
        self.image1 = QImage(imageFile1).mirrored()
        imageFile2 = os.path.join(imdir, imFName + "1.png")
        self.image2 = QImage(imageFile2).mirrored()

        # opengl data related
        self.context = QOpenGLContext()
        self.vao = QOpenGLVertexArrayObject()
        self.vbo = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)
        self.program = QOpenGLShaderProgram()
        self.texture1 = None
        self.texture2 = None
        self.texUnit1 = 0
        self.texUnit2 = 1

        # vertex data
        self.cubeVertices = np.array(
            [
                # pos vec3 || texcoord vec2
                -0.5,
                -0.5,
                -0.5,
                0.0,
                0.0,
                0.5,
                -0.5,
                -0.5,
                1.0,
                0.0,
                0.5,
                0.5,
                -0.5,
                1.0,
                1.0,
                0.5,
                0.5,
                -0.5,
                1.0,
                1.0,
                -0.5,
                0.5,
                -0.5,
                0.0,
                1.0,
                -0.5,
                -0.5,
                -0.5,
                0.0,
                0.0,
                -0.5,
                -0.5,
                0.5,
                0.0,
                0.0,
                0.5,
                -0.5,
                0.5,
                1.0,
                0.0,
                0.5,
                0.5,
                0.5,
                1.0,
                1.0,
                0.5,
                0.5,
                0.5,
                1.0,
                1.0,
                -0.5,
                0.5,
                0.5,
                0.0,
                1.0,
                -0.5,
                -0.5,
                0.5,
                0.0,
                0.0,
                -0.5,
                0.5,
                0.5,
                1.0,
                0.0,
                -0.5,
                0.5,
                -0.5,
                1.0,
                1.0,
                -0.5,
                -0.5,
                -0.5,
                0.0,
                1.0,
                -0.5,
                -0.5,
                -0.5,
                0.0,
                1.0,
                -0.5,
                -0.5,
                0.5,
                0.0,
                0.0,
                -0.5,
                0.5,
                0.5,
                1.0,
                0.0,
                0.5,
                0.5,
                0.5,
                1.0,
                0.0,
                0.5,
                0.5,
                -0.5,
                1.0,
                1.0,
                0.5,
                -0.5,
                -0.5,
                0.0,
                1.0,
                0.5,
                -0.5,
                -0.5,
                0.0,
                1.0,
                0.5,
                -0.5,
                0.5,
                0.0,
                0.0,
                0.5,
                0.5,
                0.5,
                1.0,
                0.0,
                -0.5,
                -0.5,
                -0.5,
                0.0,
                1.0,
                0.5,
                -0.5,
                -0.5,
                1.0,
                1.0,
                0.5,
                -0.5,
                0.5,
                1.0,
                0.0,
                0.5,
                -0.5,
                0.5,
                1.0,
                0.0,
                -0.5,
                -0.5,
                0.5,
                0.0,
                0.0,
                -0.5,
                -0.5,
                -0.5,
                0.0,
                1.0,
                -0.5,
                0.5,
                -0.5,
                0.0,
                1.0,
                0.5,
                0.5,
                -0.5,
                1.0,
                1.0,
                0.5,
                0.5,
                0.5,
                1.0,
                0.0,
                0.5,
                0.5,
                0.5,
                1.0,
                0.0,
                -0.5,
                0.5,
                0.5,
                0.0,
                0.0,
                -0.5,
                0.5,
                -0.5,
                0.0,
                1.0
            ],
            dtype=ctypes.c_float)
        # cube worldSpace coordinates
        self.cubeCoords = [
            QVector3D(0.2, 1.1, -1.0),
            QVector3D(2.0, 5.0, -15.0),
            QVector3D(-1.5, -2.2, -2.5),
            QVector3D(-3.8, -2.0, -12.3),
            QVector3D(2.4, -0.4, -3.5),
            QVector3D(-1.7, 3.0, -7.5),
            QVector3D(1.3, -2.0, -2.5),
            QVector3D(1.5, 2.0, -2.5),
            QVector3D(1.5, 0.2, -1.5),
            QVector3D(-1.3, 1.0, -1.5)
        ]
        self.rotateVector = QVector3D(0.7, 0.2, 0.5)