Пример #1
0
 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)
Пример #2
0
    def __init__(self):
        """
        Line numbers need to be displayed in a separate panel with different
        styling.
        """
        # Align right
        para_attribs = SimpleAttributeSet()
        StyleConstants.setAlignment(para_attribs, StyleConstants.ALIGN_RIGHT)
        self.setParagraphAttributes(para_attribs, True)

        # Use default font style
        default_attribs = SimpleAttributeSet()
        StyleConstants.setFontFamily(default_attribs, "Monaco")
        StyleConstants.setFontSize(default_attribs, 14)
        StyleConstants.setForeground(default_attribs, Color.gray)
        self.setCharacterAttributes(default_attribs, True)

        # Initialize content
        border = BorderFactory.createEmptyBorder(4, 4, 4, 4)
        self.border = border
        self.setText("1: \n")
        self.setEditable(False)

        # Prevent auto scroll down when line numbers are repainted
        caret = self.getCaret()
        caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE)
Пример #3
0
    def __init__(self):
        """
        Line numbers need to be displayed in a separate panel with different
        styling.
        """
        # Align right
        para_attribs = SimpleAttributeSet()
        StyleConstants.setAlignment(para_attribs, StyleConstants.ALIGN_RIGHT)
        self.setParagraphAttributes(para_attribs, True)

        # Use default font style
        default_attribs = SimpleAttributeSet()
        self.font = set_font()
        StyleConstants.setFontFamily(default_attribs, self.font.getFamily())
        StyleConstants.setFontSize(default_attribs, self.font.getSize())
        StyleConstants.setForeground(default_attribs, Color.gray)
        self.setCharacterAttributes(default_attribs, True)

        # Initialize content
        border = BorderFactory.createEmptyBorder(4, 4, 4, 4)
        self.border = border
        self.setText("1: \n")
        self.setEditable(False)

        # Prevent auto scroll down when line numbers are repainted
        caret = self.getCaret()
        caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE)
Пример #4
0
    def _setStyle(self, attrSet, styleSpec):
        flags, color = styleSpec

        StyleConstants.setForeground(attrSet, color)

        if flags & MONOSPACE:
            StyleConstants.setFontFamily(attrSet, self.monoFontFamily)
        else:
            StyleConstants.setFontFamily(attrSet, self.defaultFontFamily)
Пример #5
0
    def _setStyle(self, attrSet, styleSpec):
        flags, color = styleSpec

        StyleConstants.setForeground(attrSet, color)

        if flags & MONOSPACE:
            StyleConstants.setFontFamily(attrSet, self.monoFontFamily)
        else:
            StyleConstants.setFontFamily(attrSet, self.defaultFontFamily)
Пример #6
0
    def log(self, msg, color=None, bold=False, end='\n'):
        msg = str(msg).replace("\n", "\n    ") + end
        doc = self._log.getStyledDocument()
        aset = SimpleAttributeSet()
        if color:
            StyleConstants.setForeground(aset, color)
        if bold:
            StyleConstants.setBold(aset, True)

        doc.insertString(self._log.getDocument().getLength(), msg, aset)
        self._logButton.setEnabled(True)
Пример #7
0
 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)
Пример #8
0
 def get_attribs(color, error=False):
     '''
     Closure to make the generation of font styling cleaner.
     Note closures need to be defined before being invoked.
     '''
     attribs = SimpleAttributeSet()
     StyleConstants.setFontFamily(attribs, self.font.getFamily())
     StyleConstants.setFontSize(attribs, self.font.getSize())
     StyleConstants.setForeground(attribs, Color(*self.colorlut[color]))
     # Add yellow background to error line styling
     # White if no error, otherwise it'll keep on being yellow forever
     if error:
         StyleConstants.setBackground(attribs, Color.yellow)
     else:
         StyleConstants.setBackground(attribs, Color.white)
     return attribs
Пример #9
0
 def new_style(name, color=None, bold=None, italic=None, underline=None):
     style = self.doc.addStyle(name, self.parent_style)
     if color is not None:
         if isinstance(color, str):
             color = awtColor(
                 int(color[0:2], 16),
                 int(color[2:4], 16),
                 int(color[4:6], 16)
             )
         StyleConstants.setForeground(style, color)
     if bold is not None:
         StyleConstants.setBold(style, bold)
     if italic is not None:
         StyleConstants.setItalic(style, italic)
     if underline is not None:
         StyleConstants.setUnderline(style, underline)
     return style
Пример #10
0
 def get_attribs(color, error=False, match=False):
     '''
     Closure to make the generation of font styling cleaner.
     Note closures need to be defined before being invoked.
     '''
     attribs = SimpleAttributeSet()
     StyleConstants.setFontFamily(attribs,
                                  self.font.getFamily())
     StyleConstants.setFontSize(attribs,
                                self.font.getSize())
     StyleConstants.setForeground(attribs,
                                  Color(*self.colorlut[color]))
     # Add yellow background to error line styling
     # White if no error, otherwise it'll keep on being yellow forever
     if error:
         StyleConstants.setBackground(attribs, Color.yellow)
     elif match:
         # TODO: Change to another background colour Eleanor likes
         StyleConstants.setBackground(attribs, Color.yellow)
     else:
         StyleConstants.setBackground(attribs, Color.white)
     return attribs
Пример #11
0
    def filter2(self, messageContent,styledDoc,style):
        pattern = '((location\s*[\[.])|([.\[]\s*["\']?\s*(arguments|dialogArguments|innerHTML|write(ln)?|open(Dialog)?|showModalDialog|cookie|URL|documentURI|baseURI|referrer|name|opener|parent|top|content|self|frames)\W)|(localStorage|sessionStorage|Database))|(((src|href|data|location|code|value|action)\s*["\'\]]*\s*\+?\s*=)|((replace|assign|navigate|getResponseHeader|open(Dialog)?|showModalDialog|eval|evaluate|execCommand|execScript|setTimeout|setInterval)\s*["\'\]]*\s*\())|(after\(|\.append\(|\.before\(|\.html\(|\.prepend\(|\.replaceWith\(|\.wrap\(|\.wrapAll\(|\$\(|\.globalEval\(|\.add\(|jQUery\(|\$\(|\.parseHTML\()'
        compiledPattern = re.compile(pattern)

        initPos = 0
        for find in compiledPattern.finditer(messageContent):
            StyleConstants.setForeground(style, Color.black)
            styledDoc.insertString(styledDoc.getLength(),messageContent[initPos:find.start()] , style)
            StyleConstants.setForeground(style, Color.red)
            styledDoc.insertString(styledDoc.getLength(),find.group(), style)
            initPos = find.start()+len(find.group())

        StyleConstants.setForeground(style, Color.black)
        styledDoc.insertString(styledDoc.getLength(),messageContent[initPos:] , style)
        return