code_block
_code_block
¶
Code block widget with syntax highlighting.
Uses Pygments for syntax highlighting, supporting 500+ programming languages.
Classes:
| Name | Description |
|---|---|
FXCodeBlock |
A code block widget with syntax highlighting and theme-aware styling. |
FXPygmentsHighlighter |
Syntax highlighter using Pygments for multi-language support. |
Functions:
| Name | Description |
|---|---|
example |
Example demonstrating the FXCodeBlock widget with multiple languages. |
get_supported_languages |
Get a list of all supported language names. |
Classes¶
FXCodeBlock
¶
Bases: FXThemeAware, QWidget
flowchart TD
fxgui.fxwidgets._code_block.FXCodeBlock[FXCodeBlock]
fxgui.fxstyle.FXThemeAware[FXThemeAware]
fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._code_block.FXCodeBlock
click fxgui.fxwidgets._code_block.FXCodeBlock href "" "fxgui.fxwidgets._code_block.FXCodeBlock"
click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
A code block widget with syntax highlighting and theme-aware styling.
This widget displays code with: - Syntax highlighting for 500+ languages via Pygments - Theme-aware background and text colors - Monospace font - Read-only, selectable text
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The code string to display. |
''
|
|
str
|
The programming language (e.g., "python", "javascript"). |
'python'
|
|
Optional[QWidget]
|
The parent widget. |
None
|
Example
code = ''' ... def hello(): ... print("Hello, World!") ... ''' code_block = FXCodeBlock(code)
Methods:
| Name | Description |
|---|---|
code |
Get the current code. |
set_code |
Set the code to display. |
set_language |
Set the programming language for syntax highlighting. |
FXPygmentsHighlighter
¶
Bases: FXThemeAware, QSyntaxHighlighter
flowchart TD
fxgui.fxwidgets._code_block.FXPygmentsHighlighter[FXPygmentsHighlighter]
fxgui.fxstyle.FXThemeAware[FXThemeAware]
fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._code_block.FXPygmentsHighlighter
click fxgui.fxwidgets._code_block.FXPygmentsHighlighter href "" "fxgui.fxwidgets._code_block.FXPygmentsHighlighter"
click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
Syntax highlighter using Pygments for multi-language support.
This highlighter uses Pygments lexers and styles to tokenize and format code. It leverages Pygments' built-in style system for consistent token coloring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
The QTextDocument to highlight. |
required | |
|
str
|
The programming language name (e.g., "python", "javascript"). |
'python'
|
Example
highlighter = FXPygmentsHighlighter(text_edit.document(), "python")
Methods:
| Name | Description |
|---|---|
highlightBlock |
Apply syntax highlighting to a block of text. |
language |
Get the current language. |
refresh_formats |
Refresh formats when theme changes. |
set_language |
Change the syntax highlighting language. |