|
1 | 1 | #!/usr/bin/python3 |
2 | 2 | import tkinter as tk |
3 | | -from tkinter import messagebox |
| 3 | +from tkinter import messagebox, filedialog |
4 | 4 | import subprocess |
| 5 | +import sys |
5 | 6 | import internet |
6 | 7 | from msg import msg, sudo_password_prompt, close_sudo_prompt, close_msg |
7 | 8 | from img import load_icon |
@@ -35,6 +36,57 @@ def install_selected(): |
35 | 36 | return |
36 | 37 | close_msg() |
37 | 38 | messagebox.showinfo("Success", "Selected apps installed successfully.") |
| 39 | + close_msg() |
| 40 | + messagebox.showinfo("Success", "Selected apps installed successfully.") |
| 41 | + |
| 42 | + def install_deb_file(file_path=None): |
| 43 | + """ |
| 44 | + Install a .deb file using dpkg. |
| 45 | + If file_path is None, open a file dialog to select one. |
| 46 | + """ |
| 47 | + if not file_path: |
| 48 | + file_path = filedialog.askopenfilename( |
| 49 | + title="Select .deb File", |
| 50 | + filetypes=[("Debian Package", "*.deb")] |
| 51 | + ) |
| 52 | + |
| 53 | + if not file_path: |
| 54 | + return |
| 55 | + |
| 56 | + try: |
| 57 | + # Detect terminal emulator |
| 58 | + terminals = ["gnome-terminal", "x-terminal-emulator", "xterm", "konsole", "lxterminal"] |
| 59 | + terminal = None |
| 60 | + for term in terminals: |
| 61 | + if subprocess.call(f"which {term}", shell=True, stdout=subprocess.DEVNULL) == 0: |
| 62 | + terminal = term |
| 63 | + break |
| 64 | + |
| 65 | + if not terminal: |
| 66 | + messagebox.showerror("Error", "No compatible terminal emulator found.") |
| 67 | + return |
| 68 | + |
| 69 | + # Command to install .deb file |
| 70 | + # We use a complex command to handle sudo prompt and potential fix-broken install |
| 71 | + install_cmd = f"sudo dpkg -i '{file_path}' || (sudo apt --fix-broken install -y && sudo dpkg -i '{file_path}')" |
| 72 | + |
| 73 | + # Build command to run inside the new terminal |
| 74 | + # We add 'read -p "Press enter to close..."' to keep terminal open to see output |
| 75 | + terminal_cmd = [terminal, "--", "bash", "-c", f"{install_cmd}; echo 'Done. Press Enter to close.'; read"] |
| 76 | + |
| 77 | + subprocess.Popen(terminal_cmd) |
| 78 | + |
| 79 | + except Exception as e: |
| 80 | + messagebox.showerror("Error", f"Failed to launch installation: {e}") |
| 81 | + |
| 82 | + # Check for command line arguments (Open with Setbian) |
| 83 | + if len(sys.argv) > 1 and sys.argv[1].endswith(".deb"): |
| 84 | + install_deb_file(sys.argv[1]) |
| 85 | + # If opened with a file, we might want to exit after launching install, |
| 86 | + # or just show the main window too. |
| 87 | + # For now, let's show the main window as well, but maybe user just wants to install. |
| 88 | + # Let's just continue to show main window. |
| 89 | + |
38 | 90 | # Launch GUI only if internet is connected |
39 | 91 | if internet.is_connected(): |
40 | 92 | # Define available packages and their image paths |
@@ -83,7 +135,18 @@ def install_selected(): |
83 | 135 | fg="white", |
84 | 136 | command=install_selected |
85 | 137 | ) |
86 | | - install_btn.pack(pady=20) |
| 138 | + install_btn.pack(pady=10) |
| 139 | + |
| 140 | + # Open .deb file button |
| 141 | + deb_btn = tk.Button( |
| 142 | + root, |
| 143 | + text="Open .deb File", |
| 144 | + font=("Arial", 12, "bold"), |
| 145 | + bg="#2196F3", |
| 146 | + fg="white", |
| 147 | + command=install_deb_file |
| 148 | + ) |
| 149 | + deb_btn.pack(pady=10) |
87 | 150 | # Run the app |
88 | 151 | root.mainloop() |
89 | 152 | else: |
|
0 commit comments