aboutsummaryrefslogtreecommitdiff
path: root/macropad.pyw
diff options
context:
space:
mode:
Diffstat (limited to 'macropad.pyw')
-rwxr-xr-xmacropad.pyw33
1 files changed, 18 insertions, 15 deletions
diff --git a/macropad.pyw b/macropad.pyw
index f35e141..2687065 100755
--- a/macropad.pyw
+++ b/macropad.pyw
@@ -25,8 +25,6 @@ config_file = path.join(script_path, "config.ini")
config = configparser.ConfigParser(delimiters="=")
config.read(config_file)
-
-
init_mapping = config["mapping"]
mapping = dict(init_mapping)
@@ -43,14 +41,14 @@ from sys import platform
if platform == "win32":
import win32
window_listener = win32.Listener(mapping, q)
- window_listener.start()
component.provideUtility(window_listener, interfaces.desktopEvent.IDesktop)
+ window_listener.start()
elif platform == 'linux':
import xlib
xlib_listener = xlib.Listener(mapping, q)
- xlib_listener.start()
component.provideUtility(xlib_listener, interfaces.desktopEvent.IDesktop)
+ xlib_listener.start()
#
# How to connect to the peripherical
@@ -69,16 +67,14 @@ elif config.has_section("connection.socket"):
from socket_conn import SocketConnection
endpoint = component.queryAdapter(SocketConnection(config["connection.socket"]), endpoint.IEndpoint)
endpoint.queue = q
- endpoint.connect()
component.provideUtility(endpoint, interfaces.endpoint.IEndpoint)
+ endpoint.connect()
if config.has_section("socket.serve"):
import socketserver
server = socketserver.Handler(config["socket.serve"], q)
-
else:
-
server = None
@@ -95,7 +91,8 @@ class Icon(object):
self.stop = threading.Event()
self.show_hide = threading.Event()
- # Start the icon into a new thread in order to keep the main loop control
+ # Start the icon into a new thread in order to keep the main loop
+ # control
icon_thread = threading.Thread(target=self.icon.run)
self.icon_thread = icon_thread
@@ -192,13 +189,19 @@ class Application(object):
return
self.last_layout = data
- if data == "Windows":
- j = [ {"layout": data} ]
- else:
- # Add the Windows layout in the bottom layer
- j = [ {"layout": "Windows"}, {"stack": data} ]
-
- component.queryUtility(interfaces.endpoint.IEndpoint).send(j)
+ if isinstance(data, dict):
+ component.queryUtility(interfaces.endpoint.IEndpoint).send(data)
+ return
+ elif isinstance(data, str):
+ if not path.exists(data):
+ print("The file '%s' does not exists" % data)
+ return
+ with open(data, "r") as json_file:
+ json_data = json_file.read()
+ j = json.loads(json_data)
+ content = json.dumps(j)
+
+ component.queryUtility(interfaces.endpoint.IEndpoint).send(j)
def associate(self, layout: str, name: str):
mapping[name] = layout