2026-02-23 14:12:45 +00:00
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
from PySide6.QtCore import Qt
|
|
|
|
|
from PySide6.QtGui import QColor, QFont, QFontInfo, QIcon, QPalette
|
|
|
|
|
from PySide6.QtWidgets import (
|
|
|
|
|
QApplication,
|
|
|
|
|
QGridLayout,
|
|
|
|
|
QHBoxLayout,
|
|
|
|
|
QLabel,
|
|
|
|
|
QMainWindow,
|
|
|
|
|
QPushButton,
|
|
|
|
|
QWidget,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
from .autoslicer import Autoslicer, AutoslicerParams
|
|
|
|
|
from .controller import ScanSlicerControllerMixin
|
|
|
|
|
from .ui_builders import ScanSlicerUiBuilderMixin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# _unwrap_qvariant: function definition for ScanSlicer behavior.
|
2026-02-23 14:29:20 +00:00
|
|
|
def _unwrap_qvariant(value):
|
|
|
|
|
unwrapped = value
|
|
|
|
|
for _ in range(4):
|
|
|
|
|
if hasattr(unwrapped, "variant"):
|
|
|
|
|
try:
|
|
|
|
|
candidate = unwrapped.variant()
|
|
|
|
|
except Exception:
|
|
|
|
|
candidate = unwrapped
|
|
|
|
|
if candidate is not unwrapped:
|
|
|
|
|
unwrapped = candidate
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if hasattr(unwrapped, "value"):
|
|
|
|
|
try:
|
|
|
|
|
candidate = unwrapped.value()
|
|
|
|
|
except TypeError:
|
|
|
|
|
candidate = unwrapped.value
|
|
|
|
|
except Exception:
|
|
|
|
|
candidate = unwrapped
|
|
|
|
|
if candidate is not unwrapped:
|
|
|
|
|
unwrapped = candidate
|
|
|
|
|
continue
|
|
|
|
|
break
|
|
|
|
|
return unwrapped
|
2026-02-23 14:34:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# _read_portal_dark_preference: function definition for ScanSlicer behavior.
|
|
|
|
|
def _read_portal_dark_preference():
|
|
|
|
|
try:
|
|
|
|
|
from PySide6.QtDBus import QDBusConnection, QDBusInterface, QDBusMessage
|
|
|
|
|
except Exception:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
bus = QDBusConnection.sessionBus()
|
|
|
|
|
if not bus.isConnected():
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
iface = QDBusInterface(
|
|
|
|
|
"org.freedesktop.portal.Desktop",
|
|
|
|
|
"/org/freedesktop/portal/desktop",
|
|
|
|
|
"org.freedesktop.portal.Settings",
|
|
|
|
|
bus,
|
|
|
|
|
)
|
|
|
|
|
if not iface.isValid():
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
for method in ("ReadOne", "Read"):
|
|
|
|
|
reply = iface.call(method, "org.freedesktop.appearance", "color-scheme")
|
|
|
|
|
if reply.type() == QDBusMessage.MessageType.ErrorMessage:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
args = reply.arguments()
|
|
|
|
|
if not args:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
raw_value = _unwrap_qvariant(args[0])
|
|
|
|
|
if isinstance(raw_value, dict) and "color-scheme" in raw_value:
|
|
|
|
|
raw_value = _unwrap_qvariant(raw_value["color-scheme"])
|
|
|
|
|
if isinstance(raw_value, (list, tuple)) and raw_value:
|
|
|
|
|
raw_value = _unwrap_qvariant(raw_value[0])
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
color_scheme = int(raw_value)
|
|
|
|
|
except Exception:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# XDG portal color-scheme values:
|
|
|
|
|
# 0 = no preference, 1 = prefer dark, 2 = prefer light
|
|
|
|
|
if color_scheme == 1:
|
|
|
|
|
return True
|
|
|
|
|
if color_scheme == 2:
|
|
|
|
|
return False
|
|
|
|
|
return None
|