-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure_design_questions.py
More file actions
1536 lines (1283 loc) · 68.4 KB
/
Copy pathazure_design_questions.py
File metadata and controls
1536 lines (1283 loc) · 68.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
Azure Design Questions Manager
A GUI application for managing design questions for Azure components
"""
import sqlite3
import tkinter as tk
from tkinter import ttk, messagebox, scrolledtext, filedialog
from datetime import datetime
import os
class AzureDesignQuestionsApp:
def __init__(self, root):
self.root = root
self.root.title("Azure Design Questions Manager")
self.root.geometry("1400x800")
# Set window close protocol
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
# Initialize database
self.db_path = "azure_design_questions.db"
self.init_database()
# Create menu bar
self.create_menu()
# Create main UI
self.create_widgets()
# Load initial data
self.refresh_questions_list()
def init_database(self):
"""Initialize SQLite database with required tables"""
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
# Check if tables exist and have correct schema
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
existing_tables = [row[0] for row in cursor.fetchall()]
# If projects table exists but doesn't have correct schema, we need to recreate
if 'projects' in existing_tables:
try:
cursor.execute("SELECT id, project_name, description, status FROM projects LIMIT 1")
except sqlite3.OperationalError:
# Schema is outdated, need to recreate
print("Upgrading database schema...")
cursor.execute("DROP TABLE IF EXISTS project_answers")
cursor.execute("DROP TABLE IF EXISTS project_components")
cursor.execute("DROP TABLE IF EXISTS projects")
# Create azure_components table
cursor.execute('''
CREATE TABLE IF NOT EXISTS azure_components (
id INTEGER PRIMARY KEY AUTOINCREMENT,
component_name TEXT UNIQUE NOT NULL,
category TEXT,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# Create design_questions table
cursor.execute('''
CREATE TABLE IF NOT EXISTS design_questions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
component_id INTEGER NOT NULL,
question_text TEXT NOT NULL,
answer_guidance TEXT,
priority TEXT DEFAULT 'Medium',
tags TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (component_id) REFERENCES azure_components (id)
)
''')
# Create projects table
cursor.execute('''
CREATE TABLE IF NOT EXISTS projects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_name TEXT UNIQUE NOT NULL,
description TEXT,
status TEXT DEFAULT 'Active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# Create project_components table (many-to-many relationship)
cursor.execute('''
CREATE TABLE IF NOT EXISTS project_components (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER NOT NULL,
component_id INTEGER NOT NULL,
notes TEXT,
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE,
FOREIGN KEY (component_id) REFERENCES azure_components (id) ON DELETE CASCADE,
UNIQUE(project_id, component_id)
)
''')
# Create project_answers table (stores answers to questions within project context)
cursor.execute('''
CREATE TABLE IF NOT EXISTS project_answers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER NOT NULL,
question_id INTEGER NOT NULL,
answer_text TEXT,
answered_by TEXT,
answered_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE,
FOREIGN KEY (question_id) REFERENCES design_questions (id) ON DELETE CASCADE,
UNIQUE(project_id, question_id)
)
''')
# Insert default Azure components if table is empty
cursor.execute("SELECT COUNT(*) FROM azure_components")
if cursor.fetchone()[0] == 0:
default_components = [
("Azure SQL Database", "Database", "Managed relational database service"),
("Azure Function App", "Compute", "Serverless compute service"),
("Azure Key Vault", "Security", "Secrets management service"),
("Azure Storage Account", "Storage", "Cloud storage solution"),
("Azure App Service", "Compute", "Web app hosting service"),
("Azure Cosmos DB", "Database", "NoSQL database service"),
("Azure Service Bus", "Integration", "Message broker service"),
("Azure API Management", "Integration", "API gateway service"),
("Azure Virtual Network", "Networking", "Virtual network infrastructure"),
("Azure Application Insights", "Monitoring", "Application performance monitoring"),
("Azure Container Registry", "Containers", "Container image registry"),
("Azure Kubernetes Service", "Containers", "Managed Kubernetes service"),
("Azure Logic Apps", "Integration", "Workflow automation service"),
("Azure Event Grid", "Integration", "Event routing service"),
("Azure Redis Cache", "Cache", "In-memory data store")
]
cursor.executemany(
"INSERT INTO azure_components (component_name, category, description) VALUES (?, ?, ?)",
default_components
)
conn.commit()
conn.close()
except Exception as e:
print(f"Database initialization error: {e}")
print(f"If you see 'no such column' errors, delete {self.db_path} and restart the application.")
raise
def create_menu(self):
"""Create the menu bar"""
menubar = tk.Menu(self.root)
self.root.config(menu=menubar)
# File menu
file_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Export Project Report...", command=self.export_project_report_menu, accelerator="Ctrl+E")
file_menu.add_separator()
file_menu.add_command(label="Exit", command=self.on_closing, accelerator="Alt+F4")
# Edit menu
edit_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="Edit", menu=edit_menu)
edit_menu.add_command(label="Add Component", command=self.add_component)
edit_menu.add_command(label="Add Question", command=self.add_question)
edit_menu.add_separator()
edit_menu.add_command(label="New Project", command=self.add_project)
# Help menu
help_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="Help", menu=help_menu)
help_menu.add_command(label="About", command=self.show_about)
# Bind keyboard shortcuts
self.root.bind('<Control-e>', lambda e: self.export_project_report_menu())
def on_closing(self):
"""Handle window close event"""
if messagebox.askokcancel("Quit", "Do you want to exit Azure Design Questions Manager?"):
self.root.destroy()
def export_project_report_menu(self):
"""Export report from menu - checks if project is selected"""
if hasattr(self, 'current_project_id'):
self.export_project_report()
else:
messagebox.showinfo("Info",
"Please select a project in the Projects tab, then click Export Report.")
def show_about(self):
"""Show about dialog"""
about_text = """Azure Design Questions Manager
Version 2.1
A comprehensive tool for managing design questions
and architecture reviews for Azure solutions.
Features:
• Component library management
• Design questions library
• Project management
• Q&A tracking
• Report generation
© 2025 - Educational Use"""
messagebox.showinfo("About", about_text)
def create_widgets(self):
"""Create all GUI widgets"""
# Create notebook (tabbed interface)
self.notebook = ttk.Notebook(self.root)
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Create Components/Questions tab
self.components_tab = ttk.Frame(self.notebook)
self.notebook.add(self.components_tab, text="Components & Questions")
self.create_components_tab()
# Create Projects tab
self.projects_tab = ttk.Frame(self.notebook)
self.notebook.add(self.projects_tab, text="Projects")
self.create_projects_tab()
# Status bar
self.status_var = tk.StringVar()
self.status_var.set("Ready")
status_bar = ttk.Label(self.root, textvariable=self.status_var, relief=tk.SUNKEN, anchor=tk.W)
status_bar.pack(side=tk.BOTTOM, fill=tk.X)
def create_components_tab(self):
"""Create the components and questions management interface"""
# Create main container with paned window
main_paned = ttk.PanedWindow(self.components_tab, orient=tk.HORIZONTAL)
main_paned.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Left panel - Components list
left_frame = ttk.Frame(main_paned)
main_paned.add(left_frame, weight=1)
# Components section
ttk.Label(left_frame, text="Azure Components", font=("Arial", 12, "bold")).pack(pady=5)
# Search box for components
search_frame = ttk.Frame(left_frame)
search_frame.pack(fill=tk.X, padx=5, pady=5)
ttk.Label(search_frame, text="Search:").pack(side=tk.LEFT)
self.component_search_var = tk.StringVar()
self.component_search_var.trace("w", self.filter_components)
ttk.Entry(search_frame, textvariable=self.component_search_var).pack(side=tk.LEFT, fill=tk.X, expand=True, padx=5)
# Components listbox
list_frame = ttk.Frame(left_frame)
list_frame.pack(fill=tk.BOTH, expand=True, padx=5)
scrollbar = ttk.Scrollbar(list_frame)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.components_listbox = tk.Listbox(list_frame, yscrollcommand=scrollbar.set, font=("Arial", 10))
self.components_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.config(command=self.components_listbox.yview)
self.components_listbox.bind("<<ListboxSelect>>", self.on_component_select)
# Component management buttons
comp_btn_frame = ttk.Frame(left_frame)
comp_btn_frame.pack(fill=tk.X, padx=5, pady=5)
ttk.Button(comp_btn_frame, text="Add Component", command=self.add_component).pack(side=tk.LEFT, padx=2)
ttk.Button(comp_btn_frame, text="Edit Component", command=self.edit_component).pack(side=tk.LEFT, padx=2)
ttk.Button(comp_btn_frame, text="Delete Component", command=self.delete_component).pack(side=tk.LEFT, padx=2)
# Right panel - Questions
right_frame = ttk.Frame(main_paned)
main_paned.add(right_frame, weight=2)
# Questions header
header_frame = ttk.Frame(right_frame)
header_frame.pack(fill=tk.X, pady=5)
ttk.Label(header_frame, text="Design Questions", font=("Arial", 12, "bold")).pack(side=tk.LEFT, padx=5)
# Question buttons
btn_frame = ttk.Frame(header_frame)
btn_frame.pack(side=tk.RIGHT, padx=5)
ttk.Button(btn_frame, text="Add Question", command=self.add_question).pack(side=tk.LEFT, padx=2)
ttk.Button(btn_frame, text="Edit Question", command=self.edit_question).pack(side=tk.LEFT, padx=2)
ttk.Button(btn_frame, text="Delete Question", command=self.delete_question).pack(side=tk.LEFT, padx=2)
# Questions treeview
tree_frame = ttk.Frame(right_frame)
tree_frame.pack(fill=tk.BOTH, expand=True, padx=5)
# Scrollbars for treeview
tree_scroll_y = ttk.Scrollbar(tree_frame)
tree_scroll_y.pack(side=tk.RIGHT, fill=tk.Y)
tree_scroll_x = ttk.Scrollbar(tree_frame, orient=tk.HORIZONTAL)
tree_scroll_x.pack(side=tk.BOTTOM, fill=tk.X)
# Create treeview
self.questions_tree = ttk.Treeview(
tree_frame,
columns=("ID", "Question", "Priority", "Tags", "Created"),
show="tree headings",
yscrollcommand=tree_scroll_y.set,
xscrollcommand=tree_scroll_x.set
)
self.questions_tree.pack(fill=tk.BOTH, expand=True)
tree_scroll_y.config(command=self.questions_tree.yview)
tree_scroll_x.config(command=self.questions_tree.xview)
# Configure columns
self.questions_tree.column("#0", width=0, stretch=False)
self.questions_tree.column("ID", width=50, anchor=tk.CENTER)
self.questions_tree.column("Question", width=400, anchor=tk.W)
self.questions_tree.column("Priority", width=80, anchor=tk.CENTER)
self.questions_tree.column("Tags", width=150, anchor=tk.W)
self.questions_tree.column("Created", width=150, anchor=tk.CENTER)
# Configure headings
self.questions_tree.heading("ID", text="ID")
self.questions_tree.heading("Question", text="Question")
self.questions_tree.heading("Priority", text="Priority")
self.questions_tree.heading("Tags", text="Tags")
self.questions_tree.heading("Created", text="Created")
# Bind double-click to edit
self.questions_tree.bind("<Double-1>", lambda e: self.edit_question())
# Load components
self.load_components()
def create_projects_tab(self):
"""Create the projects management interface"""
# Main horizontal paned window
main_paned = ttk.PanedWindow(self.projects_tab, orient=tk.HORIZONTAL)
main_paned.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Left panel - Projects list
left_frame = ttk.Frame(main_paned)
main_paned.add(left_frame, weight=1)
# Projects header
ttk.Label(left_frame, text="Projects", font=("Arial", 12, "bold")).pack(pady=5)
# Projects listbox with scrollbar
list_frame = ttk.Frame(left_frame)
list_frame.pack(fill=tk.BOTH, expand=True, padx=5)
scrollbar = ttk.Scrollbar(list_frame)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.projects_listbox = tk.Listbox(list_frame, yscrollcommand=scrollbar.set, font=("Arial", 10))
self.projects_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.config(command=self.projects_listbox.yview)
self.projects_listbox.bind("<<ListboxSelect>>", self.on_project_select)
# Project management buttons
proj_btn_frame = ttk.Frame(left_frame)
proj_btn_frame.pack(fill=tk.X, padx=5, pady=5)
ttk.Button(proj_btn_frame, text="New Project", command=self.add_project).pack(side=tk.LEFT, padx=2)
ttk.Button(proj_btn_frame, text="Edit Project", command=self.edit_project).pack(side=tk.LEFT, padx=2)
ttk.Button(proj_btn_frame, text="Delete Project", command=self.delete_project).pack(side=tk.LEFT, padx=2)
# Right panel - Project details (notebook for components and Q&A)
right_frame = ttk.Frame(main_paned)
main_paned.add(right_frame, weight=2)
# Project details notebook
self.project_notebook = ttk.Notebook(right_frame)
self.project_notebook.pack(fill=tk.BOTH, expand=True, pady=5)
# Components tab
components_frame = ttk.Frame(self.project_notebook)
self.project_notebook.add(components_frame, text="Components")
# Components header and buttons
comp_header = ttk.Frame(components_frame)
comp_header.pack(fill=tk.X, pady=5, padx=5)
ttk.Label(comp_header, text="Project Components", font=("Arial", 11, "bold")).pack(side=tk.LEFT)
comp_btn = ttk.Frame(comp_header)
comp_btn.pack(side=tk.RIGHT)
ttk.Button(comp_btn, text="Add Component", command=self.add_component_to_project).pack(side=tk.LEFT, padx=2)
ttk.Button(comp_btn, text="Remove Component", command=self.remove_component_from_project).pack(side=tk.LEFT, padx=2)
# Project components treeview
proj_comp_frame = ttk.Frame(components_frame)
proj_comp_frame.pack(fill=tk.BOTH, expand=True, padx=5)
proj_comp_scroll = ttk.Scrollbar(proj_comp_frame)
proj_comp_scroll.pack(side=tk.RIGHT, fill=tk.Y)
self.project_components_tree = ttk.Treeview(
proj_comp_frame,
columns=("ID", "Component", "Category", "Notes"),
show="tree headings",
yscrollcommand=proj_comp_scroll.set
)
self.project_components_tree.pack(fill=tk.BOTH, expand=True)
proj_comp_scroll.config(command=self.project_components_tree.yview)
self.project_components_tree.column("#0", width=0, stretch=False)
self.project_components_tree.column("ID", width=50, anchor=tk.CENTER)
self.project_components_tree.column("Component", width=200, anchor=tk.W)
self.project_components_tree.column("Category", width=120, anchor=tk.W)
self.project_components_tree.column("Notes", width=300, anchor=tk.W)
self.project_components_tree.heading("ID", text="ID")
self.project_components_tree.heading("Component", text="Component")
self.project_components_tree.heading("Category", text="Category")
self.project_components_tree.heading("Notes", text="Notes")
# Questions & Answers tab
qa_frame = ttk.Frame(self.project_notebook)
self.project_notebook.add(qa_frame, text="Questions & Answers")
# Q&A header
qa_header = ttk.Frame(qa_frame)
qa_header.pack(fill=tk.X, pady=5, padx=5)
ttk.Label(qa_header, text="Design Questions & Answers", font=("Arial", 11, "bold")).pack(side=tk.LEFT)
# Filter by component
filter_frame = ttk.Frame(qa_header)
filter_frame.pack(side=tk.RIGHT)
ttk.Label(filter_frame, text="Component:").pack(side=tk.LEFT, padx=2)
self.qa_filter_var = tk.StringVar(value="All")
self.qa_filter_combo = ttk.Combobox(filter_frame, textvariable=self.qa_filter_var, width=20, state="readonly")
self.qa_filter_combo.pack(side=tk.LEFT, padx=2)
self.qa_filter_combo.bind("<<ComboboxSelected>>", self.filter_project_questions)
# Q&A treeview
qa_tree_frame = ttk.Frame(qa_frame)
qa_tree_frame.pack(fill=tk.BOTH, expand=True, padx=5)
qa_scroll_y = ttk.Scrollbar(qa_tree_frame)
qa_scroll_y.pack(side=tk.RIGHT, fill=tk.Y)
self.project_qa_tree = ttk.Treeview(
qa_tree_frame,
columns=("Q_ID", "Component", "Question", "Answer", "Status", "Answered By"),
show="tree headings",
yscrollcommand=qa_scroll_y.set
)
self.project_qa_tree.pack(fill=tk.BOTH, expand=True)
qa_scroll_y.config(command=self.project_qa_tree.yview)
self.project_qa_tree.column("#0", width=0, stretch=False)
self.project_qa_tree.column("Q_ID", width=50, anchor=tk.CENTER)
self.project_qa_tree.column("Component", width=150, anchor=tk.W)
self.project_qa_tree.column("Question", width=300, anchor=tk.W)
self.project_qa_tree.column("Answer", width=200, anchor=tk.W)
self.project_qa_tree.column("Status", width=100, anchor=tk.CENTER)
self.project_qa_tree.column("Answered By", width=120, anchor=tk.W)
self.project_qa_tree.heading("Q_ID", text="Q ID")
self.project_qa_tree.heading("Component", text="Component")
self.project_qa_tree.heading("Question", text="Question")
self.project_qa_tree.heading("Answer", text="Answer")
self.project_qa_tree.heading("Status", text="Status")
self.project_qa_tree.heading("Answered By", text="Answered By")
# Bind double-click to answer question
self.project_qa_tree.bind("<Double-1>", lambda e: self.answer_project_question())
# Q&A buttons
qa_btn_frame = ttk.Frame(qa_frame)
qa_btn_frame.pack(fill=tk.X, padx=5, pady=5)
ttk.Button(qa_btn_frame, text="Answer Question", command=self.answer_project_question).pack(side=tk.LEFT, padx=2)
ttk.Button(qa_btn_frame, text="View/Edit Answer", command=self.answer_project_question).pack(side=tk.LEFT, padx=2)
ttk.Button(qa_btn_frame, text="Export Report", command=self.export_project_report).pack(side=tk.LEFT, padx=2)
# Load projects
self.load_projects()
def load_components(self):
"""Load all Azure components into the listbox"""
self.components_listbox.delete(0, tk.END)
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute("SELECT id, component_name, category FROM azure_components ORDER BY component_name")
self.components_data = cursor.fetchall()
conn.close()
for comp_id, name, category in self.components_data:
display_text = f"{name} ({category})" if category else name
self.components_listbox.insert(tk.END, display_text)
def filter_components(self, *args):
"""Filter components based on search text"""
search_text = self.component_search_var.get().lower()
self.components_listbox.delete(0, tk.END)
for comp_id, name, category in self.components_data:
if search_text in name.lower() or (category and search_text in category.lower()):
display_text = f"{name} ({category})" if category else name
self.components_listbox.insert(tk.END, display_text)
def on_component_select(self, event):
"""Handle component selection"""
selection = self.components_listbox.curselection()
if selection:
index = selection[0]
# Find the actual component from filtered results
display_text = self.components_listbox.get(index)
for comp_id, name, category in self.components_data:
expected_text = f"{name} ({category})" if category else name
if expected_text == display_text:
self.current_component_id = comp_id
self.refresh_questions_list()
break
def refresh_questions_list(self):
"""Refresh the questions treeview"""
# Clear existing items
for item in self.questions_tree.get_children():
self.questions_tree.delete(item)
if not hasattr(self, 'current_component_id'):
return
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
SELECT id, question_text, priority, tags, created_at
FROM design_questions
WHERE component_id = ?
ORDER BY created_at DESC
''', (self.current_component_id,))
questions = cursor.fetchall()
conn.close()
for question in questions:
q_id, text, priority, tags, created = question
# Truncate long question text for display
display_text = text[:100] + "..." if len(text) > 100 else text
created_date = created.split()[0] if created else ""
self.questions_tree.insert("", tk.END, values=(q_id, display_text, priority, tags or "", created_date))
# Update status
count = len(questions)
self.status_var.set(f"Showing {count} question(s)")
def add_component(self):
"""Add a new Azure component"""
dialog = ComponentDialog(self.root, "Add Azure Component")
self.root.wait_window(dialog.dialog)
if dialog.result:
name, category, description = dialog.result
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
"INSERT INTO azure_components (component_name, category, description) VALUES (?, ?, ?)",
(name, category, description)
)
conn.commit()
conn.close()
self.load_components()
messagebox.showinfo("Success", "Component added successfully!")
except sqlite3.IntegrityError:
messagebox.showerror("Error", "A component with this name already exists!")
except Exception as e:
messagebox.showerror("Error", f"Failed to add component: {str(e)}")
def edit_component(self):
"""Edit selected component"""
selection = self.components_listbox.curselection()
if not selection:
messagebox.showwarning("Warning", "Please select a component to edit!")
return
if not hasattr(self, 'current_component_id'):
return
# Get current component data
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
"SELECT component_name, category, description FROM azure_components WHERE id = ?",
(self.current_component_id,)
)
current_data = cursor.fetchone()
conn.close()
dialog = ComponentDialog(self.root, "Edit Azure Component", current_data)
self.root.wait_window(dialog.dialog)
if dialog.result:
name, category, description = dialog.result
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
"UPDATE azure_components SET component_name = ?, category = ?, description = ? WHERE id = ?",
(name, category, description, self.current_component_id)
)
conn.commit()
conn.close()
self.load_components()
messagebox.showinfo("Success", "Component updated successfully!")
except Exception as e:
messagebox.showerror("Error", f"Failed to update component: {str(e)}")
def delete_component(self):
"""Delete selected component"""
selection = self.components_listbox.curselection()
if not selection:
messagebox.showwarning("Warning", "Please select a component to delete!")
return
if not hasattr(self, 'current_component_id'):
return
# Check if component has questions
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute("SELECT COUNT(*) FROM design_questions WHERE component_id = ?", (self.current_component_id,))
count = cursor.fetchone()[0]
if count > 0:
if not messagebox.askyesno("Confirm Delete",
f"This component has {count} question(s). Delete anyway?"):
conn.close()
return
cursor.execute("DELETE FROM design_questions WHERE component_id = ?", (self.current_component_id,))
cursor.execute("DELETE FROM azure_components WHERE id = ?", (self.current_component_id,))
conn.commit()
conn.close()
self.load_components()
self.refresh_questions_list()
messagebox.showinfo("Success", "Component deleted successfully!")
def add_question(self):
"""Add a new design question"""
if not hasattr(self, 'current_component_id'):
messagebox.showwarning("Warning", "Please select a component first!")
return
dialog = QuestionDialog(self.root, "Add Design Question")
self.root.wait_window(dialog.dialog)
if dialog.result:
question, answer, priority, tags = dialog.result
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
INSERT INTO design_questions
(component_id, question_text, answer_guidance, priority, tags)
VALUES (?, ?, ?, ?, ?)
''', (self.current_component_id, question, answer, priority, tags))
conn.commit()
conn.close()
self.refresh_questions_list()
messagebox.showinfo("Success", "Question added successfully!")
except Exception as e:
messagebox.showerror("Error", f"Failed to add question: {str(e)}")
def edit_question(self):
"""Edit selected question"""
selection = self.questions_tree.selection()
if not selection:
messagebox.showwarning("Warning", "Please select a question to edit!")
return
item = self.questions_tree.item(selection[0])
question_id = item['values'][0]
# Get current question data
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
SELECT question_text, answer_guidance, priority, tags
FROM design_questions WHERE id = ?
''', (question_id,))
current_data = cursor.fetchone()
conn.close()
dialog = QuestionDialog(self.root, "Edit Design Question", current_data)
self.root.wait_window(dialog.dialog)
if dialog.result:
question, answer, priority, tags = dialog.result
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
UPDATE design_questions
SET question_text = ?, answer_guidance = ?, priority = ?, tags = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
''', (question, answer, priority, tags, question_id))
conn.commit()
conn.close()
self.refresh_questions_list()
messagebox.showinfo("Success", "Question updated successfully!")
except Exception as e:
messagebox.showerror("Error", f"Failed to update question: {str(e)}")
def delete_question(self):
"""Delete selected question"""
selection = self.questions_tree.selection()
if not selection:
messagebox.showwarning("Warning", "Please select a question to delete!")
return
if not messagebox.askyesno("Confirm Delete", "Are you sure you want to delete this question?"):
return
item = self.questions_tree.item(selection[0])
question_id = item['values'][0]
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute("DELETE FROM design_questions WHERE id = ?", (question_id,))
conn.commit()
conn.close()
self.refresh_questions_list()
messagebox.showinfo("Success", "Question deleted successfully!")
except Exception as e:
messagebox.showerror("Error", f"Failed to delete question: {str(e)}")
# ========== Project Management Methods ==========
def load_projects(self):
"""Load all projects into the listbox"""
self.projects_listbox.delete(0, tk.END)
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
SELECT id, project_name, status FROM projects
ORDER BY project_name
''')
self.projects_data = cursor.fetchall()
conn.close()
for proj_id, name, status in self.projects_data:
display_text = f"{name} [{status}]"
self.projects_listbox.insert(tk.END, display_text)
def on_project_select(self, event):
"""Handle project selection"""
selection = self.projects_listbox.curselection()
if selection:
index = selection[0]
self.current_project_id = self.projects_data[index][0]
self.refresh_project_components()
self.refresh_project_questions()
def add_project(self):
"""Add a new project"""
dialog = ProjectDialog(self.root, "Add New Project")
self.root.wait_window(dialog.dialog)
if dialog.result:
name, description, status = dialog.result
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
"INSERT INTO projects (project_name, description, status) VALUES (?, ?, ?)",
(name, description, status)
)
conn.commit()
conn.close()
self.load_projects()
messagebox.showinfo("Success", "Project added successfully!")
except sqlite3.IntegrityError:
messagebox.showerror("Error", "A project with this name already exists!")
except Exception as e:
messagebox.showerror("Error", f"Failed to add project: {str(e)}")
def edit_project(self):
"""Edit selected project"""
selection = self.projects_listbox.curselection()
if not selection:
messagebox.showwarning("Warning", "Please select a project to edit!")
return
if not hasattr(self, 'current_project_id'):
return
# Get current project data
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
"SELECT project_name, description, status FROM projects WHERE id = ?",
(self.current_project_id,)
)
current_data = cursor.fetchone()
conn.close()
dialog = ProjectDialog(self.root, "Edit Project", current_data)
self.root.wait_window(dialog.dialog)
if dialog.result:
name, description, status = dialog.result
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
"UPDATE projects SET project_name = ?, description = ?, status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?",
(name, description, status, self.current_project_id)
)
conn.commit()
conn.close()
self.load_projects()
messagebox.showinfo("Success", "Project updated successfully!")
except Exception as e:
messagebox.showerror("Error", f"Failed to update project: {str(e)}")
def delete_project(self):
"""Delete selected project"""
selection = self.projects_listbox.curselection()
if not selection:
messagebox.showwarning("Warning", "Please select a project to delete!")
return
if not hasattr(self, 'current_project_id'):
return
if not messagebox.askyesno("Confirm Delete",
"Are you sure you want to delete this project? All associated data will be removed."):
return
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute("DELETE FROM projects WHERE id = ?", (self.current_project_id,))
conn.commit()
conn.close()
self.load_projects()
self.refresh_project_components()
self.refresh_project_questions()
messagebox.showinfo("Success", "Project deleted successfully!")
except Exception as e:
messagebox.showerror("Error", f"Failed to delete project: {str(e)}")
def refresh_project_components(self):
"""Refresh the project components list"""
# Clear existing items
for item in self.project_components_tree.get_children():
self.project_components_tree.delete(item)
if not hasattr(self, 'current_project_id'):
return
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
SELECT ac.id, ac.component_name, ac.category, pc.notes
FROM project_components pc
JOIN azure_components ac ON pc.component_id = ac.id
WHERE pc.project_id = ?
ORDER BY ac.component_name
''', (self.current_project_id,))
components = cursor.fetchall()
conn.close()
for comp_id, name, category, notes in components:
notes_display = (notes[:50] + "...") if notes and len(notes) > 50 else (notes or "")
self.project_components_tree.insert("", tk.END, values=(comp_id, name, category or "", notes_display))
# Update filter combo in Q&A tab
self.update_qa_filter_combo()
def update_qa_filter_combo(self):
"""Update the component filter combo box in Q&A tab"""
if not hasattr(self, 'current_project_id'):
self.qa_filter_combo['values'] = ["All"]
return
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute('''
SELECT DISTINCT ac.component_name
FROM project_components pc
JOIN azure_components ac ON pc.component_id = ac.id
WHERE pc.project_id = ?
ORDER BY ac.component_name
''', (self.current_project_id,))
components = [row[0] for row in cursor.fetchall()]
conn.close()
self.qa_filter_combo['values'] = ["All"] + components
self.qa_filter_var.set("All")
def add_component_to_project(self):
"""Add a component to the current project"""
if not hasattr(self, 'current_project_id'):
messagebox.showwarning("Warning", "Please select a project first!")
return
dialog = AddComponentToProjectDialog(self.root, self.db_path, self.current_project_id)
self.root.wait_window(dialog.dialog)
if dialog.result:
component_id, notes = dialog.result
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
cursor.execute(
"INSERT INTO project_components (project_id, component_id, notes) VALUES (?, ?, ?)",
(self.current_project_id, component_id, notes)
)
conn.commit()
conn.close()
self.refresh_project_components()
self.refresh_project_questions()
messagebox.showinfo("Success", "Component added to project!")
except sqlite3.IntegrityError:
messagebox.showwarning("Warning", "This component is already in the project!")
except Exception as e:
messagebox.showerror("Error", f"Failed to add component: {str(e)}")
def remove_component_from_project(self):
"""Remove a component from the current project"""
selection = self.project_components_tree.selection()
if not selection:
messagebox.showwarning("Warning", "Please select a component to remove!")
return
item = self.project_components_tree.item(selection[0])
component_id = item['values'][0]
if not messagebox.askyesno("Confirm Remove",
"Remove this component from the project? Associated answers will also be removed."):
return
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
# Delete answers for questions related to this component
cursor.execute('''
DELETE FROM project_answers
WHERE project_id = ? AND question_id IN (
SELECT id FROM design_questions WHERE component_id = ?
)
''', (self.current_project_id, component_id))
# Delete the component from project
cursor.execute(
"DELETE FROM project_components WHERE project_id = ? AND component_id = ?",
(self.current_project_id, component_id)
)
conn.commit()
conn.close()
self.refresh_project_components()
self.refresh_project_questions()
messagebox.showinfo("Success", "Component removed from project!")
except Exception as e:
messagebox.showerror("Error", f"Failed to remove component: {str(e)}")
def refresh_project_questions(self):
"""Refresh the project questions and answers list"""
# Clear existing items
for item in self.project_qa_tree.get_children():
self.project_qa_tree.delete(item)
if not hasattr(self, 'current_project_id'):
return
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
# Get filter value
filter_component = self.qa_filter_var.get() if hasattr(self, 'qa_filter_var') else "All"
if filter_component == "All":
cursor.execute('''
SELECT dq.id, ac.component_name, dq.question_text,
pa.answer_text, pa.answered_by
FROM design_questions dq
JOIN azure_components ac ON dq.component_id = ac.id
JOIN project_components pc ON pc.component_id = ac.id
LEFT JOIN project_answers pa ON pa.question_id = dq.id AND pa.project_id = ?
WHERE pc.project_id = ?
ORDER BY ac.component_name, dq.priority DESC, dq.created_at
''', (self.current_project_id, self.current_project_id))
else:
cursor.execute('''
SELECT dq.id, ac.component_name, dq.question_text,
pa.answer_text, pa.answered_by
FROM design_questions dq
JOIN azure_components ac ON dq.component_id = ac.id