Skip to content

Commit

Permalink
Support variable-length lists
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Oct 11, 2023
1 parent 319fdf5 commit 6fd8bc4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions gcft_ui/bunfoe_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,23 @@ def set_field_values_for_bunfoe_instance_recursive(self, instance, layout: QLayo
field_type = widget.property('field_type')
access_path = widget.property('access_path')
if access_path is not None:
value = self.get_instance_value(instance, access_path)
self.set_widget_value(widget, value, field_type, instance, disabled=disabled)
final_access_type, final_access_arg = access_path[-1]
if final_access_type == 'item' and isinstance(final_access_arg, QComboBox):
# Dynamic widget indexing.
combobox = final_access_arg
list_value = self.get_instance_value(instance, access_path[:-1])
combobox.blockSignals(True)
combobox.clear()
for i in range(len(list_value)):
index_str = self.window().stringify_number(i, min_hex_chars=1)
combobox.addItem(f"Selected: {index_str}")
combobox.blockSignals(False)
if len(list_value) > 0:
value = self.get_instance_value(instance, access_path)
self.set_widget_value(widget, value, field_type, instance, disabled=disabled)
else:
value = self.get_instance_value(instance, access_path)
self.set_widget_value(widget, value, field_type, instance, disabled=disabled)

# Uncomment the below code to make index comboboxes reset to element zero every time the
# selection changes.
Expand Down Expand Up @@ -181,7 +196,11 @@ def add_all_sequence_elements_to_new_layout(self, field: Field) -> QLayout:
# A dynamic widget is a single editor widget shared between all of the elements of the sequence,
# plus a combobox to allow switching which one is currently selected and actively being edited.

assert isinstance(field.length, int) and field.length > 0
if isinstance(field.length, int) and field.length > 0:
initial_length = field.length
else:
initial_length = 0

type_args = typing.get_args(field.type)
assert len(type_args) == 1
arg_type = type_args[0]
Expand All @@ -197,9 +216,9 @@ def add_all_sequence_elements_to_new_layout(self, field: Field) -> QLayout:
# use_static_layout = False

if use_static_layout:
return self.add_all_sequence_elements_to_static_layout(arg_type, field.length, [('attr', field.name)])
return self.add_all_sequence_elements_to_static_layout(arg_type, initial_length, [('attr', field.name)])
else:
return self.add_all_sequence_elements_to_dynamic_layout(arg_type, field.length, [('attr', field.name)])
return self.add_all_sequence_elements_to_dynamic_layout(arg_type, initial_length, [('attr', field.name)])

def add_all_sequence_elements_to_static_layout(self, arg_type, field_length, access_path, show_indexes=True) -> QLayout:
# Creates a widget for each element of a sequence, arranged horizontally.
Expand Down Expand Up @@ -276,7 +295,7 @@ def index_combobox_value_changed(self, new_index: int):
self.set_widget_value(indexed_widget, value, field_type, instance)

def make_widget_for_field(self, field: Field):
if field.name.startswith('_padding') or field.bitfield:
if field.name.startswith('_padding') or field.assert_default:
# No need to show these.
return None

Expand Down
2 changes: 1 addition & 1 deletion gclib

0 comments on commit 6fd8bc4

Please sign in to comment.