Esempio n. 1
0
 def sizeHint(self):
     """ Returns the widget size hint (based on the editor font size) """
     fm = QFontMetricsF(self.editor.codeEdit.font())
     self.size_hint = QSize(fm.height(), fm.height())
     if self.size_hint.width() > 16:
         self.size_hint.setWidth(16)
     return self.size_hint
Esempio n. 2
0
    def __init__(self, main_window):

        self._main_window = main_window
        self._instance = None
        self.views_by_category = defaultdict(list)
        self.views = []
        self.dockable_views = []
        self.view_to_dockable = {}

        #
        # Some generic configurations. move to "configurations" module later
        #
        #self.disasm_font = QFont("courier new", 20)
        self.disasm_font = QFont("DejaVu Sans Mono", 10)
        font_metrics = QFontMetricsF(self.disasm_font)
        self.disasm_font_height = font_metrics.height()
        self.disasm_font_width = font_metrics.width('A')
        self.disasm_font_ascent = font_metrics.ascent()

        default_tabs = [
            FunctionsView(self, 'left'),
            DisassemblyView(self, 'right'),
            SymexecView(self, 'right'),
            StatesView(self, 'right'),
            StringsView(self, 'right'),
            ConsoleView(self, 'bottom'),
        ]

        for tab in default_tabs:
            self.add_view(tab, tab.caption, tab.category)
Esempio n. 3
0
 def sizeHint(self):
     """
     Return the size hint of the widget (depends on the editor font)
     """
     s = str(self.editor.codeEdit.blockCount())
     fm = QFontMetricsF(self.font)
     # +1 needed on window xp! (not needed on seven nor on GNU/Linux)
     return QSize(fm.width('A') * (len(s) + 1), 0)
Esempio n. 4
0
 def __paintMargin(self, event):
     """ Paints the right margin as postPainting step. """
     rect = event.rect()
     font = self.editor.codeEdit.currentCharFormat().font()
     fm = QFontMetricsF(font)
     pos = self.marginPos
     offset = self.editor.codeEdit.contentOffset().x() + \
              self.editor.codeEdit.document().documentMargin()
     x80 = round(fm.width(' ') * pos) + offset
     p = QPainter(self.editor.codeEdit.viewport())
     p.setPen(self.pen)
     p.drawLine(x80, rect.top(), x80, rect.bottom())
Esempio n. 5
0
    def init_font_config(self):
        self.disasm_font = QFont("DejaVu Sans Mono", 10)
        font_metrics = QFontMetricsF(self.disasm_font)
        self.disasm_font_height = font_metrics.height()
        self.disasm_font_width = font_metrics.width('A')
        self.disasm_font_ascent = font_metrics.ascent()

        self.symexec_font = QFont("DejaVu Sans Mono", 10)
        font_metrics = QFontMetricsF(self.symexec_font)
        self.symexec_font_height = font_metrics.height()
        self.symexec_font_width = font_metrics.width('A')
        self.symexec_font_ascent = font_metrics.ascent()
Esempio n. 6
0
 def _onStyleChanged(self):
     """ Updates stylesheet and brushes. """
     fm = QFontMetricsF(self.editor.codeEdit.font())
     self.size_hint = QSize(fm.height(), fm.height())
     style = self.currentStyle
     self.back_brush = QBrush(QColor(style.panelsBackgroundColor))
     self.active_line_brush = QBrush(QColor(style.activeLineColor))
     self.separator_pen = QPen(QColor(style.panelSeparatorColor))
     # qss = self.QSS % {"back": style.activeLineColor,
     #                   "color": style.tokenColor(Text)}
     # self.setStyleSheet(qss)
     self.updateGeometry()
