Post by Uncle Buddy on Nov 25, 2022 2:45:54 GMT -8
<drive>:\treebard_gps\app\python\assertions.py Last Changed 2022-11-08
# assertions.py
import tkinter as tk
import sqlite3
from widgets import (
Toplevel, Frame, Button, Label, RadiobuttonBig, LabelHeader, LabelH3,
Entry, Border, Scrollbar, open_message, MessageCopiable, Dialogue,
Separator, make_formats_dict, TabBook, Scale, LabelStay, EntryAuto,
ToolTip, create_tooltip, NEUTRAL_COLOR, LabelDots, LabelButtonText,
Checkbox, Combobox, EntryAutoHilited, Radiobutton)
from repositories import RepositoryDialog
from dates import get_date_formats, format_stored_date
from right_click_menu import RightClickMenu, make_rc_menus
from notes import NotesDialog
from toykinter_widgets import run_statusbar_tooltips
from scrolling import resize_scrolled_content
from files import get_current_file, global_db_path
from messages import assertions_msg
from query_strings import (
select_assertion_ids_by_finding, insert_event_type_new, delete_assertion,
select_role_type_by_id, select_assertion_description, insert_source_new,
select_links_links_assertions_notes, select_event_type_string, select_all_sources,
select_citation_string_source, select_all_event_types, update_assertion_surety,
update_assertion_unlink_finding, select_repo_id_by_name, select_locators_by_repo,
insert_repository_new, select_all_repository_strings, update_assertion_particulars,
update_assertion_age, update_assertion_date, update_assertion_place, update_assertion_role,
update_assertion_name, select_event_type_id_by_string, select_assertion_count_finding,
update_assertion_event_type, select_source_id_by_string, update_assertion_citation,
select_citations_per_source, insert_citation_new, delete_citation, delete_source,
insert_assertion_new_age, insert_assertion_new_date, insert_assertion_new_place,
insert_assertion_new_particulars, insert_assertion_new_role, insert_assertion_new_name,
select_assertion_no_finding, update_assertion_link_finding
)
import dev_tools as dt
from dev_tools import looky, seeline
INNER_DICT = {
"assertion_id": None,
"assertion": "",
"source": [None, ""],
"citation": [None, ""],
"notes": [],
"surety": [None, 3.0]}
ASSERTION_TABS = (
("add source", "+"), ("names", "U"), ("dates", "1"), ("places", "V"), ("particulars", "Y"),
("ages", "0"), ("roles", "2"), ("unlinked", "3")) # the other TabBook lists are in main.py
COLUMNS = (
"LINK", "ASSERTION", "EVENT TYPE", "SOURCE", "CITATION", "NOTES", "SURETY", "REPO")
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 findings 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."
class AssertionsTab(Frame):
def __init__(
self, master, root, treebard, conclusions_table, finding_id, main_tabs,
widg, current_person,
# person_autofill_values,
*args, **kwargs):
Frame.__init__(self, master, *args, **kwargs)
self.master = master
self.root = root
self.treebard = treebard
self.conclusions_table = conclusions_table
self.finding_id = finding_id
self.main_tabs = main_tabs
self.inwidg = widg
self.current_person = current_person
# self.person_autofill_values = person_autofill_values
self.formats = make_formats_dict()
event_types = get_all_event_types()
self.event_autofill_values = EntryAuto.create_lists(event_types)
self.assertions_data = {}
self.table_frames = {}
self.checkboxes = []
self.uncheckboxes = []
self.slidevars = {}
self.surety_widg = None
self.slidertip = 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.master, treebard=self.treebard)
tree = get_current_file()[0]
conn = sqlite3.connect(global_db_path)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
cur.execute("ATTACH ? AS tree", (tree,))
self.make_widgets(conn, cur)
sources = self.get_all_sources(conn, cur)
self.source_autofill_values = EntryAuto.create_lists(sources)
self.citations_by_source = {}
self.create_citations_dict(cur)
self.make_inputs(conn, cur)
# self.set_combo_values()
self.main_tabs.active = self.main_tabs.tabdict["assertions"][1]
self.main_tabs.make_active()
# scroll to top so controls are seen when tab opens
self.treebard.canvas.yview_moveto(0.0)
cur.execute("DETACH tree")
cur.close()
conn.close()
def make_widgets(self, conn, cur):
def ok():
self.save_surety_changes = True
self.unlink_finding_from_assertion()
self.update_surety_changes()
self.conclusions_table.redraw_assertions_tab(self.finding_id, widg=self.inwidg)
self.assertion_tabs = TabBook(
self, root=self.master, tabs=ASSERTION_TABS, selected="add source", side="sw",
minx=0.66, miny=0.35)
header = Frame(self)
lab1 = LabelHeader(
header,
text="To display assertions linked to a finding, click the SOURCES button at the end of that row in the conclusions table.",
justify='left', wraplength=400)
lab2 = LabelHeader(
header,
text="Linked assertions refer to finding ID #{}.\n\nDOUBLE-CLICK assertion to edit.".format(self.finding_id),
justify='left', wraplength=400)
b1 = Button(header, text="SAVE CHANGES", command=ok)
# children of self
header.grid(column=0, row=0, pady=12, padx=(12,0), sticky="ew")
self.assertion_tabs.grid(column=0, row=1, padx=12, pady=12)
# children of header
header.columnconfigure(1, weight=1)
lab1.grid(column=0, row=0, ipady=6, ipadx=6, sticky="w")
lab2.grid(column=1, row=0, ipady=6, ipadx=6, sticky="w", padx=12)
b1.grid(column=3, row=0, sticky='se', padx=(0,12))
def make_inputs(self, conn, cur):
inner_dict = dict(INNER_DICT)
cur.execute(select_assertion_ids_by_finding, (self.finding_id,))
self.assertion_details = cur.fetchall()
assertion_ids = [i[0] for i in self.assertion_details]
for k,v in self.assertion_tabs.store.items():
tab = k
v.columnconfigure(0, weight=1)
v.rowconfigure(0, weight=1)
frm = Frame(v)
frm.grid(column=0, row=0, sticky="news", padx=12, pady=12)
self.table_frames[tab] = frm
if tab != "add source":
for idx, stg in enumerate(COLUMNS):
head = LabelH3(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 = Separator(frm)
sep.grid(column=0, row=1, sticky="ew", columnspan=9)
self.assertions_data[k] = []
for k in self.assertions_data:
tab = k
inner_dict = self.make_assertions_dict(tab, inner_dict, cur)
for assertion_id in assertion_ids:
cur.execute(select_assertion_description, (assertion_id,))
self.assertion_description = cur.fetchone()
cur.execute(select_links_links_assertions_notes, (assertion_id,))
self.note_details = cur.fetchone()
for k in self.assertions_data:
tab = k
self.finish_assertions_dict(tab, cur)
for tab,v in self.assertions_data.items():
self.make_assertion_tables(v, tab)
self.make_unlinked_tab(cur)
add_to = []
for k,v in self.assertions_data.items():
if k not in ("add source", "unlinked") and len(v) != 0:
add_to.append(k)
self.assertion_tabs.add_star(add_to)
def make_new_assertion(self, inputs):
tree = get_current_file()[0]
conn = sqlite3.connect(global_db_path)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
cur.execute("ATTACH ? as tree", (tree,))
tab_text = inputs[0].get()
source_text = inputs[1].get()
citation_text = inputs[2].get()
assertion_text = inputs[3].get()
event_type_text = inputs[4].get()
couple_yes_no = inputs[5].get()
after_death_yes_no = inputs[6].get()
cur.execute(select_source_id_by_string, (source_text,))
result = cur.fetchone()
if result:
source_id = result[0]
else:
source_id = self.make_new_source(source_text, cur, conn)
self.citations_by_source[source_text] = {"citations": []}
citation_id = None
for tup in self.citations_by_source[source_text]["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
cur.execute(select_event_type_id_by_string, (event_type_text,))
result = cur.fetchone()
if result:
event_type_id = result[0]
else:
event_type_id = self.make_new_event_type(
event_type_text, couple_yes_no, after_death_yes_no, cur, conn)
self.update_db_new_assertion(
event_type_id, assertion_text, tab_text, citation_id, conn, cur)
self.conclusions_table.redraw_assertions_tab(self.finding_id, widg=self.inwidg)
self.get_quantity_linked_assertions(cur)
cur.execute("DETACH tree")
cur.close()
conn.close()
def get_quantity_linked_assertions(self, cur):
cur.execute(select_assertion_count_finding, (self.finding_id,))
result = cur.fetchone()
if result is not None:
qty = result[0]
else:
qty = 0
if self.inwidg:
self.inwidg.config(text=qty)
def update_db_new_assertion(
self, event_type_id, assertion_text, tab_text,
citation_id, conn, cur):
if tab_text == "NAMES":
cur.execute(
insert_assertion_new_name, (self.finding_id, citation_id,
event_type_id, assertion_text))
conn.commit()
elif tab_text == "DATES":
cur.execute(
insert_assertion_new_date, (self.finding_id, citation_id,
event_type_id, assertion_text))
conn.commit()
elif tab_text == "PLACES":
cur.execute(
insert_assertion_new_place, (self.finding_id, citation_id,
event_type_id, assertion_text))
conn.commit()
elif tab_text == "PARTICULARS":
cur.execute(
insert_assertion_new_particulars, (self.finding_id, citation_id,
event_type_id, assertion_text))
conn.commit()
elif tab_text == "AGES":
cur.execute(
insert_assertion_new_age, (self.finding_id, citation_id,
event_type_id, assertion_text))
conn.commit()
elif tab_text == "ROLES":
cur.execute(
insert_assertion_new_role, (self.finding_id, citation_id,
event_type_id, assertion_text))
conn.commit()
def make_new_event_type(self, event_type_text, couple_yes_no, after_death_yes_no, cur, conn):
cur.execute(insert_event_type_new, (event_type_text, couple_yes_no, after_death_yes_no))
conn.commit()
event_type_id = cur.lastrowid
return event_type_id
def make_new_source(self, source_text, cur, conn):
cur.execute(insert_source_new, (source_text,))
conn.commit()
source_id = cur.lastrowid
return source_id
def make_widgets_add_source_tab(self, tab):
def ok_new_assertion():
inputs = (
tab_input.entry, source_input, citation_input.entry,
assertion_input, event_type_input, self.couple_rad,
self.after_death_rad)
for widg in inputs[0:5]:
got = widg.get()
if len(got) == 0 or got == msg:
widg.insert(0, msg)
widg.focus_set()
return
self.make_new_assertion(inputs)
# clear()
def clear():
for widg in (
tab_input.entry, source_input, citation_input.entry,
assertion_input, event_type_input):
widg.delete(0, "end")
for var in self.couple_rad, self.after_death_rad:
var.set(0)
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(citations)
tree = get_current_file()[0]
conn = sqlite3.connect(global_db_path)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
cur.execute("ATTACH ? as tree", (tree,))
msg = "INPUT IS REQUIRED"
parent = self.table_frames[tab]
l1 = Label(parent, text="What the assertion is about:", anchor="e")
tab_input = Combobox(
parent, self.root,
values=[i[0].upper() for i in ASSERTION_TABS[1:]])
l2 = Label(parent, text="Source that makes this assertion:", anchor="e")
source_input = EntryAutoHilited(
parent,
autofill=True, values=self.source_autofill_values)
source_input.bind("<FocusOut>", config_citation_combo)
l3 = Label(parent, text="Citation within the source:", anchor="e")
citation_input = Combobox(parent, self.root)
citation_input.entry.config(width=54)
citation_input.config_drop_width(54)
l4 = Label(parent, text="The assertion is:", anchor="e")
assertion_input = EntryAutoHilited(parent)
l5 = Label(parent, text="Event type:", anchor="e")
event_type_input = EntryAutoHilited(
parent,
autofill=True, values=self.event_autofill_values)
radframe = Frame(parent)
l6 = Label(radframe, text="Couple event?")
self.couple_rad = tk.IntVar(None, 0)
couple_rad1 = Radiobutton(radframe, variable=self.couple_rad, value=1, text="yes")
couple_rad2 = Radiobutton(radframe, variable=self.couple_rad, value=0, text="no")
l7 = Label(radframe, text="After death event?")
self.after_death_rad = tk.IntVar(None, 0)
after_death_rad1 = Radiobutton(
radframe, variable=self.after_death_rad, value=1, text="yes")
after_death_rad2 = Radiobutton(
radframe, variable=self.after_death_rad, value=0, text="no")
buttonbox = Frame(parent)
ok = Button(
buttonbox, text="OK", command=ok_new_assertion, width=7)
clear_new_assertion = Button(
buttonbox, text="CLEAR", command=clear, width=7)
# children of self.table_frames[tab]
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))
citation_input.grid(column=1, row=2, sticky="w", pady=(0,6))
l4.grid(column=0, row=3, sticky="ew", padx=(0,6))
assertion_input.grid(column=1, row=3, sticky="ew", pady=(0,6))
l5.grid(column=0, row=4, sticky="ew", padx=(0,6))
event_type_input.grid(column=1, row=4, sticky="ew", pady=(0,6))
radframe.grid(column=1, row=5, sticky="w")
buttonbox.grid(column=1, row=6, sticky="e", pady=(6,12))
# children of radframe
l6.grid(column=0, row=0, sticky="e")
couple_rad1.grid(column=1, row=0)
couple_rad2.grid(column=2, row=0)
l7.grid(column=0, row=1, sticky="e")
after_death_rad1.grid(column=1, row=1)
after_death_rad2.grid(column=2, row=1)
# children of buttonbox
ok.grid(column=0, row=0)
clear_new_assertion.grid(column=1, row=0, padx=(6,0))
conn.commit()
cur.execute("DETACH tree")
cur.close()
conn.close()
def make_assertion_columns(self, col, tab, assertion_id, r, v):
if col == 0:
chk = Checkbox(self.table_frames[tab])
chk.grid(column=col, row=r+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, v, r)
elif col == 1:
lab = Label(
self.table_frames[tab], anchor="w",
wraplength=270, justify="left")
lab.grid(column=col, row=r+2, sticky="ew", padx=(0,18))
lab.bind(
"<Double-Button-1>",
lambda evt, assertion_id=assertion_id, tab=tab, row=r+2, column=col:self.edit_assertion(
evt, assertion_id, tab, row, column))
self.make_assertion_content(col, v, r, lab=lab)
elif col == 2:
lab = Label(self.table_frames[tab], anchor="w")
lab.grid(column=col, row=r+2, sticky="ew", padx=(0,18))
self.make_assertion_content(col, v, r, lab=lab)
elif col == 3:
lab = Label(self.table_frames[tab], anchor="w")
lab.grid(column=col, row=r+2, sticky="ew", padx=(0,18))
self.make_assertion_content(col, v, r, lab=lab)
elif col == 4:
lab = Label(
self.table_frames[tab], anchor="w",
wraplength=270, justify="left")
lab.grid(column=col, row=r+2, sticky="ew", padx=(0,18))
self.make_assertion_content(col, v, r, lab=lab)
elif col == 5:
dots = LabelDots(
self.table_frames[tab], NotesDialog, self.treebard,
current_person=self.current_person,
# person_autofill_values=self.person_autofill_values,
assertion_id=assertion_id, use_assertion_table=True)
dots.grid(
column=col, row=r+2, sticky='ew',
pady=(3,0), padx=(0,18))
assertion_id = v[r]["assertion_id"]
assertion = v[r]["assertion"]
dots.header = "Notes for {} Assertion ID #{}: {}".format(
tab.title(), assertion_id, assertion)
self.make_assertion_content(col, v, r, dots=dots)
elif col == 6:
slidevar = tk.DoubleVar()
slider = Scale(
self.table_frames[tab],
variable=slidevar,
length=66, sliderlength=20,
orient="horizontal", to=5.0, resolution=0.1, showvalue=0)
slider.bind("<Enter>", self.get_slider_motion, add="+")
slider.bind("<ButtonRelease-1>",
lambda evt, assertion_id=assertion_id: self.get_slider_value(
evt, assertion_id),
add="+")
slider.grid(column=col, row=r+2, padx=(0,18))
self.surety_text = surety = v[r]["surety"][1]
self.slider_opening_values[slider] = surety
self.surety_widg = slider
self.make_surety_tip()
self.make_assertion_content(col, v, r, slider=slider, surety=surety)
elif col == 7:
button = LabelButtonText(
self.table_frames[tab],
width=7,
anchor='w')
button.grid(column=col, row=r+2, sticky='w', pady=(3,0))
button.bind("<Enter>", self.add_text, add="+")
button.bind("<Leave>", self.unadd_text, add="+")
button.bind("<Button-1>",
lambda evt,
assertion_id=assertion_id,
tab=tab: self.open_repo_dialog(
evt, assertion_id, tab), add="+")
elif col == 8:
button = LabelButtonText(
self.table_frames[tab],
# width=7,
anchor='w')
button.grid(column=col, row=r+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):
tree = get_current_file()[0]
conn = sqlite3.connect(tree)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
cur.execute(delete_assertion, (assertion_id,))
conn.commit()
cur.close()
conn.close()
self.conclusions_table.redraw_assertions_tab(self.finding_id, widg=self.inwidg)
def make_assertion_content(
self, col, v, r, lab=None, dots=None, slider=None, surety=None):
if col == 2:
lab.config(text=v[r]["event_type"][1])
elif col == 1:
lab.config(text=v[r]["assertion"])
elif col == 3:
lab.config(text=v[r]["source"][1])
elif col == 4:
lab.config(text=v[r]["citation"][1])
elif col == 5:
text = " "
if len(v[r]["notes"][1]) != 0:
text = " ... "
dots.config(text=text)
elif col == 6:
slider.set(surety)
def make_assertion_tables(self, v, tab):
if tab == "add source":
self.make_widgets_add_source_tab(tab)
max_row = len(v)
for r in range(max_row):
assertion_id = v[r]["assertion_id"]
for col in range(8):
self.make_assertion_columns(col, tab, assertion_id, r, v)
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, event_type_id, citation_id, surety = self.assertion_description
cur.execute(select_event_type_string, (event_type_id,))
event_type = cur.fetchone()[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]["event_type"] = [event_type_id, event_type]
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(self, tab, inner_dict, cur):
results = []
for tup in self.assertion_details:
(assertion_id, name, date, place, particulars,
age, role) = list(tup)
if tab == "names" and len(name) != 0:
inner_dict["assertion_id"] = assertion_id
inner_dict["assertion"] = name
results.append(dict(inner_dict))
elif 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
return inner_dict
def get_slider_motion(self, evt):
evt.widget.config(command=self.show_surety)
self.surety_text = self.slider_opening_values[evt.widget]
def show_surety(self, surety):
self.surety_text = surety
self.label.config(text=surety)
def show_surety_tip(self):
maxvert = self.master.winfo_screenheight()
if self.slidertip or not self.surety_text:
return
x, y, cx, cy = self.surety_widg.bbox('insert')
self.slidertip = d_tip = Toplevel(self.surety_widg)
self.label = LabelStay(
d_tip,
text=self.surety_text,
justify='left',
relief='solid',
bd=1,
bg=NEUTRAL_COLOR, fg="white")
self.label.pack(ipadx=6, ipady=3)
mouse_at = self.master.winfo_pointerxy()
tip_shift = 48
if mouse_at[1] < maxvert - tip_shift * 2:
x = mouse_at[0] + tip_shift
y = mouse_at[1] + tip_shift
else:
x = mouse_at[0] + tip_shift
y = mouse_at[1] - tip_shift
d_tip.wm_overrideredirect(1)
d_tip.wm_geometry('+{}+{}'.format(x, y))
def off(self):
d_tip = self.slidertip
self.slidertip = None
if d_tip:
d_tip.destroy()
def make_surety_tip(self):
""" Runs once on widget construction. """
self.surety_widg.bind('<Enter>', self.handle_enter, add="+")
self.surety_widg.bind('<Leave>', self.on_leave, add="+")
def handle_enter(self, evt):
if self.surety_text:
self.show_surety_tip()
def on_leave(self, evt):
self.other_names = []
self.off()
self.slider_opening_values[evt.widget] = self.surety_text
def update_surety_changes(self):
tree = get_current_file()[0]
conn = sqlite3.connect(tree)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
if self.save_surety_changes is True:
for dkt in self.new_surety_values.values():
new_value = dkt["new_value"]
assertion_id = dkt["assertion_id"]
cur.execute(update_assertion_surety, (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_finding_from_assertion(self):
def unlink(tab, assertion_id):
cur.execute(update_assertion_unlink_finding, (assertion_id,))
conn.commit()
self.get_quantity_linked_assertions(cur)
def link(tab, assertion_id):
cur.execute(update_assertion_link_finding, (self.finding_id, assertion_id))
conn.commit()
self.get_quantity_linked_assertions(cur)
tree = get_current_file()[0]
conn = sqlite3.connect(tree)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
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 open_repo_dialog(self, evt, assertion_id, tab):
def loop_values(v):
for dkt in v:
if dkt["assertion_id"] == assertion_id:
source = dkt["source"][1]
citation = dkt["citation"][1]
assertion = dkt["assertion"]
repo_msg1 = "The citation which provided this {} assertion--'{}'--is '{}', from the source '{}'.".format(tab, assertion, citation, source)
return repo_msg1
for k,v in self.assertions_data.items():
if k == tab:
repo_msg1 = loop_values(v)
break
RepositoryDialog(self, self.root, self.treebard, assertion_id, tab, repo_msg1)
def get_all_sources(self, conn, cur):
cur.execute(select_all_sources)
return [i[0] for i in cur.fetchall()]
def edit_assertion(self, evt, assertion_id, tab, row, column):
def ok_edit():
final = edit_assertion_input.get()
proceed_edit(final)
widg.config(text=final)
edit_row.destroy()
def cancel_edit():
edit_row.destroy()
def proceed_edit(final):
conn = sqlite3.connect(tree)
conn.execute("PRAGMA foreign_keys = 1")
cur = conn.cursor()
if tab == "names":
cur.execute(update_assertion_name, (final, assertion_id))
conn.commit()
elif tab == "dates":
cur.execute(update_assertion_date, (final, assertion_id))
conn.commit()
elif tab == "places":
cur.execute(update_assertion_place, (final, assertion_id))
conn.commit()
elif tab == "particulars":
cur.execute(update_assertion_particulars, (final, assertion_id))
conn.commit()
elif tab == "ages":
cur.execute(update_assertion_age, (final, assertion_id))
conn.commit()
elif tab == "roles":
cur.execute(update_assertion_role, (final, assertion_id))
conn.commit()
cur.close()
conn.close()
tree = get_current_file()[0]
widg = evt.widget
original = widg.cget("text")
edit_row = Frame(self.table_frames[tab])
edit_row.grid(row=row, column=column)
edit_assertion_input = Entry(edit_row, width=48)
yes = Button(edit_row, text="OK", command=ok_edit)
no = Button(edit_row, text="CANCEL", command=cancel_edit)
edit_assertion_input.grid(column=0, row=0, sticky="w", padx=(0,6))
yes.grid(column=1, row=0, sticky="e", padx=(0,6))
no.grid(column=2, row=0, sticky="e")
edit_assertion_input.insert(0, original)
edit_assertion_input.focus_set()
def create_citations_dict(self, cur):
for source in self.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 = LabelH3(
self.table_frames["unlinked"], text="DELETE", anchor="w")
delete_head.grid(column=8, row=0, sticky="ew", padx=(18,0))
cur.execute(select_assertion_no_finding)
unlinked_assertions = cur.fetchall()
unlinked_dict = []
for assertion in unlinked_assertions:
inner_dict = {
"assertion_id": 0, "assertion": "", "source": [], "citation": [],
"notes": [], "surety": [], "event_type": []}
(assertion_id, citation_id, event_type_id, dates, places, particulars,
ages, names, 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(names) != 0:
assertion_text = names
elif len(roles) != 0:
assertion_text = roles
cur.execute(select_citation_string_source, (citation_id,))
citation_text, source_id, source_text = cur.fetchone()
cur.execute(select_event_type_string, (event_type_id,))
event_type_text = cur.fetchone()[0]
cur.execute(select_links_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_text]
inner_dict["citation"] = [citation_id, citation_text]
inner_dict["surety"] = [None, surety]
inner_dict["event_type"] = [event_type_id, event_type_text]
if note_details:
note_id, note = note_details
inner_dict["notes"] = [note_id, note]
else:
inner_dict["notes"] = [None, ""]
unlinked_dict.append(inner_dict)
max_row = len(unlinked_dict)
for r, dkt in enumerate(unlinked_dict):
assertion_id = dkt["assertion_id"]
for col in range(9):
self.make_assertion_columns(col, "unlinked", assertion_id, r, unlinked_dict)
def get_all_event_types():
conn = sqlite3.connect(global_db_path)
cur = conn.cursor()
cur.execute(select_all_event_types)
event_types = [i[0] for i in cur.fetchall()]
cur.close()
conn.close()
return event_types