示例#1
0
    def __init__(self):
        super(myform, self).__init__()
        #窗口
        self.setObjectName("Form")
        self.resize(900, 900)
        self.setWindowTitle(QtCore.QCoreApplication.translate("Form", "Form"))

        #直接引用自定义opengl类
        self.opengl_widget = GLWidget(self)

        #self.btn 打开文件
        self.btn = QtWidgets.QPushButton(self)
        self.btn.setGeometry(QtCore.QRect(710, 40, 75, 23))
        self.btn.setObjectName("pushButton")
        self.btn.setText("打开文件")
        self.btn.clicked.connect(self.getfile)

        #self.cb  选择材质
        self.cb = QtWidgets.QComboBox(self)
        self.cb.setGeometry(QtCore.QRect(710, 70, 100, 20))
        self.cb.addItems([
            '黄铜', '青铜', '亮青铜', '铬', '铜', '亮铜', '金', '亮金', '白蜡', '银', '亮银',
            '祖母绿', '碧玉', '黑曜石', '珍珠', '红宝石', '绿宝石', '黑塑料', '黑橡胶', '紫罗兰'
        ])
        self.cb.currentIndexChanged.connect(self.selectionChange)

        self.btn_image = QtWidgets.QPushButton(self)
        self.btn_image.setGeometry(QtCore.QRect(710, 100, 75, 23))
        self.btn_image.setObjectName("pushButton_image")
        self.btn_image.setText("截图")
        self.btn_image.clicked.connect(self.getimage)

        self.btn_rotate = QtWidgets.QPushButton(self)
        self.btn_rotate.setGeometry(QtCore.QRect(710, 360, 75, 23))
        self.btn_rotate.setObjectName("pushButton_rotate")
        self.btn_rotate.setText("旋转")
        self.btn_rotate.clicked.connect(self.rote)

        self.btn_rotate = QtWidgets.QPushButton(self)
        self.btn_rotate.setGeometry(QtCore.QRect(710, 390, 75, 23))
        self.btn_rotate.setObjectName("pushButton_translate")
        self.btn_rotate.setText("平移")
        self.btn_rotate.clicked.connect(self.translate)

        self.btn_rotate = QtWidgets.QPushButton(self)
        self.btn_rotate.setGeometry(QtCore.QRect(710, 430, 75, 23))
        self.btn_rotate.setObjectName("pushButton_rotate_camera")
        self.btn_rotate.setText("旋转相机")
        self.btn_rotate.clicked.connect(self.rotate_camera)
        self.isrotatecamera = False
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.ro)

        self.qlistwidget = QtWidgets.QListWidget(self)
        self.qlistwidget.setGeometry(QtCore.QRect(720, 140, 100, 200))
        self.qlistwidget.setObjectName('Object Name')
