コード例 #1
0
    def _animate_expand(self, value):
        size_anim = qc.QPropertyAnimation(self, 'geometry')

        geometry = self.geometry()
        width = geometry.width()
        x, y, _, _ = geometry.getCoords()

        size_start = qc.QRect(x, y, width, int(not value) * 180)
        size_end = qc.QRect(x, y, width, value * 180)

        size_anim.setStartValue(size_start)
        size_anim.setEndValue(size_end)
        size_anim.setDuration(200)

        size_anim_curve = qc.QEasingCurve()
        if value:
            size_anim_curve.setType(qc.QEasingCurve.InQuad)
        else:
            size_anim_curve.setType(qc.QEasingCurve.OutQuad)
        size_anim.setEasingCurve(size_anim_curve)

        self.animation = size_anim
        size_anim.valueChanged.connect(self._force_resize)

        if not value:
            size_anim.finished.connect(self._delete_widget)
        size_anim.start(qc.QAbstractAnimation.DeleteWhenStopped)
コード例 #2
0
ファイル: Preferences.py プロジェクト: osagha/Kataja
    def prepare_easing_curve(self, curve_type, frames):
        """

        :param curve_type:
        :param frames:
        :return:
        """
        curve = QtCore.QEasingCurve(getattr(QtCore.QEasingCurve, curve_type))

        def curve_value(x):
            """

            :param x:
            :return:
            """
            z = 1.0 / frames
            y = float(x) / frames
            return z + y - curve.valueForProgress(y)

        self.easing_curve = [curve_value(x) for x in range(frames)]
        # self.easing_curve = [(1.0 / self.move_frames) + (float(x) /
        # self.move_frames) - curve.valueForProgress(float(x) /
        # self.move_frames) for x in range(self.move_frames)]
        # self.easing_curve=[(float(
        # x)/self.move_frames)-curve.valueForProgress(float(
        # x)/self.move_frames) for x in range(self.move_frames)]
        s = sum(self.easing_curve)
        self.easing_curve = [x / s for x in self.easing_curve]
        self.curve = curve
コード例 #3
0
    def __init__(self):
        super().__init__()

        ################
        # Create Chart #
        ################

        # Create qchart object
        chart = qtch.QChart(title=self.chart_title)
        self.setChart(chart)

        # Setup series
        series = qtch.QStackedBarSeries()
        chart.addSeries(series)
        self.phys_set = qtch.QBarSet("Physical")
        self.swap_set = qtch.QBarSet("Swap")
        series.append(self.phys_set)
        series.append(self.swap_set)

        # Setup Data
        self.data = deque([(0, 0)] * self.num_data_points,
                          maxlen=self.num_data_points)
        for phys, swap in self.data:
            self.phys_set.append(phys)
            self.swap_set.append(swap)

        # Setup Axes
        x_axis = qtch.QValueAxis()
        x_axis.setRange(0, self.num_data_points)
        x_axis.setLabelsVisible(False)
        y_axis = qtch.QValueAxis()
        y_axis.setRange(0, 100)
        chart.setAxisX(x_axis, series)
        chart.setAxisY(y_axis, series)

        # Start refresh timer
        self.timer = qtc.QTimer(interval=1000, timeout=self.refresh_stats)
        self.timer.start()

        ###################
        # Style the chart #
        ###################
        chart.setAnimationOptions(qtch.QChart.AllAnimations)

        chart.setAnimationEasingCurve(
            qtc.QEasingCurve(qtc.QEasingCurve.OutBounce))
        chart.setAnimationDuration(1000)

        # Add shadow around the chart area
        chart.setDropShadowEnabled(True)

        # Set the theme
        chart.setTheme(qtch.QChart.ChartThemeBrownSand)

        # Configure a background brush
        gradient = qtg.QLinearGradient(chart.plotArea().topLeft(),
                                       chart.plotArea().bottomRight())
        gradient.setColorAt(0, qtg.QColor("#333"))
        gradient.setColorAt(1, qtg.QColor("#660"))
        chart.setBackgroundBrush(qtg.QBrush(gradient))

        # Background Pen draws a border around the chart
        chart.setBackgroundPen(qtg.QPen(qtg.QColor('black'), 5))

        # Set title font and brush
        chart.setTitleBrush(qtg.QBrush(qtc.Qt.white))
        chart.setTitleFont(qtg.QFont('Impact', 32, qtg.QFont.Bold))

        # Set axes fonts and brushes
        axis_font = qtg.QFont('Mono', 16)
        axis_brush = qtg.QBrush(qtg.QColor('#EEF'))
        y_axis.setLabelsFont(axis_font)
        y_axis.setLabelsBrush(axis_brush)

        # Grid lines
        grid_pen = qtg.QPen(qtg.QColor('silver'))
        grid_pen.setDashPattern([1, 1, 0, 1])
        x_axis.setGridLinePen(grid_pen)
        y_axis.setGridLinePen(grid_pen)
        y_axis.setTickCount(11)

        #Shades
        y_axis.setShadesVisible(True)
        y_axis.setShadesColor(qtg.QColor('#884'))

        # Styling the legend
        legend = chart.legend()

        # Background
        legend.setBackgroundVisible(True)
        legend.setBrush(qtg.QBrush(qtg.QColor('white')))

        # Font
        legend.setFont(qtg.QFont('Courier', 14))
        legend.setLabelColor(qtc.Qt.darkRed)

        # Markers
        legend.setMarkerShape(qtch.QLegend.MarkerShapeCircle)
コード例 #4
0
ファイル: gui.py プロジェクト: erkanisik1/pds
    def _animate(self, direction, move_direction, start, stop, duration, just_resize = False, dont_animate = False):

        # Stop all running animations
        for timeline in (self.__sceneX, self.__sceneY, self.__sceneF):
            timeline.stop()

        # Re-initialize Timelines
        self._initializeTimeLines()

        # Use given duration time or use the default one
        duration = duration if duration > 0 else self._duration

        # Set last used animations with given values
        self.__last_stop           = stop
        self.__last_start          = start
        self.__last_move_direction = move_direction
        self.__last_direction      = direction

        # Set X coordinate timeline settings
        self.__sceneX.setDirection(move_direction)
        self.__sceneX.setEasingCurve(QtCore.QEasingCurve(self._animation))
        self.__sceneX.setDuration(duration)
        self.__sceneX.setUpdateInterval(20)

        # Set Y coordinate timeline settings
        self.__sceneY.setDirection(move_direction)
        self.__sceneY.setEasingCurve(QtCore.QEasingCurve(self._animation))
        self.__sceneY.setDuration(duration)
        self.__sceneY.setUpdateInterval(20)

        # Update duration for overlay fade effect
        self.__sceneF.setDuration(self.__overlay_duration)

        # Get current sizes
        p_width  = self.__parent.width()
        p_height = self.__parent.height()
        width  = self.width()
        height = self.height()

        # Calculate new positions for given points
        limits = {TOPLEFT   : [0, 0],
                  TOPCENTER : [p_width/2 - width/2, 0],
                  TOPRIGHT  : [p_width - width, 0],
                  MIDLEFT   : [0, p_height/2 - height/2],
                  MIDCENTER : [p_width/2 - width/2, p_height/2 - height/2],
                  MIDRIGHT  : [p_width - width, p_height/2 - height/2],
                  BOTLEFT   : [0, p_height - height],
                  BOTCENTER : [p_width/2 - width/2, p_height - height],
                  BOTRIGHT  : [p_width - width, p_height - height],
                  CURRENT   : [self.x(), self.y()]}

        # Get start and stop positions
        # I used deepcopy in case of selecting same positions for start and stop
        start_pos = copy.deepcopy(limits[start])
        stop_pos  = copy.deepcopy(limits[stop])

        # Poor developer's debug mechanism.
        # print start_pos, stop_pos, width, height

        # Update start and stop positions for given direction
        if direction == IN:
            self.show()
            if start in (TOPLEFT, MIDLEFT, BOTLEFT):
                start_pos[0] -= width
            elif start in (TOPRIGHT, MIDRIGHT, BOTRIGHT):
                start_pos[0] += width
            elif start == TOPCENTER:
                start_pos[1] -= height
            elif start == BOTCENTER:
                start_pos[1] += height
        elif direction == OUT:
            if stop in (TOPLEFT, MIDLEFT, BOTLEFT):
                stop_pos[0] -= width
            elif stop in (TOPRIGHT, MIDRIGHT, BOTRIGHT):
                stop_pos[0] += width
            elif stop == TOPCENTER:
                stop_pos[1] -= height
            elif stop == BOTCENTER:
                stop_pos[1] += height

        # Move the widget to calculated start position
        self.move(start_pos[0], start_pos[1])

        # Set calculated start and stop positions
        self.__sceneX.setFrameRange(start_pos[0], stop_pos[0])
        self.__sceneX.frameChanged.connect(lambda x: self.move(x, self.y()))
        self.__sceneY.setFrameRange(start_pos[1], stop_pos[1])
        self.__sceneY.frameChanged.connect(lambda y: self.move(self.x(), y))

        # Run predefined callback functions for given direction
        self.runCallBacks(direction)
        self._disable_parent()

        # Hide widget when direction is OUT
        self.__sceneX.finished.connect(lambda: self.setHidden(direction == OUT))

        # Run finish callbacks
        self.__sceneX.finished.connect(lambda: self.runCallBacks(FINISHED))

        # Show/hide overlay if overlay enabled
        if self.__overlay_enabled:
            self.__overlay.show()
            self.__sceneX.finished.connect(lambda: self.__overlay.setHidden(direction == OUT))
        else:
            self.__overlay.hide()

        if dont_animate:
            self.__overlay.setHidden(direction == OUT)
            self.setHidden(direction == OUT)
            self.runCallBacks(FINISHED)
        else:
            # Start the animation !
            if self.__sceneX.state() == QtCore.QTimeLine.NotRunning:
                self.__sceneX.start()
                self.__sceneY.start()
                if not just_resize:
                    # The animation will just work for repositioning the widget,
                    # so we dont need overlay fade animation
                    self.__sceneF.start()

        # Return the X coordinate timeline obj to use as reference for next animation
        return self.__sceneX
コード例 #5
0
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        #        self.ui=Ui_sequenceGUI()
        #        self.ui.setupUi(self)
        self.motionList = [[
            'grasp',
            [
                [
                    0,
                    [
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0
                    ]
                ],
                [
                    1,
                    [
                        10, 12, 13, 14, 15, 0, 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0
                    ]
                ],
                [
                    3,
                    [
                        40, 12, 13, 14, 15, 0, 0, 3, 5, 0, 0, 0, 40, 0, 0, 0,
                        2, 0, 0, 0, 0, 0, 0, 0, 0, 0
                    ]
                ],
                [
                    6,
                    [
                        50, 12, 73, 14, 15, 0, 0, 8, 5, 0, 0, 0, 40, 0, 0, 0,
                        34, 0, 0, 0, 0, 0, 0, 0, 0, 0
                    ]
                ],
                [
                    10,
                    [
                        30, 12, 53, 14, 15, 0, 0, 3, 5, 0, 0, 0, 40, 0, 0, 0,
                        88, 0, 0, 0, 0, 0, 0, 0, 0, 0
                    ]
                ],
                [
                    11,
                    [
                        10, 14, 63, 44, 15, 0, 0, 3, 5, 0, 0, 0, 40, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                    ]
                ],
                [
                    15,
                    [
                        40, 12, 13, 14, 15, 0, 0, 3, 5, 0, 0, 0, 40, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                    ]
                ],
            ]
        ],
                           [
                               'wave',
                               [[
                                   0,
                                   [
                                       1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                                   ]
                               ],
                                [
                                    1,
                                    [
                                        10, 12, 13, 14, 15, 0, 0, 3, 4, 0, 0,
                                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0, 0
                                    ]
                                ]]
                           ]]

        with open("configurationSave.txt", "rb") as fp:  # Unpickling
            b = pickle.load(fp)
            self.fromConfigure = b

        self.motionList = self.fromConfigure[1]

        self.iconList = []
        self.currentMotion = self.motionList[0][0]
        self.currentEndTime = self.motionList[0][1][-1][0]
        self.gridLayout = QtWidgets.QHBoxLayout(self)
        self.toSave = []

        self.tree = QtWidgets.QColumnView(self)

        self.motionReStart = QtWidgets.QPushButton(self)
        self.gridLayout.addWidget(self.motionReStart)
        self.motionContinuePause = QtWidgets.QPushButton(self)
        self.gridLayout.addWidget(self.motionContinuePause)
        self.motionContinuePause.setCheckable(True)
        self.motionContinuePause.setText('Motion go!')
        self.motionContinuePause.setStyleSheet(
            "background-color:rgb(122,255,122)")
        self.timeLine = QtCore.QTimeLine(self.currentEndTime * 1000, self)
        self.timeLine.setCurveShape(QtCore.QTimeLine.LinearCurve)
        self.timeLine.setUpdateInterval(100)
        self.gridLayout.addWidget(self.tree)
        self.motionReStart.clicked.connect(self.slotMotionReStart)
        self.motionContinuePause.clicked.connect(self.slotMotionContinuePause)

        self.timeLine.valueChanged.connect(self.slotTimeLineUpdate)
        self.timeLine.finished.connect(self.slotMotionReStart)
        self.model = QtGui.QStandardItemModel(self.tree)

        self.trajTimeArray = np.array(1)
        self.trajAngleArray = np.array(1)
        self.traj = []
        self.easingCurve = QtCore.QEasingCurve(QtCore.QEasingCurve.Linear)
        self.trajGeneration()

        self.tree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tree.customContextMenuRequested.connect(self.showContextMenu)
        self.sendDatHis = []

        for i in range(len(self.motionList)):
            targetMotionName = self.motionList[i][0]
            targetMotion = self.motionList[i][1]
            iconMo = QtGui.QIcon('icons/iconMotion.png')
            itemMotion = QtGui.QStandardItem(iconMo, targetMotionName)
            for targetFrameTime, targetFrameAngle in targetMotion:
                iconFr = QtGui.QIcon('icons/iconTime.jpg')
                itemFrame = QtGui.QStandardItem(iconFr, str(targetFrameTime))
                for j in range(len(targetFrameAngle)):
                    iconAn = QtGui.QIcon('icons/iconNumber{:d}'.format(j))
                    itemFrame.appendRow(
                        QtGui.QStandardItem(iconAn, str(targetFrameAngle[j])))
                itemMotion.appendRow(itemFrame)
            self.model.appendRow(itemMotion)

        a = self.tree.iconSize()
        a *= 2
        self.tree.setIconSize(a)
        self.tree.setModel(self.model)

        self.model.itemChanged.connect(self.on_item_changed)
        self.tree.clicked.connect(self.on_view_clicked)