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


Python JTextPane.getKeymap方法代码示例

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


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

示例1: Console

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import getKeymap [as 别名]

#.........这里部分代码省略.........
            start, end = self.__getLastLineOffsets()
            self.textpane.caretPosition = start

    def endAction(self, event=None):
        if self.inLastLine():
            start, end = self.__getLastLineOffsets()
            self.textpane.caretPosition = end - 1

    def pasteAction(self, event=None):
        if self.inLastLine():
            clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
            clipboard.getContents(self.textpane)
            contents = clipboard.getData(DataFlavor.stringFlavor)

            lines = contents.splitlines()
            for i, line in enumerate(lines):
                self.insertText(line)
                if i < len(lines) - 1:
                    self.enterAction()

    def keyboardInterruptAction(self, event=None):
        self.interp.runsource('raise KeyboardInterrupt\n')
        self.resetbuffer()
        self.write(self.PS1)

    def backspaceListener(self, event=None):
        start, end = self.__getLastLineOffsets()

        if self.textpane.getCaretPosition() <= start and \
            not self.textpane.getSelectedText():
                event.consume()

    def initKeyMap(self):
        import platform
        os_name = platform.java_ver()[-1][0]

        if os_name.startswith('Win'):
            exit_key = KeyEvent.VK_Z
            interrupt_key = KeyEvent.VK_PAUSE
        else:
            exit_key = KeyEvent.VK_D
            interrupt_key = KeyEvent.VK_C

        bindings = [
            (KeyEvent.VK_ENTER, 0, 'jython.enter', self.enterAction),
            (KeyEvent.VK_DELETE, 0, 'jython.delete', self.deleteAction),

            (KeyEvent.VK_HOME, 0, 'jython.home', self.homeAction),
            (KeyEvent.VK_LEFT, InputEvent.META_DOWN_MASK, 'jython.home', self.homeAction),
            (KeyEvent.VK_END, 0, 'jython.end', self.endAction),
            (KeyEvent.VK_RIGHT, InputEvent.META_DOWN_MASK, 'jython.end', self.endAction),

            (KeyEvent.VK_UP, 0, 'jython.up', self.history.historyUp),
            (KeyEvent.VK_DOWN, 0, 'jython.down', self.history.historyDown),

            (KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), 'jython.paste', self.pasteAction),

            (KeyEvent.VK_A, InputEvent.CTRL_MASK, 'jython.home', self.homeAction),
            (KeyEvent.VK_E, InputEvent.CTRL_MASK, 'jython.end', self.endAction),
            (KeyEvent.VK_K, InputEvent.CTRL_MASK, 'jython.deleteEndLine', self.deleteEndLineAction),
            (KeyEvent.VK_Y, InputEvent.CTRL_MASK, 'jython.paste', self.pasteAction),

            #(interrupt_key, InputEvent.CTRL_MASK, 'jython.keyboardInterrupt', self.keyboardInterruptAction),
            ]

        keymap = JTextComponent.addKeymap('jython', self.textpane.getKeymap())

        for key, modifier, name, function in bindings:
            keymap.addActionForKeyStroke(
                    KeyStroke.getKeyStroke(key, modifier),
                    ActionDelegator(name, function))

        self.textpane.keymap = keymap

    def inLastLine(self, include=True):
        start, end = self.__getLastLineOffsets()

        if self.textpane.getSelectedText():
            position = self.textpane.getSelectionStart()
        else:
            position = self.textpane.getCaretPosition()

        if include is True:
            return start <= position <= end

        return start < position <= end

    def __getLastLineOffsets(self):
        firstElement = self.document.getRootElements()[0]
        lines = firstElement.getElementCount()

        start = firstElement.getElement(lines - 1).getStartOffset()
        end = firstElement.getElement(lines - 1).getEndOffset()

        line = self.document.getText(start, end - start)

        if len(line) >= 4 and (line[0:4] == self.PS1 or line[0:4] == self.PS2):
            return start + 4, end

        return start, end
开发者ID:kingfs,项目名称:jython-burp-api,代码行数:104,代码来源:console.py


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