Pardus Gnome üzerinde çalışan, "Masaüstü Kilitleyici" uygulaması
Pardus 25 üzerinde çalışan, Python ve PyQt6 kullanarak hazırladığım, kullanıcı dostu (GUI) bir "Masaüstü Kilitleyici" uygulaması.
Bu uygulama arka planda dconf ve dosya kopyalama işlemlerini otomatik olarak yapacak. Öğretmenlerin tek yapması gereken resmi seçip "Kilitle" düğmesine basmak olacak.
Uygulamanın Özellikleri
🖼️ Görsel Seçimi: Dosya yöneticisinden resim seçme.
👁️ Önizleme: Seçilen resmin önizlemesini gösterme.
🔒 Kilitleme: Resmi sisteme kopyalar, dconf ayarlarını yazar ve kilitler.
unlock Kilidi Kaldırma: Yapılan ayarları silip sistemi varsayılana döndürür.
🛡️ Root Kontrolü: Uygulama yönetici haklarıyla açılmadıysa uyarır.
Gerekli Kütüphanelerin Kurulumu
Uygulamayı çalıştırmadan önce Pardus üzerinde PyQt6'nın kurulu olduğundan emin olalım:
sudo apt update
sudo apt install python3-pyqt6
Python Uygulama Kodu (pardus-kilit.py)
Aşağıdaki kodu bir metin editörüne yapıştırıp pardus-kilit.py adıyla kaydedin.
import sys
import os
import shutil
import subprocess
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QPushButton, QLabel, QFileDialog, QMessageBox, QFrame)
from PyQt6.QtGui import QPixmap, QIcon, QFont
from PyQt6.QtCore import Qt
class MasaustuKilitleyici(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Pardus Masaüstü Kilitleyici")
self.setFixedSize(500, 600)
# Sistem Yolları
self.target_bg_path = "/usr/share/backgrounds/kurumsal-duvar.jpg"
self.dconf_db_dir = "/etc/dconf/db/local.d"
self.dconf_lock_dir = "/etc/dconf/db/local.d/locks"
self.profile_path = "/etc/dconf/profile/user"
self.selected_image_path = None
self.init_ui()
self.check_root()
def init_ui(self):
# Ana Widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout()
central_widget.setLayout(layout)
# Başlık
title = QLabel("Masaüstü Arka Plan Yönetimi")
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
title.setFont(QFont("Arial", 16, QFont.Weight.Bold))
layout.addWidget(title)
# Önizleme Alanı
self.preview_label = QLabel("Resim Seçilmedi")
self.preview_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.preview_label.setStyleSheet("border: 2px dashed #aaa; background-color: #f0f0f0; border-radius: 10px;")
self.preview_label.setFixedHeight(300)
self.preview_label.setScaledContents(True)
layout.addWidget(self.preview_label)
# Butonlar
btn_layout = QVBoxLayout()
self.btn_select = QPushButton("Resim Seç")
self.btn_select.setFixedHeight(40)
self.btn_select.clicked.connect(self.select_image)
btn_layout.addWidget(self.btn_select)
self.btn_apply = QPushButton("UYGULA VE KİLİTLE")
self.btn_apply.setFixedHeight(50)
self.btn_apply.setStyleSheet("background-color: #27ae60; color: white; font-weight: bold; font-size: 14px;")
self.btn_apply.clicked.connect(self.apply_lock)
btn_layout.addWidget(self.btn_apply)
self.btn_reset = QPushButton("Kilidi Kaldır (Varsayılana Dön)")
self.btn_reset.setFixedHeight(40)
self.btn_reset.setStyleSheet("background-color: #c0392b; color: white;")
self.btn_reset.clicked.connect(self.unlock_system)
btn_layout.addWidget(self.btn_reset)
layout.addLayout(btn_layout)
# Bilgi Notu
footer = QLabel("Bu işlem tüm kullanıcıları etkiler.")
footer.setAlignment(Qt.AlignmentFlag.AlignCenter)
footer.setStyleSheet("color: gray; font-size: 10px;")
layout.addWidget(footer)
def check_root(self):
if os.geteuid() != 0:
QMessageBox.critical(self, "Yetki Hatası", "Bu uygulama sistem ayarlarını değiştirmek için\nYÖNETİCİ (ROOT) yetkisi gerektirir.\n\nLütfen 'sudo' ile çalıştırın.")
sys.exit()
def select_image(self):
fname, _ = QFileDialog.getOpenFileName(self, 'Resim Seç', '/home', "Resim Dosyaları (*.jpg *.png *.jpeg)")
if fname:
self.selected_image_path = fname
pixmap = QPixmap(fname)
self.preview_label.setPixmap(pixmap.scaled(self.preview_label.size(), Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation))
self.preview_label.setText("")
def apply_lock(self):
if not self.selected_image_path:
QMessageBox.warning(self, "Uyarı", "Lütfen önce bir resim seçiniz.")
return
try:
# 1. Klasörleri Oluştur
os.makedirs(self.dconf_db_dir, exist_ok=True)
os.makedirs(self.dconf_lock_dir, exist_ok=True)
# 2. Resmi Sisteme Kopyala
shutil.copy(self.selected_image_path, self.target_bg_path)
os.chmod(self.target_bg_path, 0o644)
# 3. Dconf Profil Kontrolü
if not os.path.exists(self.profile_path):
os.makedirs(os.path.dirname(self.profile_path), exist_ok=True)
with open(self.profile_path, 'w') as f:
f.write("user-db:user\nsystem-db:local\n")
# 4. Ayar Dosyasını Yaz (01-wallpaper)
config_content = f"""[org/gnome/desktop/background]
picture-uri='file://{self.target_bg_path}'
picture-uri-dark='file://{self.target_bg_path}'
picture-options='zoom'
primary-color='#000000'
secondary-color='#000000'
"""
with open(os.path.join(self.dconf_db_dir, "01-wallpaper"), "w") as f:
f.write(config_content)
# 5. Kilit Dosyasını Yaz (locks/wallpaper-lock)
lock_content = """/org/gnome/desktop/background/picture-uri
/org/gnome/desktop/background/picture-uri-dark
/org/gnome/desktop/background/picture-options
/org/gnome/desktop/background/primary-color
/org/gnome/desktop/background/secondary-color
"""
with open(os.path.join(self.dconf_lock_dir, "wallpaper-lock"), "w") as f:
f.write(lock_content)
# 6. Dconf Update
subprocess.run(["dconf", "update"], check=True)
QMessageBox.information(self, "Başarılı", "Masaüstü arka planı başarıyla değiştirildi ve kilitlendi.\n\nEtkiyi görmek için oturumu kapatıp açın.")
except Exception as e:
QMessageBox.critical(self, "Hata", f"İşlem sırasında bir hata oluştu:\n{str(e)}")
def unlock_system(self):
confirm = QMessageBox.question(self, "Onay", "Tüm kısıtlamalar kaldırılacak. Emin misiniz?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
if confirm == QMessageBox.StandardButton.Yes:
try:
# Dosyaları Sil
files_to_remove = [
os.path.join(self.dconf_db_dir, "01-wallpaper"),
os.path.join(self.dconf_lock_dir, "wallpaper-lock"),
self.target_bg_path
]
for f in files_to_remove:
if os.path.exists(f):
os.remove(f)
# Sistemi Güncelle
subprocess.run(["dconf", "update"], check=True)
QMessageBox.information(self, "Bilgi", "Kilit kaldırıldı. Kullanıcılar artık kendi arka planlarını seçebilir.")
self.preview_label.clear()
self.preview_label.setText("Kilit Kaldırıldı")
except Exception as e:
QMessageBox.critical(self, "Hata", f"Silme işlemi başarısız:\n{str(e)}")
if __name__ == '__main__':
app = QApplication(sys.argv)
# Uygulama Teması (Pardus'a uygun basit stil)
app.setStyle("Fusion")
window = MasaustuKilitleyici()
window.show()
sys.exit(app.exec())
Nasıl Kullanılır?
Uygulamanın sistem dosyalarına (/etc/ ve /usr/share/) yazabilmesi için yetkili kullanıcı (root) olarak çalıştırılması şarttır.
Terminali açın, dosyayı kaydettiğiniz dizine gidin ve şu komutu verin:
sudo python3 pardus-kilit.py
Uygulamanın Yaptığı İşlemler (Özet)
Resim Taşıma: Seçtiğiniz resmi
/usr/share/backgrounds/kurumsal-duvar.jpgolarak kopyalar (eski varsa üzerine yazar).Dconf Profil:
/etc/dconf/profile/userdosyasını kontrol eder, yoksa oluşturur.Ayar Yazma:
/etc/dconf/db/local.d/01-wallpaperdosyasına GNOME arka plan ayarlarını yazar.Kilitleme:
/etc/dconf/db/local.d/locks/wallpaper-lockdosyası ile bu ayarların değiştirilmesini engeller.Güncelleme:
dconf updatekomutu ile ayarları sisteme işler.
Yorumlar
Yorum Gönder