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


Python JTextPane.getActionMap方法代码示例

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


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

示例1: EditorPanel_text_utf_8

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import getActionMap [as 别名]
class EditorPanel_text_utf_8(EditorPanel_abstract):
    
    def basicRecordChanged(self, newRecord):
        self.textEditor.caretPosition = 0
        self.saveButton.background = self.normalSaveButtonColor
    
    def makeComponents(self):
        # text specific operations
        self.randomUUIDButton = JButton("Generate random UUID", actionPerformed=self.randomUUIDPressed)
        self.clearButton = JButton("Clear", actionPerformed=self.clearPressed)
        self.runButton = JButton("Run as Jython", actionPerformed=self.runPressed)
        self.revertButton = JButton("Revert", actionPerformed=self.revertPressed)

        self.buttonPanel = Box(BoxLayout.X_AXIS) 
        self.buttonPanel.add(Box.createRigidArea(Dimension(5,0)))
        self.buttonPanel.add(self.randomUUIDButton)
        self.buttonPanel.add(Box.createRigidArea(Dimension(5,0)))
        self.buttonPanel.add(self.clearButton)
        self.buttonPanel.add(Box.createRigidArea(Dimension(5,0)))
        self.buttonPanel.add(self.runButton)
        self.buttonPanel.add(Box.createRigidArea(Dimension(5,0)))
        self.buttonPanel.add(self.revertButton)
        self.buttonPanel.add(Box.createRigidArea(Dimension(5,0)))
 
        self.textEditor = JTextPane()
        self.textEditor.setFont(Font("monospaced", Font.PLAIN, 12))
        #self.textEditor.setTabSize(4) # still inserts tabs instead of spaces
        TabKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0, False)
        MyTabActionKey = Object()
        self.textEditor.getInputMap().put(TabKeyStroke, MyTabActionKey)
        actionMap = self.textEditor.getActionMap()
        actionMap.put(MyTabActionKey, AddFourSpacesAction())
        
        self.layout = BorderLayout()
        self.add(self.buttonPanel, BorderLayout.NORTH)
        self.add(JScrollPane(self.textEditor), BorderLayout.CENTER)
        
    def basicGetCurrentValueBytes(self):
        return self.textEditor.text
        
    def basicSetCurrentValueBytes(self, newValueBytes):
        self.textEditor.text = newValueBytes
        self.textEditor.caretPosition = 0
        
    # extra functionality
    def runPressed(self, event):
        print "run pressed"
        codeText = self.getCurrentValueBytes()
        print "=== run code ==="
        exec "from token import *"
        #print codeText
        self.browser.oldimport = __builtin__.__import__
        self.browser.contextUUID = self.browser.entitiesList.selectedValue
        __builtin__.__import__ = self.browser.importCodeFromRepository
        self.browser.importLevel = 0
        try:
            try:
                someGlobals = {"currentBrowser": self.browser, "contextUUID": self.browser.entitiesList.selectedValue}
                exec codeText in someGlobals
            except SyntaxError, e:
                print e
                #print "fileName", e.fileName
                #print "lineno", e.lineno
                print "offset:", e.offset
                print "text:", e.text
                lines = codeText.split('\n')
                position = 0
                for i in range(e.lineno - 1):
                    position += len(lines[i]) + 1
                position += e.offset
                self.textEditor.caretPosition = position
                self.textEditor.requestFocus()
            print "=== done ==="
        finally:
开发者ID:pdfernhout,项目名称:openvirgle,代码行数:76,代码来源:browser.py


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