|
| 1 | +import sys |
| 2 | +import os |
| 3 | +import json |
| 4 | +from PyQt6.QtWidgets import ( |
| 5 | + QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, |
| 6 | + QPushButton, QMenuBar, QMenu, QDialog, QFormLayout, QComboBox, |
| 7 | + QLabel, QDialogButtonBox, QMessageBox |
| 8 | +) |
| 9 | +from PyQt6.QtWebEngineWidgets import QWebEngineView |
| 10 | +from PyQt6.QtCore import QUrl, Qt, QDir |
| 11 | +from PyQt6.QtGui import QKeyEvent |
| 12 | +import subprocess |
1 | 13 |
|
| 14 | +class SettingsDialog(QDialog): |
| 15 | + def __init__(self, parent=None, config=None): |
| 16 | + super().__init__(parent) |
| 17 | + self.setWindowTitle("Ustawienia HackerOS TV") |
| 18 | + layout = QFormLayout(self) |
| 19 | + |
| 20 | + self.language_combo = QComboBox() |
| 21 | + self.language_combo.addItems(["Polski", "English", "Deutsch"]) |
| 22 | + if config and "language" in config: |
| 23 | + index = self.language_combo.findText(config["language"]) |
| 24 | + if index >= 0: |
| 25 | + self.language_combo.setCurrentIndex(index) |
| 26 | + layout.addRow("Język:", self.language_combo) |
| 27 | + |
| 28 | + buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) |
| 29 | + buttons.accepted.connect(self.accept) |
| 30 | + buttons.rejected.connect(self.reject) |
| 31 | + layout.addRow(buttons) |
| 32 | + |
| 33 | + def get_settings(self): |
| 34 | + return {"language": self.language_combo.currentText()} |
| 35 | + |
| 36 | +class HackerOSTV(QMainWindow): |
| 37 | + def __init__(self): |
| 38 | + super().__init__() |
| 39 | + self.setWindowTitle("HackerOS TV") |
| 40 | + self.setGeometry(100, 100, 800, 600) |
| 41 | + |
| 42 | + # Ścieżka konfiguracji |
| 43 | + self.config_dir = os.path.expanduser("~/.hackeros/HackerOS-TV/") |
| 44 | + if not os.path.exists(self.config_dir): |
| 45 | + os.makedirs(self.config_dir) |
| 46 | + self.config_file = os.path.join(self.config_dir, "config.json") |
| 47 | + self.load_config() |
| 48 | + |
| 49 | + # Menu bar |
| 50 | + self.menu_bar = QMenuBar(self) |
| 51 | + self.setMenuBar(self.menu_bar) |
| 52 | + |
| 53 | + # Hacker Menu |
| 54 | + hacker_menu = QMenu("Hacker Menu", self) |
| 55 | + self.menu_bar.addMenu(hacker_menu) |
| 56 | + |
| 57 | + shutdown_action = hacker_menu.addAction("Wyłącz komputer") |
| 58 | + shutdown_action.triggered.connect(self.shutdown) |
| 59 | + |
| 60 | + reboot_action = hacker_menu.addAction("Uruchom ponownie") |
| 61 | + reboot_action.triggered.connect(self.reboot) |
| 62 | + |
| 63 | + logout_action = hacker_menu.addAction("Wyloguj się") |
| 64 | + logout_action.triggered.connect(self.logout) |
| 65 | + |
| 66 | + settings_action = hacker_menu.addAction("Ustawienia") |
| 67 | + settings_action.triggered.connect(self.open_settings) |
| 68 | + |
| 69 | + # Central widget |
| 70 | + central_widget = QWidget() |
| 71 | + self.setCentralWidget(central_widget) |
| 72 | + layout = QVBoxLayout(central_widget) |
| 73 | + |
| 74 | + # Buttons for services |
| 75 | + buttons_layout = QHBoxLayout() |
| 76 | + layout.addLayout(buttons_layout) |
| 77 | + |
| 78 | + disney_btn = QPushButton("Disney+") |
| 79 | + disney_btn.clicked.connect(lambda: self.open_web("https://www.disneyplus.com")) |
| 80 | + buttons_layout.addWidget(disney_btn) |
| 81 | + |
| 82 | + amazon_btn = QPushButton("Amazon Prime") |
| 83 | + amazon_btn.clicked.connect(lambda: self.open_web("https://www.primevideo.com")) |
| 84 | + buttons_layout.addWidget(amazon_btn) |
| 85 | + |
| 86 | + youtube_btn = QPushButton("YouTube") |
| 87 | + youtube_btn.clicked.connect(lambda: self.open_web("https://www.youtube.com")) |
| 88 | + buttons_layout.addWidget(youtube_btn) |
| 89 | + |
| 90 | + spotify_btn = QPushButton("Spotify") |
| 91 | + spotify_btn.clicked.connect(lambda: self.open_web("https://open.spotify.com")) |
| 92 | + buttons_layout.addWidget(spotify_btn) |
| 93 | + |
| 94 | + # Web view |
| 95 | + self.web_view = QWebEngineView() |
| 96 | + layout.addWidget(self.web_view) |
| 97 | + |
| 98 | + # Initial load |
| 99 | + self.web_view.load(QUrl("about:blank")) |
| 100 | + |
| 101 | + def load_config(self): |
| 102 | + if os.path.exists(self.config_file): |
| 103 | + with open(self.config_file, 'r') as f: |
| 104 | + self.config = json.load(f) |
| 105 | + else: |
| 106 | + self.config = {"language": "Polski"} |
| 107 | + |
| 108 | + def save_config(self): |
| 109 | + with open(self.config_file, 'w') as f: |
| 110 | + json.dump(self.config, f) |
| 111 | + |
| 112 | + def open_settings(self): |
| 113 | + dialog = SettingsDialog(self, self.config) |
| 114 | + if dialog.exec() == QDialog.DialogCode.Accepted: |
| 115 | + self.config = dialog.get_settings() |
| 116 | + self.save_config() |
| 117 | + QMessageBox.information(self, "Ustawienia", "Ustawienia zapisane!") |
| 118 | + |
| 119 | + def open_web(self, url): |
| 120 | + self.web_view.load(QUrl(url)) |
| 121 | + self.showFullScreen() |
| 122 | + |
| 123 | + def keyPressEvent(self, event: QKeyEvent): |
| 124 | + if event.key() == Qt.Key.Key_Escape: |
| 125 | + if self.isFullScreen(): |
| 126 | + self.showNormal() |
| 127 | + super().keyPressEvent(event) |
| 128 | + |
| 129 | + def shutdown(self): |
| 130 | + reply = QMessageBox.question(self, 'Wyłącz', 'Czy na pewno wyłączyć komputer?', QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) |
| 131 | + if reply == QMessageBox.StandardButton.Yes: |
| 132 | + subprocess.call(["shutdown", "-h", "now"]) |
| 133 | + |
| 134 | + def reboot(self): |
| 135 | + reply = QMessageBox.question(self, 'Restart', 'Czy na pewno uruchomić ponownie?', QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) |
| 136 | + if reply == QMessageBox.StandardButton.Yes: |
| 137 | + subprocess.call(["reboot"]) |
| 138 | + |
| 139 | + def logout(self): |
| 140 | + reply = QMessageBox.question(self, 'Wyloguj', 'Czy na pewno wylogować?', QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) |
| 141 | + if reply == QMessageBox.StandardButton.Yes: |
| 142 | + # Dla X11, wylogowanie zależy od menedżera wyświetlania, np. dla lightdm: dm-tool switch-to-greeter |
| 143 | + # Zakładam prosty logout dla sesji |
| 144 | + subprocess.call(["pkill", "-u", os.getlogin()]) # Ostrożnie, to zabija wszystkie procesy użytkownika |
| 145 | + |
| 146 | +if __name__ == "__main__": |
| 147 | + app = QApplication(sys.argv) |
| 148 | + window = HackerOSTV() |
| 149 | + window.show() |
| 150 | + sys.exit(app.exec()) |
0 commit comments