コード例 #1
0
ファイル: svgviewer.py プロジェクト: MindPass/Code
    def setRenderer(self, action):
        if QGLFormat.hasOpenGL():
            self.highQualityAntialiasingAction.setEnabled(False)

        if action == self.nativeAction:
            self.view.setRenderer(SvgView.Native)
        elif action == self.glAction:
            if QGLFormat.hasOpenGL():
                self.highQualityAntialiasingAction.setEnabled(True)
                self.view.setRenderer(SvgView.OpenGL)
        elif action == self.imageAction:
            self.view.setRenderer(SvgView.Image)
コード例 #2
0
    def setRenderer(self, action):
        if QGLFormat.hasOpenGL():
            self.highQualityAntialiasingAction.setEnabled(False)

        if action == self.nativeAction:
            self.view.setRenderer(SvgView.Native)
        elif action == self.glAction:
            if QGLFormat.hasOpenGL():
                self.highQualityAntialiasingAction.setEnabled(True)
                self.view.setRenderer(SvgView.OpenGL)
        elif action == self.imageAction:
            self.view.setRenderer(SvgView.Image)
コード例 #3
0
    def __init__(self, parent):
        # OpenGL Widget setup
        f = QGLFormat()
        f.setSampleBuffers(True)
        f.setVersion(3,3)
        f.setProfile(QGLFormat.CoreProfile)
        QGLFormat.setDefaultFormat(f)

        if not QGLFormat.hasOpenGL():
            QMessageBox.information(None, "OpenGL samplebuffers",
                    "This system does not support OpenGL.")
            sys.exit(0)
        super(GLWidget, self).__init__(f, parent)
        self.setFocusPolicy(Qt.StrongFocus)
        self.list_ = []
        self.width = 640.0
        self.height = 480.0
        self.startTimer(40)
        self.setWindowTitle("Sample Buffers")
        self.fov = 60.0
        self.deltaTime = 0.0
        self.lastFrame = None
        self.sketching = False
        self.sketchType = 0
        self.sketchPoints = []
コード例 #4
0
ファイル: board.py プロジェクト: thesmartwon/OpenChess-Python
    def __init__(self, parent, scene):
        super().__init__(parent)
        self.setScene(scene)
        if QGLFormat.hasOpenGL():
            self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))

        self.numScrolls = 0
コード例 #5
0
ファイル: gui.py プロジェクト: thobson88/bluesky
def start(mode):
    # Install message handler for Qt messages
    qInstallMessageHandler(gui_msg_handler)

    # Start the Qt main object
    app = QApplication([])

    # Start the bluesky network client
    client = GuiClient()

    # Enable HiDPI support (Qt5 only)
    if QT_VERSION >= 0x050000:
        app.setAttribute(Qt.AA_UseHighDpiPixmaps)

    splash = Splash()

    # Register our custom pan/zoom event
    for etype in range(1000, 1000 + NUMCUSTOMEVENTS):
        reg_etype = QEvent.registerEventType(etype)
        if reg_etype != etype:
            print(('Warning: Registered event type differs from requested type id (%d != %d)' % (reg_etype, etype)))

    splash.show()

    # Install error message handler
    handler = QErrorMessage.qtHandler()
    handler.setWindowFlags(Qt.WindowStaysOnTopHint)

    # Check and set OpenGL capabilities
    if not QGLFormat.hasOpenGL():
        raise RuntimeError('No OpenGL support detected for this system!')
    else:
        f = QGLFormat()
        f.setVersion(3, 3)
        f.setProfile(QGLFormat.CoreProfile)
        f.setDoubleBuffer(True)
        QGLFormat.setDefaultFormat(f)
        print(('QGLWidget initialized for OpenGL version %d.%d' % (f.majorVersion(), f.minorVersion())))

    splash.showMessage('Constructing main window')
    app.processEvents()
    win = MainWindow(mode)
    win.show()
    splash.showMessage('Done!')
    app.processEvents()
    splash.finish(win)
    # If this instance of the gui is started in client-only mode, show
    # server selection dialog
    if mode == 'client':
        dialog = DiscoveryDialog(win)
        dialog.show()
        bs.net.start_discovery()

    else:
        client.connect(event_port=bs.settings.event_port,
                       stream_port=bs.settings.stream_port)

    # Start the Qt main loop
    app.exec_()
コード例 #6
0
def start():
    # Start the Qt main object
    app = QApplication([])

    # Start the bluesky network client
    client = GuiClient()

    # Enable HiDPI support (Qt5 only)
    if QT_VERSION >= 0x050000:
        app.setAttribute(Qt.AA_UseHighDpiPixmaps)

    splash = Splash()

    # Register our custom pan/zoom event
    for etype in range(1000, 1000 + NUMCUSTOMEVENTS):
        reg_etype = QEvent.registerEventType(etype)
        if reg_etype != etype:
            print((
                'Warning: Registered event type differs from requested type id (%d != %d)'
                % (reg_etype, etype)))

    splash.show()

    # Install error message handler
    handler = QErrorMessage.qtHandler()
    handler.setWindowFlags(Qt.WindowStaysOnTopHint)

    # Check and set OpenGL capabilities
    if not QGLFormat.hasOpenGL():
        raise RuntimeError('No OpenGL support detected for this system!')
    else:
        f = QGLFormat()
        f.setVersion(3, 3)
        f.setProfile(QGLFormat.CoreProfile)
        f.setDoubleBuffer(True)
        QGLFormat.setDefaultFormat(f)
        print(('QGLWidget initialized for OpenGL version %d.%d' %
               (f.majorVersion(), f.minorVersion())))

    splash.showMessage('Constructing main window')
    app.processEvents()
    win = MainWindow()
    win.show()
    splash.showMessage('Done!')
    app.processEvents()
    splash.finish(win)
    # If this instance of the gui is started in client-only mode, show
    # server selection dialog
    if bs.settings.is_client:
        dialog = DiscoveryDialog(win)
        dialog.show()
        bs.net.start_discovery()

    else:
        client.connect(event_port=bs.settings.event_port,
                       stream_port=bs.settings.stream_port)

    # Start the Qt main loop
    app.exec_()
コード例 #7
0
ファイル: svgviewer.py プロジェクト: MindPass/Code
    def setRenderer(self, renderer):
        self.renderer = renderer

        if self.renderer == SvgView.OpenGL:
            if QGLFormat.hasOpenGL():
                self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))
        else:
            self.setViewport(QWidget())
コード例 #8
0
    def setRenderer(self, renderer):
        self.renderer = renderer

        if self.renderer == SvgView.OpenGL:
            if QGLFormat.hasOpenGL():
                self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))
        else:
            self.setViewport(QWidget())
コード例 #9
0
    def __init__(self):
        super(Gui, self).__init__([])
        self.acdata = ACDataEvent()
        self.birddata = BirdDataEvent()
        self.navdb = None
        self.radarwidget = []
        self.command_history = []
        self.cmd = ''
        self.args = []
        self.history_pos = 0
        self.command_mem = ''
        self.command_line = ''
        self.prev_cmdline = ''
        self.mousedragged = False
        self.mousepos = (0, 0)
        self.prevmousepos = (0, 0)
        self.panzoomchanged = False
        self.simt = 0.0

        # Register our custom pan/zoom event
        for etype in range(1000, 1000 + NUMEVENTS):
            reg_etype = QEvent.registerEventType(etype)
            if reg_etype != etype:
                print(
                    'Warning: Registered event type differs from requested type id (%d != %d)'
                    % (reg_etype, etype))

        self.splash = Splash()
        self.splash.show()

        # Install error message handler
        handler = QErrorMessage.qtHandler()
        handler.setWindowFlags(Qt.WindowStaysOnTopHint)

        # Check and set OpenGL capabilities
        if not QGLFormat.hasOpenGL():
            raise RuntimeError('No OpenGL support detected for this system!')
        else:
            f = QGLFormat()
            f.setVersion(3, 3)
            f.setProfile(QGLFormat.CoreProfile)
            f.setDoubleBuffer(True)
            QGLFormat.setDefaultFormat(f)
            print('QGLWidget initialized for OpenGL version %d.%d' %
                  (f.majorVersion(), f.minorVersion()))

        # Enable HiDPI support (Qt5 only)
        if QT_VERSION == 5:
            self.setAttribute(Qt.AA_UseHighDpiPixmaps)
