Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import subprocess
- import tkinter as tk
- from tkinter import messagebox, ttk
- from ttkthemes import ThemedTk
- def read_file_list(file_path):
- """Read the file list from List.txt and return a dictionary of display names and file paths."""
- file_dict = {}
- try:
- with open(file_path, 'r') as file:
- for line in file:
- if ';' in line:
- display_name, file_path = line.strip().split(' ; ', 1)
- file_dict[display_name] = file_path
- except Exception as e:
- messagebox.showerror("Error", f"Failed to read List.txt: {e}")
- return file_dict
- def open_file(filepath):
- """Open the selected file."""
- try:
- os.startfile(filepath)
- except Exception as e:
- messagebox.showerror("Error", f"Failed to open file: {e}")
- def on_file_select(event):
- """Event handler for file selection."""
- selected_index = file_listbox.curselection()
- if selected_index:
- selected_display_name = file_listbox.get(selected_index)
- selected_file_path = file_dict.get(selected_display_name)
- if selected_file_path:
- open_file(selected_file_path)
- def update_listbox(filter_text=""):
- """Update the listbox based on the search filter."""
- file_listbox.delete(0, tk.END)
- for display_name in file_dict.keys():
- if filter_text.lower() in display_name.lower():
- file_listbox.insert(tk.END, display_name)
- def on_search_change(event):
- """Event handler for search field change."""
- filter_text = search_var.get()
- update_listbox(filter_text)
- # Determine the directory where the script is located
- script_dir = os.path.dirname(os.path.abspath(__file__))
- # Path to the List.txt file
- list_file_path = os.path.join(script_dir, 'LIST-EXE.txt')
- # Read the file paths from List.txt
- file_dict = read_file_list(list_file_path)
- # Create the main window with a theme
- root = ThemedTk(theme="arc")
- root.title("Najeeb Select a File to Open")
- root.geometry("320x360")
- root.configure(bg="#4a4a4a")
- # Create a frame for better layout control
- frame = ttk.Frame(root, padding="10")
- frame.pack(fill=tk.BOTH, expand=True)
- # Create a search entry field
- search_var = tk.StringVar()
- search_entry = ttk.Entry(frame, textvariable=search_var)
- search_entry.pack(fill=tk.X, padx=(0, 5))
- search_entry.bind('<KeyRelease>', on_search_change)
- # Create a Listbox to display the display names
- file_listbox = tk.Listbox(frame, selectmode=tk.SINGLE, height=15)
- file_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=(0, 5))
- # Create a scrollbar for the Listbox
- scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL, command=file_listbox.yview)
- scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- file_listbox.config(yscrollcommand=scrollbar.set)
- # Bind the selection event to the handler
- file_listbox.bind('<<ListboxSelect>>', on_file_select)
- # Initialize the listbox with all items
- update_listbox()
- # Start the GUI event loop
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement