From 0077b046988924f7d2e38b6828317921ff2960d0 Mon Sep 17 00:00:00 2001 From: RndName Date: Mon, 22 Nov 2021 16:48:52 +0100 Subject: [PATCH] Update UI when buy or sell raises exception fixes #1562 cherry-pick from 34100d1c --- qt_ui/windows/basemenu/UnitTransactionFrame.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/qt_ui/windows/basemenu/UnitTransactionFrame.py b/qt_ui/windows/basemenu/UnitTransactionFrame.py index 5ec31619..d1364342 100644 --- a/qt_ui/windows/basemenu/UnitTransactionFrame.py +++ b/qt_ui/windows/basemenu/UnitTransactionFrame.py @@ -230,25 +230,23 @@ class UnitTransactionFrame(QFrame, Generic[TransactionItemType]): self.update_purchase_controls() self.update_available_budget() - def buy(self, item: TransactionItemType, quantity: int) -> bool: + def buy(self, item: TransactionItemType, quantity: int) -> None: try: self.purchase_adapter.buy(item, quantity) except TransactionError as ex: logging.exception(f"Purchase of {self.display_name_of(item)} failed") QMessageBox.warning(self, "Purchase failed", str(ex), QMessageBox.Ok) - return False - self.post_transaction_update() - return True + finally: + self.post_transaction_update() - def sell(self, item: TransactionItemType, quantity: int) -> bool: + def sell(self, item: TransactionItemType, quantity: int) -> None: try: self.purchase_adapter.sell(item, quantity) except TransactionError as ex: logging.exception(f"Sale of {self.display_name_of(item)} failed") QMessageBox.warning(self, "Sale failed", str(ex), QMessageBox.Ok) - return False - self.post_transaction_update() - return True + finally: + self.post_transaction_update() def update_purchase_controls(self) -> None: for group in self.purchase_groups.values():