コード例 #10
0
ファイル: gui.py プロジェクト: mvanhorssen/bluesky
    def __init__(self):
        super(Gui, self).__init__([])
        self.acdata          = ACDataEvent()
        self.routedata       = RouteDataEvent()
        self.navdb           = None
        self.radarwidget     = []
        self.command_history = []
        self.cmd             = ''
        self.args            = []
        self.history_pos     = 0
        self.command_mem     = ''
        self.command_line    = ''
        self.prev_cmdline    = ''
        self.mousedragged    = False
        self.mousepos        = (0, 0)
        self.prevmousepos    = (0, 0)
        self.panzoomchanged  = False
        self.simt            = 0.0

        # Register our custom pan/zoom event
        for etype in range(1000, 1000 + NUMEVENTS):
            reg_etype = QEvent.registerEventType(etype)
            if reg_etype != etype:
                print('Warning: Registered event type differs from requested type id (%d != %d)' % (reg_etype, etype))

        self.splash = Splash()
        self.splash.show()

        # Install error message handler
        handler = QErrorMessage.qtHandler()
        handler.setWindowFlags(Qt.WindowStaysOnTopHint)

        # Check and set OpenGL capabilities
        if not QGLFormat.hasOpenGL():
            raise RuntimeError('No OpenGL support detected for this system!')
        else:
            f = QGLFormat()
            f.setVersion(3, 3)
            f.setProfile(QGLFormat.CoreProfile)
            f.setDoubleBuffer(True)
            QGLFormat.setDefaultFormat(f)
            print('QGLWidget initialized for OpenGL version %d.%d' % (f.majorVersion(), f.minorVersion()))

        # Enable HiDPI support (Qt5 only)
        if QT_VERSION == 5:
            self.setAttribute(Qt.AA_UseHighDpiPixmaps)
コード例 #11
0
ファイル: mapview.py プロジェクト: theall/Python-Tiled
    def setUseOpenGL(self, useOpenGL):
        if not QT_NO_OPENGL:
            if (useOpenGL and QGLFormat.hasOpenGL()):
                if (not self.viewport()):
                    format = QGLFormat.defaultFormat()
                    format.setDepth(False) # No need for a depth buffer
                    format.setSampleBuffers(True) # Enable anti-aliasing
                    self.setViewport(QGLWidget(format))

            else:
                if self.viewport():
                    self.setViewport(None)

            v = self.viewport()
            if (self.mMode == MapViewMode.StaticContents):
                v.setAttribute(Qt.WA_StaticContents)
            v.setMouseTracking(True)
        else:
            pass
コード例 #12
0
    def setUseOpenGL(self, useOpenGL):
        if not QT_NO_OPENGL:
            if (useOpenGL and QGLFormat.hasOpenGL()):
                if (not self.viewport()):
                    format = QGLFormat.defaultFormat()
                    format.setDepth(False)  # No need for a depth buffer
                    format.setSampleBuffers(True)  # Enable anti-aliasing
                    self.setViewport(QGLWidget(format))

            else:
                if self.viewport():
                    self.setViewport(None)

            v = self.viewport()
            if (self.mMode == MapViewMode.StaticContents):
                v.setAttribute(Qt.WA_StaticContents)
            v.setMouseTracking(True)
        else:
            pass
コード例 #13
0
    def __init__(self, *args, **kwargs):
        super(GraphicsView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        # 设置背景颜色
        self.setBackgroundBrush(self.backgroundColor)
        # 缓存背景
        self.setCacheMode(self.CacheBackground)
        # 设置拖拽样式
        # self.setDragMode(self.ScrollHandDrag)
        self.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing
                            | QPainter.SmoothPixmapTransform)
        # opengl
        if QGLFormat.hasOpenGL():
            self.setRenderHint(QPainter.HighQualityAntialiasing)
        # 尝试通过分析需要重绘的区域来找到最佳的更新模式
        self.setViewportUpdateMode(self.SmartViewportUpdate)
        self._scene = QGraphicsScene(-400, -300, 800, 600, self)
        self.setScene(self._scene)

        # 图片item
        self._itemImage = None
コード例 #14
0
    def __init__(self, parent = None):
        super().__init__(parent)
        self.mUi = Ui_PreferencesDialog()
        self.mLanguages = LanguageManager.instance().availableLanguages()

        self.mUi.setupUi(self)
        self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
        self.mUi.openGL.setEnabled(QGLFormat.hasOpenGL())
        for name in self.mLanguages:
            locale = QLocale(name)
            string = "%s (%s)"%(QLocale.languageToString(locale.language()), QLocale.countryToString(locale.country()))
            self.mUi.languageCombo.addItem(string, name)

        self.mUi.languageCombo.model().sort(0)
        self.mUi.languageCombo.insertItem(0, self.tr("System default"))
        self.mObjectTypesModel = ObjectTypesModel(self)
        self.mUi.objectTypesTable.setModel(self.mObjectTypesModel)
        self.mUi.objectTypesTable.setItemDelegateForColumn(1, ColorDelegate(self))
        horizontalHeader = self.mUi.objectTypesTable.horizontalHeader()
        horizontalHeader.setSectionResizeMode(QHeaderView.Stretch)
        Utils.setThemeIcon(self.mUi.addObjectTypeButton, "add")
        Utils.setThemeIcon(self.mUi.removeObjectTypeButton, "remove")
        self.fromPreferences()
        self.mUi.languageCombo.currentIndexChanged.connect(self.languageSelected)
        self.mUi.openGL.toggled.connect(self.useOpenGLToggled)
        self.mUi.gridColor.colorChanged.connect(preferences.Preferences.instance().setGridColor)
        self.mUi.gridFine.valueChanged.connect(preferences.Preferences.instance().setGridFine)
        self.mUi.objectLineWidth.valueChanged.connect(self.objectLineWidthChanged)
        self.mUi.objectTypesTable.selectionModel().selectionChanged.connect(self.selectedObjectTypesChanged)
        self.mUi.objectTypesTable.doubleClicked.connect(self.objectTypeIndexClicked)
        self.mUi.addObjectTypeButton.clicked.connect(self.addObjectType)
        self.mUi.removeObjectTypeButton.clicked.connect(self.removeSelectedObjectTypes)
        self.mUi.importObjectTypesButton.clicked.connect(self.importObjectTypes)
        self.mUi.exportObjectTypesButton.clicked.connect(self.exportObjectTypes)
        self.mObjectTypesModel.dataChanged.connect(self.applyObjectTypes)
        self.mObjectTypesModel.rowsRemoved.connect(self.applyObjectTypes)
        self.mUi.autoMapWhileDrawing.toggled.connect(self.useAutomappingDrawingToggled)
        self.mUi.openLastFiles.toggled.connect(self.openLastFilesToggled)
