52 lines
1.1 KiB
Python
52 lines
1.1 KiB
Python
import network
|
|
import tkinter as tk
|
|
import sys
|
|
|
|
listen_addr = ("0.0.0.0", int(sys.argv[1]))
|
|
send_addr = ("192.168.0.255", int(sys.argv[2]))
|
|
|
|
sock = network.Sock()
|
|
waiting_for_text = True
|
|
|
|
root = tk.Tk()
|
|
|
|
area = tk.Text()
|
|
area.pack()
|
|
|
|
def diff(old, new):
|
|
index = 0
|
|
if len(old) > len(new):
|
|
for i in range(len()):
|
|
pass
|
|
|
|
def area_input(event):
|
|
#print(area.get("1.0", "end"))
|
|
print(event)
|
|
sock.send({"type":"insert", "start":"1.0", "text":area.get("1.0", "end")}, send_addr)
|
|
|
|
#if event.keycode == 25:
|
|
# area.mark_set("insert", "1.0")
|
|
|
|
def on_request(r):
|
|
global waiting_for_text
|
|
print(r)
|
|
c, a = r
|
|
if c["type"] == "set":
|
|
if waiting_for_text:
|
|
area.replace("1.0", "end", c["text"])
|
|
waiting_for_text = False
|
|
elif c["type"] == "insert":
|
|
area.insert(c["start"], c["text"])
|
|
elif c["type"] == "replace":
|
|
area.replace(c["start"], c["end"], c["text"])
|
|
elif c["type"] == "get":
|
|
sock.send({"type":"set", "text":area.get("1.0", "end")}, send_addr)
|
|
area.insert("1.0", r[1])
|
|
|
|
area.bind("<KeyRelease>", area_input)
|
|
|
|
sock.listen(listen_addr, on_request)
|
|
|
|
sock.send({"type":"get"}, send_addr)
|
|
|
|
root.mainloop()
|