Пример #1
0
 def __layout__(self):
     widgets = [
         self.ldtAccount, self.ldtName, self.ldtPassword,
         self.ldtPasswordConfirm, self.ldtIdentity, self.ldtPhone,
         self.cbxDegree, self.ldtSchool, self.ldtMajor, self.gbxRadioButton,
         self.ldtCarType, self.ldtCarNumber
     ]
     titles = [
         self.lblAccount, self.lblName, self.lblPassword,
         self.lblPasswordConfirm, self.lblIdentity, self.lblPhone,
         self.lblDegree, self.lblMajor, self.lblSchool, self.lblCar,
         self.lblCarType, self.lblCarNumber
     ]
     layoutBtn = QHBoxLayout()
     layoutBtn.addWidget(self.btnClose)
     layoutBtn.addWidget(self.btnSignup)
     layoutWidget = QFormLayout()
     for title, widget in zip(titles, widgets):
         layoutZip = QHBoxLayout()
         layoutZip.addWidget(title, 1)
         layoutZip.addWidget(widget, 2)
         layoutWidget.addItem(layoutZip)
     layout = QVBoxLayout()
     layout.addLayout(layoutWidget)
     layout.addLayout(layoutBtn)
     self.setLayout(layout)
Пример #2
0
    def dadosDoPedido(self):
        self.topLeftGroupBox = QGroupBox("Dados do Pedido")

        verticalSpacer = QSpacerItem(40, 20, QSizePolicy.Minimum,
                                     QSizePolicy.Expanding)

        formLayout = QFormLayout()
        self.pedido = QLineEdit(self)
        self.pedido.setPlaceholderText("ex: 123.456")
        pedido_label = QLabel("Pedido:")

        self.n_simafic = QLineEdit(self)
        self.n_simafic.setPlaceholderText("ex: 08.04.02.507-6")
        n_simafic_label = QLabel("COD. SIMAFIC:")

        self.qtd_items = QLineEdit(self)
        self.qtd_items.setPlaceholderText("ex: 100")
        qtd_items_label = QLabel("Quantidade de Items:")
        '''ADD PEDIDO'''
        add_item = QPushButton('Adicionar Item')
        add_item.setObjectName('Add')
        add_item.setIcon(QIcon('assets/check_icon_blue2.png'))
        add_item.clicked.connect(self.add_items)
        '''CLEAR BUTTON CONFIG '''
        clear_btn = QPushButton('Limpar Campos')
        clear_btn.setObjectName('Yellow')
        clear_btn.setIcon(QIcon('assets/eraser.png'))
        clear_btn.clicked.connect(self.limpar_pedidos)

        formLayout.addRow(pedido_label, self.pedido)
        formLayout.addRow(n_simafic_label, self.n_simafic)
        formLayout.addRow(qtd_items_label, self.qtd_items)
        formLayout.addItem(verticalSpacer)
        formLayout.addRow(add_item)
        formLayout.addRow(clear_btn)
        '''checkBox = QCheckBox("Tri-state check box")
        checkBox.setTristate(True)
        checkBox.setCheckState(Qt.PartiallyChecked)'''

        #layout.addWidget(checkBox)
        '''formLayout.addWidget(add_item)
        formLayout.addWidget(clear_btn)'''

        layout = QVBoxLayout()
        layout.addLayout(formLayout)
        layout.addStretch(2)

        self.topLeftGroupBox.setLayout(layout)
Пример #3
0
    def createNewUserDialog(self):
        """Set up the dialog box that allows the user to enter new user information."""
        self.new_user_dialog = QDialog(self)
        self.new_user_dialog.setWindowTitle("Create New User")
        self.new_user_dialog.setModal(True)

        self.enter_first_line = QLineEdit()
        self.enter_last_line = QLineEdit()
        self.display_name_line = QLineEdit()

        locations_list = ["Select Location...", "Algeria", "Argentina", "Bolivia", "Canada", "Denmark",
            "Greece", "Iran", "Liberia", "New Zealand", "Qatar", "Uganda"]

        self.location_cb = QComboBox()
        self.location_cb.addItems(locations_list)

        create_button = QPushButton("Create User")
        create_button.clicked.connect(self.addNewUserToTable)
        cancel_button = QPushButton("Cancel")
        cancel_button.clicked.connect(self.new_user_dialog.reject)

        button_h_box = QHBoxLayout()
        button_h_box.addWidget(create_button)
        button_h_box.addSpacing(15)
        button_h_box.addWidget(cancel_button)

        # Add widgets to form layout
        dialog_form = QFormLayout()
        dialog_form.setFormAlignment(Qt.AlignLeft)
        dialog_form.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
        dialog_form.addRow("First name", self.enter_first_line)
        dialog_form.addRow("Last name", self.enter_last_line)
        dialog_form.addRow("Display Name", self.display_name_line)
        dialog_form.addRow("Location", self.location_cb)
        dialog_form.addItem(button_h_box)
        
        self.new_user_dialog.setLayout(dialog_form)

        # Restrict the size of the dialog in relation to the size of the 
        # dialog_form's sizeHint()
        self.new_user_dialog.setMaximumSize(dialog_form.sizeHint())
        self.new_user_dialog.show()
Пример #4
0
class ParamerterDemo(QDialog):
    def __init__(self):
        super(ParamerterDemo, self).__init__()
        self.initUI()

    def initUI(self):
        self.resize(400, 200)
        self.setMaximumSize(400, 200)
        self.setWindowTitle('设置参数')
        self.setWindowIcon(QIcon('./image/参数.png'))
        self.signal = MySignal()
        self.defuat_parameter_list = [100, 3, 10, 10, 5]

        self.form_layout = QFormLayout()

        self.lable1 = QLabel()
        self.lable1.setText('特征得分Top:')
        self.lable1.setToolTip('过滤过程')
        self.line_edit1 = QLineEdit()
        self.line_edit1.setValidator(QIntValidator())
        self.line_edit1.setText('100')
        self.form_layout.addRow(self.lable1, self.line_edit1)

        self.lable2 = QLabel()
        self.lable2.setText('主成分个数:')
        self.lable2.setToolTip('PLS中的主成分分析')
        self.line_edit2 = QLineEdit()
        self.line_edit2.setValidator(QIntValidator())
        self.line_edit2.setText('3')
        self.form_layout.addRow(self.lable2, self.line_edit2)

        self.lable3 = QLabel()
        self.lable3.setText('K折交叉验证:')
        self.lable3.setToolTip('K折交叉验证')
        self.line_edit3 = QLineEdit()
        self.line_edit3.setValidator(QIntValidator())
        self.line_edit3.setText('10')
        self.form_layout.addRow(self.lable3, self.line_edit3)

        self.lable4 = QLabel()
        self.lable4.setText('Wrapper步长:')
        self.lable4.setToolTip('封装过程')
        self.line_edit4 = QLineEdit()
        self.line_edit4.setPlaceholderText('步长最好要能被特征总数整除')
        self.line_edit4.setValidator(QIntValidator())
        self.line_edit4.setText('10')
        self.form_layout.addRow(self.lable4, self.line_edit4)

        self.lable5 = QLabel()
        self.lable5.setText('频次阈值alp:')
        self.lable5.setToolTip('投票过程')
        self.line_edit5 = QLineEdit()
        self.line_edit5.setPlaceholderText('使用的是多数投票法')
        self.line_edit5.setValidator(QIntValidator())
        self.line_edit5.setText('5')
        self.form_layout.addRow(self.lable5, self.line_edit5)

        self.button1 = QPushButton('重置')
        self.button1.setToolTip('重置为默认值')
        self.button2 = QPushButton('取消')
        self.button2.setToolTip('退出设置参数')
        self.button3 = QPushButton('完成')
        self.button3.setToolTip('确认设置参数')
        hlayout = QHBoxLayout()
        hlayout.addWidget(self.button1)
        hlayout.addWidget(self.button2)
        hlayout.addWidget(self.button3)
        hlayout.setSpacing(20)
        self.form_layout.addItem(hlayout)
        self.setLayout(self.form_layout)

        #关联信号
        self.button1.clicked.connect(self.reSetParameter)
        self.button2.clicked.connect(self.close)
        self.button3.clicked.connect(self.sendSignal)

    #重置参数
    def reSetParameter(self):
        for i in range(1, 6):
            try:
                command = 'self.line_edit{}.setText(str(self.defuat_parameter_list[i-1]))'.format(
                    i)
                eval(command)
            except Exception as e:
                print(e)
                pass

    #参数设置完成,发送信号并关闭设置参数对话框
    def sendSignal(self):
        parameter_dict = {
            'topK': int(self.line_edit1.text()),
            'n_components': int(self.line_edit2.text()),
            'K': int(self.line_edit3.text()),
            'step': int(self.line_edit4.text()),
            'alp': int(self.line_edit5.text()),
        }
        self.signal.send(parameter_dict)
        self.close()
Пример #5
0
class ParamerterDemo2(QDialog):
    def __init__(self):
        super(ParamerterDemo2, self).__init__()
        self.initUI()

    def initUI(self):
        self.resize(400, 200)
        self.setMaximumSize(400, 200)
        self.setWindowTitle('设置参数')
        self.setWindowIcon(QIcon('./image/参数.png'))
        self.signal = MySignal()
        self.defuat_parameter_list = [50, 20000]

        self.form_layout = QFormLayout()

        self.lable1 = QLabel()
        self.lable1.setText('alpha:')
        self.lable1.setToolTip('alpha')
        self.line_edit1 = QLineEdit()
        self.line_edit1.setValidator(QIntValidator())
        self.line_edit1.setText('50')
        self.form_layout.addRow(self.lable1, self.line_edit1)

        self.lable2 = QLabel()
        self.lable2.setText('max_iter:')
        self.lable2.setToolTip('最大迭代次数')
        self.line_edit2 = QLineEdit()
        self.line_edit2.setValidator(QIntValidator())
        self.line_edit2.setText('20000')
        self.form_layout.addRow(self.lable2, self.line_edit2)

        self.button1 = QPushButton('重置')
        self.button1.setToolTip('重置为默认值')
        self.button2 = QPushButton('取消')
        self.button2.setToolTip('退出设置参数')
        self.button3 = QPushButton('完成')
        self.button3.setToolTip('确认设置参数')
        hlayout = QHBoxLayout()
        hlayout.addWidget(self.button1)
        hlayout.addWidget(self.button2)
        hlayout.addWidget(self.button3)
        hlayout.setSpacing(20)
        self.form_layout.addItem(hlayout)
        self.setLayout(self.form_layout)

        #关联信号
        self.button1.clicked.connect(self.reSetParameter)
        self.button2.clicked.connect(self.close)
        self.button3.clicked.connect(self.sendSignal)

    #重置参数
    def reSetParameter(self):
        for i in range(1, 3):
            try:
                command = 'self.line_edit{}.setText(str(self.defuat_parameter_list[i-1]))'.format(
                    i)
                eval(command)
            except Exception as e:
                print(e)
                pass

    #参数设置完成,发送信号并关闭设置参数对话框
    def sendSignal(self):
        parameter_dict = {
            'alpha': int(self.line_edit1.text()),
            'max_iter': int(self.line_edit2.text()),
        }
        self.signal.send(parameter_dict)
        self.close()
    layout.addRow('Last', QLineEdit())
    layout.addRow(HorizontalLineWidget())

    layout.addRow('Phone', QLineEdit())
    layout.addRow(HorizontalLineWidget())

    h_layout = QHBoxLayout()
    label = QLabel("1")
    label.setAlignment(Qt.AlignCenter)
    h_layout.addWidget(label)
    h_layout.addWidget(VerticalLineWidget())

    label = QLabel("2")
    label.setAlignment(Qt.AlignCenter)
    h_layout.addWidget(label)
    h_layout.addWidget(VerticalLineWidget())

    label = QLabel("3")
    label.setAlignment(Qt.AlignCenter)
    h_layout.addWidget(label)

    layout.addItem(h_layout)

    layout.addRow('Ok?', QCheckBox())

    mw = QWidget()
    mw.setLayout(layout)
    mw.show()

    app.exec()
