The debug module#

This module provides a debug window to show/edit text and the tokenized tree.

Use:

$ python3 -m parceqt.debug  <filename>

You can also create a debug window in an interactive session; see the class documentation.

The debug window shows highlighted text, and the tokenized tree structure.

class DebugWindow(parent=None)[source]#

Bases: QMainWindow

A main window to edit text and examine the generated token structure.

Example:

from PyQt5.Qt import *
a=QApplication([])

from parceqt.debug import DebugWindow
w = DebugWindow()
w.resize(1200,900)
w.show()

w.set_theme("default", True)

from parce.lang.css import *
w.set_root_lexicon(Css.root)
w.set_text(open("path/to/parce/themes/default.css").read())

In the debug window you can edit the text at the left and directly at the right examine the tree structure. Along the top of the window the path to the token at the current cursor position is displayed, from the root lexicon upto the token, from which the action is displayed.

Clicking a button selects the associated range of the context or token in the text view. Clicking an item in the tree also selects that range in the text.

Moving the cursor in the text updates the current item in the tree, and the displayed ancestor path.

show_updated_region_enabled = False#
create_model()[source]#

Instantiate a tree model for the tree view.

delete_model()[source]#

Delete the model and remove it from the tree.

set_text(text)[source]#

Set the text in the text edit.

set_root_lexicon(lexicon)[source]#

Set the root lexicon to use.

guess_root_lexicon()[source]#

Again choose the root lexicon based on the text.

open_file(filename)[source]#

Read a file from disk and guess the language.

set_theme(theme='default', adjust_widget=True)[source]#

Set the theme to use for the text edit.

slot_build_started()[source]#

Called when the tree builder has started a build.

slot_build_updated()[source]#

Called when the tree builder has finished a build.

slot_cursor_position_changed()[source]#

Called when the text cursor moved.

slot_item_clicked(index)[source]#

Called when a node in the tree view is clicked.

slot_node_clicked(node)[source]#

Called when a button in the ancestor view is clicked.

highlight_current_line()[source]#

Highlight the current line.

show_updated_region()[source]#

Highlight the updated region for 2 seconds.

clear_updated_region()[source]#
eventFilter(obj, ev)[source]#

Implemented to support Ctrl+wheel zooming and keybfocus handling.

class LexiconChooser(parent=None, registry=None)[source]#

Bases: LexiconChooser

display_name(qualname)[source]#

Reimplemented to show the full root lexicon name.

class AncestorView(parent=None)[source]#

Bases: QWidget

Displays a horizontal row of buttons for a token.

node_clicked#

Qt signal, emitted when a node is clicked.

clear()[source]#

Delete all buttons.

set_token_path(token)[source]#

Create buttons for the token and its ancestors.

class Actions(mainwindow)[source]#

Bases: object

Container for all the QActions and their implementations.

create_actions()[source]#
set_action_texts()[source]#
set_action_shortcuts()[source]#
set_action_defaults()[source]#
add_menus(menubar)[source]#

Populate a menu bar.

connect_actions()[source]#
open_file()[source]#

Implementation of Open File action.

copy_html()[source]#

Copy selected text as HTML.

toggle_tree_visibility(checked)[source]#

Handle Show Tree Structure checkbox toggle.

toggle_updated_region_visibility(checked)[source]#

Handle Show Updated Region checkbox toggle.

slot_view_theme_selected(action)[source]#

Switch to the selected theme.

tree_expand_all()[source]#

Implementation of Expand All action.

tree_collapse_all()[source]#

Implementation of Collapse All action.

reload_theme()[source]#

Reload the theme.

lexicon_names(lexicons)[source]#

Yield the names of the lexicons with the language removed if that is the same as the previous lexicon’s language.

read_file(filename)[source]#

Read the contents of a file, if the encoding fails, read in latin1.