コード例 #15
0
    def __init__(self, *args, **kwargs):
        super(SimpleImageView, self).__init__(*args, **kwargs)
        # 设置背景颜色
        self.setBackgroundBrush(self.backgroundColor)
        # 缓存背景
        self.setCacheMode(self.CacheBackground)
        # 设置拖拽样式
        # self.setDragMode(self.ScrollHandDrag)
        self.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing
                            | QPainter.SmoothPixmapTransform)
        # opengl
        if hasOpenGL and QGLFormat.hasOpenGL():
            #             self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers), self))
            self.setRenderHint(QPainter.HighQualityAntialiasing)
            self.setViewportUpdateMode(self.FullViewportUpdate)
        else:
            # 尝试通过分析需要重绘的区域来找到最佳的更新模式
            self.setViewportUpdateMode(self.SmartViewportUpdate)
        self._scene = QGraphicsScene(self)
        self.setScene(self._scene)

        # 图片item
        self._itemImage = None
コード例 #16
0
ファイル: gui.py プロジェクト: AlexanderFSX/bluesky
    def __init__(self, navdb):
        super(Gui, self).__init__([])
        self.acdata          = ACDataEvent()
        self.navdb           = navdb
        self.radarwidget     = []
        self.command_history = []
        self.cmdargs         = []
        self.history_pos     = 0
        self.command_mem     = ''
        self.command_line    = ''
        self.prev_cmdline    = ''
        self.simevent_target = 0
        self.mousedragged    = False
        self.mousepos        = (0, 0)
        self.prevmousepos    = (0, 0)
        self.panzoomchanged  = False
        self.simt            = 0.0

        # Register our custom pan/zoom event
        for etype in [PanZoomEventType, ACDataEventType, SimInfoEventType,
                      StackTextEventType, ShowDialogEventType,
                      DisplayFlagEventType, RouteDataEventType,
                      DisplayShapeEventType, SimQuitEventType,
                      AMANEventType]:
            reg_etype = QEvent.registerEventType(etype)
            if reg_etype != etype:
                print('Warning: Registered event type differs from requested type id (%d != %d)' % (reg_etype, etype))

        self.splash = Splash()
        self.splash.show()

        self.splash.showMessage('Constructing main window')
        self.processEvents()

        # Install error message handler
        handler = QErrorMessage.qtHandler()
        handler.setWindowFlags(Qt.WindowStaysOnTopHint)

        # Check and set OpenGL capabilities
        if not QGLFormat.hasOpenGL():
            raise RuntimeError('No OpenGL support detected for this system!')
        else:
            f = QGLFormat()
            f.setVersion(3, 3)
            f.setProfile(QGLFormat.CoreProfile)
            f.setDoubleBuffer(True)
            QGLFormat.setDefaultFormat(f)
            print('QGLWidget initialized for OpenGL version %d.%d' % (f.majorVersion(), f.minorVersion()))

        # Create the main window and related widgets
        self.radarwidget = RadarWidget(navdb)
        self.win  = MainWindow(self, self.radarwidget)
        self.nd   = ND(shareWidget=self.radarwidget)
        #self.aman = AMANDisplay(shareWidget=self.radarwidget)

        # Enable HiDPI support (Qt5 only)
        if QT_VERSION == 5:
            self.setAttribute(Qt.AA_UseHighDpiPixmaps)

        timer = QTimer(self)
        timer.timeout.connect(self.radarwidget.updateGL)
        timer.timeout.connect(self.nd.updateGL)
        #timer.timeout.connect(self.aman.updateGL)
        timer.start(50)
