예제 #1
0
 def __init__(self, *args):
     QWidget.__init__(self, *args)
     self.edit = None
     # This is used to update the width of the control.
     # It is the highest line that is currently visibile.
     self.highest_line = 0
     self.font = None
예제 #2
0
    def __init__(self, parent, name, script="", filemodified=0):
        QWidget.__init__(self)
        self.parent = parent
        self.tabWidget = self.parent.ui.tabWidget
        self.gridlayout = QGridLayout(self)
        self._dirty = False

        self.initialize_editor()
        self.gridlayout.addWidget(self.editor)

        self.setAcceptDrops(True)

        self.filename = name
        self.filemodified = filemodified
        if self.is_file():
            self.title = os.path.basename(name)
            # if self.equals_saved():
            #    self.filemodified = os.path.getmtime(self.filename)
        else:
            self.filename = ""
            self.title = name

        # Show this file in the self.editor
        self.editor.setText(script)
        self.clean_txt = self.saved()

        self.update_dirty()

        self.editor.keyPressEvent = self.key_press_event
예제 #3
0
 def update(self, *args):
     '''
     Updates the number bar to display the current set of numbers.
     Also, adjusts the width of the number bar if necessary.
     '''
     # The + 4 is used to compensate for the current line being bold.
     width = self.fontMetrics().width(str(self.highest_line)) + 4
     if self.width() != width:
         self.setFixedWidth(width)
     QWidget.update(self, *args)
예제 #4
0
 def update(self, *args):
     '''
     Updates the number bar to display the current set of numbers.
     Also, adjusts the width of the number bar if necessary.
     '''
     # The + 4 is used to compensate for the current line being bold.
     width = self.fontMetrics().width(str(self.highest_line)) + 4
     if self.width() != width:
         self.setFixedWidth(width)
     QWidget.update(self, *args)
예제 #5
0
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(
                self.edit.textCursor().position())

            painter = QPainter(self)

            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1

                # The top left position of the block in the document
                position = self.edit.document().documentLayout(
                ).blockBoundingRect(block).topLeft()

                # Check if the position of the block is out side of the visible
                # area.
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                painter.drawText(
                    self.width() - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) - contents_y + font_metrics.ascent(),
                    str(line_count))

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
예제 #6
0
 def wheelEvent(self, event):
     if event.modifiers() == Qt.ControlModifier:
         if event.delta() > 0:
             self.editor.zoomIn()
         else:
             self.editor.zoomOut()
     return QWidget.wheelEvent(self, event)
예제 #7
0
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(self.edit.textCursor().position())

            painter = QPainter(self)

            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1

                # The top left position of the block in the document
                position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()

                # Check if the position of the block is out side of the visible
                # area.
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                painter.drawText(self.width() - font_metrics.width(str(line_count)) - 3, round(position.y()) - contents_y + font_metrics.ascent(), str(line_count))

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
예제 #8
0
 def __init__(self, *args):
     QWidget.__init__(self, *args)
     self.edit = None
     # This is used to update the width of the control.
     # It is the highest line that is currently visibile.
     self.highest_line = 0