You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.6 KiB
Python

# coding: utf-8
# Author: Arthur 'Grizzly' Grisel-Davy
import subprocess
import json
import argparse
# TODO catch errors in parameters
def get_command(options):
command = 'tilix'
# Directory
if options['dir']:
command+=" -w {}".format(options['dir'])
# Name
if options['name']:
command +=" -t {}".format(options['name'])
# Dimension absolute
if 'dimensions_abs' in options.keys():
command+=" --geometry={}x{}+{}+{}".format(options['dimensions_abs']['W'],
options['dimensions_abs']['H'],
options['dimensions_abs']['pos_W'],
options['dimensions_abs']['pos_H'])
# Dimension Relative
if 'dimensions_rel' in options.keys():
with open(params_path,'r') as f:
params = json.loads(f.read())
L,C,H,W = 0,0,0,0
if 'bottom' in options['dimensions_rel']:
H = int(params["height"]/2)
if 'right' in options['dimensions_rel']:
W = int(params["width"]/2)
if 'half_width' in options['dimensions_rel']:
C = int(params['colones']/2)
else:
C = params['colones']
if 'half_height' in options['dimensions_rel']:
L = int(params['lignes']/2)
else:
L = params['lignes']
command+=" --geometry={}x{}+{}+{}".format(C,L,W,H)
# Command (must be last!)
if 'command' in options.keys():
command += " -e {}".format(options['command'])
return(command)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("template",help="Specify the templato to use (must be in ./templates).")
parser.add_argument("-t","--templates_dir", help="Specify the template directory (absolute path)")
parser.add_argument("-p","--parameters", help="Specify the parameters file (default to ./params.json)")
parser.add_argument("-v", "--verbose", help="Activate verbose output", action="store_true")
args = parser.parse_args()
templates_dir = args.templates_dir or "./templates/"
params_path = args.parameters or "./params.json"
template = args.template + ".json"
verbose = args.verbose
with open(templates_dir+template,'r') as f:
options = json.loads(f.read())
for fen in options['fenetres']:
if verbose:print("Lancement de {}:".format(fen['name']))
command = get_command(fen)
if verbose:print("Using command: \n{}".format(command))
subprocess.call(command.split(' '))