Esempio n. 1
0
 def __init__(self):
     self.poly = QtGui.QPolygonF()
     self.pos = QtCore.QPointF(0, 0)
     self.radius = 0.0
Esempio n. 2
0
    def preview(self, printer):
        SPACE = 62
        # V_SPACE = 20

        layout = QtGui.QPageLayout()
        layout.setPageSize(QtGui.QPageSize(QtGui.QPageSize.A4))
        layout.setOrientation(QtGui.QPageLayout.Portrait)
        # layout.setMargins(20, 10, 5, 15, QtPrintSupport.QPrinter.Millimeter)
        printer.setPageLayout(layout)
        printer.setResolution(300)
        painter = QtGui.QPainter()

        painter.begin(printer)
        color = QtGui.QColor(QtCore.Qt.black)
        pen = QtGui.QPen(color)
        brush = QtGui.QBrush(color)
        font = QtGui.QFont('Segoi ui', 10)
        header_font = QtGui.QFont('Segoi ui', 14)
        painter.setPen(pen)
        painter.setBrush(brush)
        protocol_num = data.num
        protocol_date = datetime.datetime.today().strftime('%d-%m-%Y')

        # Заголовок
        # x, y = 200, 30
        x, y = 625, 94
        painter.setFont(header_font)
        painter.drawText(
            x, y,
            f'Протокол испытания № {protocol_num: <3d} от  {protocol_date}')
        painter.setFont(font)
        # Шапка
        # x = 50
        x = 156
        y += SPACE * 2.5
        painter.drawText(x, y,
                         f'Тип исполнительного устройства: {iu.dev_type}')
        y += SPACE
        painter.drawText(
            x, y,
            f'Зав. № {frm_main.auth.num}     Дата изготовления: {frm_main.auth.date}'
        )
        y += SPACE
        painter.drawText(
            x, y,
            f'Тепловоз № {frm_main.auth.locomotive}     Секция: {frm_main.auth.section}'
        )
        # Шапка таблицы
        y += SPACE * 1.5
        # w = [0, 400, 520, 620]
        w = [0, 1250, 1625, 1937]

        def print_row(row):
            nonlocal x, y
            for i, v in enumerate(row):
                painter.drawText(x + w[i], y, v)
            y += SPACE

        if data.arr:
            painter.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.black)), 4))
            points = [
                QtCore.QPointF(x + self.OFF_X + (i[0] - self.OFF_I) * self.K_X,
                               y + self.HEIGHT - self.OFF_Y - i[1] * self.K_Y)
                for i in data.arr
            ]
            points2 = [
                QtCore.QPointF(x + self.OFF_X + (i[0] - self.OFF_I) * self.K_X,
                               y + self.HEIGHT - self.OFF_Y - i[1] * self.K_Y)
                for i in data.arr_average
            ]
            painter.drawLine(x + self.OFF_X, y + self.HEIGHT - self.OFF_Y + 5,
                             x + self.OFF_X, y + self.OFF_Y)
            painter.drawLine(x + self.OFF_X - 5, y + self.HEIGHT - self.OFF_Y,
                             x + self.WIDTH - self.OFF_X,
                             y + self.HEIGHT - self.OFF_Y)

            for xx in range(0, self.WIDTH - self.OFF_X * 2,
                            int(self.K_X / 10)):
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.lightGray)), 1)
                painter.drawLine(x + self.OFF_X + xx,
                                 y + self.HEIGHT - self.OFF_Y - 5,
                                 x + self.OFF_X + xx, y + 2 * self.OFF_Y)
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.black)), 4)
                painter.drawLine(x + self.OFF_X + xx,
                                 y + self.HEIGHT - self.OFF_Y + 5,
                                 x + self.OFF_X + xx,
                                 y + self.HEIGHT - self.OFF_Y - 5)
                painter.drawText(x + self.OFF_X + xx - 25, y + self.HEIGHT - 2,
                                 f'{((xx) / self.K_X+self.OFF_I):3.1f}')
            for yy in range(1, 11):
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.lightGray)), 1)
                painter.drawLine(x + self.OFF_X + 5,
                                 y + self.HEIGHT - self.OFF_Y - yy * self.K_Y,
                                 x + self.OFF_X + self.WIDTH - 2 * self.OFF_X,
                                 y + self.HEIGHT - self.OFF_Y - yy * self.K_Y)
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.black)), 4)
                painter.drawLine(x + self.OFF_X - 5,
                                 y + self.HEIGHT - self.OFF_Y - yy * self.K_Y,
                                 x + self.OFF_X + 5,
                                 y + self.HEIGHT - self.OFF_Y - yy * self.K_Y)
                painter.drawText(
                    x - 10, y + self.HEIGHT - self.OFF_Y - yy * self.K_Y + 7,
                    f'{yy:3.1f}')
            painter.drawText(x + self.OFF_X + 10, y + self.OFF_Y + 10,
                             'Поз. инд.')
            painter.drawText(x + self.WIDTH - 30, y + self.HEIGHT - 5, 'I, A')
            i1, a1, i2, a2 = 1.3, 2.0, 2.0, 8.0
            QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.green)), 1)
            painter.drawLine(
                x + self.OFF_X + (i1 - 0.05 - self.OFF_I) * self.K_X,
                y + self.HEIGHT - self.OFF_Y - a1 * self.K_Y,
                x + self.OFF_X + (i2 - 0.05 - self.OFF_I) * self.K_X,
                y + self.HEIGHT - self.OFF_Y - a2 * self.K_Y)
            painter.drawLine(
                x + self.OFF_X + (i1 + 0.05 - self.OFF_I) * self.K_X,
                y + self.HEIGHT - self.OFF_Y - a1 * self.K_Y,
                x + self.OFF_X + (i2 + 0.05 - self.OFF_I) * self.K_X,
                y + self.HEIGHT - self.OFF_Y - a2 * self.K_Y)

            painter.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.blue)), 1))
            painter.drawPolyline(*points)

            painter.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.red)), 8))
            painter.drawPolyline(*points2)

            # painter.drawRect(x + self.WIDTH - 300, y,
            #                 x + self.WIDTH, y + 200)
            painter.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.red)), 8))
            painter.drawLine(x + self.WIDTH - 40, y + 250, x + self.WIDTH,
                             y + 250)
            painter.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.blue)), 4))
            painter.drawLine(x + self.WIDTH - 40, y + 300, x + self.WIDTH,
                             y + 300)
            painter.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.green)), 4))
            painter.drawLine(x + self.WIDTH - 40, y + 350, x + self.WIDTH,
                             y + 350)

            painter.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(QtCore.Qt.black)), 2))
            painter.drawText(x + self.WIDTH + 20, y + 250,
                             'Рабочая характеристика')
            painter.drawText(x + self.WIDTH + 20, y + 300, 'Данные измерений')
            painter.drawText(x + self.WIDTH + 20, y + 350,
                             'Норм. характеристика')

            y += 1300

        print_row(['Параметр', 'Норма', 'Факт', 'Результат'])
        y += SPACE
        # y += 20
        name = f'1. Давление масла на скорости {iu.speed[1]} об/мин, МПа'
        norm = f'не менее {iu.pressure[0]: >3.1f}'
        print_row([name, norm, '', ''])
        name = '     - при левом вращении' if iu.dir[
            0] else '     - при правом вращении'
        norm = ''
        fact = f'{data.pr[0]: <4.1f}'
        res = 'норма' if data.pr[0] >= iu.pressure[0] else 'НЕ НОРМА'
        print_row([name, norm, fact, res])
        if iu.dir[0] != iu.dir[1]:
            name = '     - при левом вращении' if iu.dir[
                1] else '     - при правом вращении'
            norm = ''
            fact = f'{data.pr[2]: <4.1f}'
            res = 'норма' if data.pr[2] >= iu.pressure[0] else 'НЕ НОРМА'
            print_row([name, norm, fact, res])

        name = f'2. Давление масла на скорости {iu.speed[2]} об/мин, МПа'
        norm = f'не менее {iu.pressure[1]: >3.1f}'
        print_row([name, norm, '', ''])
        name = '     - при левом вращении' if iu.dir[
            0] else '     - при правом вращении'
        norm = ''
        fact = f'{data.pr[1]: <4.1f}'
        res = 'норма' if data.pr[1] >= iu.pressure[1] else 'НЕ НОРМА'
        print_row([name, norm, fact, res])
        if iu.dir[0] != iu.dir[1]:
            name = '     - при левом вращении' if iu.dir[
                1] else '     - при правом вращении'
            norm = ''
            fact = f'{com.pr[3]: <4.1f}'
            res = 'норма' if data.pr[3] >= iu.pressure[1] else 'НЕ НОРМА'
            print_row([name, norm, fact, res])

        name = '3. Проверка тока ПЭ на позиции "2", А'
        norm = f'{iu.current[0]:4.3f}-{iu.current[1]:4.3f}'
        fact = f'{data.i2: <4.3f}'
        res = 'норма' if iu.current[0] <= data.i2 <= iu.current[
            1] else 'НЕ НОРМА'
        print_row([name, norm, fact, res])

        name = '4. Проверка тока ПЭ на позиции "8", А'
        norm = f'{iu.current[2]:4.3f}-{iu.current[3]:4.3f}'
        fact = f'{data.i8: <4.3f}'
        res = 'норма' if iu.current[2] <= data.i8 <= iu.current[
            3] else 'НЕ НОРМА'
        print_row([name, norm, fact, res])

        if not (iu.freq is None):
            name = '5. Проверка сигнала ДП на позиции "1", кГц'
            if data.f1 > data.f9:
                norm = 'не менее 24'
                res = 'норма' if data.f1 >= iu.freq[1] else 'НЕ НОРМА'
            else:
                norm = 'не более 20'
                res = 'норма' if 10 <= data.f1 <= iu.freq[0] else 'НЕ НОРМА'
            fact = f'{data.f1: <6.3f}'

            print_row([name, norm, fact, res])

            name = '6. Проверка сигнала ДП на позиции "9", кГц'
            if data.f1 < data.f9:
                norm = 'не менее 24'
                res = 'норма' if data.f9 >= iu.freq[1] else 'НЕ НОРМА'
            else:
                norm = 'не более 20'
                res = 'норма' if 10 <= data.f9 <= iu.freq[0] else 'НЕ НОРМА'
            fact = f'{data.f9: <6.3f}'

            print_row([name, norm, fact, res])

        if data.note:
            note = data.note.split(';')
            y += SPACE * 2.5
            painter.drawText(x, y, 'Примечание:')
            for s in note:
                y += SPACE
                painter.drawText(x + 40, y, s)

        painter.setFont(header_font)
        y += SPACE * 2.5
        painter.drawText(x, y, 'Испытание провел:')
        painter.drawText(x + 312, y,
                         f'{frm_main.auth.name1: >50}    {"_" * 20}')
        # painter.drawText(x + 100, y, '{: >50}    {}'.format(com.auth.name1, '_' * 20))

        y += SPACE * 2
        painter.drawText(x, y, 'Испытание проверил:')
        painter.drawText(x + 312, y,
                         f'{frm_main.auth.name2: >50}    {"_" * 20}')

        painter.end()
def run (x, y):
    line_width_1 = 0.75
    line_width_2 = 1
    
    icon_1 = QtWidgets.QGraphicsPathItem()
    icon_path_1 = QtGui.QPainterPath() 
    p1 = QtCore.QPointF(x+10, y+8)
    p2 = QtCore.QPointF(x+10, y+15)
    icon_path_1.addPolygon(QtGui.QPolygonF([p1, p2]))
    icon_1.setPath(icon_path_1)
    icon_1.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), line_width_1 ))
    
    icon_2 = QtWidgets.QGraphicsPathItem()
    icon_path_2 = QtGui.QPainterPath()
    p1 = QtCore.QPointF(x+5, y+15)
    p2 = QtCore.QPointF(x+15, y+15)
    p3 = QtCore.QPointF(x+10, y+25)
    p4 = QtCore.QPointF(x+5, y+15)
    icon_path_2.addPolygon(QtGui.QPolygonF([p1, p2, p3, p4]))  
    icon_2.setPath(icon_path_2)
    icon_2.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), line_width_1 ))
    
    icon_3 = QtWidgets.QGraphicsPathItem()
    icon_path_3 = QtGui.QPainterPath() 
    p1 = QtCore.QPointF(x+5, y+25)
    p2 = QtCore.QPointF(x+15, y+25)
    icon_path_3.addPolygon(QtGui.QPolygonF([p1, p2]))
    icon_3.setPath(icon_path_3)
    icon_3.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), line_width_1 ))
    
    icon_4 = QtWidgets.QGraphicsPathItem()
    icon_path_4 = QtGui.QPainterPath() 
    p1 = QtCore.QPointF(x+10, y+25)
    p2 = QtCore.QPointF(x+10, y+32)
    icon_path_4.addPolygon(QtGui.QPolygonF([p1, p2]))
    icon_4.setPath(icon_path_4)
    icon_4.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), line_width_1 ))
    
    icon_5 = QtWidgets.QGraphicsPathItem()
    icon_path_5 = QtGui.QPainterPath()
    p1 = QtCore.QPointF(x+18, y+11)
    p2 = QtCore.QPointF(x+32, y+11)
    p3 = QtCore.QPointF(x+28, y+9)
    p4 = QtCore.QPointF(x+28, y+13)
    p5 = QtCore.QPointF(x+32, y+11)
    icon_path_5.addPolygon(QtGui.QPolygonF([p1, p2, p3, p4, p5]))  
    icon_5.setPath(icon_path_5)
    icon_5.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.darkRed), line_width_2 ))
    icon_5.setBrush(QtGui.QBrush(QtGui.QColor(QtCore.Qt.darkRed)))
    
    icon_6 = QtWidgets.QGraphicsPathItem()
    icon_path_6 = QtGui.QPainterPath()
    p1 = QtCore.QPointF(x+18, y+17)
    p2 = QtCore.QPointF(x+32, y+17)
    p3 = QtCore.QPointF(x+28, y+15)
    p4 = QtCore.QPointF(x+28, y+19)
    p5 = QtCore.QPointF(x+32, y+17)
    icon_path_6.addPolygon(QtGui.QPolygonF([p1, p2, p3, p4, p5]))  
    icon_6.setPath(icon_path_6)
    icon_6.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.darkRed), line_width_2 ))
    icon_6.setBrush(QtGui.QBrush(QtGui.QColor(QtCore.Qt.darkRed)))
    
    icon_7 = QtWidgets.QGraphicsPathItem()
    icon_path_7 = QtGui.QPainterPath()
    p1 = QtCore.QPointF(x+18, y+32)
    p2 = QtCore.QPointF(x+18, y+23)
    p3 = QtCore.QPointF(x+21, y+23)
    p4 = QtCore.QPointF(x+21, y+32)
    p5 = QtCore.QPointF(x+27, y+32)
    p6 = QtCore.QPointF(x+27, y+23)
    p7 = QtCore.QPointF(x+30, y+23)
    p8 = QtCore.QPointF(x+30, y+32)
    p9 = QtCore.QPointF(x+33, y+32)
    p10 = QtCore.QPointF(x+33, y+23)
    icon_path_7.addPolygon(QtGui.QPolygonF([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10]))  
    icon_7.setPath(icon_path_7)
    icon_7.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.darkRed), line_width_1 ))
    
    icon_paths = [icon_1, icon_2, icon_3, icon_4, icon_5, icon_6, icon_7]
    return icon_paths
        
        
        
        
Esempio n. 4
0
    def on_tmrSer_timeout(self):
        self.tmrSer_Cnt += 1

        if self.ser.is_open:
            if self.ser.in_waiting > 0:
                self.rcvbuff += self.ser.read(self.ser.in_waiting)
                
                if self.chkWave.isChecked():
                    if self.rcvbuff.rfind(b',') == -1:
                        return

                    try:
                        d = self.rcvbuff[0:self.rcvbuff.rfind(b',')].split(b',')    # [b'12', b'34'] or [b'12 34', b'56 78']
                        d = [[float(x) for x in X.strip().split()] for X in d]      # [[12], [34]]   or [[12, 34], [56, 78]]
                        for arr in d:
                            for i, x in enumerate(arr):
                                if i == N_CURVES: break

                                self.PlotData[i].pop(0)
                                self.PlotData[i].append(x)
                                self.PlotPoint[i].pop(0)
                                self.PlotPoint[i].append(QtCore.QPointF(999, x))
                        
                        self.rcvbuff = self.rcvbuff[self.rcvbuff.rfind(b',')+1:]

                        if self.tmrSer_Cnt % 4 == 0:
                            if len(d[-1]) != len(self.PlotChart.series()):
                                for series in self.PlotChart.series():
                                    self.PlotChart.removeSeries(series)
                                for i in range(min(len(d[-1]), N_CURVES)):
                                    self.PlotCurve[i].setName(f'Curve {i+1}')
                                    self.PlotChart.addSeries(self.PlotCurve[i])
                                self.PlotChart.createDefaultAxes()

                            for i in range(len(self.PlotChart.series())):
                                for j, point in enumerate(self.PlotPoint[i]):
                                    point.setX(j)
                            
                                self.PlotCurve[i].replace(self.PlotPoint[i])
                        
                            miny = min([min(d) for d in self.PlotData[:len(self.PlotChart.series())]])
                            maxy = max([max(d) for d in self.PlotData[:len(self.PlotChart.series())]])
                            self.PlotChart.axisY().setRange(miny, maxy)
                            self.PlotChart.axisX().setRange(0000, 1000)
                    
                    except Exception as e:
                        self.rcvbuff = b''
                        print(e)

                else:
                    text = ''
                    if self.cmbICode.currentText() == 'ASCII':
                        text = ''.join([chr(x) for x in self.rcvbuff])
                        self.rcvbuff = b''

                    elif self.cmbICode.currentText() == 'HEX':
                        text = ' '.join([f'{x:02X}' for x in self.rcvbuff]) + ' '
                        self.rcvbuff = b''

                    elif self.cmbICode.currentText() == 'GBK':
                        while len(self.rcvbuff):
                            if self.rcvbuff[0:1].decode('GBK', 'ignore'):
                                text += self.rcvbuff[0:1].decode('GBK')
                                self.rcvbuff = self.rcvbuff[1:]

                            elif len(self.rcvbuff) > 1 and self.rcvbuff[0:2].decode('GBK', 'ignore'):
                                text += self.rcvbuff[0:2].decode('GBK')
                                self.rcvbuff = self.rcvbuff[2:]

                            elif len(self.rcvbuff) > 1:
                                text += chr(self.rcvbuff[0])
                                self.rcvbuff = self.rcvbuff[1:]

                            else:
                                break

                    elif self.cmbICode.currentText() == 'UTF-8':
                        while len(self.rcvbuff):
                            if self.rcvbuff[0:1].decode('UTF-8', 'ignore'):
                                text += self.rcvbuff[0:1].decode('UTF-8')
                                self.rcvbuff = self.rcvbuff[1:]

                            elif len(self.rcvbuff) > 1 and self.rcvbuff[0:2].decode('UTF-8', 'ignore'):
                                text += self.rcvbuff[0:2].decode('UTF-8')
                                self.rcvbuff = self.rcvbuff[2:]

                            elif len(self.rcvbuff) > 2 and self.rcvbuff[0:3].decode('UTF-8', 'ignore'):
                                text += self.rcvbuff[0:3].decode('UTF-8')
                                self.rcvbuff = self.rcvbuff[3:]

                            elif len(self.rcvbuff) > 3 and self.rcvbuff[0:4].decode('UTF-8', 'ignore'):
                                text += self.rcvbuff[0:4].decode('UTF-8')
                                self.rcvbuff = self.rcvbuff[4:]

                            elif len(self.rcvbuff) > 3:
                                text += chr(self.rcvbuff[0])
                                self.rcvbuff = self.rcvbuff[1:]

                            else:
                                break
                    
                    if len(self.txtMain.toPlainText()) > 25000: self.txtMain.clear()
                    self.txtMain.moveCursor(QtGui.QTextCursor.End)
                    self.txtMain.insertPlainText(text)

            if self.AutoInterval and self.tmrSer_Cnt % self.AutoInterval == 0:
                self.on_btnSend_clicked()

        else:
            if self.tmrSer_Cnt % 100 == 0:
                if len(comports()) != self.cmbPort.count():
                    self.cmbPort.clear()
                    for port, desc, hwid in comports():
                        self.cmbPort.addItem(f'{port} ({desc[:desc.index("(")]})')
Esempio n. 5
0
    def _setStartItem(self, start_point: QtCore.QPointF, brush: QtGui.QBrush,
                      checi: str, down: bool,
                      startAtThis: bool) -> QtGui.QPainterPath:
        label = QtGui.QPainterPath()
        label.moveTo(start_point)
        startLabelText = self._setStartEndLabelText(checi, brush)
        self.startLabelText = startLabelText
        start_height = self.graph.UIConfigData()['start_label_height']
        w, h = self.spanItemWidth, self.spanItemHeight
        if startAtThis:
            if down:
                label.moveTo(start_point)
                next_point = QtCore.QPoint(start_point.x(),
                                           start_point.y() - start_height)
                label.lineTo(next_point)
                next_point.setX(next_point.x() - self.spanItemWidth / 2)
                label.moveTo(next_point)
                # label.addText(next_point.x() + 30 - (len(checi) * 9) / 2, next_point.y(), QtGui.QFont(),
                #               checi)
                startLabelText.setX(next_point.x())
                startLabelText.setY(next_point.y() - self.spanItemHeight)
                # label.moveTo(next_point)
                next_point.setX(next_point.x() + self.spanItemWidth)
                label.lineTo(next_point)

            else:
                next_point = QtCore.QPoint(start_point.x(),
                                           start_point.y() + start_height)
                label.lineTo(next_point)
                next_point.setX(next_point.x() - self.spanItemWidth / 2)
                next_point.setY(next_point.y())
                label.moveTo(next_point)
                self.startLabelText.setX(next_point.x())
                self.startLabelText.setY(next_point.y())
                next_point.setY(next_point.y())
                next_point.setX(next_point.x() + self.spanItemWidth)
                label.lineTo(next_point)

        else:
            if down:
                label.moveTo(start_point)
                curPoint = QtCore.QPointF(start_point)
                curPoint.setY(curPoint.y() - start_height)
                label.lineTo(curPoint)
                curPoint.setX(curPoint.x() - w)
                label.lineTo(curPoint)
                startLabelText.setX(curPoint.x())
                startLabelText.setY(curPoint.y() - h)
                curPoint.setX(curPoint.x() - h)
                curPoint.setY(curPoint.y() - h)
                label.lineTo(curPoint)
            else:
                label.moveTo(start_point)
                curPoint = QtCore.QPointF(start_point)
                curPoint.setY(curPoint.y() + start_height)
                label.lineTo(curPoint)
                curPoint.setX(curPoint.x() - w)
                label.lineTo(curPoint)
                startLabelText.setPos(curPoint)
                curPoint.setX(curPoint.x() - h)
                curPoint.setY(curPoint.y() + h)
                label.lineTo(curPoint)

        return label
Esempio n. 6
0
    def updateNode(self, functional=None, inverseFunctional=None, **kwargs):
        """
        Update the current node.
        :type functional: bool
        :type inverseFunctional: bool
        """
        if functional is None:
            functional = self.isFunctional()
        if inverseFunctional is None:
            inverseFunctional = self.isInverseFunctional()

        polygon = self.polygon.geometry()

        # FUNCTIONAL POLYGON (SHAPE)
        fpolygon = QtGui.QPainterPath()
        if functional and not inverseFunctional:
            path = QtGui.QPainterPath()
            path.addPolygon(
                QtGui.QPolygonF([
                    polygon[self.IndexL] + QtCore.QPointF(+5, 0),
                    polygon[self.IndexB] + QtCore.QPointF(0, -4),
                    polygon[self.IndexR] + QtCore.QPointF(-5, 0),
                    polygon[self.IndexT] + QtCore.QPointF(0, +4),
                    polygon[self.IndexL] + QtCore.QPointF(+5, 0),
                ]))
            fpolygon.addPolygon(polygon)
            fpolygon = fpolygon.subtracted(path)

        # INVERSE FUNCTIONAL POLYGON (SHAPE)
        ipolygon = QtGui.QPainterPath()
        if not functional and inverseFunctional:
            path = QtGui.QPainterPath()
            path.addPolygon(
                QtGui.QPolygonF([
                    polygon[self.IndexL] + QtCore.QPointF(+5, 0),
                    polygon[self.IndexB] + QtCore.QPointF(0, -4),
                    polygon[self.IndexR] + QtCore.QPointF(-5, 0),
                    polygon[self.IndexT] + QtCore.QPointF(0, +4),
                    polygon[self.IndexL] + QtCore.QPointF(+5, 0),
                ]))
            ipolygon.addPolygon(polygon)
            ipolygon = ipolygon.subtracted(path)

        # FUNCTIONAL + INVERSE FUNCTIONAL POLYGONS (SHAPE)
        if functional and inverseFunctional:
            path = QtGui.QPainterPath()
            path.addPolygon(
                QtGui.QPolygonF([
                    polygon[self.IndexL] + QtCore.QPointF(+5, 0),
                    polygon[self.IndexB] + QtCore.QPointF(0, -4),
                    polygon[self.IndexB],
                    polygon[self.IndexR],
                    polygon[self.IndexT],
                    polygon[self.IndexT] + QtCore.QPointF(0, +4),
                    polygon[self.IndexL] + QtCore.QPointF(+5, 0),
                ]))
            fpolygon.addPolygon(polygon)
            fpolygon = fpolygon.subtracted(path)
            path = QtGui.QPainterPath()
            path.addPolygon(
                QtGui.QPolygonF([
                    polygon[self.IndexL],
                    polygon[self.IndexB],
                    polygon[self.IndexB] + QtCore.QPointF(0, -4),
                    polygon[self.IndexR] + QtCore.QPointF(-5, 0),
                    polygon[self.IndexT] + QtCore.QPointF(0, +4),
                    polygon[self.IndexT],
                    polygon[self.IndexL],
                ]))
            ipolygon.addPolygon(polygon)
            ipolygon = ipolygon.subtracted(path)

        # FUNCTIONAL POLYGON (PEN + BRUSH)
        fpen = QtGui.QPen(QtCore.Qt.NoPen)
        fbrush = QtGui.QBrush(QtCore.Qt.NoBrush)
        if functional:
            fpen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                              QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                              QtCore.Qt.RoundJoin)
            fbrush = QtGui.QBrush(QtGui.QColor(252, 252, 252, 255))

        # INVERSE FUNCTIONAL POLYGON (PEN + BRUSH)
        ipen = QtGui.QPen(QtCore.Qt.NoPen)
        ibrush = QtGui.QBrush(QtCore.Qt.NoBrush)
        if inverseFunctional:
            ipen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                              QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                              QtCore.Qt.RoundJoin)
            ibrush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 255))

        self.fpolygon.setPen(fpen)
        self.fpolygon.setBrush(fbrush)
        self.fpolygon.setGeometry(fpolygon)
        self.ipolygon.setPen(ipen)
        self.ipolygon.setBrush(ibrush)
        self.ipolygon.setGeometry(ipolygon)

        # SELECTION + BACKGROUND + HANDLES + ANCHORS + CACHE REFRESH
        super().updateNode(**kwargs)
Esempio n. 7
0
    def draw_grid(self, painter):
        painter.setBrush(Qt.NoBrush)
        self.pen.setWidth(self.not_selected_size)
        painter.setPen(self.pen)

        s_x = self.rect.x()
        s_y = self.rect.y()

        bottom_right = self.rect.bottomRight()
        e_x = bottom_right.x()
        e_y = bottom_right.y()

        # show rows
        height = self.rect.height() / self.rows
        if self.rows_offset:
            for i in range(1, self.rows + 1):
                y = s_y + i * height
                y_2 = y - self.rows_offset
                painter.drawLine(QtCore.QPointF(s_x, y),
                                 QtCore.QPointF(e_x, y))
                painter.drawLine(QtCore.QPointF(s_x, y_2),
                                 QtCore.QPointF(e_x, y_2))
        else:
            for i in range(1, self.rows + 1):
                y = s_y + i * height
                painter.drawLine(QtCore.QPointF(s_x, y),
                                 QtCore.QPointF(e_x, y))

        # show colls
        width = self.rect.width() / self.columns
        if self.colums_offset:
            for i in range(1, self.columns + 1):
                x = s_x + i * width
                x_2 = x - self.colums_offset
                painter.drawLine(QtCore.QPointF(x, s_y),
                                 QtCore.QPointF(x, e_y))
                painter.drawLine(QtCore.QPointF(x_2, s_y),
                                 QtCore.QPointF(x_2, e_y))
        else:
            for i in range(1, self.columns + 1):
                x = s_x + i * width
                painter.drawLine(QtCore.QPointF(x, s_y),
                                 QtCore.QPointF(x, e_y))
