|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +import tkinter as tk |
| 4 | +from tkinter import messagebox |
| 5 | +import subprocess |
| 6 | +import socket |
| 7 | + |
| 8 | +# Check for internet connection before launching the main UI |
| 9 | +def is_connected(): |
| 10 | + try: |
| 11 | + socket.create_connection(("1.1.1.1", 53), timeout=3) |
| 12 | + return True |
| 13 | + except OSError: |
| 14 | + return False |
| 15 | + |
| 16 | +# Function to install selected packages |
| 17 | +def install_selected(): |
| 18 | + selected = [pkg for name, pkg in available_apps.items() if vars_check[name].get()] |
| 19 | + |
| 20 | + if not selected: |
| 21 | + messagebox.showinfo("No Selection", "Please select at least one app to install.") |
| 22 | + return |
| 23 | + |
| 24 | + for pkg in selected: |
| 25 | + try: |
| 26 | + subprocess.run( |
| 27 | + ["sudo", "apt", "install", "-y", pkg], |
| 28 | + check=True, |
| 29 | + stdout=subprocess.DEVNULL, |
| 30 | + stderr=subprocess.DEVNULL |
| 31 | + ) |
| 32 | + except subprocess.CalledProcessError: |
| 33 | + messagebox.showerror("Installation Error", f"Failed to install {pkg}") |
| 34 | + return |
| 35 | + |
| 36 | + messagebox.showinfo("Success", "Selected apps installed successfully.") |
| 37 | + |
| 38 | +# Launch GUI only if internet is connected |
| 39 | +if is_connected(): |
| 40 | + # Define available packages |
| 41 | + available_apps = { |
| 42 | + "Git": "git", |
| 43 | + "Curl": "curl", |
| 44 | + "VLC Media Player": "vlc", |
| 45 | + "GIMP": "gimp", |
| 46 | + "VS Code": "code", |
| 47 | + "FireFox":"firefox-esr", |
| 48 | + "Google Chromium":"chromium", |
| 49 | + "Mpv":'mpv', |
| 50 | + "Telegram":"telegram-desktop", |
| 51 | + } |
| 52 | + |
| 53 | + # GUI setup |
| 54 | + root = tk.Tk() |
| 55 | + root.title("Setbian - Smart Debian App Installer") |
| 56 | + root.geometry("400x350") |
| 57 | + root.resizable(False, False) |
| 58 | + |
| 59 | + tk.Label(root, text="Select Apps to Install:", font=("Arial", 14, "bold")).pack(pady=10) |
| 60 | + |
| 61 | + # Create checkboxes dynamically |
| 62 | + vars_check = {} |
| 63 | + for app in available_apps: |
| 64 | + var = tk.BooleanVar() |
| 65 | + chk = tk.Checkbutton(root, text=app, variable=var, font=("Arial", 12)) |
| 66 | + chk.pack(anchor='w', padx=40) |
| 67 | + vars_check[app] = var |
| 68 | + |
| 69 | + # Install button |
| 70 | + install_btn = tk.Button( |
| 71 | + root, |
| 72 | + text="Install Selected", |
| 73 | + font=("Arial", 12, "bold"), |
| 74 | + bg="#4CAF50", |
| 75 | + fg="white", |
| 76 | + command=install_selected |
| 77 | + ) |
| 78 | + install_btn.pack(pady=20) |
| 79 | + |
| 80 | + # Run the app |
| 81 | + root.mainloop() |
| 82 | + |
| 83 | +else: |
| 84 | + # Show internet error popup |
| 85 | + root = tk.Tk() |
| 86 | + root.withdraw() # Hide the main window |
| 87 | + messagebox.showerror( |
| 88 | + "No Internet Connection", |
| 89 | + "Please connect to the internet via Ethernet or Wi-Fi and relaunch Setbian.\n\nThank you!" |
| 90 | + ) |
0 commit comments