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


Python JTextPane.getSelectionEnd方法代码示例

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


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

示例1: Console

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import getSelectionEnd [as 别名]
class Console(object):
    PS1 = sys.ps1
    PS2 = sys.ps2

    def __init__(self, burp, namespace=None):
        self.burp = burp
        self.log = burp.log
        self._locals = dict(Burp=burp)
        self._buffer = []
        self.history = History(self)

        if namespace is not None:
            self._locals.update(namespace)

        self.interp = JythonInterpreter(self, self._locals)

        self.textpane = JTextPane(keyTyped=self.keyTyped,
                                  keyPressed=self.keyPressed)

        self.textpane.setFont(Font('Monospaced', Font.PLAIN, 11))
        self.burp.customizeUiComponent(self.textpane)

        self.initKeyMap()

        self.document.remove(0, self.document.getLength())
        self.write('Burp Extender Jython Shell', prefix='')
        self.write(self.PS1)

        self.textpane.requestFocus()
        burp.log.info('Interactive interpreter ready...')

    @property
    def document(self):
        return self.textpane.document

    def resetbuffer(self):
        self._buffer = []

    def keyTyped(self, event=None):
        if not self.inLastLine():
            event.consume()

    def keyPressed(self, event):
        if event.keyCode in (KeyEvent.VK_BACK_SPACE, KeyEvent.VK_LEFT):
            self.backspaceListener(event)

    def getText(self):
        start, end = self.__getLastLineOffsets()
        text = self.document.getText(start, end - start)
        return text.rstrip()

    def insertText(self, data):
        position = self.textpane.getCaretPosition()
        self.textpane.select(position, position)
        self.textpane.replaceSelection(data)
        self.textpane.setCaretPosition(position + len(data))

    def replaceText(self, data):
        start, end = self.__getLastLineOffsets()
        self.textpane.select(start, end)
        self.textpane.replaceSelection(data)
        self.textpane.setCaretPosition(start + len(data))

    def write(self, data, color=Color.black, prefix='\n'):
        style = SimpleAttributeSet()

        if color is not None:
            style.addAttribute(StyleConstants.Foreground, color)

        self.document.insertString(self.document.getLength(), prefix + data, style)
        self.textpane.caretPosition = self.document.getLength()

    def enterAction(self, event=None):
        text = self.getText()
        self._buffer.append(text)
        source = '\n'.join(self._buffer)
        more = self.interp.runsource(source)

        if more:
            self.write(self.PS2, color=Color.black)
        else:
            self.resetbuffer()
            self.write(self.PS1)

        self.history.append(text)

    def deleteAction(self, event=None):
        if self.inLastLine():
            if self.textpane.getSelectedText():
                self.document.remove(self.textpane.getSelectionStart(),
                     self.textpane.getSelectionEnd() - self.textpane.getSelectionStart())

            elif self.textpane.getCaretPosition() < self.document.getLength():
                self.document.remove(self.textpane.getCaretPosition(), 1)

    def deleteEndLineAction(self, event=None):
        if self.inLastLine():
            position = self.textpane.getCaretPosition()
            self.textpane.setSelectionStart(position)
            _, end = self.__getLastLineOffsets()
#.........这里部分代码省略.........
开发者ID:kingfs,项目名称:jython-burp-api,代码行数:103,代码来源:console.py


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