示例#2
0
    def __init__(self):
        super(Ui_Read_cli, self).__init__()

        self.setObjectName("Form")
        self.resize(950, 700)
        self.setWindowTitle(QtCore.QCoreApplication.translate("Form", "Form"))

        self.widget = GLWidget(self)
        self.widget.setGeometry(QtCore.QRect(0, 0, 650, 650))
        self.widget.setObjectName("widget")
        self.widget.setWindowTitle(
            QtCore.QCoreApplication.translate("Read_cli", "Form"))

        self.verticalSlider = QtWidgets.QSlider(self)
        self.verticalSlider.setGeometry(QtCore.QRect(680, 40, 19, 601))
        self.verticalSlider.setOrientation(QtCore.Qt.Vertical)
        self.verticalSlider.setObjectName("verticalSlider")

        self.pushButton = QtWidgets.QPushButton(self)
        self.pushButton.setGeometry(QtCore.QRect(750, 40, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton.setText(
            QtCore.QCoreApplication.translate("Read_cli", "导入"))

        self.pushButton_2 = QtWidgets.QPushButton(self)
        self.pushButton_2.setGeometry(QtCore.QRect(750, 80, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_2.setText(
            QtCore.QCoreApplication.translate("Read_cli", "删除"))

        self.listWidget = QtWidgets.QListWidget(self)
        self.listWidget.setGeometry(QtCore.QRect(720, 120, 190, 192))
        self.listWidget.setObjectName("listWidget")

        self.lineEdit = QtWidgets.QLineEdit(self)
        self.lineEdit.setGeometry(QtCore.QRect(670, 10, 41, 20))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit.setText('0')

        self.pushButton.clicked.connect(self.inputfile)
        self.pushButton_2.clicked.connect(self.delete)
        self.verticalSlider.valueChanged['int'].connect(self.redraw)
        self.verticalSlider_Max = 0
示例#3
0
    def __init__(self):
        QMainWindow.__init__(self)  # call the init for the parent class

        self.resize(500, 500)
        self.setWindowTitle('Simulator')

        self.init_and_run_simulator()

        # We use the following variables to get multiple key presses in single event
        # https://stackoverflow.com/questions/7176951/how-to-get-multiple-key-presses-in-single-event/10568233#10568233
        self.__keys_list = []
        self.__first_release = False
        self.glWidget = GLWidget(self)
        self.init_gui()

        self.__jaw_clench_state = 0

        timer = QtCore.QTimer(self)
        timer.setInterval(20)  # period, in milliseconds
        timer.timeout.connect(self.glWidget.updateGL)
        timer.start()
    def initialize_glview(self):
        # create GL view
        self._glview = MyGLWidget()
        self._glview.setAcceptDrops(True)

        # backup and replace original paint method
        # self.glView.paintGL is callbacked from QGLWidget
        self._glview.paintGL_original = self._glview.paintGL
        self._glview.paintGL = self.glview_paintGL

        # backup and replace original mouse release method
        self._glview.mouseReleaseEvent_original = self._glview.mouseReleaseEvent
        self._glview.mouseReleaseEvent = self.glview_mouseReleaseEvent

        # backup and replace original mouse release method
        self._glview.wheelEvent_original = self._glview.wheelEvent
        self._glview.wheelEvent = self.glview_wheelEvent

        # add GL view to widget layout
        # http://doc.qt.io/qt-4.8/qgridlayout.html
        self.layout().addWidget(self._glview, 1, 0, 1, 4)

        self.qimage = QImage(self.filename, 'JPEG')  # GL_TEXTURE_2D
示例#5
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)  # call the init for the parent class

        self.resize(500, 500)
        self.setWindowTitle('Simulator')

        self.init_and_run_simulator()

        # We use the following variables to get multiple key presses in single event
        # https://stackoverflow.com/questions/7176951/how-to-get-multiple-key-presses-in-single-event/10568233#10568233
        self.__keys_list = []
        self.__first_release = False
        self.glWidget = GLWidget(self)
        self.init_gui()

        self.__jaw_clench_state = 0

        timer = QtCore.QTimer(self)
        timer.setInterval(20)  # period, in milliseconds
        timer.timeout.connect(self.glWidget.updateGL)
        timer.start()

    def __init_create_movements_buttons(self):

        self.__W_push_button = QPushButton("'W'\nIncrease Pitch")
        self.__S_push_button = QPushButton("'S'\nDecrease Pitch")

        self.__D_push_button = QPushButton("'D'\nIncrease Yaw")
        self.__A_push_button = QPushButton("'A'\nDecrease Yaw")

        self.__E_push_button = QPushButton("'E'\nIncrease Roll")
        self.__Q_push_button = QPushButton("'Q'\nDecrease Roll")

        self.__J_push_button = QPushButton("'J'\nJaw Clench")

        self.__SPACE_BAR_push_button = QPushButton(
            "'Space Bar'\nReset to defaults")

        self.__movements_push_buttons = {
            QtCore.Qt.Key_W: self.__W_push_button,
            QtCore.Qt.Key_S: self.__S_push_button,
            QtCore.Qt.Key_A: self.__A_push_button,
            QtCore.Qt.Key_D: self.__D_push_button,
            QtCore.Qt.Key_E: self.__E_push_button,
            QtCore.Qt.Key_Q: self.__Q_push_button,
            QtCore.Qt.Key_J: self.__J_push_button,
            QtCore.Qt.Key_Space: self.__SPACE_BAR_push_button
        }

        keys_widget = QGroupBox("Control using keyboard keys:")

        keys_grid_layout = QGridLayout()
        keys_widget.setLayout(keys_grid_layout)

        keys_grid_layout.addWidget(self.__Q_push_button, 0, 0)
        keys_grid_layout.addWidget(self.__W_push_button, 0, 1)
        keys_grid_layout.addWidget(self.__E_push_button, 0, 2)
        keys_grid_layout.addWidget(self.__A_push_button, 1, 0)
        keys_grid_layout.addWidget(self.__S_push_button, 1, 1)
        keys_grid_layout.addWidget(self.__D_push_button, 1, 2)
        keys_grid_layout.addWidget(self.__J_push_button, 0, 3, 1, 1)
        keys_grid_layout.addWidget(self.__SPACE_BAR_push_button, 2, 0, 4, 4)

        self.__E_push_button.clicked.connect(self.__increase_roll)
        self.__Q_push_button.clicked.connect(self.__decrease_roll)
        self.__W_push_button.clicked.connect(self.__increase_pitch)
        self.__S_push_button.clicked.connect(self.__decrease_pitch)
        self.__D_push_button.clicked.connect(self.__increase_yaw)
        self.__A_push_button.clicked.connect(self.__decrease_yaw)
        self.__J_push_button.clicked.connect(self.__flex_jaw_clench)
        self.__SPACE_BAR_push_button.clicked.connect(self.__reset_view)

        return keys_widget

    def init_gui(self):
        central_widget = QWidget()
        gui_layout = QGridLayout()
        central_widget.setLayout(gui_layout)
        self.setCentralWidget(central_widget)

        x_widget = QWidget()
        x_layout = QHBoxLayout()
        x_layout.setContentsMargins(0, 0, 0, 0)
        x_widget.setLayout(x_layout)
        self.x_label = QLabel("Pitch 0.0")
        x_layout.addWidget(self.x_label)
        self.slider_x = QSlider(QtCore.Qt.Horizontal)
        x_layout.addWidget(self.slider_x)
        self.slider_x.valueChanged.connect(self.slider_x_valueChanged_handler)
        self.slider_x.setMinimum(-1800)
        self.slider_x.setMaximum(1800)
        self.slider_x.setSingleStep(1)

        y_widget = QWidget()
        y_layout = QHBoxLayout()
        y_layout.setContentsMargins(0, 0, 0, 0)
        y_widget.setLayout(y_layout)
        self.y_label = QLabel("Yaw 0.0")
        y_layout.addWidget(self.y_label)
        self.slider_y = QSlider(QtCore.Qt.Horizontal)
        y_layout.addWidget(self.slider_y)
        self.slider_y.valueChanged.connect(self.slider_y_valueChanged_handler)
        self.slider_y.setMinimum(-1800)
        self.slider_y.setMaximum(1800)
        self.slider_y.setSingleStep(1)

        z_widget = QWidget()
        z_layout = QHBoxLayout()
        z_layout.setContentsMargins(0, 0, 0, 0)
        z_widget.setLayout(z_layout)
        self.z_label = QLabel("Roll 0.0")
        z_layout.addWidget(self.z_label)
        self.slider_z = QSlider(QtCore.Qt.Horizontal)
        z_layout.addWidget(self.slider_z)
        self.slider_z.valueChanged.connect(self.slider_z_valueChanged_handler)
        self.slider_z.setMinimum(-1800)
        self.slider_z.setMaximum(1800)
        self.slider_z.setSingleStep(1)

        battery_widget = QWidget()
        battery_layout = QHBoxLayout()
        battery_layout.setContentsMargins(0, 0, 0, 0)
        battery_widget.setLayout(battery_layout)
        self.battery_label = QLabel("Battery Level 0")
        battery_layout.addWidget(self.battery_label)
        self.slider_battery = QSlider(QtCore.Qt.Horizontal)
        battery_layout.addWidget(self.slider_battery)
        self.slider_battery.valueChanged.connect(
            self.battery_valueChanged_handler)
        self.slider_battery.setMinimum(0)
        self.slider_battery.setValue(100)
        self.slider_battery.setMaximum(100)

        gui_layout.addWidget(self.glWidget, 0, 0, 10, 1)
        gui_layout.addWidget(z_widget, 11, 0, 1, 1)
        gui_layout.addWidget(x_widget, 12, 0, 1, 1)
        gui_layout.addWidget(y_widget, 13, 0, 1, 1)
        gui_layout.addWidget(battery_widget, 14, 0, 1, 1)

        keys_widget = self.__init_create_movements_buttons()
        gui_layout.addWidget(keys_widget, 16, 0, 1, 1)

    def slider_x_valueChanged_handler(self, val):
        float_val = val / 10
        self.glWidget.setRotX(float_val)
        self.x_label.setText(f"Pitch {float_val}")
        self.update_simulator()

    def slider_y_valueChanged_handler(self, val):
        float_val = val / 10
        self.glWidget.setRotY(float_val)
        self.y_label.setText(f"Yaw {float_val}")
        self.update_simulator()

    def slider_z_valueChanged_handler(self, val):
        float_val = val / 10
        self.glWidget.setRotZ(float_val)
        self.z_label.setText(f"Roll {float_val}")
        self.update_simulator()

    def battery_valueChanged_handler(self, val):
        self.battery_label.setText(f"Battery Level {val}")
        self.simulator.update_battery(val)

    def init_and_run_simulator(self):
        self.simulator = Simulator()
        self.simulator.start()

    def update_simulator(self):
        self.simulator.update_rpy(self.glWidget.getRotZ(),
                                  self.glWidget.getRotX(),
                                  self.glWidget.getRotY(),
                                  self.__jaw_clench_state)

    def cleanup(self):
        self.simulator.destroy()

    def closeEvent(self, event):
        print("closeEvent invoked")
        event.accept()
        self.simulator.destroy()

    def keyPressEvent(self, event):
        self.__first_release = True
        key = event.key()
        self.__keys_list.append(key)

        if key in self.__movements_push_buttons:
            corresponding_push_button_for_key = self.__movements_push_buttons[
                key]
            corresponding_push_button_for_key.setStyleSheet(
                "background-color : green")

    def keyReleaseEvent(self, event):
        if self.__first_release == True:
            self.__process_multi_keys()

        self.__first_release = False

        key = self.__keys_list[-1]

        if key in self.__movements_push_buttons:
            corresponding_push_button_for_key = self.__movements_push_buttons[
                key]
            corresponding_push_button_for_key.setStyleSheet(
                "background-color : None")

        del self.__keys_list[-1]

    def __increase_pitch(self):
        self.slider_x.setValue(self.slider_x.value() + 5)

    def __decrease_pitch(self):
        self.slider_x.setValue(self.slider_x.value() - 5)

    def __increase_yaw(self):
        self.slider_y.setValue(self.slider_y.value() + 5)

    def __decrease_yaw(self):
        self.slider_y.setValue(self.slider_y.value() - 5)

    def __increase_roll(self):
        self.slider_z.setValue(self.slider_z.value() + 10)

    def __decrease_roll(self):
        self.slider_z.setValue(self.slider_z.value() - 10)

    def __flex_jaw_clench(self):
        # here we toggle from 1 to 0, and from 0 to 1 each time user clicks JAW Clench
        print(f"Jaw clench detected {self.__jaw_clench_state}")
        self.__jaw_clench_state = 1 - self.__jaw_clench_state
        self.update_simulator()

    def __reset_view(self):
        print("Key Space was pressed .. Restoring defaults ...")
        self.slider_x.setValue(0)
        self.slider_y.setValue(0)
        self.slider_z.setValue(0)
        self.slider_battery.setValue(100)
        self.__jaw_clench_state = 0

    def __process_multi_keys(self):
        for key in self.__keys_list:
            if key == QtCore.Qt.Key_W:
                self.__W_push_button.click()
            elif key == QtCore.Qt.Key_S:
                self.__S_push_button.click()
            elif key == QtCore.Qt.Key_D:
                self.__D_push_button.click()
            elif key == QtCore.Qt.Key_A:
                self.__A_push_button.click()
            elif key == QtCore.Qt.Key_E:
                self.__E_push_button.click()
            elif key == QtCore.Qt.Key_Q:
                self.__Q_push_button.click()
            elif key == QtCore.Qt.Key_J:
                self.__J_push_button.click()
            elif key == QtCore.Qt.Key_Space:
                self.__SPACE_BAR_push_button.click()
示例#6
0
class myform(QtWidgets.QWidget):
    def __init__(self):
        super(myform, self).__init__()
        #窗口
        self.setObjectName("Form")
        self.resize(900, 900)
        self.setWindowTitle(QtCore.QCoreApplication.translate("Form", "Form"))

        #直接引用自定义opengl类
        self.opengl_widget = GLWidget(self)

        #self.btn 打开文件
        self.btn = QtWidgets.QPushButton(self)
        self.btn.setGeometry(QtCore.QRect(710, 40, 75, 23))
        self.btn.setObjectName("pushButton")
        self.btn.setText("打开文件")
        self.btn.clicked.connect(self.getfile)

        #self.cb  选择材质
        self.cb = QtWidgets.QComboBox(self)
        self.cb.setGeometry(QtCore.QRect(710, 70, 100, 20))
        self.cb.addItems([
            '黄铜', '青铜', '亮青铜', '铬', '铜', '亮铜', '金', '亮金', '白蜡', '银', '亮银',
            '祖母绿', '碧玉', '黑曜石', '珍珠', '红宝石', '绿宝石', '黑塑料', '黑橡胶', '紫罗兰'
        ])
        self.cb.currentIndexChanged.connect(self.selectionChange)

        self.btn_image = QtWidgets.QPushButton(self)
        self.btn_image.setGeometry(QtCore.QRect(710, 100, 75, 23))
        self.btn_image.setObjectName("pushButton_image")
        self.btn_image.setText("截图")
        self.btn_image.clicked.connect(self.getimage)

        self.btn_rotate = QtWidgets.QPushButton(self)
        self.btn_rotate.setGeometry(QtCore.QRect(710, 360, 75, 23))
        self.btn_rotate.setObjectName("pushButton_rotate")
        self.btn_rotate.setText("旋转")
        self.btn_rotate.clicked.connect(self.rote)

        self.btn_rotate = QtWidgets.QPushButton(self)
        self.btn_rotate.setGeometry(QtCore.QRect(710, 390, 75, 23))
        self.btn_rotate.setObjectName("pushButton_translate")
        self.btn_rotate.setText("平移")
        self.btn_rotate.clicked.connect(self.translate)

        self.btn_rotate = QtWidgets.QPushButton(self)
        self.btn_rotate.setGeometry(QtCore.QRect(710, 430, 75, 23))
        self.btn_rotate.setObjectName("pushButton_rotate_camera")
        self.btn_rotate.setText("旋转相机")
        self.btn_rotate.clicked.connect(self.rotate_camera)
        self.isrotatecamera = False
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.ro)

        self.qlistwidget = QtWidgets.QListWidget(self)
        self.qlistwidget.setGeometry(QtCore.QRect(720, 140, 100, 200))
        self.qlistwidget.setObjectName('Object Name')

    def getfile(self):
        dlg = QtWidgets.QFileDialog()
        f = dlg.getOpenFileName(self, 'Open File', '.', 'STL File (*.stl)')
        file = FileHandler().load_mesh(f[0])  #f[0]是路径,f[1]是类型
        data = array(file['mesh'], 'f')
        print(data)
        model.append({'material': Materials[0], 'data': data})
        self.qlistwidget.addItem(f[0].split('/')[-1].split('.')[0])
        self.qlistwidget.setCurrentItem(self.qlistwidget.item(0))
        self.opengl_widget.initdata(model)
        #print(data)
        self.opengl_widget.update()

    def selectionChange(self):
        print(self.cb.currentIndex())
        self.opengl_widget.model[self.qlistwidget.currentIndex().row(
        )]['material'] = Materials[self.cb.currentIndex()]
        self.opengl_widget.update()

    def getimage(self):
        #glutSwapBuffers()
        self.opengl_widget.geti()

    def rote(self):
        matrix.rotate(model[self.qlistwidget.currentIndex().row()]['data'], 45,
                      45, 45)
        self.opengl_widget.update()

    def translate(self):
        matrix.translate(model[self.qlistwidget.currentIndex().row()]['data'],
                         10, 0, 0)
        self.opengl_widget.update()

    def rotate_camera(self):
        if self.isrotatecamera == False:
            self.isrotatecamera = True
            self.timer.start(100)
        else:
            self.isrotatecamera = False
            self.timer.stop()

    def ro(self):
        self.opengl_widget.camera.Yaw(5)
        self.opengl_widget.light.lightpos = [
            -self.opengl_widget.camera.forwardDir.X,
            -self.opengl_widget.camera.forwardDir.Y,
            -self.opengl_widget.camera.forwardDir.Z, 0
        ]
        self.opengl_widget.update()
class ThetaViewWidget(QWidget):
    def __init__(self, plugin):
        super(ThetaViewWidget, self).__init__()
        rp = rospkg.RosPack()
        loadUi(
            os.path.join(rp.get_path('rqt_theta_viewer'), 'resource',
                         'ThetaViewerWidget.ui'), self)
        self.plugin = plugin
        self.events = ThetaViewEvents(self)

        self._pushButton_open.clicked.connect(self.events.open_FileDialog)
        self._pushButton_save.clicked.connect(self.events.save_FileDialog)
        self._pushButton_shutter.clicked.connect(
            self.events.shutter_clicked_event)

        self.initialize_vals()
        self.initialize_glview()
        self.initialize_timer()

    # ==============================================
    # rqt requires
    def save_settings(self, plugin_settings, instance_settings):
        view_matrix_string = repr(self._glview.get_view_matrix())
        instance_settings.set_value('view_matrix', view_matrix_string)

    def restore_settings(self, plugin_settings, instance_settings):
        view_matrix_string = instance_settings.value('view_matrix')
        try:
            view_matrix = eval(view_matrix_string)
        except Exception:
            view_matrix = None

        if view_matrix is not None:
            self._glview.set_view_matrix(view_matrix)
        else:
            self.set_default_view()

    def shutdown_plugin(self):
        pass

    # ==============================================
    # QGLWidget requires
    def set_default_view(self):
        self._glview.makeCurrent()
        self._glview.reset_view()
        self._glview.rotate((0, 0, 1), 45)
        self._glview.rotate((1, 0, 0), -45)
        self._glview.translate((0, 0, -200))

    def update_timeout(self):
        self._glview.makeCurrent()
        self._glview.updateGL()
        glRotated(45, 0, 0, 1)

    def glview_paintGL(self):
        self._glview.paintGL_original()

        # draw the axis, the plain and something
        gl_painter.draw_basic_objects()

        self.texture = self._glview.get_texture(self.qimage)
        gl_painter.map_texture_on_sphere(self.texture, self.sphere_radius, 30,
                                         30)

    def glview_mouseReleaseEvent(self, event):
        if event.button() == Qt.RightButton:
            menu = QMenu(self._glview)
            action = QAction(self._glview.tr("Reset view"), self._glview)
            menu.addAction(action)
            action.triggered.connect(self.set_default_view)
            menu.exec_(self._glview.mapToGlobal(event.pos()))

    def glview_wheelEvent(self, event):
        # only zoom when no mouse buttons are pressed, to prevent interference with other user interactions
        if event.buttons() == Qt.NoButton:
            d = float(event.delta()) / 200.0 * self._glview._radius
            # TODO: make the moving stop when going to the outside of the sphere
            self._glview.translate([0.0, 0.0, d])
            self._glview.updateGL()
            event.accept()

    # ==============================================
    # initialize
    def initialize_vals(self):
        self.position = (0.0, 0.0, 0.0)
        self.orientation = quaternion_about_axis(0.0, (1.0, 0.0, 0.0))
        self.topicName = None
        self.subscriber = None

        self.sphere_radius = 200
        self.qimage = None
        self.texture = None

        self.filename = None
        self.jpeg_data = None

    def initialize_glview(self):
        # create GL view
        self._glview = MyGLWidget()
        self._glview.setAcceptDrops(True)

        # backup and replace original paint method
        # self.glView.paintGL is callbacked from QGLWidget
        self._glview.paintGL_original = self._glview.paintGL
        self._glview.paintGL = self.glview_paintGL

        # backup and replace original mouse release method
        self._glview.mouseReleaseEvent_original = self._glview.mouseReleaseEvent
        self._glview.mouseReleaseEvent = self.glview_mouseReleaseEvent

        # backup and replace original mouse release method
        self._glview.wheelEvent_original = self._glview.wheelEvent
        self._glview.wheelEvent = self.glview_wheelEvent

        # add GL view to widget layout
        # http://doc.qt.io/qt-4.8/qgridlayout.html
        self.layout().addWidget(self._glview, 1, 0, 1, 4)

        self.qimage = QImage(self.filename, 'JPEG')  # GL_TEXTURE_2D
        # self.qimage = QImage('/home/matsunolab/Pictures/testimage_big.jpg', 'JPEG')  # GL_TEXTURE_2D

    def initialize_timer(self):
        # updateTimeout is called with interval time
        self.update_timer = QTimer(self)
        self.update_timer.timeout.connect(self.update_timeout)
        # init and start update timer with 40ms (25fps)
        self.update_timer.start(40)
示例#8
0
class Ui_Read_cli(QtWidgets.QWidget):
    def __init__(self):
        super(Ui_Read_cli, self).__init__()

        self.setObjectName("Form")
        self.resize(950, 700)
        self.setWindowTitle(QtCore.QCoreApplication.translate("Form", "Form"))

        self.widget = GLWidget(self)
        self.widget.setGeometry(QtCore.QRect(0, 0, 650, 650))
        self.widget.setObjectName("widget")
        self.widget.setWindowTitle(
            QtCore.QCoreApplication.translate("Read_cli", "Form"))

        self.verticalSlider = QtWidgets.QSlider(self)
        self.verticalSlider.setGeometry(QtCore.QRect(680, 40, 19, 601))
        self.verticalSlider.setOrientation(QtCore.Qt.Vertical)
        self.verticalSlider.setObjectName("verticalSlider")

        self.pushButton = QtWidgets.QPushButton(self)
        self.pushButton.setGeometry(QtCore.QRect(750, 40, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton.setText(
            QtCore.QCoreApplication.translate("Read_cli", "导入"))

        self.pushButton_2 = QtWidgets.QPushButton(self)
        self.pushButton_2.setGeometry(QtCore.QRect(750, 80, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_2.setText(
            QtCore.QCoreApplication.translate("Read_cli", "删除"))

        self.listWidget = QtWidgets.QListWidget(self)
        self.listWidget.setGeometry(QtCore.QRect(720, 120, 190, 192))
        self.listWidget.setObjectName("listWidget")

        self.lineEdit = QtWidgets.QLineEdit(self)
        self.lineEdit.setGeometry(QtCore.QRect(670, 10, 41, 20))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit.setText('0')

        self.pushButton.clicked.connect(self.inputfile)
        self.pushButton_2.clicked.connect(self.delete)
        self.verticalSlider.valueChanged['int'].connect(self.redraw)
        self.verticalSlider_Max = 0

    def inputfile(self):
        dialog = QtWidgets.QFileDialog()
        f = dialog.getOpenFileNames(self, 'Open File', './喷杆cli',
                                    'CLI File (*.cli)')[0]
        for fi in f:
            file = CLI(fi)
            self.widget.data.append(file.UsePoint)

            if self.verticalSlider_Max < file.layer:
                self.verticalSlider_Max = file.layer - 1
            self.verticalSlider.setMaximum(self.verticalSlider_Max)
            #print((f[0].split('/'))[-1].split('.')[0])
            self.listWidget.addItem((fi.split('/'))[-1].split('.')[0])
        self.widget.update()
        '''file=CLI(f[0])
        self.widget.data.append(file.UsePoint)
        self.widget.update()
        if self.verticalSlider_Max<file.layer:
            self.verticalSlider_Max=file.layer-1
        self.verticalSlider.setMaximum(self.verticalSlider_Max)
        self.listWidget.addItem((f[0].split('/'))[-1].split('.')[0])'''

    def redraw(self):
        self.lineEdit.setText(str(self.verticalSlider.value()))
        self.widget.layerindex = self.verticalSlider.value()
        self.widget.update()

    def delete(self):
        self.listWidget.clear()
        self.widget.data.clear()
        self.widget.update()