コード例 #17
0
ファイル: padnavigator.py プロジェクト: Axel-Erfurt/pyqt5
    def __init__(self, size, parent=None):
        super(PadNavigator, self).__init__(parent)

        self.form = Ui_Form()

        splash = SplashItem()
        splash.setZValue(1)

        pad = FlippablePad(size)
        flipRotation = QGraphicsRotation(pad)
        xRotation = QGraphicsRotation(pad)
        yRotation = QGraphicsRotation(pad)
        flipRotation.setAxis(Qt.YAxis)
        xRotation.setAxis(Qt.YAxis)
        yRotation.setAxis(Qt.XAxis)
        pad.setTransformations([flipRotation, xRotation, yRotation])

        backItem = QGraphicsProxyWidget(pad)
        widget = QWidget()
        self.form.setupUi(widget)
        self.form.hostName.setFocus()
        backItem.setWidget(widget)
        backItem.setVisible(False)
        backItem.setFocus()
        backItem.setCacheMode(QGraphicsItem.ItemCoordinateCache)
        r = backItem.rect()
        backItem.setTransform(QTransform().rotate(180, Qt.YAxis).translate(-r.width()/2, -r.height()/2))

        selectionItem = RoundRectItem(QRectF(-60, -60, 120, 120),
                QColor(Qt.gray), pad)
        selectionItem.setZValue(0.5)

        smoothSplashMove = QPropertyAnimation(splash, b'y')
        smoothSplashOpacity = QPropertyAnimation(splash, b'opacity')
        smoothSplashMove.setEasingCurve(QEasingCurve.InQuad)
        smoothSplashMove.setDuration(250)
        smoothSplashOpacity.setDuration(250)

        smoothXSelection = QPropertyAnimation(selectionItem, b'x')
        smoothYSelection = QPropertyAnimation(selectionItem, b'y')
        smoothXRotation = QPropertyAnimation(xRotation, b'angle')
        smoothYRotation = QPropertyAnimation(yRotation, b'angle')
        smoothXSelection.setDuration(125)
        smoothYSelection.setDuration(125)
        smoothXRotation.setDuration(125)
        smoothYRotation.setDuration(125)
        smoothXSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYRotation.setEasingCurve(QEasingCurve.InOutQuad)

        smoothFlipRotation = QPropertyAnimation(flipRotation, b'angle')
        smoothFlipScale = QPropertyAnimation(pad, b'scale')
        smoothFlipXRotation = QPropertyAnimation(xRotation, b'angle')
        smoothFlipYRotation = QPropertyAnimation(yRotation, b'angle')
        flipAnimation = QParallelAnimationGroup(self)
        smoothFlipScale.setDuration(500)
        smoothFlipRotation.setDuration(500)
        smoothFlipXRotation.setDuration(500)
        smoothFlipYRotation.setDuration(500)
        smoothFlipScale.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipYRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipScale.setKeyValueAt(0, 1.0)
        smoothFlipScale.setKeyValueAt(0.5, 0.7)
        smoothFlipScale.setKeyValueAt(1, 1.0)
        flipAnimation.addAnimation(smoothFlipRotation)
        flipAnimation.addAnimation(smoothFlipScale)
        flipAnimation.addAnimation(smoothFlipXRotation)
        flipAnimation.addAnimation(smoothFlipYRotation)

        setVariablesSequence = QSequentialAnimationGroup()
        setFillAnimation = QPropertyAnimation(pad, b'fill')
        setBackItemVisibleAnimation = QPropertyAnimation(backItem, b'visible')
        setSelectionItemVisibleAnimation = QPropertyAnimation(selectionItem, b'visible')
        setFillAnimation.setDuration(0)
        setBackItemVisibleAnimation.setDuration(0)
        setSelectionItemVisibleAnimation.setDuration(0)
        setVariablesSequence.addPause(250)
        setVariablesSequence.addAnimation(setBackItemVisibleAnimation)
        setVariablesSequence.addAnimation(setSelectionItemVisibleAnimation)
        setVariablesSequence.addAnimation(setFillAnimation)
        flipAnimation.addAnimation(setVariablesSequence)

        stateMachine = QStateMachine(self)
        splashState = QState(stateMachine)
        frontState = QState(stateMachine)
        historyState = QHistoryState(frontState)
        backState = QState(stateMachine)

        frontState.assignProperty(pad, "fill", False)
        frontState.assignProperty(splash, "opacity", 0.0)
        frontState.assignProperty(backItem, "visible", False)
        frontState.assignProperty(flipRotation, "angle", 0.0)
        frontState.assignProperty(selectionItem, "visible", True)

        backState.assignProperty(pad, "fill", True)
        backState.assignProperty(backItem, "visible", True)
        backState.assignProperty(xRotation, "angle", 0.0)
        backState.assignProperty(yRotation, "angle", 0.0)
        backState.assignProperty(flipRotation, "angle", 180.0)
        backState.assignProperty(selectionItem, "visible", False)

        stateMachine.addDefaultAnimation(smoothXRotation)
        stateMachine.addDefaultAnimation(smoothYRotation)
        stateMachine.addDefaultAnimation(smoothXSelection)
        stateMachine.addDefaultAnimation(smoothYSelection)
        stateMachine.setInitialState(splashState)

        anyKeyTransition = QEventTransition(self, QEvent.KeyPress, splashState)
        anyKeyTransition.setTargetState(frontState)
        anyKeyTransition.addAnimation(smoothSplashMove)
        anyKeyTransition.addAnimation(smoothSplashOpacity)

        enterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Enter, backState)
        returnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Return, backState)
        backEnterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Enter, frontState)
        backReturnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Return, frontState)
        enterTransition.setTargetState(historyState)
        returnTransition.setTargetState(historyState)
        backEnterTransition.setTargetState(backState)
        backReturnTransition.setTargetState(backState)
        enterTransition.addAnimation(flipAnimation)
        returnTransition.addAnimation(flipAnimation)
        backEnterTransition.addAnimation(flipAnimation)
        backReturnTransition.addAnimation(flipAnimation)

        columns = size.width()
        rows = size.height()
        stateGrid = []
        for y in range(rows):
            stateGrid.append([QState(frontState) for _ in range(columns)])

        frontState.setInitialState(stateGrid[0][0])
        selectionItem.setPos(pad.iconAt(0, 0).pos())

        for y in range(rows):
            for x in range(columns):
                state = stateGrid[y][x]

                rightTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Right, state)
                leftTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Left, state)
                downTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Down, state)
                upTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Up, state)

                rightTransition.setTargetState(stateGrid[y][(x + 1) % columns])
                leftTransition.setTargetState(stateGrid[y][((x - 1) + columns) % columns])
                downTransition.setTargetState(stateGrid[(y + 1) % rows][x])
                upTransition.setTargetState(stateGrid[((y - 1) + rows) % rows][x])

                icon = pad.iconAt(x, y)
                state.assignProperty(xRotation, "angle", -icon.x() / 6.0)
                state.assignProperty(yRotation, "angle", icon.y() / 6.0)
                state.assignProperty(selectionItem, "x", icon.x())
                state.assignProperty(selectionItem, "y", icon.y())
                frontState.assignProperty(icon, "visible", True)
                backState.assignProperty(icon, "visible", False)

                setIconVisibleAnimation = QPropertyAnimation(icon, b'visible')
                setIconVisibleAnimation.setDuration(0)
                setVariablesSequence.addAnimation(setIconVisibleAnimation)

        scene = QGraphicsScene(self)
        scene.setBackgroundBrush(QBrush(QPixmap(":/images/blue_angle_swirl.jpg")))
        scene.setItemIndexMethod(QGraphicsScene.NoIndex)
        scene.addItem(pad)
        scene.setSceneRect(scene.itemsBoundingRect())
        self.setScene(scene)

        sbr = splash.boundingRect()
        splash.setPos(-sbr.width() / 2, scene.sceneRect().top() - 2)
        frontState.assignProperty(splash, "y", splash.y() - 100.0)
        scene.addItem(splash)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setMinimumSize(50, 50)
        self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
        self.setCacheMode(QGraphicsView.CacheBackground)
        self.setRenderHints(QPainter.Antialiasing |
                QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing)

        if QGLFormat.hasOpenGL():
            self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))

        stateMachine.start()
コード例 #18
0
ファイル: blipdriver.py プロジェクト: ProfHoekstra/bluesky
                increment = 10
                val = self.remainder + self.rate / 0.02

            self.selValues[4] += int(val) * increment
            self.remainder = val - int(val)

        self.update_lcd()
        if self.btn_pressed is not None:
            QTimer.singleShot(200, self.updateAPValues)


if __name__ == "__main__":
    qapp = QApplication([])

    # Check and set OpenGL capabilities
    if not QGLFormat.hasOpenGL():
        raise RuntimeError('No OpenGL support detected for this system!')
    else:
        f = QGLFormat()
        f.setVersion(3, 3)
        f.setProfile(QGLFormat.CoreProfile)
        f.setDoubleBuffer(True)
        QGLFormat.setDefaultFormat(f)
        print(('QGLWidget initialized for OpenGL version %d.%d' % (f.majorVersion(), f.minorVersion())))

    blip = BlipDriver()
    blip.show()

    gltimer          = QTimer(qapp)
    gltimer.timeout.connect(blip.updateGL)
    gltimer.start(50)
コード例 #19
0
def start(mode):
    # Install message handler for Qt messages
    qInstallMessageHandler(gui_msg_handler)

    # Start the Qt main object
    app = QApplication([])

    # Start the bluesky network client
    client = GuiClient()

    # Enable HiDPI support (Qt5 only)
    if QT_VERSION >= 0x050000:
        app.setAttribute(Qt.AA_UseHighDpiPixmaps)

    splash = Splash()

    # Register our custom pan/zoom event
    for etype in range(1000, 1000 + NUMCUSTOMEVENTS):
        reg_etype = QEvent.registerEventType(etype)
        if reg_etype != etype:
            print((
                'Warning: Registered event type differs from requested type id (%d != %d)'
                % (reg_etype, etype)))

    splash.show()

    # Install error message handler
    handler = QErrorMessage.qtHandler()
    handler.setWindowFlags(Qt.WindowStaysOnTopHint)

    # Check and set OpenGL capabilities
    if not QGLFormat.hasOpenGL():
        raise RuntimeError('No OpenGL support detected for this system!')
    else:
        f = QGLFormat()
        f.setVersion(3, 3)
        f.setProfile(QGLFormat.CoreProfile)
        f.setDoubleBuffer(True)
        QGLFormat.setDefaultFormat(f)
        print(('QGLWidget initialized for OpenGL version %d.%d' %
               (f.majorVersion(), f.minorVersion())))

    splash.showMessage('Constructing main window')
    app.processEvents()
    win = MainWindow(mode)
    splash.showMessage('Done!')
    app.processEvents()
    splash.finish(win)

    # Quick hack to connect to a remote simulation
    import sys
    arg = '--bluesky_host='
    host = next((x for x in sys.argv if x.startswith(arg)), None)
    if host is not None:
        host = host[len(arg):]
        try:
            print('Attempting connection to BlueSky at: {}'.format(host))
            client.connect(hostname=host,
                           event_port=bs.settings.event_port,
                           stream_port=bs.settings.stream_port,
                           timeout=5)
        except TimeoutError:
            print('Failed to connect to BlueSky server at {}, exiting'.format(
                host))
            QApplication.quit()
            sys.exit(0)
        win.show()
        app.exec_()
        return

    win.show()

    # If this instance of the gui is started in client-only mode, show
    # server selection dialog
    if mode == 'client':
        dialog = DiscoveryDialog(win)
        dialog.show()
        bs.net.start_discovery()

    else:
        client.connect(event_port=bs.settings.event_port,
                       stream_port=bs.settings.stream_port)

    # Start the Qt main loop
    app.exec_()