Esempio n. 7
0
    def paintEvent(self, event):
        """ Paints the widget """
        if self.enabled is False:
            return
        Panel.paintEvent(self, event)
        painter = QPainter(self)
        painter.fillRect(event.rect(), self.back_brush)

        for vb in self.editor.codeEdit.visible_blocks:
            line = vb.row
            # paint marker for line
            marker = self.getIndicatorForLine(line)
            if marker is None:
                continue
                # use the normal pen to draw the fold indicator
            drawLines = False
            pen = self.normal_pen
            if marker.hover is True:
                pen = self.highlight_pen
                drawLines = True
            painter.setPen(pen)
            # get the text to draw
            txt = '-'
            if marker.folded is True:
                drawLines = False
                txt = '+'
            offset = 4
            h = self.size_hint.height()
            fm = QFontMetricsF(self.editor.codeEdit.font())
            hoffset = (fm.height() - h) / 2.0
            r = QRect(vb.rect.x(), vb.rect.y() + hoffset, self.size_hint.width(), self.size_hint.height())
            painter.setFont(self.font)
            painter.drawText(r, Qt.AlignVCenter | Qt.AlignHCenter, txt)
            w = self.size_hint.width() - 2 * offset
            h = self.size_hint.width() - 2 * offset
            hoffset = (fm.height() - h) / 2.0
            r.setX(vb.rect.x() + offset)
            r.setY(vb.rect.y() + hoffset)
            r.setWidth(w)
            r.setHeight(h)
            painter.drawRect(r)
            if drawLines is True:
                top = (vb.rect.x() + self.size_hint.width() / 2.0,
                       vb.rect.y() + hoffset + offset * 2)
                delta = ((marker.end - marker.start) * vb.height)  # - (vb.rect.height() / 2.0)
                bottom = (top[0], top[1] + delta)
                painter.drawLine(top[0], top[1], bottom[0], bottom[1])
                painter.drawLine(bottom[0], bottom[1], bottom[0] + self.size_hint.width() / 2.0, bottom[1])

        return
Esempio n. 8
0
    def createQtNode(self, node, posx, posy, color=QColor(255, 150, 150)):
        """ Create a QtNode with given position, color for given node
        
        Arguments:
            
            - node: The graphviz node
            - posx: The x position from graphviz layout
            - posy: The y position from graphviz layout
            - color: The color of circle (red by default)
        
        """
        #dpi = float(self.gv.graph_attr['dpi'])
        dpi = 96
        try:
            width = float(node.attr['width'])
            height = float(node.attr['height'])
        except ValueError:
            #New created node
            width = 300 / 96
            height = 40 / 96

        qnode = QtNode(-width * dpi / 2, -height * dpi / 2, width * dpi,
                       height * dpi)
        qnode.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
        qnode.setPos(posx, posy)
        qnode.setFlag(QGraphicsItem.ItemIsMovable)
        qnode.setCallback(weakref.ref(self))
        qnode.setNode(node)
        qnode.setBrush(color)
        txt = QGraphicsSimpleTextItem(qnode)
        font = txt.font()
        font.setPointSize(14)
        txt.setFont(font)
        txt.setText(node)
        txtwidth = QFontMetricsF(font).width(node)
        txtheight = QFontMetricsF(font).height()
        toLeft = (-width * dpi / 2) + (width * dpi - txtwidth) / 2
        toBottom = (-height * dpi / 2) + (height * dpi - txtheight) / 2
        txt.setPos(toLeft, toBottom)

        return qnode
    def __init__(self, name, size):
        self.font = QFont(name, size)
        self.font.setKerning(False)
        self.ascent = int(QFontMetricsF(self.font).ascent())
        self.charWidth = QFontMetricsF(self.font).width("X")
        self.charHeight = int(QFontMetricsF(self.font).height())
        self.charOffset = 0  # can introduce extra linespacing here

        self.bold = QFont(self.font)
        self.bold.setBold(True)

        self.under = QFont(self.font)
        self.under.setUnderline(True)

        # align character width properly
        if self.charWidth % 1.0 < 0.5:
            adjust = -(self.charWidth % 1.0)
        else:
            adjust = 1.0 - (self.charWidth % 1.0)

        self.charWidth += adjust
        self.font.setLetterSpacing(QFont.AbsoluteSpacing, adjust)
        self.bold.setLetterSpacing(QFont.AbsoluteSpacing, adjust)
        self.under.setLetterSpacing(QFont.AbsoluteSpacing, adjust)
 def setUp(self):
     super(QFontMetricsFTest, self).setUp()
     self.font = QFont()
     self.metrics = QFontMetricsF(self.font)