Пример #7
0
    def __init__(self, pedido, parent=None):
        super(UpdateScreen, self).__init__(parent, Qt.WindowStaysOnTopHint)
        self.setWindowFlags(self.windowFlags() | Qt.Window
                            | Qt.WindowMinMaxButtonsHint
                            | Qt.WindowCloseButtonHint)
        self.setWindowTitle('Alterar Item')
        self.setMinimumSize(QSize((h_size / 2), (v_size / 2)))
        self.setWindowIcon(QIcon(main_icon))
        self.setWindowFlag(Qt.WindowStaysOnTopHint)

        self.topLeftGroupBox = QGroupBox("Alterar Pedido")

        verticalSpacer = QSpacerItem(40, 20, QSizePolicy.Minimum,
                                     QSizePolicy.Expanding)

        self.item = pedido

        formLayout = QFormLayout()

        id_ped = QLineEdit(self)
        id_ped.setText(str(self.item.id))
        id_ped.setDisabled(True)
        id_ped_label = QLabel("Id no Sistema:")

        self.pedido = QLineEdit(self)
        self.pedido.setText(self.item.id_pedido)
        pedido_label = QLabel("Pedido:")
        self.pedido.textChanged.connect(lambda x: self.item.set_id_pedido(x))
        self.pedido.setDisabled(True)

        self.n_simafic = QLineEdit(self)
        self.n_simafic.setText(self.item.cod_simafic)
        n_simafic_label = QLabel("COD. SIMAFIC:")
        self.n_simafic.textChanged.connect(
            lambda x: self.item.set_cod_simafic(x))
        self.n_simafic.setDisabled(True)

        self.desc = QLineEdit(self)
        self.desc.setText(self.item.desc)
        desc_label = QLabel("DESC:")
        self.desc.textChanged.connect(lambda x: self.item.set_desc(x))

        self.qtd_scan = QLineEdit(self)
        self.qtd_scan.setText(str(self.item.qty_scanneada))
        qtd_items_scan_label = QLabel("Quantidade de Scanneados:")
        self.qtd_scan.setDisabled(True)

        self.qtd_items = QLineEdit(self)
        self.qtd_items.setText(str(self.item.qty_total))
        qtd_items_label = QLabel("Quantidade de Items:")
        self.qtd_items.textChanged.connect(
            lambda x: self.item.set_qty_total(x))

        self.id_caixa = QLineEdit(self)
        self.id_caixa.setText(str(self.item.id_caixa))
        id_caixa_label = QLabel("Id da Caixa:")
        self.id_caixa.textChanged.connect(lambda x: self.item.set_id_caixa(x))

        self.nome_resp = QLineEdit(self)
        self.nome_resp.setText(str(self.item.nome_responsavel))
        nome_resp_label = QLabel("Nome do responsável:")
        self.nome_resp.textChanged.connect(
            lambda x: self.item.set_nome_responsavel(x))
        '''ADD PEDIDO'''
        add_item = QPushButton('Confirmar Alteração')
        add_item.setObjectName('Add')
        add_item.setIcon(QIcon('assets/check_icon_blue2.png'))
        add_item.clicked.connect(lambda: self.updateItens())
        '''CLEAR BUTTON CONFIG '''
        clear_btn = QPushButton('Cancelar Alteração')
        clear_btn.setObjectName('Yellow')
        clear_btn.setIcon(QIcon('assets/eraser.png'))
        clear_btn.clicked.connect(lambda: self.cancelar())

        formLayout.addRow(id_ped_label, id_ped)
        formLayout.addRow(pedido_label, self.pedido)
        formLayout.addRow(n_simafic_label, self.n_simafic)
        formLayout.addRow(desc_label, self.desc)
        formLayout.addRow(qtd_items_scan_label, self.qtd_scan)
        formLayout.addRow(qtd_items_label, self.qtd_items)
        formLayout.addRow(id_caixa_label, self.id_caixa)
        formLayout.addRow(nome_resp_label, self.nome_resp)
        formLayout.addItem(verticalSpacer)
        formLayout.addRow(add_item)
        formLayout.addRow(clear_btn)
        '''checkBox = QCheckBox("Tri-state check box")
        checkBox.setTristate(True)
        checkBox.setCheckState(Qt.PartiallyChecked)'''

        #layout.addWidget(checkBox)
        '''formLayout.addWidget(add_item)
        formLayout.addWidget(clear_btn)'''

        layout = QVBoxLayout()
        layout.addLayout(formLayout)
        layout.addStretch(1)

        self.setLayout(layout)
Пример #8
0
    def createFormGroupTwitch(self):
        """Create forms for twitch."""
        self.formGroupTwitch = QWidget()
        layout = QFormLayout()

        self.twitchChannel = MonitoredLineEdit()
        self.twitchChannel.textModified.connect(self.changed)
        self.twitchChannel.setText(
            hwctool.settings.config.parser.get("Twitch", "channel"))
        self.twitchChannel.setAlignment(Qt.AlignCenter)
        self.twitchChannel.setPlaceholderText(
            _("Name of the Twitch channel that should be updated"))
        self.twitchChannel.setToolTip(
            _('The connected twitch user needs to have editor'
              ' rights for this channel.'))
        layout.addRow(QLabel(
            "Twitch-Channel:"), self.twitchChannel)

        container = QHBoxLayout()

        self.twitchToken = MonitoredLineEdit()
        self.twitchToken.textModified.connect(self.changed)
        self.twitchToken.setText(
            hwctool.settings.config.parser.get("Twitch", "oauth"))
        self.twitchToken.setAlignment(Qt.AlignCenter)
        self.twitchToken.setPlaceholderText(
            _("Press 'Get' to generate a token"))
        self.twitchToken.setEchoMode(QLineEdit.Password)
        self.twitchToken.setToolTip(_("Press 'Get' to generate a new token."))
        container.addWidget(self.twitchToken)

        self.pb_getTwitch = QPushButton(_('Get'))
        self.pb_getTwitch.setFixedWidth(100)
        self.pb_getTwitch.clicked.connect(
            lambda: self.controller.authThread.requestToken('twitch'))
        container.addWidget(self.pb_getTwitch)

        layout.addRow(QLabel(_("Access-Token:")), container)

        container = QHBoxLayout()

        self.twitchTemplate = MonitoredLineEdit()
        self.twitchTemplate.textModified.connect(self.changed)
        self.twitchTemplate.setText(
            hwctool.settings.config.parser.get("Twitch", "title_template"))
        self.twitchTemplate.setAlignment(Qt.AlignCenter)
        self.twitchTemplate.setPlaceholderText("(League) – (Team1) vs (Team2)")
        self.twitchTemplate.setToolTip(
            _('Available placeholders:') + " " +
            ', '.join(self.controller.placeholders.available()))

        completer = Completer(
            self.controller.placeholders.available(), self.twitchTemplate)

        self.twitchTemplate.setCompleter(completer)

        container.addWidget(self.twitchTemplate)

        button = QPushButton(_('Test'))
        button.setFixedWidth(100)
        button.clicked.connect(
            lambda: self.testPlaceholder(self.twitchTemplate.text()))
        container.addWidget(button)

        label = QLabel(_("Title Template:"))
        label.setFixedWidth(100)
        layout.addRow(label, container)

        container = QVBoxLayout()

        self.cb_set_game = QCheckBox(_("Set twitch game to the selected game"))
        self.cb_set_game.setChecked(
            hwctool.settings.config.parser.getboolean("Twitch", "set_game"))
        self.cb_set_game.stateChanged.connect(self.changed)
        container.addWidget(self.cb_set_game)

        self.cb_set_community = QCheckBox(
            _("Add to Community 'StarCraft Casting Tool'"))
        self.cb_set_community.setChecked(
            hwctool.settings.config.parser.getboolean(
                "Twitch", "set_community"))
        self.cb_set_community.stateChanged.connect(self.changed)
        # container.addWidget(self.cb_set_community)

        label = QLabel(_("Options:") + " ")
        label.setMinimumWidth(120)
        layout.addRow(label, container)

        layout.addItem(QSpacerItem(
            0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding))

        self.formGroupTwitch.setLayout(layout)
