chipiron.scripts.tree_visualization package

Submodules

chipiron.scripts.tree_visualization.tree_visualizer module

This module contains classes for visualizing a tree structure and interacting with it.

Classes: - PhotoViewer: A QGraphicsView widget for displaying and interacting with an image. - Window: A QWidget that contains a PhotoViewer and provides additional functionality for tree visualization. - VisualizeTreeScript: A script for running the tree visualization application.

Usage: 1. Create an instance of VisualizeTreeScript. 2. Call the run() method to start the visualization application. 3. Interact with the displayed tree using mouse clicks and keyboard shortcuts. 4. Call the terminate() method to finish the script.

Note: This code requires the PySide6 library and the chipiron package to be installed.

class chipiron.scripts.tree_visualization.tree_visualizer.PhotoViewer(parent)[source]

Bases: QGraphicsView

A custom QGraphicsView widget for displaying photos.

Signals:
  • photoClicked: Signal emitted when the photo is clicked. It provides the position of the click as a QPoint.

- hasPhoto()

Check if the viewer has a photo loaded.

- fitInView(scale=True)

Fit the photo within the view.

- set_photo(pixmap=None)

Set the photo to be displayed.

- wheelEvent(event)

Handle the wheel event for zooming.

- toggleDragMode()

Toggle the drag mode between ScrollHandDrag and NoDrag.

- mousePressEvent(event)

Handle the mouse press event.

- zoomin()

Zoom in the photo.

- zoomout()

Zoom out the photo.

fitInView(scale=True)[source]

Fit the photo within the view.

Parameters:

scale (bool) – Whether to scale the photo to fit the view. Default is True.

hasPhoto()[source]

Check if the viewer has a photo loaded.

Returns:

True if a photo is loaded, False otherwise.

Return type:

bool

mousePressEvent(event)[source]

Handle the mouse press event.

Parameters:

event (QMouseEvent) – The mouse press event object.

photoClicked
set_photo(pixmap=None)[source]

Set the photo to be displayed.

Parameters:

pixmap (QPixmap) – The photo to be displayed. If None, the viewer will be empty.

staticMetaObject = PySide6.QtCore.QMetaObject("PhotoViewer" inherits "QGraphicsView": Methods:   #46 type=Signal, signature=photoClicked(QPoint), parameters=QPoint )
toggleDragMode()[source]

Toggle the drag mode between ScrollHandDrag and NoDrag.

wheelEvent(event)[source]

Handle the wheel event for zooming.

Parameters:

event (QWheelEvent) – The wheel event object.

zoomin()[source]

Zoom in the photo.

zoomout()[source]

Zoom out the photo.

class chipiron.scripts.tree_visualization.tree_visualizer.VisualizeTreeScript(base_script: Script[Any])[source]

Bases: object

This class represents a script for visualizing a tree.

base_experiment_output_folder = 'chipiron/scripts/tree_visualization/outputs/'
base_script: Script[Any]
run() None[source]

Runs the tree visualizer application.

terminate() None[source]

Finishing the script. Profiling or timing.

class chipiron.scripts.tree_visualization.tree_visualizer.Window[source]

Bases: QWidget

A class representing a window for tree visualization.

Variables:
  • viewer (PhotoViewer) – The photo viewer widget.

  • btnLoad (QtWidgets.QToolButton) – The button to load an image.

  • btnPixInfo (QtWidgets.QToolButton) – The button to enter pixel info mode.

  • editPixInfo (QtWidgets.QLineEdit) – The line edit widget for pixel info.

  • tree (MoveAndValueTree) – The tree object for visualization.

  • current_node (Node) – The current node being displayed.

  • index (dict) – A dictionary mapping moves to indices.

__init__()[source]

Initializes the Window object.

build_subtree()[source]

Builds the subtree.

display_subtree()[source]

Displays the subtree.

load_image()[source]

Loads an image.

pixInfo()[source]

Toggles between drag/pan and pixel info mode.

photoClicked()[source]

Handles the photo clicked event.

keyPressEvent()[source]

Handles the key press event.

father()[source]

Moves to the parent node.

move_to_son()[source]

Moves to the specified child node.

build_subtree()[source]

Builds the subtree of the current node.

This method iterates over the moves of the current node and assigns an index to each move. The index is stored in the index dictionary, where the move is the key and the index is the value.

Returns:

None

display_subtree()[source]

Displays the subtree rooted at the current node.

This method generates a visualization of the subtree rooted at the current node and saves it as a JPG image file.

Parameters:

None

Returns:

None

father()[source]

Move to the parent node of the current node and perform necessary operations.

keyPressEvent(event)[source]

Handles key press events.

Parameters:

event (QKeyEvent) – The key press event.

Returns:

None

load_image()[source]

Loads an image and sets it as the photo for the viewer.

The image is loaded from the file ‘chipiron/runs/treedisplays/TreeVisualtemp.jpg’.

Parameters:

None

Returns:

None

move_to_son(key)[source]

Moves to the specified son node based on the given key.

Parameters:

key – The key of the son node to move to.

Returns:

None

Raises:

None

photoClicked(pos)[source]

Handle the event when a photo is clicked.

Parameters:

pos (QPoint) – The position of the click.

Returns:

None

pixInfo()[source]

Toggles the drag mode of the viewer.

This method is used to toggle the drag mode of the viewer. It switches between the modes of dragging and not dragging the image.

Parameters:

None

Returns:

None

staticMetaObject = PySide6.QtCore.QMetaObject("Window" inherits "QWidget": )

Module contents