Skip to content

Commit

Permalink
Make tkinter optional in ticketer (#4258)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Feb 5, 2024
1 parent c86d31c commit a27b024
Showing 1 changed file with 51 additions and 49 deletions.
100 changes: 51 additions & 49 deletions scapy/modules/ticketer.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
import tkinter.simpledialog as tksd
from tkinter import ttk
except ImportError:
raise ImportError("tkinter is not installed (`apt install python3-tk` on debian)")
tk = None

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

if tk is not None:
class ScrollFrame(tk.Frame):
def __init__(self, parent):
super().__init__(parent)

class ScrollFrame(tk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.canvas = tk.Canvas(self, borderwidth=0)
self.viewPort = ttk.Frame(self.canvas)
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)

self.canvas = tk.Canvas(self, borderwidth=0)
self.viewPort = ttk.Frame(self.canvas)
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)

self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas_window = self.canvas.create_window(
(4, 4), window=self.viewPort, anchor="nw", tags="self.viewPort"
)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas_window = self.canvas.create_window(
(4, 4), window=self.viewPort, anchor="nw", tags="self.viewPort"
)

self.viewPort.bind("<Configure>", self.onFrameConfigure)
self.canvas.bind("<Configure>", self.onCanvasConfigure)
self.viewPort.bind("<Configure>", self.onFrameConfigure)
self.canvas.bind("<Configure>", self.onCanvasConfigure)

self.viewPort.bind("<Enter>", self.onEnter)
self.viewPort.bind("<Leave>", self.onLeave)
self.viewPort.bind("<Enter>", self.onEnter)
self.viewPort.bind("<Leave>", self.onLeave)

self.onFrameConfigure(None)
self.onFrameConfigure(None)

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

def onCanvasConfigure(self, event):
"""Reset the canvas window to encompass inner frame when required"""
canvas_width = event.width
self.canvas.itemconfig(self.canvas_window, width=canvas_width)
def onCanvasConfigure(self, event):
"""Reset the canvas window to encompass inner frame when required"""
canvas_width = event.width
self.canvas.itemconfig(self.canvas_window, width=canvas_width)

def onMouseWheel(self, event):
if platform.system() == "Windows":
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
elif platform.system() == "Darwin":
self.canvas.yview_scroll(int(-1 * event.delta), "units")
else:
if event.num == 4:
self.canvas.yview_scroll(-1, "units")
elif event.num == 5:
self.canvas.yview_scroll(1, "units")

def onEnter(self, event):
if platform.system() == "Linux":
self.canvas.bind_all("<Button-4>", self.onMouseWheel)
self.canvas.bind_all("<Button-5>", self.onMouseWheel)
else:
self.canvas.bind_all("<MouseWheel>", self.onMouseWheel)
def onMouseWheel(self, event):
if platform.system() == "Windows":
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
elif platform.system() == "Darwin":
self.canvas.yview_scroll(int(-1 * event.delta), "units")
else:
if event.num == 4:
self.canvas.yview_scroll(-1, "units")
elif event.num == 5:
self.canvas.yview_scroll(1, "units")

def onEnter(self, event):
if platform.system() == "Linux":
self.canvas.bind_all("<Button-4>", self.onMouseWheel)
self.canvas.bind_all("<Button-5>", self.onMouseWheel)
else:
self.canvas.bind_all("<MouseWheel>", self.onMouseWheel)

def onLeave(self, event):
if platform.system() == "Linux":
self.canvas.unbind_all("<Button-4>")
self.canvas.unbind_all("<Button-5>")
else:
self.canvas.unbind_all("<MouseWheel>")
def onLeave(self, event):
if platform.system() == "Linux":
self.canvas.unbind_all("<Button-4>")
self.canvas.unbind_all("<Button-5>")
else:
self.canvas.unbind_all("<MouseWheel>")


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

Expand Down

0 comments on commit a27b024

Please sign in to comment.