class finance_edit(QWidget):
    def __init__(self, home_button: QPushButton, parent=None):
        super().__init__(parent)

        self.presetting = False

        intValidator = QIntValidator()
        self.setStyleSheet(QSS)
        self.current_pending_months = []
        self.current_advance_months = []

        self.home_button = home_button
        self.save_button = None

        # -- LEVEL TWO GRID
        self.grid = QGridLayout()
        self.grid.setSpacing(20)
        self.setLayout(self.grid)

        # -- CELL ZERO
        self.receipt_label = QLabel("RECEIPT ID :")
        self.receipt_label.setWordWrap(True)

        self.receipt_id = QLineEdit()
        self.receipt_id.setStyleSheet("font: bold")
        self.receipt_id.setAlignment(Qt.AlignCenter)
        self.receipt_id.setToolTip("Enter a valid Receipt-ID")

        self.print_button = QPushButton("PRINT")
        self.print_button.setFixedWidth(122)
        self.print_button.setToolTip("Get Receipt PDF")

        self.resend_button = QPushButton("RESEND")
        self.resend_button.setToolTip("Send a copy via mail to the member")

        self.edit_button = QPushButton("EDIT")
        self.edit_button.setToolTip("Edit the details of this record")

        self.buttons_layout = QHBoxLayout()
        self.buttons_layout.addWidget(self.resend_button)
        self.buttons_layout.addWidget(self.edit_button)
        self.buttons_layout.setSpacing(5)

        # ---
        self.flat_label = QLabel("FLAT NO. :")
        self.flat_combo = QComboBox()
        model = self.flat_combo.model()

        for flat in flats:
            model.appendRow(QStandardItem(flat))

        self.flat_combo.setStyleSheet(
            'text-color: black; selection-background-color: rgb(215,215,215)')

        self.flat_combo.currentIndexChanged['QString'].connect(self.set_name)

        # ---
        self.name_label = QLabel("NAME :")
        self.name_value = QLabel()
        self.name_value.setFixedWidth(200)
        self.name_value.setText("Mr D. S. Patil")

        # ---
        self.finance_entry_layout0 = QFormLayout()
        self.finance_entry_layout0.addRow(self.receipt_label, self.receipt_id)
        self.finance_entry_layout0.addRow(self.print_button,
                                          self.buttons_layout)
        self.finance_entry_layout0.addRow(self.flat_label, self.flat_combo)
        self.finance_entry_layout0.addRow(self.name_label, self.name_value)
        self.finance_entry_layout0.setVerticalSpacing(90)

        # -- CELL ONE
        self.date_label = QLabel("DATE OF TRANSACTION :")
        self.date_label.setWordWrap(True)

        self.date_line = QDateEdit()
        self.date_line.setCalendarPopup(True)
        self.date_line.setDate(QDate.currentDate())
        self.date_line.setDisplayFormat("dd MMMM, yyyy")

        self.single_radio = QRadioButton("Single Month")
        self.multiple_radio = QRadioButton("Multiple Months")
        self.single_radio.setChecked(True)

        self.single_radio.toggled.connect(
            lambda: self.months(button=self.single_radio))
        self.multiple_radio.toggled.connect(
            lambda: self.months(button=self.multiple_radio))

        self.finance_entry_layout1_h1 = QHBoxLayout()
        self.finance_entry_layout1_h1.addWidget(self.date_line)
        self.finance_entry_layout1_h1.addWidget(self.single_radio)
        self.finance_entry_layout1_h1.addWidget(self.multiple_radio)
        self.finance_entry_layout1_h1.setSpacing(90)

        # ---
        self.month_label = QLabel("FEES FOR :")
        self.month_combo = QComboBox()
        self.set_pending_months()

        self.month_combo.setStyleSheet(
            'text-color: black; selection-background-color: rgb(215,215,215)')

        # ---
        self.month_till_label = QLabel("FEES TILL :")
        self.month_till_label.setAlignment(Qt.AlignCenter)
        self.month_till_combo = QComboBox()

        self.set_advance_months()

        self.month_till_combo.setStyleSheet(
            'text-color: black; selection-background-color: rgb(215,215,215)')

        self.finance_entry_layout1_h2 = QHBoxLayout()
        self.finance_entry_layout1_h2.addWidget(self.month_combo)
        self.finance_entry_layout1_h2.addWidget(self.month_till_label)
        self.finance_entry_layout1_h2.addWidget(self.month_till_combo)
        self.finance_entry_layout1_h2.setSpacing(90)

        self.month_till_label.setEnabled(False)
        self.month_till_combo.setEnabled(False)

        # ---
        self.amount_label = QLabel("AMOUNT :")
        self.amount_label.setAlignment(Qt.AlignCenter)
        self.amount_line = QLineEdit()
        self.amount_line.setText("1500")

        self.amount_line.setValidator(intValidator)

        # ---
        self.fine_label = QLabel("FINE :")
        self.fine_label.setAlignment(Qt.AlignCenter)
        self.fine_line = QLineEdit()
        self.fine_line.setText("0")

        self.fine_line.setValidator(intValidator)
        self.fine_line.setStyleSheet("border: 1px solid red; color: red")

        self.finance_entry_layout1_h3 = QHBoxLayout()
        self.finance_entry_layout1_h3.addWidget(self.amount_line)
        self.finance_entry_layout1_h3.addWidget(self.fine_label)
        self.finance_entry_layout1_h3.addWidget(self.fine_line)
        self.finance_entry_layout1_h3.setSpacing(90)

        # ---
        self.finance_entry_layout1 = QFormLayout()
        self.finance_entry_layout1.addRow(self.date_label,
                                          self.finance_entry_layout1_h1)
        self.finance_entry_layout1.addRow(self.month_label,
                                          self.finance_entry_layout1_h2)
        self.finance_entry_layout1.addRow(self.amount_label,
                                          self.finance_entry_layout1_h3)
        self.finance_entry_layout1.setVerticalSpacing(90)

        # -- CELL TWO
        self.mode_label = QLabel("PAYMENT MODE :")
        self.mode_label.setWordWrap(True)

        # ---
        self.mode_combo = QComboBox()
        self.mode_combo.addItem("Cash")
        self.mode_combo.addItem("Online Funds Transfer")
        self.mode_combo.addItem("Cheque")

        self.mode_combo.setStyleSheet(
            'text-color: black; selection-background-color: rgb(215,215,215)')
        self.mode_combo.currentIndexChanged['QString'].connect(
            self.mode_selection)

        # ---
        self.ref_label = QLabel("REFERENCE ID :")
        self.ref_label.setWordWrap(True)
        self.ref_line = QLineEdit()

        self.ref_label.setDisabled(True)
        self.ref_line.setDisabled(True)

        self.total_label = QLabel(
            f"TOTAL PAYABLE AMOUNT : {int(self.amount_line.text()) + int(self.fine_line.text())}"
        )
        self.total_label.setWordWrap(True)
        self.total_label.setAlignment(Qt.AlignCenter)

        self.save_button = QPushButton("UPDATE AND RESEND RECEIPT")
        self.save_button.setStyleSheet("font: bold")
        self.save_button.clicked.connect(lambda: self.check_form())

        self.status = QLabel("Ready")
        self.status.setStyleSheet("font: 8pt")
        self.status.setAlignment(Qt.AlignCenter)

        self.bar = QProgressBar(self)
        self.bar.setValue(0)
        self.bar.setMaximum(100)
        self.bar.setToolTip("Please wait until the process is completed.")

        # ---
        self.finance_entry_layout2 = QFormLayout()
        self.finance_entry_layout2.addRow(self.mode_label, self.mode_combo)
        self.finance_entry_layout2.addRow(self.ref_label, self.ref_line)
        self.finance_entry_layout2.addItem(create_spacer_item(w=5, h=30))
        self.finance_entry_layout2.addRow(self.total_label)
        self.finance_entry_layout2.addRow(self.save_button)
        self.finance_entry_layout2.addRow(self.status)
        self.finance_entry_layout2.addRow(self.bar)
        self.finance_entry_layout2.setVerticalSpacing(50)

        self.finance_entry_group0 = QGroupBox()
        self.finance_entry_group0.setLayout(self.finance_entry_layout0)

        self.finance_entry_group1 = QGroupBox()
        self.finance_entry_group1.setLayout(self.finance_entry_layout1)

        self.finance_entry_group2 = QGroupBox()
        self.finance_entry_group2.setLayout(self.finance_entry_layout2)
        self.finance_entry_group2.setFixedWidth(550)

        # -- FUNCTIONALITY:
        self.date_line.dateChanged.connect(lambda: self.set_pending_months(
            date=str(self.date_line.date().toPyDate())))

        self.month_combo.currentIndexChanged['QString'].connect(
            self.set_advance_months)

        self.month_combo.currentIndexChanged['QString'].connect(
            lambda ind: self.calculate_fine('from', ind))
        self.month_till_combo.currentIndexChanged['QString'].connect(
            lambda ind: self.calculate_fine('till', ind))

        self.month_combo.currentTextChanged.connect(self.calculate_amount)
        self.month_till_combo.currentTextChanged.connect(self.calculate_amount)

        self.amount_line.textChanged.connect(self.set_total)
        self.fine_line.textChanged.connect(self.set_total)

        self.edit_button.clicked.connect(self.enable_edit)
        self.print_button.clicked.connect(self.print_receipt)
        self.resend_button.clicked.connect(self.resend_receipt)

        self.receipt_id.textChanged['QString'].connect(
            lambda receipt_id: self.get_receipt(receipt_id))

        # -- FINANCE ENTRY GRID
        self.grid.addWidget(self.finance_entry_group0, 0, 0, 2, 1)
        self.grid.addWidget(self.finance_entry_group1, 0, 1, 2, 1)
        self.grid.addWidget(self.finance_entry_group2, 0, 2, 2, 1)

        self.save_button.setEnabled(False)
        self.print_button.setEnabled(False)
        self.resend_button.setEnabled(False)
        self.edit_button.setEnabled(False)
        self.flat_label.setEnabled(False)
        self.flat_combo.setEnabled(False)
        self.name_label.setEnabled(False)
        self.name_value.setEnabled(False)
        self.finance_entry_group1.setEnabled(False)
        self.finance_entry_group2.setEnabled(False)

    def get_receipt(self, receipt_id: str):
        data = db_tools.get_from_db(table='records',
                                    attribute='*',
                                    key='receipt_id',
                                    value=receipt_id)

        if len(data) > 0:

            self.presetting = True

            data = data[0]

            receipt_date = data[1].split("/")
            flat = data[2]
            fee_month = data[3]
            fee_till = data[4]
            amount = data[5]
            fine = data[6]
            mode = data[7]
            ref = data[8]

            date_to_set = QDate(int(receipt_date[2]), int(receipt_date[1]),
                                int(receipt_date[0]))

            fee_month = fee_month.split("/")
            fee_month_to_set = f"{fee_month[0]} '{fee_month[1]}"

            self.date_line.setDate(date_to_set)

            self.flat_combo.setCurrentText(flat)

            self.month_combo.setCurrentText(fee_month_to_set)

            self.amount_line.setText(f"{amount}")

            self.fine_line.setText(f"{fine}")

            self.mode_combo.setCurrentText(mode)

            self.ref_line.setText(ref)

            self.total_label.setText(f"TOTAL PAYABLE AMOUNT : {amount + fine}")

            if fee_till != "-":
                fee_till = fee_till.split("/")
                fee_till_to_set = f"{fee_till[0]} '{fee_till[1]}"

                self.multiple_radio.setChecked(True)
                self.single_radio.setChecked(False)

                self.month_till_combo.setCurrentText(fee_till_to_set)

            else:
                self.multiple_radio.setChecked(False)
                self.single_radio.setChecked(True)

            if mode == "Cash":
                self.ref_label.setEnabled(False)
                self.ref_line.setEnabled(False)

            self.presetting = False

            self.print_button.setEnabled(True)
            self.resend_button.setEnabled(True)
            self.edit_button.setEnabled(True)

        else:
            self.print_button.setEnabled(False)
            self.resend_button.setEnabled(False)
            self.edit_button.setEnabled(False)

            self.flat_label.setEnabled(False)
            self.flat_combo.setEnabled(False)
            self.name_label.setEnabled(False)
            self.name_value.setEnabled(False)
            self.finance_entry_group1.setEnabled(False)
            self.finance_entry_group2.setEnabled(False)

    def enable_edit(self):
        self.flat_label.setEnabled(True)
        self.flat_combo.setEnabled(True)
        self.name_label.setEnabled(True)
        self.name_value.setEnabled(True)
        self.finance_entry_group1.setEnabled(True)
        self.finance_entry_group2.setEnabled(True)

    def months(self, button):
        if button.isChecked():
            if button.text() == "Single Month":
                self.month_till_label.setEnabled(False)
                self.month_till_combo.setEnabled(False)

            elif button.text() == "Multiple Months":
                self.month_till_label.setEnabled(True)
                self.month_till_combo.setEnabled(True)

        self.calculate_amount()

    def mode_selection(self, selection):
        if selection == "Cash":
            self.ref_label.setText("REFERENCE ID :")
            self.ref_label.setDisabled(True)
            self.ref_line.setDisabled(True)

        elif selection == "Cheque":
            self.ref_label.setText("CHEQUE NO. :")
            self.ref_label.setDisabled(False)
            self.ref_line.setDisabled(False)

        elif selection == "Online Funds Transfer":
            self.ref_label.setText("REFERENCE ID :")
            self.ref_label.setDisabled(False)
            self.ref_line.setDisabled(False)

        if self.save_button is not None:
            self.save_button.setEnabled(True)

    def check_form(self):
        reply = QMessageBox()

        if len(self.amount_line.text()) == 0:
            reply.setIcon(QMessageBox.Warning)
            reply.setText("AMOUNTS field cannot be left empty.")
            reply.setStandardButtons(QMessageBox.Retry)
            reply.setWindowTitle("INVALID ENTRY")
            reply.exec_()

        elif len(self.fine_line.text()) == 0:
            reply.setIcon(QMessageBox.Warning)
            reply.setText("FINE field cannot be left empty.")
            reply.setStandardButtons(QMessageBox.Retry)
            reply.setWindowTitle("INVALID ENTRY")
            reply.exec_()

        elif self.ref_line.isEnabled() and len(self.ref_line.text()) == 0:
            reply.setIcon(QMessageBox.Warning)
            reply.setText(
                "Please enter the REFERENCE INFORMATION for the transaction.")
            reply.setStandardButtons(QMessageBox.Retry)
            reply.setWindowTitle("INVALID ENTRY")
            reply.exec_()

        else:
            code, ok = QInputDialog().getText(
                self, "Security", "Enter the authentication code:")

            if verify_code(code) and ok:
                print("Verified")

                if self.month_till_combo.isEnabled():
                    fee_till = f" - {self.month_till_combo.currentText()}"
                else:
                    fee_till = ''

                if self.ref_line.isEnabled():
                    ref = f" - ({self.ref_line.text()})"
                else:
                    ref = ''

                detailed_text = f"Date : {fix_date(str(self.date_line.date().toPyDate()))}\n" \
                                f"Fee for : {str(self.month_combo.currentText())}{fee_till}\n" \
                                f"Flat No : {str(self.flat_combo.currentText())}\n" \
                                f"Amount : {float(self.amount_line.text())}\n" \
                                f"Fine : {float(self.fine_line.text())}\n" \
                                f"    -> TOTAL : {float(self.amount_line.text()) + float(self.fine_line.text())} <-\n" \
                                f"Payment Mode : {str(self.mode_combo.currentText())}{ref}"

                reply.setWindowTitle("SUCCESSFUL ENTRY")
                reply.setIcon(QMessageBox.Information)
                reply.setText("ENTRY HAS BEEN RECORDED.\n")
                reply.setInformativeText("Please confirm the details below.")

                reply.setDetailedText(detailed_text)
                confirm_button = reply.addButton('Confirm',
                                                 QMessageBox.AcceptRole)
                edit_button = reply.addButton('Edit', QMessageBox.RejectRole)

                confirm_button.clicked.connect(
                    lambda: self.final_clicked(button=confirm_button))
                edit_button.clicked.connect(
                    lambda: self.final_clicked(button=edit_button))
                reply.exec_()

            else:
                reply.setIcon(QMessageBox.Critical)
                reply.setText(
                    "Transaction cannot be edited without the valid code.")
                reply.setWindowTitle("INVALID Code")
                reply.exec_()

    def set_name(self, flat):
        name = get_name(flat)
        self.name_value.setText(str(name))

        if self.save_button is not None:
            self.save_button.setEnabled(True)

    def update_entry(self):
        receipt_id = self.receipt_id.text()
        date = str(self.date_line.date().toPyDate())
        fee_month = str(self.month_combo.currentText())

        if self.month_till_combo.isEnabled():
            fee_till = self.month_till_combo.currentText()
            month = f"{fee_month}-{fee_till}"

        else:
            fee_till = ''
            month = fee_month

        flat = str(self.flat_combo.currentText())
        amount = float(self.amount_line.text())
        fine = float(self.fine_line.text())
        mode = str(self.mode_combo.currentText())

        if self.ref_line.isEnabled():
            ref = self.ref_line.text()
        else:
            ref = ''

        new_receipt = receipt.receipt(date=fix_date(date),
                                      flat=flat,
                                      month=fee_month,
                                      month_till=fee_till,
                                      amount=amount,
                                      fine=fine,
                                      mode=mode,
                                      ref=ref)
        self.disable()
        self.total_label.setText(
            "Confirming.. PLEASE DO NOT PERFORM ANY OTHER OPERATIONS.")

        new_receipt.update_db(receipt_id=self.receipt_id.text())

        self.status.setText("Adding to databse & Generating receipt")
        self.bar.setValue(40)
        design_receipt(receipt_id=f"{receipt_id}")

        self.status.setText(
            "Sending the receipt to the member. (Depends on your internet connection)"
        )
        self.bar.setValue(75)
        email_status = send_receipt(flat=flat, month=month, updated=True)
        self.enable()
        self.set_total()

        if email_status:
            self.bar.setValue(100)

        else:
            reply = QMessageBox()
            reply.setIcon(QMessageBox.Warning)
            reply.setText(
                "The system cannot access the internet. Make sure you have an active connection, or any firewall"
                "feature blocking the access.")
            reply.setStandardButtons(QMessageBox.Retry)
            reply.setWindowTitle("INTERNET")
            reply.exec_()

    def final_clicked(self, button):
        if button.text() == "Confirm":
            print("in confirm")
            self.update_entry()

            self.receipt_id.setText("")
            self.receipt_id.setFocus()
            self.flat_combo.setCurrentIndex(0)
            self.name_value.setText("")
            self.amount_line.setText('0')
            self.fine_line.setText('0')

            self.bar.setValue(0)
            self.status.setText("Done !")
            self.ref_line.clear()

    def set_pending_months(self, date: str = None):
        if not self.presetting:
            if date is None:
                date = str(self.date_line.date().toPyDate())

            months = calculate_months(month=date, pending=True, advance=False)

            self.current_pending_months = months

            self.month_combo.clear()

            model = self.month_combo.model()
            for month in months:
                model.appendRow(QStandardItem(month))

            if self.save_button is not None:
                self.save_button.setEnabled(True)

    def set_advance_months(self, date: str = None):
        if not self.presetting:

            if date is None or date == '':
                date = fix_date_back(self.current_pending_months[0])
            else:
                date = fix_date_back(date)

            months = calculate_months(month=date, pending=False, advance=True)

            self.current_advance_months = months

            self.month_till_combo.clear()
            model = self.month_till_combo.model()

            for month in months:
                model.appendRow(QStandardItem(month))

            if self.save_button is not None:
                self.save_button.setEnabled(True)

    def calculate_amount(self):
        if not self.presetting:

            if self.month_combo.count() == 0 or self.month_till_combo.count(
            ) == 0:
                self.amount_line.setText('0')
                return

            else:
                all_possible_months = self.current_advance_months.copy()
                all_possible_months = all_possible_months[::-1]

                all_possible_months.extend([
                    x for x in self.current_pending_months
                    if x not in self.current_advance_months
                ])

                if self.month_till_combo.isEnabled():
                    from_index = all_possible_months.index(
                        self.month_combo.currentText())
                    till_index = all_possible_months.index(
                        self.month_till_combo.currentText())

                    amount = (from_index - till_index + 1) * 1500

                else:
                    amount = 1500

                self.amount_line.setText(str(amount))
                self.amount_line.setToolTip(f"Total months : {amount // 1500}")

            if self.save_button is not None:
                self.save_button.setEnabled(True)

    def calculate_fine(self, from_where: str, month):
        if not self.presetting:

            if month == '' and self.month_combo.count(
            ) == 0 or self.month_till_combo.count() == 0:
                self.fine_line.setText('0')
                return

            else:
                if self.month_till_combo.isEnabled():
                    try:
                        till_index = self.current_pending_months.index(
                            str(self.month_till_combo.currentText()))
                    except ValueError:
                        till_index = 0
                else:
                    try:
                        till_index = self.current_pending_months.index(
                            str(self.month_combo.currentText()))
                    except ValueError:
                        self.fine_line.setText('0')
                        return

                try:
                    from_index = self.current_pending_months.index(
                        str(self.month_combo.currentText()))
                except ValueError:
                    self.fine_line.setText('0')
                    return

                all_fine_months = []

                for month in self.current_pending_months[
                        till_index:from_index + 1]:
                    all_fine_months.append([month])

                transact_date = str(self.date_line.date().toPyDate())

                total_fine = 0
                for month in all_fine_months:
                    fine = calculate_fine(
                        month=month[0], transact_date=fix_date(transact_date))
                    month = month.append(fine)

                    total_fine += fine * 50

                self.fine_line.setText(str(total_fine))
                self.set_fine_tip(all_fine_months=all_fine_months)

            if self.save_button is not None:
                self.save_button.setEnabled(True)

    def set_fine_tip(self, all_fine_months: list):
        tool_line = ''

        for month in all_fine_months:
            tool_line += f"{month[0]} x {month[1]}\n"

        self.fine_line.setToolTip(tool_line)

    def set_total(self):
        if not self.presetting:

            if len(self.amount_line.text()) > 0:
                amount = float(self.amount_line.text())
            else:
                amount = 0

            if len(self.fine_line.text()) > 0:
                fine = int(self.fine_line.text())
            else:
                fine = 0

            self.total_label.setText(f"TOTAL PAYABLE AMOUNT : {amount + fine}")

    def print_receipt(self):
        receipt_id = self.receipt_id.text()
        design_receipt(receipt_id=f"{receipt_id}", send=False)

        user = os.environ['USERPROFILE']
        path = user + '\\Desktop\\SocietyERP\\Receipts'

        subprocess.Popen(rf'explorer /select,{path}')

        self.receipt_id.setText("")
        self.receipt_id.setFocus()

        self.print_button.setEnabled(False)
        self.edit_button.setEnabled(False)
        self.resend_button.setEnabled(False)

    def resend_receipt(self):
        receipt_id = self.receipt_id.text()

        fee_month = str(self.month_combo.currentText())

        if self.month_till_combo.isEnabled():
            fee_till = self.month_till_combo.currentText()
            month = f"{fee_month}-{fee_till}"

        else:
            month = fee_month

        flat = str(self.flat_combo.currentText())

        self.status.setText("Generating receipt")
        self.bar.setValue(40)
        design_receipt(receipt_id=f"{receipt_id}")

        self.status.setText(
            "Sending the receipt to the member. (Depends on your internet connection)"
        )
        self.bar.setValue(75)
        email_status = send_receipt(flat=flat, month=month, updated=True)

        if email_status:
            self.bar.setValue(0)
            self.status.setText("Done !")

            self.receipt_id.setText("")
            self.flat_combo.setCurrentIndex(0)
            self.name_value.setText("")
            self.amount_line.setText('0')
            self.fine_line.setText('0')
            self.receipt_id.setFocus()

        else:
            reply = QMessageBox()
            reply.setIcon(QMessageBox.Warning)
            reply.setText(
                "The system cannot access the internet. Make sure you have an active connection, or any firewall"
                "feature blocking the access.")
            reply.setStandardButtons(QMessageBox.Retry)
            reply.setWindowTitle("INTERNET")
            reply.exec_()

    def disable(self):
        self.finance_entry_group0.setEnabled(False)
        self.finance_entry_group1.setEnabled(False)
        self.home_button.setEnabled(False)
        self.home_button.setEnabled(False)
        self.mode_label.setEnabled(False)
        self.mode_combo.setEnabled(False)
        self.ref_label.setEnabled(False)
        self.ref_line.setEnabled(False)
        self.save_button.setEnabled(False)

    def enable(self):
        self.finance_entry_group0.setEnabled(True)
        self.finance_entry_group1.setEnabled(True)
        self.home_button.setEnabled(True)
        self.home_button.setEnabled(True)
        self.mode_label.setEnabled(True)
        self.mode_combo.setEnabled(True)
        self.ref_label.setEnabled(True)
        self.ref_line.setEnabled(True)
        self.save_button.setEnabled(True)
Пример #10
0
class BaseItemDialog(QDialog):
    '''
    Abstract Dialog for all radio items.
    '''
    def __init__(self, parent, **kwargs):
        super().__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)

        self.modified = False
        self.structure = {}

        self.initStructure(kwargs)
        self.initUi()
        self.resetValues()

    def initStructure(self, kwargs):
        for attr, item in self.parent().columns.items():
            original = kwargs.get(attr, '')
            self.structure[attr] = {}
            self.structure[attr]['original'] = original
            self.structure[attr]['widgets'] = {}
            self.structure[attr]['widgets']['label'] = QLabel(self)
            self.structure[attr]['widgets']['label'].setText(item['header'])
            if item['editable']:
                widgets = self.structure[attr]['widgets']
                widgets['field'] = QLineEdit(self)
                widgets['field'].textEdited.connect(self.dataModified)
            else:
                self.structure[attr]['widgets']['field'] = QLabel(self)

    def initUi(self):
        name = self.parent().name.capitalize()
        self.setObjectName('dialog' + name)

        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setObjectName('verticalLayout' + name)

        self.formLayout = QFormLayout()
        self.formLayout.setObjectName('formLayout' + name)

        # Labels / Line Edits for item model.
        for item in self.structure.values():
            self.formLayout.addRow(item['widgets']['label'],
                                   item['widgets']['field'])
            spacer = QSpacerItem(20, 40, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)
            self.formLayout.addItem(spacer)

        # Button Box
        self.buttonBox = QDialogButtonBox(self)
        self.buttonBox.setObjectName('buttonBox' + name)
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Apply
                                          | QDialogButtonBox.Cancel
                                          | QDialogButtonBox.Ok
                                          | QDialogButtonBox.Reset)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        apply = self.buttonBox.button(QDialogButtonBox.Apply)
        apply.clicked.connect(self.saveItem)
        apply.setEnabled(False)
        reset = self.buttonBox.button(QDialogButtonBox.Reset)
        reset.clicked.connect(self.resetValues)

        self.verticalLayout.addLayout(self.formLayout)
        self.verticalLayout.addWidget(self.buttonBox)

        self.retranslateUi()

    def dataModified(self, *args, **kwargs):
        self.modified = True
        self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(True)

    def resetValues(self):
        for attr, item in self.structure.items():
            if attr == 'id' and item['original'] == '':
                font = QFont()
                font.setBold(True)
                font.setWeight(75)
                font.setItalic(True)
                item['widgets']['field'].setFont(font)
                item['widgets']['field'].setText('[NEW ITEM]')
            else:
                item['widgets']['field'].setText(str(item['original']))

        self.modified = False
        self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(False)

    def saveItem(self):
        endpoint = self.parent().plural
        current_data = {}
        for attr, item in self.structure.items():
            if attr is not 'id':
                current_data[attr] = item['widgets']['field'].text()

        if self.structure['id']['original'] == '':
            status, results = post_server_data(endpoint, current_data)
            current_data['id'] = results['id']
        else:
            current_data['id'] = self.structure['id']['original']
            status, results = put_server_data(
                endpoint + '/' + str(current_data['id']), current_data)

        if status in [200, 201]:
            for attr, item in self.structure.items():
                item['original'] = current_data[attr]
            self.resetValues()
            self.modified = False
            self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(False)

    def accept(self):
        self.saveItem()
        self.done(QDialog.Accepted)

    def reject(self):
        self.done(QDialog.Rejected)

    def retranslateUi(self):
        '''Translate labels into native language and assign them to widgets.'''
        _ = QCoreApplication.translate
        name = self.parent().name.capitalize()

        # Dialog title
        self.setWindowTitle(_('Client', 'Edit ' + name))