assertions.py
Nov 25, 2022 2:45:54 GMT -8
Post by Uncle Buddy on Nov 25, 2022 2:45:54 GMT -8
<drive>:\treebard\assertions.py Last Changed 2024-07-25
# assertions.py
import tkinter as tk
import sqlite3
from base import resize_scrolled_content, tree_path, tbard_path
from widgets import (
run_statusbar_tooltips, LabelDots, LabelButtonText, Checkbox, RightClickMenu,
configall, make_formats_dict, EntryAuto, EntryAutoSource, EntryAutoEventType,
Combobox, ScrolledDialog, open_message, Separator,
get_color_scheme_id, TabBook, make_rc_menus, Scaler)
from notes import NotesDialog
from unigeds_queries import (
select_assertion_ids_by_event, delete_assertion, update_assertion_name,
select_assertion_description, select_notes_links_assertions_notes,
select_citation_string_source, update_assertion_link_name,
update_assertion_unlink_event, select_source_id_by_string,
update_assertion_particulars, update_assertion_role,
update_assertion_age, update_assertion_date, update_assertion_place,
select_citations_per_source, insert_citation_new, insert_source_type,
insert_assertion_new_age, insert_assertion_new_date,
insert_assertion_new_particulars, insert_assertion_new_role,
insert_assertion_new_name, select_assertion_count_event,
select_assertion_no_event, update_assertion_link_event,
update_assertion_unlink_name, select_assertion_no_name,
select_assertion_ids_by_name, select_assertion_count_name,
select_all_source_types, insert_source_type_by_id, select_source_type_id,
insert_assertion_new_place)
import dev_tools as dt
from dev_tools import look, seeline
INNER_DICT = {
"assertion_id": None,
"assertion": "",
"source": [None, ""],
"citation": [None, ""],
"notes": [],
"surety": [None, 3.0]}
# the other TabBook lists are in main.py and root module
event_tabs = (
("dates", "D"), ("places", "L"),
("particulars", "P"), ("ages", "A"), ("roles", "R"), ("unlinked", "U"))
name_tabs = (("names", "N"), ("unlinked", "U"))
COLUMNS = (
"LINK", "ASSERTION", "SOURCE", "CITATION", "NOTES", "SURETY")
rcm_msg = "Each row of the conclusions table on the current person tab has a source button that you can press to open this dialog. Each value in the events row that you clicked has a corresponding tab in this dialog where you can view prior assertions that support these conclusions. You can also add more citations and sources here to back up conclusions on the table. You can also enter assertions on the assertions tab without linking them to any conclusion yet. There's also a conclusion table in the names tab."
def delete_current_source(evt):
pass
class AssertionsDialog(ScrolledDialog):
def __init__(
self, master, treebard, origin_table, widg, event_id=None,
name_id=None, position=None, *args, **kwargs):
ScrolledDialog.__init__(self, master, *args, **kwargs)
self.tree = master
self.treebard = treebard
self.inwidg = widg
self.event_id = event_id
self.name_id = name_id
self.position = position
if self.position:
self.geometry(self.position)
if self.event_id:
self.tree.open_assertions_dialogs_tracker[
"event_ids"][self.event_id] = self
assertion_type = "event ID"
element_id = self.event_id
self.tablist = event_tabs
self.selected = "dates"
self.conclusions_table = origin_table
elif self.name_id:
self.tree.open_assertions_dialogs_tracker[
"name_ids"][self.name_id] = self
assertion_type = "name ID"
element_id = self.name_id
self.tablist = name_tabs
self.names_table = origin_table
color_scheme_id = get_color_scheme_id(self.tree.tree_id)
self.formats = make_formats_dict(
self.tree.tree_id, color_scheme_id=color_scheme_id)
self.title(f"Linked assertions refer to {assertion_type} #{element_id}.")
self.assertions_data = {}
self.table_frames = {}
self.checkboxes = []
self.uncheckboxes = []
self.slidevars = {}
self.surety_widg = None
self.surety_text = None
self.slider_opening_values = {}
self.save_surety_changes = False
self.new_surety_values = {}
self.original = ["", ""]
self.rc_menu = RightClickMenu(self.tree, self.treebard)
conn = sqlite3.connect(self.tree.file)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
# Keep it small till the widgets are colorized:
self.geometry("0x0+0+0")
self.make_widgets(conn, cur)
EntryAutoEventType.create_lists()
self.tree.create_source_lists(cur=cur)
self.citations_by_source = {}
self.create_citations_dict(cur)
self.make_inputs(conn, cur)
self.make_edit_overlay()
self.focus_set()
ScrolledDialog.bind_canvas_to_mousewheel(self.canvas)
cur.close()
conn.close()
configall(self, self.formats)
TabBook.resize_scrolled_dialog_with_tabbook(
self, self.canvas, self.window)
def make_widgets(self, conn, cur):
def ok():
self.save_surety_changes = True
self.unlink_event_from_assertion()
self.update_surety_changes()
if self.event_id:
self.conclusions_table.open_assertions_dialog(
event_id=self.event_id, widg=self.inwidg)
elif self.name_id:
self.names_table.open_assertions_dialog(
name_id=self.name_id, widg=self.inwidg)
self.protocol("WM_DELETE_WINDOW", self.close_dlg)
self.header = tk.Frame(self.window)
self.assertion_tabs = TabBook(
self.window, self.formats, dialog=self,
tabs=self.tablist, side="sw",
minx=0.45, miny=0.35)
buttons = tk.Frame(self.window)
b1 = tk.Button(buttons, text="SAVE CHANGES", command=ok)
b2 = tk.Button(buttons, text="CLOSE", command=self.close_dlg)
# children of self.window
self.header.grid(column=0, row=0, pady=12, padx=12, sticky="ew")
self.assertion_tabs.grid(column=0, row=1, padx=12, pady=(12,0))
buttons.grid(column=0, row=2, padx=12, pady=12, sticky="e")
# children of buttons
b1.grid(column=0, row=0, sticky='e')
b2.grid(column=1, row=0, sticky='e', padx=(6,0))
def make_inputs(self, conn, cur):
inner_dict = dict(INNER_DICT)
if self.event_id:
cur.execute(select_assertion_ids_by_event, (self.event_id,))
elif self.name_id:
cur.execute(select_assertion_ids_by_name, (self.name_id,))
self.assertion_details = cur.fetchall()
assertion_ids = [i[0] for i in self.assertion_details]
for tab, frame in self.assertion_tabs.store.items():
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
frm = tk.Frame(frame)
frm.grid(column=0, row=0, sticky="news", padx=12, pady=12)
self.table_frames[tab] = frm
for idx, stg in enumerate(COLUMNS):
head = tk.Label(frm, text=stg, anchor="w")
if idx < 7:
head.grid(column=idx, row=0, sticky="ew", padx=(0,18))
elif idx == 7:
head.grid(column=idx, row=0, sticky="ew")
sep = tk.Frame(frm, height=2)
sep.grid(column=0, row=1, sticky="ew", columnspan=9)
self.assertions_data[tab] = []
for x in self.assertions_data:
if self.event_id:
self.make_assertions_dict_event(x, inner_dict, cur)
elif self.name_id:
self.make_assertions_dict_name(x, inner_dict, cur)
for assertion_id in assertion_ids:
cur.execute(select_assertion_description, (assertion_id,))
self.assertion_description = list(cur.fetchone())
cur.execute(
''' SELECT surety
FROM traits_tbd
WHERE assertion_id = ?
''',
(assertion_id,))
surety = cur.fetchone()
if surety:
surety = surety[0]
self.assertion_description.append(surety)
cur.execute(select_notes_links_assertions_notes, (assertion_id,))
self.note_details = cur.fetchone()
for z in self.assertions_data:
self.finish_assertions_dict(z, cur)
self.make_add_source_widgets()
for tab, lst in self.assertions_data.items():
self.make_assertion_tables(lst, tab)
self.make_unlinked_tab(cur)
add_to = []
for tab,lst in self.assertions_data.items():
if tab != "unlinked" and len(lst) != 0:
add_to.append(tab)
self.assertion_tabs.add_star(add_to)
def make_edit_overlay(self):
self.assertion_edit_overlay = tk.Frame(self)
self.edit_assertion_input = tk.Entry(
self.assertion_edit_overlay, width=48)
self.ok_edit_button = tk.Button(self.assertion_edit_overlay, text="OK")
self.cancel_edit_button = tk.Button(
self.assertion_edit_overlay, text="CANCEL")
self.edit_assertion_input.grid(column=0, row=0, sticky="w", padx=(0,6))
self.ok_edit_button.grid(column=1, row=0, sticky="e", padx=(0,6))
self.cancel_edit_button.grid(column=2, row=0, sticky="e")
def close_dlg(self):
self.position = f"+{self.geometry().split('+', 1)[1]}"
if self.event_id:
del self.tree.open_assertions_dialogs_tracker[
"event_ids"][self.event_id]
elif self.name_id:
del self.tree.open_assertions_dialogs_tracker[
"name_ids"][self.name_id]
del TabBook.related_tabbooks[self]
self.destroy()
return self.position
def make_new_source_type(self, source_type_text, cur, conn):
cur.execute(insert_source_type, (source_type_text,))
conn.commit()
return cur.lastrowid
def make_new_assertion(self, inputs):
conn = sqlite3.connect(self.tree.file)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
tab_text = inputs[0].get()
source_name = inputs[1].get()
citation_text = inputs[2].get()
assertion_text = inputs[3].get()
source_type_text = inputs[4].get()
cur.execute(select_source_id_by_string, (source_name,))
result = cur.fetchone()
if result:
source_id = result[0]
else:
cur.execute(select_source_type_id, (source_type_text,))
result = cur.fetchone()
if result:
source_type_id = result[0]
else:
source_type_id = self.make_new_source_type(source_type_text)
source_id = self.make_new_source(
source_name, source_type_id, cur, conn)
self.citations_by_source[source_name] = {"citations": []}
citation_id = None
for tup in self.citations_by_source[source_name]["citations"]:
if tup[1] == citation_text:
citation_id = tup[0]
break
if citation_id is None:
cur.execute(insert_citation_new, (citation_text, source_id))
conn.commit()
citation_id = cur.lastrowid
self.update_db_new_assertion(
assertion_text, tab_text, citation_id, conn, cur)
if self.event_id:
self.conclusions_table.open_assertions_dialog(
event_id=self.event_id, widg=self.inwidg)
elif self.name_id:
self.names_table.open_assertions_dialog(
name_id=self.name_id, widg=self.inwidg)
self.get_quantity_linked_assertions(cur)
cur.close()
conn.close()
def get_quantity_linked_assertions(self, cur):
qty = 0
if self.event_id:
cur.execute(select_assertion_count_event, (self.event_id,))
elif self.name_id:
cur.execute(select_assertion_count_name, (self.name_id,))
result = cur.fetchone()
if result:
qty = result[0]
if self.inwidg:
self.inwidg.config(text=qty)
def update_db_new_assertion(
self, assertion_text, tab_text, citation_id, conn, cur):
if tab_text == "NAMES":
cur.execute(
insert_assertion_new_name,
(self.name_id, citation_id, assertion_text))
conn.commit()
elif tab_text == "DATES":
cur.execute(
insert_assertion_new_date,
(self.event_id, citation_id, assertion_text))
conn.commit()
elif tab_text == "PLACES":
cur.execute(
insert_assertion_new_place,
(self.event_id, citation_id, assertion_text))
conn.commit()
elif tab_text == "PARTICULARS":
cur.execute(
insert_assertion_new_particulars,
(self.event_id, citation_id, assertion_text))
conn.commit()
elif tab_text == "AGES":
cur.execute(
insert_assertion_new_age,
(self.event_id, citation_id, assertion_text))
conn.commit()
elif tab_text == "ROLES":
cur.execute(
insert_assertion_new_role,
(self.event_id, citation_id, assertion_text))
conn.commit()
def make_new_source(self, source_name, source_type_id, cur, conn):
cur.execute(insert_source_type_by_id, (source_name, source_type_id))
conn.commit()
source_id = cur.lastrowid
return source_id
def make_add_source_widgets(self):
def ok_new_assertion():
inputs = (
tab_input.entry, source_input, citation_input.entry,
assertion_input, source_type_input.entry)
for widg in inputs:
got = widg.get()
if widg == source_type_input.entry:
user_source = source_input.get()
if user_source in self.tree.source_autofill_values:
widg.delete(0, "end")
elif user_source not in self.tree.source_autofill_values:
# New source and source type are made in the next method.
pass
elif widg.get() == msg:
widg.focus_set()
return
else:
source_input.insert(0, msg)
source_input.focus_set()
return
elif widg == assertion_input:
# Allow blank assertion.
pass
elif len(got) == 0 or got == msg:
widg.insert(0, msg)
widg.focus_set()
return
self.make_new_assertion(inputs)
def clear():
for widg in (
tab_input.entry, source_input, citation_input.entry,
assertion_input, source_type_input.entry):
widg.delete(0, "end")
def config_citation_combo(evt):
citations= []
widg = evt.widget
if len(widg.get()) == 0:
widg.insert(0, msg)
widg.focus_set()
return
for k,v in self.citations_by_source.items():
if k == source_input.get():
citations = [i[1] for i in v["citations"]]
break
citation_input.config_values(new_values=citations)
conn = sqlite3.connect(self.tree.file)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
msg = "INPUT IS REQUIRED"
l1 = tk.Label(
self.header, text="What the new assertion is about:", anchor="e")
tab_input = Combobox(
self.header, self.formats, tree=self.tree,
values=[i[0].upper() for i in self.tablist][0:-1])
l2 = tk.Label(
self.header, text="Source that makes this assertion:", anchor="e")
source_input = EntryAutoSource(
self.header, self.tree,
autofill=True, values=self.tree.source_autofill_values)
source_input.bind("<FocusOut>", config_citation_combo)
l3 = tk.Label(
self.header,
text="Source type (if new source is being added):", anchor="e")
cur.execute(select_all_source_types)
self.source_types = cur.fetchall()
source_type_input = Combobox(
self.header, self.formats, tree=self.tree,
values=[i[1] for i in self.source_types])
l4 = tk.Label(
self.header, text="Citation within the source:", anchor="e")
citation_input = Combobox(
self.header, self.formats, tree=self.tree)
l5 = tk.Label(self.header, text="The assertion is:", anchor="e")
assertion_input = EntryAuto(self.header)
buttonbox = tk.Frame(self.header)
ok = tk.Button(
buttonbox, text="OK", command=ok_new_assertion, width=7)
clear_new_assertion = tk.Button(
buttonbox, text="CLEAR", command=clear, width=7)
# children of self.header
self.header.columnconfigure(1, weight=1)
l1.grid(column=0, row=0, sticky="ew", padx=(0,6))
tab_input.grid(column=1, row=0, sticky="w", pady=(0,6))
l2.grid(column=0, row=1, sticky="ew", padx=(0,6))
source_input.grid(column=1, row=1, sticky="ew", pady=(0,6))
l3.grid(column=0, row=2, sticky="ew", padx=(0,6), pady=(0,6))
source_type_input.grid(column=1, row=2, sticky="w", pady=(0,6))
l4.grid(column=0, row=3, sticky="ew", padx=(0,6))
citation_input.grid(column=1, row=3, sticky="ew", pady=(0,6))
l5.grid(column=0, row=4, sticky="ew", padx=(0,6))
assertion_input.grid(column=1, row=4, sticky="ew", pady=(0,6))
buttonbox.grid(column=1, row=5, sticky="e", pady=(6,12))
# children of buttonbox
ok.grid(column=0, row=0)
clear_new_assertion.grid(column=1, row=0, padx=(6,0))
conn.commit()
cur.close()
conn.close()
def make_assertion_columns(self, col, tab, assertion_id, row, lst):
if col == 0:
chk = Checkbox(
self.table_frames[tab])
chk.grid(column=col, row=row+2, padx=(0,18), pady=3)
dkt = {"widget": chk, "tab": tab, "assertion_id": assertion_id}
if tab != "unlinked":
self.checkboxes.append(dkt)
chk.label.config(text="X")
else:
self.uncheckboxes.append(dkt)
self.make_assertion_content(col, lst, row)
elif col == 1:
lab = tk.Label(
self.table_frames[tab], anchor="w", cursor="hand2",
wraplength=270, justify="left")
lab.grid(column=col, row=row+2, sticky="ew", padx=(0,18))
lab.bind("<Double-Button-1>", lambda evt:
self.edit_assertion(evt, assertion_id=assertion_id, tab=tab))
self.make_assertion_content(col, lst, row, lab=lab)
elif col == 2:
lab = tk.Label(self.table_frames[tab], anchor="w")
lab.grid(column=col, row=row+2, sticky="ew", padx=(0,18))
self.make_assertion_content(col, lst, row, lab=lab)
elif col == 3:
lab = tk.Label(
self.table_frames[tab], anchor="w",
wraplength=270, justify="left")
lab.grid(column=col, row=row+2, sticky="ew", padx=(0,18))
self.make_assertion_content(col, lst, row, lab=lab)
elif col == 4:
dots = LabelDots(
self.table_frames[tab], self.tree, self.treebard, NotesDialog,
assertion_id=assertion_id, linked_element="assertion")
dots.grid(
column=col, row=row+2, sticky='ew', pady=(3,0), padx=(0,18))
assertion_id = lst[row]["assertion_id"]
assertion = lst[row]["assertion"]
dots.header = "Notes for {} Assertion ID #{}: {}".format(
tab.title(), assertion_id, assertion)
self.make_assertion_content(col, lst, row, dots=dots)
elif col == 5:
slider = Scaler(self.table_frames[tab], self.formats)
slider.grid(column=col, row=row+2, padx=(0,18))
slider.bind("<ButtonRelease-1>",
lambda evt, assertion_id=assertion_id: self.get_slider_value(
evt, assertion_id),
add="+")
self.surety_text = surety = lst[row]["surety"][1]
self.slider_opening_values[slider] = surety
self.surety_widg = slider
self.make_assertion_content(
col, lst, row, slider=slider, surety=surety)
elif col == 6:
button = LabelButtonText(
self.table_frames[tab],
anchor='w')
button.grid(column=col, row=row+2, sticky='w', pady=(3,0), padx=(18,0))
button.bind(
"<Button-1>",
lambda evt, assertion_id=assertion_id: self.delete_assertion(
evt, assertion_id))
def delete_assertion(self, evt, assertion_id):
conn = sqlite3.connect(self.tree.file)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
cur.execute(
''' DELETE FROM traits_tbd
WHERE assertion_id = ?
''',
(assertion_id,))
conn.commit()
cur.execute(delete_assertion, (assertion_id,))
conn.commit()
cur.close()
conn.close()
self.conclusions_table.open_assertions_dialog(
event_id=self.event_id, widg=self.inwidg)
def make_assertion_content(
self, col, v, r, lab=None, dots=None, slider=None, surety=None):
if col == 1:
lab.config(text=v[r]["assertion"])
elif col == 2:
lab.config(text=v[r]["source"][1])
elif col == 3:
lab.config(text=v[r]["citation"][1])
elif col == 4:
text = " "
if len(v[r]["notes"][1]) != 0:
text = " ... "
dots.config(text=text)
elif col == 5:
if surety is None:
surety = 3.0
slider.set(surety)
def make_assertion_tables(self, lst, tab):
max_row = len(lst)
for row in range(max_row):
assertion_id = lst[row]["assertion_id"]
for col in range(6):
# for col in range(7):
self.make_assertion_columns(col, tab, assertion_id, row, lst)
def add_text(self, evt):
evt.widget.config(text="OPEN")
def unadd_text(self, evt):
evt.widget.config(text="")
def finish_assertions_dict(self, tab, cur):
copy = self.assertions_data
for k,v in copy.items():
if k == tab:
assertion_id, citation_id, surety = self.assertion_description
if surety is None:
surety = 3.0
cur.execute(select_citation_string_source, (citation_id,))
citation, source_id, source = cur.fetchone()
for idx, dkt in enumerate(v):
if assertion_id == dkt["assertion_id"]:
self.assertions_data[tab][idx]["citation"] = [
citation_id, citation]
self.assertions_data[tab][idx]["source"] = [source_id, source]
self.assertions_data[tab][idx]["surety"] = [None, surety]
if self.note_details:
note_id, note = self.note_details
self.assertions_data[tab][idx]["notes"] = [note_id, note]
else:
self.assertions_data[tab][idx]["notes"] = [None, ""]
def make_assertions_dict_event(self, tab, inner_dict, cur):
results = []
for tup in self.assertion_details:
(assertion_id, date, place, particulars,
age, role) = list(tup)
if tab == "dates" and len(date) != 0:
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = date
results.append(dict(inner_dict))
elif tab == "places" and len(place) != 0:
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = place
results.append(dict(inner_dict))
elif tab == "particulars" and len(particulars) != 0:
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = particulars
results.append(dict(inner_dict))
elif tab == "ages" and len(age) != 0:
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = age
results.append(dict(inner_dict))
elif tab == "roles" and len(role) != 0:
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = role
results.append(dict(inner_dict))
else:
pass
self.assertions_data[tab] = results
def make_assertions_dict_name(self, tab, inner_dict, cur):
results = []
for tup in self.assertion_details:
assertion_id, name_assertion = tup
if tab == "names" and len(name_assertion) != 0:
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = name_assertion
results.append(dict(inner_dict))
else:
pass
self.assertions_data[tab] = results
def update_surety_changes(self):
conn = sqlite3.connect(self.tree.file)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
if self.save_surety_changes:
for dkt in self.new_surety_values.values():
new_value = dkt["new_value"]
assertion_id = dkt["assertion_id"]
cur.execute(
''' SELECT traits_tbd_id
FROM traits_tbd
WHERE assertion_id = ?
''',
(assertion_id,))
result = cur.fetchone()
if result:
cur.execute(
''' UPDATE traits_tbd
SET surety = ?
WHERE assertion_id = ?
''',
(new_value, assertion_id))
conn.commit()
else:
cur.execute(
''' INSERT INTO traits_tbd (surety, assertion_id)
VALUES (?, ?)
''',
(new_value, assertion_id))
conn.commit()
cur.close()
conn.close()
def get_slider_value(self, evt, assertion_id):
widg = evt.widget
new_value = widg.get()
self.new_surety_values[widg] = {"assertion_id": None, "new_value": None}
self.new_surety_values[widg]["assertion_id"] = assertion_id
self.new_surety_values[widg]["new_value"] = new_value
def unlink_event_from_assertion(self):
def unlink(tab, assertion_id):
cur.execute(unlink_query, (assertion_id,))
conn.commit()
self.get_quantity_linked_assertions(cur)
def link(tab, assertion_id):
cur.execute(link_query, (element_id, assertion_id))
conn.commit()
self.get_quantity_linked_assertions(cur)
conn = sqlite3.connect(self.tree.file)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
if self.event_id:
unlink_query = update_assertion_unlink_event
link_query = update_assertion_link_event
element_id = self.event_id
elif self.name_id:
unlink_query = update_assertion_unlink_name
link_query = update_assertion_link_name
element_id = self.name_id
for dkt in self.checkboxes:
widg = dkt["widget"]
assertion_id = dkt["assertion_id"]
tab = dkt["tab"]
if widg.label.cget("text") != "X":
unlink(tab, assertion_id)
for dkt in self.uncheckboxes:
widg = dkt["widget"]
assertion_id = dkt["assertion_id"]
tab = dkt["tab"]
if widg.label.cget("text") == "X":
link(tab, assertion_id)
cur.close()
conn.close()
def edit_assertion(self, evt, assertion_id, tab):
def ok_edit():
final_text = self.edit_assertion_input.get()
proceed_edit(final_text)
widg.config(text=final_text)
self.edit_assertion_input.delete(0, "end")
self.assertion_edit_overlay.grid_forget()
def cancel_edit():
self.edit_assertion_input.delete(0, "end")
self.assertion_edit_overlay.grid_forget()
def proceed_edit(final_text):
conn = sqlite3.connect(self.tree.file)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
if tab == "names":
cur.execute(update_assertion_name, (final_text, assertion_id))
conn.commit()
elif tab == "dates":
cur.execute(update_assertion_date, (final_text, assertion_id))
conn.commit()
elif tab == "places":
cur.execute(update_assertion_place, (final_text, assertion_id))
conn.commit()
elif tab == "particulars":
cur.execute(update_assertion_particulars, (final_text, assertion_id))
conn.commit()
elif tab == "ages":
cur.execute(update_assertion_age, (final_text, assertion_id))
conn.commit()
elif tab == "roles":
cur.execute(update_assertion_role, (final_text, assertion_id))
conn.commit()
cur.close()
conn.close()
self.ok_edit_button.config(command=ok_edit)
self.cancel_edit_button.config(command=cancel_edit)
widg = evt.widget
grid_info = widg.grid_info()
row = grid_info["row"]
column = grid_info["column"]
original = widg.cget("text")
self.assertion_edit_overlay.grid(
in_=self.table_frames[tab], column=column, row=row, columnspan=4,
sticky="ew")
self.edit_assertion_input.insert(0, original)
self.edit_assertion_input.focus_set()
def create_citations_dict(self, cur):
for source in self.tree.source_autofill_values:
inner_dict = {"citations": []}
self.citations_by_source[source] = inner_dict
cur.execute(select_citations_per_source, (source,))
results = cur.fetchall()
self.citations_by_source[source]["citations"] = results
def make_unlinked_tab(self, cur):
delete_head = tk.Label(
self.table_frames["unlinked"], text="DELETE", anchor="w")
delete_head.grid(column=7, row=0, sticky="ew", padx=(18,0))
if self.event_id:
cur.execute(select_assertion_no_event)
elif self.name_id:
cur.execute(select_assertion_no_name)
unlinked_assertions = [list(i) for i in cur.fetchall()]
for idx, lst in enumerate(list(unlinked_assertions)):
if len(lst) == 0:
continue
else:
cur.execute(
''' SELECT surety
FROM traits_tbd
WHERE assertion_id = ?
''',
(lst[0],))
surety = cur.fetchone()
if surety:
surety = surety[0]
lst.append(surety)
unlinked_assertions[idx] = lst
unlinked_dicts = []
for assertion in unlinked_assertions:
assertion_text = None
inner_dict = {
"assertion_id": 0, "assertion": "", "source": [], "citation": [],
"notes": [], "surety": []}
if self.event_id:
(assertion_id, citation_id, dates, places,
particulars, ages, roles, surety) = assertion
if len(dates) != 0:
assertion_text = dates
elif len(places) != 0:
assertion_text = places
elif len(particulars) != 0:
assertion_text = particulars
elif len(ages) != 0:
assertion_text = ages
elif len(roles) != 0:
assertion_text = roles
elif self.name_id:
(assertion_id, citation_id, names, surety) = assertion
if len(names) != 0:
assertion_text = names
if assertion_text is None:
continue
cur.execute(select_citation_string_source, (citation_id,))
citation_text, source_id, source_name = cur.fetchone()
cur.execute(select_notes_links_assertions_notes, (assertion_id,))
note_details = cur.fetchone()
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = assertion_text
inner_dict["source"] = [source_id, source_name]
inner_dict["citation"] = [citation_id, citation_text]
inner_dict["surety"] = [None, surety]
if note_details:
note_id, note = note_details
inner_dict["notes"] = [note_id, note]
else:
inner_dict["notes"] = [None, ""]
unlinked_dicts.append(inner_dict)
max_row = len(unlinked_dicts)
for row, dkt in enumerate(unlinked_dicts):
assertion_id = dkt["assertion_id"]
for col in range(7):
# for col in range(8):
self.make_assertion_columns(
col, "unlinked", assertion_id, row, unlinked_dicts)