本文整理汇总了Python中javax.swing.JTextPane类的典型用法代码示例。如果您正苦于以下问题:Python JTextPane类的具体用法?Python JTextPane怎么用?Python JTextPane使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JTextPane类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BurpExtender
class BurpExtender(IBurpExtender, IExtensionStateListener, IHttpListener, IProxyListener, ITab):
def registerExtenderCallbacks(self, callbacks):
self.callbacks = callbacks
self.helpers = callbacks.helpers
self.scriptpane = JTextPane()
self.scriptpane.setFont(Font('Monospaced', Font.PLAIN, 11))
self.scrollpane = JScrollPane()
self.scrollpane.setViewportView(self.scriptpane)
self._code = compile('', '<string>', 'exec')
self._script = ''
callbacks.registerExtensionStateListener(self)
callbacks.registerProxyListener(self)
callbacks.customizeUiComponent(self.getUiComponent())
callbacks.addSuiteTab(self)
self.scriptpane.requestFocus()
def extensionUnloaded(self):
try:
self.callbacks.saveExtensionSetting(
'script', base64.b64encode(self._script))
except Exception:
traceback.print_exc(file=self.callbacks.getStderr())
return
def processProxyMessage(self, messageIsRequest, message):
try:
globals_ = {'extender': self,
'callbacks': self.callbacks,
'helpers': self.helpers
}
locals_ = {'messageIsRequest': messageIsRequest,
'message': message
}
exec(self.script, globals_, locals_)
except Exception:
traceback.print_exc(file=self.callbacks.getStderr())
return
def getTabCaption(self):
return 'Script'
def getUiComponent(self):
return self.scrollpane
@property
def script(self):
end = self.scriptpane.document.length
_script = self.scriptpane.document.getText(0, end)
if _script == self._script:
return self._code
self._script = _script
self._code = compile(_script, '<string>', 'exec')
return self._code
示例2: __init__
def __init__(self):
super(AboutDialog, self).__init__()
# Open the files and build a tab pane
self.tabbedPane = tabs = JTabbedPane()
for title, path in self.INFO_FILES:
textPane = JTextPane()
textPane.editable = False
scrollPane = JScrollPane(textPane)
scrollPane.preferredSize = (32767, 32767) # just a large number
with open(path, 'r') as fd:
infoText = fd.read().decode('utf8')
textPane.text = infoText
textPane.caretPosition = 0
tabs.addTab(title, scrollPane)
# Load this tabbed pane into the layout
self.add(tabs, BorderLayout.CENTER)
# Add a label at the top
versionLabel = JLabel(JESVersion.TITLE + " version " + JESVersion.RELEASE)
versionLabel.alignmentX = Component.CENTER_ALIGNMENT
versionPanel = JPanel()
versionPanel.add(versionLabel)
self.add(versionPanel, BorderLayout.PAGE_START)
# Make an OK button
self.okButton = JButton(self.ok)
self.buttonPanel.add(self.okButton)
示例3: updateUI
def updateUI(self):
# Update the default font, if necessary,
# when the look and feel changes.
JTextPane.updateUI(self)
doc = self.getStyledDocument()
if hasattr(doc, 'setTheme'):
# Sometimes, we don't have a CommandWindowDocument here.
doc.setTheme(doc.themeName)
示例4: LineNumbering
class LineNumbering(DocumentListener):
"""Pane containing line numbers.
Listens to changes in a textpane to update itself automatically.
"""
def __init__(self, textpane):
self.component = JTextPane(
font=textpane.font,
border=BorderFactory.createEmptyBorder(5, 5, 5, 5),
editable=False,
background=awtColor(220, 220, 220),
)
self.doc = self.component.document
self.component.setParagraphAttributes(
textpane.paragraphAttributes, True
)
self.linecount = 0
self.style = new_style(self.doc, "default",
foreground=awtColor(100, 100, 100),
)
self.reset(1)
textpane.document.addDocumentListener(self)
def reset(self, lc):
self.linecount = lc
self.doc.remove(0, self.doc.length)
self.doc.insertString(0, make_line_numbers(1, lc), self.style)
def resize(self, lc):
if not lc:
self.reset(1)
elif len(str(lc)) != len(str(self.linecount)):
self.reset(lc)
elif lc > self.linecount:
self.doc.insertString(self.doc.length, "\n", self.style)
self.doc.insertString(self.doc.length,
make_line_numbers(self.linecount + 1, lc),
self.style
)
self.linecount = lc
elif lc < self.linecount:
root = self.doc.defaultRootElement
offset = root.getElement(lc).startOffset - 1
self.doc.remove(offset, self.doc.length - offset)
self.linecount = lc
# Implementation of DocumentListener
def changedUpdate(self, evt):
pass
def insertUpdate(self, evt):
self.resize(document_linecount(evt.document))
def removeUpdate(self, evt):
self.resize(document_linecount(evt.document))
示例5: __init__
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...')
示例6: makeComponents
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)
示例7: __init__
def __init__(self, extender, namespace=None):
self.extender = extender
self.callbacks = extender.callbacks
self.helpers = extender.helpers
self._locals = dict(Burp=extender, items=[])
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.callbacks.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()
self.callbacks.getStdout().write('Interactive interpreter ready...\n')
示例8: init
def init(self):
global exampleList
self.thinFont = Font("Dialog", 0, 10)
self.pane = self.getContentPane()
self.examples = exampleList.keys()
self.examples.sort()
self.exampleSelector = JList(self.examples, valueChanged=self.valueChanged)
self.exampleSelector.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
self.exampleSelector.setLayoutOrientation(JList.VERTICAL)
self.exampleSelector.setPreferredSize(Dimension(150,500))
self.exampleSelector.setBackground(Color(0.95, 0.95, 0.98))
self.exampleSelector.setFont(self.thinFont)
self.centerPanel = JPanel(BorderLayout())
self.canvas = GraphCanvas()
self.canvas.setApplet(self)
self.buttonRow = JPanel(FlowLayout())
self.backButton = JButton("<", actionPerformed = self.backAction)
self.backButton.setFont(self.thinFont)
self.continueButton = JButton("continue >",
actionPerformed=self.continueAction)
self.continueButton.setFont(self.thinFont)
self.scaleGroup = ButtonGroup()
self.linearButton = JRadioButton("linear scale",
actionPerformed=self.linearAction)
self.linearButton.setSelected(True)
self.linearButton.setFont(self.thinFont)
self.logarithmicButton = JRadioButton("logarithmic scale",
actionPerformed=self.logarithmicAction)
self.logarithmicButton.setFont(self.thinFont)
self.aboutButton = JButton("About...",
actionPerformed=self.aboutAction)
self.aboutButton.setFont(self.thinFont)
self.scaleGroup.add(self.linearButton)
self.scaleGroup.add(self.logarithmicButton)
self.buttonRow.add(self.backButton)
self.buttonRow.add(self.continueButton)
self.buttonRow.add(JLabel(" "*5))
self.buttonRow.add(self.linearButton)
self.buttonRow.add(self.logarithmicButton)
self.buttonRow.add(JLabel(" "*20));
self.buttonRow.add(self.aboutButton)
self.centerPanel.add(self.canvas, BorderLayout.CENTER)
self.centerPanel.add(self.buttonRow, BorderLayout.PAGE_END)
self.helpText = JTextPane()
self.helpText.setBackground(Color(1.0, 1.0, 0.5))
self.helpText.setPreferredSize(Dimension(800,80))
self.helpText.setText(re_sub("[ \\n]+", " ", """
Please select one of the examples in the list on the left!
"""))
self.pane.add(self.exampleSelector, BorderLayout.LINE_START)
self.pane.add(self.centerPanel, BorderLayout.CENTER)
self.pane.add(self.helpText, BorderLayout.PAGE_END)
self.graph = None
self.simulation = None
self.touched = ""
self.selected = ""
self.gfxDriver = None
示例9: __init__
def __init__(self):
self.textpane = JTextPane()
self.doc = self.textpane.getStyledDocument()
self.textpane.editable = False
style_context = StyleContext.getDefaultStyleContext()
default_style = style_context.getStyle(StyleContext.DEFAULT_STYLE)
parent_style = self.doc.addStyle("parent", default_style)
StyleConstants.setFontFamily(parent_style, "Monospaced")
input_style = self.doc.addStyle("input", parent_style)
output_style = self.doc.addStyle("output", parent_style)
StyleConstants.setForeground(output_style, awtColor.BLUE)
error_style = self.doc.addStyle("error", parent_style)
StyleConstants.setForeground(error_style, awtColor.RED)
# Do a dance to set tab size
font = Font("Monospaced", Font.PLAIN, 12)
self.textpane.setFont(font)
fm = self.textpane.getFontMetrics(font)
tabw = float(fm.stringWidth(" "*4))
tabs = [
TabStop(tabw*i, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE)
for i in xrange(1, 51)
]
attr_set = style_context.addAttribute(
SimpleAttributeSet.EMPTY,
StyleConstants.TabSet,
TabSet(tabs)
)
self.textpane.setParagraphAttributes(attr_set, False)
示例10: __init__
def __init__(self, frame, namespace=None):
"""
Create a Jython Console.
namespace is an optional and should be a dictionary or Map
"""
self.frame = frame
self.history = History(self)
if namespace != None:
self.locals = namespace
else:
self.locals = {}
self.buffer = [] # buffer for multi-line commands
self.interp = Interpreter(self, self.locals)
sys.stdout = StdOutRedirector(self)
self.text_pane = JTextPane(keyTyped = self.keyTyped, keyPressed = self.keyPressed)
self.__initKeyMap()
self.doc = self.text_pane.document
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.text_pane)
self.tip = Tip(None)
# get fontmetrics info so we can position the popup
metrics = self.text_pane.getFontMetrics(self.text_pane.getFont())
self.dotWidth = metrics.charWidth('.')
self.textHeight = metrics.getHeight()
示例11: __init__
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()
示例12: OutputPane
class OutputPane(object):
def __init__(self):
self.textpane = JTextPane()
self.doc = self.textpane.getStyledDocument()
self.textpane.editable = False
default_style = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE)
parent_style = self.doc.addStyle("parent", default_style)
StyleConstants.setFontFamily(parent_style, "Monospaced")
input_style = self.doc.addStyle("input", parent_style)
output_style = self.doc.addStyle("output", parent_style)
StyleConstants.setForeground(output_style, Color.BLUE)
error_style = self.doc.addStyle("error", parent_style)
StyleConstants.setForeground(error_style, Color.RED)
def addtext(self, text, style="input", ensure_newline=False):
doclen = self.doc.length
if ensure_newline and self.doc.getText(doclen - 1, 1) != '\n':
text = '\n' + text
self.doc.insertString(self.doc.length, text, self.doc.getStyle(style))
# Scroll down
self.textpane.setCaretPosition(self.doc.length)
示例13: __init__
def __init__(self):
self.textpane = JTextPane()
self.doc = self.textpane.getStyledDocument()
self.textpane.editable = False
default_style = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE)
parent_style = self.doc.addStyle("parent", default_style)
StyleConstants.setFontFamily(parent_style, "Monospaced")
input_style = self.doc.addStyle("input", parent_style)
output_style = self.doc.addStyle("output", parent_style)
StyleConstants.setForeground(output_style, Color.BLUE)
error_style = self.doc.addStyle("error", parent_style)
StyleConstants.setForeground(error_style, Color.RED)
示例14: __init__
def __init__(self):
super(IntroDialog, self).__init__()
# Open the text file and make a text pane
textPane = JTextPane()
textPane.editable = False
scrollPane = JScrollPane(textPane)
scrollPane.preferredSize = (32767, 32767) # just a large number
with open(self.INFO_FILE, 'r') as fd:
infoText = fd.read().decode('utf8').replace(
"@[email protected]", JESVersion.VERSION
)
textPane.text = infoText
# Load the scroll pane into the layout
self.add(scrollPane, BorderLayout.CENTER)
# Make an OK button
self.okButton = JButton(self.ok)
self.buttonPanel.add(self.okButton)
示例15: __init__
def __init__(self):
super(BugReportDialog, self).__init__()
# Add a message
textPane = JTextPane()
textPane.editable = False
version = "\n".join(" " + line for line in JESVersion.getMessage().splitlines())
textPane.text = MESSAGE % version
scrollPane = JScrollPane(textPane)
scrollPane.preferredSize = (32767, 32767) # just a large number
# Load it into the layout
self.add(scrollPane, BorderLayout.CENTER)
# Make buttons
self.sendButton = JButton(self.send)
self.buttonPanel.add(self.sendButton)
self.closeButton = JButton(self.close)
self.buttonPanel.add(self.closeButton)