Skip to content

Commit 0c118da

Browse files
committed
fast run
1 parent 115f4ba commit 0c118da

File tree

4 files changed

+251
-0
lines changed

4 files changed

+251
-0
lines changed

FastRun/GUI.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from PySimpleGUI.PySimpleGUI import Button
2+
from configurer import create_config
3+
from tkinter.constants import CENTER
4+
import PySimpleGUI as sg
5+
6+
choose = [
7+
[
8+
sg.Button("Add"),
9+
sg.In(size=(25, 1), key="app")
10+
],
11+
[
12+
sg.Text("or")
13+
],
14+
[
15+
sg.FileBrowse("Choose application", enable_events=True, key="chooseApp"),
16+
]
17+
]
18+
19+
layout = [
20+
[
21+
sg.Text("FastRun", justification=CENTER, size=(50,2)),
22+
],
23+
[
24+
sg.Text("Name"),
25+
sg.In(size=(25, 1), default_text="main",enable_events=True, key="name"),
26+
],
27+
[
28+
sg.Text("Number of screen"),
29+
sg.In(size=(5, 1),enable_events=True, key="nScreen"),
30+
],
31+
choose,
32+
[
33+
sg.Listbox(values=[], enable_events=True, size=(50, 10), key="appList")
34+
],
35+
[
36+
sg.Button("Submit")
37+
]
38+
]
39+
40+
window = sg.Window("FastRun", layout)
41+
42+
Name = "main"
43+
nScreen = 1
44+
AppList = []
45+
46+
while True:
47+
event, values = window.read()
48+
if event == sg.WIN_CLOSED:
49+
break
50+
elif event == "Submit" :
51+
create_config(AppList, nScreen, Name)
52+
break
53+
54+
elif event == "name":
55+
Name = values["name"]
56+
57+
elif event == "nScreen":
58+
try:
59+
nScreen = int(values["nScreen"])
60+
except:
61+
pass
62+
63+
elif event == "chooseApp":
64+
app = values["chooseApp"]
65+
if(app.strip() != ""):
66+
AppList.append(app)
67+
window["appList"].update(AppList)
68+
69+
elif event == "Add":
70+
app = values["app"]
71+
if(app.strip() != ""):
72+
AppList.append(app)
73+
window["appList"].update(AppList)
74+
window["app"].update("")
75+
76+
window.close()

FastRun/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# FastRun
2+
3+
FastRun is a script to create a routine to launch several applications on the different Windows desktops with a single click.
4+
5+
## Instalation
6+
* ``` bash
7+
pip install pysimplegui
8+
```
9+
## Execution
10+
Click on GUI.py to lauch the interface
11+
12+
## Use
13+
14+
1. Choose a name for your routine
15+
2. Give your number of desktop
16+
3. Add an url to open like "www.google.com" or Choose an application to open.
17+
4. Submit your choices. Now there is a shortcut on your desktop to lauch your new routine.

FastRun/VirtualDesktopAccessor.dll

30 KB
Binary file not shown.

