本文整理汇总了Python中javax.swing.JTextPane.getCaret方法的典型用法代码示例。如果您正苦于以下问题:Python JTextPane.getCaret方法的具体用法?Python JTextPane.getCaret怎么用?Python JTextPane.getCaret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextPane
的用法示例。
在下文中一共展示了JTextPane.getCaret方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import getCaret [as 别名]
class Console:
PROMPT = sys.ps1
PROCESS = sys.ps2
BANNER = ["Jython Completion Shell", InteractiveConsole.getDefaultBanner()]
def __init__(self, frame):
self.frame = frame # TODO do I need a reference to frame after the constructor?
self.history = History(self)
self.bs = 0 # what is this?
# command buffer
self.buffer = []
self.locals = {"gvSIG": sys.gvSIG}
self.interp = Interpreter(self, self.locals)
sys.stdout = StdOutRedirector(self)
# create a textpane
self.output = JTextPane(keyTyped=self.keyTyped, keyPressed=self.keyPressed)
# TODO rename output to textpane
# CTRL UP AND DOWN don't work
keyBindings = [
(KeyEvent.VK_ENTER, 0, "jython.enter", self.enter),
(KeyEvent.VK_DELETE, 0, "jython.delete", self.delete),
(KeyEvent.VK_HOME, 0, "jython.home", self.home),
(KeyEvent.VK_UP, 0, "jython.up", self.history.historyUp),
(KeyEvent.VK_DOWN, 0, "jython.down", self.history.historyDown),
(KeyEvent.VK_PERIOD, 0, "jython.showPopup", self.showPopup),
(KeyEvent.VK_ESCAPE, 0, "jython.hide", self.hide),
("(", 0, "jython.showTip", self.showTip),
(")", 0, "jython.hideTip", self.hideTip),
# (KeyEvent.VK_UP, InputEvent.CTRL_MASK, DefaultEditorKit.upAction, self.output.keymap.getAction(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0))),
# (KeyEvent.VK_DOWN, InputEvent.CTRL_MASK, DefaultEditorKit.downAction, self.output.keymap.getAction(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)))
]
# TODO rename newmap to keymap
newmap = JTextComponent.addKeymap("jython", self.output.keymap)
for (key, modifier, name, function) in keyBindings:
newmap.addActionForKeyStroke(KeyStroke.getKeyStroke(key, modifier), ActionDelegator(name, function))
self.output.keymap = newmap
self.doc = self.output.document
# self.panel.add(BorderLayout.CENTER, JScrollPane(self.output))
self.__propertiesChanged()
self.__inittext()
self.initialLocation = self.doc.createPosition(self.doc.length - 1)
# Don't pass frame to popups. JWindows with null owners are not focusable
# this fixes the focus problem on Win32, but make the mouse problem worse
self.popup = Popup(None, self.output)
self.tip = Tip(None)
# get fontmetrics info so we can position the popup
metrics = self.output.getFontMetrics(self.output.getFont())
self.dotWidth = metrics.charWidth(".")
self.textHeight = metrics.getHeight()
# add some handles to our objects
self.locals["console"] = self
self.caret = self.output.getCaret()
# TODO refactor me
def getinput(self):
offsets = self.__lastLine()
text = self.doc.getText(offsets[0], offsets[1] - offsets[0])
return text
def getDisplayPoint(self):
"""Get the point where the popup window should be displayed"""
screenPoint = self.output.getLocationOnScreen()
caretPoint = self.output.caret.getMagicCaretPosition()
# TODO use SwingUtils to do this translation
x = screenPoint.getX() + caretPoint.getX() + self.dotWidth
y = screenPoint.getY() + caretPoint.getY() + self.textHeight
return Point(int(x), int(y))
def hide(self, event=None):
"""Hide the popup or tip window if visible"""
if self.popup.visible:
self.popup.hide()
if self.tip.visible:
self.tip.hide()
def hideTip(self, event=None):
self.tip.hide()
# TODO this needs to insert ')' at caret!
self.write(")")
def showTip(self, event=None):
# get the display point before writing text
# otherwise magicCaretPosition is None
displayPoint = self.getDisplayPoint()
if self.popup.visible:
self.popup.hide()
#.........这里部分代码省略.........