Esempio n. 8
0
    def interactiveResize(self, mousePos):
        """
        Perform shape interactive resize.
        """
        offset = self.handleSize + self.handleSpace
        boundingRect = self.boundingRect()
        rect = self.rect()
        diff = QtCore.QPointF(0, 0)

        self.prepareGeometryChange()

        if self.handleSelected == self.handleTopLeft:

            fromX = self.mousePressRect.left()
            fromY = self.mousePressRect.top()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setLeft(toX)
            boundingRect.setTop(toY)
            rect.setLeft(boundingRect.left() + offset)
            rect.setTop(boundingRect.top() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleTopMiddle:

            fromY = self.mousePressRect.top()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setY(toY - fromY)
            boundingRect.setTop(toY)
            rect.setTop(boundingRect.top() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleTopRight:

            fromX = self.mousePressRect.right()
            fromY = self.mousePressRect.top()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setRight(toX)
            boundingRect.setTop(toY)
            rect.setRight(boundingRect.right() - offset)
            rect.setTop(boundingRect.top() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleMiddleLeft:

            fromX = self.mousePressRect.left()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            diff.setX(toX - fromX)
            boundingRect.setLeft(toX)
            rect.setLeft(boundingRect.left() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleMiddleRight:
            print("MR")
            fromX = self.mousePressRect.right()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            diff.setX(toX - fromX)
            boundingRect.setRight(toX)
            rect.setRight(boundingRect.right() - offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleBottomLeft:

            fromX = self.mousePressRect.left()
            fromY = self.mousePressRect.bottom()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setLeft(toX)
            boundingRect.setBottom(toY)
            rect.setLeft(boundingRect.left() + offset)
            rect.setBottom(boundingRect.bottom() - offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleBottomMiddle:

            fromY = self.mousePressRect.bottom()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setY(toY - fromY)
            boundingRect.setBottom(toY)
            rect.setBottom(boundingRect.bottom() - offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleBottomRight:

            fromX = self.mousePressRect.right()
            fromY = self.mousePressRect.bottom()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setRight(toX)
            boundingRect.setBottom(toY)
            rect.setRight(boundingRect.right() - offset)
            rect.setBottom(boundingRect.bottom() - offset)
            self.setRect(rect)

        self.updateHandlesPos()
Esempio n. 9
0
    def resourceGrid(self):
        def in_map(a_min, a_max, b_min, b_max):
            return (a_min <= b_max) and (b_min <= a_max)
        self.clear_Resource()
        for key in self.colours:
            if self.colours[key][0] == self.whatCombo.currentText():
                colours = self.colours[key][3]
                break
        period = self.periodCombo.currentText()
        if self.detailCombo.currentText() == 'Daily By Month':
            pass
        else:
            if self.detailCombo.currentText() == 'Hourly by Day':
                period += '-' + self.dayCombo.currentText()
            period += '_' + self.hourCombo.currentText()
        variable = self.whatCombo.currentText()
        steps = self.stepSpin.value()
        opacity = self.opacitySpin.value()
        i = period.find('_')
        if i > 0:
            new_file = rreplace(self.scene.resource_grid, '$YEAR$', period[:i], 1)
            new_file = new_file.replace('$YEAR$', period[:4])
        else:
            new_file = self.scene.resource_grid.replace('$YEAR$', period[:4])
        self.resource_items = []
        if new_file[-4:] == '.xls' or new_file[-5:] == '.xlsx':
            if new_file != self.resource_file:
                if os.path.exists(new_file):
                    self.resource_var = {}
                    workbook = xlrd.open_workbook(new_file)
                    self.resource_worksheet = workbook.sheet_by_index(0)
                    num_cols = self.resource_worksheet.ncols - 1
#                   get column names
                    curr_col = -1
                    while curr_col < num_cols:
                        curr_col += 1
                        self.resource_var[self.resource_worksheet.cell_value(0, curr_col)] = curr_col
                    self.resource_file = new_file
                else:
                    return
            num_rows = self.resource_worksheet.nrows - 1
            num_cols = self.resource_worksheet.ncols - 1
            lo_valu = 99999.
            hi_valu = 0.
            calc_minmax = True
            cells = []
            curr_row = 1
            if self.resource_worksheet.cell_value(curr_row, self.resource_var['Period']) == 'Min.' and \
              self.resource_worksheet.cell_value(curr_row + 1, self.resource_var['Period']) == 'Max.':
                calc_minmax = False
                lo_valu = self.resource_worksheet.cell_value(curr_row, self.resource_var[variable])
                hi_valu = self.resource_worksheet.cell_value(curr_row + 1, self.resource_var[variable])
                curr_row += 1
            while curr_row < num_rows:
                curr_row += 1
                a_lat = float(self.resource_worksheet.cell_value(curr_row, self.resource_var['Latitude']))
                a_lon = float(self.resource_worksheet.cell_value(curr_row, self.resource_var['Longitude']))
                if in_map(a_lat - 0.25, a_lat + 0.25, self.scene.map_lower_right[0],
                          self.scene.map_upper_left[0]) \
                  and in_map(a_lon - 0.3333, a_lon + 0.3333,
                          self.scene.map_upper_left[1], self.scene.map_lower_right[1]):
                    try:
                        if self.resource_worksheet.cell_value(curr_row, self.resource_var['Period']) == period:
                            cells.append([float(self.resource_worksheet.cell_value(curr_row, self.resource_var['Latitude'])),
                                         float(self.resource_worksheet.cell_value(curr_row, self.resource_var['Longitude'])),
                                         self.resource_worksheet.cell_value(curr_row, self.resource_var[variable])])
                        if calc_minmax:
                            if self.resource_worksheet.cell_value(curr_row, self.resource_var[variable]) < lo_valu:
                                lo_valu = self.resource_worksheet.cell_value(curr_row, self.resource_var[variable])
                            if self.resource_worksheet.cell_value(curr_row, self.resource_var[variable]) > hi_valu:
                                hi_valu = self.resource_worksheet.cell_value(curr_row, self.resource_var[variable])
                    except:
                        pass
        else:
            if os.path.exists(new_file):
                resource = open(new_file)
                things = csv.DictReader(resource)
                for cell in things:
                    a_lat = float(cell['Latitude'])
                    a_lon = float(cell['Longitude'])
                    if in_map(a_lat - 0.25, a_lat + 0.25, self.scene().map_lower_right[0],
                              self.scene().map_upper_left[0]) \
                      and in_map(a_lon - 0.3333, a_lon + 0.3333,
                              self.scene().map_upper_left[1], self.scene().map_lower_right[1]):
                        if cell['Period'] == period:
                            cells.append(cell['Latitude'], cell['Longitude'], cell[variable])
                        if cell[variable] < lo_valu:
                            lo_valu = cell[variable]
                        if cell[variable] > hi_valu:
                            hi_valu = cell[variable]
                resource.close()
            else:
                return
        if steps > 0:
            incr = (hi_valu - lo_valu) / steps
        else:
            lo_colour = []
            hi_colour = []
            for i in range(3):
                lo_1 = int(colours[0][i * 2 + 1:i * 2 + 3], base=16)
                lo_colour.append(lo_1)
                hi_1 = int(colours[-1][i * 2 + 1:i * 2 + 3], base=16)
                hi_colour.append(hi_1)
        lo_per = 99999.
        hi_per = 0.
        lons = []
        lon_cell = .3125
        for cell in cells:
            if cell[1] not in lons:
                lons.append(cell[1])
        if len(lons) > 1:
            lons = sorted(lons)
            lon_cell = (lons[1] - lons[0]) / 2.
            del lons
        for cell in cells:
            p = self.scene.mapFromLonLat(QtCore.QPointF(cell[1] - lon_cell, cell[0] + .25))
            pe = self.scene.mapFromLonLat(QtCore.QPointF(cell[1] + lon_cell, cell[0] + .25))
            ps = self.scene.mapFromLonLat(QtCore.QPointF(cell[1] - lon_cell, cell[0] - .25))
            x_d = pe.x() - p.x()
            y_d = ps.y() - p.y()
            self.resource_items.append(QtWidgets.QGraphicsRectItem(p.x(), p.y(), x_d, y_d))
            if steps > 0:
                step = int(round((cell[2] - lo_valu) / incr))
                a_colour = QtGui.QColor(colours[step])
            else:
                colr = []
                pct = (cell[2] - lo_valu) / (hi_valu - lo_valu)
                for i in range(3):
                    colr.append(((hi_colour[i] - lo_colour[i]) * pct + lo_colour[i]) / 255.)
                a_colour = QtGui.QColor()
                a_colour.setRgbF(colr[0], colr[1], colr[2])
            if not self.grid_only.isChecked():
                if cell[2] >= lo_valu:
                    if cell[2] > 0 or variable == 'temp':
                        self.resource_items[-1].setBrush(a_colour)
            self.resource_items[-1].setPen(a_colour)
            self.resource_items[-1].setOpacity(opacity)
            self.resource_items[-1].setZValue(1)
            self.scene.addItem(self.resource_items[-1])
            if cell[2] < lo_per:
                lo_per = cell[2]
            if cell[2] > hi_per:
                hi_per = cell[2]
        QtCore.QCoreApplication.processEvents()
        QtCore.QCoreApplication.flush()
        if self.do_loop and not self.scene.exitLoop:
            if self.loopSpin.value() > 0:
                time.sleep(self.loopSpin.value())
Esempio n. 10
0
class Toast(QtWidgets.QWidget):
    background_color = QtGui.QColor("#778899")
    text_color = QtCore.Qt.black
    font = QtGui.QFont('Simsun', 10)
    text = ''
    times = 3
    parent = None
    min_height = 10
    min_width = 10
    pos = QtCore.QPointF(0, 0)

    def __init__(
        self,
        parent=None,
    ):
        super(Toast, self).__init__(parent)
        self.parent = parent
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

    def init_UI(self):
        # 计算气泡长宽及移动气泡到指定位置
        self.height = self.get_font_size() * 2
        self.width = len(self.text) * self.height * 0.8
        if self.height < self.min_height:
            self.height = self.min_height
        # else:
        #     self.height = self.min_height * 2
        if self.width < self.min_width:
            self.width = self.min_width
        self.resize(int(self.width), int(self.height))
        if self.pos.x() != 0 or self.pos.y() != 0:
            self.move(int(self.pos.x() - self.width / 2),
                      int(self.pos.y() - self.height / 2))

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setRenderHints(QtGui.QPainter.Antialiasing
                               | QtGui.QPainter.TextAntialiasing)
        rect_line_path = QtGui.QPainterPath()
        rectangle = QtCore.QRectF(0, 0, self.width, self.height)
        rect_line_path.addRoundedRect(rectangle, self.height / 2,
                                      self.height / 2, QtCore.Qt.AbsoluteSize)
        painter.fillPath(rect_line_path, QtGui.QColor(self.background_color))

        pen = QtGui.QPen(QtGui.QColor(self.text_color))
        painter.setPen(pen)
        painter.setFont(self.font)
        self.draw_text(painter)

    def get_font_size(self):
        return self.font.pointSizeF()

    def draw_text(self, painter):
        painter.drawText(QtCore.QRectF(0, 0, self.width, self.height),
                         QtCore.Qt.AlignCenter, self.text)

    def make_text(self, pos, text, times=None, background_color=None):
        if pos:
            self.pos = pos
        if text:
            self.text = text
        if times:
            self.times = times
        if background_color:
            self.background_color = background_color
        self.init_UI()
        self.repaint()
        self.show()

        toast_timer = threading.Timer(self.times, self.toast_timeout)
        toast_timer.start()

    def toast_timeout(self):
        self.close()
Esempio n. 11
0
    def getContextMenus(self, *, rect=None, event=None):
        if self.menu is None:
            self.menu = QtGui.QMenu()
        self.menu.clear()

        # Add color selector
        if self.gradientSelectorMenu is None:
            l = 80
            self.gradientSelectorMenu = QtGui.QMenu()
            self.gradientSelectorMenu.setTitle("Color Scale")
            gradients = graphicsItems.GradientEditorItem.Gradients
            for g in gradients:
                if g in COLORMAPS:
                    cmap = COLORMAPS[g]
                else:
                    pos = [x[0] for x in gradients[g]['ticks']]
                    colors = [x[1] for x in gradients[g]['ticks']]
                    mode = ColorMap.RGB if gradients[g][
                        'mode'] == 'rgb' else ColorMap.HSV_POS
                    cmap = ColorMap(pos, colors, mode=mode)
                    COLORMAPS[g] = cmap

                px = QtGui.QPixmap(l, 15)
                p = QtGui.QPainter(px)
                grad = cmap.getGradient(QtCore.QPointF(0, 0),
                                        QtCore.QPointF(l, 0))
                brush = QtGui.QBrush(grad)
                p.fillRect(QtCore.QRect(0, 0, l, 15), brush)
                p.end()
                label = QtGui.QLabel()
                label.setPixmap(px)
                label.setContentsMargins(1, 1, 1, 1)
                act = QtGui.QWidgetAction(self)
                act.setDefaultWidget(label)
                act.triggered.connect(partial(self.changeColorScale, name=g))
                act.name = g
                self.gradientSelectorMenu.addAction(act)
        self.menu.addMenu(self.gradientSelectorMenu)

        # Actions that use the scale box
        if rect is not None:
            xrange = rect.left(), rect.right()
            yrange = rect.top(), rect.bottom()

            qaction = QtGui.QAction("Colour By Marquee", self.menu)
            qaction.triggered.connect(
                partial(self.colorByMarquee, xrange=xrange, yrange=yrange))
            self.menu.addAction(qaction)

            qaction = QtGui.QAction("Plane Fit", self.menu)
            qaction.triggered.connect(
                partial(self.planeFit, xrange=xrange, yrange=yrange))
            self.menu.addAction(qaction)

            qaction = QtGui.QAction("Level Columns", self.menu)
            qaction.triggered.connect(
                partial(self.levelColumns, xrange=xrange, yrange=yrange))
            self.menu.addAction(qaction)

        self.menu.setTitle("Image Item")

        return self.menu
Esempio n. 12
0
    def draw_text(self, painter):
        painter.drawText(QtCore.QRectF(0, 0, self.width, self.height),
                         QtCore.Qt.AlignCenter, self.text)

    def make_text(self, pos, text, times=None, background_color=None):
        if pos:
            self.pos = pos
        if text:
            self.text = text
        if times:
            self.times = times
        if background_color:
            self.background_color = background_color
        self.init_UI()
        self.repaint()
        self.show()

        toast_timer = threading.Timer(self.times, self.toast_timeout)
        toast_timer.start()

    def toast_timeout(self):
        self.close()


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    toast = Toast()
    toast.make_text(QtCore.QPointF(1000, 1000), "hahahaha", 5)
    sys.exit(app.exec_())
Esempio n. 13
0
def paintArrow(painter, bf):
    posicion = bf.posicion
    dx = posicion.x
    dy = posicion.y
    hx = posicion.ancho
    hy = posicion.alto

    p_ini = QtCore.QPointF(dx, dy)
    p_fin = QtCore.QPointF(hx, hy)
    linea = QtCore.QLineF(p_ini, p_fin)
    tamLinea = linea.length()
    if linea.isNull():
        return None

    color = QtGui.QColor(bf.color)
    pen = QtGui.QPen()
    pen.setWidth(bf.grosor)
    pen.setColor(color)
    pen.setStyle(bf.tipoqt())
    if bf.redondeos:
        pen.setCapStyle(QtCore.Qt.RoundCap)
        pen.setJoinStyle(QtCore.Qt.RoundJoin)
    painter.setPen(pen)

    xk = bf.anchoCasilla / 32.0

    ancho = float(bf.ancho) * xk
    vuelo = float(bf.vuelo) * xk

    altoCab = float(bf.altocabeza) * xk
    if tamLinea * 0.65 < altoCab:
        nv = tamLinea * 0.65
        prc = nv / altoCab
        altoCab = nv
        ancho *= prc
        vuelo *= prc

    xp = 1.0 - float(altoCab) / tamLinea
    pbc = linea.pointAt(xp)  # base de la cabeza

    # Usamos una linea a 90 grados para calcular los puntos del final de la cabeza de flecha
    l90 = linea.normalVector()
    l90.setLength(ancho + vuelo * 2)
    l90.translate(pbc - p_ini)  # la llevamos a la base de la cabeza
    p_ala1 = l90.pointAt(0.5)  # final del ala de un lado
    l90.translate(p_ala1 - l90.p2())  # La colocamos que empiece en ala1
    p_ala2 = l90.p1()  # final del ala de un lado

    xp = 1.0 - float(altoCab - bf.descuelgue) / tamLinea
    p_basecab = linea.pointAt(xp)  # Punto teniendo en cuenta el angulo en la base de la cabeza, valido para tipo c y p

    # Puntos de la base, se calculan aunque no se dibujen para determinar el poligono de control
    l90 = linea.normalVector()
    l90.setLength(ancho)
    p_base1 = l90.pointAt(0.5)  # final de la base de un lado
    l90.translate(p_base1 - l90.p2())
    p_base2 = l90.p1()  # final de la base de un lado

    lf = QtCore.QLineF(p_ini, p_basecab)
    lf.translate(p_base1 - p_ini)
    p_cab1 = lf.p2()
    lf.translate(p_base2 - p_base1)
    p_cab2 = lf.p2()

    # Poligonos para determinar si se ha pulsado sobre la flecha
    xancho = max(ancho + vuelo * 2.0, 16.0)
    xl90 = linea.normalVector()
    xl90.setLength(xancho)
    xp_base2 = xl90.pointAt(0.5)
    xl90.translate(xp_base2 - xl90.p2())  # La colocamos que empiece en base1
    xp_base1 = xl90.p1()
    xpbb = linea.pointAt(0.15)  # Siempre un 15% para cambiar de tama_o por el pie
    xl90.translate(xpbb - p_ini)  # la llevamos a la base de la cabeza
    xp_medio1b = xl90.p1()
    xp_medio2b = xl90.p2()
    xl90.translate(p_ini - xpbb)  # la llevamos a la base para poderla trasladar
    xpbc = linea.pointAt(0.85)  # Siempre un 15% para cambiar de tama_o por la cabeza
    xl90.translate(xpbc - p_ini)  # la llevamos a la base de la cabeza
    xp_medio1t = xl90.p1()
    xp_medio2t = xl90.p2()
    xl90.translate(p_fin - xpbc)  # la llevamos al final
    xp_final1 = xl90.p1()
    xp_final2 = xl90.p2()

    poligonoSizeBottom = QtGui.QPolygonF([xp_base1, xp_medio1b, xp_medio2b, xp_base2, xp_base1])
    poligonoMove = QtGui.QPolygonF([xp_medio1b, xp_medio1t, xp_medio2t, xp_medio2b, xp_medio1b])
    poligonoSizeTop = QtGui.QPolygonF([xp_medio1t, xp_final1, xp_final2, xp_medio2t, xp_medio1t])

    forma = bf.forma
    # Abierta, forma normal
    if forma == "a":
        painter.drawLine(linea)

        if altoCab:
            lf = QtCore.QLineF(p_fin, p_ala1)
            painter.drawLine(lf)

            lf = QtCore.QLineF(p_fin, p_ala2)
            painter.drawLine(lf)

    else:
        if bf.colorinterior >= 0:
            color = QtGui.QColor(bf.colorinterior)
            if bf.colorinterior2 >= 0:
                color2 = QtGui.QColor(bf.colorinterior2)
                x, y = p_ini.x(), p_ini.y()
                gradient = QtGui.QLinearGradient(x, y, x, y - tamLinea - altoCab)
                gradient.setColorAt(0.0, color)
                gradient.setColorAt(1.0, color2)
                painter.setBrush(QtGui.QBrush(gradient))
            else:
                painter.setBrush(color)

        # Cabeza cerrada
        if forma == "c":
            lf = QtCore.QLineF(p_ini, p_basecab)
            painter.drawLine(lf)
            painter.drawPolygon(QtGui.QPolygonF([p_fin, p_ala1, p_basecab, p_ala2, p_fin]))

        # Poligonal
        elif forma in "123":

            # tipo 1
            if forma == "1":
                painter.drawPolygon(QtGui.QPolygonF([p_base1, p_cab1, p_ala1, p_fin, p_ala2, p_cab2, p_base2, p_base1]))
            # tipo 2 base = un punto
            elif forma == "2":
                painter.drawPolygon(QtGui.QPolygonF([p_ini, p_cab1, p_ala1, p_fin, p_ala2, p_cab2, p_ini]))
            # tipo 3 base cabeza = un punto
            elif forma == "3":
                painter.drawPolygon(
                        QtGui.QPolygonF([p_base1, p_basecab, p_ala1, p_fin, p_ala2, p_basecab, p_base2, p_base1]))

    return poligonoSizeBottom, poligonoMove, poligonoSizeTop
Esempio n. 14
0
    def on_tmrRTT_timeout(self):
        if self.btnOpen.text() == '关闭连接':
            try:
                self.rcvbuff += self.aUpRead()

                if self.txtMain.isVisible():
                    if self.chkHEXShow.isChecked():
                        text = ''.join(f'{x:02X} ' for x in self.rcvbuff)

                    else:
                        text = self.rcvbuff.decode('latin')

                    if len(self.txtMain.toPlainText()) > 25000:
                        self.txtMain.clear()
                    self.txtMain.moveCursor(QtGui.QTextCursor.End)
                    self.txtMain.insertPlainText(text)

                    self.rcvbuff = b''

                else:
                    if self.rcvbuff.rfind(b',') == -1: return

                    d = self.rcvbuff[0:self.rcvbuff.rfind(b',')].split(
                        b',')  # [b'12', b'34'] or [b'12 34', b'56 78']
                    d = [[float(x) for x in X.strip().split()]
                         for X in d]  # [[12], [34]]   or [[12, 34], [56, 78]]
                    for arr in d:
                        for i, x in enumerate(arr):
                            if i == N_CURVES: break

                            self.PlotData[i].pop(0)
                            self.PlotData[i].append(x)
                            self.PlotPoint[i].pop(0)
                            self.PlotPoint[i].append(QtCore.QPointF(999, x))

                    self.rcvbuff = self.rcvbuff[self.rcvbuff.rfind(b',') + 1:]

                    self.tmrRTT_Cnt += 1
                    if self.tmrRTT_Cnt % 4 == 0:
                        if len(d[-1]) != len(self.PlotChart.series()):
                            for series in self.PlotChart.series():
                                self.PlotChart.removeSeries(series)
                            for i in range(min(len(d[-1]), N_CURVES)):
                                self.PlotCurve[i].setName(f'Curve {i+1}')
                                self.PlotChart.addSeries(self.PlotCurve[i])
                            self.PlotChart.createDefaultAxes()

                        for i in range(len(self.PlotChart.series())):
                            for j, point in enumerate(self.PlotPoint[i]):
                                point.setX(j)

                            self.PlotCurve[i].replace(self.PlotPoint[i])

                        miny = min([
                            min(d) for d in
                            self.PlotData[:len(self.PlotChart.series())]
                        ])
                        maxy = max([
                            max(d) for d in
                            self.PlotData[:len(self.PlotChart.series())]
                        ])
                        self.PlotChart.axisY().setRange(miny, maxy)
                        self.PlotChart.axisX().setRange(0000, 1000)

            except Exception as e:
                self.rcvbuff = b''
                print(str(e))  # 波形显示模式下 txtMain 不可见,因此错误信息不能显示在其上

        else:
            self.tmrDAP_Cnt += 1
            if self.tmrDAP_Cnt % 100 == 0:
                try:
                    from pyocd.probe import aggregator
                    self.daplinks = aggregator.DebugProbeAggregator.get_all_connected_probes(
                    )
                    if len(self.daplinks) != self.cmbDLL.count() - 1:
                        for i in range(1, self.cmbDLL.count()):
                            self.cmbDLL.removeItem(i)
                        for i, daplink in enumerate(self.daplinks):
                            self.cmbDLL.addItem(daplink.product_name)
                except Exception as e:
                    pass
Esempio n. 15
0
 def center(self):
     rect = self.boundingRect()
     center = QtCore.QPointF(rect.x() + rect.width() * 0.5,
                             rect.y() + rect.height() * 0.5)
     return self.mapToScene(center)
Esempio n. 16
0
 def getCenter(self):
     rect = self.boundingRect()
     center = QtCore.QPointF(rect.x() + rect.width()/2, rect.y() + rect.height()/2)
     center = self.mapToScene(center)
     return center
Esempio n. 17
0
    def resize(self, mousePos):
        """
        Handle the interactive resize of the shape.
        :type mousePos: QtCore.QPointF
        """
        snap = self.session.action('toggle_grid').isChecked()
        size = self.diagram.GridSize
        moved = self.label.isMoved()

        background = self.background.geometry()
        selection = self.selection.geometry()
        polygon = self.polygon.geometry()

        R = QtCore.QRectF(self.boundingRect())
        D = QtCore.QPointF(0, 0)

        mbrh = 58
        mbrw = 78

        self.prepareGeometryChange()

        if self.mp_Handle == self.HandleTL:

            fromX = self.mp_Bound.left()
            fromY = self.mp_Bound.top()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, -4, snap)
            toY = snapF(toY, size, -4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setLeft(toX)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() - mbrw + R.width())
                R.setLeft(R.left() - mbrw + R.width())
            if R.height() < mbrh:
                D.setY(D.y() - mbrh + R.height())
                R.setTop(R.top() - mbrh + R.height())

            selection[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    R.top())
            selection[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexB].y())
            selection[self.IndexL] = QtCore.QPointF(R.left(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(R.left(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(selection[self.IndexR].x(),
                                                    R.top() + R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                     R.top())
            background[self.IndexB] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexB].y())
            background[self.IndexL] = QtCore.QPointF(R.left(),
                                                     R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(R.left(),
                                                     R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.top() + R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  R.top() + 4)
            polygon[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexB].y())
            polygon[self.IndexL] = QtCore.QPointF(R.left() + 4,
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(R.left() + 4,
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleTM:

            fromY = self.mp_Bound.top()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toY = snapF(toY, size, -4, snap)
            D.setY(toY - fromY)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.height() < mbrh:
                D.setY(D.y() - mbrh + R.height())
                R.setTop(R.top() - mbrh + R.height())

            selection[self.IndexT] = QtCore.QPointF(selection[self.IndexT].x(),
                                                    R.top())
            selection[self.IndexL] = QtCore.QPointF(selection[self.IndexL].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(selection[self.IndexE].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(selection[self.IndexR].x(),
                                                    R.top() + R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(
                background[self.IndexT].x(), R.top())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.top() + R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(polygon[self.IndexT].x(),
                                                  R.top() + 4)
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleTR:

            fromX = self.mp_Bound.right()
            fromY = self.mp_Bound.top()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, +4, snap)
            toY = snapF(toY, size, -4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setRight(toX)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() + mbrw - R.width())
                R.setRight(R.right() + mbrw - R.width())
            if R.height() < mbrh:
                D.setY(D.y() - mbrh + R.height())
                R.setTop(R.top() - mbrh + R.height())

            selection[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    R.top())
            selection[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexB].y())
            selection[self.IndexL] = QtCore.QPointF(selection[self.IndexL].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(selection[self.IndexE].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(R.right(),
                                                    R.top() + R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                     R.top())
            background[self.IndexB] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexB].y())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(R.right(),
                                                     R.top() + R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  R.top() + 4)
            polygon[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexB].y())
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(R.right() - 4,
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleML:

            fromX = self.mp_Bound.left()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toX = snapF(toX, size, -4, snap)
            D.setX(toX - fromX)
            R.setLeft(toX)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() - mbrw + R.width())
                R.setLeft(R.left() - mbrw + R.width())

            selection[self.IndexL] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            selection[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexB].y())

            background[self.IndexL] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            background[self.IndexT] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexB].y())

            polygon[self.IndexL] = QtCore.QPointF(
                R.left() + 4,
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(
                R.left() + 4,
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            polygon[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexB].y())

        elif self.mp_Handle == self.HandleMR:

            fromX = self.mp_Bound.right()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toX = snapF(toX, size, +4, snap)
            D.setX(toX - fromX)
            R.setRight(toX)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() + mbrw - R.width())
                R.setRight(R.right() + mbrw - R.width())

            selection[self.IndexR] = QtCore.QPointF(
                R.right(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            selection[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexB].y())

            background[self.IndexR] = QtCore.QPointF(
                R.right(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            background[self.IndexT] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexB].y())

            polygon[self.IndexR] = QtCore.QPointF(
                R.right() - 4,
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            polygon[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexB].y())

        elif self.mp_Handle == self.HandleBL:

            fromX = self.mp_Bound.left()
            fromY = self.mp_Bound.bottom()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, -4, snap)
            toY = snapF(toY, size, +4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setLeft(toX)
            R.setBottom(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() - mbrw + R.width())
                R.setLeft(R.left() - mbrw + R.width())
            if R.height() < mbrh:
                D.setY(D.y() + mbrh - R.height())
                R.setBottom(R.bottom() + mbrh - R.height())

            selection[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    R.bottom())
            selection[self.IndexL] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(
                selection[self.IndexR].x(),
                R.bottom() - R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                     R.bottom())
            background[self.IndexL] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.bottom() - R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  R.bottom() - 4)
            polygon[self.IndexL] = QtCore.QPointF(R.left() + 4,
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(R.left() + 4,
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.bottom() - R.height() / 2)

        elif self.mp_Handle == self.HandleBM:

            fromY = self.mp_Bound.bottom()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toY = snapF(toY, size, +4, snap)
            D.setY(toY - fromY)
            R.setBottom(toY)

            ## CLAMP SIZE
            if R.height() < mbrh:
                D.setY(D.y() + mbrh - R.height())
                R.setBottom(R.bottom() + mbrh - R.height())

            selection[self.IndexB] = QtCore.QPointF(selection[self.IndexB].x(),
                                                    R.bottom())
            selection[self.IndexL] = QtCore.QPointF(selection[self.IndexL].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(selection[self.IndexE].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(selection[self.IndexR].x(),
                                                    R.top() + R.height() / 2)

            background[self.IndexB] = QtCore.QPointF(
                background[self.IndexB].x(), R.bottom())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.top() + R.height() / 2)

            polygon[self.IndexB] = QtCore.QPointF(polygon[self.IndexB].x(),
                                                  R.bottom() - 4)
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleBR:

            fromX = self.mp_Bound.right()
            fromY = self.mp_Bound.bottom()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, +4, snap)
            toY = snapF(toY, size, +4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setRight(toX)
            R.setBottom(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() + mbrw - R.width())
                R.setRight(R.right() + mbrw - R.width())
            if R.height() < mbrh:
                D.setY(D.y() + mbrh - R.height())
                R.setBottom(R.bottom() + mbrh - R.height())

            selection[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    R.bottom())
            selection[self.IndexL] = QtCore.QPointF(
                selection[self.IndexL].x(),
                R.bottom() - R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(
                selection[self.IndexE].x(),
                R.bottom() - R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(
                R.right(),
                R.bottom() - R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                     R.bottom())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.bottom() - R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.bottom() - R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                R.right(),
                R.bottom() - R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  R.bottom() - 4)
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(R.right() - 4,
                                                  R.bottom() - R.height() / 2)

        self.background.setGeometry(background)
        self.selection.setGeometry(selection)
        self.polygon.setGeometry(polygon)

        self.updateNode(selected=True,
                        handle=self.mp_Handle,
                        anchors=(self.mp_Data, D))
        self.updateTextPos(moved=moved)
Esempio n. 18
0
 def Priosimulation(self):
     FullProject.preemptive_priority(int(self.ProcessNoText.text()))
     averagetime = FullProject.averagetime(int(self.ProcessNoText.text()))
     print(averagetime)
     self.WaitingTime_display.display(averagetime)
     for i in range(len(FullProject.SJprecurrent_running)):
         if FullProject.current_running[i] != "IDLE":
             FullProject.current_running[i] = "IDLE"
         else:
             FullProject.current_running[i] = "P" + str(
                 FullProject.current_running[i])
     print(FullProject.current_running)
     arr2 = []
     lastdone = FullProject.current_running[0]
     arr2.append(lastdone)
     for i in range(len(FullProject.current_running)):
         if FullProject.current_running[i] != lastdone:
             arr2.append(FullProject.current_running[i])
             lastdone = FullProject.current_running[i]
     print(arr2)
     burst = []
     jstart = 0
     for i in range(len(arr2)):
         searchn = arr2[i]
         burstno = 0
         index = 0
         for j in range(jstart, len(FullProject.current_running)):
             if FullProject.current_running[j] == searchn:
                 burstno += 1
             else:
                 break
         jstart = jstart + burstno
         burst.append(burstno)
     print(burst)
     SJFdep = []
     depsum = 0
     for i in range(len(arr2)):
         depsum = depsum + burst[i]
         SJFdep.append(depsum)
     arr = SJFdep
     scene = QtWidgets.QGraphicsScene()
     self.graphicsView.setScene(scene)
     pen = QtGui.QPen(QtCore.Qt.black, 3)
     brush = QtGui.QBrush(QtCore.Qt.lightGray)
     print(arr)
     print(arr2)
     print(burst)
     n = len(arr)
     next = 0
     for i in range(n):
         if burst[i] < 3:
             m = 20 * burst[i]
         elif burst[i] < 5:
             m = 10 * burst[i]
         else:
             m = burst[i]
         if i == 0:
             r = QtCore.QRectF(QtCore.QPointF(10, 0),
                               QtCore.QSizeF(m * burst[i], 80))
             scene.addRect(r, pen, brush)
             next = r.right()
             mytext1 = QGraphicsSimpleTextItem(str(arr2[i]))
             scene.addItem(mytext1)
             mytext1.setPos((next - burst[i] - 18), 30)
             mytext1.setScale(1.5)
             mytext2 = QGraphicsSimpleTextItem(str(arr[i]))
             scene.addItem(mytext2)
             mytext2.setPos(m * burst[i], 85)
             mytext2.setScale(1.3)
         else:
             r = QtCore.QRectF(QtCore.QPointF(next, 0),
                               QtCore.QSizeF(m * burst[i], 80))
             scene.addRect(r, pen, brush)
             mytext1 = QGraphicsSimpleTextItem(str(arr2[i]))
             scene.addItem(mytext1)
             mytext1.setPos(burst[i] + next, 30)
             mytext1.setScale(1.5)
             mytext2 = QGraphicsSimpleTextItem(str(arr[i]))
             scene.addItem(mytext2)
             mytext2.setPos(m * burst[i] + next, 85)
             mytext2.setScale(1.3)
             next = r.right()
Esempio n. 19
0
    def start_move(self, pos):
        try:
            if self.rect.contains(pos):
                top_left = self.rect.topLeft()
                # 1. calculate offset for choose borders
                self.selector_offsets = self.view.camera.to_scene(
                    self.view.camera.to_view(top_left) + QtCore.QPointF(
                        self.selector_size, self.selector_size)) - top_left

                top_left_rect = QtCore.QRectF(top_left.x(), top_left.y(),
                                              self.selector_offsets.x(),
                                              self.selector_offsets.y())
                if top_left_rect.contains(pos):
                    self.state = self.move_top_left
                    self.start_move_pos = pos
                    self.top_left = self.rect.topLeft()
                    return 1
                else:
                    top_right = self.rect.topRight()
                    top_right_rect = QtCore.QRectF(
                        top_right.x() - self.selector_offsets.x(),
                        top_left.y(), self.selector_offsets.x(),
                        self.selector_offsets.y())

                    if top_right_rect.contains(pos):
                        self.state = self.move_top_right
                        self.start_move_pos = pos
                        self.top_right = self.rect.topRight()
                        return 1
                    else:
                        bottom_left = self.rect.bottomLeft()
                        bottom_left_rect = QtCore.QRectF(
                            bottom_left.x(),
                            bottom_left.y() - self.selector_offsets.x(),
                            self.selector_offsets.x(),
                            self.selector_offsets.y())

                        if bottom_left_rect.contains(pos):
                            self.state = self.move_bottom_left
                            self.start_move_pos = pos
                            self.bottom_left = self.rect.bottomLeft()
                            return 1
                        else:
                            bottom_right = self.rect.bottomRight()
                            bottom_right_rect = QtCore.QRectF(
                                bottom_right.x() - self.selector_offsets.x(),
                                bottom_right.y() - self.selector_offsets.x(),
                                self.selector_offsets.x(),
                                self.selector_offsets.y())

                            if bottom_right_rect.contains(pos):
                                self.state = self.move_bottom_right
                                self.start_move_pos = pos
                                self.bottom_right = self.rect.bottomRight()
                                return 1
                            # move all
                            else:
                                self.state = self.move_state
                                self.start_move_pos = pos
                                self.top_left = self.rect.topLeft()

                                # get selected cell
                                width = self.rect.width() / self.columns
                                height = self.rect.height() / self.rows
                                pos = pos - self.rect.topLeft()
                                col = math.trunc(pos.x() / width)
                                row = math.trunc(pos.y() / height)
                                self.selected_cell = [col, row]
                                return 1
        finally:
            self.view.update()
Esempio n. 20
0
    def generatePicture(self, stocklist):
        p = QtGui.QPainter(self.picture)
        p.setPen(pg.mkPen('g'))
        prePoint = 0
        selectIndex = 0

        t = [i[0] for i in self.stocklist]
        trade_date = [i[1] for i in self.stocklist]
        list = dict(zip(trade_date, t))

        for i in range(len(self.x)):
            t = list[self.x[i]]

            if t == config.StockDataDays:
                break
            radio = 1
            yoffset = 5
            if prePoint != 0:
                # if stocklist[selectIndex].Decision == 'buy':
                #         p.setPen(pg.mkPen('r'))
                #         p.setBrush(pg.mkBrush('r'))
                #         p.drawLine(QtCore.QPointF(pre_t, prePoint), QtCore.QPointF(t, self.y[selectIndex]/10000))
                # if stocklist[selectIndex].Decision == "sale":
                #         p.setPen(pg.mkPen('g'))
                #         p.setBrush(pg.mkBrush('g'))
                #         p.drawLine(QtCore.QPointF(pre_t, prePoint), QtCore.QPointF(t, self.y[selectIndex]/10000))

                p.setPen(pg.mkPen('g'))
                p.setBrush(pg.mkBrush('g'))

                p.drawLine(QtCore.QPointF(pre_t, prePoint),
                           QtCore.QPointF(t, self.y[selectIndex] / 10000))

                p.setPen(pg.mkPen('r'))
                p.setBrush(pg.mkBrush('r'))
                p.drawEllipse(pre_t - 1, prePoint - 1, 1 * 2, 1 * 2)

            pre_t = t
            prePoint = self.y[selectIndex] / 10000
            selectIndex = selectIndex + 1

        selectIndex = 0
        radio = 1
        yoffset = 5
        for td in trade_date:
            if prePoint != 0:
                if td == stocklist[selectIndex].DateToBuy or td == stocklist[
                        selectIndex].DateToSale:
                    if stocklist[selectIndex].Decision == 'buy':
                        p.setPen(pg.mkPen('r'))
                        p.setBrush(pg.mkBrush('r'))
                        p.drawLine(
                            QtCore.QPointF(pre_t, prePoint),
                            QtCore.QPointF(t, self.y[selectIndex] / 10000))
                    elif stocklist[selectIndex].Decision == "sale":
                        p.setPen(pg.mkPen('g'))
                        p.setBrush(pg.mkBrush('g'))
                        p.drawLine(
                            QtCore.QPointF(pre_t, prePoint),
                            QtCore.QPointF(t, self.y[selectIndex] / 10000))

            pre_t = t
            prePoint = self.y[selectIndex] / 10000
            if len(stocklist) - 1 != selectIndex:
                selectIndex += 1
        p.end()
Esempio n. 21
0
 def moveright(self):
     dPos = self.viewRect.topLeft() - QtCore.QPointF(20.0, 20.0) * self.slide.level_downsamples[self.read_level]
     self.updateViewRect(dPos)
Esempio n. 22
0
    def iconFor(self, item):
        """
        Returns the appropriate icon for the given item.
        :type item: Item
        :rtype: QtGui.QIcon
        """
        icon = QtGui.QIcon()

        for i in (1.0, 2.0):

            pixmap = QtGui.QPixmap(60 * i, 44 * i)
            pixmap.setDevicePixelRatio(i)
            pixmap.fill(QtCore.Qt.transparent)

            #############################################
            # CONCEPT NODE
            #################################

            if item is Item.ConceptNode:
                painter = QtGui.QPainter(pixmap)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRect(QtCore.QRectF(-27, -17, 54, 34))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-27, -17, 54, 34),
                                 QtCore.Qt.AlignCenter, 'concept')
                painter.end()

            #############################################
            # ROLE NODE
            #################################

            elif item is Item.RoleNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(0, +17),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(0, -17),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -17, 46, 34),
                                 QtCore.Qt.AlignCenter, 'role')
                painter.end()

            #############################################
            # ATTRIBUTE NODE
            #################################

            elif item is Item.AttributeNode:

                painter = QtGui.QPainter(pixmap)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.translate(0, 0)
                painter.drawText(QtCore.QRectF(0, 0, 60, 22),
                                 QtCore.Qt.AlignCenter, 'attribute')
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 30)
                painter.drawEllipse(QtCore.QRectF(-9, -9, 18, 18))
                painter.end()

            #############################################
            # VALUE-DOMAIN NODE
            #################################

            elif item is Item.ValueDomainNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRoundedRect(QtCore.QRectF(-27, -17, 54, 34), 6, 6)
                painter.setFont(Font('Roboto', 10, Font.Light))
                painter.drawText(QtCore.QRectF(-27, -17, 54, 34),
                                 QtCore.Qt.AlignCenter, 'xsd:string')
                painter.end()

            #############################################
            # INDIVIDUAL NODE
            #################################

            elif item is Item.IndividualNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-20, -((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(-20, +((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(-((40 / (1 + sqrt(2))) / 2), +20),
                        QtCore.QPointF(+((40 / (1 + sqrt(2))) / 2), +20),
                        QtCore.QPointF(+20, +((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(+20, -((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(+((40 / (1 + sqrt(2))) / 2), -20),
                        QtCore.QPointF(-((40 / (1 + sqrt(2))) / 2), -20),
                        QtCore.QPointF(-20, -((40 / (1 + sqrt(2))) / 2)),
                    ]))
                painter.setFont(
                    Font('Roboto', 8 if self.isHDPI() else 9, Font.Light))
                painter.drawText(-16 if self.isHDPI() else -18, 4,
                                 'individual')
                painter.end()

            #############################################
            # FACET NODE
            #################################

            elif item is Item.FacetNode:

                polygonA = QtGui.QPolygonF([
                    QtCore.QPointF(-54 / 2 + 4, -32 / 2),
                    QtCore.QPointF(+54 / 2, -32 / 2),
                    QtCore.QPointF(+54 / 2 - 4 / 2, 0),
                    QtCore.QPointF(-54 / 2 + 4 / 2, 0),
                    QtCore.QPointF(-54 / 2 + 4, -32 / 2),
                ])
                polygonB = QtGui.QPolygonF([
                    QtCore.QPointF(-54 / 2 + 4 / 2, 0),
                    QtCore.QPointF(+54 / 2 - 4 / 2, 0),
                    QtCore.QPointF(+54 / 2 - 4, +32 / 2),
                    QtCore.QPointF(-54 / 2, +32 / 2),
                    QtCore.QPointF(-54 / 2 + 4 / 2, 0),
                ])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.setBrush(QtGui.QBrush(QtGui.QColor(222, 222, 222,
                                                           255)))
                painter.drawPolygon(polygonA)
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.drawPolygon(polygonB)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.drawText(QtCore.QPointF(-19 if _MACOS else -20, -5),
                                 Facet.length.value)
                painter.drawText(QtCore.QPointF(-8, 12), '"32"')
                painter.end()

            #############################################
            # DOMAIN RESTRICTION NODE
            #################################

            elif item is Item.DomainRestrictionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.translate(0, 0)
                painter.drawText(QtCore.QRectF(0, 0, 60, 22),
                                 QtCore.Qt.AlignCenter, 'restriction')
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRect(QtCore.QRectF(-18 / 2, -18 / 2 + 6, 18, 18))
                painter.end()

            #############################################
            # RANGE RESTRICTION NODE
            #################################

            elif item is Item.RangeRestrictionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.translate(0, 0)
                painter.drawText(QtCore.QRectF(0, 0, 60, 22),
                                 QtCore.Qt.AlignCenter, 'restriction')
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.translate(30, 22)
                painter.drawRect(QtCore.QRectF(-18 / 2, -18 / 2 + 6, 18, 18))
                painter.end()

            #############################################
            # INTERSECTION NODE
            #################################

            elif item is Item.IntersectionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'and')
                painter.end()

            #############################################
            # ROLE CHAIN NODE
            #################################

            elif item is Item.RoleChainNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'chain')
                painter.end()

            #############################################
            # DATATYPE RESTRICTION NODE
            #################################

            elif item is Item.DatatypeRestrictionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'data')
                painter.end()

            #############################################
            # ROLE INVERSE NODE
            #################################

            elif item is Item.RoleInverseNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'inv')
                painter.end()

            #############################################
            # COMPLEMENT NODE
            #################################

            elif item is Item.ComplementNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'not')
                painter.end()

            #############################################
            # ENUMERATION NODE
            #################################

            elif item is Item.EnumerationNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'oneOf')
                painter.end()

            #############################################
            # UNION NODE
            #################################

            elif item is Item.UnionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'or')
                painter.end()

            #############################################
            # DISJOINT-UNION NODE
            #################################

            elif item is Item.DisjointUnionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.end()

            #############################################
            # PROPERTY ASSERTION NODE
            #################################

            elif item is Item.PropertyAssertionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRoundedRect(QtCore.QRectF(-23, -15, 46, 30), 14,
                                        14)
                painter.end()

            #############################################
            # INCLUSION EDGE
            #################################

            elif item is Item.InclusionEdge:

                P1 = QtCore.QPointF(3, 22)
                P2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(P1, P2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x() + 2, L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.drawPolygon(H1)
                painter.end()

            #############################################
            # EQUIVALENCE EDGE
            #################################

            elif item is Item.EquivalenceEdge:

                P1 = QtCore.QPointF(3, 22)
                P2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(P1, P2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x(), L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3])
                P1 = QtCore.QPointF(L1.p1().x(), L1.p1().y())
                P2 = P1 + QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 + QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                T1 = QtGui.QPolygonF([P1, P2, P3])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.drawPolygon(H1)
                painter.drawPolygon(T1)
                painter.end()

            #############################################
            # INPUT EDGE
            #################################

            elif item is Item.InputEdge:

                P1 = QtCore.QPointF(3, 22)
                P2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(P1, P2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x() + 2, L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 4.0) * 8,
                    cos(A1 + M_PI / 4.0) * 8)
                P3 = P2 - QtCore.QPointF(
                    sin(A1 + 3.0 / 4.0 * M_PI) * 8,
                    cos(A1 + 3.0 / 4.0 * M_PI) * 8)
                p4 = P3 - QtCore.QPointF(
                    sin(A1 - 3.0 / 4.0 * M_PI) * 8,
                    cos(A1 - 3.0 / 4.0 * M_PI) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3, p4])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                                 QtCore.Qt.CustomDashLine, QtCore.Qt.RoundCap,
                                 QtCore.Qt.RoundJoin)
                pen.setDashPattern([3, 3])
                painter.setPen(pen)
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.drawPolygon(H1)
                painter.end()

            #############################################
            # MEMBERSHIP EDGE
            #################################

            elif item is Item.MembershipEdge:

                PP1 = QtCore.QPointF(2, 22)
                PP2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(PP1, PP2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x() + 2, L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3])
                S1 = 2 if _MACOS else 0
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.drawPolygon(H1)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.drawText(PP1.x() + S1, 18, 'instanceOf')
                painter.end()

            #############################################
            # ADD THE GENERATED PIXMAP TO THE ICON
            #################################

            icon.addPixmap(pixmap)

        return icon
Esempio n. 23
0
    def _setEndItem(self, end_point: QtCore.QPointF, brush: QtGui.QBrush,
                    checi: str, down: bool,
                    endAtThis: bool) -> QtGui.QPainterPath:
        """
        绘制终点标签。
        同时设定spanItemHeight和~width两个attribute。
        """
        # 终点标签
        endLabelText = self._setStartEndLabelText(checi, brush)
        w, h = self.spanItemWidth, self.spanItemHeight
        endLabel = QtGui.QPainterPath()
        self.endLabelText = endLabelText
        end_height = self.graph.UIConfigData()['end_label_height']
        if endAtThis:
            if down:
                endLabel.moveTo(end_point)
                curPoint = QtCore.QPointF(end_point.x(), end_point.y())
                curPoint.setY(curPoint.y() + end_height / 2)
                endLabel.lineTo(curPoint)
                poly = QtGui.QPolygonF(
                    (QtCore.QPointF(curPoint.x() - end_height / 3,
                                    curPoint.y()),
                     QtCore.QPointF(curPoint.x() + end_height / 3,
                                    curPoint.y()),
                     QtCore.QPointF(curPoint.x(),
                                    curPoint.y() + end_height / 2),
                     QtCore.QPointF(curPoint.x() - end_height / 3,
                                    curPoint.y())))
                endLabel.addPolygon(poly)
                curPoint.setY(end_point.y() + end_height)
                curPoint.setX(curPoint.x() - w / 2)
                endLabel.moveTo(curPoint)
                endLabelText.setX(curPoint.x())
                endLabelText.setY(curPoint.y())
                curPoint.setX(curPoint.x() + w)
                endLabel.lineTo(curPoint)

            else:
                endLabel.moveTo(end_point)
                curPoint = QtCore.QPointF(end_point)
                curPoint.setY(end_point.y() - end_height / 2)
                endLabel.lineTo(curPoint)
                curPoint.setY(end_point.y() - end_height)
                endLabel.moveTo(curPoint)
                poly = QtGui.QPolygonF(
                    (curPoint,
                     QtCore.QPointF(curPoint.x() - end_height / 3,
                                    curPoint.y() + end_height / 2),
                     QtCore.QPointF(curPoint.x() + end_height / 3,
                                    curPoint.y() + end_height / 2), curPoint))
                endLabel.addPolygon(poly)
                curPoint.setX(curPoint.x() - w / 2)
                endLabel.moveTo(curPoint)
                endLabelText.setX(curPoint.x())
                endLabelText.setY(curPoint.y() - h)
                curPoint.setX(curPoint.x() + w)
                endLabel.lineTo(curPoint)
        else:  # not endAtThis
            if down:
                endLabel.moveTo(end_point)
                curPoint = QtCore.QPointF(end_point)
                curPoint.setY(curPoint.y() + h)
                endLabel.lineTo(curPoint)
                endLabelText.setPos(curPoint)
                curPoint.setX(curPoint.x() + w + h)
                endLabel.lineTo(curPoint)
                curPoint.setX(curPoint.x() - h)
                curPoint.setY(curPoint.y() + h)
                endLabel.lineTo(curPoint)
            else:
                endLabel.moveTo(end_point)
                curPoint = QtCore.QPointF(end_point)
                curPoint.setY(curPoint.y() - h)
                endLabel.lineTo(curPoint)
                endLabelText.setX(curPoint.x())
                endLabelText.setY(curPoint.y() - h)
                curPoint.setX(curPoint.x() + w + h)
                endLabel.lineTo(curPoint)
                curPoint.setX(curPoint.x() - h)
                curPoint.setY(curPoint.y() - h)
                endLabel.lineTo(curPoint)

        return endLabel
Esempio n. 24
0
    def paintEvent(self, event):
        #init painter from QPainter object
        painter = QPainter(self)
        path = QPainterPath()
        painter.begin(self)

        painter.setRenderHint(QPainter.Antialiasing)
        #choose pen color
        painter.setPen(QtCore.Qt.red)
        #choose brush color
        painter.setBrush(QtCore.Qt.red)

        # print edges between nodes if exists
        for x in self.edges.values():
            painter.drawLine(x.x1, x.y1, x.x2, x.y2)
            ###################################################################################################
            ################### DRAW THE ARROWS "THIS CODE IS FROM ANOTHER SOURCE" ############################

            point_array = self.get_directed_arrow_points(
                x.x1, x.y1, x.x2, x.y2,
                20)  # get coordinates of arrow vertices

            points = [
                QtCore.QPointF(point_array[0][0], point_array[0][1]),
                QtCore.QPointF(point_array[1][0], point_array[1][1]),
                QtCore.QPointF(point_array[2][0], point_array[2][1])
            ]  # create a list of QPointF
            arrow = QtGui.QPolygonF(
                points)  # create a triangle with the given points
            painter.drawPolygon(arrow)  # draw arrow

            ######################################################################################################
            ######################################################################################################

            # set pen color to green, and type solid
        painter.setPen(QPen(Qt.green, 2, Qt.SolidLine))
        # set fill color to red
        painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))

        #init node with attributes
        node = Node(self.x, self.y, self.h, self.w, self.val)
        #add it to our dictionary
        self.NodeList[node.val] = node
        # paint our nodes
        for i in self.NodeList.values():
            painter.drawEllipse(i.x, i.y, i.h, i.w)
        # new painter for text
        txtPaint = QPainter(self)
        #set pen color for yellow
        txtPaint.setPen(QPen(Qt.yellow, 10, Qt.SolidLine))
        #paint text over nodes
        for i in self.NodeList.values():
            txtPaint.drawText(i.x + 18, i.y + 23, i.val)
        #change pen color to red
        txtPaint.setPen(QPen(Qt.black, 10, Qt.SolidLine))
        #to paint text on the middle of the edge
        for x in self.edges.values():

            point_array = self.get_directed_arrow_points(
                x.x1, x.y1, x.x2, x.y2, 20)
            xAxis = point_array[1][0]
            yAxis = point_array[1][1] - 10
            xAxis = int(xAxis)
            yAxis = int(yAxis)
            txtPaint.drawText(xAxis, yAxis, x.weight)
Esempio n. 25
0
    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        if self.display_pixmap:

            # Draw image.
            destination_rect = QtCore.QRect(0, 0, self.width(), self.height())
            painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
            painter.drawPixmap(destination_rect, self.display_pixmap)

            # Draw alignment lines & zoomed image.
            if self.adjust_mode:

                painter.setPen(QtGui.QColor(100, 100, 100))
                painter.drawLine(0.0, 0.5 * self.height(), self.width(),
                                 0.5 * self.height())
                for mult in [0.25, 0.5, 0.75]:
                    painter.drawLine(mult * self.width(), 0.0,
                                     mult * self.width(), self.height())

                if self.zoom_image:
                    destination_rect = QtCore.QRect(self.zoom_x, self.zoom_y,
                                                    self.zoom_size,
                                                    self.zoom_size)
                    painter.drawImage(destination_rect, self.zoom_image)
                    painter.setPen(QtGui.QColor(200, 200, 200))
                    painter.setBrush(QtGui.QColor(0, 0, 0, 0))
                    painter.drawRect(destination_rect)

                painter.setPen(QtGui.QColor(255, 255, 255))
                if self.fit_mode:
                    painter.drawStaticText(2, 102, self.static_text[0])
                else:
                    painter.drawStaticText(2, 102, self.static_text[1])

            # Draw focus lock feedback.
            else:
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setBrush(QtGui.QColor(0, 0, 0, 0))

                # Round green circles for fitting mode.
                if self.fit_mode:
                    painter.setPen(QtGui.QColor(0, 255, 0))
                    if self.draw_e1:
                        painter.drawEllipse(
                            QtCore.QPointF(self.x_off1, self.y_off1),
                            self.e_size, self.e_size)
                    if self.draw_e2:
                        painter.drawEllipse(
                            QtCore.QPointF(self.x_off2, self.y_off2),
                            self.e_size, self.e_size)

                # Square blue boxes for moment mode.
                else:
                    painter.setPen(QtGui.QColor(0, 0, 255))
                    if self.draw_e1:
                        painter.drawRect(self.x_off1, self.y_off1,
                                         2 * self.e_size, 2 * self.e_size)
                    if self.draw_e2:
                        painter.drawRect(self.x_off2, self.y_off2,
                                         2 * self.e_size, 2 * self.e_size)

            # display red dot (or not)
            if self.show_dot:
                painter.setPen(QtGui.QColor(255, 0, 0))
                painter.drawRect(2, 2, 2, 2)

        else:
            painter.setPen(self.background)
            painter.setBrush(self.background)
            painter.drawRect(0, 0, self.width(), self.height())
