# Path: FabLabKasse/faucardPayment/faucardStates.py
# class Status(Enum):
#     """
#     Status Codes from FAUcardPayment for MagPosLog logging
#     MagPosLog saves them as int values
#     """
#     initializing = 0            # The process starts connection to MagnaBox
#     waiting_card = 1            # Init done: Now waiting for card to read its balance and check it
#     decreasing_balance = 2      # Card read: Now sending decreasing command to MagnaBox
#     decreasing_done = 3         # Card balance decreased: Now executing booking
#     booking_done = 4            # Payment fully booked and payed
#     transaction_result = 5      # Got last transaction details which were not acknowledged by program
#     balance_underflow = 8       # Not enough balance on card to decrease
#     unknown_error = 9           # Payment canceled on error the program cant handle on its self
#     con_lost = 10               # Payment was canceled during a lost connection to the MagnaBox
# 
# class Info(Enum):
#     """
#     Info code containing OK / Error codes from FAUcardPayment for MagPosLog logging
#     MagPosLog saves them as int values
#     """
#     OK = 0                  # Everything OK, No Error
#     con_error = 1           # Connection was lost during Payment
#     balance_underflow = 2   # Card balance was lower than the amount to pay
#     unknown_error = 3       # Error that could not be handled by program
#     user_abort = 4          # User aborted execution before decreasing
#     transaction_ok = 5      # Last transaction marked as successfully executed
#     transaction_error = 6   # Last transaction marked as aborted on error
#     con_back = 7            # Connection has been retrieved
#     check_transaction_failed = 8  # Failed to check transaction
#     booking_error = 9       # Error occured during booking


import logging
from PyQt4 import QtGui, QtCore, Qt
from .uic_generated.FAUcardPaymentDialog import Ui_FAUcardPaymentDialog
from ..faucardPayment.faucardStates import Status, Info
from decimal import Decimal
        self.setupUi(self)
        self.setModal(True)

        assert isinstance(amount, Decimal), "PayupFAUCard: Amount to pay not Decimal or float"
        
        # Set up member variables and fill GUI
        self.amount = amount
        self.label_betrag.setText(u'{} €'.format(unicode(self.amount)).replace('.', ','))
        self.label_status.setText(u'Starte FAUcard-Zahlung\n')
        self.counter = 0
        self.thread_aborted = False
        self.thread_broken = False
        self.timer_terminate = QtCore.QTimer()
        self.timer_terminate.timeout.connect(self.request_thread_termination)
        self.timer_terminate.setSingleShot(True)
        self.status = Status.initializing

        # Start a timer to periodically update the GUI (show life sign)
        self.utimer = QtCore.QTimer()
        QtCore.QObject.connect(self.utimer, QtCore.SIGNAL("timeout()"), self.show_active)
        QtCore.QObject.connect(self.pushButton_abbrechen, QtCore.SIGNAL("clicked()"), self.reject)
        self.utimer.start(1000)

    @QtCore.pyqtSlot()
    def thread_terminated(self):
        """
        A Slot to recognize if the Thread was terminated and tell the user
        """
        logging.error("FAUcardPayment: Thread was terminated")
        self.thread_aborted = True

# Path: FabLabKasse/faucardPayment/faucardStates.py
# class Status(Enum):
#     """
#     Status Codes from FAUcardPayment for MagPosLog logging
#     MagPosLog saves them as int values
#     """
#     initializing = 0            # The process starts connection to MagnaBox
#     waiting_card = 1            # Init done: Now waiting for card to read its balance and check it
#     decreasing_balance = 2      # Card read: Now sending decreasing command to MagnaBox
#     decreasing_done = 3         # Card balance decreased: Now executing booking
#     booking_done = 4            # Payment fully booked and payed
#     transaction_result = 5      # Got last transaction details which were not acknowledged by program
#     balance_underflow = 8       # Not enough balance on card to decrease
#     unknown_error = 9           # Payment canceled on error the program cant handle on its self
#     con_lost = 10               # Payment was canceled during a lost connection to the MagnaBox
# 
# class Info(Enum):
#     """
#     Info code containing OK / Error codes from FAUcardPayment for MagPosLog logging
#     MagPosLog saves them as int values
#     """
#     OK = 0                  # Everything OK, No Error
#     con_error = 1           # Connection was lost during Payment
#     balance_underflow = 2   # Card balance was lower than the amount to pay
#     unknown_error = 3       # Error that could not be handled by program
#     user_abort = 4          # User aborted execution before decreasing
#     transaction_ok = 5      # Last transaction marked as successfully executed
#     transaction_error = 6   # Last transaction marked as aborted on error
#     con_back = 7            # Connection has been retrieved
#     check_transaction_failed = 8  # Failed to check transaction
#     booking_error = 9       # Error occured during booking


# Path: FabLabKasse/UI/FAUcardPaymentDialogCode.py
import logging
from PyQt4 import QtGui, QtCore, Qt
from .uic_generated.FAUcardPaymentDialog import Ui_FAUcardPaymentDialog
from ..faucardPayment.faucardStates import Status, Info
from decimal import Decimal

        self.setupUi(self)
        self.setModal(True)

        assert isinstance(amount, Decimal), "PayupFAUCard: Amount to pay not Decimal or float"
        
        # Set up member variables and fill GUI
        self.amount = amount
        self.label_betrag.setText(u'{} €'.format(unicode(self.amount)).replace('.', ','))
        self.label_status.setText(u'Starte FAUcard-Zahlung\n')
        self.counter = 0
        self.thread_aborted = False
        self.thread_broken = False
        self.timer_terminate = QtCore.QTimer()
        self.timer_terminate.timeout.connect(self.request_thread_termination)
        self.timer_terminate.setSingleShot(True)
        self.status = Status.initializing

        # Start a timer to periodically update the GUI (show life sign)
        self.utimer = QtCore.QTimer()
        QtCore.QObject.connect(self.utimer, QtCore.SIGNAL("timeout()"), self.show_active)
        QtCore.QObject.connect(self.pushButton_abbrechen, QtCore.SIGNAL("clicked()"), self.reject)
        self.utimer.start(1000)

    @QtCore.pyqtSlot()
    def thread_terminated(self):
        """
        A Slot to recognize if the Thread was terminated and tell the user
        """
        logging.error("FAUcardPayment: Thread was terminated")
        self.thread_aborted = True

        self.update_gui([Info.unknown_error])