当前位置: 首页>>代码示例>>Python>>正文


Python JTextPane.setParagraphAttributes方法代码示例

本文整理汇总了Python中javax.swing.JTextPane.setParagraphAttributes方法的典型用法代码示例。如果您正苦于以下问题:Python JTextPane.setParagraphAttributes方法的具体用法?Python JTextPane.setParagraphAttributes怎么用?Python JTextPane.setParagraphAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextPane的用法示例。


在下文中一共展示了JTextPane.setParagraphAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LineNumbering

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import setParagraphAttributes [as 别名]
class LineNumbering(DocumentListener):
    """Pane containing line numbers.
    
    Listens to changes in a textpane to update itself automatically.
    """
    
    def __init__(self, textpane):
        self.component = JTextPane(
            font=textpane.font,
            border=BorderFactory.createEmptyBorder(5, 5, 5, 5),
            editable=False,
            background=awtColor(220, 220, 220),
        )
        self.doc = self.component.document
        self.component.setParagraphAttributes(
            textpane.paragraphAttributes, True
        )
        self.linecount = 0
        self.style = new_style(self.doc, "default",
            foreground=awtColor(100, 100, 100),
        )
        self.reset(1)
        textpane.document.addDocumentListener(self)
    
    def reset(self, lc):
        self.linecount = lc
        self.doc.remove(0, self.doc.length)
        self.doc.insertString(0, make_line_numbers(1, lc), self.style)
    
    def resize(self, lc):
        if not lc:
            self.reset(1)
        elif len(str(lc)) != len(str(self.linecount)):
            self.reset(lc)
        elif lc > self.linecount:
            self.doc.insertString(self.doc.length, "\n", self.style)
            self.doc.insertString(self.doc.length,
                make_line_numbers(self.linecount + 1, lc),
                self.style
            )
            self.linecount = lc
        elif lc < self.linecount:
            root = self.doc.defaultRootElement
            offset = root.getElement(lc).startOffset - 1
            self.doc.remove(offset, self.doc.length - offset)
            self.linecount = lc
    
    # Implementation of DocumentListener
    def changedUpdate(self, evt):
        pass
    
    def insertUpdate(self, evt):
        self.resize(document_linecount(evt.document))
    
    def removeUpdate(self, evt):
        self.resize(document_linecount(evt.document))
开发者ID:Serabe,项目名称:geogebra,代码行数:58,代码来源:gui.py

示例2: OutputPane

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import setParagraphAttributes [as 别名]
class OutputPane(object):
    
    """Pane for outpout of interactive session"""
    
    def __init__(self):
        self.textpane = JTextPane()
        self.doc = self.textpane.getStyledDocument()
        self.textpane.editable = False
        style_context = StyleContext.getDefaultStyleContext()
        default_style = style_context.getStyle(StyleContext.DEFAULT_STYLE)
        parent_style = self.doc.addStyle("parent", default_style)
        StyleConstants.setFontFamily(parent_style, "Monospaced")
        input_style = self.doc.addStyle("input", parent_style)
        output_style = self.doc.addStyle("output", parent_style)
        StyleConstants.setForeground(output_style, awtColor.BLUE)
        error_style = self.doc.addStyle("error", parent_style)
        StyleConstants.setForeground(error_style, awtColor.RED)
        
        # Do a dance to set tab size
        font = Font("Monospaced", Font.PLAIN, 12)
        self.textpane.setFont(font)
        fm = self.textpane.getFontMetrics(font)
        tabw = float(fm.stringWidth(" "*4))
        tabs = [
            TabStop(tabw*i, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE)
            for i in xrange(1, 51)
        ]
        attr_set = style_context.addAttribute(
            SimpleAttributeSet.EMPTY,
            StyleConstants.TabSet,
            TabSet(tabs)
        )
        self.textpane.setParagraphAttributes(attr_set, False)
        #Dance done!
        
    def addtext(self, text, style="input", ensure_newline=False):
        doclen = self.doc.length
        if ensure_newline and doclen:
            if self.doc.getText(doclen - 1, 1) != '\n':
                text = '\n' + text
        self.doc.insertString(self.doc.length, text, self.doc.getStyle(style))
        # Scroll down
        self.textpane.setCaretPosition(self.doc.length)

    def clear(self):
        """Remove all text"""
        self.doc.remove(0, self.doc.length)
开发者ID:aeriksson,项目名称:geogebra,代码行数:49,代码来源:gui.py


注:本文中的javax.swing.JTextPane.setParagraphAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。