KindIRC/kindirc.py
2025-01-06 16:28:17 -08:00

167 lines
5.3 KiB
Python

import tkinter as tk, threading, socket, ssl
root = tk.Tk()
root.geometry("1072x1448")
root.attributes('-topmost',True)
splash = """KindIRC v0.1
######################
# # #
# ## ## # # #
# ####### # # #
# ##### # # #
# # # # #
# # #
# ##################
# #
# #
##
Please use:
* /nick nick - Set the nickname before connecting
* /pass pass - Set the password (znc pass) before connecting
* /nsid [username] pass - Set the nickserv pass before connecting
* /connect server [port] - Connect to server.
"""
text = tk.Text(root, width=1072, font=("monospace", 25))
root.columnconfigure(index=0, weight=1)
root.rowconfigure(index=1, weight=1)
def insert(stri):
text.configure(state=tk.NORMAL)
text.insert(tk.END,stri)
text.see("end")
text.configure(state=tk.DISABLED)
global frame
global frame2
global caps
global shft
global connected
global nick
global socket
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
nick = "kindle"
connected = False
caps = False
shft = False
insert(splash)
input = tk.Entry(root, width=1072, font=("monospace", 25))
text.pack()
input.pack()
def press(key:str):
if key == "":
pass
elif len(key) == 1:
input.insert(tk.END, key)
else:
if key == "SPACE":
input.insert(tk.END, " ")
elif key == "BKSP":
e = input.get()[:-1]
input.delete(0, tk.END)
input.insert(tk.END, e)
input.xview_scroll(500, tk.UNITS)
def enter():
out = input.get()
if out == "":
pass
if out[0] == "/":
if out.split(" ")[0] == "/connect":
insert("\nNot implemented.")
elif out.split(" ")[0] == "/nick":
if len(out.split(" ")) == 2:
global nick
nick = out.split(" ")[1]
if not connected:
insert(f"Nickname changed to {nick}")
else:
if connected:
pass
else:
insert("\nNot connected to a server.")
input.delete(0, tk.END)
def rebuild_keyboard():
global shft
global caps
def keyse(k):
global shft
press(k)
if shft:
shft = False
rebuild_keyboard()
global frame
global frame2
try:
frame.destroy()
except:
pass
try:
frame2.destroy()
except:
pass
frame2 = tk.Frame(root, width=1072)
space = tk.Button(frame2, font=("monospace", 25), width=45, height=2, text=" ", command=lambda k="SPACE": press(k))
space.grid(row=1, column=1)
frame = tk.Frame(root, width=1072)
frame.pack()
frame2.pack()
keys_lower = [
"`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "",
"", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\\",
"", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "", "",
"", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"
]
keys_capper = [
"`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "",
"", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\",
"", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "", "",
"","Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"
]
keys_shift = [
"~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "",
"", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "{", "}", "|",
"", "A", "S", "D", "F", "G", "H", "J", "K", "L", ":", '"', "", "",
"", "Z", "X", "C", "V", "B", "N", "M", "<", ">", "?"
]
keys_shift_cap = [
"~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "",
"", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "{", "}", "|",
"", "a", "s", "d", "f", "g", "h", "j", "k", "l", ":", '"', "", "",
"", "z", "x", "c", "v", "b", "n", "m", "<", ">", "?"
]
if caps:
if shft:
keys = keys_shift_cap
else:
keys = keys_capper
elif shft:
keys = keys_shift
else:
keys = keys_lower
row, col = 0, 1
for key in keys:
if key != "":
button = tk.Button(frame, font=("monospace", 25), width=3, height=2, text=key, command=lambda k=key: keyse(k))
button.grid(row=row, column=col, padx=2, pady=2)
col += 1
if col > 14:
col = 1
row += 1
bksp = tk.Button(frame, font=("monospace", 25), width=3, height=2, text="", command=lambda k="BKSP": keyse(k))
bksp.grid(row=0, column=14)
def cap():
global caps
caps = not caps
rebuild_keyboard()
capskey = tk.Button(frame, font=("monospace", 25), width=3, height=2, text="CAP" if not caps else "low", command=cap)
capskey.grid(row=2, column=1)
def shf():
global shft
shft = not shft
rebuild_keyboard()
shftkey = tk.Button(frame, font=("monospace", 25), width=3, height=2, text="" if not shft else "", command=shf)
shftkey.grid(row=3, column=1)
shftkey = tk.Button(frame, font=("monospace", 25), width=3, height=2, text="" if not shft else "", command=shf)
shftkey.grid(row=3, column=12)
enterkey = tk.Button(frame, font=("monospace", 25), width=3, height=2, text="", command=enter)
enterkey.grid(row=2, column=13)
rebuild_keyboard()
input.focus()
root.mainloop()