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


Python JTextPane.requestFocus方法代码示例

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


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

示例1: BurpExtender

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import requestFocus [as 别名]
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
开发者ID:Izib,项目名称:ProxyScripter,代码行数:62,代码来源:ProxyScripter.py

示例2: Console

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import requestFocus [as 别名]
class Console(object):
    PS1 = sys.ps1
    PS2 = sys.ps2

    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...')

    @property
    def document(self):
        return self.textpane.document

    def resetbuffer(self):
        self._buffer = []

    def keyTyped(self, event=None):
        if not self.inLastLine():
            event.consume()

    def keyPressed(self, event):
        if event.keyCode in (KeyEvent.VK_BACK_SPACE, KeyEvent.VK_LEFT):
            self.backspaceListener(event)

    def getText(self):
        start, end = self.__getLastLineOffsets()
        text = self.document.getText(start, end - start)
        return text.rstrip()

    def insertText(self, data):
        position = self.textpane.getCaretPosition()
        self.textpane.select(position, position)
        self.textpane.replaceSelection(data)
        self.textpane.setCaretPosition(position + len(data))

    def replaceText(self, data):
        start, end = self.__getLastLineOffsets()
        self.textpane.select(start, end)
        self.textpane.replaceSelection(data)
        self.textpane.setCaretPosition(start + len(data))

    def write(self, data, color=Color.black, prefix='\n'):
        style = SimpleAttributeSet()

        if color is not None:
            style.addAttribute(StyleConstants.Foreground, color)

        self.document.insertString(self.document.getLength(), prefix + data, style)
        self.textpane.caretPosition = self.document.getLength()

    def enterAction(self, event=None):
        text = self.getText()
        self._buffer.append(text)
        source = '\n'.join(self._buffer)
        more = self.interp.runsource(source)

        if more:
            self.write(self.PS2, color=Color.black)
        else:
            self.resetbuffer()
            self.write(self.PS1)

        self.history.append(text)

    def deleteAction(self, event=None):
        if self.inLastLine():
            if self.textpane.getSelectedText():
                self.document.remove(self.textpane.getSelectionStart(),
                     self.textpane.getSelectionEnd() - self.textpane.getSelectionStart())

            elif self.textpane.getCaretPosition() < self.document.getLength():
                self.document.remove(self.textpane.getCaretPosition(), 1)

    def deleteEndLineAction(self, event=None):
        if self.inLastLine():
            position = self.textpane.getCaretPosition()
            self.textpane.setSelectionStart(position)
            _, end = self.__getLastLineOffsets()
#.........这里部分代码省略.........
开发者ID:kingfs,项目名称:jython-burp-api,代码行数:103,代码来源:console.py

示例3: BurpExtender

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import requestFocus [as 别名]
class BurpExtender(IBurpExtender, IIntruderPayloadGeneratorFactory, IExtensionStateListener, ITab):
    
    #
    # implement IBurpExtender
    #
    def	registerExtenderCallbacks(self, callbacks):   

        callbacks.registerExtensionStateListener(self)
        # keep a reference to our callbacks object
        self._callbacks = callbacks  
        # obtain an extension helpers object
        self._helpers = callbacks.getHelpers()
        # set our extension name
        callbacks.setExtensionName("Super Payload")
        # register ourselves as a payload generator factory
        callbacks.registerIntruderPayloadGeneratorFactory(self)

        # the Super Payload UI 
        self.scriptpane = JTextPane()
        self.scriptpane.setFont(Font('Monospaced', Font.PLAIN, 11))
        self.scrollpane = JScrollPane()
        self.scrollpane.setViewportView(self.scriptpane)
        callbacks.customizeUiComponent(self.getUiComponent())
        callbacks.addSuiteTab(self)
        self.scriptpane.requestFocus()

        # Compile the init script content
        self._code = compile('', '<string>', 'exec')
        self._script = ''

        script = callbacks.loadExtensionSetting('script')

        if script:
            script = base64.b64decode(script)

            self.scriptpane.document.insertString(
                self.scriptpane.document.length,
                script,
                SimpleAttributeSet())

            self._script = script
            self._code = compile(script, '<string>', 'exec')

        
        return

    def createNewInstance(self, attack):
    	return SuperGenerator(self, attack)

    def getGeneratorName(self):
    	return "SuperPayload"

    def extensionUnloaded(self):
        try:
            self.callbacks.saveExtensionSetting(
                'script', base64.b64encode(self._script))
        except Exception:
            traceback.print_exc(file=self.callbacks.getStderr())
        return

    def getTabCaption(self):
        return 'Super Payload Script'

    def getUiComponent(self):
        return self.scrollpane

    # Get the compiled code of user script (update or not)
    @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
开发者ID:zangzhe,项目名称:burp-suite-extensions,代码行数:80,代码来源:SuperPayload.py

示例4: BurpExtender

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import requestFocus [as 别名]
class BurpExtender(IBurpExtender, IExtensionStateListener, IHttpListener, ITab):

    def registerExtenderCallbacks(self, callbacks):
        self.callbacks = callbacks
        self.helpers = callbacks.helpers
        
        # text pane
        self.scriptpane = JTextPane()
        self.scriptpane.setFont(Font('Monospaced', Font.PLAIN, 11))

        self.scrollpane = JScrollPane()
        self.scrollpane.setViewportView(self.scriptpane)
        
        # compile to bytecode
        self._code = compile('', '<string>', 'exec')
        self._script = ''
        
        #  load configuration settings for the extension that were saved using the method saveExtensionSetting().
        script = callbacks.loadExtensionSetting('script')
        
        if script:
            script = base64.b64decode(script)

            self.scriptpane.document.insertString(
                self.scriptpane.document.length,
                script,
                SimpleAttributeSet())

            self._script = script
            self._code = compile(script, '<string>', 'exec')
            
        # register
        callbacks.registerExtensionStateListener(self)
        callbacks.registerHttpListener(self)
        
        # ui
        callbacks.customizeUiComponent(self.getUiComponent())
        callbacks.addSuiteTab(self)

        self.scriptpane.requestFocus()
        
    #
    # extender unload
    #

    def extensionUnloaded(self):
        try:
            # save script, base64 encode
            self.callbacks.saveExtensionSetting(
                'script', base64.b64encode(self._script))
        except Exception:
            traceback.print_exc(file=self.callbacks.getStderr())
        return
    
    #
    # implement IHttpListener
    #
    
    def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo):
        try:
            globals_ = {'extender': self,
                        'callbacks': self.callbacks,
                        'helpers': self.helpers
            }
            locals_  = {'toolFlag': toolFlag,
                        'messageIsRequest': messageIsRequest,
                        'messageInfo': messageInfo
            }
            exec(self.script, globals_, locals_)
        except Exception:
            traceback.print_exc(file=self.callbacks.getStderr())
        return

    #
    # implement ITab
    #
    def getTabCaption(self):
        return 'Script'

    def getUiComponent(self):
        return self.scrollpane
    
    #
    # script 不变时,不用重复编译, 优化性能
    #
    
    @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
开发者ID:hxer,项目名称:BurpExtender,代码行数:99,代码来源:burpscript.py

示例5: EditorPanel_text_utf_8

# 需要导入模块: from javax.swing import JTextPane [as 别名]
# 或者: from javax.swing.JTextPane import requestFocus [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.requestFocus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。