Exemplo n.º 1
0
    def add_purchase_row(
        self,
        unit_type: UnitType,
        layout: QGridLayout,
        row: int,
    ) -> None:
        exist = QGroupBox()
        exist.setProperty("style", "buy-box")
        exist.setMaximumHeight(36)
        exist.setMinimumHeight(36)
        existLayout = QHBoxLayout()
        exist.setLayout(existLayout)

        existing_units = self.cp.base.total_units_of_type(unit_type)

        unitName = QLabel(f"<b>{unit_type.name}</b>")
        unitName.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

        existing_units = QLabel(str(existing_units))
        existing_units.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        self.existing_units_labels[unit_type] = existing_units

        price = QLabel(f"<b>$ {unit_type.price}</b> M")
        price.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        purchase_group = PurchaseGroup(unit_type, self)
        self.purchase_groups[unit_type] = purchase_group

        info = QGroupBox()
        info.setProperty("style", "buy-box")
        info.setMaximumHeight(36)
        info.setMinimumHeight(36)
        infolayout = QHBoxLayout()
        info.setLayout(infolayout)

        unitInfo = QPushButton("i")
        unitInfo.setProperty("style", "btn-info")
        unitInfo.setMinimumSize(16, 16)
        unitInfo.setMaximumSize(16, 16)
        unitInfo.clicked.connect(lambda: self.info(unit_type))
        unitInfo.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        existLayout.addWidget(unitName)
        existLayout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))
        existLayout.addWidget(existing_units)
        existLayout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))
        existLayout.addWidget(price)

        infolayout.addWidget(unitInfo)

        layout.addWidget(exist, row, 1)
        layout.addWidget(purchase_group, row, 2)
        layout.addWidget(info, row, 3)
    def add_unit_row(
        self,
        unit_type: GroundUnitType,
        layout: QGridLayout,
        row: int,
    ) -> None:
        exist = QGroupBox()
        exist.setProperty("style", "buy-box")
        exist.setMaximumHeight(36)
        exist.setMinimumHeight(36)
        origin_inventory_layout = QHBoxLayout()
        exist.setLayout(origin_inventory_layout)

        origin_inventory = self.cp.base.total_units_of_type(unit_type)

        unit_name = QLabel(f"<b>{unit_type.name}</b>")
        unit_name.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

        origin_inventory_label = QLabel(str(origin_inventory))
        origin_inventory_label.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        def increase(controls: TransferControls):
            nonlocal origin_inventory
            nonlocal origin_inventory_label
            if not origin_inventory:
                return

            self.transfers[unit_type] += 1
            origin_inventory -= 1
            controls.set_quantity(self.transfers[unit_type])
            origin_inventory_label.setText(str(origin_inventory))
            self.transfer_quantity_changed.emit()

        def decrease(controls: TransferControls):
            nonlocal origin_inventory
            nonlocal origin_inventory_label
            if not controls.quantity:
                return

            self.transfers[unit_type] -= 1
            origin_inventory += 1
            controls.set_quantity(self.transfers[unit_type])
            origin_inventory_label.setText(str(origin_inventory))
            self.transfer_quantity_changed.emit()

        transfer_controls = TransferControls("->", increase, "<-", decrease)

        origin_inventory_layout.addWidget(unit_name)
        origin_inventory_layout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))
        origin_inventory_layout.addWidget(origin_inventory_label)
        origin_inventory_layout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))

        layout.addWidget(exist, row, 1)
        layout.addWidget(transfer_controls, row, 2)
