pyfigures-noai 0.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyfigures/__init__.py +10 -0
- pyfigures/__main__.py +354 -0
- pyfigures/album/__init__.py +9 -0
- pyfigures/album/__main__.py +13 -0
- pyfigures/arrowheads.py +36 -0
- pyfigures/assistant/__init__.py +68 -0
- pyfigures/assistant/advanced_annotations.py +407 -0
- pyfigures/assistant/assistant_actions.py +379 -0
- pyfigures/assistant/categorized_mcp.py +436 -0
- pyfigures/assistant/existing_tools.py +170 -0
- pyfigures/assistant/figure_state.py +106 -0
- pyfigures/assistant/gui_selection.py +189 -0
- pyfigures/assistant/launch.py +241 -0
- pyfigures/assistant/letter_sequence.py +30 -0
- pyfigures/assistant/live_mcp.py +355 -0
- pyfigures/assistant/live_structure.py +224 -0
- pyfigures/assistant/manual_help.py +165 -0
- pyfigures/assistant/manual_help_verified.json +10 -0
- pyfigures/assistant/native_gui.py +354 -0
- pyfigures/assistant/original_registry.py +150 -0
- pyfigures/assistant/partner_gui.py +962 -0
- pyfigures/assistant/plot_lifecycle.py +47 -0
- pyfigures/assistant/pointer_context.py +63 -0
- pyfigures/assistant/readability.py +72 -0
- pyfigures/assistant/recovery.py +56 -0
- pyfigures/assistant/result_evidence.py +57 -0
- pyfigures/assistant/session.py +918 -0
- pyfigures/assistant/submission_review.py +86 -0
- pyfigures/assistant/web_chat.py +308 -0
- pyfigures/atomic_io.py +79 -0
- pyfigures/burned_text.py +104 -0
- pyfigures/colorbar_script.py +85 -0
- pyfigures/constant_panels.py +79 -0
- pyfigures/cvd.py +67 -0
- pyfigures/equations.py +309 -0
- pyfigures/extras.py +188 -0
- pyfigures/flip.py +19 -0
- pyfigures/gui/__init__.py +0 -0
- pyfigures/gui/about_dialog_pzf.py +104 -0
- pyfigures/gui/annotation_editor.py +3813 -0
- pyfigures/gui/asingleoraspanel.py +39 -0
- pyfigures/gui/autolettering_widget.py +320 -0
- pyfigures/gui/bg_color_selection.py +92 -0
- pyfigures/gui/bug_recorder.py +720 -0
- pyfigures/gui/caption_dialog.py +52 -0
- pyfigures/gui/colorassistant.py +131 -0
- pyfigures/gui/command_box.py +36 -0
- pyfigures/gui/ctrl_key.py +17 -0
- pyfigures/gui/deckcraft_blank.json +1 -0
- pyfigures/gui/dimchooser.py +33 -0
- pyfigures/gui/drag_sketch.py +455 -0
- pyfigures/gui/drop_sketch.py +354 -0
- pyfigures/gui/editable_export.py +1395 -0
- pyfigures/gui/editor_interaction.py +189 -0
- pyfigures/gui/emptyimagedialog.py +51 -0
- pyfigures/gui/equation_dialog.py +217 -0
- pyfigures/gui/ezfig.py +6582 -0
- pyfigures/gui/fonts/README.md +28 -0
- pyfigures/gui/fontselectorgui.py +59 -0
- pyfigures/gui/group_builder_GUI.py +120 -0
- pyfigures/gui/headless_ops.py +308 -0
- pyfigures/gui/integrity_ops.py +449 -0
- pyfigures/gui/journal_style_editor.py +346 -0
- pyfigures/gui/keep_tst_images_for_pzf.py +1243 -0
- pyfigures/gui/label_rows.py +79 -0
- pyfigures/gui/latex_code_dialog.py +137 -0
- pyfigures/gui/latex_support.py +115 -0
- pyfigures/gui/lutmultiselector.py +156 -0
- pyfigures/gui/mcp_server_dialog.py +252 -0
- pyfigures/gui/pagelimitswidget.py +72 -0
- pyfigures/gui/panelcreationwidget.py +123 -0
- pyfigures/gui/pdf_support.py +127 -0
- pyfigures/gui/pfgui.py +8437 -0
- pyfigures/gui/portable_fonts.py +236 -0
- pyfigures/gui/qc_reports.py +235 -0
- pyfigures/gui/region_picker.py +68 -0
- pyfigures/gui/render_headless.py +204 -0
- pyfigures/gui/review/__init__.py +41 -0
- pyfigures/gui/review/_template.py +231 -0
- pyfigures/gui/review/dialog.py +86 -0
- pyfigures/gui/review/html_export.py +101 -0
- pyfigures/gui/review/send.py +43 -0
- pyfigures/gui/row_letters.py +134 -0
- pyfigures/gui/scalebareditor.py +206 -0
- pyfigures/gui/scrollableEZFIG.py +574 -0
- pyfigures/gui/show_me_how.py +462 -0
- pyfigures/gui/show_me_where.py +353 -0
- pyfigures/gui/simple_text_editor.py +1273 -0
- pyfigures/gui/spaceselector.py +55 -0
- pyfigures/gui/style_text_headless.py +171 -0
- pyfigures/gui/svg_painter.py +76 -0
- pyfigures/gui/textEditWatcher.py +105 -0
- pyfigures/gui/theme.py +102 -0
- pyfigures/gui/tipdialog.py +117 -0
- pyfigures/gui/tutorial.py +3610 -0
- pyfigures/gui/user_extra_translation.py +52 -0
- pyfigures/gui/user_prefs.py +96 -0
- pyfigures/gui/video_support.py +76 -0
- pyfigures/gui/web_chat_panel.py +591 -0
- pyfigures/gui/widget_for_inset.py +134 -0
- pyfigures/gui/zoom_links.py +130 -0
- pyfigures/guides.py +877 -0
- pyfigures/history.py +272 -0
- pyfigures/icons/__init__.py +40 -0
- pyfigures/icons/pyfigures.png +0 -0
- pyfigures/icons/pyfigures_album.png +0 -0
- pyfigures/icons/pyfigures_poster.png +0 -0
- pyfigures/image_search.py +445 -0
- pyfigures/journal_styles.py +761 -0
- pyfigures/latex_document.py +378 -0
- pyfigures/layout_formula.py +234 -0
- pyfigures/layout_picture.py +146 -0
- pyfigures/mcp_control.py +624 -0
- pyfigures/mcp_server.py +208 -0
- pyfigures/mcp_tools/__init__.py +1 -0
- pyfigures/mcp_tools/annotations.py +1711 -0
- pyfigures/mcp_tools/app.py +517 -0
- pyfigures/mcp_tools/content.py +1536 -0
- pyfigures/mcp_tools/core.py +2844 -0
- pyfigures/mcp_tools/export.py +2388 -0
- pyfigures/mcp_tools/guidance.py +71 -0
- pyfigures/mcp_tools/image_search.py +70 -0
- pyfigures/mcp_tools/journal.py +130 -0
- pyfigures/mcp_tools/overlays.py +1447 -0
- pyfigures/mcp_tools/poster.py +898 -0
- pyfigures/mcp_tools/qc.py +939 -0
- pyfigures/mcp_tools/stacks.py +1027 -0
- pyfigures/mcp_tools/structure.py +2224 -0
- pyfigures/mcp_tools/upkeep.py +662 -0
- pyfigures/mcp_tools/workflow.py +1103 -0
- pyfigures/office_math.py +149 -0
- pyfigures/offscreen.py +46 -0
- pyfigures/panel_source_preview.py +101 -0
- pyfigures/path_resolution.py +223 -0
- pyfigures/poster/__init__.py +9 -0
- pyfigures/poster/__main__.py +45 -0
- pyfigures/poster/page_presets.py +25 -0
- pyfigures/poster/poster_align.py +187 -0
- pyfigures/poster/poster_canvas.py +2119 -0
- pyfigures/poster/poster_headless.py +1072 -0
- pyfigures/poster/poster_layout_dialog.py +114 -0
- pyfigures/poster/poster_layouts.py +216 -0
- pyfigures/poster/poster_recipe.py +384 -0
- pyfigures/poster/poster_shapes.py +619 -0
- pyfigures/poster/poster_source_data.py +130 -0
- pyfigures/poster/poster_templates.py +257 -0
- pyfigures/poster/poster_text_dialog.py +79 -0
- pyfigures/poster/poster_web_export.py +252 -0
- pyfigures/poster/poster_window.py +945 -0
- pyfigures/poster/serialization.py +277 -0
- pyfigures/qt_exit.py +117 -0
- pyfigures/recipe.py +2286 -0
- pyfigures/script_helpers.py +24 -0
- pyfigures/self_test.py +181 -0
- pyfigures/source_snapshot.py +220 -0
- pyfigures/stack_info.py +190 -0
- pyfigures/version.py +11 -0
- pyfigures/zoom_geometry.py +174 -0
- pyfigures_noai-0.2.7.dist-info/METADATA +368 -0
- pyfigures_noai-0.2.7.dist-info/RECORD +163 -0
- pyfigures_noai-0.2.7.dist-info/WHEEL +5 -0
- pyfigures_noai-0.2.7.dist-info/licenses/LICENSE +24 -0
- pyfigures_noai-0.2.7.dist-info/top_level.txt +1 -0
pyfigures/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# exit codes are recorded from here on, for the Qt-teardown guard that a
|
|
2
|
+
# headless tool may arm later (pyfigures/qt_exit.py)
|
|
3
|
+
from pyfigures.qt_exit import install_recorder as _install_recorder
|
|
4
|
+
|
|
5
|
+
_install_recorder()
|
|
6
|
+
|
|
7
|
+
# extras the user installed into a standalone app (e.g. PyMuPDF) become importable
|
|
8
|
+
from pyfigures.extras import enable_extras as _enable_extras
|
|
9
|
+
|
|
10
|
+
_enable_extras()
|
pyfigures/__main__.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# all seems now ok and working well maybe do advanced tests so that I can do this even better
|
|
2
|
+
|
|
3
|
+
from batoolset.settings.global_settings import set_UI
|
|
4
|
+
set_UI()
|
|
5
|
+
from qtpy.QtWidgets import QApplication, QMessageBox, QProgressDialog
|
|
6
|
+
import sys
|
|
7
|
+
from pyfigures.gui.pfgui import EZFIG_GUI
|
|
8
|
+
import os
|
|
9
|
+
# os.environ['QT_FONT_DPI'] = '144'
|
|
10
|
+
# os.environ['QT_LOGGING_RULES'] = 'qt.qpa.wayland*=false' # --> silences wayland bugs but still crashes
|
|
11
|
+
|
|
12
|
+
def run_pyfigures():
|
|
13
|
+
"""
|
|
14
|
+
Runs the PyFigures GUI.
|
|
15
|
+
|
|
16
|
+
This function sets the UI and initializes the QApplication.
|
|
17
|
+
The EPySeg PyFigures window is created and shown.
|
|
18
|
+
The application event loop is started and the program exits
|
|
19
|
+
when the GUI window is closed.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
import batoolset.IJ.ij_reader as ij_reader # availability check — no JVM started yet
|
|
24
|
+
_use_ij_reader = True
|
|
25
|
+
except ImportError:
|
|
26
|
+
ij_reader = None
|
|
27
|
+
_use_ij_reader = False
|
|
28
|
+
|
|
29
|
+
# Initialize the QApplication. Shared GL contexts first: Qt WebEngine (Tools →
|
|
30
|
+
# Chat in a web page) can then be imported later, when the panel opens
|
|
31
|
+
from qtpy.QtCore import QCoreApplication, Qt as _Qt
|
|
32
|
+
QCoreApplication.setAttribute(_Qt.ApplicationAttribute.AA_ShareOpenGLContexts)
|
|
33
|
+
app = QApplication(sys.argv)
|
|
34
|
+
from pyfigures.icons import set_app_identity
|
|
35
|
+
set_app_identity('pyfigures')
|
|
36
|
+
|
|
37
|
+
# Install a Qt-safe global exception hook: without it, any unhandled exception
|
|
38
|
+
# raised inside a slot/timer/event makes PyQt6 abort the whole app with
|
|
39
|
+
# 0xC0000409. With it, the error is logged and shown, and the app keeps running.
|
|
40
|
+
from batoolset.GUI.exception_handler import install_global_exception_handler
|
|
41
|
+
install_global_exception_handler()
|
|
42
|
+
|
|
43
|
+
from pyfigures.gui.theme import apply_theme, load_saved_theme
|
|
44
|
+
apply_theme(load_saved_theme())
|
|
45
|
+
|
|
46
|
+
if False:
|
|
47
|
+
# just a trick to override the default cursor...
|
|
48
|
+
from qtpy.QtGui import QCursor, QPixmap
|
|
49
|
+
# Load a custom cursor image
|
|
50
|
+
cursor_image = QPixmap("/home/aigouy/Téléchargements/cursor-mini.png")
|
|
51
|
+
# Create a custom cursor object with the cursor image
|
|
52
|
+
custom_cursor = QCursor(cursor_image)
|
|
53
|
+
# Set the custom cursor globally for the application
|
|
54
|
+
QApplication.setOverrideCursor(custom_cursor)
|
|
55
|
+
|
|
56
|
+
if True: # TODO -> set this to true at some point
|
|
57
|
+
if _use_ij_reader:
|
|
58
|
+
from qtpy.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout,
|
|
59
|
+
QLabel, QPushButton, QFrame)
|
|
60
|
+
from qtpy.QtCore import Qt, QTimer
|
|
61
|
+
import threading
|
|
62
|
+
|
|
63
|
+
import queue as _queue
|
|
64
|
+
import io as _io
|
|
65
|
+
import re as _re
|
|
66
|
+
import time as _time
|
|
67
|
+
|
|
68
|
+
_ANSI_RE = _re.compile(r'\x1b\[[0-9;]*[mGKHF]')
|
|
69
|
+
|
|
70
|
+
class _QueueWriter(_io.TextIOBase):
|
|
71
|
+
"""Tees stdout/stderr to the original stream and a queue for the dialog."""
|
|
72
|
+
def __init__(self, original, q):
|
|
73
|
+
self._original = original
|
|
74
|
+
self._q = q
|
|
75
|
+
def write(self, text):
|
|
76
|
+
self._original.write(text)
|
|
77
|
+
self._original.flush()
|
|
78
|
+
clean = _ANSI_RE.sub('', text).replace('\r', '').strip()
|
|
79
|
+
if clean:
|
|
80
|
+
self._q.put(clean)
|
|
81
|
+
return len(text)
|
|
82
|
+
def flush(self):
|
|
83
|
+
self._original.flush()
|
|
84
|
+
|
|
85
|
+
class FijiInitDialog(QDialog):
|
|
86
|
+
"""Progress dialog for Fiji initialisation with Skip and Quit options."""
|
|
87
|
+
|
|
88
|
+
def __init__(self, log_queue, parent=None):
|
|
89
|
+
super().__init__(parent)
|
|
90
|
+
from qtpy.QtWidgets import QTextEdit
|
|
91
|
+
self._programmatic_close = False
|
|
92
|
+
self._log_queue = log_queue
|
|
93
|
+
self.setWindowTitle('Fiji initialisation')
|
|
94
|
+
self.setWindowFlags(
|
|
95
|
+
Qt.Window |
|
|
96
|
+
Qt.WindowStaysOnTopHint |
|
|
97
|
+
Qt.WindowTitleHint
|
|
98
|
+
)
|
|
99
|
+
self.setFixedSize(560, 420)
|
|
100
|
+
self.user_skipped = False
|
|
101
|
+
self.user_quit = False
|
|
102
|
+
|
|
103
|
+
layout = QVBoxLayout()
|
|
104
|
+
layout.setSpacing(12)
|
|
105
|
+
layout.setContentsMargins(20, 20, 20, 20)
|
|
106
|
+
|
|
107
|
+
title = QLabel('Fiji (ImageJ) — First Time Setup')
|
|
108
|
+
title.setStyleSheet('font-size: 14pt; font-weight: bold;')
|
|
109
|
+
layout.addWidget(title)
|
|
110
|
+
|
|
111
|
+
line = QFrame()
|
|
112
|
+
line.setFrameShape(QFrame.HLine)
|
|
113
|
+
line.setFrameShadow(QFrame.Sunken)
|
|
114
|
+
layout.addWidget(line)
|
|
115
|
+
|
|
116
|
+
msg = QLabel(
|
|
117
|
+
'Fiji is being downloaded and initialised for the first time.<br>'
|
|
118
|
+
'This requires a one-time download of approximately <b>200MB</b>.<br><br>'
|
|
119
|
+
'<b style="color:red;">⚠ This can take up to 10 minutes</b> depending on your '
|
|
120
|
+
'internet speed — hundreds of dependencies must be resolved.<br>'
|
|
121
|
+
'Subsequent launches will be <b>instant</b> — this only happens once.'
|
|
122
|
+
)
|
|
123
|
+
msg.setWordWrap(True)
|
|
124
|
+
msg.setStyleSheet('font-size: 10pt;')
|
|
125
|
+
layout.addWidget(msg)
|
|
126
|
+
|
|
127
|
+
auto_close = QLabel(
|
|
128
|
+
'<html>ⓘ This window will close automatically once initialisation is complete.'
|
|
129
|
+
)
|
|
130
|
+
auto_close.setWordWrap(True)
|
|
131
|
+
auto_close.setStyleSheet('font-size: 10pt; color: red; font-style: italic;')
|
|
132
|
+
layout.addWidget(auto_close)
|
|
133
|
+
|
|
134
|
+
self._spinner_label = QLabel('Please wait...')
|
|
135
|
+
self._spinner_label.setAlignment(Qt.AlignCenter)
|
|
136
|
+
self._spinner_label.setStyleSheet('font-size: 10pt; color: grey;')
|
|
137
|
+
layout.addWidget(self._spinner_label)
|
|
138
|
+
|
|
139
|
+
self._log_view = QTextEdit()
|
|
140
|
+
self._log_view.setReadOnly(True)
|
|
141
|
+
self._log_view.setFixedHeight(100)
|
|
142
|
+
self._log_view.setStyleSheet('font-size: 8pt; font-family: monospace; background: #1e1e1e; color: #d4d4d4;')
|
|
143
|
+
layout.addWidget(self._log_view)
|
|
144
|
+
|
|
145
|
+
layout.addSpacing(4)
|
|
146
|
+
|
|
147
|
+
line2 = QFrame()
|
|
148
|
+
line2.setFrameShape(QFrame.HLine)
|
|
149
|
+
line2.setFrameShadow(QFrame.Sunken)
|
|
150
|
+
layout.addWidget(line2)
|
|
151
|
+
|
|
152
|
+
options_label = QLabel('Or choose an option below:')
|
|
153
|
+
options_label.setStyleSheet('font-size: 9pt; color: grey;')
|
|
154
|
+
layout.addWidget(options_label)
|
|
155
|
+
|
|
156
|
+
btn_layout = QHBoxLayout()
|
|
157
|
+
btn_skip = QPushButton('Skip (use legacy reader)')
|
|
158
|
+
btn_quit = QPushButton('Quit')
|
|
159
|
+
btn_skip.setMinimumWidth(160)
|
|
160
|
+
btn_quit.setMinimumWidth(80)
|
|
161
|
+
btn_quit.setStyleSheet('color: red;')
|
|
162
|
+
btn_layout.addWidget(btn_skip)
|
|
163
|
+
btn_layout.addStretch()
|
|
164
|
+
btn_layout.addWidget(btn_quit)
|
|
165
|
+
layout.addLayout(btn_layout)
|
|
166
|
+
|
|
167
|
+
self.setLayout(layout)
|
|
168
|
+
|
|
169
|
+
btn_skip.clicked.connect(self._on_skip)
|
|
170
|
+
btn_quit.clicked.connect(self._on_quit)
|
|
171
|
+
|
|
172
|
+
self._spinner_states = ['Please wait . ', 'Please wait .. ', 'Please wait ...']
|
|
173
|
+
self._spinner_idx = 0
|
|
174
|
+
self._timer = QTimer()
|
|
175
|
+
self._timer.timeout.connect(self._tick)
|
|
176
|
+
self._timer.start(400)
|
|
177
|
+
|
|
178
|
+
def _tick(self):
|
|
179
|
+
self._spinner_label.setText(
|
|
180
|
+
self._spinner_states[self._spinner_idx % len(self._spinner_states)])
|
|
181
|
+
self._spinner_idx += 1
|
|
182
|
+
# drain the log queue and append to the log view
|
|
183
|
+
try:
|
|
184
|
+
while True:
|
|
185
|
+
line = self._log_queue.get_nowait()
|
|
186
|
+
self._log_view.append(line)
|
|
187
|
+
self._log_view.verticalScrollBar().setValue(
|
|
188
|
+
self._log_view.verticalScrollBar().maximum())
|
|
189
|
+
except _queue.Empty:
|
|
190
|
+
pass
|
|
191
|
+
|
|
192
|
+
def _on_skip(self):
|
|
193
|
+
self.user_skipped = True
|
|
194
|
+
self._timer.stop()
|
|
195
|
+
self.accept()
|
|
196
|
+
|
|
197
|
+
def _on_quit(self):
|
|
198
|
+
self.user_quit = True
|
|
199
|
+
self._timer.stop()
|
|
200
|
+
self.reject()
|
|
201
|
+
|
|
202
|
+
def closeEvent(self, event):
|
|
203
|
+
if not self._programmatic_close:
|
|
204
|
+
self.user_skipped = True
|
|
205
|
+
self._timer.stop()
|
|
206
|
+
event.accept()
|
|
207
|
+
|
|
208
|
+
if not ij_reader._is_fiji_cached():
|
|
209
|
+
# Fiji not cached — show dialog and wait for download
|
|
210
|
+
log_queue = _queue.Queue()
|
|
211
|
+
dialog = FijiInitDialog(log_queue=log_queue, parent=app.activeWindow())
|
|
212
|
+
dialog.show()
|
|
213
|
+
app.processEvents()
|
|
214
|
+
|
|
215
|
+
done = threading.Event()
|
|
216
|
+
error = [None]
|
|
217
|
+
|
|
218
|
+
def _run():
|
|
219
|
+
import sys as _sys
|
|
220
|
+
import logging as _logging
|
|
221
|
+
_orig_out = _sys.stdout
|
|
222
|
+
_orig_err = _sys.stderr
|
|
223
|
+
try:
|
|
224
|
+
_sys.stdout = _QueueWriter(_orig_out, log_queue)
|
|
225
|
+
_sys.stderr = _QueueWriter(_orig_err, log_queue)
|
|
226
|
+
|
|
227
|
+
# Forward jgo/imagej/scyjava log records to the dialog queue
|
|
228
|
+
class _QHandler(_logging.Handler):
|
|
229
|
+
def emit(self, record):
|
|
230
|
+
print(f'[{record.name.split(".")[-1]}] {record.getMessage()}')
|
|
231
|
+
|
|
232
|
+
_qh = _QHandler(_logging.DEBUG)
|
|
233
|
+
_patched_loggers = []
|
|
234
|
+
for _name in ('jgo', 'imagej', 'scyjava', 'cjdk'):
|
|
235
|
+
_lg = _logging.getLogger(_name)
|
|
236
|
+
_prev_level = _lg.level
|
|
237
|
+
_lg.setLevel(_logging.DEBUG)
|
|
238
|
+
_lg.addHandler(_qh)
|
|
239
|
+
_patched_loggers.append((_lg, _qh, _prev_level))
|
|
240
|
+
|
|
241
|
+
try:
|
|
242
|
+
ij_reader.init_ij()
|
|
243
|
+
except Exception as e:
|
|
244
|
+
error[0] = str(e)
|
|
245
|
+
finally:
|
|
246
|
+
for _lg, _qh, _prev in _patched_loggers:
|
|
247
|
+
_lg.removeHandler(_qh)
|
|
248
|
+
_lg.setLevel(_prev)
|
|
249
|
+
finally:
|
|
250
|
+
_sys.stdout = _orig_out
|
|
251
|
+
_sys.stderr = _orig_err
|
|
252
|
+
done.set()
|
|
253
|
+
|
|
254
|
+
threading.Thread(target=_run, daemon=True).start()
|
|
255
|
+
|
|
256
|
+
while not done.is_set() and dialog.isVisible():
|
|
257
|
+
app.processEvents()
|
|
258
|
+
_time.sleep(0.05)
|
|
259
|
+
|
|
260
|
+
dialog._programmatic_close = True
|
|
261
|
+
dialog.close()
|
|
262
|
+
app.processEvents()
|
|
263
|
+
|
|
264
|
+
if dialog.user_quit:
|
|
265
|
+
sys.exit(0)
|
|
266
|
+
|
|
267
|
+
if error[0]:
|
|
268
|
+
QMessageBox.critical(None, 'Fiji init failed',
|
|
269
|
+
f'Could not initialise Fiji:\n\n{error[0]}')
|
|
270
|
+
elif not dialog.user_skipped:
|
|
271
|
+
print('Fiji loaded successfully.')
|
|
272
|
+
|
|
273
|
+
else:
|
|
274
|
+
# Fiji already cached — init silently in background
|
|
275
|
+
def _init_fiji_cached():
|
|
276
|
+
try:
|
|
277
|
+
ij_reader.init_ij()
|
|
278
|
+
print('Fiji loaded successfully.')
|
|
279
|
+
except Exception:
|
|
280
|
+
pass
|
|
281
|
+
threading.Thread(target=_init_fiji_cached, daemon=True).start()
|
|
282
|
+
|
|
283
|
+
# Only NOW create the main window — Fiji is fully ready (or skipped)
|
|
284
|
+
from pyfigures.gui.user_prefs import load_chat_at_start
|
|
285
|
+
from pyfigures.assistant import sidecar_available
|
|
286
|
+
if load_chat_at_start() and '--chat' not in sys.argv and sidecar_available():
|
|
287
|
+
sys.argv.append('--chat') # View → Open the chat at start-up
|
|
288
|
+
share = '--share' in sys.argv or '--chat' in sys.argv or '--web-chat' in sys.argv
|
|
289
|
+
if share:
|
|
290
|
+
# a window that can share its figure with `python -m pyfigures.assistant.live_mcp`
|
|
291
|
+
from pyfigures.assistant.partner_gui import PartnerGUI
|
|
292
|
+
w = PartnerGUI()
|
|
293
|
+
else:
|
|
294
|
+
w = EZFIG_GUI()
|
|
295
|
+
w.show()
|
|
296
|
+
w.open_guide_mailbox() # MCP show_me_how / `python -m pyfigures.guides show …`
|
|
297
|
+
if share:
|
|
298
|
+
from pyfigures.assistant.launch import apply_launch_flags
|
|
299
|
+
try:
|
|
300
|
+
apply_launch_flags(w, sys.argv[1:])
|
|
301
|
+
except Exception as e:
|
|
302
|
+
QMessageBox.warning(w, 'Share the figure', str(e))
|
|
303
|
+
|
|
304
|
+
# Run the event loop; it returns once the last window is closed.
|
|
305
|
+
exit_code = app.exec_() if hasattr(app, 'exec_') else app.exec()
|
|
306
|
+
# Force-terminate: the ImageJ/JVM background threads are non-daemon and would
|
|
307
|
+
# otherwise keep the interpreter alive after the window closes. closeEvent has
|
|
308
|
+
# already run its cleanup by this point.
|
|
309
|
+
os._exit(exit_code)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def requested_tool(argv, executable):
|
|
313
|
+
"""'album' or 'poster' when that designer should open instead of the
|
|
314
|
+
figure editor: `--album`/`--poster` on the command line, or, in the
|
|
315
|
+
standalone app, the 'PyFigures Album' / 'PyFigures Poster' executables
|
|
316
|
+
(copies of PyFigures built by pyfigures.spec, told apart only by their
|
|
317
|
+
name). None otherwise."""
|
|
318
|
+
if '--album' in argv:
|
|
319
|
+
return 'album'
|
|
320
|
+
if '--poster' in argv:
|
|
321
|
+
return 'poster'
|
|
322
|
+
name = os.path.basename(executable).lower()
|
|
323
|
+
for tool in ('album', 'poster'):
|
|
324
|
+
if tool in name:
|
|
325
|
+
return tool
|
|
326
|
+
return None
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
if __name__ == '__main__':
|
|
330
|
+
if '--live-mcp' in sys.argv:
|
|
331
|
+
# the chat sidebar's MCP server in the standalone apps, where
|
|
332
|
+
# `python -m pyfigures.assistant.live_mcp` has no python to run
|
|
333
|
+
from pyfigures.assistant.live_mcp import main as run_live_mcp
|
|
334
|
+
run_live_mcp()
|
|
335
|
+
sys.stdout.flush()
|
|
336
|
+
os._exit(0)
|
|
337
|
+
if '--self-test' in sys.argv:
|
|
338
|
+
# build check: PyFigures --self-test report.json (see pyfigures/self_test.py)
|
|
339
|
+
from pyfigures.self_test import run as run_self_test
|
|
340
|
+
args = sys.argv[sys.argv.index('--self-test') + 1:]
|
|
341
|
+
code = run_self_test(args[0] if args else 'pyfigures_self_test.json')
|
|
342
|
+
sys.stdout.flush()
|
|
343
|
+
os._exit(code)
|
|
344
|
+
from pyfigures.assistant.web_chat import is_web_chat_app
|
|
345
|
+
if (getattr(sys, 'frozen', False) and is_web_chat_app(sys.executable)
|
|
346
|
+
and '--web-chat' not in sys.argv and not requested_tool(sys.argv[1:], '')):
|
|
347
|
+
sys.argv.append('--web-chat') # the "PyFigures Web Chat" app opens with the web chat
|
|
348
|
+
tool = requested_tool(sys.argv[1:], sys.executable if getattr(sys, 'frozen', False) else '')
|
|
349
|
+
if tool is not None:
|
|
350
|
+
from pyfigures.poster.__main__ import run_poster_designer
|
|
351
|
+
run_poster_designer(album=tool == 'album')
|
|
352
|
+
else:
|
|
353
|
+
# Run the PyFigures GUI
|
|
354
|
+
run_pyfigures()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Photo album designer.
|
|
2
|
+
|
|
3
|
+
A separate tool from the poster / collage designer: `python -m pyfigures.album`
|
|
4
|
+
(or Tools > Photo album designer… in the figure editor) opens a PosterWindow
|
|
5
|
+
in album mode — pinned front and back covers with two-page spreads between
|
|
6
|
+
them. The poster designer cannot turn a poster into an album; albums are made
|
|
7
|
+
here. Drawing, file format (.pyfalbum), exports, recipes (`album: true`) and
|
|
8
|
+
MCP tools are the poster module's (pyfigures.poster).
|
|
9
|
+
"""
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Standalone launcher: `python -m pyfigures.album` opens the photo album
|
|
2
|
+
designer directly — the same window as the figure editor's
|
|
3
|
+
`Tools > Photo album designer…` menu.
|
|
4
|
+
"""
|
|
5
|
+
from pyfigures.poster.__main__ import run_poster_designer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def run_album_designer():
|
|
9
|
+
run_poster_designer(album=True)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
if __name__ == '__main__':
|
|
13
|
+
run_album_designer()
|
pyfigures/arrowheads.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Arrowhead-only marks, as in papers: a larger head and no line. Stored as an
|
|
2
|
+
ordinary arrow (Line2D, arrow=True) whose line is much shorter than its head,
|
|
3
|
+
so the head always swallows it — nothing new in the .pyf format, every export
|
|
4
|
+
draws it. One rule shared by the image editor, the MCP tools and the readers
|
|
5
|
+
that tell an arrowhead from an arrow.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import math
|
|
10
|
+
|
|
11
|
+
# head (half width, length) in multiples of the stroke: larger than an arrow's
|
|
12
|
+
ARROWHEAD_ONLY = (6.0, 16.0)
|
|
13
|
+
ARROWHEAD_SIZES = {"small": (4.5, 12.0), "normal": (6.0, 16.0), "large": (8.0, 22.0)}
|
|
14
|
+
# line length (image px) of a stored arrowhead: only its direction matters
|
|
15
|
+
HEAD_ONLY_LENGTH = 0.5
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def make_head_only(line, sizes=ARROWHEAD_ONLY):
|
|
19
|
+
"""Turn a drawn arrow (Line2D) into an arrowhead: same tip and direction,
|
|
20
|
+
a line too short to show, a larger head."""
|
|
21
|
+
p1, p2 = line.p1(), line.p2()
|
|
22
|
+
dx, dy = p2.x() - p1.x(), p2.y() - p1.y()
|
|
23
|
+
n = math.hypot(dx, dy)
|
|
24
|
+
if n > 0:
|
|
25
|
+
from qtpy.QtCore import QPointF
|
|
26
|
+
line.setP1(QPointF(p2.x() - dx / n * HEAD_ONLY_LENGTH, p2.y() - dy / n * HEAD_ONLY_LENGTH))
|
|
27
|
+
line.arrow = True
|
|
28
|
+
line.arrow_at_both_ends = False
|
|
29
|
+
line.arrowhead_width_scaler = max(float(line.arrowhead_width_scaler or 0), sizes[0])
|
|
30
|
+
line.arrowhead_height_scaler = max(float(line.arrowhead_height_scaler or 0), sizes[1])
|
|
31
|
+
return line
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def is_head_only(x1, y1, x2, y2, arrow) -> bool:
|
|
35
|
+
"""An arrow whose line is (about) HEAD_ONLY_LENGTH long: an arrowhead."""
|
|
36
|
+
return bool(arrow) and math.hypot(float(x2) - float(x1), float(y2) - float(y1)) <= 2 * HEAD_ONLY_LENGTH
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Live link between the open figure editor and an MCP client or the
|
|
2
|
+
qtpy_ai_sidecar chat dock.
|
|
3
|
+
|
|
4
|
+
``start_live_session(window)`` serves the open document on 127.0.0.1 (bearer
|
|
5
|
+
token in ``connection.json``); ``python -m pyfigures.assistant.live_mcp`` is
|
|
6
|
+
the stdio MCP server that forwards to it. The chat dock itself is the separate
|
|
7
|
+
``qtpy_ai_sidecar`` package (optional): ``attach_sidecar(window)`` docks it
|
|
8
|
+
when it is installed.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def runtime_dir() -> Path:
|
|
18
|
+
"""Connection descriptor, recovery copies and transaction workspaces:
|
|
19
|
+
``PYFIGURES_LIVE_RUNTIME`` if set, else the user's app-data folder
|
|
20
|
+
(never the repository, never the figure's folder)."""
|
|
21
|
+
override = os.environ.get("PYFIGURES_LIVE_RUNTIME")
|
|
22
|
+
if override:
|
|
23
|
+
path = Path(override)
|
|
24
|
+
elif sys.platform == "win32":
|
|
25
|
+
path = Path(os.environ.get("LOCALAPPDATA") or Path.home() / "AppData" / "Local") / "PyFigures" / "assistant"
|
|
26
|
+
elif sys.platform == "darwin":
|
|
27
|
+
path = Path.home() / "Library" / "Application Support" / "PyFigures" / "assistant"
|
|
28
|
+
else:
|
|
29
|
+
path = Path(os.environ.get("XDG_DATA_HOME") or Path.home() / ".local" / "share") / "PyFigures" / "assistant"
|
|
30
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
return path
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def descriptor_path() -> Path:
|
|
35
|
+
return runtime_dir() / "connection.json"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def sidecar_available() -> bool:
|
|
39
|
+
if not ai_features_enabled():
|
|
40
|
+
return False
|
|
41
|
+
try:
|
|
42
|
+
import qtpy_ai_sidecar # noqa: F401
|
|
43
|
+
except Exception:
|
|
44
|
+
return False
|
|
45
|
+
return True
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def is_no_ai_app(executable) -> bool:
|
|
49
|
+
"""The 'PyFigures NoAI' standalone app, told apart by its name."""
|
|
50
|
+
name = os.path.basename(executable).lower().replace(" ", "").replace("-", "").replace("_", "")
|
|
51
|
+
return "noai" in name
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def ai_features_enabled() -> bool:
|
|
55
|
+
"""False in the no-AI install (``pip install pyfigures-noai``: no chat
|
|
56
|
+
sidebar package, and the chat / MCP entries hidden) or with
|
|
57
|
+
PYFIGURES_NO_AI=1."""
|
|
58
|
+
if os.environ.get("PYFIGURES_NO_AI") == "1":
|
|
59
|
+
return False
|
|
60
|
+
if getattr(sys, "frozen", False):
|
|
61
|
+
# the "PyFigures NoAI" app (pyfigures.spec with PYFIGURES_NO_AI=1)
|
|
62
|
+
return not is_no_ai_app(sys.executable)
|
|
63
|
+
import importlib.metadata as md
|
|
64
|
+
try:
|
|
65
|
+
md.distribution("pyfigures-noai")
|
|
66
|
+
except md.PackageNotFoundError:
|
|
67
|
+
return True
|
|
68
|
+
return False
|