Add default values for AutoInstaller GUI selections

- Set default timezone to Africa/Johannesburg
- Auto-detect and select first available WiFi network with strongest signal
- Prompt for WiFi password when network is selected
- Fallback to first available Ethernet interface if no WiFi found
- Set default IP method to DHCP for both WiFi and Ethernet
- Auto-detect first available installation disk (not USB, >4GB)
- Pre-populate GUI with detected defaults on startup
- Add set_defaults() method called during GUI initialization
- Implement WiFi scanning with signal strength sorting
- Add detect_default_network() and detect_default_disk() methods
- Use QInputDialog for WiFi password input

This provides sensible defaults for all GUI selections, making the
installation process more user-friendly by pre-selecting appropriate
options based on the detected hardware and network environment.
parent cbff4724
......@@ -18,7 +18,7 @@ try:
from PyQt6.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout, QWidget, QLabel,
QPushButton, QProgressBar, QTextEdit, QComboBox, QLineEdit,
QGroupBox, QFormLayout, QMessageBox, QCheckBox, QDialog, QTreeWidget,
QTreeWidgetItem, QAbstractItemView, QListWidget, QListWidgetItem)
QTreeWidgetItem, QAbstractItemView, QListWidget, QListWidgetItem, QInputDialog)
from PyQt6.QtCore import QThread, pyqtSignal, Qt, QTimer
from PyQt6.QtGui import QFont, QIcon, QShortcut
except ImportError:
......@@ -737,6 +737,7 @@ class AutoInstallerGUI(QMainWindow):
self.worker = None
self.init_ui()
self.config = {}
self.set_defaults()
def init_ui(self):
central_widget = QWidget()
......@@ -843,6 +844,173 @@ class AutoInstallerGUI(QMainWindow):
except NameError:
print("Warning: QShortcut not available - keyboard shortcut disabled")
def set_defaults(self):
"""Set default values for GUI selections"""
# Set default timezone to South Africa/Johannesburg
self.selected_timezone = "Africa/Johannesburg"
self.timezone_label.setText("Africa/Johannesburg")
self.config['timezone'] = self.selected_timezone
# Set default network configuration
self.network_checkbox.setChecked(True)
self.toggle_network_config(Qt.CheckState.Checked.value)
# Auto-detect and set default network interface
self.detect_default_network()
# Set default IP method to DHCP
self.ip_method_combo.setCurrentText("DHCP (automatic)")
# Auto-detect and set default installation disk
self.detect_default_disk()
def detect_default_network(self):
"""Detect and set default network interface"""
try:
# Try to find WiFi networks first
wifi_interfaces = []
try:
result = subprocess.run(['iw', 'dev'], capture_output=True, text=True, check=True)
for line in result.stdout.split('\n'):
if 'Interface' in line:
parts = line.split()
if len(parts) >= 2:
wifi_interfaces.append(parts[1])
except subprocess.CalledProcessError:
pass
if wifi_interfaces:
# Use first WiFi interface
self.selected_interface = wifi_interfaces[0]
self.interface_type = 'wireless'
self.interface_label.setText(f"Selected: {self.selected_interface} (Wireless)")
# Try to scan for networks and select strongest signal
self.scan_and_select_best_wifi()
return
# If no WiFi, try Ethernet
result = subprocess.run(['ip', 'link', 'show'], capture_output=True, text=True, check=True)
for line in result.stdout.split('\n'):
if ': e' in line and 'state' in line:
parts = line.split(':')
if len(parts) >= 2:
iface = parts[1].strip().split()[0]
if iface.startswith('e'):
self.selected_interface = iface
self.interface_type = 'ethernet'
self.interface_label.setText(f"Selected: {iface} (Ethernet)")
return
except subprocess.CalledProcessError:
pass
def scan_and_select_best_wifi(self):
"""Scan WiFi networks and select the one with strongest signal"""
try:
# Enable interface for scanning
subprocess.run(['ip', 'link', 'set', self.selected_interface, 'up'], check=True)
import time
time.sleep(2)
# Scan networks
result = subprocess.run(['iw', 'dev', self.selected_interface, 'scan'],
capture_output=True, text=True, check=True)
networks = []
current_network = None
for line in result.stdout.split('\n'):
if 'BSS ' in line:
if current_network:
networks.append(current_network)
current_network = {'bssid': line.split()[1], 'signal': -100, 'ssid': ''}
elif current_network and 'signal:' in line:
try:
signal = int(line.split('signal:')[1].split()[0])
current_network['signal'] = signal
except (ValueError, IndexError):
pass
elif current_network and 'SSID:' in line:
ssid = line.split('SSID:')[1].strip()
current_network['ssid'] = ssid
if current_network:
networks.append(current_network)
# Sort by signal strength (strongest first)
networks.sort(key=lambda x: x['signal'], reverse=True)
# Select strongest network
if networks and networks[0]['ssid']:
self.selected_ssid = networks[0]['ssid']
self.interface_label.setText(f"Selected: {self.selected_interface} (WiFi: {self.selected_ssid})")
# Ask for password
password, ok = QInputDialog.getText(
self, 'WiFi Password',
f'Enter password for WiFi network "{self.selected_ssid}":',
QLineEdit.EchoMode.Password
)
if ok:
self.wifi_config = {
'ssid': self.selected_ssid,
'security': 'WPA', # Assume WPA by default
'password': password
}
except subprocess.CalledProcessError:
pass
def detect_default_disk(self):
"""Detect and set default installation disk"""
try:
# Get all available disk devices
result = subprocess.run(['lsblk', '-rno', 'NAME,TYPE'], capture_output=True, text=True, check=True)
disks = []
for line in result.stdout.strip().split('\n'):
if line and 'disk' in line:
parts = line.split()
if len(parts) >= 1:
disks.append(f'/dev/{parts[0]}')
# Find USB device to exclude
usb_device = None
for mount_point in ['/lib/live/mount/medium', '/cdrom', '/run/live/medium']:
if os.path.isdir(mount_point):
try:
result = subprocess.run(['df', mount_point], capture_output=True, text=True, check=True)
lines = result.stdout.strip().split('\n')
if len(lines) >= 2:
device = lines[1].split()[0]
device = re.sub(r'\d+$', '', device)
if os.path.exists(device):
usb_device = device
break
except subprocess.CalledProcessError:
continue
# Find first suitable disk (not USB, >4GB)
for disk in disks:
if disk == usb_device:
continue
try:
size_result = subprocess.run(['lsblk', '-rbno', 'SIZE', disk],
capture_output=True, text=True, check=True)
size_bytes = int(size_result.stdout.strip().split('\n')[0])
size_gb = size_bytes // (1024 * 1024 * 1024)
if size_gb >= 4:
# Set as default disk
self.selected_disk = disk
self.log(f"Auto-selected installation disk: {disk} ({size_gb} GB)")
break
except (subprocess.CalledProcessError, ValueError, IndexError):
continue
except subprocess.CalledProcessError:
pass
def open_timezone_dialog(self):
dialog = TimezoneDialog(self)
if dialog.exec() == QDialog.DialogCode.Accepted:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment