Skip to content

Feature: Embed python shell #12

@0rShemesh

Description

@0rShemesh

Hey,

I think about feature that will makes the editor easier to use:
python shell for scripting!

the benefits:

  • editing in real time
  • load structs
  • binary data
  • stream data to editor (file or socket with Rebuffered)

In these days construct-editor requires knowledge in wxPython library, I don't think that users of construct have any knowledge in this library, for make the application(or library) be use by more people around the world I think that would be better to find a way to make some generic API for construct-editor (easy to extendable) without know any knowledge in GUI.

for example of usage of python shell in construct-editor:
image

changed lines in main.py file:

class ConstructGallery(wx.Panel):
.......

#line 296:
    def display_binary(self, data: bytes) -> None:
        """display binary data to screen

        Args:
            data (bytes): bytes to load
        """
        self.construct_hex_editor.binary = data
        self.construct_hex_editor.refresh()
         
    def on_load_binary_file_clicked(self, event):
        with wx.FileDialog(
            self,
            "Open binary file",
            wildcard="binary files (*.*)|*.*",
            style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST,
        ) as fileDialog:

            if fileDialog.ShowModal() == wx.ID_CANCEL:
                return  # the user changed their mind

            # Proceed loading the file chosen by the user
            pathname = Path(fileDialog.GetPath())
            with open(pathname, "rb") as file:
                self.display_binary(file.read())

in main function:

    frame = ConstructGalleryFrame(None)
    import __main__
    main_locals = __main__.__dict__
    main_locals["construct_gallery"] = frame.main_panel.construct_gallery
    main_locals["load_binary"] = lambda data: frame.main_panel.display_binary(data) 
    
    pyshell = wx.py.shell.ShellFrame(locals=main_locals)
    pyshell.Show()
    frame.Show(True)
    if wit is not None:
        wit.InspectionTool().Show()
    app.MainLoop()


if __name__ == "__main__":
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions