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
This commit is contained in:
LemonNexus 2026-02-11 11:36:21 +00:00
parent 522ee8e719
commit 1ef6b0c0a1
1 changed files with 17 additions and 8 deletions

View File

@ -20,7 +20,7 @@ from PyQt6.QtWidgets import (
QDialog, QLineEdit, QFormLayout, QDialogButtonBox, QDialog, QLineEdit, QFormLayout, QDialogButtonBox,
QMessageBox, QGroupBox, QFrame, QApplication, QMessageBox, QGroupBox, QFrame, QApplication,
QTreeWidget, QTreeWidgetItem, QHeaderView, QComboBox, QTreeWidget, QTreeWidgetItem, QHeaderView, QComboBox,
QGridLayout, QToolButton QGridLayout, QToolButton, QCheckBox
) )
from PyQt6.QtCore import Qt, pyqtSignal, QTimer, QSize, QSettings from PyQt6.QtCore import Qt, pyqtSignal, QTimer, QSize, QSettings
from PyQt6.QtGui import QAction, QFont, QColor, QPalette, QIcon from PyQt6.QtGui import QAction, QFont, QColor, QPalette, QIcon
@ -1069,7 +1069,9 @@ class MainWindow(QMainWindow):
) )
for proj in projects: 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 # Get session count
count_result = self.db.fetchone( count_result = self.db.fetchone(
"SELECT COUNT(*) as count FROM sessions WHERE project_id = ?", "SELECT COUNT(*) as count FROM sessions WHERE project_id = ?",
@ -1086,12 +1088,16 @@ class MainWindow(QMainWindow):
if last_result and last_result['last']: if last_result and last_result['last']:
last_session = datetime.fromisoformat(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( template = SessionTemplate(
id=proj['id'], id=proj['id'],
name=proj['name'], name=proj['name'],
activity_type=activity, activity_type=activity,
description=proj.get('description', ''), description=description,
created_at=datetime.fromisoformat(proj['created_at']) if proj.get('created_at') else None, created_at=datetime.fromisoformat(created_at) if created_at else None,
session_count=session_count, session_count=session_count,
last_session=last_session last_session=last_session
) )
@ -1192,13 +1198,16 @@ class MainWindow(QMainWindow):
""") """)
for row in rows: 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 # Calculate duration
started = datetime.fromisoformat(row['started_at']) started = datetime.fromisoformat(row['started_at'])
duration = 0 duration = 0
if row.get('ended_at'): ended_at = row['ended_at'] if 'ended_at' in row.keys() else None
ended = datetime.fromisoformat(row['ended_at']) if ended_at:
ended = datetime.fromisoformat(ended_at)
duration = int((ended - started).total_seconds() / 60) duration = int((ended - started).total_seconds() / 60)
elif row['status'] == 'running': elif row['status'] == 'running':
duration = int((datetime.now() - started).total_seconds() / 60) duration = int((datetime.now() - started).total_seconds() / 60)
@ -1215,7 +1224,7 @@ class MainWindow(QMainWindow):
duration_minutes=duration, duration_minutes=duration,
total_cost=total_cost, total_cost=total_cost,
total_return=total_return, total_return=total_return,
status=row.get('status', 'unknown') status=row['status'] if 'status' in row.keys() else 'unknown'
) )
sessions.append(session) sessions.append(session)
except Exception as e: except Exception as e: