-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_dialogs.py
More file actions
242 lines (212 loc) · 11.8 KB
/
data_dialogs.py
File metadata and controls
242 lines (212 loc) · 11.8 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
# data_dialogs.py
# CV PDF Project
# Copyright 2025 pyrus-code
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
import json
import database as db
class EditSkillDialog(simpledialog.Dialog):
def __init__(self, parent, title, skill_data=None):
self.skill_data = skill_data or {}
super().__init__(parent, title)
def body(self, master):
self.title(self.skill_data.get('skill_name', 'New Skill'))
ttk.Label(master, text="Skill Name:").pack(anchor='w', padx=5)
self.name_var = tk.StringVar(value=self.skill_data.get('skill_name', ''))
def validate_length(P):
if len(P) > 40:
self.bell()
return False
return True
vcmd = (self.register(validate_length), '%P')
self.name_entry = ttk.Entry(master, textvariable=self.name_var, width=50, validate='key', validatecommand=vcmd)
self.name_entry.pack(fill='x', padx=5, pady=(0, 10))
return self.name_entry
def apply(self):
skill_name = self.name_var.get().strip()
if not skill_name:
messagebox.showerror("Input Required", "Skill Name cannot be empty.", parent=self)
self.result = None
return
self.result = {'skill_name': skill_name}
class EditItemDialog(tk.Toplevel):
def __init__(self, master, title, item_id, item_type, on_close_callback):
super().__init__(master)
self.item_id = item_id
self.item_type = item_type.lower().replace(' ', '_')
self.on_close_callback = on_close_callback
self.item_data = {}
if self.item_id:
all_data = db.load_all_data()
self.item_data = next(
(item for item in all_data.get(self.item_type, []) if item['id'] == int(self.item_id)), None)
self.title(title)
self.transient(master)
self.entries = {}
frame = ttk.Frame(self, padding="20")
frame.pack(fill="both", expand=True)
content_frame = ttk.Frame(frame)
content_frame.pack(fill="x", expand=True)
if self.item_type == 'education':
self.create_education_fields(content_frame)
elif self.item_type == 'software_skills':
self.create_software_skills_fields(content_frame)
else:
fields = {"languages": ["language", "proficiency", "details"]}
for i, field in enumerate(fields[self.item_type]):
ttk.Label(content_frame, text=f"{field.title()}:").grid(row=i, column=0, sticky="w", pady=5)
entry = ttk.Entry(content_frame, width=40)
if self.item_data: entry.insert(0, self.item_data.get(field, ''))
entry.grid(row=i, column=1, sticky="ew", padx=5, pady=2)
self.entries[field] = entry
ttk.Button(frame, text="Save", command=self.save).pack(pady=20)
self.protocol("WM_DELETE_WINDOW", self.destroy)
def create_software_skills_fields(self, frame):
fields = ["skill", "level", "comments"]
for i, field in enumerate(fields):
ttk.Label(frame, text=f"{field.title()}:").grid(row=i, column=0, sticky="w", pady=5)
entry = ttk.Entry(frame, width=40)
if self.item_data: entry.insert(0, self.item_data.get(field, ''))
if field == "comments":
def validate_length(P):
if len(P) > 50: self.bell(); return False
return True
vcmd = (self.register(validate_length), '%P')
entry.config(validate='key', validatecommand=vcmd)
entry.grid(row=i, column=1, sticky="ew", padx=5, pady=2)
self.entries[field] = entry
def create_education_fields(self, frame):
initial_type = self.item_data.get('type', 'Education') if self.item_data else 'Education'
self.type_var = tk.StringVar(value=initial_type)
ttk.Label(frame, text="Type:").grid(row=0, column=0, sticky="w", pady=5)
type_menu = ttk.OptionMenu(frame, self.type_var, self.type_var.get(), "Education", "Certification",
command=self.toggle_edu_fields)
type_menu.grid(row=0, column=1, sticky="ew")
self.edu_frame = ttk.Frame(frame)
self.edu_frame.grid(row=1, column=0, columnspan=2)
self.toggle_edu_fields()
def toggle_edu_fields(self, event=None):
for widget in self.edu_frame.winfo_children(): widget.destroy()
self.entries = {}
item_type = self.type_var.get()
fields = {"Certification": ["certification_name", "certification_description"],
"Education": ["description", "school", "dates"]}
for i, field in enumerate(fields[item_type]):
ttk.Label(self.edu_frame, text=f"{field.replace('_', ' ').title()}:").grid(row=i, column=0, sticky="w",
pady=5)
entry = ttk.Entry(self.edu_frame, width=40)
if self.item_data: entry.insert(0, self.item_data.get(field, ''))
entry.grid(row=i, column=1, sticky="ew", pady=5)
self.entries[field] = entry
def save(self):
new_data = {key: entry.get() for key, entry in self.entries.items()}
if self.item_type == 'education':
new_data['type'] = self.type_var.get()
query = "UPDATE education SET type = ?, data = ? WHERE id = ?" if self.item_id else "INSERT INTO education (type, data, order_index) VALUES (?, ?, (SELECT IFNULL(MAX(order_index), -1) + 1 FROM education))"
params = (new_data['type'], json.dumps(new_data), self.item_id) if self.item_id else (new_data['type'],
json.dumps(new_data))
elif self.item_type == 'languages':
query = "UPDATE languages SET language=?, proficiency=?, details=? WHERE id=?" if self.item_id else "INSERT INTO languages (language, proficiency, details, order_index) VALUES (?,?,?, (SELECT IFNULL(MAX(order_index), -1) + 1 FROM languages))"
params = (new_data.get('language'), new_data.get('proficiency'), new_data.get('details'),
self.item_id) if self.item_id else (new_data.get('language'), new_data.get('proficiency'),
new_data.get('details'))
elif self.item_type == 'software_skills':
query = "UPDATE software_skills SET skill=?, level=?, comments=? WHERE id=?" if self.item_id else "INSERT INTO software_skills (skill, level, comments, order_index) VALUES (?,?,?, (SELECT IFNULL(MAX(order_index), -1) + 1 FROM software_skills))"
params = (new_data.get('skill'), new_data.get('level'), new_data.get('comments', ''),
self.item_id) if self.item_id else (new_data.get('skill'), new_data.get('level'),
new_data.get('comments', ''))
db.execute_query(query, params)
self.on_close_callback()
self.destroy()
class EditJobDialog(tk.Toplevel):
def __init__(self, master, title, item_id, on_close_callback):
super().__init__(master)
self.item_id = item_id
self.on_close_callback = on_close_callback
self.item_data = {}
if self.item_id:
all_jobs = db.load_all_data().get('jobs', [])
self.item_data = next((job for job in all_jobs if job['id'] == int(self.item_id)), None)
self.title(title)
self.transient(master)
frame = ttk.Frame(self, padding="20")
frame.pack(fill="both", expand=True)
ttk.Label(frame, text="Job Title:").pack(anchor='w')
self.title_entry = ttk.Entry(frame, width=50)
self.title_entry.pack(fill='x', pady=(0, 5))
self.title_entry.insert(0, self.item_data.get('title', ''))
ttk.Label(frame, text="Company:").pack(anchor='w')
self.company_entry = ttk.Entry(frame, width=50)
self.company_entry.pack(fill='x', pady=(0, 5))
self.company_entry.insert(0, self.item_data.get('company', ''))
ttk.Label(frame, text="Dates:").pack(anchor='w')
self.dates_entry = ttk.Entry(frame, width=50)
self.dates_entry.pack(fill='x', pady=(0, 10))
self.dates_entry.insert(0, self.item_data.get('dates', ''))
ttk.Button(frame, text="Save", command=self.save).pack()
def save(self):
title = self.title_entry.get()
company = self.company_entry.get()
dates = self.dates_entry.get()
if not all([title, company, dates]): messagebox.showerror("Validation Error", "All fields are required.",
parent=self); return
if self.item_id:
query = "UPDATE jobs SET title=?, company=?, dates=? WHERE id=?"
params = (title, company, dates, self.item_id)
else:
query = "INSERT INTO jobs (title, company, dates, order_index) VALUES (?, ?, ?, (SELECT IFNULL(MAX(order_index), -1) + 1 FROM jobs))"
params = (title, company, dates)
db.execute_query(query, params)
self.on_close_callback()
self.destroy()
class EditStandardCVDialog(tk.Toplevel):
def __init__(self, master, title, on_close_callback, cv_data=None):
super().__init__(master)
self.on_close_callback = on_close_callback
self.cv_data = cv_data or {}
self.title(title)
self.geometry("700x600")
self.transient(master)
self.grab_set()
main_frame = ttk.Frame(self, padding="10")
main_frame.pack(fill="both", expand=True)
ttk.Label(main_frame, text="CV Version Name (e.g., 'Finance', 'Logistics'):").pack(anchor='w', padx=5)
self.name_var = tk.StringVar(value=self.cv_data.get('name', ''))
self.name_entry = ttk.Entry(main_frame, textvariable=self.name_var, width=50)
self.name_entry.pack(fill='x', padx=5, pady=(0, 10))
text_frame = ttk.LabelFrame(main_frame, text="CV Content (Formatted Experience)")
text_frame.pack(fill='both', expand=True, padx=5, pady=5)
self.text_widget = tk.Text(text_frame, wrap='word', undo=True, height=20)
self.text_widget.pack(fill='both', expand=True, padx=5, pady=5)
self.text_widget.insert('1.0', self.cv_data.get('content', ''))
button_frame = ttk.Frame(main_frame)
button_frame.pack(fill='x', side='bottom', pady=(10, 0))
ttk.Button(button_frame, text="Save", command=self.save).pack(side='right')
ttk.Button(button_frame, text="Cancel", command=self.destroy).pack(side='right', padx=5)
self.protocol("WM_DELETE_WINDOW", self.destroy)
self.name_entry.focus_set()
def save(self):
cv_name = self.name_var.get().strip()
if not cv_name:
messagebox.showerror("Input Required", "CV Version Name cannot be empty.", parent=self)
return
result = {
'id': self.cv_data.get('id'),
'name': cv_name,
'content': self.text_widget.get('1.0', 'end-1c')
}
db.save_standard_cv(result)
self.on_close_callback()
self.destroy()