diff --git a/FastRun/GUI.py b/FastRun/GUI.py new file mode 100644 index 00000000..998af0c0 --- /dev/null +++ b/FastRun/GUI.py @@ -0,0 +1,76 @@ +from PySimpleGUI.PySimpleGUI import Button +from configurer import create_config +from tkinter.constants import CENTER +import PySimpleGUI as sg + +choose = [ + [ + sg.Button("Add"), + sg.In(size=(25, 1), key="app") + ], + [ + sg.Text("or") + ], + [ + sg.FileBrowse("Choose application", enable_events=True, key="chooseApp"), + ] +] + +layout = [ + [ + sg.Text("FastRun", justification=CENTER, size=(50,2)), + ], + [ + sg.Text("Name"), + sg.In(size=(25, 1), default_text="main",enable_events=True, key="name"), + ], + [ + sg.Text("Number of screen"), + sg.In(size=(5, 1),enable_events=True, key="nScreen"), + ], + choose, + [ + sg.Listbox(values=[], enable_events=True, size=(50, 10), key="appList") + ], + [ + sg.Button("Submit") + ] +] + +window = sg.Window("FastRun", layout) + +Name = "main" +nScreen = 1 +AppList = [] + +while True: + event, values = window.read() + if event == sg.WIN_CLOSED: + break + elif event == "Submit" : + create_config(AppList, nScreen, Name) + break + + elif event == "name": + Name = values["name"] + + elif event == "nScreen": + try: + nScreen = int(values["nScreen"]) + except: + pass + + elif event == "chooseApp": + app = values["chooseApp"] + if(app.strip() != ""): + AppList.append(app) + window["appList"].update(AppList) + + elif event == "Add": + app = values["app"] + if(app.strip() != ""): + AppList.append(app) + window["appList"].update(AppList) + window["app"].update("") + +window.close() \ No newline at end of file diff --git a/FastRun/README.md b/FastRun/README.md new file mode 100644 index 00000000..e5596274 --- /dev/null +++ b/FastRun/README.md @@ -0,0 +1,17 @@ +# FastRun + +FastRun is a script to create a routine to launch several applications on the different Windows desktops with a single click. + +## Instalation +* ``` bash + pip install pysimplegui + ``` +## Execution +Click on GUI.py to lauch the interface + +## Use + +1. Choose a name for your routine +2. Give your number of desktop +3. Add an url to open like "www.google.com" or Choose an application to open. +4. Submit your choices. Now there is a shortcut on your desktop to lauch your new routine. \ No newline at end of file diff --git a/FastRun/VirtualDesktopAccessor.dll b/FastRun/VirtualDesktopAccessor.dll new file mode 100644 index 00000000..d6af0adc Binary files /dev/null and b/FastRun/VirtualDesktopAccessor.dll differ diff --git a/FastRun/configurer.py b/FastRun/configurer.py new file mode 100644 index 00000000..a431b0cb --- /dev/null +++ b/FastRun/configurer.py @@ -0,0 +1,158 @@ +import os +import json +import sys +import ctypes, time, subprocess +import getpass +import webbrowser +from win32com.client import Dispatch + +# file in which all configurations will be stored +FILE = 'config.json' + +# return value used in case of success for some functions +# it is set to '' so as to append error messages if error happen +SUCCESS = '' + +# set of commands used to check user input in the main method +RESET = ['r', 'reset', 'rm', 'remove'] +CREATE = ['c', 'create', 'cr'] +YES = ['yes', 'y', 'ya', 'ye'] + +# gets the username of C:\Users\username +USER = getpass.getuser() + +isFile = lambda x : os.path.isfile(x) +rm = lambda x : os.remove(x) + + + +class Config: + ''' + This class represents a configuration object + such configuration has a list of strings, each string in this list should be the path to the + executable file of a program. + the n_desktops attribute states how many desktops will be used to start such programs + the name of the configuration is the way this configuration is identified, it should be unique for + each configuration + ''' + + def __init__(self, programs = None, n_desktops = 1, name = 'main'): + self.programs = programs + self.n_desktops = n_desktops + self.name = name + + def __str__(self): + return str(self.__dict__) + + + +def reset_config(filename): + if isFile(filename): rm(filename) + + +def save_configs(configs, filename): + json_str = json.dumps([c.__dict__ for c in configs]) + with open(filename, 'w') as f: + f.write(json_str) + + +def load_configs(filename): + if not isFile(filename) : return None + + with open(filename, 'r') as f: + lines = json.load(f) + + return [Config(d['programs'], d['n_desktops'], d['name']) for d in lines] + + +def find_config(configs, name): + for c in configs: + if c.name == name: return c + return None + +def isUrl(program): + if "http" in program or "www." in program: + return True + return False + +def isValid(program): + return isUrl(program) or isFile(program) + +def run_config(configs, name): + config = find_config(configs, name) + err_code = SUCCESS + if config : + virtual_desktop_accessor = ctypes.WinDLL("./VirtualDesktopAccessor.dll") + for i in range(len(config.programs)): + program = config.programs[i] + if (i < config.n_desktops): + virtual_desktop_accessor.GoToDesktopNumber(i) + print("Go to screen ", i) + + if isUrl(program): + webbrowser.open(program) + else: + subprocess.Popen(program, close_fds=True) + + time.sleep(1) + print("Run ", program) + else : + err_code = "No config {0} found".format(name) + return err_code + +def create_config(programs, nScreen, name, filename = FILE): + configs = load_configs(FILE) + if name.strip() == "": + name = 'main' + + config = Config(programs, nScreen, name) + if configs : + configs.append(config) + save_configs(configs, filename) + else : + save_configs([config], filename) + + create_executable(config) + +def create_executable(config): + print(config) + filename = config.name + ".bat" + print(filename) + f = open(filename, "w") + f.write("python configurer.py {0}".format(config.name)) + f.close() + + createShortcut(filename, config.name, icon="C:\\Users\\Ugo\\Documents\\Projet\\FastRun\\icone\\beeboop.ico") + + +def createShortcut(filename, name, icon=''): + desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') + shell = Dispatch('WScript.Shell') + shortcut = shell.CreateShortCut(desktop + "\\" + name + ".lnk") + shortcut.Targetpath = os.path.abspath(os.getcwd()) + "\\" + filename + shortcut.WorkingDirectory = os.path.abspath(os.getcwd()) + if icon == '': + pass + else: + shortcut.IconLocation = icon + shortcut.save() + + +if __name__ == '__main__': + configs = load_configs(FILE) + argv = sys.argv + + if configs : + if len(argv) == 1: + error = run_config(configs, configs[0].name) + if error != SUCCESS: print(error) + + elif argv[1].lower() in RESET: + reset_config(FILE) + + else : + error = run_config(configs, argv[1]) + if error != SUCCESS: print(error) + + else : + create_config(argv[1], argv[2], argv[3])