コード例 #20
0
ファイル: svgviewer.py プロジェクト: MindPass/Code
    def __init__(self):
        super(MainWindow, self).__init__()

        self.currentPath = ''

        self.view = SvgView()

        fileMenu = QMenu("&File", self)
        openAction = fileMenu.addAction("&Open...")
        openAction.setShortcut("Ctrl+O")
        quitAction = fileMenu.addAction("E&xit")
        quitAction.setShortcut("Ctrl+Q")

        self.menuBar().addMenu(fileMenu)

        viewMenu = QMenu("&View", self)
        self.backgroundAction = viewMenu.addAction("&Background")
        self.backgroundAction.setEnabled(False)
        self.backgroundAction.setCheckable(True)
        self.backgroundAction.setChecked(False)
        self.backgroundAction.toggled.connect(self.view.setViewBackground)

        self.outlineAction = viewMenu.addAction("&Outline")
        self.outlineAction.setEnabled(False)
        self.outlineAction.setCheckable(True)
        self.outlineAction.setChecked(True)
        self.outlineAction.toggled.connect(self.view.setViewOutline)

        self.menuBar().addMenu(viewMenu)

        rendererMenu = QMenu("&Renderer", self)
        self.nativeAction = rendererMenu.addAction("&Native")
        self.nativeAction.setCheckable(True)
        self.nativeAction.setChecked(True)

        if QGLFormat.hasOpenGL():
            self.glAction = rendererMenu.addAction("&OpenGL")
            self.glAction.setCheckable(True)

        self.imageAction = rendererMenu.addAction("&Image")
        self.imageAction.setCheckable(True)

        if QGLFormat.hasOpenGL():
            rendererMenu.addSeparator()
            self.highQualityAntialiasingAction = rendererMenu.addAction("&High Quality Antialiasing")
            self.highQualityAntialiasingAction.setEnabled(False)
            self.highQualityAntialiasingAction.setCheckable(True)
            self.highQualityAntialiasingAction.setChecked(False)
            self.highQualityAntialiasingAction.toggled.connect(self.view.setHighQualityAntialiasing)

        rendererGroup = QActionGroup(self)
        rendererGroup.addAction(self.nativeAction)

        if QGLFormat.hasOpenGL():
            rendererGroup.addAction(self.glAction)

        rendererGroup.addAction(self.imageAction)

        self.menuBar().addMenu(rendererMenu)

        openAction.triggered.connect(self.openFile)
        quitAction.triggered.connect(QApplication.instance().quit)
        rendererGroup.triggered.connect(self.setRenderer)

        self.setCentralWidget(self.view)
        self.setWindowTitle("SVG Viewer")
コード例 #21
0
ファイル: svgviewer.py プロジェクト: MindPass/Code
 def setHighQualityAntialiasing(self, highQualityAntialiasing):
     if QGLFormat.hasOpenGL():
         self.setRenderHint(QPainter.HighQualityAntialiasing,
                 highQualityAntialiasing)
コード例 #22
0
 def setHighQualityAntialiasing(self, highQualityAntialiasing):
     if QGLFormat.hasOpenGL():
         self.setRenderHint(QPainter.HighQualityAntialiasing,
                            highQualityAntialiasing)
コード例 #23
0
                        QPointF(latitude, -longitude)
                        for latitude, longitude in coordinate
                    ])
                    item = QGraphicsPolygonItem(polygon)
                    item.setPen(QPen(self.borderColor, 0))
                    item.setBrush(QBrush(self.backgroundColor))
                    item.setPos(0, 0)
                    self._scene.addItem(item)
                elif _type == "MultiPolygon":
                    for _coordinate in coordinate:
                        polygon = QPolygonF([
                            QPointF(latitude, -longitude)
                            for latitude, longitude in _coordinate
                        ])
                        item = QGraphicsPolygonItem(polygon)
                        item.setPen(QPen(self.borderColor, 0))
                        item.setBrush(QBrush(self.backgroundColor))
                        item.setPos(0, 0)
                        self._scene.addItem(item)


if __name__ == "__main__":
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)
    print("OpenGL Status:", QGLFormat.hasOpenGL())
    view = GraphicsView()
    view.setWindowTitle("世界地图")
    view.show()
    sys.exit(app.exec_())
コード例 #24
0
    def __init__(self, *args, **kwargs):
        super(GraphicsView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        # 设置背景颜色
        self.setBackgroundBrush(self.backgroundColor)
        '''
        #参考 http://doc.qt.io/qt-5/qgraphicsview.html#CacheModeFlag-enum
        CacheNone                    不使用缓存
        CacheBackground              缓存背景
        '''
        self.setCacheMode(self.CacheBackground)
        '''
        #参考 http://doc.qt.io/qt-5/qgraphicsview.html#DragMode-enum
        NoDrag                       什么都没发生; 鼠标事件被忽略。
        ScrollHandDrag               光标变成指针,拖动鼠标将滚动滚动条。 该模式可以在交互式和非交互式模式下工作。
        RubberBandDrag               拖动鼠标将设置橡皮筋几何形状,并选择橡皮筋所覆盖的所有项目。 对于非交互式视图,此模式被禁用。
        '''
        self.setDragMode(self.ScrollHandDrag)
        '''
        #参考 http://doc.qt.io/qt-5/qgraphicsview.html#OptimizationFlag-enum
        DontClipPainter              已过时
        DontSavePainterState         渲染时,QGraphicsView在渲染背景或前景时以及渲染每个项目时保护painter状态(请参阅QPainter.save())。 这允许你离开painter处于改变状态(即你可以调用QPainter.setPen()或QPainter.setBrush(),而不需要在绘制之后恢复状态)。 但是,如果项目一致地恢复状态,则应启用此标志以防止QGraphicsView执行相同的操作。
        DontAdjustForAntialiasing    禁用QGraphicsView的抗锯齿自动调整曝光区域。 在QGraphicsItem.boundingRect()的边界上渲染反锯齿线的项目可能会导致渲染部分线外。 为了防止渲染失真,QGraphicsView在所有方向上将所有曝光区域扩展2个像素。 如果启用此标志,QGraphicsView将不再执行这些调整,最大限度地减少需要重绘的区域,从而提高性能。 一个常见的副作用是,使用抗锯齿功能进行绘制的项目可能会在移动时在画面上留下绘画痕迹。
        IndirectPainting             从Qt 4.6开始,恢复调用QGraphicsView.drawItems()和QGraphicsScene.drawItems()的旧绘画算法。 仅用于与旧代码的兼容性。
        '''
        self.setOptimizationFlag(self.DontSavePainterState)
        '''
        #参考 http://doc.qt.io/qt-5/qpainter.html#RenderHint-enum
        Antialiasing                 抗锯齿
        TextAntialiasing             文本抗锯齿
        SmoothPixmapTransform        平滑像素变换算法
        HighQualityAntialiasing      请改用Antialiasing
        NonCosmeticDefaultPen        已过时
        Qt4CompatiblePainting        从Qt4移植到Qt5可能有用
        '''
        self.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing
                            | QPainter.SmoothPixmapTransform)
        if QGLFormat.hasOpenGL():
            self.setRenderHint(QPainter.HighQualityAntialiasing)
        '''
        #当视图被调整大小时,视图如何定位场景。使用这个属性来决定当视口控件的大小改变时,如何在视口中定位场景。 缺省行为NoAnchor在调整大小的过程中不改变场景的位置; 视图的左上角将显示为在调整大小时被锚定。请注意,只有场景的一部分可见(即有滚动条时),此属性的效果才明显。 否则,如果整个场景适合视图,QGraphicsScene使用视图对齐将视景中的场景定位。 
        #参考 http://doc.qt.io/qt-5/qgraphicsview.html#ViewportAnchor-enum
        NoAnchor                     视图保持场景的位置不变
        AnchorViewCenter             视图中心被用作锚点。
        AnchorUnderMouse             鼠标当前位置被用作锚点
        '''
        self.setResizeAnchor(self.AnchorUnderMouse)
        '''
        Rubber选择模式
        #参考 http://doc.qt.io/qt-5/qt.html#ItemSelectionMode-enum
        ContainsItemShape            输出列表仅包含形状完全包含在选择区域内的项目。 不包括与区域轮廓相交的项目。
        IntersectsItemShape          默认,输出列表包含其形状完全包含在选择区域内的项目以及与区域轮廓相交的项目。
        ContainsItemBoundingRect     输出列表仅包含边界矩形完全包含在选择区域内的项目。 不包括与区域轮廓相交的项目。
        IntersectsItemBoundingRect   输出列表包含边界矩形完全包含在选择区域内的项目以及与区域轮廓相交的项目。 这种方法通常用于确定需要重绘的区域。
        '''
        self.setRubberBandSelectionMode(Qt.IntersectsItemShape)
        '''
        #在转换过程中如何定位视图。QGraphicsView使用这个属性决定当变换矩阵改变时如何在视口中定位场景,并且视图的坐标系被变换。 默认行为AnchorViewCenter确保在视图中心的场景点在变换过程中保持不变(例如,在旋转时,场景将围绕视图的中心旋转)。请注意,只有场景的一部分可见(即有滚动条时),此属性的效果才明显。 否则,如果整个场景适合视图,QGraphicsScene使用视图对齐将视景中的场景定位。
        #参考 http://doc.qt.io/qt-5/qgraphicsview.html#ViewportAnchor-enum
        NoAnchor                     视图保持场景的位置不变
        AnchorViewCenter             视图中心被用作锚点。
        AnchorUnderMouse             鼠标当前位置被用作锚点
        '''
        self.setTransformationAnchor(self.AnchorUnderMouse)
        #         if QGLFormat.hasOpenGL():  # 如果开启了OpenGL则使用OpenGL Widget
        #             self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))
        '''
        #参考 http://doc.qt.io/qt-5/qgraphicsview.html#ViewportUpdateMode-enum
        FullViewportUpdate           当场景的任何可见部分改变或重新显示时,QGraphicsView将更新整个视口。 当QGraphicsView花费更多的时间来计算绘制的内容(比如重复更新很多小项目)时,这种方法是最快的。 这是不支持部分更新(如QGLWidget)的视口以及需要禁用滚动优化的视口的首选更新模式。
        MinimalViewportUpdate        QGraphicsView将确定需要重绘的最小视口区域,通过避免重绘未改变的区域来最小化绘图时间。 这是QGraphicsView的默认模式。 虽然这种方法提供了一般的最佳性能,但如果场景中有很多小的可见变化,QGraphicsView最终可能花费更多的时间来寻找最小化的方法。
        SmartViewportUpdate          QGraphicsView将尝试通过分析需要重绘的区域来找到最佳的更新模式。
        BoundingRectViewportUpdate   视口中所有更改的边界矩形将被重绘。 这种模式的优点是,QGraphicsView只搜索一个区域的变化,最大限度地减少了花在确定需要重绘的时间。 缺点是还没有改变的地方也需要重新绘制。
        NoViewportUpdate             当场景改变时,QGraphicsView将永远不会更新它的视口。 预计用户将控制所有更新。 此模式禁用QGraphicsView中的所有(可能较慢)项目可见性测试,适用于要求固定帧速率或视口以其他方式在外部进行更新的场景。
        '''
        self.setViewportUpdateMode(self.SmartViewportUpdate)
        # 设置场景(根据地图的经纬度,并让原点显示在屏幕中间)
        self._scene = QGraphicsScene(-180, -90, 360, 180, self)
        self.setScene(self._scene)

        # 初始化地图
        self.initMap()
コード例 #25
0
    def __init__(self):
        super(MainWindow, self).__init__()

        self.currentPath = ""

        self.view = SvgView()

        fileMenu = QMenu("&File", self)
        openAction = fileMenu.addAction("&Open...")
        openAction.setShortcut("Ctrl+O")
        quitAction = fileMenu.addAction("E&xit")
        quitAction.setShortcut("Ctrl+Q")

        self.menuBar().addMenu(fileMenu)

        viewMenu = QMenu("&View", self)
        self.backgroundAction = viewMenu.addAction("&Background")
        self.backgroundAction.setEnabled(False)
        self.backgroundAction.setCheckable(True)
        self.backgroundAction.setChecked(False)
        self.backgroundAction.toggled.connect(self.view.setViewBackground)

        self.outlineAction = viewMenu.addAction("&Outline")
        self.outlineAction.setEnabled(False)
        self.outlineAction.setCheckable(True)
        self.outlineAction.setChecked(True)
        self.outlineAction.toggled.connect(self.view.setViewOutline)

        self.menuBar().addMenu(viewMenu)

        rendererMenu = QMenu("&Renderer", self)
        self.nativeAction = rendererMenu.addAction("&Native")
        self.nativeAction.setCheckable(True)
        self.nativeAction.setChecked(True)

        if QGLFormat.hasOpenGL():
            self.glAction = rendererMenu.addAction("&OpenGL")
            self.glAction.setCheckable(True)

        self.imageAction = rendererMenu.addAction("&Image")
        self.imageAction.setCheckable(True)

        if QGLFormat.hasOpenGL():
            rendererMenu.addSeparator()
            self.highQualityAntialiasingAction = rendererMenu.addAction(
                "&High Quality Antialiasing")
            self.highQualityAntialiasingAction.setEnabled(False)
            self.highQualityAntialiasingAction.setCheckable(True)
            self.highQualityAntialiasingAction.setChecked(False)
            self.highQualityAntialiasingAction.toggled.connect(
                self.view.setHighQualityAntialiasing)

        rendererGroup = QActionGroup(self)
        rendererGroup.addAction(self.nativeAction)

        if QGLFormat.hasOpenGL():
            rendererGroup.addAction(self.glAction)

        rendererGroup.addAction(self.imageAction)

        self.menuBar().addMenu(rendererMenu)

        openAction.triggered.connect(self.openFile)
        quitAction.triggered.connect(QApplication.instance().quit)
        rendererGroup.triggered.connect(self.setRenderer)

        self.setCentralWidget(self.view)
        self.setWindowTitle("SVG Viewer")
