Open a PDF and select text to get started.
' + ) + layout.addWidget(self._browser) + + # Bottom buttons + btn_layout = QHBoxLayout() + self._clear_btn = QPushButton("Clear History") + self._clear_btn.clicked.connect(self.clear_history) + + self._export_btn = QPushButton("Export Explanations") + self._export_btn.clicked.connect(self._export_explanations) + + btn_layout.addWidget(self._clear_btn) + btn_layout.addWidget(self._export_btn) + btn_layout.addStretch() + layout.addLayout(btn_layout) + + def show_loading(self) -> None: + """Show the loading indicator.""" + self._progress_bar.show() + self._loading_label.show() + + def hide_loading(self) -> None: + """Hide the loading indicator.""" + self._progress_bar.hide() + self._loading_label.hide() + + def show_explanation( + self, query: str, response_text: str + ) -> List[HighlightSegment]: + """Display a Gemini response and return highlight segments. + + Args: + query: The user's original query/selection. + response_text: Raw response text from Gemini. + + Returns: + List of HighlightSegment objects found in the response. + """ + self.hide_loading() + html = response_to_html(response_text) + highlights = extract_highlights(response_text) + + entry = {"query": query, "html": html, "raw": response_text} + self._history.append(entry) + + self._render_history() + return highlights + + def show_error(self, message: str) -> None: + """Display an error message. + + Args: + message: Error message to display. + """ + self.hide_loading() + error_html = ( + f'History cleared. Select text to get a new explanation.
' + ) + + def _render_history(self) -> None: + """Render the full conversation history.""" + html_parts = [] + for i, entry in enumerate(reversed(self._history)): + idx = len(self._history) - i + html_parts.append( + f'