timrid / construct-editor Goto Github PK
View Code? Open in Web Editor NEWGUI (based on wxPython) for 'construct', which is a powerful declarative and symmetrical parser and builder for binary data.
License: MIT License
GUI (based on wxPython) for 'construct', which is a powerful declarative and symmetrical parser and builder for binary data.
License: MIT License
wxPython>=4.1.1 is required.
With wxPython==4.1.0 the following exception occures:
AttributeError: module 'wx.grid' has no attribute 'EVT_GRID_RANGE_SELECTING'
repace TContainerMixin
with DataclassMixin
in wrapper.py
When "Enabe List View" of root element is activated and then should be deactivated again, the following exception occures when right clicking the root element:
wx._core.wxAssertionError: C++ assertion "Assert failure" failed at .../src/common/stockitem.cpp(213) in wxGetStockLabel(): invalid stock item ID
(at line 172 in construct_editor.py: item: wx.MenuItem = submenu.AppendCheckItem(wx.ID_ANY, name)
)
Problem is, that the path of the root element is empty.
To fix this, the path of the root element has to be non empty. So the root element has to be added to the path.
An error appears if the top left panel of the Construct Editor GUI is quickly changed by selecting a construct sample and then pressing a UP or DOWN arrow key, keeping it pressed.
Often (but possibly not always) a KeyError is shown. E.g., the GetSize() or Render() methods of the ObjectRenderer class in wx_construct_editor.py are often impacted.
Example:
File "...\Python39\site-packages\construct_editor\wx_widgets\wx_construct_editor.py", line 54, in GetSize
return self.entry_renderer_helper.get_size(self)
File "...\Python39\site-packages\construct_editor\wx_widgets\wx_obj_view.py", line 376, in get_size
obj_str = self.entry.obj_str if self.entry else ""
File "...\Python39\site-packages\construct_editor\core\entries.py", line 1789, in obj_str
return self.conv_obj_to_str(self.obj)
File "...\Python39\site-packages\construct_editor\core\entries.py", line 252, in obj
obj = obj[p]
Uncaught exception: KeyError: 'days2'
The frequency of the error depends on how many elements are consecutively browsed in sequence (many are needed for the error to occur, not just some) and on the speed of the computer.
We have a 10-byte PaddedString like this:
value: str = cst.csfield(
cs.PaddedString(10, "ascii"),
)
This works fine when I enter text, but in the case of a numeric input (any hex number, ie. [0..9A..Fa..f]
) the field throws a parsing error:
For the input "1234" I would expect the string to be parsed as bytes "\x31\x32\x33\x34\x00\x00\x00\x00\x00\x00".
Issue when the root construct has a name other than None
. Then a KeyError occurs with the name of the root object. Possibly something wrong in obj_str
method...
Hey,
I think about feature that will makes the editor easier to use:
python shell for scripting!
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:
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()
add cs.FixedSized
to wrapper.construct_entry_mapping
Add new parameter to IncludeGuiMetaData
to disable the creation of offset_start
and offset_end
because they would be only valid in the main Stream.
This has to be used in :
cs.Tunnel
, cs.Prefixed
, cs.FixedSized
, cs.NullTerminated
, cs.NullStripped
, cs.RestreamData
, ...)cs.Restreamed
& cs.Transformed
)The white text is not visible with a white background when using the dark theme in ubuntu.
import wx
import construct as cs
from construct_editor.wx_widgets import WxConstructHexEditor
constr = cs.Struct(
"a" / cs.Int16sb,
"b" / cs.Int16sb,
)
b = bytes([0x12, 0x34, 0x56, 0x78])
app = wx.App(False)
frame = wx.Frame(None, title="Construct Hex Editor", size=(1000, 200))
editor_panel = WxConstructHexEditor(frame, construct=constr, binary=b)
editor_panel.construct_editor.expand_all()
frame.Show(True)
app.MainLoop()
construct-editor 0.1.4 with wxpython 4.2.1
python 3.10
Ubuntu 22.04 with dark theme
Change EntryTimestamp.obj_str()
so that it always returns str(self.obj)
:
@property
def obj_str(self) -> str:
return str(self.obj)
Change ObjPanel_Timestamp.get_new_obj()
so that it creates an instance of the old obj_typ (obj_type = type(self.entry.obj)
) and not always a new arrow.Arrow
object:
def get_new_obj(self) -> Any:
date: wx.DateTime = self.date_picker.GetValue()
time: wx.DateTime = self.time_picker.GetValue()
obj_type = type(self.entry.obj)
new_obj = obj_type(
year=date.year,
month=date.month + 1, # in wx.adc.DatePickerCtrl the month start with 0
day=date.day,
hour=time.hour,
minute=time.minute,
second=time.second,
)
return new_obj
I have a binary file, and I'd like to define a new stucture of it prior coding. How would I do it?
The following error occurs:
(example.py:46458): Gtk-WARNING **: 15:32:24.623: Negative content width -22 (allocation 12, extents 17x17) while allocating gadget (node button, owner GtkButton)
Changing the value of 12 tot 35 shows the '«' and gets rid of the error.
on line: https://github.com/timrid/construct-editor/blob/main/construct_editor/wx_widgets/wx_construct_hex_editor.py#L113
Steps to reproduce:
Run the example program:
## example.py
import wx
import construct as cs
from construct_editor.wx_widgets import WxConstructHexEditor
constr = cs.Struct(
"a" / cs.Int16sb,
"b" / cs.Int16sb,
)
b = bytes([0x12, 0x34, 0x56, 0x78])
app = wx.App(False)
frame = wx.Frame(None, title="Construct Hex Editor", size=(1000, 200))
editor_panel = WxConstructHexEditor(frame, construct=constr, binary=b)
editor_panel.construct_editor.expand_all()
frame.Show(True)
app.MainLoop()
Run the program, hoover over the divider in the middle and this error will show in the terminal:
(example.py:46458): Gtk-WARNING **: 15:32:24.623: Negative content width -22 (allocation 12, extents 17x17) while allocating gadget (node button, owner GtkButton)
Versions:
construct-editor: 0.1.4
construct: 2.10.68
wxpython: 4.2.1
ubuntu: 22.04.2
Extend the ConstructViewer with cs.Bytes
, so that the displayed Bytes can be changed via the ContextMenu between HEX (currently the only format) and ASCII (to implement).
Hi,
I'm looking into ways to document a binary format hands on,
and hopefully work together with others on this.
construct together with the construct editor seems like a good match.
However installing construct-editor is very hard and an impediment for
collaboration.
Could construct-editor document known working versions?
The problem is mainly with wxPython.
Note: I did end up getting something working with Python3.9, poetry, pip and a github checkout of wxPython.
Here are the problems I had on ubuntu 22.04 which comes with python3.10.
Steps to reproduce:
Problem: ModuleNotFoundError: No module named 'attrdict'
It seems wxpython is not compatible with python3.10.
gist with full log: https://gist.github.com/rvanlaar/adb5f440db3b7bf49076b1f7b96d2787
ps. I did get something working with python3.9 and poetry. Creating a venv with python3.9 on ub
My usecase boils down to this:
s = c.Struct(
'type' / u32,
'value' / c.Switch(c.this.type, {
1: u32,
2: f32,
3: u32, # will be replaced later
})
)
s.value.cases[3] = s # make it recursive
This works perfectly, but your project enters infinite recursion and crashes:
Traceback (most recent call last):
File "D:\GitHub\Space Rangers\ranger-tools\rangers\scr.py", line 328, in <module>
editor_panel = WxConstructHexEditor(frame, construct=s, binary=b'')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\wx_widgets\wx_construct_hex_editor.py", line 89, in __init__
self._init_gui_construct_editor(hsizer, construct)
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\wx_widgets\wx_construct_hex_editor.py", line 121, in _init_gui_construct_editor
self.construct_editor: WxConstructEditor = WxConstructEditor(
^^^^^^^^^^^^^^^^^^
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\wx_widgets\wx_construct_editor.py", line 288, in __init__
ConstructEditor.__init__(self, construct, self._model)
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\core\construct_editor.py", line 17, in __init__
self.change_construct(construct)
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\core\construct_editor.py", line 129, in change_construct
self._construct = include_metadata(constr)
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\core\preprocessor.py", line 261, in include_metadata
constr.subcon = include_metadata(constr.subcon, bitwise) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\core\preprocessor.py", line 210, in include_metadata
new_subcons.append(include_metadata(subcon, bitwise))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\core\preprocessor.py", line 261, in include_metadata
constr.subcon = include_metadata(constr.subcon, bitwise) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Programs\Python\3.12\Lib\site-packages\construct_editor\core\preprocessor.py", line 246, in include_metadata
new_cases[key] = include_metadata(subcon, bitwise)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
I'm using construct v2.10.68 and would love to try out construct-editor, but currently construct-editor (0.0.19) depends on construct (2.10.67)
Would supporting that be as easy as bumping construct==2.10.67
to either construct==2.10.68
, or construct>=2.10.67
in requirements.txt? I can drop a PR if you like.
Thanks so much
I have a laptop, MBA 14" and window is too large for it. Could you please set at least fully visible if screen is small enough?
After a tricky resize, everything is usable
Extend the HexEditor, so that the displayed Bytes can be changed via the ContextMenu between HEX (currently the only format) and ASCII (to implement).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.