network
This commit is contained in:
parent
4d6911cb29
commit
d980fdb944
2 changed files with 108 additions and 2 deletions
34
editor.py
34
editor.py
|
|
@ -1,4 +1,12 @@
|
|||
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()
|
||||
|
||||
|
|
@ -14,9 +22,31 @@ def diff(old, new):
|
|||
def area_input(event):
|
||||
#print(area.get("1.0", "end"))
|
||||
print(event)
|
||||
if event.keycode == 25:
|
||||
area.mark_set("insert", "1.0")
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue