import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout,…
- User
import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QListWidget, QMessageBox, QInputDialog, QGridLayout
class MinecraftInventorySystem(QWidget): MAX_STACK_LIMIT = 64
def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle('Minecraft Inventory System') self.setGeometry(100, 100, 600, 400) # Widgets self.item_name_label = QLabel('Minecraft Block:') self.item_name_edit = QLineEdit() self.quantity_label = QLabel('Quantity:') self.quantity_edit = QLineEdit() self.add_button = QPushButton('Mine') self.view_button = QPushButton('Inspect') self.update_button = QPushButton('Craft') self.delete_button = QPushButton('Drop') self.item_list = QListWidget() # Layout layout = QVBoxLayout() form_layout = QGridLayout() form_layout.addWidget(self.item_name_label, 0, 0) form_layout.addWidget(self.item_name_edit, 0, 1) form_layout.addWidget(self.quantity_label, 1, 0) form_layout.addWidget(self.quantity_edit, 1, 1) layout.addLayout(form_layout) button_layout = QHBoxLayout() button_layout.addWidget(self.add_button) button_layout.addWidget(self.view_button) button_layout.addWidget(self.update_button) button_layout.addWidget(self.delete_button) layout.addLayout(button_layout) layout.addWidget(self.item_list) self.setLayout(layout) # Connect buttons to functions self.add_button.clicked.connect(self.mine_item) self.view_button.clicked.connect(self.inspect_items) self.update_button.clicked.connect(self.craft_item) self.delete_button.clicked.connect(self.drop_item) def mine_item(self): item_name = self.item_name_edit.text() quantity = int(self.quantity_edit.text()) if item_name and quantity: if quantity > self.MAX_STACK_LIMIT: QMessageBox.warning(self, 'Oops', 'Quantity cannot exceed Minecraft Stack Limit of 64.') else: item_text = f'{item_name} x{quantity}' self.item_list.addItem(item_text) self.item_name_edit.clear() self.quantity_edit.clear() else: QMessageBox.warning(self, 'Oops', 'Please enter a Minecraft block and quantity.') def inspect_items(self): selected_item = self.item_list.currentItem() if selected_item: QMessageBox.information(self, 'Inspect Item', f'Selected Item: {selected_item.text()}') else: QMessageBox.warning(self, 'Oops', 'Please select a block to inspect.') def craft_item(self): selected_item = self.item_list.currentItem() if selected_item: new_item_name, ok1 = QInputDialog.getText(self, 'Craft New Block', 'Enter new block name:', QLineEdit.Normal, selected_item.text().split('x')[0]) new_quantity, ok2 = QInputDialog.getInt(self, 'Craft Quantity', 'Enter new quantity:', int(selected_item.text().split('x')[1])) if ok1 and ok2: if new_quantity <= self.MAX_STACK_LIMIT: selected_item.setText(f'{new_item_name.strip()} x{new_quantity}') else: QMessageBox.warning(self, 'Oops', 'The quantity entered exceeds the stack limit of 64.') else: QMessageBox.warning(self, 'Oops', 'Please select a block to craft.') def drop_item(self): selected_item = self.item_list.currentItem() if selected_item: self.item_list.takeItem(self.item_list.row(selected_item)) else: QMessageBox.warning(self, 'Oops', 'Please select a block to drop.') - Assistant
The code you have provided is a simple PyQt5 implementation of a Minecraft-like inventory system interface. The program creates a window with several widgets that allow the user to add items to an inventory, inspect an item, craft a new item, and drop an item. Below is a brief overview of the code structure and functionality:
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.