Skip to content

gui

phyllotaxis_analysis.gui Link

MainWindow Link

MainWindow()

Bases: QMainWindow

Main application window for the Phyllotaxis Analyzer.

Source code in src/phyllotaxis_analysis/gui/gui.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def __init__(self) -> None:
    super().__init__()

    # Runtime state
    self.data: list | None = None
    self.datafilename: str = ""
    self.save_filename: str = ""
    self.user_seq: list[float] | None = None

    # Per-analysis result state (populated by _display_analysis_results)
    self.current_seq: list[float] = []
    self.dir_rev: bool = False
    self.seq_rev: list[float] = []
    self.prediction_dir: list[float] = []
    self.prediction_reverse: list[float] = []
    self.not_explained_list_dir: list[int] = []
    self.not_explained_list_rev: list[int] = []
    self.invalids_dir: list = []
    self.invalids_reverse: list = []

    self._setup_window()
    self._create_actions()
    self._setup_menus()
    self._setup_toolbars()
    self._setup_central_widget()
    self._connect_signals()

analyze Link

analyze(user_enter=None, reverse_analysis=False)

Run analysis on the current sequence.

Parameters:

Name Type Description Default
user_enter

When not None the analysis uses self.user_seq instead of a sequence from the loaded file.

None
reverse_analysis bool

Force reverse analysis even when the checkbox is unchecked.

False

Returns:

Type Description
bool

True on success, False on validation failure.

Source code in src/phyllotaxis_analysis/gui/gui.py
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
def analyze(self, user_enter=None, reverse_analysis: bool = False) -> bool:
    """Run analysis on the current sequence.

    Parameters
    ----------
    user_enter:
        When not ``None`` the analysis uses ``self.user_seq`` instead of a
        sequence from the loaded file.
    reverse_analysis:
        Force reverse analysis even when the checkbox is unchecked.

    Returns
    -------
    bool
        ``True`` on success, ``False`` on validation failure.
    """
    if not self.dir_check.isChecked() and not self.reverse_check.isChecked():
        QtWidgets.QMessageBox.warning(
            self, "Check box warning", "Please choose a direction!", QtWidgets.QMessageBox.Ok
        )
        return False

    if self.data is None and user_enter is None:
        QtWidgets.QMessageBox.warning(
            self, "File Warning", "Open a data file please!", QtWidgets.QMessageBox.Ok
        )
        return False

    params = self._collect_params()

    self.status_label.setText("Analyzing...")
    self.status_bar.addWidget(self.status_label, 1)

    seq = (
        list(self.user_seq)
        if user_enter is not None
        else list(self.data[params["plant_no"]])
    )

    if self.direction_check.isChecked():
        seq = change_sequence_orientation(seq)

    all_seqs: list[list[float]] = []
    self.dir_rev = self.dir_check.isChecked() and self.reverse_check.isChecked()

    if self.dir_check.isChecked():
        all_seqs.append(seq)
    if self.reverse_check.isChecked() or reverse_analysis:
        seq_rev = list(seq)
        seq_rev.reverse()
        all_seqs.append(seq_rev)

    self.current_seq = all_seqs[0]

    main_list_of_trees_index = []
    for s in all_seqs:
        trees = code_sequence(
            s,
            params["max_inv"],
            params["phyl_angle"],
            borders_dict,
            params["cons_par"],
            params["prob_threshold"],
        )
        main_list_of_trees_index.append(trees)

    self.status_label.setText("")
    self._display_analysis_results(main_list_of_trees_index, all_seqs, user_enter)
    return True

PlotWindow Link

PlotWindow(parent=None)

Bases: QMainWindow

Standalone window used to display a matplotlib figure with save support.

Source code in src/phyllotaxis_analysis/gui/gui.py
57
58
59
60
def __init__(self, parent: QtWidgets.QWidget | None = None) -> None:
    super().__init__(parent)
    self.canvas: FigureCanvas | None = None
    self._setup_menus()