示例#1
0
    def __init__(self, parent):
        super(Edith, self).__init__()

        self.parent = parent
        self._defaul_font_size = 12
        self._zoom = 1

        self.undostack = UndoStack()

        #self.setStyleSheet('font-family: \'Calibri\'; background-color: #FFFFFF')
        self.setWordWrapMode(QtGui.QTextOption.WrapAnywhere)

        self._test_str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghim'
        self.setStyleSheet(
            'font-size: %.3fpt;font-family: \'Calibri\'; background-color: #FFFFFF'
            % (self._zoom * 12))

        metric = QtGui.QFontMetrics(QtGui.QFont('Calibri', 12))
        self._text_width = metric.boundingRect(self._test_str).width()
        self.setFixedWidth(1.1 * self._text_width)

        self.document().setDocumentMargin(0.05 * self._text_width)

        super().setFixedHeight(self._text_width / 2)

        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFrameShape(QtWidgets.QFrame.NoFrame)

        self.bridge = Bridge()

        # setup frame
        self.setFrameShape(QtWidgets.QFrame.Box)
        self.setFrameShadow(QtWidgets.QFrame.Plain)
        self.setLineWidth(1)

        # eventlistening
        self.document().contentsChange.connect(self.update_parser)
        self.cursorPositionChanged.connect(self.cursor_position_changed)
示例#2
0
文件: edith.py 项目: ChrisCuts/edith
    def __init__(self, parent):
        super(Edith, self).__init__()
        
        self.parent = parent
        self._defaul_font_size = 12
        self._zoom = 1
        
        self.undostack = UndoStack()
        
        #self.setStyleSheet('font-family: \'Calibri\'; background-color: #FFFFFF')
        self.setWordWrapMode(QtGui.QTextOption.WrapAnywhere)

        self._test_str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghim'
        self.setStyleSheet('font-size: %.3fpt;font-family: \'Calibri\'; background-color: #FFFFFF' % (self._zoom * 12))
            
        metric = QtGui.QFontMetrics(QtGui.QFont('Calibri', 12))
        self._text_width = metric.boundingRect(self._test_str).width()
        self.setFixedWidth(1.1 * self._text_width)
            
        self.document().setDocumentMargin(0.05 * self._text_width)
        
        super().setFixedHeight(self._text_width/2)
        
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFrameShape(QtWidgets.QFrame.NoFrame)
        
        
        self.bridge = Bridge()
        
        # setup frame
        self.setFrameShape(QtWidgets.QFrame.Box)
        self.setFrameShadow(QtWidgets.QFrame.Plain)
        self.setLineWidth(1)
        
        # eventlistening
        self.document().contentsChange.connect(self.update_parser)
        self.cursorPositionChanged.connect(self.cursor_position_changed)
示例#3
0
文件: edith.py 项目: ChrisCuts/edith
class Edith(QtWidgets.QTextEdit, QtWidgets.QFrame):
    def __init__(self, parent):
        super(Edith, self).__init__()
        
        self.parent = parent
        self._defaul_font_size = 12
        self._zoom = 1
        
        self.undostack = UndoStack()
        
        #self.setStyleSheet('font-family: \'Calibri\'; background-color: #FFFFFF')
        self.setWordWrapMode(QtGui.QTextOption.WrapAnywhere)

        self._test_str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghim'
        self.setStyleSheet('font-size: %.3fpt;font-family: \'Calibri\'; background-color: #FFFFFF' % (self._zoom * 12))
            
        metric = QtGui.QFontMetrics(QtGui.QFont('Calibri', 12))
        self._text_width = metric.boundingRect(self._test_str).width()
        self.setFixedWidth(1.1 * self._text_width)
            
        self.document().setDocumentMargin(0.05 * self._text_width)
        
        super().setFixedHeight(self._text_width/2)
        
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFrameShape(QtWidgets.QFrame.NoFrame)
        
        
        self.bridge = Bridge()
        
        # setup frame
        self.setFrameShape(QtWidgets.QFrame.Box)
        self.setFrameShadow(QtWidgets.QFrame.Plain)
        self.setLineWidth(1)
        
        # eventlistening
        self.document().contentsChange.connect(self.update_parser)
        self.cursorPositionChanged.connect(self.cursor_position_changed)
        
    @QtCore.pyqtSlot()
    def cursor_position_changed(self):
        self.undostack.push(self.toPlainText())
        
        
    @QtCore.pyqtSlot(int,int,int)
    def update_parser(self, position, chars_removed, chars_added):
        
        new_text = self.toPlainText()[position:position+chars_added]
        
        decorated = self.bridge.document_changed(position,  new_text,  chars_removed)
        decorated = '<span style="white-space: pre-wrap;">' + decorated + '</span>'
        
        self.document().blockSignals(True)
        self.document().setHtml(decorated)
        self.document().blockSignals(False)
        
        self.setFixedHeight(self.document().size().height())
    
    def setFixedHeight(self, height):
        #print(self.cursorRect())
        super().setFixedHeight(max([height, self._text_width/2]))
            
    @QtCore.pyqtSlot()
    def openDialog(self):
        filename = QtWidgets.QFileDialog.getOpenFileName(scrollArea,
                                             caption= 'Open File',
                                             filter='Edith\'s Files (*.efi)')
        
        if filename != ('',''):
            with codecs.open(filename, 'r', 'utf-8') as file:
                
                text = ''.join(file.readlines())
                
                self.setPlainText(text)
                file.close()
                self.setFocus()
        
    @QtCore.pyqtSlot()
    def clearEdith(self):
        
        self.clear()
        
        
    def wheelEvent(self, event):
        
        if event.modifiers() & QtCore.Qt.ControlModifier:
            if event.angleDelta().y() > 0:
                 
                
                if self._defaul_font_size * self._zoom < 30:
                    self._zoom += 0.1
                    
            else:
                 
                if self._defaul_font_size * self._zoom > 5:
                    self._zoom -= 0.1
            
            self.setStyleSheet('font-size: %.3fpt;font-family: \'Calibri\'; background-color: #FFFFFF' % (self._zoom * 12))
            metric = QtGui.QFontMetrics(self.font())
            self._text_width = metric.boundingRect(self._test_str).width()
            self.setFixedWidth(1.1 * self._text_width)
                
            self.document().setDocumentMargin(0.05 * self._text_width)
            
        else:
            super(Edith, self).wheelEvent(event)
示例#4
0
class Edith(QtWidgets.QTextEdit, QtWidgets.QFrame):
    def __init__(self, parent):
        super(Edith, self).__init__()

        self.parent = parent
        self._defaul_font_size = 12
        self._zoom = 1

        self.undostack = UndoStack()

        #self.setStyleSheet('font-family: \'Calibri\'; background-color: #FFFFFF')
        self.setWordWrapMode(QtGui.QTextOption.WrapAnywhere)

        self._test_str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghim'
        self.setStyleSheet(
            'font-size: %.3fpt;font-family: \'Calibri\'; background-color: #FFFFFF'
            % (self._zoom * 12))

        metric = QtGui.QFontMetrics(QtGui.QFont('Calibri', 12))
        self._text_width = metric.boundingRect(self._test_str).width()
        self.setFixedWidth(1.1 * self._text_width)

        self.document().setDocumentMargin(0.05 * self._text_width)

        super().setFixedHeight(self._text_width / 2)

        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFrameShape(QtWidgets.QFrame.NoFrame)

        self.bridge = Bridge()

        # setup frame
        self.setFrameShape(QtWidgets.QFrame.Box)
        self.setFrameShadow(QtWidgets.QFrame.Plain)
        self.setLineWidth(1)

        # eventlistening
        self.document().contentsChange.connect(self.update_parser)
        self.cursorPositionChanged.connect(self.cursor_position_changed)

    @QtCore.pyqtSlot()
    def cursor_position_changed(self):
        self.undostack.push(self.toPlainText())

    @QtCore.pyqtSlot(int, int, int)
    def update_parser(self, position, chars_removed, chars_added):

        new_text = self.toPlainText()[position:position + chars_added]

        decorated = self.bridge.document_changed(position, new_text,
                                                 chars_removed)
        decorated = '<span style="white-space: pre-wrap;">' + decorated + '</span>'

        self.document().blockSignals(True)
        self.document().setHtml(decorated)
        self.document().blockSignals(False)

        self.setFixedHeight(self.document().size().height())

    def setFixedHeight(self, height):
        #print(self.cursorRect())
        super().setFixedHeight(max([height, self._text_width / 2]))

    @QtCore.pyqtSlot()
    def openDialog(self):
        filename = QtWidgets.QFileDialog.getOpenFileName(
            scrollArea, caption='Open File', filter='Edith\'s Files (*.efi)')

        if filename != ('', ''):
            with codecs.open(filename, 'r', 'utf-8') as file:

                text = ''.join(file.readlines())

                self.setPlainText(text)
                file.close()
                self.setFocus()

    @QtCore.pyqtSlot()
    def clearEdith(self):

        self.clear()

    def wheelEvent(self, event):

        if event.modifiers() & QtCore.Qt.ControlModifier:
            if event.angleDelta().y() > 0:

                if self._defaul_font_size * self._zoom < 30:
                    self._zoom += 0.1

            else:

                if self._defaul_font_size * self._zoom > 5:
                    self._zoom -= 0.1

            self.setStyleSheet(
                'font-size: %.3fpt;font-family: \'Calibri\'; background-color: #FFFFFF'
                % (self._zoom * 12))
            metric = QtGui.QFontMetrics(self.font())
            self._text_width = metric.boundingRect(self._test_str).width()
            self.setFixedWidth(1.1 * self._text_width)

            self.document().setDocumentMargin(0.05 * self._text_width)

        else:
            super(Edith, self).wheelEvent(event)