Пример #1
0
    def __init__(self, parent, nbt_data, root_tag_name="", callback=None):
        super(NBTEditor, self).__init__(parent)

        self.nbt_data = nbt_data

        self.image_list = wx.ImageList(16, 16)
        self.image_map = {
            nbt.TAG_Byte:
            self.image_list.Add(nbt_resources.nbt_tag_byte.bitmap()),
            nbt.TAG_Short:
            self.image_list.Add(nbt_resources.nbt_tag_short.bitmap()),
            nbt.TAG_Int:
            self.image_list.Add(nbt_resources.nbt_tag_int.bitmap()),
            nbt.TAG_Long:
            self.image_list.Add(nbt_resources.nbt_tag_long.bitmap()),
            nbt.TAG_Float:
            self.image_list.Add(nbt_resources.nbt_tag_float.bitmap()),
            nbt.TAG_Double:
            self.image_list.Add(nbt_resources.nbt_tag_double.bitmap()),
            nbt.TAG_String:
            self.image_list.Add(nbt_resources.nbt_tag_string.bitmap()),
            nbt.TAG_Compound:
            self.image_list.Add(nbt_resources.nbt_tag_compound.bitmap()),
            nbt.NBTFile:
            self.image_list.ImageCount - 1,
            nbt.TAG_List:
            self.image_list.Add(nbt_resources.nbt_tag_list.bitmap()),
            nbt.TAG_Byte_Array:
            self.image_list.Add(nbt_resources.nbt_tag_array.bitmap()),
            nbt.TAG_Int_Array:
            self.image_list.ImageCount - 1,
            nbt.TAG_Long_Array:
            self.image_list.ImageCount - 1,
        }
        self.other = self.image_map[nbt.TAG_String]

        self.tree = self.build_tree(root_tag_name)
        self.add_object(self.tree, 1, wx.ALL | wx.CENTER | wx.EXPAND)

        button_row = simple.SimplePanel(self, wx.HORIZONTAL)
        self.commit_button = wx.Button(button_row, label="Commit")
        self.cancel_button = wx.Button(button_row, label="Cancel")

        button_row.add_object(self.commit_button, space=0)
        button_row.add_object(self.cancel_button, space=0)

        self.commit_button.Bind(wx.EVT_BUTTON, self.commit)
        self.cancel_button.Bind(wx.EVT_BUTTON, self._close)

        self.add_object(button_row, space=0)

        self.callback = callback
Пример #2
0
    def __init__(self, parent, open_world_callback):
        super(WorldSelectUI, self).__init__(parent)
        self.open_world_callback = open_world_callback
        self.header = simple.SimplePanel(self, wx.HORIZONTAL)
        self.header_open_world = wx.Button(self.header,
                                           wx.ID_ANY,
                                           label=lang.get("open_world_button"))
        self.header_open_world.Bind(wx.EVT_BUTTON, self._open_world)
        self.header.add_object(self.header_open_world)
        self.add_object(self.header, 0, 0)

        self.content = ScrollableWorldsUI(self, open_world_callback)
        self.add_object(self.content, 1, wx.EXPAND)
Пример #3
0
    def __init__(self,
                 parent,
                 tag_name,
                 tag,
                 tag_types,
                 create=False,
                 save_callback=None):
        super(EditTagDialog, self).__init__(parent,
                                            title="Edit NBT Tag",
                                            size=(500, 280))

        self.save_callback = save_callback
        self.old_name = tag_name
        self.data_type_func = lambda x: x

        main_panel = simple.SimplePanel(self)

        name_panel = simple.SimplePanel(main_panel, sizer_dir=wx.HORIZONTAL)
        value_panel = simple.SimplePanel(main_panel, sizer_dir=wx.HORIZONTAL)
        tag_type_panel = simple.SimplePanel(main_panel)
        button_panel = simple.SimplePanel(main_panel, sizer_dir=wx.HORIZONTAL)

        name_label = wx.StaticText(name_panel, label="Name: ")
        self.name_field = wx.TextCtrl(name_panel)

        if tag_name == "" and not create:
            self.name_field.Disable()
        else:
            self.name_field.SetValue(tag_name)

        name_panel.add_object(name_label, space=0, options=wx.ALL | wx.CENTER)
        name_panel.add_object(self.name_field,
                              space=1,
                              options=wx.ALL | wx.EXPAND)

        value_label = wx.StaticText(value_panel, label="Value: ")
        self.value_field = wx.TextCtrl(value_panel)

        if isinstance(tag, (nbt.TAG_Compound, nbt.TAG_List)):
            self.value_field.Disable()
        else:
            self.value_field.SetValue(str(tag.value))

        value_panel.add_object(value_label,
                               space=0,
                               options=wx.ALL | wx.CENTER)
        value_panel.add_object(self.value_field,
                               space=1,
                               options=wx.ALL | wx.EXPAND)

        tag_type_sizer = wx.GridSizer(self.GRID_ROWS, self.GRID_COLUMNS, 0, 0)

        self.radio_buttons = []

        for tag_type in tag_types:
            rd_btn = NBTRadioButton(
                tag_type_panel,
                tag_type,
                parent.image_list.GetBitmap(parent.image_map[getattr(
                    nbt, tag_type)]),
            )
            self.radio_buttons.append(rd_btn)
            rd_btn.Bind(wx.EVT_RADIOBUTTON,
                        partial(self.handle_radio_button, tag_type))
            tag_type_sizer.Add(rd_btn, 0, wx.ALL, 0)

            if tag_type == tag.__class__.__name__:
                rd_btn.SetValue(True)

        tag_type_panel.SetSizerAndFit(tag_type_sizer)

        self.save_button = wx.Button(button_panel, label="Save")
        self.cancel_button = wx.Button(button_panel, label="Cancel")

        button_panel.add_object(self.save_button, space=0)
        button_panel.add_object(self.cancel_button, space=0)

        main_panel.add_object(name_panel, space=0, options=wx.ALL | wx.EXPAND)
        main_panel.add_object(value_panel, space=0, options=wx.ALL | wx.EXPAND)
        main_panel.add_object(tag_type_panel, space=0)
        main_panel.add_object(button_panel, space=0)

        self.save_button.Bind(wx.EVT_BUTTON, self.save)
        self.cancel_button.Bind(wx.EVT_BUTTON, lambda evt: self.Close())

        self.value_field.Bind(wx.EVT_TEXT, self.value_changed)

        self.SetSize((235, 260))
        self.Layout()