Skip to content

Commit e5f3b3d

Browse files
Update setbian.py with .deb file selection to install...
1 parent 92c5426 commit e5f3b3d

1 file changed

Lines changed: 65 additions & 2 deletions

File tree

code files/setbian.py

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/python3
22
import tkinter as tk
3-
from tkinter import messagebox
3+
from tkinter import messagebox, filedialog
44
import subprocess
5+
import sys
56
import internet
67
from msg import msg, sudo_password_prompt, close_sudo_prompt, close_msg
78
from img import load_icon
@@ -35,6 +36,57 @@ def install_selected():
3536
return
3637
close_msg()
3738
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+
3890
# Launch GUI only if internet is connected
3991
if internet.is_connected():
4092
# Define available packages and their image paths
@@ -83,7 +135,18 @@ def install_selected():
83135
fg="white",
84136
command=install_selected
85137
)
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)
87150
# Run the app
88151
root.mainloop()
89152
else:

0 commit comments

Comments
 (0)