Esempio n. 26
0
 def paint(self, painter: Painter):
     if self.pose is not None:
         color = qtg.QColor(
             self.layer_model["config"]["pose"]["fixedColor"])
         if not self.layer_model["config"]["pose"]["useFixedColor"]:
             if self.role is not None:
                 color = qtg.QColor(self.layer_model["config"]["pose"][
                     Roles(self.role).name + "Color"])
     if self.searchPosition is not None and self.pose is not None:
         if self.layer_model["config"]["ballSearch"]["drawSearchTarget"]:
             # Search position
             painter.setPen(qtg.QPen(qtc.Qt.black, 0))
             painter.setBrush(color)
             painter.drawEllipse(
                 qtc.QPointF(self.searchPosition[0],
                             self.searchPosition[1]),
                 self.layer_model["config"]["ballSearch"]
                 ["searchCircleDiameter"] / 2, self.layer_model["config"]
                 ["ballSearch"]["searchCircleDiameter"] / 2)
     if self.pose is not None:
         # Transform to local coords
         painter.transformByPose(self.pose)
     if self.jointSensorData is not None and self.pose is not None:
         if self.layer_model["config"]["fov"]["drawFOV"]:
             # FOV
             painter.setBrush(qtc.Qt.NoBrush)
             painter.setPen(qtg.QPen(qtc.Qt.yellow, 0))
             painter.drawFOV(
                 [[0.0, 0.0], 0.0], self.jointSensorData[0],
                 self.layer_model["config"]["fov"]["maxDistance"],
                 self.layer_model["config"]["fov"]["cameraOpeningAngle"])
     if self.motionPlan is not None and self.pose is not None:
         if self.layer_model["config"]["motionPlan"]["drawMotionPlan"]:
             # Walking-target
             painter.setBrush(qtc.Qt.NoBrush)
             painter.setPen(color, 0)
             painter.drawTarget(
                 self.motionPlan["walkTarget"], self.layer_model["config"]
                 ["motionPlan"]["targetCircleDiameter"])
             # Dotted line to walking-target
             dotted_pen = qtg.QPen(qtc.Qt.yellow, 0, qtc.Qt.DashDotLine)
             painter.setPen(dotted_pen)
             painter.drawLineF(0.0, 0.0,
                               self.motionPlan["walkTarget"][0][0],
                               self.motionPlan["walkTarget"][0][1])
         if self.layer_model["config"]["motionPlan"]["drawTranslation"]:
             # Translation
             tl = self.motionPlan["translation"]
             painter.setPen(
                 qtg.QColor(self.layer_model["config"]["motionPlan"]
                            ["translationColor"]), 0)
             orthoOffset = [tl[1] * 0.05, -tl[0] * 0.05]
             painter.drawLineF(0.0, 0.0, tl[0], tl[1])
             painter.drawLineF(tl[0] * 0.9 - orthoOffset[0],
                               tl[1] * 0.9 - orthoOffset[1], tl[0], tl[1])
             painter.drawLineF(tl[0] * 0.9 + orthoOffset[0],
                               tl[1] * 0.9 + orthoOffset[1], tl[0], tl[1])
     if self.pose is not None:
         if self.layer_model["config"]["pose"]["drawPose"]:
             # Pose
             painter.setPen(qtg.QPen(qtc.Qt.black, 0))
             painter.setBrush(color)
             painter.drawPose([[0.0, 0.0], 0.0], self.layer_model["config"]
                              ["pose"]["positionCircleDiameter"],
                              self.layer_model["config"]["pose"]
                              ["orientationLineLength"])