コード例 #26
0
ファイル: view.py プロジェクト: bsdo64/qt_apps
    def __init__(self, name, parent=None):
        super().__init__(parent)

        self.setFrameStyle(QFrame.Sunken | QFrame.StyledPanel)
        self.graphicsView = GraphicsView(self)
        self.graphicsView.setRenderHint(QPainter.Antialiasing, False)
        self.graphicsView.setDragMode(QGraphicsView.RubberBandDrag)
        self.graphicsView.setOptimizationFlags(
            QGraphicsView.DontSavePainterState)
        self.graphicsView.setViewportUpdateMode(
            QGraphicsView.SmartViewportUpdate)
        self.graphicsView.setTransformationAnchor(
            QGraphicsView.AnchorUnderMouse)

        size = self.style().pixelMetric(QStyle.PM_ToolBarIconSize)
        iconSize = QSize(size, size)

        zoomInIcon = QToolButton()
        zoomInIcon.setAutoRepeat(True)
        zoomInIcon.setAutoRepeatInterval(33)
        zoomInIcon.setAutoRepeatDelay(0)
        zoomInIcon.setIcon(QIcon(QPixmap(':/images/zoomin.png')))
        zoomInIcon.setIconSize(iconSize)
        zoomOutIcon = QToolButton()
        zoomOutIcon.setAutoRepeat(True)
        zoomOutIcon.setAutoRepeatInterval(33)
        zoomOutIcon.setAutoRepeatDelay(0)
        zoomOutIcon.setIcon(QIcon(QPixmap(':/images/zoomout.png')))
        zoomOutIcon.setIconSize(iconSize)
        self.zoomSlider = QSlider()
        self.zoomSlider.setMinimum(0)
        self.zoomSlider.setMaximum(500)
        self.zoomSlider.setValue(250)
        self.zoomSlider.setTickPosition(QSlider.TicksRight)

        zoomSliderLayout = QVBoxLayout()
        zoomSliderLayout.addWidget(zoomInIcon)
        zoomSliderLayout.addWidget(self.zoomSlider)
        zoomSliderLayout.addWidget(zoomOutIcon)

        rotateLeftIcon = QToolButton()
        rotateLeftIcon.setIcon(QIcon(QPixmap(':/images/rotateleft.png')))
        rotateLeftIcon.setIconSize(iconSize)
        rotateRightIcon = QToolButton()
        rotateRightIcon.setIcon(QIcon(QPixmap(':/images/rotateright.png')))
        rotateRightIcon.setIconSize(iconSize)
        self.rotateSlider = QSlider()
        self.rotateSlider.setOrientation(Qt.Horizontal)
        self.rotateSlider.setMinimum(-360)
        self.rotateSlider.setMaximum(360)
        self.rotateSlider.setValue(0)
        self.rotateSlider.setTickPosition(QSlider.TicksBelow)

        rotateSliderLayout = QHBoxLayout()
        rotateSliderLayout.addWidget(rotateLeftIcon)
        rotateSliderLayout.addWidget(self.rotateSlider)
        rotateSliderLayout.addWidget(rotateRightIcon)

        self.resetButton = QToolButton()
        self.resetButton.setText('0')
        self.resetButton.setEnabled(False)

        labelLayout = QHBoxLayout()
        self.label = QLabel(name)
        self.label2 = QLabel("Pointer Mode")
        self.selectModeButton = QToolButton()
        self.selectModeButton.setText("Select")
        self.selectModeButton.setCheckable(True)
        self.selectModeButton.setChecked(True)
        self.dragModeButton = QToolButton()
        self.dragModeButton.setText("Drag")
        self.dragModeButton.setCheckable(True)
        self.dragModeButton.setChecked(False)
        self.openGlButton = QToolButton()
        self.openGlButton.setText("OpenGL")
        self.openGlButton.setCheckable(True)
        self.openGlButton.setEnabled(QGLFormat.hasOpenGL())
        self.antialiasButton = QToolButton()
        self.antialiasButton.setText("Antialiasing")
        self.antialiasButton.setCheckable(True)
        self.antialiasButton.setChecked(False)

        self.printButton = QToolButton()
        self.printButton.setIcon(QIcon(QPixmap(":/images/fileprint.png")))

        pointerModeGroup = QButtonGroup(self)
        pointerModeGroup.setExclusive(True)
        pointerModeGroup.addButton(self.selectModeButton)
        pointerModeGroup.addButton(self.dragModeButton)

        labelLayout.addWidget(self.label)
        labelLayout.addStretch()
        labelLayout.addWidget(self.label2)
        labelLayout.addWidget(self.selectModeButton)
        labelLayout.addWidget(self.dragModeButton)
        labelLayout.addStretch()
        labelLayout.addWidget(self.antialiasButton)
        labelLayout.addWidget(self.openGlButton)
        labelLayout.addWidget(self.printButton)

        topLayout = QGridLayout()
        topLayout.addLayout(labelLayout, 0, 0)
        topLayout.addWidget(self.graphicsView, 1, 0)
        topLayout.addLayout(zoomSliderLayout, 1, 1)
        topLayout.addLayout(rotateSliderLayout, 2, 0)
        topLayout.addWidget(self.resetButton, 2, 1)
        self.setLayout(topLayout)

        self.resetButton.clicked.connect(self.resetView)
        self.zoomSlider.valueChanged.connect(self.setupMatrix)
        self.rotateSlider.valueChanged.connect(self.setupMatrix)
        self.graphicsView.verticalScrollBar().valueChanged.connect(
            self.setResetButtonEnabled)
        self.graphicsView.horizontalScrollBar().valueChanged.connect(
            self.setResetButtonEnabled)
        self.selectModeButton.toggled.connect(self.togglePointerMode)
        self.dragModeButton.toggled.connect(self.togglePointerMode)
        self.antialiasButton.toggled.connect(self.toggleAntialiasing)
        self.openGlButton.toggled.connect(self.toggleOpenGL)
        rotateLeftIcon.clicked.connect(self.rotateLeft)
        rotateRightIcon.clicked.connect(self.rotateRight)
        zoomInIcon.clicked.connect(self.zoomIn)
        zoomOutIcon.clicked.connect(self.zoomOut)
        self.printButton.clicked.connect(self.print)

        self.setupMatrix()
コード例 #27
0
                increment = 10
                val = self.remainder + self.rate / 0.02

            self.selValues[4] += int(val) * increment
            self.remainder = val - int(val)

        self.update_lcd()
        if self.btn_pressed is not None:
            QTimer.singleShot(200, self.updateAPValues)


if __name__ == "__main__":
    qapp = QApplication([])

    # Check and set OpenGL capabilities
    if not QGLFormat.hasOpenGL():
        raise RuntimeError('No OpenGL support detected for this system!')
    else:
        f = QGLFormat()
        f.setVersion(3, 3)
        f.setProfile(QGLFormat.CoreProfile)
        f.setDoubleBuffer(True)
        QGLFormat.setDefaultFormat(f)
        print('QGLWidget initialized for OpenGL version %d.%d' %
              (f.majorVersion(), f.minorVersion()))

    blip = BlipDriver()
    blip.show()

    gltimer = QTimer(qapp)
    gltimer.timeout.connect(blip.updateGL)
