コード例 #1
0
ファイル: PaintBoard.py プロジェクト: skianzad/MagicPen
    def penMoveEvent(self, pos, pressure, liftedDeque):
        pen_x = pos[0]
        pen_y = pos[1]
        pen_pressure = pressure

        # print(liftedDeque)
        # print(self.__lastPos)

        if self.__lastPos is None:
            self.__lastPos = QPoint(pen_x, pen_y)

        self.__currentPos = QPoint(pen_x, pen_y)
        self.__painter.begin(self.__board)

        if self.EraserMode == False:
            #Non-Eraser mode
            self.__penColor = QColor("blue")
            self.__painter.setPen(QPen(
                self.__penColor, self.__thickness))  #Set pen color, thickness
        else:
            #Eraser mode: pen color is white, thickness is 6
            self.__painter.setPen(QPen(Qt.white, 6))

        self.__painter.drawLine(self.__lastPos, self.__currentPos)
        self.__painter.end()
        self.__lastPos = self.__currentPos

        self.update()  #Show updates

        # If ever detected the pen is lifted, reset the __lastPos variable in order to reposition the pen
        if (True in liftedDeque):
            self.__lastPos = None
コード例 #2
0
    def drawScaleContents(self, painter, center, radius):
        dir = 90  #360 - int(roud(self.origin() - self.value()))
        arc = 90  #+ int(round(self.gradient * 90))
        skyColor = QColor(38, 151, 221)
        painter.save()
        painter.setBrush(skyColor)
        painter.drawChord(self.scaleContentsRect(), (dir - arc) * 16,
                          2 * arc * 16)
        direction1 = self.value() * M_PI / 180.0
        direction2 = self.value() * M_PI / 180.0 + M_PI_2

        triangleSize = qRound(radius * 0.15)
        p0 = (QPoint(center.x() + 0, center.y() + 0))
        p1 = qwtPolar2Pos(p0, 2, direction2)
        pa = QPolygon(3)
        pa.setPoint(0, qwtPolar2Pos(p1, 2 * triangleSize, direction2))
        pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction2 + M_PI_2))
        pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction2 - M_PI_2))
        color = self.palette().color(QPalette.Text)
        painter.setBrush(color)
        painter.drawPolygon(pa)

        p0 = (QPoint(center.x() + 0, center.y() + 0))
        color = self.palette().color(QPalette.Text)
        painter.setBrush(color)
        painter.setPen(QPen(color, 3))
        painter.drawLine(qwtPolar2Pos(p0, radius - 3, direction1),
                         qwtPolar2Pos(p0, radius - 3, direction1 - M_PI))

        painter.restore()
コード例 #3
0
ファイル: PaintBoard.py プロジェクト: skianzad/MagicPen
    def penMoveEvent(self, pos, pressure):
        pen_x = pos[0]
        pen_y = pos[1]
        pen_pressure = pressure

        if self.__lastPos is None:
            self.__lastPos = QPoint(pen_x, pen_y)
        elif (abs(pen_x - self.__lastPos.x()) > 21
              or abs(pen_y - self.__lastPos.y()) > 21):
            self.__lastPos = QPoint(pen_x, pen_y)

        self.__currentPos = QPoint(pen_x, pen_y)
        self.__painter.begin(self.__board)

        if self.EraserMode == False:
            #Non-Eraser mode
            self.__painter.setPen(QPen(
                self.__penColor, self.__thickness))  #Set pen color, thickness
        else:
            #Eraser mode: pen color is white, thickness is 6
            self.__painter.setPen(QPen(Qt.white, 6))

        self.__painter.drawLine(self.__lastPos, self.__currentPos)
        self.__painter.end()
        self.__lastPos = self.__currentPos

        self.update()  #Show updates
コード例 #4
0
 def mousePressEvent(self, event):
     self.drag_is_not_DND = False  # don't know yet
     qp = event.globalPos()  # clone the point to keep it constant
     self.mouse_press_qpoint = QPoint(qp.x(), qp.y())
     self.mouse_press_event = QMouseEvent(event.type(),
                                          QPoint(event.x(), event.y()),
                                          event.button(), event.buttons(),
                                          event.modifiers())
コード例 #5
0
 def compute_path(self):
     p1 = self.p1 if self.p1.x() < self.p2.x() else self.p2
     p2 = self.p2 if self.p1.x() < self.p2.x() else self.p1
     path = QPainterPath()
     path.moveTo(p1)
     dx = p2.x() - p1.x()
     path.cubicTo(QPoint(p1.x() + dx / 3, p1.y()), QPoint(p2.x() - dx / 3, p2.y()), p2)
     self.__path = path
