From 1ef6b0c0a1aa2854716bcec3d607546a5af29e35 Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Wed, 11 Feb 2026 11:36:21 +0000 Subject: [PATCH] fix: add QCheckBox import and fix sqlite3.Row access - Add missing QCheckBox to PyQt6.QtWidgets import - Fix sqlite3.Row access - use 'in row.keys()' instead of .get() - Fixes template and session loading errors --- ui/main_window.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/ui/main_window.py b/ui/main_window.py index ee4c5e2..c1701be 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -20,7 +20,7 @@ from PyQt6.QtWidgets import ( QDialog, QLineEdit, QFormLayout, QDialogButtonBox, QMessageBox, QGroupBox, QFrame, QApplication, QTreeWidget, QTreeWidgetItem, QHeaderView, QComboBox, - QGridLayout, QToolButton + QGridLayout, QToolButton, QCheckBox ) from PyQt6.QtCore import Qt, pyqtSignal, QTimer, QSize, QSettings from PyQt6.QtGui import QAction, QFont, QColor, QPalette, QIcon @@ -1069,7 +1069,9 @@ class MainWindow(QMainWindow): ) for proj in projects: - activity = ActivityType.from_string(proj.get('type', 'hunting')) + # sqlite3.Row doesn't have .get() method + proj_type = proj['type'] if 'type' in proj.keys() else 'hunt' + activity = ActivityType.from_string(proj_type) # Get session count count_result = self.db.fetchone( "SELECT COUNT(*) as count FROM sessions WHERE project_id = ?", @@ -1086,12 +1088,16 @@ class MainWindow(QMainWindow): if last_result and last_result['last']: last_session = datetime.fromisoformat(last_result['last']) + # Handle description which might not exist in old databases + description = proj['description'] if 'description' in proj.keys() else '' + created_at = proj['created_at'] if 'created_at' in proj.keys() else None + template = SessionTemplate( id=proj['id'], name=proj['name'], activity_type=activity, - description=proj.get('description', ''), - created_at=datetime.fromisoformat(proj['created_at']) if proj.get('created_at') else None, + description=description, + created_at=datetime.fromisoformat(created_at) if created_at else None, session_count=session_count, last_session=last_session ) @@ -1192,13 +1198,16 @@ class MainWindow(QMainWindow): """) for row in rows: - activity = ActivityType.from_string(row.get('type', 'hunting')) + # sqlite3.Row doesn't have .get() method, use direct access + row_type = row['type'] if 'type' in row.keys() else 'hunt' + activity = ActivityType.from_string(row_type) # Calculate duration started = datetime.fromisoformat(row['started_at']) duration = 0 - if row.get('ended_at'): - ended = datetime.fromisoformat(row['ended_at']) + ended_at = row['ended_at'] if 'ended_at' in row.keys() else None + if ended_at: + ended = datetime.fromisoformat(ended_at) duration = int((ended - started).total_seconds() / 60) elif row['status'] == 'running': duration = int((datetime.now() - started).total_seconds() / 60) @@ -1215,7 +1224,7 @@ class MainWindow(QMainWindow): duration_minutes=duration, total_cost=total_cost, total_return=total_return, - status=row.get('status', 'unknown') + status=row['status'] if 'status' in row.keys() else 'unknown' ) sessions.append(session) except Exception as e: