-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
199 lines (150 loc) · 6.41 KB
/
gui.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import subprocess
import time
import platform
import re
import tkinter.font as font
from tkinter import ttk
from PIL import ImageTk,Image
from frames.InitFrame import *
""" Global variables"""
g_list_nic = []
g_dict_osinfo = {}
g_suitable_os = ["Microsoft Windows Server 2012",
"Microsoft Windows Server 2016",
"Microsoft Windows Server 2019",
"Microsoft Windows Server 2022",
"Microsoft Windows 10"]
""" Main funtions"""
def destroy_items(buttons_list, buttons_border_list):
""" Delete all items of the frame"""
for index in range(0, len(buttons_list)):
buttons_list[index].destroy()
buttons_border_list[index].destroy()
def check_os_list():
""" Search in suitable OS list"""
suitable_os = False
for os in range(len(g_suitable_os)):
if g_suitable_os[os] in g_dict_osinfo["OsName"]:
suitable_os = True
break
return suitable_os
def check_os(master):
""" Create new next frame menu if system is Windows Server """
suitable_os = False
if (check_os_list()):
messagebox.showinfo("Check operating system","Version " + g_dict_osinfo["OsName"] + " is valid")
suitable_os = True
else:
messagebox.showwarning("Check operating system", "Must be a Windows version 2012/2016/2019/2022 " + "\n(You have " + g_dict_osinfo["OsName"] + ")")
return suitable_os
def check_system(master):
""" Check if the system is Windows Server """
suitable_os = False
if len(g_dict_osinfo) == 0:
if platform.system() == 'Windows':
# Create background subprocess for cmdlet
p = subprocess.Popen(['powershell.exe', "-ExecutionPolicy", "Bypass", '.\\scripts\\osinfo.ps1'], stdout=subprocess.PIPE, stderr= subprocess.PIPE)
# Create progress bar
create_progress_bar("Executing command Get-ComputerInfo.", p)
skip_title = 0
for line in p.stdout:
if len(line) > 2:
# Decode line format
decoded_line = line.decode('utf-8', errors='strict').strip()
clean_line = re.sub('\s+',' ', str(decoded_line))
key = clean_line.split()[0]
g_dict_osinfo[key] = clean_line.partition(' ')[2]
else:
skip_title += 1
suitable_os = check_os(master)
else:
messagebox.showwarning("Check operating system", "Must be a Windows version 2012/2016/2019/2022 " + "\n(You have " + g_dict_osinfo["OsName"] + ")")
else:
suitable_os = check_os(master)
return suitable_os
def get_nics(master):
""" Execute cmdlet to get all NICs of the machine """
if len(g_list_nic) == 0:
p = subprocess.Popen(['powershell.exe', "-ExecutionPolicy", "Bypass", '.\\scripts\\nics.ps1'], stdout=subprocess.PIPE, stderr= subprocess.PIPE)
# Create progress bar
create_progress_bar("Executing command Get-NetAdapter.", p)
skip_title = 0
for line in p.stdout:
if len(line) > 2 and skip_title >= 3:
decoded_line = line.decode('utf-8', errors='replace').strip()
clean_line = re.sub('\s+',' ', str(decoded_line))
#print(clean_line)
g_list_nic.append(clean_line)
else:
skip_title += 1
def create_progress_bar(text, p):
""" Create generic progress bar """
top = tk.Toplevel()
top.resizable(False, False)
top.geometry("400x80")
top.title("Checking OS information")
top.iconbitmap("img/icaad.ico")
lbl = tk.Label(top, text= text, bg='white', fg='#707070')
lbl.pack(pady=10)
s = ttk.Style()
s.theme_use("winnative")
s.configure("blue.Horizontal.TProgressbar",troughcolor='#f2f2f2', foreground='white', background='#0077d1')
progress_bar = ttk.Progressbar(top, style="blue.Horizontal.TProgressbar", orient=tk.HORIZONTAL, length=300, mode="indeterminate")
progress_bar.pack()
cnt = 0
# Show progress bar while cmdlet is running
while (p.poll() is None):
if progress_bar['value'] == 100:
progress_bar['value'] = 0
else:
progress_bar['value'] += 5%100
if progress_bar['value']%25 == 0:
if cnt == 2:
lbl['text'] = lbl['text'][:-2]
cnt = 0
else:
lbl['text'] += "."
cnt += 1
top.update_idletasks()
time.sleep(0.125)
top.destroy()
def create_button(master, button_name):
""" Create a generic button """
main_font = font.Font(size="13", family="Helvetica")
button_border = tk.Frame(master,
highlightbackground="gray87",
highlightcolor="gray87",
highlightthickness=2,
bd=0)
button = tk.Button(button_border,
activebackground='#e6f5ff',
bg="white", width = 30,
height = 3, text=button_name,
relief='groove',
borderwidth=0,
font = main_font)
button.bind("<Enter>", lambda e: button.config(bg='#f7fcff'))
button_border.bind("<Enter>", lambda e: button_border.config(highlightbackground="#538de6", highlightcolor="#538de6"))
button.bind("<Leave>", lambda e: button.config(bg='white'))
button_border.bind("<Leave>", lambda e: button_border.config(highlightbackground="gray87", highlightcolor="gray87"))
return button_border, button
def open_cmd(root):
""" Runs cmd.py and destroy GUI frame """
option = messagebox.askquestion("CMD Version","Do you want to open ICAAD CMD version?")
if option == "yes":
root.destroy()
subprocess.run(["python.exe","cmd.py"])
def main():
""" Define and create main frame """
root = tk.Tk()
root.title("ICAAD Software")
root.iconbitmap("img/icaad.ico")
#root.wm_minsize(435,450)
root.resizable(False, False)
root.configure(bg='white')
main_icon = ImageTk.PhotoImage(Image.open("img/icaad.png"))
icon_label = tk.Label(root, image=main_icon, bg='white').place(x=13, y=13)
e = InitFrame(root)
root.mainloop()
if __name__ == "__main__":
main()