From 38d8a0aec7d890903e58b39cac4a3e69e14ea118 Mon Sep 17 00:00:00 2001 From: spertl Date: Mon, 26 Aug 2024 04:51:00 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9Eupload?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upload/test_webserver.py | 96 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 upload/test_webserver.py diff --git a/upload/test_webserver.py b/upload/test_webserver.py new file mode 100644 index 0000000..58a1ebc --- /dev/null +++ b/upload/test_webserver.py @@ -0,0 +1,96 @@ +# Python 3 server example +from http.server import BaseHTTPRequestHandler, HTTPServer +import time +import _thread as thread +import requests +import os +import toml + +#file_path = os.path.dirname(os.path.realpath(__file__)) +file_path = "D:/Daten/nc/Ingenieurbüro/98-CAD-Daten/Tools-QGIS/ibpTools/" + +with open(file_path + 'config.toml', 'r') as f: + config = toml.load(f) + +hostName = config['iface']['host'] +serverPort = config['iface']['port'] + +class IBP_ToolsWebserver(HTTPServer): + + def __init__(self, address, handler, iface): + self.keepalive = True + self.iface = iface + #super().__init__(address, handler) + + def handler(*args): + IBP_ToolsWebserverRequestHandler(iface, *args) + + super().__init__((hostName, serverPort), handler) + print("Server started http://%s:%s" % address) + + def run_server(self): + self.keepalive = True + + while self.keepalive: + self.handle_request() + self.server_close() + print("gestoppt") + + def stop_server(self): + self.keepalive = False + print("Keepalive = False") + requests.get('http://{}:{}'.format(hostName, serverPort)) + + + +class IBP_ToolsWebserverRequestHandler(BaseHTTPRequestHandler): + def __init__(self, iface, *args): + + self.iface = iface + BaseHTTPRequestHandler.__init__(self, *args) + #super().__init__(self, *args) + #super().__init__(request, client_address, server) + + def do_GET(self): + + cmd = self.path.split("/") + + if cmd[1] == "canvas": + if cmd[2] == "center": + print("move to ....") + x = float(cmd[3].split(",")[0]) + y = float(cmd[3].split(",")[1]) + self.iface.mapCanvas().setCenter(QgsPointXY(x ,y)) + + self.send_response(200) + self.send_header("Content-type", "text/html") + self.end_headers() + self.wfile.write(bytes("https://pythonbasics.org", "utf-8")) + self.wfile.write(bytes("

Request: %s

" % self.path, "utf-8")) + self.wfile.write(bytes("", "utf-8")) + self.wfile.write(bytes("

This is an example web server.

", "utf-8")) + self.wfile.write(bytes("", "utf-8")) + + +webServer = IBP_ToolsWebserver((hostName, serverPort), IBP_ToolsWebserverRequestHandler, iface) +# start the server in a background thread +thread.start_new_thread(webServer.run_server, ()) + +print('The server is running but my script is still executing!') + +#webServer.stop_server() + + + +""" +https://qgis.org/pyqgis/3.4/gui/QgsMapCanvas.html +zoomToFeatureIds + +iface.mapCanvas().setCenter(QgsPointXY(797040.360,5306381.879)) +/canvas/center/797040.360,5306381.879 + +http://localhost:8080/test +http://localhost:8080/canvas/center/797040.360,5306381.879 + + +""" \ No newline at end of file