コード例 #28
0
    def __init__(self, size, parent=None):
        super(PadNavigator, self).__init__(parent)

        self.form = Ui_Form()

        splash = SplashItem()
        splash.setZValue(1)

        pad = FlippablePad(size)
        flipRotation = QGraphicsRotation(pad)
        xRotation = QGraphicsRotation(pad)
        yRotation = QGraphicsRotation(pad)
        flipRotation.setAxis(Qt.YAxis)
        xRotation.setAxis(Qt.YAxis)
        yRotation.setAxis(Qt.XAxis)
        pad.setTransformations([flipRotation, xRotation, yRotation])

        backItem = QGraphicsProxyWidget(pad)
        widget = QWidget()
        self.form.setupUi(widget)
        self.form.hostName.setFocus()
        backItem.setWidget(widget)
        backItem.setVisible(False)
        backItem.setFocus()
        backItem.setCacheMode(QGraphicsItem.ItemCoordinateCache)
        r = backItem.rect()
        backItem.setTransform(QTransform().rotate(180, Qt.YAxis).translate(
            -r.width() / 2, -r.height() / 2))

        selectionItem = RoundRectItem(QRectF(-60, -60, 120, 120),
                                      QColor(Qt.gray), pad)
        selectionItem.setZValue(0.5)

        smoothSplashMove = QPropertyAnimation(splash)
        smoothSplashOpacity = QPropertyAnimation(splash)
        smoothSplashMove.setEasingCurve(QEasingCurve.InQuad)
        smoothSplashMove.setDuration(250)
        smoothSplashOpacity.setDuration(250)

        smoothXSelection = QPropertyAnimation(selectionItem)
        smoothYSelection = QPropertyAnimation(selectionItem)
        smoothXRotation = QPropertyAnimation(xRotation)
        smoothYRotation = QPropertyAnimation(yRotation)
        smoothXSelection.setDuration(125)
        smoothYSelection.setDuration(125)
        smoothXRotation.setDuration(125)
        smoothYRotation.setDuration(125)
        smoothXSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYRotation.setEasingCurve(QEasingCurve.InOutQuad)

        smoothFlipRotation = QPropertyAnimation(flipRotation)
        smoothFlipScale = QPropertyAnimation(pad)
        smoothFlipXRotation = QPropertyAnimation(xRotation)
        smoothFlipYRotation = QPropertyAnimation(yRotation)
        flipAnimation = QParallelAnimationGroup(self)
        smoothFlipScale.setDuration(500)
        smoothFlipRotation.setDuration(500)
        smoothFlipXRotation.setDuration(500)
        smoothFlipYRotation.setDuration(500)
        smoothFlipScale.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipYRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipScale.setKeyValueAt(0, 1.0)
        smoothFlipScale.setKeyValueAt(0.5, 0.7)
        smoothFlipScale.setKeyValueAt(1, 1.0)
        flipAnimation.addAnimation(smoothFlipRotation)
        flipAnimation.addAnimation(smoothFlipScale)
        flipAnimation.addAnimation(smoothFlipXRotation)
        flipAnimation.addAnimation(smoothFlipYRotation)

        setVariablesSequence = QSequentialAnimationGroup()
        setFillAnimation = QPropertyAnimation(pad)
        setBackItemVisibleAnimation = QPropertyAnimation(backItem)
        setSelectionItemVisibleAnimation = QPropertyAnimation(selectionItem)
        setFillAnimation.setDuration(0)
        setBackItemVisibleAnimation.setDuration(0)
        setSelectionItemVisibleAnimation.setDuration(0)
        setVariablesSequence.addPause(250)
        setVariablesSequence.addAnimation(setBackItemVisibleAnimation)
        setVariablesSequence.addAnimation(setSelectionItemVisibleAnimation)
        setVariablesSequence.addAnimation(setFillAnimation)
        flipAnimation.addAnimation(setVariablesSequence)

        stateMachine = QStateMachine(self)
        splashState = QState(stateMachine)
        frontState = QState(stateMachine)
        historyState = QHistoryState(frontState)
        backState = QState(stateMachine)

        frontState.assignProperty(pad, "fill", False)
        frontState.assignProperty(splash, "opacity", 0.0)
        frontState.assignProperty(backItem, "visible", False)
        frontState.assignProperty(flipRotation, "angle", 0.0)
        frontState.assignProperty(selectionItem, "visible", True)

        backState.assignProperty(pad, "fill", True)
        backState.assignProperty(backItem, "visible", True)
        backState.assignProperty(xRotation, "angle", 0.0)
        backState.assignProperty(yRotation, "angle", 0.0)
        backState.assignProperty(flipRotation, "angle", 180.0)
        backState.assignProperty(selectionItem, "visible", False)

        stateMachine.addDefaultAnimation(smoothXRotation)
        stateMachine.addDefaultAnimation(smoothYRotation)
        stateMachine.addDefaultAnimation(smoothXSelection)
        stateMachine.addDefaultAnimation(smoothYSelection)
        stateMachine.setInitialState(splashState)

        anyKeyTransition = QEventTransition(self, QEvent.KeyPress, splashState)
        anyKeyTransition.setTargetState(frontState)
        anyKeyTransition.addAnimation(smoothSplashMove)
        anyKeyTransition.addAnimation(smoothSplashOpacity)

        enterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                              Qt.Key_Enter, backState)
        returnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                               Qt.Key_Return, backState)
        backEnterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                                  Qt.Key_Enter, frontState)
        backReturnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                                   Qt.Key_Return, frontState)
        enterTransition.setTargetState(historyState)
        returnTransition.setTargetState(historyState)
        backEnterTransition.setTargetState(backState)
        backReturnTransition.setTargetState(backState)
        enterTransition.addAnimation(flipAnimation)
        returnTransition.addAnimation(flipAnimation)
        backEnterTransition.addAnimation(flipAnimation)
        backReturnTransition.addAnimation(flipAnimation)

        columns = size.width()
        rows = size.height()
        stateGrid = []
        for y in range(rows):
            stateGrid.append([QState(frontState) for _ in range(columns)])

        frontState.setInitialState(stateGrid[0][0])
        selectionItem.setPos(pad.iconAt(0, 0).pos())

        for y in range(rows):
            for x in range(columns):
                state = stateGrid[y][x]

                rightTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                                      Qt.Key_Right, state)
                leftTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                                     Qt.Key_Left, state)
                downTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                                     Qt.Key_Down, state)
                upTransition = QKeyEventTransition(self, QEvent.KeyPress,
                                                   Qt.Key_Up, state)

                rightTransition.setTargetState(stateGrid[y][(x + 1) % columns])
                leftTransition.setTargetState(
                    stateGrid[y][((x - 1) + columns) % columns])
                downTransition.setTargetState(stateGrid[(y + 1) % rows][x])
                upTransition.setTargetState(stateGrid[((y - 1) + rows) %
                                                      rows][x])

                icon = pad.iconAt(x, y)
                state.assignProperty(xRotation, "angle", -icon.x() / 6.0)
                state.assignProperty(yRotation, "angle", icon.y() / 6.0)
                state.assignProperty(selectionItem, "x", icon.x())
                state.assignProperty(selectionItem, "y", icon.y())
                frontState.assignProperty(icon, "visible", True)
                backState.assignProperty(icon, "visible", False)

                setIconVisibleAnimation = QPropertyAnimation(icon)
                setIconVisibleAnimation.setDuration(0)
                setVariablesSequence.addAnimation(setIconVisibleAnimation)

        scene = QGraphicsScene(self)
        scene.setBackgroundBrush(
            QBrush(QPixmap(":/images/blue_angle_swirl.jpg")))
        scene.setItemIndexMethod(QGraphicsScene.NoIndex)
        scene.addItem(pad)
        scene.setSceneRect(scene.itemsBoundingRect())
        self.setScene(scene)

        sbr = splash.boundingRect()
        splash.setPos(-sbr.width() / 2, scene.sceneRect().top() - 2)
        frontState.assignProperty(splash, "y", splash.y() - 100.0)
        scene.addItem(splash)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setMinimumSize(50, 50)
        self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
        self.setCacheMode(QGraphicsView.CacheBackground)
        self.setRenderHints(QPainter.Antialiasing
                            | QPainter.SmoothPixmapTransform
                            | QPainter.TextAntialiasing)

        if QGLFormat.hasOpenGL():
            self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))

        stateMachine.start()