Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk
- import subprocess
- class ConsoleWindow(tk.Toplevel):
- def __init__(self, parent):
- super().__init__(parent)
- self.geometry('1000x300')
- self.title("Najeeb CMD ALIASES COMMONDS RUNNER")
- self.iconbitmap('C.ico') # Add icon to the title bar
- self.text_area = tk.Text(self, wrap="word", state="disabled")
- self.text_area.pack(expand=True, fill="both")
- self.scrollbar = tk.Scrollbar(self, command=self.text_area.yview)
- self.scrollbar.pack(side="right", fill="y")
- self.text_area.config(yscrollcommand=self.scrollbar.set)
- def append_text(self, text, tag=None):
- self.text_area.config(state="normal")
- if tag:
- self.text_area.insert("end", text, tag)
- else:
- self.text_area.insert("end", text)
- self.text_area.config(state="disabled")
- self.text_area.see("end")
- class AliasButtonExample(tk.Tk):
- def __init__(self):
- super().__init__()
- self.geometry('1000x340')
- self.config(bg='green')
- self.title("Najeeb CMD ALIASES COMMONDS RUNNER")
- self.iconbitmap('C.ico') # Add icon to the title bar
- self.aliases = {}
- self.create_widgets()
- def create_widgets(self):
- style = ttk.Style()
- style.configure("TButton", foreground="blue", background="lightgray", font=('Arial', 10, 'bold'))
- style.configure("TLabel", foreground="darkblue", background="lightgray", font=('Arial', 10))
- tk.Label(self, text="Command:").grid(row=0, column=0, padx=5, pady=5)
- tk.Label(self, text="Alias:").grid(row=1, column=0, padx=5, pady=5)
- tk.Label(self, text="Aliases: Najeeb New Aliases Add And Save").grid(row=2, column=0, sticky="n", padx=5, pady=5)
- self.command_entry = tk.Entry(self, width=250) # Increase width here
- self.command_entry.grid(row=0, column=1, padx=5, pady=5)
- self.alias_entry = tk.Entry(self, width=250)
- self.alias_entry.grid(row=1, column=1, padx=5, pady=5)
- self.alias_button = ttk.Button(self, text="Insert Alias", command=self.insert_alias, style="TButton")
- self.alias_button.grid(row=1, column=2, padx=5, pady=5)
- self.run_button = ttk.Button(self, text="Run Command", command=self.run_command, style="TButton")
- self.run_button.grid(row=0, column=2, rowspan=1, padx=5, pady=5, sticky="nsew")
- self.save_button = ttk.Button(self, text="Save Aliases", command=self.save_aliases, style="TButton")
- self.save_button.grid(row=2, column=2, padx=5, pady=5)
- self.aliases_frame = tk.Frame(self)
- self.aliases_frame.grid(row=3, column=0, columnspan=3, padx=5, pady=5, sticky="nsew")
- self.aliases_text = tk.Text(self.aliases_frame, wrap="word", state="normal", height=10, width=120)
- self.aliases_text.grid(row=0, column=0, padx=5, pady=5, sticky="nsew")
- self.aliases_scrollbar = tk.Scrollbar(self.aliases_frame, orient="vertical", command=self.aliases_text.yview)
- self.aliases_scrollbar.grid(row=0, column=1, sticky="ns")
- self.aliases_text.config(yscrollcommand=self.aliases_scrollbar.set)
- self.search_label = tk.Label(self, text="Search Aliases:")
- self.search_label.grid(row=4, column=0, padx=5, pady=5, sticky="e")
- self.search_entry = tk.Entry(self, width=250)
- self.search_entry.grid(row=4, column=1, padx=5, pady=5)
- self.search_button = ttk.Button(self, text="Search", command=self.search_aliases, style="TButton")
- self.search_button.grid(row=4, column=2, padx=5, pady=5)
- self.console_window = ConsoleWindow(self)
- self.grid_columnconfigure(1, weight=1) # Expand column 1
- self.read_aliases() # Call read_aliases to load aliases when the GUI is initialized
- def insert_alias(self):
- alias = self.alias_entry.get()
- print(f"Attempting to insert alias: {alias}")
- if alias in self.aliases:
- print(f"Alias found: {alias}")
- self.command_entry.delete(0, tk.END)
- self.command_entry.insert(tk.END, self.aliases[alias])
- else:
- print("Alias not found")
- def run_command(self):
- command = self.command_entry.get()
- process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- stdout, stderr = process.communicate()
- output = stdout.decode()
- error = stderr.decode()
- self.console_window.append_text(output)
- if error:
- self.console_window.append_text(error, tag="error")
- def save_aliases(self):
- with open("Aliases.txt", "a") as f:
- alias = self.alias_entry.get()
- command = self.command_entry.get()
- f.write(f"{alias}={command}\n")
- self.aliases[alias] = command
- self.aliases_text.insert("end", f"{alias}: {command}\n") # Also update the aliases_text field
- def read_aliases(self):
- try:
- with open("Aliases.txt", "r") as f:
- for line in f:
- if '=' in line:
- alias, command = line.strip().split("=", 1)
- self.aliases[alias] = command
- self.aliases_text.insert("end", f"{alias}: {command}\n")
- except FileNotFoundError:
- # If the file doesn't exist, do nothing
- pass
- def search_aliases(self):
- query = self.search_entry.get().strip().lower()
- self.aliases_text.delete('1.0', tk.END) # Clear previous search results
- for alias, command in self.aliases.items():
- if query in alias.lower() or query in command.lower():
- self.aliases_text.insert(tk.END, f"{alias}: {command}\n")
- if __name__ == "__main__":
- app = AliasButtonExample()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement