summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2017-01-05 18:33:13 +0100
committerYves Fischer <yvesf-git@xapek.org>2017-01-05 18:33:13 +0100
commit7bd7f060dfceac021b225d9f3e03032e5f2b109b (patch)
treecf605b0a97a68165c408391b8967cb674b6d0878
parent893389f3782379f25bc8220845fe83a78e3125c7 (diff)
downloadmp-tool-7bd7f060dfceac021b225d9f3e03032e5f2b109b.tar.gz
mp-tool-7bd7f060dfceac021b225d9f3e03032e5f2b109b.zip
UI ExampleHEADmaster
-rwxr-xr-xexamples/mp-gtk-remote/mp-gtk-remote.py38
-rw-r--r--mp_tool/web.py9
2 files changed, 45 insertions, 2 deletions
diff --git a/examples/mp-gtk-remote/mp-gtk-remote.py b/examples/mp-gtk-remote/mp-gtk-remote.py
new file mode 100755
index 0000000..c478728
--- /dev/null
+++ b/examples/mp-gtk-remote/mp-gtk-remote.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+from mp_tool import web
+
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk
+
+
+def send_signal(sender):
+ value = int(entry_number.get_value())
+ web.eval(entry_host.get_text(),
+ entry_password.get_text(),
+ "set_value({})\r\n".format(repr(value)))
+
+
+win = Gtk.Dialog(default_width=1100, default_height=200)
+win.connect("delete-event", Gtk.main_quit)
+vbox = win.get_content_area()
+
+entry_host = Gtk.Entry(text='ws://esp_licht:8266')
+vbox.pack_start(entry_host, True, False, 0)
+
+entry_password = Gtk.Entry(text='password')
+vbox.pack_start(entry_password, True, False, 0)
+
+entry_number = Gtk.Scale(
+ orientation=Gtk.Orientation.HORIZONTAL,
+ adjustment=Gtk.Adjustment(0, 0, 63, 1, 10, 0),
+ digits=0)
+vbox.pack_start(entry_number, True, True, 0)
+
+button = Gtk.Button("Sende Signal")
+button.connect("clicked", send_signal)
+vbox.pack_start(button, True, True, 0)
+
+win.show_all()
+Gtk.main()
+
diff --git a/mp_tool/web.py b/mp_tool/web.py
index 39e3010..6891aa5 100644
--- a/mp_tool/web.py
+++ b/mp_tool/web.py
@@ -129,6 +129,8 @@ def eval(url: str, password: str, code: str):
ws = _connect_and_auth(url, password)
ws.send(Constants.ENTER_REPL_MODE)
stdout.write(read_until_eval_or_timeout(ws))
+
+ ws.settimeout(5)
ws.send(code + "\r\n")
result = read_until_eval_or_timeout(ws)
@@ -139,8 +141,11 @@ def eval(url: str, password: str, code: str):
def read_until_eval_or_timeout(ws: websocket.WebSocket):
buf = ""
- while not buf.endswith("\r\n>>> "):
- buf += ws.recv()
+ try:
+ while not buf.endswith("\r\n>>> "):
+ buf += ws.recv()
+ except websocket.WebSocketTimeoutException:
+ pass
return buf