83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
# based on tkinter-oop-2.py
|
|
|
|
# Thinking in Frames: one Frame is the user input and its label, four more for the host type Listboxes, a last one for the host formatting?
|
|
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
|
|
from generic import sanitize, type_hosts_listed, type_hosts_organized
|
|
|
|
APP_TITLE = "Extract and look up hosts"
|
|
ENTRY_LABEL = "Enter some IPs, domains, email addresses:"
|
|
IP_LABEL = "IP => hostname"
|
|
|
|
|
|
class InputFrame(ttk.Frame):
|
|
def __init__(self, container):
|
|
super().__init__(container)
|
|
self.columnconfigure(0, weight=1)
|
|
self.columnconfigure(1, weight=1)
|
|
self.columnconfigure(2, weight=1)
|
|
self.columnconfigure(3, weight=1)
|
|
|
|
self.__create_widgets()
|
|
|
|
def __create_widgets(self) -> None:
|
|
ttk.Label(self, text=ENTRY_LABEL).grid(column=0, row=0)
|
|
self.entry = ttk.Entry(self)
|
|
self.entry.focus()
|
|
self.entry.grid(column=0, row=1, columnspan=4, sticky="nsew")
|
|
self.entry.bind("<Return>", self.key_handler_function)
|
|
|
|
for widget in self.winfo_children():
|
|
widget.grid(padx=0, pady=5)
|
|
|
|
def key_handler_function(self, event) -> None:
|
|
inputs = self.entry.get()
|
|
sanitized = sanitize.strip_and_list(inputs)
|
|
typed = type_hosts_organized.type_hosts(sanitized)
|
|
var = tk.Variable()
|
|
|
|
|
|
class LookupFrame(ttk.Frame):
|
|
def __init__(self, container):
|
|
super().__init__(container)
|
|
self.columnconfigure(0, weight=2)
|
|
|
|
self.__create_widgets()
|
|
|
|
def __create_widgets(self) -> None:
|
|
ttk.Label(self, text=IP_LABEL).grid(column=0, row=3)
|
|
self.ip_listbox = tk.Listbox(self)
|
|
self.ip_listbox.insert("end", "TEST")
|
|
|
|
for widget in self.winfo_children():
|
|
widget.grid(padx=0, pady=5)
|
|
|
|
|
|
class App(tk.Tk):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(self, *args, **kwargs)
|
|
self.title(APP_TITLE)
|
|
self.geometry("400x150")
|
|
self.resizable(None, None)
|
|
self.shared_data = {}
|
|
|
|
# layout on the root window
|
|
self.columnconfigure(0, weight=4)
|
|
self.columnconfigure(1, weight=1)
|
|
|
|
self.__create_widgets()
|
|
|
|
def __create_widgets(self) -> None:
|
|
# create the input frame
|
|
input_frame = InputFrame(self)
|
|
input_frame.grid(column=0, row=0)
|
|
lookup_frame = LookupFrame(self)
|
|
lookup_frame.grid(column=0, row=2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = App()
|
|
app.mainloop()
|