def populate(self, data): self._data = data if data == None: # null check self.set_defaults() return for k, v in data.items(): if k == "name": # non-null self._nameLabel.config(text=v) elif k == "img": if v == None: # null check v = BaseView.DEFAULT_IMG utility.update_img(self._imgLabel, v, maxSize=300) elif k == "location": # non-null self._locPreview.populate(v) elif k == "description": if v == None: # null check v = BaseView.EMPTY_STR utility.update_text(self._descText, v) elif k == "notes": if v == None: # null check v = BaseView.EMPTY_STR utility.update_text(self._notesText, v) elif k == "sells": self._update_inventory()
def populate(self, data): self._data = data if data == None: # null check self.set_defaults() return for k, v in data.items(): if k == "img": if v == None: # null check v = BaseView.DEFAULT_IMG utility.update_img(self._imgLabel, v, maxSize=300) elif k == "name": # non-null self._nameLabel.config(text=v) elif k == "description": if v == None: # null check v = "" utility.update_text(self._descText, v) elif k == "notes": if v == None: # null check v = "" utility.update_text(self._notesText, v) elif k == "stores": if v == None: # null check v = [] utility.update_combobox(self._storeCombo, [store["name"] for store in v]) elif k == "creatures": if v == None: # null check v = [] utility.update_combobox( self._inhabitantCombo, [creature["creature"]["name"] for creature in v])
def set_defaults(self): utility.update_img(self._imgLabel, BaseView.DEFAULT_IMG, maxSize=300) utility.update_img(self._nameLabel, BaseView.RARITY_IMG[None], maxSize=30) utility.update_text(self._descText, BaseView.EMPTY_STR) utility.update_text(self._notesText, BaseView.EMPTY_STR) utility.update_combobox(self._equipCombo, []) utility.update_combobox(self._dropCombo, []) utility.update_combobox(self._attacksCombo, []) utility.update_combobox(self._inhabitsCombo, [])
def _preview_inhabit(self, *args, **kwargs): # first reset all self._inhabitsPreview.set_defaults() utility.update_text(self._inhabitsNotes, BaseView.EMPTY_STR) # update with new values if self._data == None or self._inhabitsCombo.current() == -1: return newInhabits = self._data["inhabits"][self._inhabitsCombo.current()] if newInhabits != None: self._inhabitsPreview.populate(newInhabits["location"]) if newInhabits["notes"] != None: utility.update_text(self._inhabitsNotes, newInhabits["notes"])
def populate(self, data): self._data = data if data == None: # null check self.set_defaults() return for k, v in data.items(): if k == "name": # non-null self._nameLabel.config(text=v) elif k == "img": if v == None: # null check v = BaseView.DEFAULT_IMG utility.update_img(self._imgLabel, v, maxSize=300) elif k == "isSpell": # non-null utility.update_img(self._nameLabel, BaseView.WAND_IMG[v], maxSize=30) self._show_spell_fields(v) elif k == "description": if v == None: # null check v = BaseView.EMPTY_STR utility.update_text(self._descText, v) elif k == "notes": if v == None: # null check v = BaseView.EMPTY_STR utility.update_text(self._notesText, v) elif k == "dmg": if v == None: # null check v = BaseView.DEFAULT self._dmgLabel.config(text=AttackView.DMG.format(v)) elif k == "channel": if v == None: # null check v = BaseView.DEFAULT self._channelLabel.config(text=AttackView.CHANNEL.format(v)) elif k == "creatures": # non-null utility.update_combobox(self._creatureCombo, [creature["name"] for creature in v]) elif k == "weapons": # non-null utility.update_combobox(self._weaponCombo, [item["name"] for item in v]) elif k == "costs": # non-null utility.update_combobox(self._costCombo, [cost["item"]["name"] for cost in v])
def _preview_drop(self, *args, **kwargs): # first reset all self._dropPreview.set_defaults() self._dropChance.config( text=CreatureView.DROP_CHANCE.format(BaseView.DEFAULT)) utility.update_text(self._dropNotes, BaseView.EMPTY_STR) # update with new values if self._data == None or self._dropCombo.current() == -1: return newDrop = self._data["drops"][self._dropCombo.current()] if newDrop != None: self._dropPreview.populate(newDrop["item"]) if newDrop["dropChance"] != None: self._dropChance.config(text=CreatureView.DROP_CHANCE.format( newDrop["equipChance"])) if newDrop["notes"] != None: utility.update_text(self._dropNotes, newDrop["notes"])
def set_defaults(self): utility.update_img(self._imgLabel, BaseView.DEFAULT_IMG, maxSize=300) utility.update_text(self._descText, BaseView.EMPTY_STR) utility.update_text(self._notesText, BaseView.EMPTY_STR) utility.update_combobox(self._storeCombo, []) utility.update_combobox(self._inhabitantCombo, [])
def set_defaults(self): utility.update_img(self._imgLabel, BaseView.DEFAULT_IMG, maxSize=300) utility.update_text(self._descText, BaseView.EMPTY_STR) utility.update_text(self._notesText, BaseView.EMPTY_STR)
def populate(self, data): self._data = data if data == None: # null check self.set_defaults() return for k, v in data.items(): if k == "img": if v == None: # null check v = BaseView.DEFAULT_IMG utility.update_img(self._imgLabel, v, maxSize=300) elif k == "rarity": # null accepted utility.update_img(self._nameLabel, BaseView.RARITY_IMG[v], maxSize=30) elif k == "name": # non-null self._nameLabel.config(text=v) elif k == "description": if v == None: # null check v = "" utility.update_text(self._descText, v) elif k == "notes": if v == None: # null check v = "" utility.update_text(self._notesText, v) elif k == "hd": if v == None: # null check v = BaseView.DEFAULT self._hdLabel.config(text=CreatureView.HD_FMT.format(v)) elif k == "hp": if v == None: # null check v = BaseView.DEFAULT self._hpLabel.config(text=CreatureView.HP_FMT.format(v)) elif k == "ac": if v == None: # null check v = BaseView.DEFAULT self._acLabel.config(text=CreatureView.AC_FMT.format(v)) elif k == "xp": if v == None: # null check v = BaseView.DEFAULT self._xpLabel.config(text=CreatureView.XP_FMT.format(v)) elif k == "basicAttack": if v == None: # null check v = BaseView.DEFAULT self._basicAttack.config( text=CreatureView.BASIC_ATTACK.format(v)) elif k == "equips": if v == None: # null check v = [] utility.update_combobox(self._equipCombo, [equip["item"]["name"] for equip in v]) elif k == "drops": if v == None: # null check v = [] utility.update_combobox(self._dropCombo, [drop["item"]["name"] for drop in v]) elif k == "attacks": if v == None: # null check v = [] utility.update_combobox(self._attacksCombo, [attack["name"] for attack in v]) elif k == "inhabits": if v == None: # null check v = [] utility.update_combobox(self._inhabitsCombo, [loc["location"]["name"] for loc in v])
def populate(self, data): self._data = data if data == None: # null check self.set_defaults() return # forget conditional fields self._weaponFrame.grid_forget() self._armorFrame.grid_forget() self._consumableFrame.grid_forget() for k, v in data.items(): if k == "name": # non-null self._nameLabel.config(text=v) elif k == "img": if v == None: # null check v = BaseView.DEFAULT_IMG utility.update_img(self._imgLabel, v, maxSize=300) elif k == "rarity": # null accepted utility.update_img(self._nameLabel, BaseView.RARITY_IMG[v], maxSize=30) elif k == "description": if v == None: # null check v = BaseView.EMPTY_STR utility.update_text(self._descText, v) elif k == "notes": if v == None: # null check v = BaseView.EMPTY_STR utility.update_text(self._notesText, v) elif k == "type": # non-null if v == 1: self._consumableFrame.grid(row=6, column=0, columnspan=5, sticky=W + E) elif v == 2: self._armorFrame.grid(row=6, column=0, columnspan=5, sticky=W + E) elif v == 3: self._weaponFrame.grid(row=6, column=0, columnspan=5, sticky=W + E) elif k == "value": if v == None: # null check v = BaseView.DEFAULT self._valLabel.config(text=v) elif k == "ac": if v == None: # null check v = BaseView.DEFAULT self._acLabel.config(text=ItemView.AC.format(v)) elif k == "slot": if v == None: # null check v = BaseView.DEFAULT self._armorSlot.config(text=ItemView.SLOT.format(v)) self._weaponSlot.config(text=ItemView.SLOT.format(v)) elif k == "dmg": if v == None: # null check v = BaseView.DEFAULT self._weaponDmg.config(text=ItemView.DMG.format(v)) elif k == "crit": if v == None: # null check v = BaseView.DEFAULT self._weaponCrit.config(text=ItemView.CRIT.format(v)) elif k == "ammo": # null accepted self._weaponAmmoPreview.populate(v) elif k == "range": if v == None: # null check v = BaseView.DEFAULT self._weaponRange.config(text=ItemView.RANGE.format(v)) elif k == "effect": if v == None: # null check v = BaseView.EMPTY_STR utility.update_text(self._effectText, v) elif k == "equippedBy": # non-null utility.update_combobox( self._equipCombo, [creature["creature"]["name"] for creature in v]) elif k == "droppedBy": # non-null utility.update_combobox( self._dropCombo, [creature["creature"]["name"] for creature in v]) elif k == "ammoFor": # non-null utility.update_combobox(self._ammoCombo, [item["name"] for item in v]) elif k == "spellCost": # non-null utility.update_combobox( self._spellCombo, [spell["spell"]["name"] for spell in v]) elif k == "soldAt": # non-null utility.update_combobox(self._soldAtCombo, [ "{} ({})".format(store["store"]["name"], store["store"]["location"]) for store in v ]) elif k == "attacks": # non-null utility.update_combobox(self._weaponAttackCombo, [attack["name"] for attack in v])