@@ -29,6 +29,7 @@ def int_to_str(integer_format: "construct_editor.IntegerFormat", val: int) -> st
29
29
return f"0x{ val :X} "
30
30
return f"{ val } "
31
31
32
+
32
33
def str_to_int (s : str ) -> int :
33
34
if len (s ) == 0 :
34
35
s = "0"
@@ -40,7 +41,6 @@ def str_to_int(s: str) -> int:
40
41
return i
41
42
42
43
43
-
44
44
# #####################################################################################################################
45
45
# GUI Elements ########################################################################################################
46
46
# #####################################################################################################################
@@ -94,7 +94,7 @@ def __init__(self, parent, entry: "EntryConstruct"):
94
94
95
95
self .SetSizer (hsizer )
96
96
self .Layout ()
97
-
97
+
98
98
def get_new_obj (self ) -> Any :
99
99
return self .entry .obj
100
100
@@ -300,7 +300,9 @@ def __init__(self, parent, entry: Union["EntryTFlagsEnum", "EntryFlagsEnum"]):
300
300
items = self .entry .get_flagsenum_items_from_obj ()
301
301
for pos , item in enumerate (items ):
302
302
self .popup_ctrl .clbx .Insert (
303
- item = f"{ int_to_str (entry .model .integer_format , item .value )} ({ item .name } )" , pos = pos , clientData = item
303
+ item = f"{ int_to_str (entry .model .integer_format , item .value )} ({ item .name } )" ,
304
+ pos = pos ,
305
+ clientData = item ,
304
306
)
305
307
self .popup_ctrl .clbx .Check (pos , item .checked )
306
308
@@ -763,7 +765,7 @@ def create_obj_panel(self, parent) -> ObjPanel:
763
765
return ObjPanel_Default (parent , self ) # TODO: create panel for cs.Array
764
766
765
767
def modify_context_menu (self , menu : "construct_editor.ContextMenu" ):
766
- # If the subentry has no subentries itselfe , it makes no sense to create a list view.
768
+ # If the subentry has no subentries itself , it makes no sense to create a list view.
767
769
temp_subentry = create_entry_from_construct (
768
770
self .model , self , self .construct .subcon
769
771
)
@@ -1227,11 +1229,21 @@ def __init__(
1227
1229
construct : "cs.Bytes[Any, Any]" ,
1228
1230
):
1229
1231
super ().__init__ (model , parent , construct )
1232
+ self .ascii_view = False
1230
1233
1231
1234
@property
1232
1235
def obj_str (self ) -> str :
1233
1236
try :
1234
- return self .obj .hex (" " )
1237
+ if self .ascii_view :
1238
+ chars = []
1239
+ for b in self .obj :
1240
+ char = chr (b )
1241
+ if char not in string .printable :
1242
+ char = "."
1243
+ chars .append (char )
1244
+ return "" .join (chars )
1245
+ else :
1246
+ return self .obj .hex (" " )
1235
1247
except Exception :
1236
1248
return str (self .obj )
1237
1249
@@ -1243,6 +1255,18 @@ def typ_str(self) -> str:
1243
1255
except Exception :
1244
1256
return "Byte[{}]" .format (str (self .construct .length ))
1245
1257
1258
+ def modify_context_menu (self , menu : "construct_editor.ContextMenu" ):
1259
+ menu .Append (wx .MenuItem (menu , wx .ID_ANY , kind = wx .ITEM_SEPARATOR ))
1260
+
1261
+ def on_menu_item_clicked (event : wx .MenuEvent ):
1262
+ self .ascii_view = not self .ascii_view
1263
+ menu .parent .reload ()
1264
+
1265
+ menu_item = wx .MenuItem (menu , wx .ID_ANY , "ASCII View" , kind = wx .ITEM_CHECK )
1266
+ menu .Append (menu_item )
1267
+ menu_item .Check (self .ascii_view )
1268
+ menu .Bind (wx .EVT_MENU , on_menu_item_clicked , menu_item )
1269
+
1246
1270
1247
1271
# EntryRenamed ########################################################################################################
1248
1272
class EntryRenamed (EntrySubconstruct ):
0 commit comments