Esempio n. 1
0
 def see_whats_needed(self):
     for dkt in self.place_dicts:
         if len(dkt["id"]) == 0:
             self.new_places = True
         elif len(dkt["id"]) > 0:
             if dkt.get("temp_id") is not None:
                 self.new_places = True
             elif len(dkt["id"]) > 1 and dkt["inner_dupe"] is False:
                 self.outer_duplicates = True
             elif len(dkt["id"]) > 1 and dkt["inner_dupe"] is True:
                 self.inner_duplicates = True
             elif len(dkt["id"]) == 1:
                 pass
             else:
                 print("line",
                       looky(seeline()).lineno, "case not handled",
                       dkt['id'])
         else:
             print("line", looky(seeline()).lineno, "case not handled")
     if self.new_places is True:
         self.make_new_places()
     if self.inner_duplicates is True:
         self.handle_inner_duplicates()
     if self.outer_duplicates is True:
         self.handle_outer_duplicates()
Esempio n. 2
0
def do_place_update(right_nest, finding):
    print("line",
          looky(seeline()).lineno, "right_nest, finding:", right_nest, finding)
    conn = sqlite3.connect(current_file)
    cur = conn.cursor()
    cur.execute(update_finding_nested_places, (right_nest, finding))
    conn.commit()
    cur.close()
    conn.close()
Esempio n. 3
0
 def test_for_new_plus_known():
     new = 0
     known = 0
     z = 0
     for dkt in self.place_dicts:
         if len(dkt["id"]) > 1:
             return
         elif len(dkt["id"]) == 1 and dkt.get("temp_id") is None:
             known += 1
         elif len(dkt["id"]) == 1 and dkt.get("temp_id") is not None:
             known += 1
             new += 1
         elif len(dkt["id"]) == 0 and dkt.get("temp_id") is None:
             print("line", looky(seeline()).lineno, "case not handled")
         elif len(dkt["id"]) == 0 and dkt.get("temp_id") is not None:
             new += 1
         else:
             print("line", looky(seeline()).lineno, "case not handled")
         z += 1
     if new == 0 and known == 0:
         self.open_dialog = False
Esempio n. 4
0
 def collect_place_ids(self):
     print("line",
           looky(seeline()).lineno, "self.place_dicts", self.place_dicts)
     ids = []
     r = 0
     for dkt in self.place_dicts:
         new_id = None
         if len(dkt["id"]) == 0:
             if dkt.get("temp_id") is None:
                 print("line",
                       looky(seeline()).lineno, "something is wrong")
                 return
             else:
                 new_id = dkt["temp_id"]
         elif len(dkt["id"]) > 1:
             print("line",
                   looky(seeline()).lineno, "there are still duplicates")
         elif len(dkt["id"]) == 1:
             if dkt.get("temp_id") is None:
                 print("line",
                       looky(seeline()).lineno,
                       "place is already in database")
                 new_id = dkt["id"][0]
             elif dkt.get("temp_id") is not None:
                 new_id = self.new_place_dialog.radvars[r].get()
             else:
                 print("line", looky(seeline()).lineno, "case not handled")
         else:
             print("line", looky(seeline()).lineno, "case not handled")
         ids.append(new_id)
         print("line", looky(seeline()).lineno, "ids:", ids)
         print("line",
               looky(seeline()).lineno,
               "self.new_place_dialog.radvars[r].get():",
               self.new_place_dialog.radvars[r].get())
         r += 1