Esempio n. 27
0
 def __init__(self, x: float, y: float, brush: qg.QBrush):
     super().__init__()
     self.pos = qc.QPointF(x, y)
     self.radius = 1.0
     self.setPen(qg.QPen(qc.Qt.NoPen))
     self.setBrush(brush)
Esempio n. 28
0
 def boundingRect(self):
     tl = QtCore.QPointF(self.xmin, self.ymin)
     br = QtCore.QPointF(self.xmax, self.ymax)
     return QtCore.QRectF(tl, br)
Esempio n. 29
0
    def updatePath(self):

        if (self._pointB.x() - self._pointA.x()) < 30:
            path = QtGui.QPainterPath()
            midptx = (self.pointA.x() + 13)
    
            ctrl1_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
            ctrl2_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
            pt1 = QtCore.QPointF(midptx , self.pointA.y())
            path.moveTo(pt1)
            path.cubicTo(ctrl1_1, ctrl2_1, pt1) 

            if abs(self.pointB.x()-midptx) > 150:                
                ctrl1_2 = QtCore.QPointF(midptx, self.pointB.y())
                ctrl2_2 = QtCore.QPointF(midptx, self.pointB.y())
                pt2 = QtCore.QPointF(midptx , self.pointA.y()+100)
                path.cubicTo(ctrl1_2, ctrl2_2, pt2)
                path.moveTo(pt2)

                ctrl1_3 = QtCore.QPointF(midptx, self.pointA.y()+100)
                ctrl2_3 = QtCore.QPointF(midptx, self.pointA.y()+100)
                pt3 = QtCore.QPointF(self.pointB.x()-13, self.pointA.y()+100)
                path.cubicTo(ctrl1_3, ctrl2_3, pt3)
                path.moveTo(pt3)

                ctrl1_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                ctrl2_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                pt4 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
                path.cubicTo(ctrl1_4, ctrl2_4, pt4)
                path.moveTo(pt4)

                ctrl1_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
                ctrl2_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
                pt5 = QtCore.QPointF(self.pointB.x(), self.pointB.y())
                path.cubicTo(ctrl1_5, ctrl2_5, pt5)
                path.moveTo(pt5)

                self.setPath(path)
                return
            else:
                ctrl1_2 = QtCore.QPointF(midptx, self.pointB.y())
                ctrl2_2 = QtCore.QPointF(midptx, self.pointB.y())
                pt2 = QtCore.QPointF(midptx , max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                path.cubicTo(ctrl1_2, ctrl2_2, pt2)
                path.moveTo(pt2)

                ctrl1_3 = QtCore.QPointF(midptx, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                ctrl2_3 = QtCore.QPointF(midptx, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                pt3 = QtCore.QPointF(self.pointB.x()-13,  max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                path.cubicTo(ctrl1_3, ctrl2_3, pt3)
                path.moveTo(pt3)

                ctrl1_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                ctrl2_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
                pt4 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
                path.cubicTo(ctrl1_4, ctrl2_4, pt4)
                path.moveTo(pt4)

                ctrl1_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
                ctrl2_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
                pt5 = QtCore.QPointF(self.pointB.x(), self.pointB.y())
                path.cubicTo(ctrl1_5, ctrl2_5, pt5)
                path.moveTo(pt5)

                self.setPath(path)
                return
        
        path = QtGui.QPainterPath()
        path.moveTo(self.pointA)
        midptx = 0.5*(self.pointA.x() + self.pointB.x())
 
        ctrl1_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
        ctrl2_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
        pt1 = QtCore.QPointF(midptx , self.pointA.y())
        path.cubicTo(ctrl1_1, ctrl2_1, pt1) 
        path.moveTo(pt1)

        ctrl1_2 = QtCore.QPointF(midptx, self.pointB.y())
        ctrl2_2 = QtCore.QPointF(midptx, self.pointB.y())
        pt2 = QtCore.QPointF(midptx , self.pointB.y())
        path.cubicTo(ctrl1_2, ctrl2_2, pt2)
        path.moveTo(pt2)

        ctrl1_3 = QtCore.QPointF(midptx, self.pointB.y())
        ctrl2_3 = QtCore.QPointF(midptx, self.pointB.y())
        path.cubicTo(ctrl1_3, ctrl2_3, self.pointB)
        path.moveTo(self.pointB)
        self.setPath(path)
Esempio n. 30
0
    def paint(self, painter, styleOptionGraphicsItem, widget_widget=None):
        #super(CodeUIItem, self).paint(painter, styleOptionGraphicsItem, widget_widget)

        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setRenderHint(QtGui.QPainter.TextAntialiasing)
        r = self.getBodyRadius()

        trans = painter.worldTransform()
        lod = QtWidgets.QStyleOptionGraphicsItem().levelOfDetailFromTransform(
            trans)

        selectedOrHover = self.isSelected() or self.isHover

        if r * lod > 1.0:
            if selectedOrHover:
                pen = QtGui.QPen(
                    QtGui.QBrush(QtGui.QColor(255, 157, 38, 255)), 20.0
                )  #, QtCore.Qt.SolidLine, QtCore.Qt.SquareCap, QtCore.Qt.RoundJoin)
                painter.setPen(pen)
                self.drawShape(painter)

            painter.setPen(QtCore.Qt.NoPen)

            clr = self.color
            if self.isFunction():
                painter.setBrush(clr)
                nCaller = self.customData.get('nCaller', 0)
                nCallee = self.customData.get('nCallee', 0)
                if nCaller > 0:
                    cr = self.customData['callerR']
                    painter.drawPie(-r - cr, -cr, cr * 2, cr * 2, 160 * 16,
                                    40 * 16)
                if nCallee > 0:
                    cr = self.customData['calleeR']
                    painter.drawPie(r - cr, -cr, cr * 2, cr * 2, -20 * 16,
                                    40 * 16)

            clr = self.color
            painter.setBrush(clr)
            self.drawShape(painter)

            if self.kind == ITEM_FUNCTION and (
                    self.lines == 0 or self.customData.get('hasDef') == False):
                painter.setBrush(QtGui.QColor(50, 50, 50, 255))
                painter.setPen(QtCore.Qt.NoPen)
                painter.drawEllipse(QtCore.QPointF(0, 0), 2.5, 2.5)

        if r * lod > 2 or selectedOrHover:
            painter.scale(1.0 / lod, 1.0 / lod)
            painter.setPen(QtGui.QPen())
            painter.setFont(self.titleFont)
            if self.kind == ITEM_VARIABLE:
                rect = QtCore.QRectF(r, self.lineHeight * -0.5,
                                     self.fontSize.width(),
                                     self.fontSize.height())
            else:
                rect = QtCore.QRectF(0, 0, self.fontSize.width(),
                                     self.fontSize.height())

            dx = 1.0
            painter.setPen(QtGui.QPen(QtGui.QColor(50, 50, 50)))
            rect0 = rect.translated(dx, dx)
            painter.drawText(rect0, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop,
                             self.displayName)

            painter.setPen(QtGui.QPen(QtGui.QColor(255, 239, 183)))
            painter.drawText(rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop,
                             self.displayName)

            scene = self.scene()
            commentData = scene.itemDataDict.get(self.uniqueName,
                                                 {}).get('comment')
            if commentData:
                painter.setPen(QtGui.QPen(QtGui.QColor(166, 241, 27)))
                rect.moveTop(rect.bottom())
                rect.setSize(QtCore.QSizeF(100, 500))
                painter.drawText(
                    rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop
                    | QtCore.Qt.TextWordWrap, commentData)