annotate python/ide/disasm.py @ 333:dcae6574c974

Increment to qt5
author Windel Bouwman
date Sun, 09 Feb 2014 15:27:57 +0100
parents 917eab04b8b7
children
rev   line source
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 291
diff changeset
1 import binascii
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 295
diff changeset
2 from qtwrapper import QtGui, QtCore, QtWidgets, Qt
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
3
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
4
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 295
diff changeset
5 class DisAsmModel(QtCore.QAbstractTableModel):
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
6 def __init__(self):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
7 super().__init__()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
8 self.outs = None
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
9 self.instructions = []
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
10 self.headers = ['Address', 'Bytes', 'Instruction']
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
11 self.txts = []
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
12 self.txts.append(lambda i: '0x{:08x}'.format(i.address))
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 291
diff changeset
13 self.txts.append(lambda i: binascii.hexlify(i.encode()).decode('ascii'))
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
14 self.txts.append(lambda i: str(i))
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
15
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
16 def rowCount(self, parent):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
17 return len(self.instructions)
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 295
diff changeset
18
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
19 def columnCount(self, parent):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
20 return len(self.headers)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
21
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
22 def data(self, index, role):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
23 if not index.isValid():
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
24 return
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
25 row, col = index.row(), index.column()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
26 if role == Qt.DisplayRole:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
27 i = self.instructions[row]
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
28 return self.txts[col](i)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
29
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
30 def headerData(self, section, orientation, role):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
31 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
32 return self.headers[section]
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 295
diff changeset
33
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
34 def setInstructions(self, ins):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
35 self.instructions = ins
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
36 self.modelReset.emit()
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 295
diff changeset
37
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
38
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 295
diff changeset
39 class Disassembly(QtWidgets.QTableView):
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
40 def __init__(self):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
41 super().__init__()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
42 self.dm = DisAsmModel()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
43 self.setModel(self.dm)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
44
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
45 def showPos(self, p):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
46 for i in self.dm.instructions:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
47 if i.address == p:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
48 row = self.dm.instructions.index(i)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
49 self.selectRow(row)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
50