-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_manager.py
74 lines (66 loc) · 2.66 KB
/
app_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import subprocess
import webbrowser
class AppManager:
def __init__(self):
self._load_resource_paths()
def _load_resource_paths(self):
self.apps = {
"notepad": "notepad.exe",
"calculator": "calc.exe",
"paint": "mspaint.exe",
"word": r"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE",
"excel": r"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE",
"powerpoint": r"C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE",
"chrome": r"C:\Program Files\Google\Chrome\Application\chrome.exe",
"vlc": r"C:\Program Files\VideoLAN\VLC\vlc.exe",
"control panel": "control",
"file explorer": "explorer.exe"
}
self.common_dirs = {
"desktop": os.path.join(os.path.expanduser("~"), "Desktop"),
"documents": os.path.join(os.path.expanduser("~"), "Documents"),
"downloads": os.path.join(os.path.expanduser("~"), "Downloads"),
"music": os.path.join(os.path.expanduser("~"), "Music"),
"pictures": os.path.join(os.path.expanduser("~"), "Pictures"),
"videos": os.path.join(os.path.expanduser("~"), "Videos")
}
self.websites = {
"google": "https://www.google.com",
"youtube": "https://www.youtube.com",
"github": "https://www.github.com",
"wikipedia": "https://www.wikipedia.org",
"gmail": "https://www.gmail.com",
"amazon": "https://www.amazon.com",
"netflix": "https://www.netflix.com"
}
def open_website(self, url_or_name):
try:
if url_or_name.lower() in self.websites:
url = self.websites[url_or_name.lower()]
webbrowser.open(url)
return True
return False
except Exception:
return False
def open_directory(self, dir_path):
try:
if dir_path.lower() in self.common_dirs:
full_path = self.common_dirs[dir_path.lower()]
else:
full_path = os.path.expandvars(os.path.expanduser(dir_path))
if os.path.exists(full_path):
subprocess.Popen(f'explorer "{full_path}"')
return True
return False
except Exception:
return False
def open_application(self, app_name):
try:
app_path = self.apps.get(app_name.lower())
if app_path:
subprocess.Popen(app_path)
return True
return False
except Exception:
return False