From 86145dea370ff85a7b78e8f633235101f3365ec8 Mon Sep 17 00:00:00 2001 From: Julien Date: Wed, 12 Jul 2023 10:19:23 +0200 Subject: Rename callback to callback_parser in db.py --- callbacks.py | 46 ---------------------------------------------- db.py | 20 ++++++++++---------- lidecli.py | 9 +++++---- parsing_callbacks.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 60 deletions(-) delete mode 100644 callbacks.py create mode 100644 parsing_callbacks.py diff --git a/callbacks.py b/callbacks.py deleted file mode 100644 index 70ea1da..0000000 --- a/callbacks.py +++ /dev/null @@ -1,46 +0,0 @@ -import re - -def xprop_parser(input): - result = { - "win_maximized": 0, - "win_maximized_horizontal": 0, - "win_maximized_vertical": 0, - "win_hidden": 0, - "win_minimized": 0, - "win_modal": 0, - "win_sticky": 0, - "win_shaded": 0, - "win_fullscreen": 0, - "win_above": 0, - "win_below": 0 - } - match = re.search(r'_NET_WM_STATE\(ATOM\) = (.*)$', input, re.MULTILINE) - if match: - values = match.group(1).split(", ") - for v in values: - if v == '_NET_WM_STATE_MAXIMIZED_HORZ': - result['win_maximized_horizontal'] = 1 - if v == '_NET_WM_STATE_MAXIMIZED_VERT': - result['win_maximized_vertical'] = 1 - if v == '_NET_WM_STATE_MODAL': - result['win_modal'] = 1 - if v == '_NET_WM_STATE_STICKY': - result['win_sticky'] = 1 - if v == '_NET_WM_STATE_SHADED': - result['win_shaded'] = 1 - if v == '_NET_WM_STATE_HIDDEN': - result['win_hidden'] = 1 - if v == '_NET_WM_STATE_FULLSCREEN': - result['win_fullscreen'] = 1 - if v == '_NET_WM_STATE_BELOW': - result['win_below'] = 1 - if v == '_NET_WM_STATE_ABOVE': - result['win_above'] = 1 - - if result['win_maximized_horizontal'] == 1 and result['win_maximized_vertical'] == 1: - result['win_maximized'] = 1 - if result['win_hidden'] == 1: - result['win_minimized'] = 1 - - return result - diff --git a/db.py b/db.py index e162539..b42362d 100644 --- a/db.py +++ b/db.py @@ -75,7 +75,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_maximized" }, @@ -90,7 +90,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_maximized_horizontal" }, @@ -105,7 +105,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_maximized_vertical" }, @@ -120,7 +120,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_minimized" }, @@ -135,7 +135,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_modal" }, @@ -150,7 +150,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_sticky" }, @@ -165,7 +165,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_shaded" }, @@ -180,7 +180,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_fullscreen" }, @@ -195,7 +195,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_above" }, @@ -210,7 +210,7 @@ def commands(): "versions_working": [("x11", "all")], "versions_not_working": [], "command": "xprop -id #1#", - "callback": { + "callback_parser": { "function": "xprop_parser", "output_key": "win_below" }, diff --git a/lidecli.py b/lidecli.py index 83c2ada..aa717ec 100755 --- a/lidecli.py +++ b/lidecli.py @@ -6,7 +6,7 @@ import sys import json import os import configparser -import callbacks +import parsing_callbacks import db version = "1.0.2" @@ -112,10 +112,11 @@ def exec_command(args): print("Command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output)) return ret = ret.decode('utf-8') - if "callback" in command: - function = getattr(callbacks, command["callback"]["function"]) + if "callback_parser" in command: + function = getattr(parsing_callbacks, command["callback_parser"]["function"]) ret = function(ret) - print(ret["win_maximized"], end='') + ret = ret[command['callback_parser']['output_key']] + # print(ret["win_maximized"], end='') else: print(ret, end='') if (args.store): diff --git a/parsing_callbacks.py b/parsing_callbacks.py new file mode 100644 index 0000000..70ea1da --- /dev/null +++ b/parsing_callbacks.py @@ -0,0 +1,46 @@ +import re + +def xprop_parser(input): + result = { + "win_maximized": 0, + "win_maximized_horizontal": 0, + "win_maximized_vertical": 0, + "win_hidden": 0, + "win_minimized": 0, + "win_modal": 0, + "win_sticky": 0, + "win_shaded": 0, + "win_fullscreen": 0, + "win_above": 0, + "win_below": 0 + } + match = re.search(r'_NET_WM_STATE\(ATOM\) = (.*)$', input, re.MULTILINE) + if match: + values = match.group(1).split(", ") + for v in values: + if v == '_NET_WM_STATE_MAXIMIZED_HORZ': + result['win_maximized_horizontal'] = 1 + if v == '_NET_WM_STATE_MAXIMIZED_VERT': + result['win_maximized_vertical'] = 1 + if v == '_NET_WM_STATE_MODAL': + result['win_modal'] = 1 + if v == '_NET_WM_STATE_STICKY': + result['win_sticky'] = 1 + if v == '_NET_WM_STATE_SHADED': + result['win_shaded'] = 1 + if v == '_NET_WM_STATE_HIDDEN': + result['win_hidden'] = 1 + if v == '_NET_WM_STATE_FULLSCREEN': + result['win_fullscreen'] = 1 + if v == '_NET_WM_STATE_BELOW': + result['win_below'] = 1 + if v == '_NET_WM_STATE_ABOVE': + result['win_above'] = 1 + + if result['win_maximized_horizontal'] == 1 and result['win_maximized_vertical'] == 1: + result['win_maximized'] = 1 + if result['win_hidden'] == 1: + result['win_minimized'] = 1 + + return result + -- cgit v1.2.3