class ObjectViewer(CustomChildWindow): def __init__(self, parent): super(ObjectViewer, self).__init__(parent, title="Object Viewer") self.spin_domain = Spinner(self, MAX_DOMAIN) self.spin_domain.valueChanged.connect(self.on_spin) self.spin_type = Spinner(self, MAX_TYPE) self.spin_type.valueChanged.connect(self.on_spin) self.spin_length = Spinner(self, MAX_LENGTH) self.spin_length.setDisabled(True) self.spin_length.valueChanged.connect(self.on_spin) _toolbar = QToolBar(self) _toolbar.addWidget(self.spin_domain) _toolbar.addWidget(self.spin_type) _toolbar.addWidget(self.spin_length) self.object_set_dropdown = QComboBox(_toolbar) self.object_set_dropdown.addItems(OBJECT_SET_ITEMS[1:]) self.object_set_dropdown.setCurrentIndex(0) self.graphic_set_dropdown = QComboBox(_toolbar) self.graphic_set_dropdown.addItems(GRAPHIC_SET_NAMES) self.graphic_set_dropdown.setCurrentIndex(1) self.object_set_dropdown.currentIndexChanged.connect( self.on_object_set) self.graphic_set_dropdown.currentIndexChanged.connect( self.on_graphic_set) _toolbar.addWidget(self.object_set_dropdown) _toolbar.addWidget(self.graphic_set_dropdown) self.addToolBar(_toolbar) self.drawing_area = ObjectDrawArea(self, 1) self.status_bar = QStatusBar(parent=self) self.status_bar.showMessage(self.drawing_area.current_object.name) self.setStatusBar(self.status_bar) self.drawing_area.update() self.block_list = BlockArray(self, self.drawing_area.current_object) central_widget = QWidget() central_widget.setLayout(QVBoxLayout()) central_widget.layout().addWidget(self.drawing_area) central_widget.layout().addWidget(self.block_list) self.setCentralWidget(central_widget) self.layout().setSizeConstraint(QLayout.SetFixedSize) return def set_object_and_graphic_set(self, object_set: int, graphics_set: int): self.object_set_dropdown.setCurrentIndex(object_set - 1) self.graphic_set_dropdown.setCurrentIndex(graphics_set) self.drawing_area.change_object_set(object_set) self.drawing_area.change_graphic_set(graphics_set) self.block_list.update_object(self.drawing_area.current_object) self.status_bar.showMessage(self.drawing_area.current_object.name) def on_object_set(self): object_set = self.object_set_dropdown.currentIndex() + 1 graphics_set = object_set self.set_object_and_graphic_set(object_set, graphics_set) def on_graphic_set(self): object_set = self.object_set_dropdown.currentIndex() + 1 graphics_set = self.graphic_set_dropdown.currentIndex() self.set_object_and_graphic_set(object_set, graphics_set) def set_object(self, domain: int, obj_index: int, secondary_length: int): object_data = bytearray(4) object_data[0] = domain << 5 object_data[1] = 0 object_data[2] = obj_index object_data[3] = secondary_length self.spin_domain.setValue(domain) self.spin_type.setValue(obj_index) self.spin_length.setValue(secondary_length) self.drawing_area.update_object(object_data) self.block_list.update_object(self.drawing_area.current_object) if self.drawing_area.current_object.is_4byte: self.spin_length.setEnabled(True) else: self.spin_length.setValue(0) self.spin_length.setEnabled(False) self.drawing_area.update() self.status_bar.showMessage(self.drawing_area.current_object.name) def on_spin(self, _): domain = self.spin_domain.value() obj_index = self.spin_type.value() secondary_length = self.spin_length.value() self.set_object(domain, obj_index, secondary_length)
class ObjectViewer(CustomChildWindow): def __init__(self, parent): super(ObjectViewer, self).__init__(parent, title="Object Viewer") self.spin_domain = Spinner(self, MAX_DOMAIN) self.spin_domain.valueChanged.connect(self.on_spin) self.spin_type = Spinner(self, MAX_TYPE) self.spin_type.valueChanged.connect(self.on_spin) self.spin_length = Spinner(self, MAX_LENGTH) self.spin_length.setDisabled(True) self.spin_length.valueChanged.connect(self.on_spin) _toolbar = QToolBar(self) _toolbar.addWidget(self.spin_domain) _toolbar.addWidget(self.spin_type) _toolbar.addWidget(self.spin_length) self.object_set_dropdown = QComboBox(_toolbar) self.object_set_dropdown.addItems(OBJECT_SET_ITEMS[1:]) self.object_set_dropdown.setCurrentIndex(0) self.graphic_set_dropdown = QComboBox(_toolbar) self.graphic_set_dropdown.addItems( [f"Graphics Set {gfx_set}" for gfx_set in range(32)]) self.graphic_set_dropdown.setCurrentIndex(1) self.object_set_dropdown.currentIndexChanged.connect( self.on_object_set) self.graphic_set_dropdown.currentIndexChanged.connect( self.on_graphic_set) _toolbar.addWidget(self.object_set_dropdown) _toolbar.addWidget(self.graphic_set_dropdown) self.addToolBar(_toolbar) self.object_set = 1 self.drawing_area = ObjectDrawArea(self, self.object_set) self.status_bar = QStatusBar(parent=self) self.status_bar.showMessage( self.drawing_area.current_object.description) self.setStatusBar(self.status_bar) self.setCentralWidget(self.drawing_area) self.drawing_area.update() self.layout().setSizeConstraint(QLayout.SetFixedSize) return def on_object_set(self): self.object_set = self.object_set_dropdown.currentIndex() + 1 gfx_set = self.object_set self.graphic_set_dropdown.setCurrentIndex(gfx_set) self.drawing_area.change_object_set(self.object_set) self.drawing_area.change_graphic_set(gfx_set) self.status_bar.showMessage( self.drawing_area.current_object.description) def on_graphic_set(self): gfx_set = self.graphic_set_dropdown.currentIndex() self.drawing_area.change_graphic_set(gfx_set) self.status_bar.showMessage( self.drawing_area.current_object.description) def on_spin(self, _): object_data = bytearray(4) object_data[0] = self.spin_domain.value() << 5 object_data[1] = 0 object_data[2] = self.spin_type.value() object_data[3] = self.spin_length.value() self.drawing_area.update_object(object_data) if self.drawing_area.current_object.is_4byte: self.spin_length.setEnabled(True) else: self.spin_length.setValue(0) self.spin_length.setEnabled(False) self.drawing_area.update() self.status_bar.showMessage( self.drawing_area.current_object.description)