-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
359 lines (304 loc) · 14.6 KB
/
Copy pathgui.py
File metadata and controls
359 lines (304 loc) · 14.6 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
##Archivo de interfaz grafica en donde se le da estilo a los frames del programa
import tkinter as tk
from tkinter import ttk, scrolledtext, filedialog
from shell import Shell
from commands import Commands
from utils import get_current_path
import psutil
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import matplotlib.patheffects as patheffects
class CustomShellUI:
def __init__(self, root):
self.root = root
self.root.title("SisShell")
self.root.geometry("900x650")
self.root.minsize(700, 500)
self.create_system_stats()
self.create_resource_graphs()
self.update_metrics()
# Configuración del tema
self.set_neon_theme()
# Objeto shell y comandos
self.shell = Shell(self)
self.commands = Commands(self.shell)
# Barra de ruta
self.path_frame = ttk.Frame(self.root, style='Neon.TFrame')
self.path_frame.pack(fill=tk.X, padx=10, pady=(10, 0))
self.current_path = get_current_path()
self.path_label = ttk.Label(
self.path_frame,
text=self.current_path,
font=('Consolas', 10, 'bold'),
style='Neon.TLabel',
relief=tk.GROOVE,
padding=5
)
self.path_label.pack(fill=tk.X, expand=True)
# Terminal principal con su scroll
self.main_frame = ttk.Frame(self.root, style='Neon.TFrame')
self.main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
self.text_output = scrolledtext.ScrolledText(
self.main_frame,
wrap=tk.WORD,
bg='#0a0a12',
fg='#00fffc',
insertbackground='#ff00ff',
selectbackground='#6a00ff',
selectforeground='#ffffff',
font=('Consolas', 12),
padx=15,
pady=15,
state="normal",
highlightthickness=2,
highlightbackground='#6a00ff'
)
self.text_output.pack(fill=tk.BOTH, expand=True)
# Panel de entrada de comandos
self.input_frame = ttk.Frame(self.root, style='Neon.TFrame')
self.input_frame.pack(fill=tk.X, padx=10, pady=(0, 10))
# Prompt con estilo neon
self.prompt_label = ttk.Label(
self.input_frame,
text=">",
font=('Consolas', 14, 'bold'),
style='NeonPrompt.TLabel',
padding=(0, 0, 10, 0)
)
self.prompt_label.pack(side=tk.LEFT)
# Entrada de comandos
self.command_entry = ttk.Entry(
self.input_frame,
font=('Consolas', 12),
style='Neon.TEntry',
width=50
)
self.command_entry.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(0, 10))
#Botón para exportar la salida a un archivo.
self.export_button = ttk.Button(
self.input_frame,
text = "Exportar",
style = 'Neon.TButton',
command=lambda: self.export_output()
)
self.export_button.pack(side=tk.RIGHT)
# Botón de ejecución
self.run_button = ttk.Button(
self.input_frame,
text="Ejecutar",
style='Neon.TButton',
command=lambda: self.execute_command(None)
) # <-- Paréntesis cerrado aquí
self.run_button.pack(side=tk.RIGHT)
# Eventos (sin cambios)
self.command_entry.bind("<Return>", self.execute_command)
self.command_entry.bind("<Up>", self.show_previous_command)
self.command_entry.bind("<Down>", self.show_next_command)
self.command_entry.focus_set()
# Historial (sin cambios)
self.command_history = []
self.history_index = -1
# Mensaje de bienvenida
self.display_welcome_message()
def create_system_stats(self):
"""Sección de estadísticas en tiempo real debajo de la entrada"""
self.stats_frame = ttk.Frame(self.root, style='Neon.TFrame')
self.stats_frame.pack(side=tk.TOP, fill=tk.X, padx=10, pady=(0, 5))
# Variables dinámicas
self.cpu_var = tk.StringVar(value="🖥 CPU: 0.0%")
self.ram_var = tk.StringVar(value="💾 RAM: 0.0%")
self.disk_var = tk.StringVar(value="💿 DISK: 0.0%")
# Estilo común
stat_style = {
'style': 'Neon.TLabel',
'font': ('Consolas', 10, 'bold'),
'padding': (15, 8),
'anchor': tk.CENTER
}
# Etiquetas para estadisticas
ttk.Label(self.stats_frame, textvariable=self.cpu_var,
foreground='#00fffc', **stat_style).pack(side=tk.LEFT, expand=True)
ttk.Label(self.stats_frame, textvariable=self.ram_var,
foreground='#ff00ff', **stat_style).pack(side=tk.LEFT, expand=True)
ttk.Label(self.stats_frame, textvariable=self.disk_var,
foreground='#6a00ff', **stat_style).pack(side=tk.LEFT, expand=True)
def create_resource_graphs(self):
"""Gráficos circulares para recursos del sistema"""
self.graph_frame = ttk.Frame(self.root, style='Graph.TFrame')
self.graph_frame.pack(side=tk.LEFT, fill=tk.BOTH, padx=10, pady=10, expand=True)
# Configuración del frae de las estadfisticas
self.graph_style = {
'figsize': (1.75, 1.25),
'facecolor': '#0a0a12',
'edgecolor': '#6a00ff',
'dpi': 90
}
# Creacion de graficos
self.cpu_fig = Figure(**self.graph_style)
self.cpu_ax = self.cpu_fig.add_subplot(111)
self.cpu_canvas = FigureCanvasTkAgg(self.cpu_fig, self.graph_frame)
self.cpu_canvas.get_tk_widget().pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
self.ram_fig = Figure(**self.graph_style)
self.ram_ax = self.ram_fig.add_subplot(111)
self.ram_canvas = FigureCanvasTkAgg(self.ram_fig, self.graph_frame)
self.ram_canvas.get_tk_widget().pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
def update_resource_graph(self, ax, value, color):
"""Actualiza los gráficos circulares"""
ax.clear()
ax.pie([value, 100-value],
colors=[color, '#1a1a2f'],
startangle=90,
wedgeprops={'linewidth': 1.5, 'edgecolor': '#6a00ff'})
ax.text(0, 0, f"{value:.1f}%",
ha='center', va='center',
fontsize=14, color=color,
path_effects=[patheffects.withStroke(linewidth=3, foreground='#0a0a12')])
def update_metrics(self):
"""Actualiza todas las métricas del sistema"""
try:
# Obtener datos de la computadora
cpu = psutil.cpu_percent()
ram = psutil.virtual_memory().percent
disk = psutil.disk_usage('/').percent
# Actualizar los dats
self.cpu_var.set(f"🖥 CPU: {cpu:.1f}%")
self.ram_var.set(f"💾 RAM: {ram:.1f}%")
self.disk_var.set(f"💿 ALMACENAMIENTO: {disk:.1f}%")
# Actualizar los gráficos
self.update_resource_graph(self.cpu_ax, cpu, '#00fffc')
self.update_resource_graph(self.ram_ax, ram, '#ff00ff')
self.cpu_canvas.draw_idle()
self.ram_canvas.draw_idle()
except Exception as e:
print(f"Error en métricas: {str(e)}")
self.root.after(1000, self.update_metrics)
def set_neon_theme(self):
"""Configura el tema neon futurista"""
self.root.configure(bg='#0a0a12')
# Configurar colores
self.neon_blue = '#4db8ff'
self.neon_pink = '#ff00ff'
self.neon_purple = '#6a00ff'
self.dark_bg = '#0a0a12'
self.darker_bg = '#050510'
# Configurar estilos ttk
self.style = ttk.Style()
self.style.theme_use('clam')
#Estilos de las graficas
self.style.configure('Graph.TFrame',
background='#12012a',
borderwidth=2,
relief='ridge',
lightcolor=self.neon_purple,
darkcolor='#12012a')
# Frame style
self.style.configure('Neon.TFrame', background=self.dark_bg)
# Label style
self.style.configure('Neon.TLabel',
background=self.darker_bg,
foreground=self.neon_blue,
bordercolor=self.neon_purple,
lightcolor=self.neon_purple,
darkcolor=self.darker_bg)
# Prompt style
self.style.configure('NeonPrompt.TLabel',
background=self.dark_bg,
foreground=self.neon_pink,
font=('Consolas', 14, 'bold'))
# Entry style
self.style.configure('Neon.TEntry',
fieldbackground=self.darker_bg,
foreground=self.neon_blue,
bordercolor=self.neon_purple,
lightcolor=self.neon_purple,
darkcolor=self.darker_bg,
insertwidth=2)
# Button style
self.style.configure('Neon.TButton',
background=self.darker_bg,
foreground=self.neon_pink,
bordercolor=self.neon_purple,
lightcolor=self.neon_purple,
darkcolor=self.darker_bg,
font=('Consolas', 10, 'bold'),
padding=5)
self.style.map('Neon.TButton',
background=[('active', '#12012a')],
foreground=[('active', self.neon_blue)])
def display_welcome_message(self):
"""Muestra mensaje de bienvenida con estilo futurista"""
welcome_msg = """
╔══════════════════════════════════════════════════════╗
║ ⢀⣤⣤⣤⣄⣀⣠⣤⣤⣄⡀
║ ⣰⠟⠁⠀⠀⠀⠉⠉⠀⠀⠀⠈⠛⢷⡄
║ ⢀⣴⠾⠃⠀⠀⣾⣿⣷⡄⠀⢠⣾⣿⣷⡄⠈⣿⣤⣄⡀
║ ⢰⡟⠁⠀⣀⡀⠘⣿⣿⣿⡇⠀⢸⣿⣿⣿⠃⠀⠀⠀⠈⢻⣆
║ ⣿⡇⠀⣼⣿⣿⡄⠈⠛⠛⠁⠀⠀⠙⠉⠁⠀⣠⣶⣦⡀⠀⣿
║ ⣿⡇⠀⠸⣿⣿⠇⠀⠀⣠⣾⣿⣿⣦⠀⠀⢸⣿⣿⣿⠇⠀⣿
║ ⢸⣇⠀⠀⠈⠁⠀⣠⣶⣿⣿⣿⣿⣿⣧⣄⠈⠛⠛⠋⠀⣼⠃
║ ⢿⡄⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⣼⡏
║ ⠈⣿⡀⠀⠀⠈⠻⠿⠟⠛⠛⠻⠿⠿⠟⠃⠀⢸⣿
║ ⣽⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡟
║ ⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇
╠══════════════════════════════════════════════════════╣
║ SisShell - Escribe 'ayuda' para más info ║
╚══════════════════════════════════════════════════════╝
"""
self.text_output.insert(tk.END, welcome_msg, 'neon_pink')
self.text_output.tag_config('neon_pink', foreground=self.neon_pink)
self.text_output.insert(tk.END, f"\n\n{self.current_path} ", 'path_style')
self.text_output.tag_config('path_style', foreground=self.neon_blue)
self.text_output.insert(tk.END, ">>> ", 'prompt_style')
self.text_output.tag_config('prompt_style', foreground=self.neon_pink)
self.text_output.see(tk.END)
#Actualizar laber de la ruta actual.
def update_path_label(self):
self.current_path = get_current_path()
self.path_label.config(text=self.current_path)
# MÉTODOS ORIGINALES (SIN MODIFICACIONES)
def execute_command(self, event=None):
self.text_output.config(state="normal")
command = self.command_entry.get()
# Mostrar comando con estilo diferente
self.text_output.insert(tk.END, "> ", 'prompt_style')
self.text_output.insert(tk.END, f"{command}\n", 'command_style')
self.text_output.tag_config('command_style', foreground='#ffffff')
self.command_history.append(command)
self.history_index = len(self.command_history)
self.shell.execute(command)
# Separador entre comandos
self.text_output.insert(tk.END, "-"*80 + "\n", 'separator')
self.text_output.tag_config('separator', foreground=self.neon_purple)
self.text_output.see("end")
self.text_output.config(state="disabled")
self.command_entry.delete(0, tk.END)
def show_previous_command(self, event=None):
if self.command_history and self.history_index > 0:
self.history_index -= 1
self.command_entry.delete(0, tk.END)
self.command_entry.insert(0, self.command_history[self.history_index])
return "break"
def show_next_command(self, event=None):
if self.command_history and self.history_index < len(self.command_history) - 1:
self.history_index += 1
self.command_entry.delete(0, tk.END)
self.command_entry.insert(0, self.command_history[self.history_index])
else:
self.history_index = len(self.command_history)
self.command_entry.delete(0, tk.END)
return "break"
def export_output(self):
content = self.text_output.get("1.0", tk.END)
file_path = tk.filedialog.asksaveasfilename(
defaultextension=".txt",
filetypes=[("Archivos de texto", "*.txt"), ("Todos los archivos", "*.*")],
title="Exportar salida"
)
if file_path: # Si el usuario no cancela
try:
with open(file_path, "w", encoding="utf-8") as file:
file.write(content)
self.text_output.insert(tk.END, f"\nSalida exportada a: {file_path}\n", 'success')
except Exception as e:
self.text_output.insert(tk.END, f"\nError al exportar: {str(e)}\n", 'error')
self.text_output.see(tk.END)