def itemListboxSelect(self, event): listbox = event.widget choice = listbox.curselection() if len(choice) != 0: idx = choice[0] value = listbox.get(choice[0]) self.curSelectIdx = idx else: self.curSelectIdx = -1 if self.curSelectIdx == -1: return if self.curChosenType == 'Equip': equip = Equip(self.listboxList[self.curSelectIdx]) equip.setClean() self.descriptionContent.config(state=Tkinter.NORMAL) self.descriptionContent.delete('1.0', Tkinter.END) self.descriptionContent.insert('insert', equip.showEquip()) self.descriptionContent.config(state=Tkinter.DISABLED) self.marketInfoContent.config(state=Tkinter.NORMAL) self.marketInfoContent.delete('1.0', Tkinter.END) self.marketInfoContent.insert('insert', self.parent.m_marketInfo.showMarketInfo(equip.m_name, self.parent.m_inventory.m_etc)) self.marketInfoContent.config(state=Tkinter.DISABLED) elif self.curChosenType == 'Use': scrollName = self.listboxList[self.curSelectIdx] description = scrollName + '\n\n' description += 'Quantity in inventory: ' + EtcLib.dispLongNum(self.parent.m_inventory.m_use[scrollName]) + '\n\n' if self.curChosenCategory in ['Special', 'Hammer', 'Cube']: description += SpecialLib.m_lib[scrollName]['description'] self.descriptionContent.config(state=Tkinter.NORMAL) self.descriptionContent.delete('1.0', Tkinter.END) self.descriptionContent.insert('insert', description) self.descriptionContent.config(state=Tkinter.DISABLED) else: description += ScrollLib.showScrollStat(scrollName) self.descriptionContent.config(state=Tkinter.NORMAL) self.descriptionContent.delete('1.0', Tkinter.END) self.descriptionContent.insert('insert', description) self.descriptionContent.config(state=Tkinter.DISABLED) self.marketInfoContent.config(state=Tkinter.NORMAL) self.marketInfoContent.delete('1.0', Tkinter.END) self.marketInfoContent.insert('insert', self.parent.m_marketInfo.showMarketInfo(scrollName, self.parent.m_inventory.m_etc)) self.marketInfoContent.config(state=Tkinter.DISABLED) elif self.curChosenType == 'Etc': etcName = self.listboxList[self.curSelectIdx] description = etcName + '\n\n' description += 'Quantity in inventory: ' + EtcLib.dispLongNum(self.parent.m_inventory.m_etc[EtcLib.m_lib[etcName]['etc']]) + ' ' + EtcLib.m_lib[etcName]['etc'] +'\n\n' description += EtcLib.m_lib[etcName]['description'] self.descriptionContent.config(state=Tkinter.NORMAL) self.descriptionContent.delete('1.0', Tkinter.END) self.descriptionContent.insert('insert', description) self.descriptionContent.config(state=Tkinter.DISABLED) self.marketInfoContent.config(state=Tkinter.NORMAL) self.marketInfoContent.delete('1.0', Tkinter.END) self.marketInfoContent.insert('insert', self.parent.m_marketInfo.showMarketInfo(etcName, self.parent.m_inventory.m_etc)) self.marketInfoContent.config(state=Tkinter.DISABLED)
def purchaseUse(): choiceIdx = radioButtonVar.get() if choiceIdx == -1: tkMessageBox.showwarning('Invalid', 'Please select payment type.') return value = quantityEntry.get() try: quantity = int(value) assert quantity > 0 except Exception: tkMessageBox.showwarning('Invalid', 'Invalid input!') return marketInfo = self.parent.m_marketInfo.m_info[scrollName] availPay = self.parent.m_inventory.m_etc[marketInfo['cost'][choiceIdx]] if marketInfo['stock'][choiceIdx] == 0: tkMessageBox.showwarning('Invalid', 'Out of stock.') return elif marketInfo['stock'][choiceIdx] != -1 and marketInfo['stock'][choiceIdx] < quantity: message = 'Only ' + EtcLib.dispLongNum(marketInfo['stock'][choiceIdx]) + ' in stock.\n' tkMessageBox.showwarning('Invalid', message) return elif marketInfo['value'][choiceIdx] * quantity > availPay: message = 'Can not afford.\n\n' message += 'Price: ' + EtcLib.dispLongNum(marketInfo['value'][choiceIdx] * quantity) + ' ' + marketInfo['cost'][choiceIdx] + '.\n' message += 'You only have ' + EtcLib.dispLongNum(availPay) + ' ' + marketInfo['cost'][choiceIdx] + '.' tkMessageBox.showwarning('Invalid', message) return else: message = 'Are You Sure?\n\n' message += 'Purchasing ' + EtcLib.dispLongNum(quantity) + ' ' + self.listboxList[self.curSelectIdx] + '.\n' message += 'Price: ' + EtcLib.dispLongNum(marketInfo['value'][choiceIdx] * quantity) + ' ' + marketInfo['cost'][choiceIdx] + '.\n' message += 'You have ' + EtcLib.dispLongNum(availPay) + ' ' + marketInfo['cost'][choiceIdx] + '.' res = tkMessageBox.askquestion('Purchase', message, type='yesno') if res == 'yes': self.parent.m_inventory.m_etc[marketInfo['cost'][choiceIdx]] -= (marketInfo['value'][choiceIdx] * quantity) if marketInfo['stock'][choiceIdx] != -1: self.parent.m_marketInfo.m_info[scrollName]['stock'][choiceIdx] -= quantity self.parent.m_inventory.m_use[self.listboxList[self.curSelectIdx]] += quantity message = 'Meso: ' + EtcLib.dispLongNum(self.parent.m_inventory.m_etc['Meso']) + '\n' message += 'NX: ' + EtcLib.dispLongNum(self.parent.m_inventory.m_etc['NX']) self.resourceContent.set(message) self.marketInfoContent.config(state=Tkinter.NORMAL) self.marketInfoContent.delete('1.0', Tkinter.END) self.marketInfoContent.insert('insert', self.parent.m_marketInfo.showMarketInfo(scrollName, self.parent.m_inventory.m_etc)) self.marketInfoContent.config(state=Tkinter.DISABLED) self.parent.tabInventory.reset() description = scrollName + '\n\n' description += 'Quantity in inventory: ' + EtcLib.dispLongNum(self.parent.m_inventory.m_use[scrollName]) + '\n\n' if self.curChosenCategory in ['Special', 'Hammer', 'Cube']: description += SpecialLib.m_lib[scrollName]['description'] self.descriptionContent.config(state=Tkinter.NORMAL) self.descriptionContent.delete('1.0', Tkinter.END) self.descriptionContent.insert('insert', description) self.descriptionContent.config(state=Tkinter.DISABLED) else: description += ScrollLib.showScrollStat(scrollName) self.descriptionContent.config(state=Tkinter.NORMAL) self.descriptionContent.delete('1.0', Tkinter.END) self.descriptionContent.insert('insert', description) self.descriptionContent.config(state=Tkinter.DISABLED) ## self.parent.tabEquip.reset() toplevel.destroy()