コード例 #6
0
 def contains(self, p: QPoint):
     cx = self.pos.x() + self.size / 2.0
     cy = self.pos.y() + self.size / 2.0
     dx = p.x() - cx
     dy = p.y() - cy
     if math.sqrt(dx * dx + dy * dy) <= self.size + 1:
         return True
     return False
コード例 #7
0
ファイル: PaintBoard.py プロジェクト: skianzad/MagicPen
    def paintPolyg(self, x1, y1, x2, y2, x3, y3, x4, y4):
        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawPolygon(QPoint(x1, y1), QPoint(x2, y2),
                                   QPoint(x3, y3), QPoint(x4, y4))
        self.__painter.end()

        self.update()  #Show updates
コード例 #8
0
ファイル: PaintBoard.py プロジェクト: skianzad/MagicPen
    def paintLine(self, P1_x, P1_y, P2_x, P2_y):
        P1 = QPoint(P1_x, P1_y)
        P2 = QPoint(P2_x, P2_y)

        self.__painter.begin(self.__board)
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawLine(P1, P2)
        self.__painter.end()

        self.update()  #Show updates
コード例 #9
0
    def mouseMoveEvent(self, e: QMouseEvent):
        if self.__action == Action.DRAG:
            dx = e.x() - self.__origin.x()
            dy = e.y() - self.__origin.y()
            self.set_pos(self.x() + dx, self.y() + dy)
        elif self.__action == Action.RESIZE:
            self.set_size(e.x(), e.y())
        elif self.__action == Action.CONNECTING and self.__line is not None:
            p = QPoint(e.x() + self.x(), e.y() + self.y())

            n = self.parent().get_node(p)
            if n is not None and n.compatible(self.__line.n1):
                self.__line.status(True)
            else:
                self.__line.status(False)

            self.__line.update(p)

        else:
            n = self.node(e.pos())
            if self.__label is None and n is not None:
                self.__label = self.parent().create_label(self.node_name(n), n)
            elif self.__label is not None and self.__label.node() is not n and n is not None:
                self.parent().delete_label(self.__label)
                self.__label = self.parent().create_label(self.node_name(n), n)
            elif n is None:
                self.parent().delete_label(self.__label)
                self.__label = None
コード例 #10
0
ファイル: alternate_views.py プロジェクト: siebert/calibre
 def first_visible_row(self):
     geom = self.viewport().geometry()
     for y in xrange(geom.top(), (self.spacing()*2) + geom.top(), 5):
         for x in xrange(geom.left(), (self.spacing()*2) + geom.left(), 5):
             ans = self.indexAt(QPoint(x, y)).row()
             if ans > -1:
                 return ans
コード例 #11
0
 def _paint_widget(self, p):
     if self._widget is not None and (self.mode() == Mode.DEBUG or self.mode() == Mode.EDIT_LOGIC):
         p.setClipRect(Block.padding + 5, 5 + Block.padding, self.width() - 2 * Block.padding - 10,
                       25)
         p.translate(self.padding + 5, 5 + self.padding)
         self._widget.render(p, QPoint(), QRegion(0, 0, self.width(), 25),
                             QWidget.IgnoreMask)
コード例 #12
0
    def virtual_library_clicked(self):
        m = self.virtual_library_menu
        m.clear()

        a = m.addAction(_('Create Virtual Library'))
        a.triggered.connect(partial(self.do_create_edit, name=None))

        a = self.edit_menu
        self.build_virtual_library_list(a, self.do_create_edit)
        m.addMenu(a)

        a = self.rm_menu
        self.build_virtual_library_list(a, self.remove_vl_triggered)
        m.addMenu(a)

        m.addSeparator()

        db = self.library_view.model().db

        a = self.ar_menu
        a.clear()
        a.setIcon(self.checked if db.data.get_search_restriction_name(
        ) else self.empty)
        self.build_search_restriction_list()
        m.addMenu(a)

        m.addSeparator()

        current_lib = db.data.get_base_restriction_name()

        if current_lib == '':
            a = m.addAction(self.checked, self.no_restriction)
        else:
            a = m.addAction(self.empty, self.no_restriction)
        a.triggered.connect(partial(self.apply_virtual_library, library=''))

        a = m.addAction(self.empty, _('*current search'))
        a.triggered.connect(partial(self.apply_virtual_library, library='*'))

        if self.search_based_vl_name:
            a = m.addAction(
                self.checked
                if db.data.get_base_restriction_name().startswith('*') else
                self.empty, self.search_based_vl_name)
            a.triggered.connect(
                partial(self.apply_virtual_library,
                        library=self.search_based_vl_name))

        m.addSeparator()

        virt_libs = db.prefs.get('virtual_libraries', {})
        for vl in sorted(virt_libs.keys(), key=sort_key):
            a = m.addAction(self.checked if vl == current_lib else self.empty,
                            vl)
            a.triggered.connect(partial(self.apply_virtual_library,
                                        library=vl))

        p = QPoint(0, self.virtual_library.height())
        self.virtual_library_menu.popup(self.virtual_library.mapToGlobal(p))
コード例 #13
0
ファイル: alternate_views.py プロジェクト: siebert/calibre
 def last_visible_row(self):
     geom = self.viewport().geometry()
     for y in xrange(geom.bottom(), geom.bottom() - 2 * self.spacing(), -5):
         for x in xrange(geom.left(), (self.spacing()*2) + geom.left(), 5):
             ans = self.indexAt(QPoint(x, y)).row()
             if ans > -1:
                 item_width = self.delegate.item_size.width() + 2*self.spacing()
                 return ans + (geom.width() // item_width)
コード例 #14
0
 def get_node(self, p):
     for b in self.blocks:
         if b.geometry().contains(p):
             p1 = QPoint(p.x() - b.x(), p.y() - b.y())
             n = b.node(p1)
             if n is not None:
                 return n
     return None
コード例 #15
0
 def __init__(self, type_name: str, name: str, parent: QWidget=None):
     QWidget.__init__(self, parent)
     self.settings = {"Name": Setting("Name", StringValue(name), parent=self)}
     self.outputs = {}
     self.inputs = {}
     self.__type_name = type_name
     self._bg_color = QColor(159, 160, 144, 255)
     self._fg_color = QColor(255, 255, 255)
     self._resizable = True
     self.setMinimumSize(90, 120)
     self.__origin = QPoint(0, 0)
     self.__action = Action.NONE
     self.__status = Mode.EDIT_LOGIC
     self.__selected = False
     self.__line = None
     self.__label = None
     self.setMouseTracking(True)
     if self._resizable:
         self.__init_corner()
コード例 #16
0
ファイル: PaintBoard.py プロジェクト: skianzad/MagicPen
    def paintEllipse(self, center_x, center_y, radias1, radias2):
        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawEllipse(QPoint(center_x, center_y), radias1,
                                   radias2)

        self.__painter.end()

        self.update()  #Show updates
コード例 #17
0
ファイル: PaintBoard.py プロジェクト: skianzad/MagicPen
    def paintBezierSpline(self, pointListX, pointListY):
        P1 = QPoint(int(pointListX[0]), int(pointListY[0]))
        path = QtGui.QPainterPath()
        path.moveTo(P1)

        self.__painter.begin(self.__board)
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))

        i = 0
        while i < len(pointListX) - 3:
            P2 = QPoint(int(pointListX[i + 1]), int(pointListY[i + 1]))
            P3 = QPoint(int(pointListX[i + 2]), int(pointListY[i + 2]))
            P4 = QPoint(int(pointListX[i + 3]), int(pointListY[i + 3]))
            path.cubicTo(P2, P3, P4)
            self.__painter.drawPath(path)
            i += 3

        self.__painter.end()

        self.update()  #Show updates
コード例 #18
0
 def check_line(self, line):
     p = line.p2
     for b in self.blocks:
         if b.geometry().contains(p):
             p1 = QPoint(p.x() - b.x(), p.y() - b.y())
             n = b.node(p1)
             if n is not None and n.compatible(
                     line.n1) and line.n1.compatible(n):
                 line.connect(n)
                 return
     line.remove()
コード例 #19
0
 def drawScale(self, painter, center, radius, origin, minArc, maxArc):
     direction1 = M_PI_2
     triangleSize = qRound(radius * 0.15)
     p0 = (QPoint(center.x() + 0, center.y() + 0))
     p1 = qwtPolar2Pos(p0, radius - 2 * triangleSize + 20, direction1)
     pa = QPolygon(3)
     pa.setPoint(0, qwtPolar2Pos(p1, -1.6 * triangleSize, direction1))
     pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction1 + M_PI_2))
     pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction1 - M_PI_2))
     color = self.palette().color(QPalette.Text)
     painter.setBrush(color)
     painter.drawPolygon(pa)
コード例 #20
0
ファイル: views.py プロジェクト: oheil/calibre
 def drag_data(self):
     m = self.model()
     rows = self.selectionModel().selectedRows()
     paths = [force_unicode(p, enc=filesystem_encoding) for p in m.paths(rows) if p]
     md = QMimeData()
     md.setData('application/calibre+from_device', 'dummy')
     md.setUrls([QUrl.fromLocalFile(p) for p in paths])
     drag = QDrag(self)
     drag.setMimeData(md)
     cover = self.drag_icon(m.cover(self.currentIndex().row()), len(paths) >
             1)
     drag.setHotSpot(QPoint(-15, -15))
     drag.setPixmap(cover)
     return drag
コード例 #21
0
    def popup(self, select_first=True):
        if self.disable_popup:
            return
        p = self
        m = p.model()
        widget = self.completer_widget()
        if widget is None:
            return
        screen = QApplication.desktop().availableGeometry(widget)
        h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) +
             3) + 3
        hsb = p.horizontalScrollBar()
        if hsb and hsb.isVisible():
            h += hsb.sizeHint().height()

        rh = widget.height()
        pos = widget.mapToGlobal(QPoint(0, widget.height() - 2))
        w = min(widget.width(), screen.width())

        if (pos.x() + w) > (screen.x() + screen.width()):
            pos.setX(screen.x() + screen.width() - w)
        if pos.x() < screen.x():
            pos.setX(screen.x())

        top = pos.y() - rh - screen.top() + 2
        bottom = screen.bottom() - pos.y()
        h = max(h, p.minimumHeight())
        if h > bottom:
            h = min(max(top, bottom), h)

            if top > bottom:
                pos.setY(pos.y() - h - rh + 2)

        p.setGeometry(pos.x(), pos.y(), w, h)

        if (tweaks['preselect_first_completion'] and select_first
                and not self.currentIndex().isValid()
                and self.model().rowCount() > 0):
            self.setCurrentIndex(self.model().index(0))

        if not p.isVisible():
            if isosx and get_osx_version() >= (10, 9, 0):
                # On mavericks the popup menu seems to use a font smaller than
                # the widgets font, see for example:
                # https://bugs.launchpad.net/bugs/1243761
                fp = QFontInfo(widget.font())
                f = QFont()
                f.setPixelSize(fp.pixelSize())
                self.setFont(f)
            p.show()
コード例 #22
0
 def draw(self, painter, center, length, direction, cg):
     direction1 = direction * M_PI / 180.0
     triangleSize = qRound(length * 0.1)
     painter.save()
     p0 = (QPoint(center.x() + 0, center.y() + 0))
     p1 = qwtPolar2Pos(p0, length - 2 * triangleSize - 2, direction1)
     pa = QPolygon(3)
     pa.setPoint(0, qwtPolar2Pos(p1, 2 * triangleSize, direction1))
     pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction1 + M_PI_2))
     pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction1 - M_PI_2))
     color = self.palette().color(cg, QPalette.Text)
     painter.setBrush(color)
     painter.drawPolygon(pa)
     painter.setPen(QPen(color, 3))
     painter.drawLine(qwtPolar2Pos(p0, length - 2, direction1 + M_PI_2),
                      qwtPolar2Pos(p0, length - 2, direction1 - M_PI_2))
     painter.restore()
コード例 #23
0
ファイル: PaintBoard.py プロジェクト: skianzad/MagicPen
    def __InitData(self, sizeX, sizeY):
        self.__size = QSize(sizeX, sizeY)

        self.__board = QPixmap(
            self.__size)  # Make a new QPixmap as paint board,350px * 250px
        self.__board.fill(Qt.white)  #Fill the paint board with white

        self.__IsEmpty = True  #board is empty by default
        self.EraserMode = False  #eraser mode is disabled by default

        self.__lastPos = None
        self.__currentPos = QPoint(0, 0)

        self.__painter = QPainter()

        self.__thickness = 1  #default pen thickness is 1
        self.__penColor = QColor("black")  #default color is black
        self.__colorList = QColor.colorNames()  #get the list of colors
コード例 #24
0
ファイル: test.py プロジェクト: sss/calibre
def full(p, xmax, ymax):
    p.drawRect(0, 0, xmax, ymax)
    p.drawPolyline(QPoint(0, 0), QPoint(xmax, 0), QPoint(xmax, ymax),
                   QPoint(0, ymax), QPoint(0, 0))
    pp = QPainterPath()
    pp.addRect(0, 0, xmax, ymax)
    p.drawPath(pp)
    p.save()
    for i in xrange(3):
        col = [0, 0, 0, 200]
        col[i] = 255
        p.setOpacity(0.3)
        p.fillRect(0, 0, xmax / 10, xmax / 10, QBrush(QColor(*col)))
        p.setOpacity(1)
        p.drawRect(0, 0, xmax / 10, xmax / 10)
        p.translate(xmax / 10, xmax / 10)
        p.scale(1, 1.5)
    p.restore()

    # p.scale(2, 2)
    # p.rotate(45)
    p.drawPixmap(0, 0, xmax / 4, xmax / 4, QPixmap(I('library.png')))
    p.drawRect(0, 0, xmax / 4, xmax / 4)

    f = p.font()
    f.setPointSize(20)
    # f.setLetterSpacing(f.PercentageSpacing, 200)
    f.setUnderline(True)
    # f.setOverline(True)
    # f.setStrikeOut(True)
    f.setFamily('Calibri')
    p.setFont(f)
    # p.setPen(QColor(0, 0, 255))
    # p.scale(2, 2)
    # p.rotate(45)
    p.drawText(QPoint(xmax / 3.9, 30), 'Some—text not By’s ū --- Д AV ff ff')

    b = QBrush(Qt.HorPattern)
    b.setColor(QColor(Qt.blue))
    pix = QPixmap(I('console.png'))
    w = xmax / 4
    p.fillRect(0, ymax / 3, w, w, b)
    p.fillRect(xmax / 3, ymax / 3, w, w, QBrush(pix))
    x, y = 2 * xmax / 3, ymax / 3
    p.drawTiledPixmap(QRectF(x, y, w, w), pix, QPointF(10, 10))

    x, y = 1, ymax / 1.9
    g = QLinearGradient(QPointF(x, y), QPointF(x + w, y + w))
    g.setColorAt(0, QColor('#00f'))
    g.setColorAt(1, QColor('#fff'))
    p.fillRect(x, y, w, w, QBrush(g))
コード例 #25
0
def drag_data(self):
    m = self.model()
    db = m.db
    selected = self.get_selected_ids()
    ids = ' '.join(map(str, selected))
    md = QMimeData()
    md.setData('application/calibre+from_library', ids)
    fmt = prefs['output_format']

    def url_for_id(i):
        try:
            ans = db.format_path(i, fmt, index_is_id=True)
        except:
            ans = None
        if ans is None:
            fmts = db.formats(i, index_is_id=True)
            if fmts:
                fmts = fmts.split(',')
            else:
                fmts = []
            for f in fmts:
                try:
                    ans = db.format_path(i, f, index_is_id=True)
                except:
                    ans = None
        if ans is None:
            ans = db.abspath(i, index_is_id=True)
        return QUrl.fromLocalFile(ans)

    md.setUrls([url_for_id(i) for i in selected])
    drag = QDrag(self)
    col = self.selectionModel().currentIndex().column()
    try:
        md.column_name = self.column_map[col]
    except AttributeError:
        md.column_name = 'title'
    drag.setMimeData(md)
    cover = self.drag_icon(m.cover(self.currentIndex().row()),
                           len(selected) > 1)
    drag.setHotSpot(QPoint(-15, -15))
    drag.setPixmap(cover)
    return drag
コード例 #26
0
 def recount(self, *args):
     '''
     Rebuild the category tree, expand any categories that were expanded,
     reset the search states, and reselect the current node.
     '''
     if self.disable_recounting or not self.pane_is_visible:
         return
     self.refresh_signal_processed = True
     ci = self.currentIndex()
     if not ci.isValid():
         ci = self.indexAt(QPoint(10, 10))
     path = self.model().path_for_index(ci) if self.is_visible(ci) else None
     expanded_categories, state_map = self.get_state()
     self._model.rebuild_node_tree(state_map=state_map)
     self.blockSignals(True)
     for category in expanded_categories:
         idx = self._model.index_for_category(category)
         if idx is not None and idx.isValid():
             self.expand(idx)
     self.show_item_at_path(path)
     self.blockSignals(False)
コード例 #27
0
ファイル: complete2.py プロジェクト: sss/calibre
    def popup(self, select_first=True):
        p = self
        m = p.model()
        widget = self.completer_widget()
        if widget is None:
            return
        screen = QApplication.desktop().availableGeometry(widget)
        h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) +
             3) + 3
        hsb = p.horizontalScrollBar()
        if hsb and hsb.isVisible():
            h += hsb.sizeHint().height()

        rh = widget.height()
        pos = widget.mapToGlobal(QPoint(0, widget.height() - 2))
        w = min(widget.width(), screen.width())

        if (pos.x() + w) > (screen.x() + screen.width()):
            pos.setX(screen.x() + screen.width() - w)
        if pos.x() < screen.x():
            pos.setX(screen.x())

        top = pos.y() - rh - screen.top() + 2
        bottom = screen.bottom() - pos.y()
        h = max(h, p.minimumHeight())
        if h > bottom:
            h = min(max(top, bottom), h)

            if top > bottom:
                pos.setY(pos.y() - h - rh + 2)

        p.setGeometry(pos.x(), pos.y(), w, h)

        if (tweaks['preselect_first_completion'] and select_first
                and not self.currentIndex().isValid()
                and self.model().rowCount() > 0):
            self.setCurrentIndex(self.model().index(0))

        if not p.isVisible():
            p.show()
