-
Notifications
You must be signed in to change notification settings - Fork 1
/
choose_multi.py
70 lines (57 loc) · 2.12 KB
/
choose_multi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
summary: A widget showing data in a tabular fashion, providing multiple selection
description:
Similar to @{choose}, but with multiple selection
keywords: chooser, actions
see_also: choose, chooser_with_folders
"""
from __future__ import print_function
from ida_kernwin import Choose
class MyChoose(Choose):
def __init__(self, items, title, cols, icon=-1):
# idaapi.Choose.__init__(self, title, cols, flags=idaapi.Choose.CH_MODAL | idaapi.Choose.CH_MULTI, icon=icon)
Choose.__init__(
self,
# title,
# [ ["Bit", Choose.CHCOL_HEX | 10] ],
title, # "Select Patch",
cols, # [["Type", 8], ["Function", 25], ["Start", 16], ["End", 16], ["Disassembly", 128]],
flags = Choose.CH_MULTI
)
# self.items = items
# self.items = [ "1,2,3,4," for x in range(len(items)) ]
self.n = 0
self.items = [ self.make_item(item) for item in items ]
def OnGetSize(self):
return len(self.items)
def OnGetLine(self, n):
return self.items[n]
def OnSelectLine(self, n):
self.deflt = n # save current selection
return (Choose.NOTHING_CHANGED, )
def OnDeleteLine(self, indices):
new_items = []
for idx, item in enumerate(self.items):
if idx not in indices:
new_items.append(item)
self.items = new_items
return [Choose.ALL_CHANGED] + indices
def make_item(self, item):
r = [str(x) for x in item]
self.n += 1
return r
def show(self, num):
# self.deflt = [x
# for x in range(len(self.items))
# if (num & (1 << x)) != 0]
if self.Show(True) < 0:
return 0
return self.deflt
# return sum([(1 << x) for x in self.deflt])
# -----------------------------------------------------------------------
# def test_choose(num):
# c = MyChoose("Choose - sample 2", nb = 5)
# return c.show(num)
# -----------------------------------------------------------------------
if __name__ == '__main__':
print(test_choose(11))