Exemplo n.º 3
0
    def add_purchase_row(self, unit_type, layout, row):

        exist = QGroupBox()
        exist.setProperty("style", "buy-box")
        exist.setMaximumHeight(36)
        exist.setMinimumHeight(36)
        existLayout = QHBoxLayout()
        exist.setLayout(existLayout)

        existing_units = self.cp.base.total_units_of_type(unit_type)
        scheduled_units = self.deliveryEvent.units.get(unit_type, 0)

        unitName = QLabel("<b>" + db.unit_type_name_2(unit_type) + "</b>")
        unitName.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

        existing_units = QLabel(str(existing_units))
        existing_units.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        amount_bought = QLabel("<b>{}</b>".format(str(scheduled_units)))
        amount_bought.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        self.existing_units_labels[unit_type] = existing_units
        self.bought_amount_labels[unit_type] = amount_bought

        price = QLabel("<b>$ {:02d}</b> m".format(db.PRICES[unit_type]))
        price.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        buysell = QGroupBox()
        buysell.setProperty("style", "buy-box")
        buysell.setMaximumHeight(36)
        buysell.setMinimumHeight(36)
        buysellayout = QHBoxLayout()
        buysell.setLayout(buysellayout)

        buy = QPushButton("+")
        buy.setProperty("style", "btn-buy")
        buy.setMinimumSize(16, 16)
        buy.setMaximumSize(16, 16)
        buy.clicked.connect(lambda: self.buy(unit_type))
        buy.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        sell = QPushButton("-")
        sell.setProperty("style", "btn-sell")
        sell.setMinimumSize(16, 16)
        sell.setMaximumSize(16, 16)
        sell.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
        sell.clicked.connect(lambda: self.sell(unit_type))

        existLayout.addWidget(unitName)
        existLayout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))
        existLayout.addWidget(existing_units)
        existLayout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))
        existLayout.addWidget(price)

        buysellayout.addWidget(sell)
        buysellayout.addWidget(amount_bought)
        buysellayout.addWidget(buy)

        layout.addWidget(exist, row, 1)
        layout.addWidget(buysell, row, 2)

        return row + 1
Exemplo n.º 4
0
    def add_purchase_row(self, unit_type: Type[UnitType], layout: QLayout,
                         row: int, disabled: bool = False) -> int:
        exist = QGroupBox()
        exist.setProperty("style", "buy-box")
        exist.setMaximumHeight(36)
        exist.setMinimumHeight(36)
        existLayout = QHBoxLayout()
        exist.setLayout(existLayout)

        existing_units = self.cp.base.total_units_of_type(unit_type)
        scheduled_units = self.pending_deliveries.units.get(unit_type, 0)

        unitName = QLabel("<b>" + db.unit_get_expanded_info(self.game_model.game.player_country, unit_type, 'name') + "</b>")
        unitName.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

        existing_units = QLabel(str(existing_units))
        existing_units.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        amount_bought = QLabel("<b>{}</b>".format(str(scheduled_units)))
        amount_bought.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        self.existing_units_labels[unit_type] = existing_units
        self.bought_amount_labels[unit_type] = amount_bought

        price = QLabel("<b>$ {:02d}</b> m".format(db.PRICES[unit_type]))
        price.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        buysell = QGroupBox()
        buysell.setProperty("style", "buy-box")
        buysell.setMaximumHeight(36)
        buysell.setMinimumHeight(36)
        buysellayout = QHBoxLayout()
        buysell.setLayout(buysellayout)

        buy = QPushButton("+")
        buy.setProperty("style", "btn-buy")
        buy.setDisabled(disabled)
        buy.setMinimumSize(16, 16)
        buy.setMaximumSize(16, 16)
        buy.clicked.connect(lambda: self.buy(unit_type))
        buy.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        sell = QPushButton("-")
        sell.setProperty("style", "btn-sell")
        sell.setDisabled(disabled)
        sell.setMinimumSize(16, 16)
        sell.setMaximumSize(16, 16)
        sell.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
        sell.clicked.connect(lambda: self.sell(unit_type))

        info = QGroupBox()
        info.setProperty("style", "buy-box")
        info.setMaximumHeight(36)
        info.setMinimumHeight(36)
        infolayout = QHBoxLayout()
        info.setLayout(infolayout)
        
        unitInfo = QPushButton("i")
        unitInfo.setProperty("style", "btn-info")
        unitInfo.setDisabled(disabled)
        unitInfo.setMinimumSize(16, 16)
        unitInfo.setMaximumSize(16, 16)
        unitInfo.clicked.connect(lambda: self.info(unit_type))
        unitInfo.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        existLayout.addWidget(unitName)
        existLayout.addItem(QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))
        existLayout.addWidget(existing_units)
        existLayout.addItem(QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum))
        existLayout.addWidget(price)

        buysellayout.addWidget(sell)
        buysellayout.addWidget(amount_bought)
        buysellayout.addWidget(buy)

        infolayout.addWidget(unitInfo)

        layout.addWidget(exist, row, 1)
        layout.addWidget(buysell, row, 2)
        layout.addWidget(info, row, 3)

        return row + 1