FastRun/configurer.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import os
2+
import json
3+
import sys
4+
import ctypes, time, subprocess
5+
import getpass
6+
import webbrowser
7+
from win32com.client import Dispatch
8+
9+
# file in which all configurations will be stored
10+
FILE = 'config.json'
11+
12+
# return value used in case of success for some functions
13+
# it is set to '' so as to append error messages if error happen
14+
SUCCESS = ''
15+
16+
# set of commands used to check user input in the main method
17+
RESET = ['r', 'reset', 'rm', 'remove']
18+
CREATE = ['c', 'create', 'cr']
19+
YES = ['yes', 'y', 'ya', 'ye']
20+
21+
# gets the username of C:\Users\username
22+
USER = getpass.getuser()
23+
24+
isFile = lambda x : os.path.isfile(x)
25+
rm = lambda x : os.remove(x)
26+
27+
28+
29+
class Config:
30+
'''
31+
This class represents a configuration object
32+
such configuration has a list of strings, each string in this list should be the path to the
33+
executable file of a program.
34+
the n_desktops attribute states how many desktops will be used to start such programs
35+
the name of the configuration is the way this configuration is identified, it should be unique for
36+
each configuration
37+
'''
38+
39+
def __init__(self, programs = None, n_desktops = 1, name = 'main'):
40+
self.programs = programs
41+
self.n_desktops = n_desktops
42+
self.name = name
43+
44+
def __str__(self):
45+
return str(self.__dict__)
46+
47+
48+
49+
def reset_config(filename):
50+
if isFile(filename): rm(filename)
51+
52+
53+
def save_configs(configs, filename):
54+
json_str = json.dumps([c.__dict__ for c in configs])
55+
with open(filename, 'w') as f:
56+
f.write(json_str)
57+
58+
59+
def load_configs(filename):
60+
if not isFile(filename) : return None
61+
62+
with open(filename, 'r') as f:
63+
lines = json.load(f)
64+
65+
return [Config(d['programs'], d['n_desktops'], d['name']) for d in lines]
66+
67+
68+
def find_config(configs, name):
69+
for c in configs:
70+
if c.name == name: return c
71+
return None
72+
73+
def isUrl(program):
74+
if "http" in program or "www." in program:
75+
return True
76+
return False
77+
78+
def isValid(program):
79+
return isUrl(program) or isFile(program)
80+
81+
def run_config(configs, name):
82+
config = find_config(configs, name)
83+
err_code = SUCCESS
84+
if config :
85+
virtual_desktop_accessor = ctypes.WinDLL("./VirtualDesktopAccessor.dll")
86+
for i in range(len(config.programs)):
87+
program = config.programs[i]
88+
if (i < config.n_desktops):
89+
virtual_desktop_accessor.GoToDesktopNumber(i)
90+
print("Go to screen ", i)
91+
92+
if isUrl(program):
93+
webbrowser.open(program)
94+
else:
95+
subprocess.Popen(program, close_fds=True)
96+
97+
time.sleep(1)
98+
print("Run ", program)
99+
else :
100+
err_code = "No config {0} found".format(name)
101+
return err_code
102+
103+
def create_config(programs, nScreen, name, filename = FILE):
104+
configs = load_configs(FILE)
105+
if name.strip() == "":
106+
name = 'main'
107+
108+
config = Config(programs, nScreen, name)
109+
if configs :
110+
configs.append(config)
111+
save_configs(configs, filename)
112+
else :
113+
save_configs([config], filename)
114+
115+
create_executable(config)
116+
117+
def create_executable(config):
118+
print(config)
119+
filename = config.name + ".bat"
120+
print(filename)
121+
f = open(filename, "w")
122+
f.write("python configurer.py {0}".format(config.name))
123+
f.close()
124+
125+
createShortcut(filename, config.name, icon="C:\\Users\\Ugo\\Documents\\Projet\\FastRun\\icone\\beeboop.ico")
126+
127+
128+
def createShortcut(filename, name, icon=''):
129+
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
130+
shell = Dispatch('WScript.Shell')
131+
shortcut = shell.CreateShortCut(desktop + "\\" + name + ".lnk")
132+
shortcut.Targetpath = os.path.abspath(os.getcwd()) + "\\" + filename
133+
shortcut.WorkingDirectory = os.path.abspath(os.getcwd())
134+
if icon == '':
135+
pass
136+
else:
137+
shortcut.IconLocation = icon
138+
shortcut.save()
139+
140+
141+
if __name__ == '__main__':
142+
configs = load_configs(FILE)
143+
argv = sys.argv
144+
145+
if configs :
146+
if len(argv) == 1:
147+
error = run_config(configs, configs[0].name)
148+
if error != SUCCESS: print(error)
149+
150+
elif argv[1].lower() in RESET:
151+
reset_config(FILE)
152+
153+
else :
154+
error = run_config(configs, argv[1])
155+
if error != SUCCESS: print(error)
156+
157+
else :
158+
create_config(argv[1], argv[2], argv[3])

0 commit comments

Comments
 (0)