summaryrefslogtreecommitdiff
path: root/monitor-menu.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2018-07-04 10:52:47 +0200
committerOlivier Gayot <olivier.gayot@sigexec.com>2018-07-04 10:54:07 +0200
commit315a75e3ee57b479dade9ce14d70b3aa2d56e105 (patch)
treea9c2cf7baf060695eb02daed381919b566e3700a /monitor-menu.py
parent35f33f81e41a13aa2a68d9266fab4094707e1984 (diff)
Added basics for the script to run
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'monitor-menu.py')
-rwxr-xr-xmonitor-menu.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/monitor-menu.py b/monitor-menu.py
new file mode 100755
index 0000000..4aeec25
--- /dev/null
+++ b/monitor-menu.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+
+from os.path import expanduser
+
+import dialog
+import json
+import subprocess
+
+d = dialog.Dialog()
+
+class MonitorMenu():
+ def __init__(self, config_file='~/.config/monitor-profiles.json'):
+ with open(expanduser(config_file)) as fd:
+ self.profiles = json.load(fd)
+
+ def run(self):
+ choices = []
+
+ i = 0
+ for p in self.profiles:
+ choices.append((str(i), p['name']))
+ i += 1
+
+ code, profile_idx = d.menu('Select the profile you want to use.', choices=choices)
+
+ if code == d.ESC or code == d.CANCEL:
+ return
+
+ profile = self.profiles[int(profile_idx)]
+
+ # We build the command line starting from just "xrandr" and adding arguments.
+ cmd = ['xrandr']
+
+ try:
+ cmd += profile['xrandr-opts']
+ except KeyError:
+ pass
+
+ for monitor in profile['monitors']:
+ cmd += monitor['xrandr-opts']
+
+ subprocess.run(cmd)
+
+
+def main():
+ menu = MonitorMenu()
+
+ menu.run()
+
+if __name__ == '__main__':
+ main()