コード例 #28
0
ファイル: Basics.py プロジェクト: Mandarancio/OpenIris
class Block(QWidget):
    border_color = QColor(137, 117, 89)
    border_pen = QPen(border_color, 2)
    selected_pen = QPen(border_color.lighter().lighter(), 2)
    padding = 5

    def __init__(self, type_name: str, name: str, parent: QWidget=None):
        QWidget.__init__(self, parent)
        self.settings = {"Name": Setting("Name", StringValue(name), parent=self)}
        self.outputs = {}
        self.inputs = {}
        self.__type_name = type_name
        self._bg_color = QColor(159, 160, 144, 255)
        self._fg_color = QColor(255, 255, 255)
        self._resizable = True
        self.setMinimumSize(90, 120)
        self.__origin = QPoint(0, 0)
        self.__action = Action.NONE
        self.__status = Mode.EDIT_LOGIC
        self.__selected = False
        self.__line = None
        self.__label = None
        self.setMouseTracking(True)
        if self._resizable:
            self.__init_corner()

    def remove_connections(self):
        for k in self.inputs:
            self.inputs[k].delete()
        for k in self.outputs:
            self.outputs[k].delete()

    def delete(self):
        self.remove_connections()

    def name(self):
        return self.settings["Name"].data()

    def type_name(self):
        return self.__type_name

    def mode(self):
        return self.__status

    def action(self):
        return self.__action

    def setVisible(self, val):
        QWidget.setVisible(self, val)
        self.update_nodes()

    def set_mode(self, mode):
        self.__status = mode
        if (mode == Mode.EDIT_LOGIC or mode == Mode.DEBUG) and not self.isVisible():
            self.setVisible(True)
        elif (mode == Mode.RUN or mode == Mode.EDIT_GUI) and self.isVisible():
            self.setVisible(False)

    def __init_corner(self):
        path = QPainterPath()
        path.moveTo(-Block.padding, -15 - Block.padding)
        path.lineTo(-15 - Block.padding, -Block.padding)
        path.lineTo(-Block.padding, -Block.padding)
        path.closeSubpath()
        self.__corner_path = path

    def _add_input(self, name: str, t: Type):
        if not name in self.inputs:
            x = 1
            y = 40 + Block.padding + len(self.inputs) * 13
            self.inputs[name] = Input(t, QPoint(x, y), self)

    def _add_output(self, name: str, t: Type):
        if not name in self.outputs:
            x = self.width() - 10
            y = 40 + Block.padding + len(self.outputs) * 13
            self.outputs[name] = Output(t, QPoint(x, y), self)

    def _add_setting(self, name, value, constant=False):
        self.settings[name] = Setting(name, value, constant, self)

    def bg(self):
        return self._bg_color

    def title_bg(self):
        return self._bg_color.light(80)

    def selected(self):
        return self.__selected

    def set_selected(self, selected):
        self.__selected = selected

    def deselect(self):
        if self.__selected:
            self.set_selected(False)
            eff = self.graphicsEffect()
            del eff
            self.setGraphicsEffect(None)

    def select(self):
        if not self.__selected:
            self.set_selected(True)
            effect = QGraphicsDropShadowEffect()
            effect.setBlurRadius(20)
            effect.setXOffset(0)
            effect.setYOffset(0)
            effect.setColor(QColor(0, 0, 0, 180))
            self.setGraphicsEffect(effect)
            self.raise_()

    def pen(self):
        return Block.selected_pen if self.__selected else Block.border_pen

    def _paint(self, p: QPainter):
        self._paint_bg(p)
        self._paint_title(p)
        p.setPen(QPen(self.pen().brush(), 1))
        self._paint_ins(p)
        self._paint_outs(p)
        self._paint_content(p)

    def _paint_bg(self, p: QPainter):
        pen = Block.selected_pen if self.__selected else Block.border_pen
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setPen(pen)
        p.setBrush(self.bg())
        p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding,
                          self.height() - 2 * Block.padding, 8, 8)
        p.setBrush(self.title_bg())
        p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding, 35 + Block.padding, 8, 8)
        p.setBrush(self.bg())
        p.setPen(QColor(0, 0, 0, 0))
        p.drawRect(1 + Block.padding, 35 + Block.padding, self.width() - 2 - 2 * Block.padding, 10)
        p.setPen(pen)
        if self._resizable:
            p.setBrush(pen.brush())
            p.drawPath(self.__corner_path.translated(self.width(), self.height()))

    def _paint_title(self, p: QPainter):
        p.drawLine(Block.padding, 35 + Block.padding, self.width() - Block.padding, 35 + Block.padding)
        p.setPen(self._fg_color)
        f = p.font()
        f.setPointSize(10)
        f.setBold(True)
        p.setFont(f)
        p.drawText(QRectF(4 + Block.padding, Block.padding + 2, self.width() - 12, 25),
                   str(self.settings["Name"].value()))
        f.setBold(False)
        f.setPointSize(8)
        p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 100))
        p.setFont(f)
        p.drawText(QRectF(4 + Block.padding, 18 + Block.padding, self.width() - 12, 15), str(self.__type_name))

    def _paint_ins(self, p: QPainter):
        for i in self.inputs:
            self.inputs[i].paint(p)

    def _paint_outs(self, p: QPainter):
        for i in self.outputs:
            self.outputs[i].paint(p)

    def _paint_content(self, p: QPainter):
        # nothing to do
        return

    def paintEvent(self, e: QPaintEvent):
        if e.isAccepted():
            p = QPainter(self)
            self._paint(p)

    def _check_action(self, action):
        if self.__action != Action.NONE and action != Action.NONE:
            return False
        return True

    def node(self, p):
        for k in self.inputs:
            i = self.inputs[k]
            if i.contains(p):
                return i
        for k in self.outputs:
            o = self.outputs[k]
            if o.contains(p):
                return o
        return None

    def node_name(self, n):
        for k in self.inputs:
            i = self.inputs[k]
            if n == i:
                return k
        for k in self.outputs:
            o = self.outputs[k]
            if o == n:
                return k
        return ''

    def __create_line(self, n):
        l = n.get_line()
        self.parent().add_line(l)
        return l

    def mousePressEvent(self, e: QMouseEvent):
        self.parent().select(self)
        n = self.node(e.pos())

        if n is not None:
            self.__line = self.__create_line(n)
            self.__action = Action.CONNECTING
            if self.__label is not None and self.__label.node() is not n:
                self.parent().delete_label(self.__label)
                self.__label = None
            return

        if self.__label is not None:
            self.parent().delete_label(self.__label)
            self.__label = None

        if self._resizable:
            if abs(e.x() - self.width()) < 8 + Block.padding \
                    and abs(e.y() - self.height()) < 8 + Block.padding \
                    and self._check_action(Action.RESIZE):
                self.__origin = e.pos()
                self.__action = Action.RESIZE
                return
        if self._check_action(Action.DRAG):
            self.__origin = e.pos()
            self.__action = Action.DRAG

    def mouseMoveEvent(self, e: QMouseEvent):
        if self.__action == Action.DRAG:
            dx = e.x() - self.__origin.x()
            dy = e.y() - self.__origin.y()
            self.set_pos(self.x() + dx, self.y() + dy)
        elif self.__action == Action.RESIZE:
            self.set_size(e.x(), e.y())
        elif self.__action == Action.CONNECTING and self.__line is not None:
            p = QPoint(e.x() + self.x(), e.y() + self.y())

            n = self.parent().get_node(p)
            if n is not None and n.compatible(self.__line.n1):
                self.__line.status(True)
            else:
                self.__line.status(False)

            self.__line.update(p)

        else:
            n = self.node(e.pos())
            if self.__label is None and n is not None:
                self.__label = self.parent().create_label(self.node_name(n), n)
            elif self.__label is not None and self.__label.node() is not n and n is not None:
                self.parent().delete_label(self.__label)
                self.__label = self.parent().create_label(self.node_name(n), n)
            elif n is None:
                self.parent().delete_label(self.__label)
                self.__label = None

    def mouseReleaseEvent(self, e: QMouseEvent):
        if self.__action == Action.CONNECTING and self.__line is not None:
            self.parent().check_line(self.__line)
            self.__line = None
        self.__action = Action.NONE
        if self.__label is not None:
            self.parent().delete_label(self.__label)
            self.__label = None

    def leaveEvent(self, e):
        QWidget.leaveEvent(self, e)
        if self.__label is not None:
            self.parent().delete_label(self.__label)
            self.__label = None

    def mouseDoubleClickEvent(self, e: QMouseEvent):
        self._double_click()

    def _double_click(self):
        # to be defined in the sub blocks
        return

    def set_pos(self, x: int, y: int):
        xx = x if x >= 0 else 0
        yy = y if y >= 0 else 0
        if xx + self.width() > self.parent().width():
            xx = self.parent().width() - self.width()
        if yy + self.height() > self.parent().height():
            yy = self.parent().height() - self.height()
        self.setGeometry(xx, yy, self.width(), self.height())

    def set_size(self, w: int, h: int):
        if self._resizable:
            width = w if w >= self.minimumWidth() else self.minimumWidth()
            height = h if h >= self.minimumHeight() else self.minimumHeight()
            self.setGeometry(self.x(), self.y(), width, height)

    def setGeometry(self, *__args):
        QWidget.setGeometry(self, *__args)
        self.update_nodes()

    def update_nodes(self):
        x = self.width() - 5 - Block.padding
        for k in self.outputs:
            o = self.outputs[k]
            o.pos.setX(x)
            o.set_visible(self.isVisible())
            o.update()
        for k in self.inputs:
            i = self.inputs[k]
            i.set_visible(self.isVisible())
            i.update()

    def _corner_path(self):
        return self.__corner_path
