from collections import OrderedDict
from PyQt5.QtWidgets import QWidget, QLabel
from PyQt5.QtCore import Qt

__all__ = ['StatusBar']


class StatusBar(QWidget):

    def __init__(self, parent):
        super(StatusBar, self).__init__()
        p = parent
        values = OrderedDict([
            ('stb_shop', {'name': self.tr('SHOP'), 'value': p.shop['name']}),
            ('stb_device', {'name': self.tr('DEVICE'), 'value': p.device['name']}),
            ('stb_database', {'name': self.tr('DATABASE'), 'value': p.database}),
            ('stb_user', {'name': self.tr('USER'), 'value': p.user}),
            ('stb_printer', {'name': self.tr('PRINTER'), 'value': p.printer_sale_name})
        ])

        status_bar = p.statusBar()
        status_bar.setSizeGripEnabled(False)

        for k, v in values.items():
            _label = QLabel(v['name'] + ':')
            _label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
            _label.setObjectName('label_status_bar')
            status_bar.addWidget(_label, 1)
            setattr(parent, k, QLabel(str(v['value'])))
            _field_info = getattr(parent, k)
            _field_info.setObjectName('field_status_bar')
            _field_info.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
            status_bar.addWidget(_field_info)