Exemplo n.º 5
0
class Window(QWidget):
    def __init__(self):
        # call the constructor of the parent (QWidget)
        super().__init__()

        # check if it the first time for user to plot
        self.firstTime = False

        # set title  and geometry for the window
        self.setWindowTitle("Function Plotter")
        self.setGeometry(500, 400, 400, 200)

        # give orange background to the window
        palette = self.palette()
        palette.setColor(QPalette.Window, QColor(150, 150, 150))
        self.setPalette(palette)
        self.setAutoFillBackground(True)

        # set minimum width and height for the window
        self.setMinimumHeight(200)
        self.setMinimumWidth(400)
        self.setMaximumHeight(200)
        self.setMaximumWidth(400)

        # set icon for the application at run time and center the application window with the primary screen
        self.setIcon()
        self.center()

        # setup the grid layout design and components
        self.createGridLayout()
        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.groupBox)
        self.vbox.setAlignment(Qt.AlignCenter | Qt.AlignTop)
        self.setLayout(self.vbox)

    # set icon for the application
    def setIcon(self):
        appIcon = QIcon("icon.png")
        self.setWindowIcon(appIcon)

    # reading the data from text input and apply check tests
    def readData(self):
        # read the equation and check if there is an actual input
        equation = self.equationInput.text()
        if equation == '':
            self.aboutBox("Empty section", "Please enter an equation")
            return
        # remove spaces from the equation and check if the equation has valid variable name
        equation = removeSpaces(equation)
        varName, _ = getVariableName(equation)
        check, error = checkVarName(equation, varName)
        if not check:
            self.aboutBox("Wrong equation", error)
            return

        # check min and max value if it's a real number and the text input isn't empty
        maxValue = self.maxInput.text()
        if maxValue == '':
            self.aboutBox("Empty section", "Please enter maximum value")
            return
        try:
            maxValue = float(maxValue)
        except ValueError:
            self.aboutBox(
                "Wrong range",
                "Invalid value for maximum, please enter float or integer value"
            )
            return
        minValue = self.minInput.text()
        if minValue == '':
            self.aboutBox("Empty section", "Please enter minimum value")
            return
        try:
            minValue = float(minValue)
        except ValueError:
            self.aboutBox(
                "Wrong range",
                "Invalid value for minimum, please enter float or integer value"
            )
            return

        # the max value should be greater than min value
        if minValue >= maxValue:
            self.aboutBox("Wrong range",
                          "Your maximum value should be greater than minimum")
            return

        # process the equation by trying to solve it with max value and check if there is error with operatos, operands or parentheses
        ops = trimTerms(equation, varName)
        temp_ops = replaceVar(ops, varName, str(maxValue))
        testVal, error = functionCalculator(temp_ops)

        if error != None:
            self.aboutBox("Evaluation error", error)
            return

        # function to evaluate f(x) array and return f(x) and x lists to be plotted
        fx, x = self.evaluateFunction(ops, maxValue, minValue, varName)

        # plot the graph
        self.plotGraph(fx, x, varName)

    def plotGraph(self, fx, x, varName):
        # remove the old figure if user request another equation
        if self.firstTime:
            self.fig.clear()
            self.vbox.removeWidget(self.toolbar)
            self.vbox.removeWidget(self.canvas)

        # set first time to be True, to remove the old figures
        self.firstTime = True

        # set the figure and toolbar and add it to the window
        self.fig = Figure(figsize=(7, 5),
                          dpi=65,
                          facecolor=(1, 1, 1),
                          edgecolor=(0, 0, 0))
        self.canvas = FigureCanvas(self.fig)
        self.toolbar = NavigationToolbar(self.canvas, self)
        self.vbox.addWidget(self.toolbar)
        self.vbox.addWidget(self.canvas)

        # set new geometry to the window to fit the graph
        self.resize(400, 500)
        self.setMinimumHeight(500)
        self.setMaximumHeight(500)

        # plot the graph and set the labels
        self.ax = self.fig.add_subplot(111)
        self.ax.plot(x, fx)
        if varName == '':
            varName = 'x'
        self.ax.set_xlabel(varName)
        self.ax.set_ylabel('f(' + varName + ')')

    # QMessageBox which shows any error for the user
    def aboutBox(self, title, error):
        QMessageBox.about(self, title, error)

    def evaluateFunction(self, ops, maxVal, minVal, varName):
        # make array with start = minVal, end, maxVal and step for 0.25 for some accuracy
        x = np.arange(minVal, maxVal, 0.25)
        fx = []
        # loop over each number(i) and evaluate f(i) then add it to f(x) list
        for number in x:
            temp_ops = replaceVar(ops, varName, number)
            val, _ = functionCalculator(temp_ops)
            fx.append(val)

        return fx, x

    # to center the application window at the beginning
    def center(self):
        qRect = self.frameGeometry()
        centerPoint = QtGui.QGuiApplication.primaryScreen().availableGeometry(
        ).center()
        qRect.moveCenter(centerPoint)
        self.move(qRect.topLeft())

    def createGridLayout(self):
        # make group box with headline then add the gridlayout to it
        self.groupBox = QGroupBox("Please fill next sections")
        self.groupBox.setFont(QFont("Helvetica", 12))
        self.groupBox.setMaximumWidth(400)
        self.groupBox.setMaximumHeight(200)
        # create gridlayout with spacing between columns and rows
        gridLayout = QGridLayout()
        gridLayout.setSpacing(10)

        # set equation text input
        self.equationInput = QLineEdit()
        self.equationInput.setMaximumHeight(30)
        #self.equationInput.setMaximumWidth(175)
        self.equationInput.setPlaceholderText("Enter your equation")
        gridLayout.addWidget(self.equationInput, 0, 0, 1, 0)

        # set max value text input
        self.maxInput = QLineEdit()
        self.maxInput.setMaximumHeight(30)
        self.maxInput.setMaximumWidth(175)
        self.maxInput.setPlaceholderText("Enter maximum value")
        gridLayout.addWidget(self.maxInput, 1, 0)

        # set min value text input
        self.minInput = QLineEdit()
        self.minInput.setMaximumHeight(30)
        self.minInput.setMaximumWidth(175)
        self.minInput.setPlaceholderText("Enter minimum value")
        gridLayout.addWidget(self.minInput, 1, 1)

        # set Plot push button with green color and an icon
        plotButton = QPushButton("Plot")
        plotButton.setStyleSheet("background-color: green")
        plotButton.setIcon(QIcon("curve.png"))
        plotButton.setMaximumHeight(30)
        plotButton.setMaximumWidth(75)
        # when button is clicked, call readData and then will plot the function
        plotButton.clicked.connect(self.readData)
        gridLayout.addWidget(plotButton, 2, 0)

        # add gridlayout to the group box
        self.setLayout(gridLayout)
        self.groupBox.setLayout(gridLayout)
