def affix_to_str(affix): try: affix_return = db.get_affix_from_id(affix)[0][3] except IndexError: affix_return = 'Unknown Affix {}'.format(affix) query = "insert or ignore into unknown(id, type) values({0}, 'affix')".format(affix) db.instance_and_run(query) return affix_return
def safemode_toggle(self): if self.item_frame: if self.safemode.get() == 1: try: self.valid_values = [db.get_affix_from_id(x)[0][3] for x in self.entry['legal_affixes']] except KeyError: self.valid_values = [x[3] for x in db.get_affix_all()] print("Safemode ON!") else: self.valid_values = [x[3] for x in db.get_affix_all()] print("Safemode OFF!") self.load_item_frame(self.item_list_frame)
def load_item_frame(self, parent): if self.item_frame: self.item_frame.destroy() self.index = self.item_scrollbar.listbox.curselection()[0] self.entry = self.item_scrollbar.indexmap[self.index] self.item_main_frame = tk.Frame(parent) self.item_main_frame.grid(row=0, column=1, sticky='WN', rowspan=10) seframe = tk.Frame(self.item_main_frame) cb = tk.Checkbutton(seframe, text="Safe Edit Mode", variable=self.safemode, onvalue=1, offvalue=0, command=self.safemode_toggle) cb.grid(column=0, row=0, sticky='W') tl = tk.Label(seframe, text=' (Try to show only affixes that make sense)') tl.grid(column=1, row=0, sticky='W') seframe.grid(column=0, row=0, columnspan=2, sticky='WN') self.item_frame = tk.Frame(self.item_main_frame) self.item_frame.grid(row=1, column=0, sticky='WN') # INSIDE ABOVE FRAME if self.entry == 'No Item': addid = tk.StringVar(value='0') affixnum = tk.StringVar(value='0') lab = ttk.Label(self.item_frame, text="Add item with ID:") lab.grid(column=0, row=6) ent = ttk.Entry(self.item_frame, textvariable=addid) ent.grid(column=1, row=6) lab = ttk.Label(self.item_frame, text="Number of Affixes:") lab.grid(column=0, row=7) ent2 = ttk.Entry(self.item_frame, textvariable=affixnum) ent2.grid(column=1, row=7) sb = ttk.Button(self.item_frame, text="Add Item", command=lambda: self.additem(addid.get(), affixnum.get())) sb.grid(column=0, row=8) return row = 0 v = tk.StringVar() v.set(self.entry['name']) l = int(len(self.entry['name'])*0.9) e = tk.Entry(self.item_frame, readonlybackground='white', fg='black', textvariable=v, bd=0, width=l, state='readonly', highlightthickness=0) e.grid(row=row, sticky='W', columnspan=2) if self.safemode.get() == 1: try: self.valid_values = [db.get_affix_from_id(x)[0][3] for x in self.entry['legal_affixes']] except KeyError: self.valid_values = [x[3] for x in db.get_affix_all()] else: self.valid_values = [x[3] for x in db.get_affix_all()] category = self.entry['category'] quality = self.entry['item'].generator.item_quality_level row = row + 1 ttk.Label(self.item_frame, text=self.entry['slot']).grid(column=0, row=row, sticky='W') if (category == 'Gems') and (quality == 9): row = row + 1 ttk.Label(self.item_frame, text="Legendary Gem Level: ").grid(column=0, row=row) ttk.Entry(self.item_frame, textvariable=self.entry['jewel_rank']).grid(column=1, row=row) elif self.entry['stackable']: row = row + 1 ttk.Label(self.item_frame, text="Stack Size: ").grid(column=0, row=row) ttk.Entry(self.item_frame, textvariable=self.entry['stack_size']).grid(column=1, row=row) try: enchanted = self.entry['enchanted'] except KeyError: enchanted = False crow = row self.cbl = 30 for affix, description in self.entry['affixes']: ccbl = len(description.get()) * 0.85 if ccbl > self.cbl: self.cbl = int(ccbl) for affix, description in self.entry['affixes']: crow = crow + 1 if enchanted: # noinspection PyUnresolvedReferences if affix == enchanted[0][0]: ttk.Label(self.item_frame, text="Enchanted").grid(column=1, row=crow, sticky='NES') description = enchanted[1] cb = ttk.Combobox(self.item_frame, textvariable=description, width=self.cbl, values=self.valid_values, state='readonly') cb.grid(row=crow, sticky='W') cb.bind("<<ComboboxSelected>>", lambda x: self.set_item_affixes(x, row)) sb = ttk.Button(self.item_frame, text="Save Item", command=self.saveitem) sb.grid(column=0, row=98) delb = ttk.Button(self.item_frame, text="Delete Item", command=self.deleteitem) delb.grid(column=0, row=99)
def load_item_frame(self, parent): if self.item_frame: self.item_frame.destroy() self.index = self.item_scrollbar.listbox.curselection()[0] self.entry = self.item_scrollbar.indexmap[self.index] self.item_main_frame = tk.Frame(parent, bg='white') self.item_main_frame.grid(row=0, column=1, sticky='WN', rowspan=10) seframe = tk.Frame(self.item_main_frame, bg='white') cb = tk.Checkbutton(seframe, text="Safe Edit Mode", variable=self.safemode, onvalue=1, offvalue=0, command=self.safemode_toggle) cb.grid(column=0, row=0, sticky='W') tl = tk.Label(seframe, text=' (Try to show only affixes that make sense)') tl.grid(column=1, row=0, sticky='W') seframe.grid(column=0, row=0, columnspan=2, sticky='WN') self.item_frame = tk.Frame(self.item_main_frame, bg='white') self.item_frame.grid(row=1, column=0, sticky='WN') # INSIDE ABOVE FRAME if self.entry == 'No Item': self.item_frame = AddItemFrame(account=self.account, parent=self.item_main_frame, bg='white', stash=self.active_stash.get(), nb=self) self.item_frame.grid(column=0, row=1, sticky='WN') return row = 0 v = tk.StringVar() v.set(self.entry['name']) le = int(len(self.entry['name']) * 0.9) e = tk.Entry(self.item_frame, readonlybackground='white', fg='black', textvariable=v, bd=0, width=le, state='readonly', highlightthickness=0) e.grid(row=row, sticky='W', columnspan=2) if self.safemode.get() == 1: try: self.valid_values = [ db.get_affix_from_id(x)[0][3] for x in self.entry['legal_affixes'] ] except KeyError: self.valid_values = [x[3] for x in db.get_affix_all()] else: self.valid_values = [x[3] for x in db.get_affix_all()] category = self.entry['category'] row = row + 1 ttk.Label(self.item_frame, text=self.entry['slot']).grid(column=0, row=row, sticky='W') if category == 'Legendary Gems': row = row + 1 ttk.Label(self.item_frame, text="Legendary Gem Level: ").grid(column=0, row=row) ttk.Entry(self.item_frame, textvariable=self.entry['jewel_rank']).grid(column=1, row=row) elif self.entry['stackable']: row = row + 1 ttk.Label(self.item_frame, text="Stack Size: ").grid(column=0, row=row) ttk.Entry(self.item_frame, textvariable=self.entry['stack_size']).grid(column=1, row=row) try: enchanted = self.entry['enchanted'] except KeyError: enchanted = False crow = row self.cbs = [] for affix, description in self.entry['affixes']: crow = crow + 1 if enchanted: # noinspection PyUnresolvedReferences if affix == enchanted[0][0]: ttk.Label(self.item_frame, text="Enchanted").grid(column=1, row=crow, sticky='NES') description = enchanted[1] cb = ttk.Combobox(self.item_frame, textvariable=description, values=self.valid_values, state='readonly') cb.grid(row=crow, sticky='W') cb.bind("<<ComboboxSelected>>", lambda x: self.set_item_affixes(x, row)) self.cbs.append(cb) self.size_affix_combobox() if self.affixfilter.get(): self.update_affixes() button_frame = tk.Frame(self.item_frame, background='white') button_frame.grid(column=0, row=99, sticky='NW') if self.cbs: search = ttk.Entry(button_frame, textvariable=self.affixfilter) search.grid(column=1, row=0) search.bind("<KeyRelease>", self.update_affixes) search.bind("<space>", self.update_affixes) ttk.Label(button_frame, text="Affix Filter:").grid(column=0, row=0) sb = ttk.Button(button_frame, text="Save Item", command=self.saveitem) sb.grid(column=0, row=97) cb = ttk.Button( button_frame, text="Duplicate Item", command=lambda: self.additem(target_stash=self.active_stash.get(), affixnum=0, ids=0, item=self.entry['item'])) cb.grid(column=1, row=97) rb = ttk.Button(button_frame, text="Reroll Item", command=self.reroll_item) rb.grid(column=0, row=98) ttk.Label(button_frame, text="(generate new random seed)").grid(column=1, row=98) delb = ttk.Button(button_frame, text="Delete Item", command=self.deleteitem) delb.grid(column=0, row=99)