aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2021-06-07 20:54:01 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2021-06-07 20:54:01 +0200
commitd3d7deb62bc53f7b6fa25468f12f2042f62d1555 (patch)
tree40aabc967e01437cfeaa0397fc5fabf26de3aac0
parent44c04c06319cb82a2d9ef2ad4a44da133381f302 (diff)
downloadpicardy-master.tar.gz
picardy-master.tar.bz2
picardy-master.zip
gui: add multiline messages and keyboard shortcutsHEADmaster
-rwxr-xr-xsw/eval-clock-cw-tx/gui.py54
1 files changed, 44 insertions, 10 deletions
diff --git a/sw/eval-clock-cw-tx/gui.py b/sw/eval-clock-cw-tx/gui.py
index 5b39ccb..577dd8c 100755
--- a/sw/eval-clock-cw-tx/gui.py
+++ b/sw/eval-clock-cw-tx/gui.py
@@ -65,7 +65,16 @@ class GUI(Frame):
elif self.last_serial_message == b"Switch TX\n" and self.enable_mute.get():
os.system("pactl set-sink-mute 0 1")
elif self.last_serial_message.startswith(b"FH sent"):
- self.send_serial(b'rx\n')
+ if self.tx_messages:
+ del self.tx_messages[0]
+ self.tx_messages_var.set(self.tx_messages)
+
+ if self.tx_messages:
+ msg = self.tx_messages[0]
+ print(f"Send '{msg}'")
+ self.send_serial('m {} \n'.format(msg).encode("ascii"))
+ else:
+ self.send_serial(b'rx\n')
self.last_serial_message = bytes()
except serial.SerialException as e:
self.set_status(f"Serial read failed: {e:!r}")
@@ -110,7 +119,8 @@ class GUI(Frame):
self.root.after(1000, self.send_serial, b'rx\n')
def load_macro(self, i):
- self.tx_message.set(self.macro_widgets[i]["var"].get())
+ self.tx_messages.append(self.macro_widgets[i]["var"].get())
+ self.tx_messages_var.set(self.tx_messages)
def send_serial(self, message):
if self.serial is not None:
@@ -125,9 +135,19 @@ class GUI(Frame):
self.send_serial(b'fontw\n')
def send_tx_message(self):
- msg = self.tx_message.get()
- print(f"TX and Send '{msg}'")
- self.send_serial('tx\nm {} \n'.format(msg).encode("ascii"))
+ if self.tx_messages:
+ msg = self.tx_messages[0]
+ print(f"TX and Send '{msg}'")
+ self.send_serial('tx\nm {} \n'.format(msg).encode("ascii"))
+
+ def append_message_edit(self, event=None):
+ self.tx_messages.append(self.message_edit_var.get())
+ self.tx_messages_var.set(self.tx_messages)
+ self.message_edit_var.set("")
+
+ def clear_tx_messages(self):
+ self.tx_messages.clear()
+ self.tx_messages_var.set(self.tx_messages)
def create_widgets(self):
self.root.columnconfigure(0, weight=1)
@@ -148,9 +168,13 @@ class GUI(Frame):
tv.set(DEFAULT_MACROS[i])
e = Entry(self.macros_frame, textvariable=tv, width=80)
e.grid(column=0, row=i)
- b = Button(self.macros_frame, text=f"Load {i}", command=partial(self.load_macro, i))
+ b = Button(self.macros_frame, text=f"Load {i+1}", command=partial(self.load_macro, i))
b.grid(column=1, row=i)
+ def handle_f1_event(i, event=None):
+ self.load_macro(i)
+ self.root.bind("<F{}>".format(i+1), partial(handle_f1_event, i))
+
self.macro_widgets.append({'entry': e, 'button': b, 'var': tv})
@@ -199,13 +223,23 @@ class GUI(Frame):
self.transmit_frame.columnconfigure(0, weight=1)
self.transmit_frame.columnconfigure(1, weight=1)
- self.tx_message = StringVar()
- self.tx_message_entry = Entry(self.transmit_frame, width=90, textvariable=self.tx_message)
- self.tx_message_entry.grid(column=0, row=0, sticky=(N, S, E, W))
+ self.message_edit_var = StringVar()
+ self.message_edit = Entry(self.transmit_frame, width=90, textvariable=self.message_edit_var)
+ self.message_edit.bind("<Return>", self.append_message_edit)
+ self.message_edit.grid(column=0, row=0, sticky=(N, S, E, W))
+
+ self.tx_messages = []
+ self.tx_messages_var = StringVar(value=self.tx_messages)
+ self.tx_message_entry = Listbox(self.transmit_frame, width=90, listvariable=self.tx_messages_var)
+ self.tx_message_entry.grid(column=0, columnspan=2, row=1, sticky=(N, S, E, W))
self.tx_message_entry.columnconfigure(0, weight=1)
self.tx_message_entry.columnconfigure(1, weight=1)
+
self.tx_message_button = Button(self.transmit_frame, text="Send", command=self.send_tx_message)
- self.tx_message_button.grid(column=0, row=1, sticky=(N, S, E, W))
+ self.tx_message_button.grid(column=0, row=2, sticky=(N, S, E, W), columnspan=1)
+ self.clear_tx_message_button = Button(self.transmit_frame, text="Clear", command=self.clear_tx_messages)
+ self.clear_tx_message_button.grid(column=1, row=2, sticky=(N, S, E, W), columnspan=1)
+
self.status_var = StringVar()
self.status_label = Label(self.top_frame, bd=1, relief=SUNKEN, anchor=W, textvariable=self.status_var)