Skip to content

Commit a27b024

Browse files
authored
Make tkinter optional in ticketer (#4258)
1 parent c86d31c commit a27b024

File tree

1 file changed

+51
-49
lines changed

1 file changed

+51
-49
lines changed

scapy/modules/ticketer.py

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
import tkinter.simpledialog as tksd
105105
from tkinter import ttk
106106
except ImportError:
107-
raise ImportError("tkinter is not installed (`apt install python3-tk` on debian)")
107+
tk = None
108108

109109
# CCache
110110
# https://web.mit.edu/kerberos/krb5-latest/doc/formats/ccache_file_format.html (official doc but garbage)
@@ -279,63 +279,63 @@ class CCache(Packet):
279279
# Credits to @mp035
280280
# https://gist.github.com/mp035/9f2027c3ef9172264532fcd6262f3b01
281281

282+
if tk is not None:
283+
class ScrollFrame(tk.Frame):
284+
def __init__(self, parent):
285+
super().__init__(parent)
282286

283-
class ScrollFrame(tk.Frame):
284-
def __init__(self, parent):
285-
super().__init__(parent)
287+
self.canvas = tk.Canvas(self, borderwidth=0)
288+
self.viewPort = ttk.Frame(self.canvas)
289+
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
290+
self.canvas.configure(yscrollcommand=self.vsb.set)
286291

287-
self.canvas = tk.Canvas(self, borderwidth=0)
288-
self.viewPort = ttk.Frame(self.canvas)
289-
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
290-
self.canvas.configure(yscrollcommand=self.vsb.set)
291-
292-
self.vsb.pack(side="right", fill="y")
293-
self.canvas.pack(side="left", fill="both", expand=True)
294-
self.canvas_window = self.canvas.create_window(
295-
(4, 4), window=self.viewPort, anchor="nw", tags="self.viewPort"
296-
)
292+
self.vsb.pack(side="right", fill="y")
293+
self.canvas.pack(side="left", fill="both", expand=True)
294+
self.canvas_window = self.canvas.create_window(
295+
(4, 4), window=self.viewPort, anchor="nw", tags="self.viewPort"
296+
)
297297

298-
self.viewPort.bind("<Configure>", self.onFrameConfigure)
299-
self.canvas.bind("<Configure>", self.onCanvasConfigure)
298+
self.viewPort.bind("<Configure>", self.onFrameConfigure)
299+
self.canvas.bind("<Configure>", self.onCanvasConfigure)
300300

301-
self.viewPort.bind("<Enter>", self.onEnter)
302-
self.viewPort.bind("<Leave>", self.onLeave)
301+
self.viewPort.bind("<Enter>", self.onEnter)
302+
self.viewPort.bind("<Leave>", self.onLeave)
303303

304-
self.onFrameConfigure(None)
304+
self.onFrameConfigure(None)
305305

306-
def onFrameConfigure(self, event):
307-
"""Reset the scroll region to encompass the inner frame"""
308-
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
306+
def onFrameConfigure(self, event):
307+
"""Reset the scroll region to encompass the inner frame"""
308+
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
309309

310-
def onCanvasConfigure(self, event):
311-
"""Reset the canvas window to encompass inner frame when required"""
312-
canvas_width = event.width
313-
self.canvas.itemconfig(self.canvas_window, width=canvas_width)
310+
def onCanvasConfigure(self, event):
311+
"""Reset the canvas window to encompass inner frame when required"""
312+
canvas_width = event.width
313+
self.canvas.itemconfig(self.canvas_window, width=canvas_width)
314314

315-
def onMouseWheel(self, event):
316-
if platform.system() == "Windows":
317-
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
318-
elif platform.system() == "Darwin":
319-
self.canvas.yview_scroll(int(-1 * event.delta), "units")
320-
else:
321-
if event.num == 4:
322-
self.canvas.yview_scroll(-1, "units")
323-
elif event.num == 5:
324-
self.canvas.yview_scroll(1, "units")
325-
326-
def onEnter(self, event):
327-
if platform.system() == "Linux":
328-
self.canvas.bind_all("<Button-4>", self.onMouseWheel)
329-
self.canvas.bind_all("<Button-5>", self.onMouseWheel)
330-
else:
331-
self.canvas.bind_all("<MouseWheel>", self.onMouseWheel)
315+
def onMouseWheel(self, event):
316+
if platform.system() == "Windows":
317+
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
318+
elif platform.system() == "Darwin":
319+
self.canvas.yview_scroll(int(-1 * event.delta), "units")
320+
else:
321+
if event.num == 4:
322+
self.canvas.yview_scroll(-1, "units")
323+
elif event.num == 5:
324+
self.canvas.yview_scroll(1, "units")
325+
326+
def onEnter(self, event):
327+
if platform.system() == "Linux":
328+
self.canvas.bind_all("<Button-4>", self.onMouseWheel)
329+
self.canvas.bind_all("<Button-5>", self.onMouseWheel)
330+
else:
331+
self.canvas.bind_all("<MouseWheel>", self.onMouseWheel)
332332

333-
def onLeave(self, event):
334-
if platform.system() == "Linux":
335-
self.canvas.unbind_all("<Button-4>")
336-
self.canvas.unbind_all("<Button-5>")
337-
else:
338-
self.canvas.unbind_all("<MouseWheel>")
333+
def onLeave(self, event):
334+
if platform.system() == "Linux":
335+
self.canvas.unbind_all("<Button-4>")
336+
self.canvas.unbind_all("<Button-5>")
337+
else:
338+
self.canvas.unbind_all("<MouseWheel>")
339339

340340

341341
# Build ticketer
@@ -1643,6 +1643,8 @@ def edit_ticket(self, i, key=None, hash=None):
16431643
"""
16441644
Edit a Kerberos ticket using the GUI
16451645
"""
1646+
if tk is None:
1647+
raise ImportError("tkinter is not installed (`apt install python3-tk` on debian)")
16461648
tkt = self.dec_ticket(i, key=key, hash=hash)
16471649
pac = tkt.authorizationData.seq[0].adData[0].seq[0].adData
16481650

0 commit comments

Comments
 (0)