Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_click(event):
if event.state & 0x0001 and self.anchor_index is not None: # shift
start = min(self.anchor_index, index)
end = max(self.anchor_index, index)
for i in range(start, end + 1):
if i in (index, self.anchor_index):
continue
check = self.checks[i]
if check.instate(("selected", )):
check.state(("!selected", ))
else:
check.state(("selected", ))
else:
self.anchor_index = index
check = ttk.Checkbutton(self.window, text=safe_tk(ep.title))
check.bind("", handle_click)
check.state(("!alternate",))
if not ep.skip:
check.state(("selected",))
check.grid(
column=(index // 20) - self.window_column,
row=index % 20,
sticky="w"
)
self.checks.append(check)
def update_table(self, pool):
"""Refresh treeview."""
table = self.pool_index[id(pool)]
missions = pool.values()
table.clear(exclude=missions)
for mission in missions:
if not table.contains(mission):
table.add({
"name": safe_tk(mission.title),
"host": mission.module.name,
"state": STATE[mission.state],
"last_update": draw_last_update(mission.last_update)
}, key=mission)
table.rearrange(missions)
def __init__(self, parent, title="Dialog", on_closed=None):
self.parent = parent
self.result = None
self.on_closed = on_closed
# root
self.root = tk.Toplevel(parent)
self.root.title(safe_tk(title))
# body
self.body = ttk.Frame(self.root)
self.create_body()
self.body.pack()
# button bar
self.btn_bar = ttk.Frame(self.root)
self.create_buttons()
self.btn_bar.pack()
# bind event
self.root.bind("", self.resolve)
self.root.bind("", self.reject)
# show dialog and disable parent
def create_body(self):
entry = ttk.Entry(self.body)
entry.insert(0, safe_tk(mission.title))
entry.selection_range(0, "end")
entry.pack()
entry.focus_set()
self.entry = entry
def update_mission_info(self, table, mission):
"""Update mission info on treeview."""
if not table.contains(mission):
return
table.update(
mission,
name=safe_tk(mission.title),
state=STATE[mission.state],
last_update=draw_last_update(mission.last_update)
)