def __init__(self, parent, col_hdr, bins): cols = len(col_hdr) col_byte_len = [] for col in range(cols): #Columns col_byte_len.append(int(col_hdr[col].split(':')[1])) byte_len = sum(col_byte_len) rows = (len(bins) + byte_len - 1) // byte_len self.rows = rows self.cols = cols self.col_byte_len = col_byte_len self.col_hdr = col_hdr self.size = len(bins) self.last_dir = '' style = ttk.Style() style.configure("Custom.Treeview.Heading", font=('calibri', 10, 'bold'), foreground="blue") ttk.Treeview.__init__(self, parent, height=rows, columns=[''] + col_hdr, show='headings', style="Custom.Treeview", selectmode='none') self.bind("<Button-1>", self.click) self.bind("<FocusOut>", self.focus_out) self.entry = validating_entry(self, width=4, justify=tkinter.CENTER) self.heading(0, text='LOAD') self.column(0, width=60, stretch=0, anchor=tkinter.CENTER) for col in range(cols): #Columns text = col_hdr[col].split(':')[0] byte_len = int(col_hdr[col].split(':')[1]) self.heading(col + 1, text=text) self.column(col + 1, width=self.to_cell_width(byte_len), stretch=0, anchor=tkinter.CENTER) idx = 0 for row in range(rows): #Rows text = '%04X' % (row * len(col_hdr)) vals = ['%04X:' % (cols * row)] for col in range(cols): #Columns if idx >= len(bins): break byte_len = int(col_hdr[col].split(':')[1]) value = bytes_to_value(bins[idx:idx + byte_len]) hex = ("%%0%dX" % (byte_len * 2)) % value vals.append(hex) idx += byte_len self.insert('', 'end', values=tuple(vals)) if idx >= len(bins): break
def refresh_bin (self, bins): if not bins: return # Reload binary into widget bin_len = len(bins) for row in range(self.rows): iid = self.get_children()[row] for col in range(self.cols): idx = row * sum(self.col_byte_len) + sum(self.col_byte_len[:col]) byte_len = self.col_byte_len[col] if idx + byte_len <= self.size: byte_len = int(self.col_hdr[col].split(':')[1]) if idx + byte_len > bin_len: val = 0 else: val = bytes_to_value (bins[idx:idx+byte_len]) hex_val = ("%%0%dX" % (byte_len * 2) ) % val self.set (iid, col + 1, hex_val)