def initComponent(self): self.drawPanel = GLWidget(self) self.infoPanel = InfoWidget(self) self.controlPanel = ControlWidget(self) self.splitterPanel = SplitWidget(self) self.globalPanel = mylable(self) controlLayout = QVBoxLayout() controlLayout.addWidget(self.infoPanel) controlLayout.addWidget(self.controlPanel) # controlLayout.addWidget(self.globalPanel) controlLayout.addWidget(self.splitterPanel) subLayout = QVBoxLayout() subLayout.addWidget(self.globalPanel) mainLayout = QHBoxLayout() mainLayout.addWidget(self.drawPanel) mainLayout.addLayout(controlLayout) mainLayout.addWidget(self.globalPanel) mainWidget = QWidget() mainWidget.setLayout(mainLayout) # mainWidget.setLayout(subLayout) return mainWidget
def __init__(self): super(GLContainer, self).__init__() self.horizontalScrollBar().setSingleStep(10) self.horizontalScrollBar().setPageStep(100) self.horizontalScrollBar().setVisible(True) self.verticalScrollBar().setSingleStep(10) self.verticalScrollBar().setPageStep(100) self.verticalScrollBar().setVisible(True) self.horizontalScrollBar().valueChanged.connect(self.HScrollChanged) self.verticalScrollBar().valueChanged.connect(self.VScrollChanged) self.__glWidget = GLWidget() self.setViewport(self.__glWidget) self.setMouseTracking(True) self.__mousePressed = False self.__ctrlPressed = False self.__scrollMoved = False self.__xPrevF = 0.0 self.__yPrevF = 0.0 self.__prevZoomFactor = self.__glWidget.GetZoomFactor() self.__mousePos = QPointF(0, 0) QtCore.QCoreApplication.instance().aboutToQuit.connect( self.DeleteGLWidget) self.__justInitialized = True self.UpdateViewport(True)
def __init__(self, gadget=None, bufferOptions=set(), **kw): GLWidget.__init__(self, bufferOptions, **kw) self._qtWidget().setFocusPolicy(QtCore.Qt.ClickFocus) # Force the IECoreGL lazy loading to kick in /now/. Otherwise we can get IECoreGL objects # being returned from the GafferUIBindings without the appropriate boost::python converters # having been registered first. IECoreGL.Renderer self.__requestedDepthBuffer = self.BufferOptions.Depth in bufferOptions self.__enterConnection = self.enterSignal().connect( Gaffer.WeakMethod(self.__enter)) self.__leaveConnection = self.leaveSignal().connect( Gaffer.WeakMethod(self.__leave)) self.__keyPressConnection = self.keyPressSignal().connect( Gaffer.WeakMethod(self.__keyPress)) self.__keyReleaseConnection = self.keyReleaseSignal().connect( Gaffer.WeakMethod(self.__keyRelease)) self.__buttonPressConnection = self.buttonPressSignal().connect( Gaffer.WeakMethod(self.__buttonPress)) self.__buttonReleaseConnection = self.buttonReleaseSignal().connect( Gaffer.WeakMethod(self.__buttonRelease)) self.__buttonDoubleClickConnection = self.buttonDoubleClickSignal( ).connect(Gaffer.WeakMethod(self.__buttonDoubleClick)) self.__mouseMoveConnection = self.mouseMoveSignal().connect( Gaffer.WeakMethod(self.__mouseMove)) self.__dragBeginConnection = self.dragBeginSignal().connect( Gaffer.WeakMethod(self.__dragBegin)) self.__dragEnterConnection = self.dragEnterSignal().connect( Gaffer.WeakMethod(self.__dragEnter)) self.__dragMoveConnection = self.dragMoveSignal().connect( Gaffer.WeakMethod(self.__dragMove)) self.__dragLeaveConnection = self.dragLeaveSignal().connect( Gaffer.WeakMethod(self.__dragLeave)) self.__dropConnection = self.dropSignal().connect( Gaffer.WeakMethod(self.__drop)) self.__dragEndConnection = self.dragEndSignal().connect( Gaffer.WeakMethod(self.__dragEnd)) self.__wheelConnection = self.wheelSignal().connect( Gaffer.WeakMethod(self.__wheel)) self.__viewportGadget = None if isinstance(gadget, GafferUI.ViewportGadget): self.setViewportGadget(gadget) else: self.setViewportGadget(GafferUI.ViewportGadget(gadget)) self._qtWidget().installEventFilter(_eventFilter)
def __init__(self, face_renderer, parent=None, **kwargs): """ Creates a view of the specified partition using the supplied face renderer. face_renderer should be a cell handler suitable for passing to the iterate_cells routine. It is used to create the faces this RubikView will render. """ GLWidget.__init__(self, parent) self.partition = None self.face_renderer = None self.solid_faces = [] self.solid_face_list = DisplayList(self.draw_solid_faces) self.show_axis = False
def __init__(self): super(GLContainer, self).__init__() self.horizontalScrollBar().setSingleStep(10) self.horizontalScrollBar().setPageStep(100) self.horizontalScrollBar().setVisible(True) self.verticalScrollBar().setSingleStep(10) self.verticalScrollBar().setPageStep(100) self.verticalScrollBar().setVisible(True) self.horizontalScrollBar().valueChanged.connect(self.HScrollChanged) self.verticalScrollBar().valueChanged.connect(self.VScrollChanged) self.__glWidget = GLWidget() self.setViewport(self.__glWidget) self.setMouseTracking(True) self.__mousePressed = False self.__ctrlPressed = False self.__scrollMoved = False self.__xPrevF = 0.0 self.__yPrevF = 0.0 self.__prevZoomFactor = self.__glWidget.GetZoomFactor() self.__mousePos = QPointF(0, 0) QtCore.QCoreApplication.instance().aboutToQuit.connect(self.DeleteGLWidget) self.__justInitialized = True self.UpdateViewport(True)
def __init__(self): super(Window, self).__init__() self.setWindowTitle("offset surface visualization") self.last_dir = '.' # the last directory read from. mainFrame = QtGui.QFrame(self) self.scene = Scene() self.manip = OffsetManipulator() self.scene.context = self.manip self.glWidget = GLWidget(self.scene) mainLayout = QtGui.QVBoxLayout(mainFrame) mainLayout.addWidget(self.glWidget) mainLayout.setStretch(0, 1) fileMenu = self.menuBar().addMenu("File") open_obj = QtGui.QAction("Open &Obj", self, statusTip="Select OBJ file to load", triggered=self.spawnOpenFileDlg, shortcut="Ctrl+o") clear = QtGui.QAction("&Clear", self, statusTip="Clear the scene", triggered=self.clear, shortcut="Ctrl+x") fileMenu.addAction(open_obj) fileMenu.addAction(clear) viewMenu = self.menuBar().addMenu("View") toggle_cam_widget = QtGui.QAction( "Show Camera Movement Widgets", self, statusTip= "Control whether manipulation icons appear while the view is being manipulated", triggered=self.toggle_cam_widgets) toggle_cam_widget.setCheckable(True) toggle_cam_widget.setChecked(True) viewMenu.addAction(toggle_cam_widget) self.setCentralWidget(mainFrame)
def __init__(self): QMainWindow.__init__(self) Globals.glwidget = GLWidget(self) self.setCentralWidget(Globals.glwidget) Globals.glwidget.makeCurrent() if Globals.musicOn: print "Using music" Globals.mediaobject = Phonon.MediaObject(self) self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self) Phonon.createPath(Globals.mediaobject, self.audioOutput)
def __init__(self, gadget=None, bufferOptions=set(), cameraMode=CameraMode.Mode2D): GLWidget.__init__(self, bufferOptions) self.gtkWidget().add_events(gtk.gdk.BUTTON_PRESS_MASK) self.gtkWidget().add_events(gtk.gdk.BUTTON_RELEASE_MASK) self.gtkWidget().add_events(gtk.gdk.POINTER_MOTION_MASK) self.gtkWidget().add_events(gtk.gdk.KEY_PRESS_MASK) self.gtkWidget().add_events(gtk.gdk.KEY_RELEASE_MASK) self.gtkWidget().add_events(gtk.gdk.ENTER_NOTIFY_MASK) self.gtkWidget().set_flags(gtk.CAN_FOCUS) self.gtkWidget().connect("button_press_event", self.__buttonPress) self.gtkWidget().connect("button_release_event", self.__buttonRelease) self.gtkWidget().connect("motion_notify_event", self.__motion) self.gtkWidget().connect("key_press_event", self.__keyPress) self.gtkWidget().connect("configure_event", self.__configure) self.gtkWidget().connect("enter_notify_event", self.__enterNotify) self.gtkWidget().connect("scroll_event", self.__scroll) self.__camera = IECore.Camera() self.__cameraController = IECore.CameraController(self.__camera) self.__renderer = IECoreGL.Renderer() self.__renderer.setOption("gl:mode", IECore.StringData("deferred")) self.setCameraMode(cameraMode) self.setBackgroundColor(IECore.Color3f(0)) self.setGadget(gadget) self.__lastButtonPressGadget = None self.__dragDropEvent = None self.__cameraInMotion = False self.__baseState = IECoreGL.State(True)
def addWidgets(self):#dodanie widgetow do glownego okna #opengl self.qgl = GLWidget(self) self.ui.horizontalLayout.addWidget(self.qgl) #dodanie widgeta zajmujacego sie obsluga opengl do glownego okna #lista obiektow self.widgetlist = WidgetList() self.ui.horizontalLayout.addWidget(self.widgetlist) self.widgetlist.hide() #przyciski do recznego wprowadzania danych self.widgetxy = WidgetXY() self.ui.verticalLayoutDown.addWidget(self.widgetxy)
def __init__(self): super(MainWindow, self).__init__() self.ui = Ui_main_window() self.ui.setupUi(self) self.glGeometry = self.ui.opengl_widget.geometry() self.glObjectName = self.ui.opengl_widget.objectName() self.glWidget = GLWidget(self.ui.centralwidget) self.glWidget.setGeometry(self.glGeometry) self.glWidget.setObjectName(self.glObjectName) self.ui.box_button.clicked.connect( lambda: self.glWidget.setObject('box')) self.ui.sphere_button.clicked.connect( lambda: self.glWidget.setObject('sphere', r=1, step=100)) self.ui.pyramid_button.clicked.connect( lambda: self.glWidget.setObject('pyramid')) self.ui.thor_button.clicked.connect( lambda: self.glWidget.setObject('thor', ir=0.5, step=100)) self.ui.cylinder_button.clicked.connect( lambda: self.glWidget.setObject('cylinder', r=1, h=0.5, step=100)) self.ui.csg_button.clicked.connect( lambda: self.glWidget.setObject('csg', operation='a_or_b')) self.ui.reset_button.clicked.connect(self.glWidget.resetPosition) self.ui.mouse_wheel_check_box.clicked.connect( lambda: self.glWidget.setMouseWheelInvertion( self.ui.mouse_wheel_check_box.isChecked())) self.ui.mouse_wheel_slider.sliderReleased.connect( lambda: self.glWidget.setMouseWheelSensitivity(10 - ( self.ui.mouse_wheel_slider.value()) // 10)) self.ui.rotation_slider.sliderReleased.connect( lambda: self.glWidget.setRotationSensitivity(10 - ( self.ui.rotation_slider.value()) // 10)) self.ui.lighting_checkbox.clicked.connect( lambda: self.glWidget.setGLlighting(self.ui.lighting_checkbox. isChecked()))
class MainWindow: def __init__(self, fps, SceneManager): self.mainWindow = QMainWindow() self.quitButton = QPushButton('Quitter', self.mainWindow) self.quitButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.centralWidget = QWidget() self.centralWidget.setMinimumSize(640, 480) self.centralWidget.setWindowTitle('TIPE') self.mainWindow.setCentralWidget(self.centralWidget) self.label = QLabel('TIPE : Detection de collisions entre corps convexes', self.centralWidget) self.RenderWidget = GLWidget(self.centralWidget, fps, SceneManager) self.RenderWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.layout1 = QGridLayout(self.centralWidget) self.layout1.addWidget(self.RenderWidget,0 , 0, 1, 0) self.layout1.addWidget(self.label, 1, 0) self.layout1.addWidget(self.quitButton, 1, 1) self.quitButton.clicked.connect(self.quitter) def quitter(self): self.mainWindow.close()
class GLContainer(QAbstractScrollArea): """ Class GLContainer """ def __init__(self): super(GLContainer, self).__init__() self.horizontalScrollBar().setSingleStep(10) self.horizontalScrollBar().setPageStep(100) self.horizontalScrollBar().setVisible(True) self.verticalScrollBar().setSingleStep(10) self.verticalScrollBar().setPageStep(100) self.verticalScrollBar().setVisible(True) self.horizontalScrollBar().valueChanged.connect(self.HScrollChanged) self.verticalScrollBar().valueChanged.connect(self.VScrollChanged) self.__glWidget = GLWidget() self.setViewport(self.__glWidget) self.setMouseTracking(True) self.__mousePressed = False self.__ctrlPressed = False self.__scrollMoved = False self.__xPrevF = 0.0 self.__yPrevF = 0.0 self.__prevZoomFactor = self.__glWidget.GetZoomFactor() self.__mousePos = QPointF(0, 0) QtCore.QCoreApplication.instance().aboutToQuit.connect( self.DeleteGLWidget) self.__justInitialized = True self.UpdateViewport(True) def HScrollChanged(self, val): self.__xPrevF = float(val) self.__glWidget.SetHorizontalScroll(val) self.__scrollMoved = True def VScrollChanged(self, val): self.__yPrevF = float(val) self.__glWidget.SetVerticalScroll(val) self.__scrollMoved = True def UpdateViewport(self, putInMiddle=False): """ leftRange = 0 rightRange = 0 upRange = 0 downRange = 0 hPos = 0 vPos = 0 """ barSize = QSize(self.width() - 20, self.height() - 20) zoomFactor = self.__glWidget.GetZoomFactor() imgSize = self.__glWidget.GetImageSize() img_width = float(imgSize.width() * zoomFactor) img_height = float(imgSize.height() * zoomFactor) if (img_width == 0 or img_height == 0): print "duh" img_width = 100 * zoomFactor img_height = 100 * zoomFactor xSPos = 0 ySPos = 0 if not putInMiddle: xNormPos = float(self.__mousePos.x()) + self.__xPrevF yNormPos = float(self.__mousePos.y()) + self.__yPrevF xNormPos /= self.__prevZoomFactor yNormPos /= self.__prevZoomFactor xRev = float(xNormPos) * zoomFactor yRev = float(yNormPos) * zoomFactor xSPos = xRev - float(self.__mousePos.x()) ySPos = yRev - float(self.__mousePos.y()) xGap = np.abs(barSize.width() - img_width) yGap = np.abs(barSize.height() - img_height) if (img_width <= barSize.width()): if (putInMiddle): hPos = -xGap * 0.5 else: hPos = xSPos leftRange = -img_width - xGap rightRange = img_width else: if (putInMiddle): hPos = xGap * 0.5 else: hPos = xSPos leftRange = -img_width + xGap rightRange = img_width if (img_height <= barSize.height()): if (putInMiddle): vPos = -yGap * 0.5 else: vPos = ySPos upRange = -img_height - yGap downRange = img_height else: if (putInMiddle): vPos = yGap * 0.5 else: vPos = ySPos upRange = -img_height + yGap downRange = img_height self.__xPrevF = hPos self.__yPrevF = vPos self.horizontalScrollBar().setRange(leftRange, rightRange) self.verticalScrollBar().setRange(upRange, downRange) self.horizontalScrollBar().setSliderPosition(hPos) self.verticalScrollBar().setSliderPosition(vPos) def setScrolls(self): """ Currently not being used... """ self.horizontalScrollBar().setVisible(True) self.verticalScrollBar().setVisible(True) self.__prevZoomFactor = 1.0 # nasty code here... shouldZoom = True while (shouldZoom): w = self.width() h = self.height() imgSize = self.__glWidget.GetImageSize() if (imgSize.width() == 0 or imgSize.height() == 0): imgSize = QSize(100, 100) zoomFactor = self.__glWidget.GetZoomFactor() if (w < imgSize.width() * zoomFactor or h < imgSize.height() * zoomFactor): self.__glWidget.ZoomOut() else: shouldZoom = False self.UpdateViewport(True) def mousePressEvent(self, event): super(GLContainer, self).mousePressEvent(event) #pass def mouseMoveEvent(self, event): super(GLContainer, self).mouseMoveEvent(event) self.__mousePos.setX(event.x()) self.__mousePos.setY(event.y()) def mouseReleaseEvent(self, event): #pass super(GLContainer, self).mouseReleaseEvent(event) def wheelEvent(self, event): #super(GLContainer, self).wheelEvent(event) # don't uncomment !!! scrollDir = True if (event.delta() > 0) else False self.__prevZoomFactor = self.__glWidget.GetZoomFactor() if (scrollDir): self.__glWidget.ZoomOut() else: self.__glWidget.ZoomIn() # update scrollbars self.UpdateViewport() def keyPressEvent(self, event): super(GLContainer, self).keyPressEvent(event) if (event.key() == Qt.Key_Control): #print "CRTL pressed" self.__ctrlPressed = True QApplication.setOverrideCursor(Qt.OpenHandCursor) #if (event.key() == Qt.Key_Right) # self.__glWidget.AddSlice() #elif (event.key() == Qt.Key_Left): # self.__glWidget.RemoveSlice() self.__glWidget.updateGL() def keyReleaseEvent(self, event): super(GLContainer, self).keyReleaseEvent(event) if (event.key() == Qt.Key_Control): #print "CRTL released" self.__ctrlPressed = False QApplication.restoreOverrideCursor() def DeleteGLWidget(self): print "QUIT" self.__glWidget.setParent(None) del self.__glWidget def paintEvent(self, event): if (self.__justInitialized): self.UpdateViewport(True) self.__justInitialized = False self.__glWidget.updateGL()
class Window(QtGui.QMainWindow): def __init__(self): super(Window, self).__init__() self.setWindowTitle("offset surface visualization") self.last_dir = '.' # the last directory read from. mainFrame = QtGui.QFrame(self) self.scene = Scene() self.manip = OffsetManipulator() self.scene.context = self.manip self.glWidget = GLWidget(self.scene) mainLayout = QtGui.QVBoxLayout(mainFrame) mainLayout.addWidget(self.glWidget) mainLayout.setStretch(0, 1) fileMenu = self.menuBar().addMenu("File") open_obj = QtGui.QAction("Open &Obj", self, statusTip="Select OBJ file to load", triggered=self.spawnOpenFileDlg, shortcut="Ctrl+o") clear = QtGui.QAction("&Clear", self, statusTip="Clear the scene", triggered=self.clear, shortcut="Ctrl+x") fileMenu.addAction(open_obj) fileMenu.addAction(clear) viewMenu = self.menuBar().addMenu("View") toggle_cam_widget = QtGui.QAction( "Show Camera Movement Widgets", self, statusTip= "Control whether manipulation icons appear while the view is being manipulated", triggered=self.toggle_cam_widgets) toggle_cam_widget.setCheckable(True) toggle_cam_widget.setChecked(True) viewMenu.addAction(toggle_cam_widget) self.setCentralWidget(mainFrame) def clear(self): self.glWidget.clear_nodes() self.manip.clear_object() def toggle_cam_widgets(self, state): '''Toggles the display of camera control widgets on the camera control''' self.glWidget.toggle_cam_control_widget_display(state) def spawnOpenFileDlg(self): fileName = QtGui.QFileDialog.getOpenFileName(self, "Read OBJ file", self.last_dir, "OBJ files (*.obj)") if (fileName): self.clear() self.glWidget.addObjToScene(fileName, selectable=False) self.manip.set_object(self.scene.nodes[-1].drawable) path, fName = os.path.split(str(fileName)) self.last_dir = path
class GLContainer(QAbstractScrollArea): """ Class GLContainer """ def __init__(self): super(GLContainer, self).__init__() self.horizontalScrollBar().setSingleStep(10) self.horizontalScrollBar().setPageStep(100) self.horizontalScrollBar().setVisible(True) self.verticalScrollBar().setSingleStep(10) self.verticalScrollBar().setPageStep(100) self.verticalScrollBar().setVisible(True) self.horizontalScrollBar().valueChanged.connect(self.HScrollChanged) self.verticalScrollBar().valueChanged.connect(self.VScrollChanged) self.__glWidget = GLWidget() self.setViewport(self.__glWidget) self.setMouseTracking(True) self.__mousePressed = False self.__ctrlPressed = False self.__scrollMoved = False self.__xPrevF = 0.0 self.__yPrevF = 0.0 self.__prevZoomFactor = self.__glWidget.GetZoomFactor() self.__mousePos = QPointF(0, 0) QtCore.QCoreApplication.instance().aboutToQuit.connect(self.DeleteGLWidget) self.__justInitialized = True self.UpdateViewport(True) def HScrollChanged(self, val): self.__xPrevF = float(val) self.__glWidget.SetHorizontalScroll(val) self.__scrollMoved = True def VScrollChanged(self, val): self.__yPrevF = float(val) self.__glWidget.SetVerticalScroll(val) self.__scrollMoved = True def UpdateViewport(self, putInMiddle=False): """ leftRange = 0 rightRange = 0 upRange = 0 downRange = 0 hPos = 0 vPos = 0 """ barSize = QSize(self.width() - 20, self.height() - 20) zoomFactor = self.__glWidget.GetZoomFactor() imgSize = self.__glWidget.GetImageSize() img_width = float(imgSize.width() * zoomFactor) img_height = float(imgSize.height() * zoomFactor) if img_width == 0 or img_height == 0: print "duh" img_width = 100 * zoomFactor img_height = 100 * zoomFactor xSPos = 0 ySPos = 0 if not putInMiddle: xNormPos = float(self.__mousePos.x()) + self.__xPrevF yNormPos = float(self.__mousePos.y()) + self.__yPrevF xNormPos /= self.__prevZoomFactor yNormPos /= self.__prevZoomFactor xRev = float(xNormPos) * zoomFactor yRev = float(yNormPos) * zoomFactor xSPos = xRev - float(self.__mousePos.x()) ySPos = yRev - float(self.__mousePos.y()) xGap = np.abs(barSize.width() - img_width) yGap = np.abs(barSize.height() - img_height) if img_width <= barSize.width(): if putInMiddle: hPos = -xGap * 0.5 else: hPos = xSPos leftRange = -img_width - xGap rightRange = img_width else: if putInMiddle: hPos = xGap * 0.5 else: hPos = xSPos leftRange = -img_width + xGap rightRange = img_width if img_height <= barSize.height(): if putInMiddle: vPos = -yGap * 0.5 else: vPos = ySPos upRange = -img_height - yGap downRange = img_height else: if putInMiddle: vPos = yGap * 0.5 else: vPos = ySPos upRange = -img_height + yGap downRange = img_height self.__xPrevF = hPos self.__yPrevF = vPos self.horizontalScrollBar().setRange(leftRange, rightRange) self.verticalScrollBar().setRange(upRange, downRange) self.horizontalScrollBar().setSliderPosition(hPos) self.verticalScrollBar().setSliderPosition(vPos) def setScrolls(self): """ Currently not being used... """ self.horizontalScrollBar().setVisible(True) self.verticalScrollBar().setVisible(True) self.__prevZoomFactor = 1.0 # nasty code here... shouldZoom = True while shouldZoom: w = self.width() h = self.height() imgSize = self.__glWidget.GetImageSize() if imgSize.width() == 0 or imgSize.height() == 0: imgSize = QSize(100, 100) zoomFactor = self.__glWidget.GetZoomFactor() if w < imgSize.width() * zoomFactor or h < imgSize.height() * zoomFactor: self.__glWidget.ZoomOut() else: shouldZoom = False self.UpdateViewport(True) def mousePressEvent(self, event): super(GLContainer, self).mousePressEvent(event) # pass def mouseMoveEvent(self, event): super(GLContainer, self).mouseMoveEvent(event) self.__mousePos.setX(event.x()) self.__mousePos.setY(event.y()) def mouseReleaseEvent(self, event): # pass super(GLContainer, self).mouseReleaseEvent(event) def wheelEvent(self, event): # super(GLContainer, self).wheelEvent(event) # don't uncomment !!! scrollDir = True if (event.delta() > 0) else False self.__prevZoomFactor = self.__glWidget.GetZoomFactor() if scrollDir: self.__glWidget.ZoomOut() else: self.__glWidget.ZoomIn() # update scrollbars self.UpdateViewport() def keyPressEvent(self, event): super(GLContainer, self).keyPressEvent(event) if event.key() == Qt.Key_Control: # print "CRTL pressed" self.__ctrlPressed = True QApplication.setOverrideCursor(Qt.OpenHandCursor) # if (event.key() == Qt.Key_Right) # self.__glWidget.AddSlice() # elif (event.key() == Qt.Key_Left): # self.__glWidget.RemoveSlice() self.__glWidget.updateGL() def keyReleaseEvent(self, event): super(GLContainer, self).keyReleaseEvent(event) if event.key() == Qt.Key_Control: # print "CRTL released" self.__ctrlPressed = False QApplication.restoreOverrideCursor() def DeleteGLWidget(self): print "QUIT" self.__glWidget.setParent(None) del self.__glWidget def paintEvent(self, event): if self.__justInitialized: self.UpdateViewport(True) self.__justInitialized = False self.__glWidget.updateGL()
class BVHPlayerPy(QMainWindow): def __init__(self, pathCD): super().__init__() self.setMaximumSize(800, 500) self.pathCurrentDir = pathCD self.pathMotionFileDir = pathCD.rstrip(os.path.basename(pathCD)) self.setCentralWidget(self.initComponent()) menuBar = self.menuBar() menuBar.setNativeMenuBar(False) fileMenu = menuBar.addMenu("&File") loadAction = QAction("&Open...", self) loadAction.triggered.connect(self.loadFile) loadAction.setShortcut("Ctrl+l") fileMenu.addAction(loadAction) quitAction = QAction("&Quit...", self) quitAction.triggered.connect(self.quit) quitAction.setShortcut("Ctrl+q") fileMenu.addAction(quitAction) self.setMenuBar(menuBar) self.setWindowTitle("BVH Player") def initComponent(self): self.drawPanel = GLWidget(self) self.infoPanel = InfoWidget(self) self.controlPanel = ControlWidget(self) self.splitterPanel = SplitWidget(self) controlLayout = QVBoxLayout() controlLayout.addWidget(self.infoPanel) controlLayout.addWidget(self.controlPanel) controlLayout.addWidget(self.splitterPanel) mainLayout = QHBoxLayout() mainLayout.addWidget(self.drawPanel) mainLayout.addLayout(controlLayout) mainWidget = QWidget() mainWidget.setLayout(mainLayout) return mainWidget def quit(self): sys.exit() def loadFile(self): filePath = QFileDialog.getOpenFileName(self, "Choose Motion File...", self.pathMotionFileDir, "Biovision Hierarchy (*.bvh)") if filePath[0] == "": # print("Error: Motion file is not given") pass else: root, motion, frames, frameTime = BVH.readBVH(filePath[0]) self.pathMotionFileDir = os.path.dirname(filePath[0]) self.drawPanel.setMotion(root, motion, frames, frameTime) self.infoPanel.initInfo(os.path.basename(filePath[0]), frameTime, frames) self.controlPanel.setPlayMode(True) self.splitterPanel.setActive() self.splitterPanel.initMotionData(os.path.basename(filePath[0]), root, motion, frameTime) def keyPressEvent(self, event:QKeyEvent): if event.key() == Qt.Key_Escape: self.quit() elif event.key() == Qt.Key_S: if self.drawPanel.motion is not None: self.drawPanel.isPlaying = not self.drawPanel.isPlaying self.controlPanel.setPlayMode(self.drawPanel.isPlaying) elif event.key() == Qt.Key_F: self.drawPanel.fastRatio *= 2.0 elif event.key() == Qt.Key_D: self.drawPanel.fastRatio /= 2.0 elif event.key() == Qt.Key_Right: if self.drawPanel.frames is not None: self.drawPanel.frameCount += 1 if self.drawPanel.frameCount >= self.drawPanel.frames: self.drawPanel.frameCount = 0 elif event.key() == Qt.Key_Left: if self.drawPanel.frames is not None: self.drawPanel.frameCount -= 1 if self.drawPanel.frameCount < 0: self.drawPanel.frameCount = self.drawPanel.frames - 1 else: pass
def setupUi(self, glFormat, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1200, 900) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( MainWindow.sizePolicy().hasHeightForWidth()) MainWindow.setSizePolicy(sizePolicy) MainWindow.setMinimumSize(QtCore.QSize(0, 0)) MainWindow.setMaximumSize(QtCore.QSize(1920, 1080)) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setMinimumSize(QtCore.QSize(400, 300)) self.centralwidget.setMaximumSize(QtCore.QSize(1920, 1080)) self.centralwidget.setObjectName("centralwidget") self.gridLayout_3 = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout_3.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize) self.gridLayout_3.setObjectName("gridLayout_3") self.openGLWidget = GLWidget(glFormat, Robot, self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.openGLWidget.sizePolicy().hasHeightForWidth()) self.openGLWidget.setSizePolicy(sizePolicy) self.openGLWidget.setMinimumSize(QtCore.QSize(400, 300)) self.openGLWidget.setMaximumSize(QtCore.QSize(1920, 1080)) self.openGLWidget.setMouseTracking(True) self.openGLWidget.setObjectName("openGLWidget") self.gridLayout_3.addWidget(self.openGLWidget, 0, 0, 1, 1) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setSizeConstraint( QtWidgets.QLayout.SetDefaultConstraint) self.horizontalLayout.setObjectName("horizontalLayout") self.gridLayout_2 = QtWidgets.QGridLayout() self.gridLayout_2.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) self.gridLayout_2.setObjectName("gridLayout_2") self.append_button = QtWidgets.QPushButton(self.centralwidget) self.append_button.setMaximumSize(QtCore.QSize(80, 40)) self.append_button.setFlat(False) self.append_button.setObjectName("append_button") self.gridLayout_2.addWidget(self.append_button, 0, 0, 1, 1) self.remove_button = QtWidgets.QPushButton(self.centralwidget) self.remove_button.setMaximumSize(QtCore.QSize(80, 40)) self.remove_button.setObjectName("remove_button") self.gridLayout_2.addWidget(self.remove_button, 1, 1, 1, 1) self.menu_label = QtWidgets.QLabel(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.menu_label.sizePolicy().hasHeightForWidth()) self.menu_label.setSizePolicy(sizePolicy) self.menu_label.setObjectName("menu_label") self.gridLayout_2.addWidget(self.menu_label, 2, 0, 1, 1) self.joint_menu = QtWidgets.QComboBox(self.centralwidget) self.joint_menu.setMaximumSize(QtCore.QSize(40, 40)) self.joint_menu.setEditable(False) self.joint_menu.setObjectName("joint_menu") self.joint_menu.addItem("") self.gridLayout_2.addWidget(self.joint_menu, 2, 1, 1, 1) self.insert_button = QtWidgets.QPushButton(self.centralwidget) self.insert_button.setMaximumSize(QtCore.QSize(80, 40)) self.insert_button.setObjectName("insert_button") self.gridLayout_2.addWidget(self.insert_button, 1, 0, 1, 1) self.pop_button = QtWidgets.QPushButton(self.centralwidget) self.pop_button.setMaximumSize(QtCore.QSize(80, 40)) self.pop_button.setObjectName("pop_button") self.gridLayout_2.addWidget(self.pop_button, 0, 1, 1, 1) self.horizontalLayout.addLayout(self.gridLayout_2) self.gridLayout = QtWidgets.QGridLayout() self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) self.gridLayout.setObjectName("gridLayout") self.d_label = QtWidgets.QLabel(self.centralwidget) self.d_label.setMaximumSize(QtCore.QSize(40, 20)) self.d_label.setObjectName("d_label") self.gridLayout.addWidget(self.d_label, 0, 2, 1, 1) self.a_input = QtWidgets.QLineEdit(self.centralwidget) self.a_input.setMaximumSize(QtCore.QSize(40, 20)) self.a_input.setObjectName("a_input") self.gridLayout.addWidget(self.a_input, 1, 1, 1, 1) self.theta_label = QtWidgets.QLabel(self.centralwidget) self.theta_label.setMaximumSize(QtCore.QSize(40, 20)) self.theta_label.setObjectName("theta_label") self.gridLayout.addWidget(self.theta_label, 0, 3, 1, 1) self.d_input = QtWidgets.QLineEdit(self.centralwidget) self.d_input.setMaximumSize(QtCore.QSize(40, 20)) self.d_input.setObjectName("d_input") self.gridLayout.addWidget(self.d_input, 1, 2, 1, 1) self.theta_input = QtWidgets.QLineEdit(self.centralwidget) self.theta_input.setMaximumSize(QtCore.QSize(40, 20)) self.theta_input.setObjectName("theta_input") self.gridLayout.addWidget(self.theta_input, 1, 3, 1, 1) self.theta_var = QtWidgets.QCheckBox(self.centralwidget) self.theta_var.setMaximumSize(QtCore.QSize(40, 20)) self.theta_var.setObjectName("theta_var") self.gridLayout.addWidget(self.theta_var, 2, 3, 1, 1) self.a_label = QtWidgets.QLabel(self.centralwidget) self.a_label.setEnabled(True) self.a_label.setMaximumSize(QtCore.QSize(40, 20)) self.a_label.setObjectName("a_label") self.gridLayout.addWidget(self.a_label, 0, 1, 1, 1) self.d_var = QtWidgets.QCheckBox(self.centralwidget) self.d_var.setObjectName("d_var") self.gridLayout.addWidget(self.d_var, 2, 2, 1, 1) self.alpha_input = QtWidgets.QLineEdit(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.alpha_input.sizePolicy().hasHeightForWidth()) self.alpha_input.setSizePolicy(sizePolicy) self.alpha_input.setMaximumSize(QtCore.QSize(40, 20)) self.alpha_input.setObjectName("alpha_input") self.gridLayout.addWidget(self.alpha_input, 1, 0, 1, 1) self.alpha_label = QtWidgets.QLabel(self.centralwidget) self.alpha_label.setMaximumSize(QtCore.QSize(40, 20)) self.alpha_label.setObjectName("alpha_label") self.gridLayout.addWidget(self.alpha_label, 0, 0, 1, 1) self.horizontalLayout.addLayout(self.gridLayout) self.gridLayout_3.addLayout(self.horizontalLayout, 1, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.menu_label.setBuddy(self.joint_menu) self.d_label.setBuddy(self.d_input) self.theta_label.setBuddy(self.theta_input) self.a_label.setBuddy(self.a_input) self.alpha_label.setBuddy(self.alpha_input) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) MainWindow.setTabOrder(self.append_button, self.pop_button) MainWindow.setTabOrder(self.pop_button, self.insert_button) MainWindow.setTabOrder(self.insert_button, self.remove_button) MainWindow.setTabOrder(self.remove_button, self.joint_menu) MainWindow.setTabOrder(self.joint_menu, self.alpha_input) MainWindow.setTabOrder(self.alpha_input, self.a_input) MainWindow.setTabOrder(self.a_input, self.d_input) MainWindow.setTabOrder(self.d_input, self.d_var) MainWindow.setTabOrder(self.d_var, self.theta_input) MainWindow.setTabOrder(self.theta_input, self.theta_var) self.connect_all()
class Ui_MainWindow(object): def setupUi(self, glFormat, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1200, 900) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( MainWindow.sizePolicy().hasHeightForWidth()) MainWindow.setSizePolicy(sizePolicy) MainWindow.setMinimumSize(QtCore.QSize(0, 0)) MainWindow.setMaximumSize(QtCore.QSize(1920, 1080)) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setMinimumSize(QtCore.QSize(400, 300)) self.centralwidget.setMaximumSize(QtCore.QSize(1920, 1080)) self.centralwidget.setObjectName("centralwidget") self.gridLayout_3 = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout_3.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize) self.gridLayout_3.setObjectName("gridLayout_3") self.openGLWidget = GLWidget(glFormat, Robot, self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.openGLWidget.sizePolicy().hasHeightForWidth()) self.openGLWidget.setSizePolicy(sizePolicy) self.openGLWidget.setMinimumSize(QtCore.QSize(400, 300)) self.openGLWidget.setMaximumSize(QtCore.QSize(1920, 1080)) self.openGLWidget.setMouseTracking(True) self.openGLWidget.setObjectName("openGLWidget") self.gridLayout_3.addWidget(self.openGLWidget, 0, 0, 1, 1) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setSizeConstraint( QtWidgets.QLayout.SetDefaultConstraint) self.horizontalLayout.setObjectName("horizontalLayout") self.gridLayout_2 = QtWidgets.QGridLayout() self.gridLayout_2.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) self.gridLayout_2.setObjectName("gridLayout_2") self.append_button = QtWidgets.QPushButton(self.centralwidget) self.append_button.setMaximumSize(QtCore.QSize(80, 40)) self.append_button.setFlat(False) self.append_button.setObjectName("append_button") self.gridLayout_2.addWidget(self.append_button, 0, 0, 1, 1) self.remove_button = QtWidgets.QPushButton(self.centralwidget) self.remove_button.setMaximumSize(QtCore.QSize(80, 40)) self.remove_button.setObjectName("remove_button") self.gridLayout_2.addWidget(self.remove_button, 1, 1, 1, 1) self.menu_label = QtWidgets.QLabel(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.menu_label.sizePolicy().hasHeightForWidth()) self.menu_label.setSizePolicy(sizePolicy) self.menu_label.setObjectName("menu_label") self.gridLayout_2.addWidget(self.menu_label, 2, 0, 1, 1) self.joint_menu = QtWidgets.QComboBox(self.centralwidget) self.joint_menu.setMaximumSize(QtCore.QSize(40, 40)) self.joint_menu.setEditable(False) self.joint_menu.setObjectName("joint_menu") self.joint_menu.addItem("") self.gridLayout_2.addWidget(self.joint_menu, 2, 1, 1, 1) self.insert_button = QtWidgets.QPushButton(self.centralwidget) self.insert_button.setMaximumSize(QtCore.QSize(80, 40)) self.insert_button.setObjectName("insert_button") self.gridLayout_2.addWidget(self.insert_button, 1, 0, 1, 1) self.pop_button = QtWidgets.QPushButton(self.centralwidget) self.pop_button.setMaximumSize(QtCore.QSize(80, 40)) self.pop_button.setObjectName("pop_button") self.gridLayout_2.addWidget(self.pop_button, 0, 1, 1, 1) self.horizontalLayout.addLayout(self.gridLayout_2) self.gridLayout = QtWidgets.QGridLayout() self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) self.gridLayout.setObjectName("gridLayout") self.d_label = QtWidgets.QLabel(self.centralwidget) self.d_label.setMaximumSize(QtCore.QSize(40, 20)) self.d_label.setObjectName("d_label") self.gridLayout.addWidget(self.d_label, 0, 2, 1, 1) self.a_input = QtWidgets.QLineEdit(self.centralwidget) self.a_input.setMaximumSize(QtCore.QSize(40, 20)) self.a_input.setObjectName("a_input") self.gridLayout.addWidget(self.a_input, 1, 1, 1, 1) self.theta_label = QtWidgets.QLabel(self.centralwidget) self.theta_label.setMaximumSize(QtCore.QSize(40, 20)) self.theta_label.setObjectName("theta_label") self.gridLayout.addWidget(self.theta_label, 0, 3, 1, 1) self.d_input = QtWidgets.QLineEdit(self.centralwidget) self.d_input.setMaximumSize(QtCore.QSize(40, 20)) self.d_input.setObjectName("d_input") self.gridLayout.addWidget(self.d_input, 1, 2, 1, 1) self.theta_input = QtWidgets.QLineEdit(self.centralwidget) self.theta_input.setMaximumSize(QtCore.QSize(40, 20)) self.theta_input.setObjectName("theta_input") self.gridLayout.addWidget(self.theta_input, 1, 3, 1, 1) self.theta_var = QtWidgets.QCheckBox(self.centralwidget) self.theta_var.setMaximumSize(QtCore.QSize(40, 20)) self.theta_var.setObjectName("theta_var") self.gridLayout.addWidget(self.theta_var, 2, 3, 1, 1) self.a_label = QtWidgets.QLabel(self.centralwidget) self.a_label.setEnabled(True) self.a_label.setMaximumSize(QtCore.QSize(40, 20)) self.a_label.setObjectName("a_label") self.gridLayout.addWidget(self.a_label, 0, 1, 1, 1) self.d_var = QtWidgets.QCheckBox(self.centralwidget) self.d_var.setObjectName("d_var") self.gridLayout.addWidget(self.d_var, 2, 2, 1, 1) self.alpha_input = QtWidgets.QLineEdit(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.alpha_input.sizePolicy().hasHeightForWidth()) self.alpha_input.setSizePolicy(sizePolicy) self.alpha_input.setMaximumSize(QtCore.QSize(40, 20)) self.alpha_input.setObjectName("alpha_input") self.gridLayout.addWidget(self.alpha_input, 1, 0, 1, 1) self.alpha_label = QtWidgets.QLabel(self.centralwidget) self.alpha_label.setMaximumSize(QtCore.QSize(40, 20)) self.alpha_label.setObjectName("alpha_label") self.gridLayout.addWidget(self.alpha_label, 0, 0, 1, 1) self.horizontalLayout.addLayout(self.gridLayout) self.gridLayout_3.addLayout(self.horizontalLayout, 1, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.menu_label.setBuddy(self.joint_menu) self.d_label.setBuddy(self.d_input) self.theta_label.setBuddy(self.theta_input) self.a_label.setBuddy(self.a_input) self.alpha_label.setBuddy(self.alpha_input) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) MainWindow.setTabOrder(self.append_button, self.pop_button) MainWindow.setTabOrder(self.pop_button, self.insert_button) MainWindow.setTabOrder(self.insert_button, self.remove_button) MainWindow.setTabOrder(self.remove_button, self.joint_menu) MainWindow.setTabOrder(self.joint_menu, self.alpha_input) MainWindow.setTabOrder(self.alpha_input, self.a_input) MainWindow.setTabOrder(self.a_input, self.d_input) MainWindow.setTabOrder(self.d_input, self.d_var) MainWindow.setTabOrder(self.d_var, self.theta_input) MainWindow.setTabOrder(self.theta_input, self.theta_var) self.connect_all() def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "DH Modeler")) self.append_button.setText(_translate("MainWindow", "Append Joint")) self.remove_button.setText(_translate("MainWindow", "Remove Joint")) self.menu_label.setText( _translate( "MainWindow", "<html><head/><body><p align=\"right\">Current Joint</p></body></html>" )) self.joint_menu.setItemText(0, _translate("MainWindow", "1")) self.insert_button.setText(_translate("MainWindow", "Insert Joint")) self.pop_button.setText(_translate("MainWindow", "Pop Joint")) self.d_label.setText( _translate( "MainWindow", "<html><head/><body><p align=\"center\">d</p></body></html>")) self.a_input.setText(_translate("MainWindow", "0.0")) self.theta_label.setText( _translate( "MainWindow", "<html><head/><body><p align=\"center\">θ</p></body></html>" )) self.d_input.setText(_translate("MainWindow", "0.0\n")) self.theta_input.setText(_translate("MainWindow", "0.0\n")) self.theta_var.setText(_translate("MainWindow", "var")) self.a_label.setText( _translate( "MainWindow", "<html><head/><body><p align=\"center\">a</p></body></html>")) self.d_var.setText(_translate("MainWindow", "var")) self.alpha_input.setText(_translate("MainWindow", "0.0")) self.alpha_label.setText( _translate( "MainWindow", "<html><head/><body><p align=\"center\">α</p></body></html>")) # Following methods are not generated by QT def connect_all(self): self.append_button.clicked.connect(self.append_joint) self.insert_button.clicked.connect(self.insert_joint) self.pop_button.clicked.connect(self.pop_joint) self.remove_button.clicked.connect(self.remove_joint) self.joint_menu.currentIndexChanged.connect(self.switch_joint) self.alpha_input.editingFinished.connect(self.change_alpha) self.a_input.editingFinished.connect(self.change_a) self.d_input.editingFinished.connect(self.change_d) self.theta_input.editingFinished.connect(self.change_theta) self.d_var.clicked.connect(self.change_d_var) self.theta_var.clicked.connect(self.change_theta_var) def append_joint(self): if Robot.append_joint(): self.joint_menu.addItem(str(Robot.len - 1)) self.joint_menu.setCurrentIndex(Robot.len - 2) def insert_joint(self): if Robot.insert_joint(self.joint_menu.currentIndex()): self.joint_menu.addItem(str(Robot.len - 1)) self.joint_menu.setCurrentIndex(self.joint_menu.currentIndex() + 1) def pop_joint(self): if Robot.pop_joint(): self.joint_menu.removeItem(self.joint_menu.count() - 1) def remove_joint(self): if Robot.remove_joint(self.joint_menu.currentIndex()): self.joint_menu.removeItem(self.joint_menu.count() - 1) self.switch_joint() def switch_joint(self): i = self.joint_menu.currentIndex() self.alpha_input.setText(str(Robot.return_joint(i).alpha)) self.a_input.setText(str(Robot.return_joint(i).a)) self.d_input.setText(str(Robot.return_joint(i).d)) self.theta_input.setText(str(Robot.return_joint(i).theta)) self.d_var.setChecked(Robot.return_joint(i).d_var) self.theta_var.setChecked(Robot.return_joint(i).theta_var) def change_alpha(self): joint_num = self.joint_menu.currentIndex() joint = Robot.return_joint(joint_num) text = self.alpha_input.text() joint.alpha = float(text if text != "" else 0) Robot.update_joint(joint_num) self.openGLWidget.update() def change_a(self): joint_num = self.joint_menu.currentIndex() joint = Robot.return_joint(joint_num) text = self.a_input.text() joint.a = float(text if text != "" else 0) Robot.update_joint(joint_num) self.openGLWidget.update() def change_d(self): joint_num = self.joint_menu.currentIndex() joint = Robot.return_joint(joint_num) text = self.d_input.text() joint.d = float(text if text != "" else 0) Robot.update_joint(joint_num) self.openGLWidget.update() def change_theta(self): joint_num = self.joint_menu.currentIndex() joint = Robot.return_joint(joint_num) text = self.theta_input.text() joint.theta = float(text if text != "" else 0) Robot.update_joint(joint_num) self.openGLWidget.update() def change_d_var(self): d_on = self.d_var.isChecked() Robot.return_joint(self.joint_menu.currentIndex()).d_var = d_on if d_on: self.theta_var.setChecked(False) self.openGLWidget.update() def change_theta_var(self): theta_on = self.theta_var.isChecked() Robot.return_joint(self.joint_menu.currentIndex()).theta_var = theta_on if theta_on: self.d_var.setChecked(False) self.openGLWidget.update()
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.setWindowModality(QtCore.Qt.WindowModal) MainWindow.setFixedSize(1000, 600) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( MainWindow.sizePolicy().hasHeightForWidth()) MainWindow.setSizePolicy(sizePolicy) self.centralWidget = QtWidgets.QWidget(MainWindow) self.centralWidget.setObjectName("centralWidget") self.layoutWidget = QtWidgets.QWidget(self.centralWidget) self.layoutWidget.setGeometry(QtCore.QRect(0, 0, 1001, 411)) self.layoutWidget.setObjectName("layoutWidget") self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget) self.gridLayout.setContentsMargins(11, 11, 11, 11) self.gridLayout.setSpacing(6) self.gridLayout.setObjectName("gridLayout") spacerItem = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout.addItem(spacerItem, 0, 0, 1, 1) self.gridLayout_2 = QtWidgets.QGridLayout() self.gridLayout_2.setSpacing(6) self.gridLayout_2.setObjectName("gridLayout_2") self.sceneOpenGLWidget = GLWidget( self.layoutWidget, self.layoutWidget.frameGeometry().width(), self.layoutWidget.frameGeometry().height()) self.sceneOpenGLWidget.setEnabled(True) self.sceneOpenGLWidget.setObjectName("sceneOpenGLWidget") self.gridLayout_2.addWidget(self.sceneOpenGLWidget, 0, 1, 1, 1) spacerItem1 = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem1, 0, 0, 1, 1) spacerItem2 = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem2, 0, 2, 1, 1) self.gridLayout.addLayout(self.gridLayout_2, 1, 0, 1, 1) spacerItem3 = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout.addItem(spacerItem3, 2, 0, 1, 1) self.layoutWidget1 = QtWidgets.QWidget(self.centralWidget) self.layoutWidget1.setGeometry(QtCore.QRect(0, 410, 1001, 161)) self.layoutWidget1.setObjectName("layoutWidget1") self.gridLayout_3 = QtWidgets.QGridLayout(self.layoutWidget1) self.gridLayout_3.setContentsMargins(11, 11, 11, 11) self.gridLayout_3.setSpacing(6) self.gridLayout_3.setObjectName("gridLayout_3") spacerItem4 = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum) self.gridLayout_3.addItem(spacerItem4, 0, 0, 1, 1) self.gridLayout_4 = QtWidgets.QGridLayout() self.gridLayout_4.setSpacing(6) self.gridLayout_4.setObjectName("gridLayout_4") spacerItem5 = QtWidgets.QSpacerItem(20, 35, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_4.addItem(spacerItem5, 0, 0, 1, 1) self.graphObjectComboBox = QtWidgets.QComboBox(self.layoutWidget1) self.graphObjectComboBox.setObjectName("graphObjectComboBox") self.gridLayout_4.addWidget(self.graphObjectComboBox, 1, 0, 1, 1) self.graphObjectLabel = QtWidgets.QLabel(self.layoutWidget1) self.graphObjectLabel.setObjectName("graphObjectLabel") self.gridLayout_4.addWidget(self.graphObjectLabel, 2, 0, 1, 1) spacerItem6 = QtWidgets.QSpacerItem(20, 35, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_4.addItem(spacerItem6, 3, 0, 1, 1) self.gridLayout_3.addLayout(self.gridLayout_4, 0, 1, 1, 1) self.line_3 = QtWidgets.QFrame(self.layoutWidget1) self.line_3.setFrameShape(QtWidgets.QFrame.VLine) self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_3.setObjectName("line_3") self.gridLayout_3.addWidget(self.line_3, 0, 2, 1, 1) self.gridLayout_5 = QtWidgets.QGridLayout() self.gridLayout_5.setSpacing(6) self.gridLayout_5.setObjectName("gridLayout_5") self.objectXDial = QtWidgets.QDial(self.layoutWidget1) self.objectXDial.setObjectName("objectXDial") self.gridLayout_5.addWidget(self.objectXDial, 0, 0, 1, 1) self.objectXLabel = QtWidgets.QLabel(self.layoutWidget1) self.objectXLabel.setObjectName("objectXLabel") self.gridLayout_5.addWidget(self.objectXLabel, 1, 0, 1, 1) self.gridLayout_3.addLayout(self.gridLayout_5, 0, 3, 1, 1) self.gridLayout_6 = QtWidgets.QGridLayout() self.gridLayout_6.setSpacing(6) self.gridLayout_6.setObjectName("gridLayout_6") self.objectYDial = QtWidgets.QDial(self.layoutWidget1) self.objectYDial.setObjectName("objectYDial") self.gridLayout_6.addWidget(self.objectYDial, 0, 0, 1, 1) self.objectYLabel = QtWidgets.QLabel(self.layoutWidget1) self.objectYLabel.setObjectName("objectYLabel") self.gridLayout_6.addWidget(self.objectYLabel, 1, 0, 1, 1) self.gridLayout_3.addLayout(self.gridLayout_6, 0, 4, 1, 1) self.gridLayout_7 = QtWidgets.QGridLayout() self.gridLayout_7.setSpacing(6) self.gridLayout_7.setObjectName("gridLayout_7") self.objectZDial = QtWidgets.QDial(self.layoutWidget1) self.objectZDial.setObjectName("objectZDial") self.gridLayout_7.addWidget(self.objectZDial, 0, 0, 1, 1) self.objectZLabel = QtWidgets.QLabel(self.layoutWidget1) self.objectZLabel.setObjectName("objectZLabel") self.gridLayout_7.addWidget(self.objectZLabel, 1, 0, 1, 1) self.gridLayout_3.addLayout(self.gridLayout_7, 0, 5, 1, 1) self.line = QtWidgets.QFrame(self.layoutWidget1) self.line.setFrameShape(QtWidgets.QFrame.VLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.gridLayout_3.addWidget(self.line, 0, 6, 1, 1) self.gridLayout_8 = QtWidgets.QGridLayout() self.gridLayout_8.setSpacing(6) self.gridLayout_8.setObjectName("gridLayout_8") spacerItem7 = QtWidgets.QSpacerItem(20, 35, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_8.addItem(spacerItem7, 0, 0, 1, 1) self.hidePushButton = QtWidgets.QPushButton(self.layoutWidget1) self.hidePushButton.setObjectName("hidePushButton") self.gridLayout_8.addWidget(self.hidePushButton, 1, 0, 1, 1) self.modifyPushButton = QtWidgets.QPushButton(self.layoutWidget1) self.modifyPushButton.setObjectName("modifyPushButton") self.gridLayout_8.addWidget(self.modifyPushButton, 2, 0, 1, 1) spacerItem8 = QtWidgets.QSpacerItem(20, 35, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_8.addItem(spacerItem8, 3, 0, 1, 1) self.gridLayout_3.addLayout(self.gridLayout_8, 0, 7, 1, 1) self.line_2 = QtWidgets.QFrame(self.layoutWidget1) self.line_2.setFrameShape(QtWidgets.QFrame.VLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_2.setObjectName("line_2") self.gridLayout_3.addWidget(self.line_2, 0, 9, 1, 1) self.gridLayout_11 = QtWidgets.QGridLayout() self.gridLayout_11.setSpacing(6) self.gridLayout_11.setObjectName("gridLayout_11") self.gridLayout_12 = QtWidgets.QGridLayout() self.gridLayout_12.setSizeConstraint(QtWidgets.QLayout.SetFixedSize) self.gridLayout_12.setSpacing(6) self.gridLayout_12.setObjectName("gridLayout_12") spacerItem9 = QtWidgets.QSpacerItem(15, 35, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_12.addItem(spacerItem9, 2, 0, 1, 1) self.zoomVerticalSlider = QtWidgets.QSlider(self.layoutWidget1) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.zoomVerticalSlider.sizePolicy().hasHeightForWidth()) self.zoomVerticalSlider.setSizePolicy(sizePolicy) self.zoomVerticalSlider.setOrientation(QtCore.Qt.Vertical) self.zoomVerticalSlider.setObjectName("zoomVerticalSlider") self.gridLayout_12.addWidget(self.zoomVerticalSlider, 1, 0, 1, 1) spacerItem10 = QtWidgets.QSpacerItem(15, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_12.addItem(spacerItem10, 0, 0, 1, 1) spacerItem11 = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum) self.gridLayout_12.addItem(spacerItem11, 1, 1, 1, 1) self.gridLayout_11.addLayout(self.gridLayout_12, 0, 1, 1, 1) self.gridLayout_9 = QtWidgets.QGridLayout() self.gridLayout_9.setSpacing(6) self.gridLayout_9.setObjectName("gridLayout_9") self.povFieldLabel = QtWidgets.QLabel(self.layoutWidget1) self.povFieldLabel.setObjectName("povFieldLabel") self.gridLayout_9.addWidget(self.povFieldLabel, 6, 0, 1, 1) spacerItem12 = QtWidgets.QSpacerItem(20, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_9.addItem(spacerItem12, 0, 0, 1, 1) self.zoomLcdNumber = QtWidgets.QLCDNumber(self.layoutWidget1) self.zoomLcdNumber.setObjectName("zoomLcdNumber") self.gridLayout_9.addWidget(self.zoomLcdNumber, 1, 0, 1, 1) self.zoomLabel = QtWidgets.QLabel(self.layoutWidget1) self.zoomLabel.setObjectName("zoomLabel") self.gridLayout_9.addWidget(self.zoomLabel, 3, 0, 1, 1) spacerItem13 = QtWidgets.QSpacerItem(20, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_9.addItem(spacerItem13, 8, 0, 1, 1) self.povFieldLcdNumber = QtWidgets.QLCDNumber(self.layoutWidget1) self.povFieldLcdNumber.setObjectName("povFieldLcdNumber") self.gridLayout_9.addWidget(self.povFieldLcdNumber, 5, 0, 1, 1) self.povFieldHorizontalSlider = QtWidgets.QSlider(self.layoutWidget1) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.povFieldHorizontalSlider.sizePolicy().hasHeightForWidth()) self.povFieldHorizontalSlider.setSizePolicy(sizePolicy) self.povFieldHorizontalSlider.setOrientation(QtCore.Qt.Horizontal) self.povFieldHorizontalSlider.setObjectName("povFieldHorizontalSlider") self.gridLayout_9.addWidget(self.povFieldHorizontalSlider, 7, 0, 1, 1) spacerItem14 = QtWidgets.QSpacerItem(20, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.gridLayout_9.addItem(spacerItem14, 4, 0, 1, 1) self.gridLayout_10 = QtWidgets.QGridLayout() self.gridLayout_10.setSpacing(6) self.gridLayout_10.setObjectName("gridLayout_10") self.gridLayout_9.addLayout(self.gridLayout_10, 9, 0, 1, 1) self.gridLayout_11.addLayout(self.gridLayout_9, 0, 0, 1, 1) self.gridLayout_3.addLayout(self.gridLayout_11, 0, 10, 1, 1) MainWindow.setCentralWidget(self.centralWidget) self.menuBar = QtWidgets.QMenuBar(MainWindow) self.menuBar.setGeometry(QtCore.QRect(0, 0, 1000, 25)) self.menuBar.setObjectName("menuBar") self.menuFile = QtWidgets.QMenu(self.menuBar) self.menuFile.setObjectName("menuFile") self.menuLoad = QtWidgets.QMenu(self.menuFile) self.menuLoad.setObjectName("menuLoad") self.menuSave = QtWidgets.QMenu(self.menuFile) self.menuSave.setObjectName("menuSave") self.menuEdit = QtWidgets.QMenu(self.menuBar) self.menuEdit.setObjectName("menuEdit") self.menuTools = QtWidgets.QMenu(self.menuBar) self.menuTools.setObjectName("menuTools") self.menuHelp = QtWidgets.QMenu(self.menuBar) self.menuHelp.setObjectName("menuHelp") MainWindow.setMenuBar(self.menuBar) self.actionExit = QtWidgets.QAction(MainWindow) self.actionExit.setWhatsThis("") self.actionExit.setObjectName("actionExit") self.actionExit.setShortcut('Ctrl+Q') self.actionExit.triggered.connect(self.closeMainWindow) self.actionObject = QtWidgets.QAction(MainWindow) self.actionObject.setObjectName("actionObject") self.actionObject.setShortcut('Ctrl+O') self.actionObject.triggered.connect(self.openFileNamesDialog) self.actionModel = QtWidgets.QAction(MainWindow) self.actionModel.setObjectName("actionModel") self.actionObject_2 = QtWidgets.QAction(MainWindow) self.actionObject_2.setObjectName("actionObject_2") self.actionObject_2.setShortcut('Ctrl+S') self.actionObject_2.triggered.connect(self.saveFileDialog) self.actionModel_2 = QtWidgets.QAction(MainWindow) self.actionModel_2.setObjectName("actionModel_2") self.actionPredefined_Forms = QtWidgets.QAction(MainWindow) self.actionPredefined_Forms.setObjectName("actionPredefined_Forms") self.actionPredefined_Scenes = QtWidgets.QAction(MainWindow) self.actionPredefined_Scenes.setObjectName("actionPredefined_Scenes") self.actionObject_3 = QtWidgets.QAction(MainWindow) self.actionObject_3.setObjectName("actionObject_3") self.actionModel_3 = QtWidgets.QAction(MainWindow) self.actionModel_3.setObjectName("actionModel_3") self.actionScene_POV = QtWidgets.QAction(MainWindow) self.actionScene_POV.setObjectName("actionScene_POV") self.actionAbout = QtWidgets.QAction(MainWindow) self.actionAbout.setObjectName("actionAbout") self.menuLoad.addAction(self.actionObject) self.menuLoad.addAction(self.actionModel) self.menuSave.addAction(self.actionObject_2) self.menuSave.addAction(self.actionModel_2) self.menuFile.addAction(self.menuLoad.menuAction()) self.menuFile.addAction(self.menuSave.menuAction()) self.menuFile.addAction(self.actionExit) self.menuEdit.addAction(self.actionObject_3) self.menuEdit.addAction(self.actionModel_3) self.menuTools.addAction(self.actionPredefined_Forms) self.menuTools.addAction(self.actionPredefined_Scenes) self.menuHelp.addAction(self.actionAbout) self.menuBar.addAction(self.menuFile.menuAction()) self.menuBar.addAction(self.menuEdit.menuAction()) self.menuBar.addAction(self.menuTools.menuAction()) self.menuBar.addAction(self.menuHelp.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
class MainWindow(QtGui.QMainWindow): def __init__(self):#inicjalizacja klasy QtGui.QMainWindow.__init__(self) #inicjalizacji glownego ui ui = self.ui = Ui_MainWindow() self.ui.setupUi(self) self.show() self.addWidgets() #dodanie pozostalych widgetow self.connectSignals() #polaczenie sygnalow ze slotami self.flags() #stworzenie/ustawinie flag self.variables() #inicjalizacja zmiennych self.setToolTipsForAll() #ustawia wskazowki do wsyzstkich narzezi self.setWindowTitle("PyCAD") def addWidgets(self):#dodanie widgetow do glownego okna #opengl self.qgl = GLWidget(self) self.ui.horizontalLayout.addWidget(self.qgl) #dodanie widgeta zajmujacego sie obsluga opengl do glownego okna #lista obiektow self.widgetlist = WidgetList() self.ui.horizontalLayout.addWidget(self.widgetlist) self.widgetlist.hide() #przyciski do recznego wprowadzania danych self.widgetxy = WidgetXY() self.ui.verticalLayoutDown.addWidget(self.widgetxy) #self.widgetxy.hide() def flags(self): #flagi self.setMouseTracking(False) #wylaczenie sledzenia myszki w glownym oknie self.f_saved = True #czy plik zostal zapisany self.setAcceptDrops(True) def variables(self): #wykorzystywane zmienne self.markedobjects = [] #zaznaczone obiekty self.nrofconstobjt = 2 self.fname = "" #nazwa pliku self.zoom = 0.5 #o ile bedzie zmienial sie widok self.dxdy = 0.5 #o ile przesuwam scene przy uzyciu strzalek def connectSignals(self):#polaczenie sygnalow i slotow #sygnaly wyemitowane przez qgl przypisanego do jednego slota (nie ma potrzeby rozroznienia tych zdarzen w tym miejscu) self.qgl.s_mousepos.connect(self.qglMouse) #zmiana pozycji self.qgl.s_mousepress.connect(self.qglMouse) #klikniecie self.qgl.s_newobj.connect(self.addedObjWidgetList)#dodano nowy obiekt do listy self.qgl.s_filechanged.connect(self.FileNotSaved) self.qgl.s_zoomend.connect(self.zoomSignal) self.qgl.s_knowpoint.connect(self.knowpoint) #lista self.widgetlist.ui.pushButtonDown.clicked.connect(self.pushButtonDown) self.widgetlist.ui.pushButtonUp.clicked.connect(self.pushButtonUp) self.widgetlist.ui.pushButtonUsun.clicked.connect(self.pushButtonRemove) self.widgetlist.ui.listWidget.itemClicked.connect(self.clickWidgetList) self.widgetlist.ui.listWidget.itemSelectionChanged.connect(self.clickWidgetList) #Przyciski - niestety klasa QSignalMapper nie dziala wec zostaje to self.ui.pushButtonNarz0.clicked.connect(self.pushButtonNarz0) self.ui.pushButtonNarz1.clicked.connect(self.pushButtonNarz1) self.ui.pushButtonNarz2.clicked.connect(self.pushButtonNarz2) self.ui.pushButtonNarz3.clicked.connect(self.pushButtonNarz3) self.ui.pushButtonNarz4.clicked.connect(self.pushButtonNarz4) self.ui.pushButtonNarz5.clicked.connect(self.pushButtonNarz5) self.ui.pushButtonNarz6.clicked.connect(self.pushButtonNarz6) self.ui.pushButtonNarz7.clicked.connect(self.pushButtonNarz7) self.ui.pushButtonNarz8.clicked.connect(self.pushButtonNarz8) #menubar - plik self.ui.actionNowy.triggered.connect(self.newAction) #wcisniecie przycisku nowy self.ui.actionZakoncz.triggered.connect(self.closeEvent) #uwaga dwa razy wola zamkniecie self.ui.actionZapisz.triggered.connect(self.saveFile) #zapisanie self.ui.actionZapisz_jako.triggered.connect(self.saveFileAs) #zapisz jako self.ui.actionOtworz.triggered.connect(self.loadAction) #otwarcie pliku self.ui.actionZakoncz.triggered.connect(self.closeEvent) #wcisniecie przycisku nowy #menubar - edycja self.ui.actionCofnij.triggered.connect(self.menubarBack) self.qgl.s_previous.connect(self.signalMenubarBack) self.ui.actionPonow.triggered.connect(self.menubarForward) self.qgl.s_next.connect(self.signalMenubarNext) #menubar - widok self.ui.actionPowieksz.triggered.connect(self.ZoomInView) self.ui.actionPomniejsz.triggered.connect(self.ZoomOutView) self.ui.actionStandardowy.triggered.connect(self.defaultView) def setToolTipsForAll(self): #ustawia wskazowki do wszystkich narzedzi #--- Ui_MainWindow (glowne ui) ---# self.defaultToolTipStyleForButton(self.ui.pushButtonNarz0,"Zaznaczenie jednego obiektu") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz1,"Linia") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz2,"Linie laczace sie") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz3,"Tworzenie luku") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz4,"Lista obiektow") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz5,"Linia + kat - do wycofania") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz6,"Zaznaczenie wielu obiektow") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz7,"Strzalki (nie zaimplementowane)") self.defaultToolTipStyleForButton(self.ui.pushButtonNarz8,"Przesuwanie punktu") #------------ WIDGETLIST ------------# def markObjectsWidgetList(self): #zanaczenie listy obiektow for nr in self.markedobjects: self.qgl.setMarkedObj(nr) def unmarObjectsWidgetList(self):#odznaczenie listy obiektow for nr in self.markedobjects: self.qgl.setUnmarkedObj(nr) self.markedobjects = [] def addedObjWidgetList(self): #osbluga sygnalu o dodaniu nowego obiektu do sceny self.widgetlist.ui.listWidget.addItem(self.qgl.obj[-1].WhatAmILongTxt()) def clickWidgetList(self):#obsluga klikniecia na listWidget #odznaecznie obiekotw self.unmarObjectsWidgetList() #odczytanie ktory obiekt ma byc zaznaczony nr = self.widgetlist.ui.listWidget.currentIndex().row() nr = nr + self.nrofconstobjt self.markedobjects.append(nr) #zaznaczenie obiektow self.markObjectsWidgetList() def createWidgetList(self):#stworzenie calej listy od zera lengthobj = len(self.qgl.obj) if(lengthobj > self.nrofconstobjt): #cos wiecej niz osie X,Y self.widgetlist.ui.listWidget.clear() for i in range(self.nrofconstobjt,lengthobj): self.widgetlist.ui.listWidget.addItem(self.qgl.obj[i].WhatAmILongTxt()) #objekty sie przedstawia w odpowiednim formacie wystarczy je dodac do listy def pushButtonUp(self): #zmiana kolejnosci obiektow if(len(self.widgetlist.ui.listWidget.selectedItems()) != 0): #numer wybranej linii liczony od 0 nr = self.widgetlist.ui.listWidget.currentIndex().row() if(nr != 0): #zamiana w liscie item = self.widgetlist.ui.listWidget.item(nr-1).text() self.widgetlist.ui.listWidget.item(nr-1).setText(self.widgetlist.ui.listWidget.item(nr).text()) self.widgetlist.ui.listWidget.item(nr).setText(item) self.widgetlist.ui.listWidget.setCurrentItem(self.widgetlist.ui.listWidget.item(nr-1)) #zmiany na obiektach self.unmarObjectsWidgetList() nr = nr + self.nrofconstobjt self.qgl.swapObj(nr,nr-1) self.markedobjects.append(nr-1) self.markObjectsWidgetList() def pushButtonDown(self): #zmiana kolejnosci obiektow if(len(self.widgetlist.ui.listWidget.selectedItems()) != 0): nr = self.widgetlist.ui.listWidget.currentIndex().row() #numer wybranej linii liczony od 0 if(nr != (len(self.widgetlist.ui.listWidget)-1)): #zamiana w liscie item = self.widgetlist.ui.listWidget.item(nr+1).text() self.widgetlist.ui.listWidget.item(nr+1).setText(self.widgetlist.ui.listWidget.item(nr).text()) self.widgetlist.ui.listWidget.item(nr).setText(item) #zmiany na obiektach self.unmarObjectsWidgetList() nr = nr + self.nrofconstobjt self.qgl.swapObj(nr,nr+1) self.widgetlist.ui.listWidget.setCurrentItem(self.widgetlist.ui.listWidget.item(nr+1-self.nrofconstobjt)) def pushButtonRemove(self): #usuwa obiekty ze sceny if(len(self.widgetlist.ui.listWidget.selectedItems()) != 0): #odczytanie indeksu zaznaczonego obiektu na liscie nr = self.widgetlist.ui.listWidget.currentIndex().row() #numer wybranej linii liczony od 0 #usuniecie numeru z listy item = self.widgetlist.ui.listWidget.takeItem(nr) del item #usuniecie obiektu ze sceny self.qgl.removeObj(nr+self.nrofconstobjt) #usuniecie obiektu ze sceny #zaznaczenie kolejnego obiektu na liscie self.clickWidgetList() #odswezenie lsity self.createWidgetList() #------------ PRZYCISKI (TOOLS) ------------# #tool5 - linia + kat (moze bedzie do wycofania) #tool7 - strzalki informujace o poczatku i koncu wszystkich obiektow #tool8 - przesuwanie pkt def defaultToolTipStyleForButton(self,obj,txt): #domyslny styl wskazowek dla przyciskow html = "<font color ='purple'><b><i>" #styl htmlowy wskaozwki - otwarcie html = html + txt #wlozenie stylu txt do html html = html + "</i></b></font>" #styl htmlowy wskaozwki - zamkniecie obj.setToolTip(html) #ustawienie wskazowki wraz ze stworzonym stylem def pushButtonNarz0(self): #klikniecie na obiekt self.qgl.setTool(0) def pushButtonNarz1(self): #linia self.qgl.setTool(1) def pushButtonNarz2(self): #linia-linia self.qgl.setTool(2) def pushButtonNarz3(self): self.qgl.setTool(3) def pushButtonNarz4(self): #lista if(self.widgetlist.isVisible() == True): self.widgetlist.hide() else: self.widgetlist.show() self.qgl.setTool(4) def pushButtonNarz5(self): self.qgl.setTool(5) def pushButtonNarz6(self): #zaznaczanie wielu obiektow na scenie self.qgl.setTool(6) def pushButtonNarz7(self): self.qgl.setTool(7) def pushButtonNarz8(self): self.qgl.setTool(8) #------------ GUI XY ------------# def knowpoint(self,nr): #ustawienie na GUI if(nr == 1): self.widgetxy.setxpyp(self.qgl.obj[-1].xp,self.qgl.obj[-1].yp) elif(nr == 2): self.widgetxy.setxkyk(self.qgl.obj[-1].xk,self.qgl.obj[-1].yk) #------------ MYSZKA ------------# def qglMouse(self): #wczytanie pozycji myszki na scenie i umieszczenie jej w status barze mousepos = self.qgl.mousepos mousepos = "%.4f : %.4f" % (mousepos[0], mousepos[1]) #ustawienie odpowiedniego formatu self.ui.statusbar.showMessage(mousepos,0) #wyswietlenie infromacji w statusbar #------------ KLAWIATURA ------------# def keyPressEvent(self, event): #wcisniecie przycisku key = event.key() #-- usuwanie --# if(key == QtCore.Qt.Key_Delete): if(self.qgl.tool==0): #zaznaczony obiekt self.qgl.removeObjs(self.qgl.listclicked) self.qgl.listclicked = [] self.createWidgetList() elif(self.qgl.tool==4): #sortowanie self.pushButtonRemove() #-- anulowanie akacji --# elif(key == QtCore.Qt.Key_Escape): self.qgl.cancelDraw() #przesuwanie sceny elif(key == QtCore.Qt.Key_Left): self.qgl.changedxView(-self.dxdy) elif(key == QtCore.Qt.Key_Right): self.qgl.changedxView(self.dxdy) elif(key == QtCore.Qt.Key_Up): self.qgl.changedyView(self.dxdy) elif(key == QtCore.Qt.Key_Down): self.qgl.changedyView(-self.dxdy) elif(key == QtCore.Qt.Key_Shift): self.qgl.f_straight = True self.qgl.update() def keyReleaseEvent(self, event): #puszczenie przycisku key = event.key() if(key == QtCore.Qt.Key_Shift): self.qgl.f_straight = False self.qgl.update() #------------ MENUBAR - WIDOK ------------# def defaultView(self): #ustawia standarowy widok self.ui.actionPomniejsz.setEnabled(True) self.ui.actionPowieksz.setEnabled(True) self.qgl.defaultZoomView() def zoomSignal(self,signal): #dba o to czy uzytkownik moze kliknac powieksz lub pomniejsz if(signal == 0): self.ui.actionPowieksz.setEnabled(False) elif(signal == 1): self.ui.actionPomniejsz.setEnabled(False) else: self.ui.actionPomniejsz.setEnabled(True) self.ui.actionPowieksz.setEnabled(True) def ZoomInView(self): #zmienia wielkosc sceny self.qgl.changeZoomView(-self.zoom) def ZoomOutView(self): #zmienia wielkosc sceny self.qgl.changeZoomView(self.zoom) #------------ MENUBAR - EDYCJA ------------# def menubarBack(self): #cofnij ctrl+z self.qgl.previousStepJourney() def signalMenubarBack(self,i): #zablokowuje/odblokowuje przycisk cofnij self.ui.actionCofnij.setEnabled(i) def signalMenubarNext(self,i): #zablokowuje/odblokowuje przycisk naprzod self.ui.actionPonow.setEnabled(i) def menubarForward(self): #naprzod ctrl+z+shift self.qgl.nextStepJourney() #------------ MENUBAR - PLIK ------------# #--- Czy plik zapisany --- def FileNotSaved(self): #zmienia tytul okna gdy wystepuje taka potrzeba if(self.f_saved == True): #ustawienie tytulu okna na niezapisana txt = str(self.windowTitle()) txt = "*"+txt self.setWindowTitle(txt) self.f_saved = False self.ui.actionZapisz.setEnabled(True) #--- Nowy plik --- def newAction(self): #nowa scena if(self.f_saved == False): self.doYouWantToSaveFile("Czy przed stworzeniem nowego pliku chcesz zapsiac?") self.qgl.clearMysefl() self.fname = "" self.f_saved = True self.setWindowTitle("PyCAD") self.widgetlist.ui.listWidget.clear() self.qgl.update() #---Zakmniecie programu --- def closeEvent(self,event): #zamkniecie aplikacji - rowniez przez krzyzyk if(self.f_saved == False): self.doYouWantToSaveFile("Czy przed wyjsciem, chcesz zapisac zmiany?") self.f_saved = True self.close() #--- Zapisanie pliku --- def localAskDialog(self,txt): #Message box ktory pyta czy chcesz zapisac plik mbox = QtGui.QMessageBox() mbox.setWindowTitle("Zapis?") mbox.setText(txt) mbox.setIcon(QtGui.QMessageBox.Warning) mbox.setStandardButtons(QtGui.QMessageBox.Yes) mbox.addButton(QtGui.QMessageBox.No) mbox.setDefaultButton(QtGui.QMessageBox.No) #zmiana wyswietlanych napisow na przyciskach buttons = mbox.buttons() buttons[0].setText("Tak") buttons[1].setText("Nie") if(mbox.exec_() == QtGui.QMessageBox.Yes): return True else: return False def localSaveDialog(self): #dialog wywolywany do wczytania sciezki do pliku przy zapisie fdialog = QtGui.QFileDialog(self) #ustawienie trybu fdialog.setFileMode(QtGui.QFileDialog.AnyFile) #fdialog.setNameFilters(["data exchange format (*.dxf)", "downolny plik (*.*)"]) #jak dodac inne fdialog.setNameFilters(["data exchange format (*.dxf)"]) #filtry do wyboru fdialog.selectNameFilter("data exchange format (*.dxf)") #domyslny filtr #ustawienie tekstu na polski fdialog.setLabelText(QtGui.QFileDialog.LookIn,"aktualny folder") fdialog.setLabelText(QtGui.QFileDialog.FileName,"nazwa pliku") fdialog.setLabelText(QtGui.QFileDialog.FileType,"rozszerzenie") fdialog.setLabelText(QtGui.QFileDialog.Accept,"Zapisz") fdialog.setLabelText(QtGui.QFileDialog.Reject,"Anuluj") #tytul oknas fdialog.setWindowTitle("Zapisywanie pliku") if(fdialog.exec_()): fname = fdialog.selectedFiles()[0] if(fdialog.result() == 1): fname = str(fname) #konwertuje na stirng pythona, bo tak wynikiem jest QString tmp = fname.split(".") if(tmp[-1] != "dxf"): fname = fname + ".dxf" return fname else: return "" def saveFile(self): #zapisuje plik self.qgl.cancelDraw() if(self.fname == ""): #odczytanie sciezki do pliku fname = self.localSaveDialog() if(fname != ""): self.fname = fname if(self.fname != ""): if(self.qgl.DXFSave(self.fname) == True): self.setWindowTitle(self.fname) self.f_saved = True self.ui.actionZapisz.setEnabled(False) def saveFileAs(self): #zapisz jako (korzysta z metody saveFile) self.qgl.cancelDraw() fname = self.localSaveDialog() if(fname != ""): self.fname = fname self.saveFile() def doYouWantToSaveFile(self,txt): if(self.f_saved == False): #zmiany nie zapisane if(self.localAskDialog(txt) == True): if(len(self.qgl.obj) != self.qgl.howmanyignore ): #czy plik zostal wlasnie utworzony? self.saveFile() #--- Wczytanie pliku --- def localLoadDialog(self): #dialog wywolywany do wczytania sciezki do pliku przy otwieraniu pliku fdialog = QtGui.QFileDialog(self) #ustawienie trybu fdialog.setFileMode(QtGui.QFileDialog.AnyFile) #fdialog.setNameFilters(["data exchange format (*.dxf)", "downolny plik (*.*)"]) #jak dodac inne fdialog.setNameFilters(["data exchange format (*.dxf)"]) #filtry do wyboru fdialog.selectNameFilter("data exchange format (*.dxf)") #domyslny filtr #ustawienie tekstu na polski fdialog.setLabelText(QtGui.QFileDialog.LookIn,"aktualny folder") fdialog.setLabelText(QtGui.QFileDialog.FileName,"nazwa pliku") fdialog.setLabelText(QtGui.QFileDialog.FileType,"rozszerzenie") fdialog.setLabelText(QtGui.QFileDialog.Accept,"Wczytaj") fdialog.setLabelText(QtGui.QFileDialog.Reject,"Anuluj") #tytul okna fdialog.setWindowTitle("Wczytywanie pliku") if(fdialog.exec_()): fname = fdialog.selectedFiles()[0] if(fdialog.result() == 1): fname = str(fname) #konwertuje na stirng pythona, bo tak wynikiem jest QString tmp = fname.split(".") if(tmp[-1] != "dxf"): #sprawdza czy znany jest format return "" else: return fname else: return "" def loadDXF(self,fname): #wczytanie pliku self.qgl.clearMysefl() result = self.qgl.DXFLoad(fname) if(result == True): self.fname = fname self.setWindowTitle(fname) self.f_saved = True QtGui.QMessageBox.information(self, 'Wczytywanie', "Plik zostal wczytany pomyslnie",QtGui.QMessageBox.Ok) self.createWidgetList() elif(result == False): self.newAction() QtGui.QMessageBox.information(self, 'Wczytywanie', "Wczytywanie pliku nie powiodlo sie",QtGui.QMessageBox.Ok) def loadAction(self): #wczytywanie self.doYouWantToSaveFile("Czy chcesz zapisac zmiany przed otwraciem pliku") fname = self.localLoadDialog() if(fname != ""): self.loadDXF(fname) #------------ DRAG & DROP (do wczytania) ------------# def loadDrop(self,fname): #wczytanie pliku przy uzyciu drag and drop self.doYouWantToSaveFile("Czy chcesz zapisac zmiany przed otwraciem pliku") self.loadDXF(fname) def dragEnterEvent(self, event): #przesuniecie obiektu na obszar main window if event.mimeData().hasUrls(): event.acceptProposedAction() else: event.ignore() def dropEvent(self, event): #po upuszczeniu obiektu zrob cos z nim if ( len(event.mimeData().urls()) == 1): #sprawdza czy tylko jeden plik zostal upuszczony url = event.mimeData().urls()[0] #konwenture liste QUrl na QUrl url = str(url.path()) #konwertuje Qurl na sciezke a potem na pythonoweg stringa tmp = url.split(".") if(tmp[-1] == "dxf"): #sprawdza czy foramt to "dxf" self.loadDrop(url) else: event.ignore() else: event.ignore() #ignoruje drop jesli wystapi wiecej niz jeden plik
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) l=QVBoxLayout(self) self._glWidget=GLWidget(self) l.addWidget(self._glWidget)
def __init__( self, gadget=None, bufferOptions=set(), **kw ) : GLWidget.__init__( self, bufferOptions, **kw ) # Force the IECoreGL lazy loading to kick in /now/. Otherwise we can get IECoreGL objects # being returned from the GafferUIBindings without the appropriate boost::python converters # having been registered first. IECoreGL.Renderer self.__requestedDepthBuffer = self.BufferOptions.Depth in bufferOptions self.__keyPressConnection = self.keyPressSignal().connect( Gaffer.WeakMethod( self.__keyPress ) ) self.__keyReleaseConnection = self.keyReleaseSignal().connect( Gaffer.WeakMethod( self.__keyRelease ) ) self.__buttonPressConnection = self.buttonPressSignal().connect( Gaffer.WeakMethod( self.__buttonPress ) ) self.__buttonReleaseConnection = self.buttonReleaseSignal().connect( Gaffer.WeakMethod( self.__buttonRelease ) ) self.__buttonDoubleClickConnection = self.buttonDoubleClickSignal().connect( Gaffer.WeakMethod( self.__buttonDoubleClick ) ) self.__mouseMoveConnection = self.mouseMoveSignal().connect( Gaffer.WeakMethod( self.__mouseMove ) ) self.__dragBeginConnection = self.dragBeginSignal().connect( Gaffer.WeakMethod( self.__dragBegin ) ) self.__dragEnterConnection = self.dragEnterSignal().connect( Gaffer.WeakMethod( self.__dragEnter ) ) self.__dragMoveConnection = self.dragMoveSignal().connect( Gaffer.WeakMethod( self.__dragMove ) ) self.__dragLeaveConnection = self.dragLeaveSignal().connect( Gaffer.WeakMethod( self.__dragLeave ) ) self.__dropConnection = self.dropSignal().connect( Gaffer.WeakMethod( self.__drop ) ) self.__dragEndConnection = self.dragEndSignal().connect( Gaffer.WeakMethod( self.__dragEnd ) ) self.__wheelConnection = self.wheelSignal().connect( Gaffer.WeakMethod( self.__wheel ) ) self.__viewportGadget = None if isinstance( gadget, GafferUI.ViewportGadget ) : self.setViewportGadget( gadget ) else : self.setViewportGadget( GafferUI.ViewportGadget( gadget ) ) self._qtWidget().installEventFilter( _eventFilter )