コード例 #1
0
    def _add_table(self, tab, cursor):
        fmt = QTextCharFormat()
        fmt.setFont(QFont(self.factory.font_name))
        fmt.setFontPointSize(self.factory.font_size)
        bc = QColor(self.factory.bg_color) if self.factory.bg_color else None
        ec, oc, hc = bc, bc, bc
        if self.factory.even_color:
            ec = QColor(self.factory.even_color)
        if self.factory.odd_color:
            oc = QColor(self.factory.odd_color)
        if self.factory.header_color:
            hc = QColor(self.factory.header_color)

        with edit_block(cursor):
            for i, row in enumerate(tab.items):
                cell = row.cells[0]
                if cell.bold:
                    fmt.setFontWeight(QFont.Bold)
                else:
                    fmt.setFontWeight(QFont.Normal)

                if i == 0 and hc:
                    c = hc
                elif (i - 1) % 2 == 0:
                    c = ec
                else:
                    c = oc

                if c:
                    fmt.setBackground(c)

                txt = ''.join([u'{{:<{}s}}'.format(cell.width).format(cell.text)
                              for cell in row.cells
                              ])
                cursor.insertText(txt + '\n', fmt)
コード例 #2
0
ファイル: bug_662.py プロジェクト: Hasimir/PySide
    def tesIterator(self):
        edit = QTextEdit()
        cursor = edit.textCursor()
        fmt = QTextCharFormat()
        frags = []
        for i in range(10):
            fmt.setFontPointSize(i+10)
            frags.append("block%d"%i)
            cursor.insertText(frags[i], fmt)

        doc = edit.document()
        block = doc.begin()

        index = 0
        for i in block:
            self.assertEqual(i.fragment().text(), frags[index])
            index += 1
コード例 #3
0
ファイル: bug_662.py プロジェクト: zkactivity/PySide
    def tesIterator(self):
        edit = QTextEdit()
        cursor = edit.textCursor()
        fmt = QTextCharFormat()
        frags = []
        for i in range(10):
            fmt.setFontPointSize(i + 10)
            frags.append("block%d" % i)
            cursor.insertText(frags[i], fmt)

        doc = edit.document()
        block = doc.begin()

        index = 0
        for i in block:
            self.assertEqual(i.fragment().text(), frags[index])
            index += 1
コード例 #4
0
    def _add_table(self, tab, cursor):
        fmt = QTextCharFormat()
        fmt.setFont(QFont(self.factory.font_name))
        fmt.setFontPointSize(self.factory.font_size)
        bc = QColor(self.factory.bg_color) if self.factory.bg_color else None
        ec, oc, hc = bc, bc, bc
        if self.factory.even_color:
            ec = QColor(self.factory.even_color)
        if self.factory.odd_color:
            oc = QColor(self.factory.odd_color)
        if self.factory.header_color:
            hc = QColor(self.factory.header_color)

        with edit_block(cursor):
            for i, row in enumerate(tab.items):
                cell = row.cells[0]
                if cell.bold:
                    fmt.setFontWeight(QFont.Bold)
                else:
                    fmt.setFontWeight(QFont.Normal)

                if i == 0 and hc:
                    c = hc
                elif (i - 1) % 2 == 0:
                    c = ec
                else:
                    c = oc

                if c:
                    fmt.setBackground(c)

                txt = ''.join([
                    u'{{:<{}s}}'.format(cell.width).format(cell.text)
                    for cell in row.cells
                ])
                cursor.insertText(txt + '\n', fmt)
コード例 #5
0
class SyntaxHighlightSetting():
    """ This class contains a single Setting for a code block in the SyntaxHighlighter. 
    
    Variables:
        
        - expression: The regular expression of the syntax block
        - expression_end: If the expression has a start and an end expression
        - font_size
        - font_color
        - font_weight
        - font_style
        - font_underline
        - use_font_size
        
    
    """
    def __init__(self,
                 expression,
                 font_family,
                 font_size,
                 font_color,
                 font_weight,
                 font_style,
                 font_underline,
                 use_font_size,
                 expression_end=''):
        self.expression = expression
        if expression_end != '':
            self.expression_end = expression_end
        self.font_family = font_family
        self.font_size = font_size
        self.font_color = font_color
        self.font_weight = font_weight
        self.font_style = font_style
        self.font_underline = font_underline
        self.use_font_size = use_font_size
        self.createFormat()

    def createFormat(self):
        """ Create a QTextCharformat and saves it in self.class_format"""
        self.class_format = QTextCharFormat()
        self.class_format.setFontFamily(self.font_family)
        if self.use_font_size:
            self.class_format.setFontPointSize(self.font_size)
        self.class_format.setForeground(self.font_color)
        self.class_format.setFontWeight(self.font_weight)
        self.class_format.setFontItalic(self.font_style)
        self.class_format.setFontUnderline(self.font_underline)

    def get_format(self):
        return self.class_format

    def getValues(self):
        return [self.expression, self.font_color, self.font_weight]

    def serialize(self):
        str1 = ""
        str1 += self.expression + "//"
        str1 += str(self.font_color) + "//"
        str1 += str(self.font_weight) + "//"
        return str1

    def deserialize(self, string):
        splitted = string.split("//")
        self.expression = splitted[0]
        self.font_color = splitted[1]
        self.font_weight = splitted[2]