Esempio n. 5
0
    def show_choices(self):
        conn = sqlite3.connect(current_file)
        cur = conn.cursor()

        self.radvars = []
        for dd in self.place_dicts:
            self.var = tk.IntVar(None, 0)
            self.radvars.append(self.var)

        d = 0
        t = 0
        bullet = len(self.place_dicts)
        # configure place_id for query
        for dkt in self.place_dicts:
            add_new_place_option = False
            place_hints = []
            if len(dkt["id"]) == 1:
                if dkt.get("temp_id") is None:
                    place_id = (dkt["id"][0], )
                else:
                    place_id = (dkt["id"][0])
                    add_new_place_option = True
            elif len(dkt["id"]) > 1:
                if dkt.get("temp_id") is not None:
                    add_new_place_option = True
                place_id = dkt["id"]
            elif dkt.get("temp_id") is None:
                place_id = ("none", )
            elif dkt.get("temp_id"):
                # place id will be int type which marks it as a new place
                place_id = dkt["temp_id"]
            else:
                print("line", looky(seeline()).lineno, "case not handled")
            if type(place_id) is int:
                place_hints.append('')
            else:
                for num in place_id:
                    if num == "none":
                        place_hints.append('')
                    else:
                        cur.execute(select_place_hint, (num, ))
                        place_hint = cur.fetchone()
                        if place_hint[0] is None:
                            place_hint = ''
                        else:
                            place_hint = place_hint[0]
                        place_hints.append(place_hint)
            # reconfigure place_id for display
            if type(place_id) is int:
                if dkt["temp_id"] is not None and len(dkt["id"]) > 0:
                    place_hints.append('')
            elif add_new_place_option is True:
                place_hints.append('')
            elif len(place_id) == 1:
                place_id = place_id[0]
            else:
                print("line", looky(seeline()).lineno, "case not handled")
            place_input = dkt["input"]
            place_string = '{}: {}, place ID #{}'.format(
                bullet, place_input, place_id)

            lab = Label(self.frm, text=place_string)
            lab.grid(column=0, row=d, sticky='w')

            self.hint_frm = Frame(self.frm, name="nest{}".format(bullet - 1))
            self.hint_frm.grid(column=0,
                               row=d + 1,
                               sticky='w',
                               padx=(0, 3),
                               columnspan=2)
            self.hint_frm.columnconfigure(0, minsize=48)

            self.make_edit_row(self.hint_frm)

            h = 0
            row = 0
            for hint in place_hints:
                if dkt.get("temp_id") is not None and len(dkt["id"]) > 0:
                    # user will choose between a new ID or one of the existing IDs
                    new_id = dkt["temp_id"]
                    last_idx = len(dkt["id"])
                    if h == last_idx:
                        current_id = new_id
                        rad_string = "{}: {} (new place and new place ID)".format(
                            current_id, dkt["input"])
                    else:
                        current_id = dkt["id"][h]
                        cur.execute(select_first_nested_place, (current_id, ))
                        nesting = cur.fetchone()
                        nesting = [i for i in nesting if i]
                        nesting = ", ".join(nesting)
                        rad_string = "{}: {}".format(current_id, nesting)
                elif dkt.get("temp_id") is not None and len(dkt["id"]) == 0:
                    # user will OK or CANCEL new ID
                    current_id = dkt["temp_id"]
                    rad_string = "{}: {} (new place and new place ID)".format(
                        current_id, dkt["input"])
                else:
                    current_id = dkt["id"][h]
                    cur.execute(select_first_nested_place, (current_id, ))
                    nesting = cur.fetchone()
                    nesting = [i for i in nesting if i]
                    nesting = ", ".join(nesting)
                    rad_string = "{}: {}".format(current_id, nesting)
                rad = RadiobuttonBig(self.hint_frm,
                                     variable=self.radvars[t],
                                     value=h,
                                     text=rad_string,
                                     anchor="w")
                lab = Label(self.hint_frm,
                            text="hint: {}".format(hint),
                            anchor='w',
                            bg='red')
                editx = ButtonQuiet(
                    self.hint_frm,
                    width=2,
                    command=lambda hint=hint: self.grid_edit_row(hint))

                self.hint_frm.columnconfigure(1, weight=1)
                rad.grid(column=0, row=row, sticky='we', columnspan=2)
                editx.grid(column=0, row=row + 1, pady=(0, 3), sticky='e')
                lab.grid(column=1, row=row + 1, sticky='w', padx=6)

                editx.bind('<Enter>', self.on_hover)
                editx.bind('<Leave>', self.on_unhover)
                editx.bind('<Button-1>', self.get_clicked_row)
                editx.bind('<space>', self.get_clicked_row)
                editx.bind('<FocusIn>', self.on_hover)
                editx.bind('<FocusOut>', self.on_unhover)
                h += 1
                row += 2

            sep = Separator(self.frm, 3)
            sep.grid(column=0,
                     row=d + 2,
                     sticky='ew',
                     columnspan=3,
                     pady=(3, 0))
            d += 3
            t += 1
            bullet -= 1

        cur.close()
        conn.close()