本文整理汇总了Python中javax.swing.JTextPane.getInputMap方法的典型用法代码示例。如果您正苦于以下问题:Python JTextPane.getInputMap方法的具体用法?Python JTextPane.getInputMap怎么用?Python JTextPane.getInputMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextPane
的用法示例。
在下文中一共展示了JTextPane.getInputMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EditorPanel_text_utf_8
# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import getInputMap [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: