def rename_lost_focus(self, item): # Check if name was changed if item.data.data.name != item.text: self.envedit_data.modify() # Replace textbox with list label item.data.data.name = item.text label = GUILabel() label.text_size = 12 label.receive_events = False label.set_text(item.data.data.name) item.data.child.remove_child(item.data.child.children[3]) item.data.child.add_child(label) item.data.update()
def use_stacked_labels(self): if self.child is not None: self.remove_child() self.set_child(GUIStackLayout(vertical=False)) self.child.bbox.height = self.bbox.height first_label = GUILabel() first_label.set_text_color(self.curr_text_color) first_label.receive_events = False self.child.add_child(first_label) cursor = GUIFrame() cursor.bbox.width = 1 cursor.set_bg_color((1, 1, 1, 1)) cursor.receive_events = False self.child.add_child(cursor) second_label = GUILabel() second_label.set_text_color(self.curr_text_color) second_label.receive_events = False self.child.add_child(second_label) self.update()
def add_button_handler(self, button): # Add new element to array self.component.property_vals[button.data].append("") # Add new field to list of elements element_layout = GUIStackLayout(vertical=False) element_layout.padding = 4 element_layout.bbox.height = 28 self.property_fields[button.data].add_child(element_layout) inner_property_val = GUITextBox() inner_property_val.data = { "parent": button.data, "index": len(self.component.property_vals[button.data]) - 1 } inner_property_val.set_text("") inner_property_val.on_text_changed = self.text_change_handler element_layout.add_child(inner_property_val) element_spacer = GUIComponent() element_spacer.bbox.width = 4 element_layout.add_child(element_spacer) del_button = GUIButton() del_button.padding = 3 del_button.bbox.width = 16 del_button.bbox.height = 20 del_button.set_normal_color((1, 0, 0, 0.8)) del_button.set_hover_color((1, 0.4, 0.4, 0.8)) del_button.set_pressed_color((0.4, 0, 0, 0.8)) del_button.on_click = self.element_del_button_handler del_button.data = element_layout del_button_label = GUILabel() del_button_label.set_text("X") del_button_label.receive_events = False del_button.set_child(del_button_label) element_layout.add_child(del_button)
def setup_drawer(self): if self.component is not None: for property in self.component.property_types: property_type = self.component.property_types[property] property_frame = GUIFrame() property_frame.bbox.height = 30 property_frame.padding = 4 self.properties_layout.add_child(property_frame) property_layout = GUIStackLayout(vertical=False) property_layout.bbox.height = 30 property_frame.set_child(property_layout) property_name = GUILabel() property_name.set_text(property + ":") property_layout.add_child(property_name) spacer = GUIComponent() spacer.bbox.width = 20 property_layout.add_child(spacer) if property_type == PropertyType.INT: property_val = GUINumberBox(use_int=True) property_val.text_box.data = property property_val.text_box.set_text( self.component.property_vals[property]) property_val.text_box.on_text_changed = self.text_change_handler self.property_fields[property] = property_val property_layout.add_child(property_val) elif property_type == PropertyType.FLOAT: property_val = GUINumberBox() property_val.text_box.data = property property_val.text_box.set_text( self.component.property_vals[property]) property_val.text_box.on_text_changed = self.text_change_handler self.property_fields[property] = property_val property_layout.add_child(property_val) elif property_type == PropertyType.BOOL: property_val = GUITextBox() property_val.data = property property_val.set_text( self.component.property_vals[property]) property_val.on_text_changed = self.text_change_handler self.property_fields[property] = property_val property_layout.add_child(property_val) elif property_type == PropertyType.STRING: property_val = GUITextBox() property_val.data = property property_val.set_text( self.component.property_vals[property]) property_val.on_text_changed = self.text_change_handler self.property_fields[property] = property_val property_layout.add_child(property_val) elif property_type == PropertyType.FILE: property_val = GUITextBox() property_val.data = property property_val.set_text( self.component.property_vals[property]) property_val.on_selected = self.file_open_handler self.property_fields[property] = property_val property_layout.add_child(property_val) elif property_type == PropertyType.ARRAY: property_val = GUIStackLayout() property_val.bbox.width = 124 add_button = GUIButton() add_button.padding = 2 add_button.bbox.width = 20 add_button.bbox.height = 20 add_button.data = property add_button.on_click = self.add_button_handler button_label = GUILabel() button_label.receive_events = False button_label.set_text("Add Element") add_button.set_child(button_label) property_val.add_child(add_button) vals = self.component.property_vals[property] for i in range(len(vals)): val = vals[i] element_layout = GUIStackLayout(vertical=False) element_layout.padding = 4 element_layout.bbox.height = 28 property_val.add_child(element_layout) inner_property_val = GUITextBox() inner_property_val.data = { "parent": property, "index": i } inner_property_val.set_text(val) inner_property_val.on_text_changed = self.text_change_handler element_layout.add_child(inner_property_val) element_spacer = GUIComponent() element_spacer.bbox.width = 4 element_layout.add_child(element_spacer) del_button = GUIButton() del_button.padding = 3 del_button.bbox.width = 16 del_button.bbox.height = 20 del_button.set_normal_color((1, 0, 0, 0.8)) del_button.set_hover_color((1, 0.4, 0.4, 0.8)) del_button.set_pressed_color((0.4, 0, 0, 0.8)) del_button.on_click = self.element_del_button_handler del_button.data = element_layout del_button_label = GUILabel() del_button_label.set_text("X") del_button_label.receive_events = False del_button.set_child(del_button_label) element_layout.add_child(del_button) self.property_fields[property] = property_val property_layout.add_child(property_val) property_frame.fit_height_to_content = True property_layout.bbox.height = property_val.bbox.height elif property_type == PropertyType.VECTOR3: property_val = GUIStackLayout(vertical=False) x_val = GUINumberBox() x_val.text_box.data = {"parent": property, "index": 0} x_val.bbox.width = 60 x_val.text_box.set_text( str(self.component.property_vals[property][0])) x_val.text_box.on_text_changed = self.text_change_handler property_val.add_child(x_val) spacer_1 = GUIComponent() spacer_1.bbox.width = 10 property_val.add_child(spacer_1) y_val = GUINumberBox() y_val.text_box.data = {"parent": property, "index": 1} y_val.bbox.width = 60 y_val.text_box.set_text( str(self.component.property_vals[property][1])) y_val.text_box.on_text_changed = self.text_change_handler property_val.add_child(y_val) spacer_2 = GUIComponent() spacer_2.bbox.width = 10 property_val.add_child(spacer_2) z_val = GUINumberBox() z_val.text_box.data = {"parent": property, "index": 2} z_val.bbox.width = 60 z_val.text_box.set_text( str(self.component.property_vals[property][2])) z_val.text_box.on_text_changed = self.text_change_handler property_val.add_child(z_val) self.property_fields[property] = property_val property_layout.add_child(property_val)