114 lines
3.7 KiB
Python
114 lines
3.7 KiB
Python
"""
|
|
Incremental diagnostic test #2.
|
|
|
|
The standalone minimal_crash_test.py (bare dialog, no app code) has
|
|
NEVER crashed. A dialog inside the real app with almost no widgets at
|
|
all (just one label and two buttons) STILL crashes. So the difference
|
|
must be something about the app around the dialog, not the dialog's
|
|
own widgets - two candidates: (1) a real SQLAlchemy Order object is
|
|
involved, (2) the dialog opens via a QToolBar/QAction inside a larger
|
|
QMainWindow rather than a plain QPushButton on a near-empty window.
|
|
|
|
This script adds BOTH of those, on top of the exact same working
|
|
baseline dialog content, using this project's actual database code -
|
|
run it from the project root (same folder as main.py):
|
|
|
|
python minimal_crash_test_2.py
|
|
|
|
Click "Open Dialog", close it (X or Cancel). If this crashes, we've
|
|
found the actual trigger. If it doesn't, the cause is something more
|
|
specific to main_window.py itself that isn't reproduced here yet.
|
|
"""
|
|
import sys
|
|
import datetime as dt
|
|
|
|
from PyQt6.QtWidgets import (
|
|
QApplication,
|
|
QMainWindow,
|
|
QToolBar,
|
|
QDialog,
|
|
QVBoxLayout,
|
|
QLabel,
|
|
QDialogButtonBox,
|
|
)
|
|
from PyQt6.QtGui import QAction
|
|
|
|
from app.database import init_db
|
|
from app.workers import save_orders, load_all_orders
|
|
|
|
|
|
class MinimalDialog(QDialog):
|
|
def __init__(self, order, parent=None):
|
|
super().__init__(parent)
|
|
self.order = order
|
|
self.setWindowTitle("Minimal Test Dialog (with real Order)")
|
|
layout = QVBoxLayout(self)
|
|
info = order.shipping_info or {}
|
|
layout.addWidget(
|
|
QLabel(f"Ticket: {order.ticket_number}\nCustomer: {info.get('name')}")
|
|
)
|
|
|
|
button_box = QDialogButtonBox()
|
|
button_box.addButton("OK", QDialogButtonBox.ButtonRole.AcceptRole)
|
|
button_box.addButton(QDialogButtonBox.StandardButton.Cancel)
|
|
button_box.accepted.connect(self.accept)
|
|
button_box.rejected.connect(self.reject)
|
|
layout.addWidget(button_box)
|
|
|
|
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self, order):
|
|
super().__init__()
|
|
self.order = order
|
|
self.setWindowTitle("Minimal Crash Test 2 (real Order + QAction + QToolBar)")
|
|
self.resize(400, 150)
|
|
|
|
toolbar = QToolBar("Main")
|
|
self.addToolBar(toolbar)
|
|
action = QAction("Open Dialog", self)
|
|
action.triggered.connect(self.open_dialog)
|
|
toolbar.addAction(action)
|
|
|
|
def open_dialog(self):
|
|
print("about to construct dialog", flush=True)
|
|
dialog = MinimalDialog(self.order, self)
|
|
print("about to call exec()", flush=True)
|
|
result = dialog.exec()
|
|
print(f"exec() returned {result}", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
init_db()
|
|
|
|
# Ensure there's at least one order to work with
|
|
orders = load_all_orders()
|
|
if not orders:
|
|
save_orders(
|
|
[
|
|
{
|
|
"source": "jira",
|
|
"external_id": "TEST-1",
|
|
"ticket_number": "TEST-1",
|
|
"company": "Oak Street Health",
|
|
"skus": ["OK012"],
|
|
"line_items": [],
|
|
"shipping_info": {"name": "Test Customer"},
|
|
"creator": "X",
|
|
"assignee": "Y",
|
|
"description": "",
|
|
"tracking_numbers": [],
|
|
"shipping_method": None,
|
|
"summary": "",
|
|
"status": "Created",
|
|
"source_created_at": dt.datetime.now(),
|
|
"raw_data": {},
|
|
}
|
|
]
|
|
)
|
|
orders = load_all_orders()
|
|
|
|
app = QApplication(sys.argv)
|
|
window = MainWindow(orders[0])
|
|
window.show()
|
|
sys.exit(app.exec())
|