コード例 #29
0
ファイル: widgets.py プロジェクト: alexston/calibre-webserver
    def paintEvent(self, ev):
        offset = QPoint(0, 0)
        p = QPainter(self)
        p.setClipRect(ev.rect())
        bottom = self.rect().bottom()

        if self.results:
            for i, (prefix, full, text) in enumerate(self.results):
                size = prefix.size()
                if offset.y() + size.height() > bottom:
                    break
                self.max_result = i
                offset.setX(0)
                if i in (self.current_result, self.mouse_hover_result):
                    p.save()
                    if i != self.current_result:
                        p.setPen(Qt.DotLine)
                    p.drawLine(offset, QPoint(self.width(), offset.y()))
                    p.restore()
                offset.setY(offset.y() + self.MARGIN // 2)
                p.drawStaticText(offset, prefix)
                offset.setX(self.maxwidth + 5)
                p.drawStaticText(offset, self.divider)
                offset.setX(offset.x() + self.divider.size().width())
                p.drawStaticText(offset, full)
                offset.setY(offset.y() + size.height() + self.MARGIN // 2)
                if i in (self.current_result, self.mouse_hover_result):
                    offset.setX(0)
                    p.save()
                    if i != self.current_result:
                        p.setPen(Qt.DotLine)
                    p.drawLine(offset, QPoint(self.width(), offset.y()))
                    p.restore()
        else:
            p.drawText(self.rect(), Qt.AlignCenter, _('No results found'))

        p.end()
コード例 #30
0
ファイル: widgets.py プロジェクト: dusual/calibre
    def paintEvent(self, ev):
        offset = QPoint(0, 0)
        p = QPainter(self)
        p.setClipRect(ev.rect())
        bottom = self.rect().bottom()

        if self.results:
            for i, (prefix, full, text) in enumerate(self.results):
                size = prefix.size()
                if offset.y() + size.height() > bottom:
                    break
                self.max_result = i
                offset.setX(0)
                if i in (self.current_result, self.mouse_hover_result):
                    p.save()
                    if i != self.current_result:
                        p.setPen(Qt.DotLine)
                    p.drawLine(offset, QPoint(self.width(), offset.y()))
                    p.restore()
                offset.setY(offset.y() + self.MARGIN // 2)
                p.drawStaticText(offset, prefix)
                offset.setX(self.maxwidth + 5)
                p.drawStaticText(offset, self.divider)
                offset.setX(offset.x() + self.divider.size().width())
                p.drawStaticText(offset, full)
                offset.setY(offset.y() + size.height() + self.MARGIN // 2)
                if i in (self.current_result, self.mouse_hover_result):
                    offset.setX(0)
                    p.save()
                    if i != self.current_result:
                        p.setPen(Qt.DotLine)
                    p.drawLine(offset, QPoint(self.width(), offset.y()))
                    p.restore()
        else:
            p.drawText(self.rect(), Qt.AlignCenter, _('No results found'))

        p.end()
コード例 #31
0
ファイル: documentview.py プロジェクト: kmshi/calibre
 def scroll_to(self, x=0, y=0):
     self.mainFrame().setScrollPosition(QPoint(x, y))
コード例 #32
0
ファイル: test.py プロジェクト: sss/calibre
def text(p, xmax, ymax):
    f = p.font()
    f.setPixelSize(24)
    f.setFamily('Candara')
    p.setFont(f)
    p.drawText(QPoint(0, 100), 'Test intra glyph spacing ffagain imceo')