Exemplo n.º 6
0
class IpInformation(QWidget):
    def __init__(self):
        super(IpInformation, self).__init__()

        # Use language settings
        self.ml = ManageLng()

        main_layout = QGridLayout()
        self.setLayout(main_layout)

        # Prefix-mask-conversion group box
        self.prefix_mask_box = QGroupBox(
            self.ml.get_tr_text("tab_ip_information_prefix_mask_conv"))
        self.prefix_mask_box.setMaximumHeight(90)
        main_layout.addWidget(self.prefix_mask_box, 0, 0)
        prefix_mask_box_layout = QGridLayout()
        prefix_mask_box_layout.setContentsMargins(200, 20, 200, 20)
        prefix_mask_box_layout.setHorizontalSpacing(30)
        self.prefix_mask_box.setLayout(prefix_mask_box_layout)

        self.prefix_input = QLineEdit()
        self.prefix_input.setMaxLength(3)
        self.prefix_input.setAlignment(Qt.AlignCenter)
        self.prefix_input.setPlaceholderText(
            self.ml.get_tr_text("tab_ip_information_prefix_ptext"))
        prefix_mask_box_layout.addWidget(self.prefix_input, 0, 0)
        self.mask_input = QLineEdit()
        self.mask_input.setMaxLength(15)
        self.mask_input.setAlignment(Qt.AlignCenter)
        self.mask_input.setPlaceholderText(
            self.ml.get_tr_text("tab_ip_information_mask_ptext"))
        prefix_mask_box_layout.addWidget(self.mask_input, 0, 1)

        self.convert_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_conv_btn"))
        self.convert_btn.setIcon(QIcon("static/images/exchange.png"))
        self.convert_btn.clicked.connect(self.convert_action)
        self.prefix_input.returnPressed.connect(self.convert_action)
        self.mask_input.returnPressed.connect(self.convert_action)
        prefix_mask_box_layout.addWidget(self.convert_btn,
                                         0,
                                         2,
                                         alignment=Qt.AlignLeft)

        # IP information group box
        self.ip_information_box = QGroupBox(
            self.ml.get_tr_text("tab_ip_information_ipinfo_gbox"))
        main_layout.addWidget(self.ip_information_box, 1, 0)
        ip_information_box_layout = QGridLayout()
        ip_information_box_layout.setContentsMargins(80, 80, 80, 80)
        ip_information_box_layout.setHorizontalSpacing(30)
        ip_information_box_layout.setVerticalSpacing(15)
        self.ip_information_box.setLayout(ip_information_box_layout)

        self.ip_address_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_ipadd_lab"))
        ip_information_box_layout.addWidget(self.ip_address_label,
                                            0,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.ip_address_textfield = QLineEdit()
        self.ip_address_textfield.setPlaceholderText("192.168.1.100/24")
        self.ip_address_textfield.setAlignment(Qt.AlignCenter)
        self.ip_address_textfield.setMaxLength(18)
        ip_information_box_layout.addWidget(self.ip_address_textfield, 0, 1)

        self.get_info_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_getinfo_btn"))
        self.get_info_btn.setIcon(QIcon("static/images/get_info.png"))
        self.get_info_btn.clicked.connect(self.get_info_action)
        self.ip_address_textfield.returnPressed.connect(self.get_info_action)
        ip_information_box_layout.addWidget(self.get_info_btn, 0, 2)

        self.ip_class_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_ipclass_lab"))
        ip_information_box_layout.addWidget(self.ip_class_label,
                                            1,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.ip_class_textfield = QLineEdit()
        self.ip_class_textfield.setReadOnly(True)
        self.ip_class_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(self.ip_class_textfield, 1, 1)
        self.ip_class_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.ip_class_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.ip_class_copy_btn.clicked.connect(
            lambda: copy_action(self.ip_class_textfield.text()))
        ip_information_box_layout.addWidget(self.ip_class_copy_btn, 1, 2)

        self.ip_type_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_iptype_lab"))
        ip_information_box_layout.addWidget(self.ip_type_label,
                                            2,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.ip_type_textfield = QLineEdit()
        self.ip_type_textfield.setReadOnly(True)
        self.ip_type_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(self.ip_type_textfield, 2, 1)
        self.ip_type_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.ip_type_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.ip_type_copy_btn.clicked.connect(
            lambda: copy_action(self.ip_type_textfield.text()))
        ip_information_box_layout.addWidget(self.ip_type_copy_btn, 2, 2)

        self.network_address_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_netadd_lab"))
        ip_information_box_layout.addWidget(self.network_address_label,
                                            3,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.network_address_textfield = QLineEdit()
        self.network_address_textfield.setReadOnly(True)
        self.network_address_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(self.network_address_textfield, 3,
                                            1)
        self.network_address_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.network_address_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.network_address_copy_btn.clicked.connect(
            lambda: copy_action(self.network_address_textfield.text()))
        ip_information_box_layout.addWidget(self.network_address_copy_btn, 3,
                                            2)

        self.subnet_mask_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_mask_lab"))
        ip_information_box_layout.addWidget(self.subnet_mask_label,
                                            4,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.subnet_mask_textfield = QLineEdit()
        self.subnet_mask_textfield.setReadOnly(True)
        self.subnet_mask_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(self.subnet_mask_textfield, 4, 1)
        self.subnet_mask_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.subnet_mask_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.subnet_mask_copy_btn.clicked.connect(
            lambda: copy_action(self.subnet_mask_textfield.text()))
        ip_information_box_layout.addWidget(self.subnet_mask_copy_btn, 4, 2)

        self.first_addressable_ip_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_firstip_lab"))
        ip_information_box_layout.addWidget(self.first_addressable_ip_label,
                                            5,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.first_addressable_ip_textfield = QLineEdit()
        self.first_addressable_ip_textfield.setReadOnly(True)
        self.first_addressable_ip_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(
            self.first_addressable_ip_textfield, 5, 1)
        self.first_addressable_ip_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.first_addressable_ip_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.first_addressable_ip_copy_btn.clicked.connect(
            lambda: copy_action(self.first_addressable_ip_textfield.text()))
        ip_information_box_layout.addWidget(self.first_addressable_ip_copy_btn,
                                            5, 2)

        self.last_addressable_ip_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_lastip_lab"))
        ip_information_box_layout.addWidget(self.last_addressable_ip_label,
                                            6,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.last_addressable_ip_textfield = QLineEdit()
        self.last_addressable_ip_textfield.setReadOnly(True)
        self.last_addressable_ip_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(self.last_addressable_ip_textfield,
                                            6, 1)
        self.last_addressable_ip_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.last_addressable_ip_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.last_addressable_ip_copy_btn.clicked.connect(
            lambda: copy_action(self.last_addressable_ip_textfield.text()))
        ip_information_box_layout.addWidget(self.last_addressable_ip_copy_btn,
                                            6, 2)

        self.broadcast_address_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_bcastip_lab"))
        ip_information_box_layout.addWidget(self.broadcast_address_label,
                                            7,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.broadcast_address_textfield = QLineEdit()
        self.broadcast_address_textfield.setReadOnly(True)
        self.broadcast_address_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(self.broadcast_address_textfield,
                                            7, 1)
        self.broadcast_address_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.broadcast_address_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.broadcast_address_copy_btn.clicked.connect(
            lambda: copy_action(self.broadcast_address_textfield.text()))
        ip_information_box_layout.addWidget(self.broadcast_address_copy_btn, 7,
                                            2)

        self.next_network_address_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_nextnetip_lab"))
        ip_information_box_layout.addWidget(self.next_network_address_label,
                                            8,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.next_network_address_textfield = QLineEdit()
        self.next_network_address_textfield.setReadOnly(True)
        self.next_network_address_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(
            self.next_network_address_textfield, 8, 1)
        self.next_network_address_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.next_network_address_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.next_network_address_copy_btn.clicked.connect(
            lambda: copy_action(self.next_network_address_textfield.text()))
        ip_information_box_layout.addWidget(self.next_network_address_copy_btn,
                                            8, 2)

        self.max_endpoint_label = QLabel(
            self.ml.get_tr_text("tab_ip_information_maxend_lab"))
        ip_information_box_layout.addWidget(self.max_endpoint_label,
                                            9,
                                            0,
                                            alignment=Qt.AlignCenter)
        self.max_endpoint_textfield = QLineEdit()
        self.max_endpoint_textfield.setReadOnly(True)
        self.max_endpoint_textfield.setAlignment(Qt.AlignCenter)
        ip_information_box_layout.addWidget(self.max_endpoint_textfield, 9, 1)
        self.max_endpoint_copy_btn = QPushButton(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.max_endpoint_copy_btn.setIcon(
            QIcon("static/images/copy_clipboard.png"))
        self.max_endpoint_copy_btn.clicked.connect(
            lambda: copy_action(self.max_endpoint_textfield.text()))
        ip_information_box_layout.addWidget(self.max_endpoint_copy_btn, 9, 2)

    def convert_action(self):
        if is_empty(self.prefix_input.text()) and \
                is_empty(self.mask_input.text()):
            PopupWindow("warning",
                        self.ml.get_tr_text("tab_ip_information_warning01"),
                        self.prefix_input)
        elif not is_empty(self.prefix_input.text()) and \
                not is_empty(self.mask_input.text()):
            if is_correct_prefix(self.prefix_input.text()):
                prefix_corrected = self.prefix_input.text().replace(
                    "/", "").replace("\\", "")
                self.mask_input.setText(get_mask_from_prefix(prefix_corrected))
            else:
                PopupWindow(
                    "warning",
                    self.ml.get_tr_text("tab_ip_information_warning02"),
                    self.prefix_input)
        else:
            if self.prefix_input.text():
                if is_correct_prefix(self.prefix_input.text()):
                    prefix_corrected = self.prefix_input.text().replace(
                        "/", "").replace("\\", "")
                    self.mask_input.setText(
                        get_mask_from_prefix(prefix_corrected))
                else:
                    PopupWindow(
                        "warning",
                        self.ml.get_tr_text("tab_ip_information_warning02"),
                        self.prefix_input)
            else:
                if is_correct_mask(self.mask_input.text()):
                    self.prefix_input.setText(
                        f"/{get_prefix_from_mask(self.mask_input.text())}")
                else:
                    PopupWindow(
                        "warning",
                        self.ml.get_tr_text("tab_ip_information_warning03"),
                        self.mask_input)

    def get_info_action(self):
        if is_empty(self.ip_address_textfield.text()):
            PopupWindow("warning",
                        self.ml.get_tr_text("tab_ip_information_warning04"),
                        self.ip_address_textfield)
        elif is_correct_ip_with_prefix(self.ip_address_textfield.text()):
            ip = self.ip_address_textfield.text().split("/")[0]
            ip_first_octet = int(str(ip).split(".")[0])
            prefix = self.ip_address_textfield.text().split("/")[1]

            if ip_first_octet == 127:
                PopupWindow(
                    "warning",
                    self.ml.get_tr_text("tab_ip_information_warning05"),
                    self.ip_address_textfield)
            elif 224 <= ip_first_octet <= 239:
                PopupWindow(
                    "warning",
                    self.ml.get_tr_text("tab_ip_information_warning06"),
                    self.ip_address_textfield)
            elif 240 <= ip_first_octet <= 254:
                PopupWindow(
                    "warning",
                    self.ml.get_tr_text("tab_ip_information_warning07"),
                    self.ip_address_textfield)
            elif ip_first_octet == 255:
                PopupWindow(
                    "warning",
                    self.ml.get_tr_text("tab_ip_information_warning08"),
                    self.ip_address_textfield)
            else:
                self.ip_class_textfield.setText(
                    self.ml.get_tr_text(get_ip_class(ip)))
                self.ip_type_textfield.setText(
                    self.ml.get_tr_text(get_ip_type(ip, prefix)))
                self.network_address_textfield.setText(
                    get_network_address(ip, prefix))
                self.subnet_mask_textfield.setText(
                    get_mask_from_prefix(prefix))
                self.first_addressable_ip_textfield.setText(
                    get_first_addressable_ip(ip, prefix))
                self.last_addressable_ip_textfield.setText(
                    get_last_addressable_ip(ip, prefix))
                self.broadcast_address_textfield.setText(
                    get_broadcast_ip(ip, prefix))
                self.next_network_address_textfield.setText(
                    get_next_network_ip(ip, prefix))
                self.max_endpoint_textfield.setText(
                    get_max_endpoint_formatted(prefix))
        else:
            PopupWindow("warning",
                        self.ml.get_tr_text("tab_ip_information_warning09"),
                        self.ip_address_textfield)

    def re_translate_ui(self, lang):
        self.ml = ManageLng(lang)

        if self.ip_address_textfield.text():
            ip = self.ip_address_textfield.text().split("/")[0]
            prefix = self.ip_address_textfield.text().split("/")[1]
        else:
            ip = None
            prefix = None

        self.prefix_mask_box.setTitle(
            self.ml.get_tr_text("tab_ip_information_prefix_mask_conv"))
        self.prefix_input.setPlaceholderText(
            self.ml.get_tr_text("tab_ip_information_prefix_ptext"))
        self.mask_input.setPlaceholderText(
            self.ml.get_tr_text("tab_ip_information_mask_ptext"))
        self.convert_btn.setText(
            self.ml.get_tr_text("tab_ip_information_conv_btn"))
        self.ip_information_box.setTitle(
            self.ml.get_tr_text("tab_ip_information_ipinfo_gbox"))
        self.ip_address_label.setText(
            self.ml.get_tr_text("tab_ip_information_ipadd_lab"))
        self.get_info_btn.setText(
            self.ml.get_tr_text("tab_ip_information_getinfo_btn"))
        self.ip_class_label.setText(
            self.ml.get_tr_text("tab_ip_information_ipclass_lab"))
        self.ip_class_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.ip_type_label.setText(
            self.ml.get_tr_text("tab_ip_information_iptype_lab"))
        self.ip_type_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.network_address_label.setText(
            self.ml.get_tr_text("tab_ip_information_netadd_lab"))
        self.network_address_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.subnet_mask_label.setText(
            self.ml.get_tr_text("tab_ip_information_mask_lab"))
        self.subnet_mask_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.first_addressable_ip_label.setText(
            self.ml.get_tr_text("tab_ip_information_firstip_lab"))
        self.first_addressable_ip_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.last_addressable_ip_label.setText(
            self.ml.get_tr_text("tab_ip_information_lastip_lab"))
        self.last_addressable_ip_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.broadcast_address_label.setText(
            self.ml.get_tr_text("tab_ip_information_bcastip_lab"))
        self.broadcast_address_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.next_network_address_label.setText(
            self.ml.get_tr_text("tab_ip_information_nextnetip_lab"))
        self.next_network_address_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))
        self.max_endpoint_label.setText(
            self.ml.get_tr_text("tab_ip_information_maxend_lab"))
        self.max_endpoint_copy_btn.setText(
            self.ml.get_tr_text("tab_ip_information_copy_btn"))

        if self.ip_class_textfield.text() and self.ip_type_textfield.text():
            self.ip_class_textfield.setText(
                self.ml.get_tr_text(get_ip_class(ip)))
            self.ip_type_textfield.setText(
                self.ml.get_tr_text(get_ip_type(ip, prefix)))
    def add_purchase_row(
        self,
        item: TransactionItemType,
        layout: QGridLayout,
        row: int,
    ) -> None:
        exist = QGroupBox()
        exist.setProperty("style", "buy-box")
        exist.setMaximumHeight(72)
        exist.setMinimumHeight(36)
        existLayout = QHBoxLayout()
        existLayout.setSizeConstraint(QLayout.SetMinimumSize)
        exist.setLayout(existLayout)

        existing_units = self.current_quantity_of(item)

        unitName = QLabel(f"<b>{self.display_name_of(item, multiline=True)}</b>")
        unitName.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        )

        existing_units = QLabel(str(existing_units))
        existing_units.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        self.existing_units_labels[item] = existing_units

        price = QLabel(f"<b>$ {self.price_of(item)}</b> M")
        price.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        purchase_group = PurchaseGroup(item, self)
        self.purchase_groups[item] = purchase_group

        info = QGroupBox()
        info.setProperty("style", "buy-box")
        info.setMaximumHeight(72)
        info.setMinimumHeight(36)
        infolayout = QHBoxLayout()
        info.setLayout(infolayout)

        unitInfo = QPushButton("i")
        unitInfo.setProperty("style", "btn-info")
        unitInfo.setMinimumSize(16, 16)
        unitInfo.setMaximumSize(16, 16)
        unitInfo.clicked.connect(lambda: self.info(item))
        unitInfo.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

        existLayout.addWidget(unitName)
        existLayout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum)
        )
        existLayout.addWidget(existing_units)
        existLayout.addItem(
            QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Minimum)
        )
        existLayout.addWidget(price)

        infolayout.addWidget(unitInfo)

        layout.addWidget(exist, row, 1)
        layout.addWidget(purchase_group, row, 2)
        layout.addWidget(info, row, 3)