55import os
66
77from PyQt5 .QtGui import QColor , QFont , QTextCharFormat , QTextCursor
8- from PyQt5 .QtWidgets import (QLabel , QLineEdit , QMainWindow , QPushButton ,
9- QStackedWidget , QTextEdit , QVBoxLayout , QWidget )
8+ from PyQt5 .QtWidgets import (QLabel , QLineEdit , QMainWindow , QMessageBox ,
9+ QPushButton , QStackedWidget , QTextEdit ,
10+ QVBoxLayout , QWidget )
1011
1112from search import search_questions
13+ from src .cloud_sync import CloudSync
1214from src .cpp_questions import questions as cpp_questions
15+ from src .error_monitor import ErrorMonitor
1316from src .java_questions import questions as java_questions
1417from src .language_selector import LanguageSelector
1518from src .logging_utils import log_error
19+ from src .realtime_analytics import RealTimeAnalyticsDashboard
1620from src .settings import SettingsPanel
1721
1822
@@ -37,8 +41,12 @@ def __init__(self):
3741 self .search_bar .textChanged .connect (self .update_search_results )
3842 self .stacked = QStackedWidget ()
3943 layout .addWidget (self .stacked )
40- self .init_navigation (layout )
44+ self .settings_panel = None
45+ self .analytics_window = None
46+ self .error_monitor = None
47+ self .cloud_sync = None
4148 self .questions = self .load_questions ()
49+ self .init_navigation (layout )
4250 self .init_sections ()
4351 self .search_results_widget = QWidget ()
4452 self .search_results_layout = QVBoxLayout (self .search_results_widget )
@@ -49,7 +57,8 @@ def load_questions(self, language='Python'):
4957 Load interview questions from the data file or language module.
5058 """
5159 if language == 'Python' :
52- path = os .path .join (os .path .dirname (__file__ ), '../data/questions.json' )
60+ base = os .path .dirname (__file__ )
61+ path = os .path .join (base , '../data/questions.json' )
5362 with open (path , 'r' , encoding = 'utf-8' ) as f :
5463 return json .load (f )
5564 elif language == 'Java' :
@@ -190,6 +199,15 @@ def init_navigation(self, layout):
190199 self .settings_btn = QPushButton ("Settings" )
191200 layout .addWidget (self .settings_btn )
192201 self .settings_btn .clicked .connect (self .open_settings )
202+ self .analytics_btn = QPushButton ("Real-Time Analytics" )
203+ layout .addWidget (self .analytics_btn )
204+ self .analytics_btn .clicked .connect (self .open_analytics )
205+ self .error_btn = QPushButton ("Error Monitor" )
206+ layout .addWidget (self .error_btn )
207+ self .error_btn .clicked .connect (self .open_error_monitor )
208+ self .cloud_btn = QPushButton ("Cloud Sync" )
209+ layout .addWidget (self .cloud_btn )
210+ self .cloud_btn .clicked .connect (self .open_cloud_sync )
193211
194212 def open_settings (self ):
195213 self .settings_panel = SettingsPanel ()
@@ -244,3 +262,31 @@ def section_widget(self, level):
244262 code_btn .clicked .connect (lambda checked , t = code_text :
245263 t .setVisible (True ))
246264 return widget
265+
266+ def open_analytics (self ):
267+ """
268+ Open the real-time analytics dashboard with error handling.
269+ """
270+ try :
271+ self .analytics_window = RealTimeAnalyticsDashboard ()
272+ self .analytics_window .show ()
273+ except (RuntimeError , ImportError ) as e :
274+ log_error (f"Analytics dashboard error: { e } " )
275+ QMessageBox .critical (self , "Analytics Error" , str (e ))
276+
277+ def open_error_monitor (self ):
278+ self .error_monitor = ErrorMonitor ()
279+ # For demonstration, show errors in a message box
280+ errors = self .error_monitor .get_errors ()
281+ msg = '\n ' .join (errors ) if errors else 'No errors reported.'
282+ QMessageBox .information (self , "Error Monitor" , msg )
283+
284+ def open_cloud_sync (self ):
285+ # Use a default progress file for demonstration
286+ progress_file = os .path .join (
287+ os .path .dirname (__file__ ), '../data/user_progress.json'
288+ )
289+ self .cloud_sync = CloudSync (progress_file )
290+ self .cloud_sync .sync_to_cloud ()
291+ msg = "Progress synced to cloud."
292+ QMessageBox .information (self , "Cloud Sync" , msg )
0 commit comments