Skip to content

Commit 08427ed

Browse files
authored
Update main.py
1 parent 3628057 commit 08427ed

File tree

1 file changed

+157
-122
lines changed

1 file changed

+157
-122
lines changed

main.py

Lines changed: 157 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,110 @@
22
import os
33
import webbrowser
44
import subprocess
5-
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QHBoxLayout, QFrame
6-
from PySide6.QtGui import QPixmap, QFont
7-
from PySide6.QtCore import Qt
8-
9-
class HackerOSWelcome(QWidget):
10-
def __init__(self):
11-
super().__init__()
12-
self.setWindowTitle("HackerOS Welcome")
13-
self.setGeometry(100, 100, 900, 650)
14-
self.setStyleSheet("background-color: #121212; color: white;")
15-
self.initUI()
16-
17-
def initUI(self):
18-
main_layout = QVBoxLayout()
19-
top_layout = QHBoxLayout()
20-
5+
import gi
6+
gi.require_version('Gtk', '4.0')
7+
from gi.repository import Gtk, GdkPixbuf, Gdk, GLib, Gio
8+
9+
class HackerOSWelcome(Gtk.ApplicationWindow):
10+
def __init__(self, *args, **kwargs):
11+
super().__init__(*args, **kwargs)
12+
self.set_title("HackerOS Welcome")
13+
self.set_default_size(900, 650)
14+
# Stylizacja
15+
self.style_provider = Gtk.CssProvider()
16+
css = """
17+
window {
18+
background-color: #121212;
19+
color: white;
20+
}
21+
label {
22+
color: white;
23+
}
24+
button {
25+
background-color: #1E1E1E;
26+
color: white;
27+
border: 2px solid #555;
28+
border-radius: 8px;
29+
padding: 10px;
30+
font-size: 14px;
31+
}
32+
button:hover {
33+
background-color: #333;
34+
border-color: #777;
35+
}
36+
button:active {
37+
background-color: #444;
38+
}
39+
"""
40+
self.style_provider.load_from_data(css.encode())
41+
Gtk.StyleContext.add_provider_for_display(
42+
Gdk.Display.get_default(),
43+
self.style_provider,
44+
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
45+
)
46+
self.init_ui()
47+
48+
def init_ui(self):
49+
main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
50+
self.set_child(main_box)
51+
# Górny layout z logo i tytułem
52+
top_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
53+
top_box.set_margin_top(20)
54+
top_box.set_margin_start(20)
55+
top_box.set_margin_end(20)
2156
# Logo
22-
self.logo_label = QLabel(self)
23-
pixmap = QPixmap("/usr/share/HackerOS/ICONS/HackerOS.png")
24-
self.logo_label.setPixmap(pixmap)
25-
self.logo_label.setFixedSize(120, 120)
26-
self.logo_label.setScaledContents(True)
27-
top_layout.addWidget(self.logo_label)
28-
29-
# Title
30-
self.title_label = QLabel("Witaj w HackerOS!", self)
31-
self.title_label.setFont(QFont("Arial", 28, QFont.Bold))
32-
self.title_label.setAlignment(Qt.AlignCenter)
33-
top_layout.addWidget(self.title_label)
34-
35-
main_layout.addLayout(top_layout)
36-
37-
self.subtitle_label = QLabel("Twój system do Gier i Etycznego Hakowania", self)
38-
self.subtitle_label.setFont(QFont("Arial", 18))
39-
self.subtitle_label.setAlignment(Qt.AlignCenter)
40-
main_layout.addWidget(self.subtitle_label)
41-
57+
logo_path = "/usr/share/HackerOS/ICONS/Plymouth-Icons/watermark.png"
58+
if os.path.exists(logo_path):
59+
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(logo_path, 120, 120)
60+
self.logo_image = Gtk.Image.new_from_pixbuf(pixbuf)
61+
else:
62+
self.logo_image = Gtk.Image() # Puste jeśli nie znaleziono
63+
top_box.append(self.logo_image)
64+
# Tytuł
65+
title_label = Gtk.Label(label="Witaj w HackerOS!")
66+
title_label.set_markup("<span font='Arial bold 28'>Witaj w HackerOS!</span>")
67+
title_label.set_hexpand(True)
68+
title_label.set_halign(Gtk.Align.CENTER)
69+
top_box.append(title_label)
70+
main_box.append(top_box)
71+
# Podtytuł (używany też do feedbacku)
72+
self.subtitle_label = Gtk.Label(label="Twój system do Gier i Etycznego Hakowania")
73+
self.subtitle_label.set_markup("<span font='Arial 18'>Twój system do Gier i Etycznego Hakowania</span>")
74+
self.subtitle_label.set_halign(Gtk.Align.CENTER)
75+
main_box.append(self.subtitle_label)
4276
# Separator
43-
separator = QFrame()
44-
separator.setFrameShape(QFrame.HLine)
45-
separator.setFrameShadow(QFrame.Sunken)
46-
separator.setStyleSheet("background-color: #888; height: 2px;")
47-
main_layout.addWidget(separator)
48-
49-
# Buttons layout
50-
buttons_layout = QHBoxLayout()
51-
left_buttons = QVBoxLayout()
52-
right_buttons = QVBoxLayout()
53-
54-
button_style = """
55-
QPushButton {
56-
background-color: #1E1E1E;
57-
color: white;
58-
border: 2px solid #555;
59-
border-radius: 8px;
60-
padding: 10px;
61-
font-size: 14px;
62-
}
63-
QPushButton:hover {
64-
background-color: #333;
65-
border-color: #777;
66-
}
67-
QPushButton:pressed {
68-
background-color: #444;
69-
}
70-
"""
71-
72-
# Left side buttons
73-
buttons_left = [
74-
("Sprawdź aktualizacje", self.checkUpdates),
75-
("Uruchom narzędzia HackerOS", self.launchTools),
77+
separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
78+
separator.set_margin_start(20)
79+
separator.set_margin_end(20)
80+
main_box.append(separator)
81+
# Layout przycisków - dwie kolumny
82+
buttons_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=20)
83+
buttons_box.set_margin_start(20)
84+
buttons_box.set_margin_end(20)
85+
buttons_box.set_margin_bottom(20)
86+
left_buttons_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
87+
right_buttons_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
88+
# Przyciski lewej kolumny
89+
left_buttons = [
90+
("Sprawdź aktualizacje", self.check_updates),
91+
("Uruchom narzędzia HackerOS", self.launch_tools),
7692
("Otwórz stronę HackerOS", lambda: webbrowser.open("https://hackeros-linux-system.github.io/HackerOS-Website/Home-page.html")),
7793
("Otwórz X", lambda: webbrowser.open("https://x.com/hackeros_linux")),
78-
("Otwórz dokumentację", self.openDocumentation),
79-
("Uruchom Steam", self.launchSteam),
80-
("Otwórz sklep z aplikacjami", self.openSoftware)
94+
("Otwórz dokumentację", self.open_documentation),
95+
("Uruchom Steam", self.launch_steam),
96+
("Otwórz sklep z aplikacjami", self.open_software),
97+
("Changelog", lambda: webbrowser.open("https://hackeros-linux-system.github.io/HackerOS-Website/releases.html")),
98+
("Informacje o systemie", lambda: webbrowser.open("https://hackeros-linux-system.github.io/HackerOS-Website/about-hackeros.html")),
99+
("Zgłoś błąd", lambda: webbrowser.open("https://github.com/HackerOS-Linux-System/HackerOS-Website/issues")),
100+
("Forum dyskusyjne", lambda: webbrowser.open("https://github.com/HackerOS-Linux-System/HackerOS-Website/discussions")),
101+
("Zaktualizuj system", self.update_system)
81102
]
82-
for text, action in buttons_left:
83-
btn = QPushButton(text, self)
84-
btn.setStyleSheet(button_style)
85-
btn.clicked.connect(action)
86-
left_buttons.addWidget(btn)
87-
88-
# Right side buttons
89-
buttons_right = [
103+
for text, action in left_buttons:
104+
btn = Gtk.Button(label=text)
105+
btn.connect("clicked", lambda widget, act=action: act())
106+
left_buttons_box.append(btn)
107+
# Przyciski prawej kolumny
108+
right_buttons = [
90109
("Proton Updater", "/usr/share/HackerOS/Scripts/Bin/Proton-Updater.sh"),
91110
("Switch to Hacker Mode", "/usr/share/HackerOS/Scripts/Bin/Switch_To_Hacker-Mode.sh"),
92111
("HackerOS Cockpit", "/usr/share/HackerOS/Scripts/Bin/HackerOS-Cockpit.sh"),
@@ -97,68 +116,84 @@ def initUI(self):
97116
("The Racer", "/usr/share/HackerOS/Scripts/Hacker-Games/The-Racer"),
98117
("Hacker Launcher", "/usr/share/HackerOS/Scripts/HackerOS-Apps/Hacker_Launcher")
99118
]
100-
for text, cmd in buttons_right:
101-
btn = QPushButton(text, self)
102-
btn.setStyleSheet(button_style)
103-
btn.clicked.connect(lambda _, c=cmd: self.run_command_with_feedback(c))
104-
right_buttons.addWidget(btn)
105-
106-
buttons_layout.addLayout(left_buttons)
107-
buttons_layout.addLayout(right_buttons)
108-
main_layout.addLayout(buttons_layout)
109-
self.setLayout(main_layout)
119+
for text, cmd in right_buttons:
120+
btn = Gtk.Button(label=text)
121+
btn.connect("clicked", lambda widget, c=cmd: self.run_command_with_feedback(c))
122+
right_buttons_box.append(btn)
123+
buttons_box.append(left_buttons_box)
124+
buttons_box.append(right_buttons_box)
125+
main_box.append(buttons_box)
110126

111127
def run_command_with_feedback(self, cmd):
112-
"""Wspólna metoda do uruchamiania komend z feedbackiem."""
128+
"""Uruchamianie komend z feedbackiem."""
113129
full_cmd = f"bash -c '{cmd}'"
114130
result = os.system(f"pkexec {full_cmd}")
131+
cmd_name = cmd.split('/')[-1] if '/' in cmd else cmd
115132
if result == 0:
116-
self.subtitle_label.setText(f"Uruchomiono: {cmd.split()[0]}.")
133+
self.subtitle_label.set_label(f"Uruchomiono: {cmd_name}.")
117134
else:
118-
self.subtitle_label.setText(f"Błąd podczas uruchamiania: {cmd.split()[0]}.")
135+
self.subtitle_label.set_label(f"Błąd podczas uruchamiania: {cmd_name}.")
119136

120-
def checkUpdates(self):
121-
result = os.system("pkexec bash -c 'apt update && apt upgrade -y && flatpak update'")
137+
def check_updates(self):
138+
result = os.system("pkexec bash -c 'apt update && apt upgrade -y && flatpak update -y'")
122139
if result == 0:
123-
self.subtitle_label.setText("Sprawdzenie aktualizacji zakończone pomyślnie.")
140+
self.subtitle_label.set_label("Sprawdzenie aktualizacji zakończone pomyślnie.")
124141
else:
125-
self.subtitle_label.setText("Błąd podczas sprawdzania aktualizacji.")
142+
self.subtitle_label.set_label("Błąd podczas sprawdzania aktualizacji.")
126143

127-
def launchTools(self):
144+
def launch_tools(self):
128145
result = os.system("pkexec bash /usr/share/HackerOS/Scripts/Bin/install-tools.sh")
129146
if result == 0:
130-
self.subtitle_label.setText("Uruchomiono narzędzia HackerOS pomyślnie.")
147+
self.subtitle_label.set_label("Uruchomiono narzędzia HackerOS pomyślnie.")
148+
else:
149+
self.subtitle_label.set_label("Błąd podczas uruchamiania narzędzi HackerOS.")
150+
151+
def open_documentation(self):
152+
result = os.system("pkexec bash /usr/share/HackerOS/Scripts/Bin/HackerOS-Documentation.sh")
153+
if result == 0:
154+
self.subtitle_label.set_label("Otworzono dokumentację HackerOS.")
131155
else:
132-
self.subtitle_label.setText("Błąd podczas uruchamiania narzędzi HackerOS.")
156+
self.subtitle_label.set_label("Błąd podczas otwierania dokumentacji.")
133157

134-
def launchSteam(self):
158+
def launch_steam(self):
135159
try:
136160
subprocess.run(["flatpak", "run", "com.valvesoftware.Steam", "-gamepadui"], check=True)
137-
self.subtitle_label.setText("Steam został uruchomiony w trybie gamepad UI.")
138-
except FileNotFoundError:
139-
os.system("flatpak install com.valvesoftware.Steam")
140-
try:
141-
subprocess.run(["steam", "-gamepadui"], check=True)
142-
self.subtitle_label.setText("Steam zainstalowany i uruchomiony.")
143-
except subprocess.CalledProcessError:
144-
self.subtitle_label.setText("Błąd podczas uruchamiania Steam po instalacji.")
145-
except subprocess.CalledProcessError:
146-
self.subtitle_label.setText("Wystąpił błąd podczas uruchamiania Steam.")
147-
148-
def openSoftware(self):
161+
self.subtitle_label.set_label("Steam został uruchomiony w trybie gamepad UI.")
162+
except (FileNotFoundError, subprocess.CalledProcessError):
163+
self.subtitle_label.set_label("Instalowanie Steam...")
164+
install_result = os.system("flatpak install -y com.valvesoftware.Steam")
165+
if install_result == 0:
166+
try:
167+
subprocess.run(["flatpak", "run", "com.valvesoftware.Steam", "-gamepadui"], check=True)
168+
self.subtitle_label.set_label("Steam zainstalowany i uruchomiony.")
169+
except subprocess.CalledProcessError:
170+
self.subtitle_label.set_label("Błąd podczas uruchamiania Steam po instalacji.")
171+
else:
172+
self.subtitle_label.set_label("Błąd podczas instalacji Steam.")
173+
174+
def open_software(self):
149175
result = os.system("gnome-software &")
150-
self.subtitle_label.setText("Uruchomiono Sklep z aplikacjami.")
176+
self.subtitle_label.set_label("Uruchomiono Sklep z aplikacjami.")
151177

152-
def openDocumentation(self):
153-
result = os.system("pkexec bash /usr/share/HackerOS/Scripts/Bin/HackerOS-Documentation.sh")
178+
def update_system(self):
179+
# Otwiera terminal z komendą hacker update, potem pyta o zamknięcie
180+
terminal_cmd = 'gnome-terminal -- bash -c "hacker update; read -p \'Chcesz zamknąć terminal? (t/n) \' answer; if [ \"$answer\" = \'t\' ]; then exit; else echo \'Terminal pozostanie otwarty.\'; read; fi"'
181+
result = os.system(terminal_cmd)
154182
if result == 0:
155-
self.subtitle_label.setText("Otworzono dokumentację HackerOS.")
183+
self.subtitle_label.set_label("Rozpoczęto aktualizację systemu w terminalu.")
156184
else:
157-
self.subtitle_label.setText("Błąd podczas otwierania dokumentacji.")
185+
self.subtitle_label.set_label("Błąd podczas uruchamiania aktualizacji systemu.")
186+
187+
class Application(Gtk.Application):
188+
def __init__(self):
189+
super().__init__(application_id="org.hackeros.welcome",
190+
flags=Gio.ApplicationFlags.FLAGS_NONE)
191+
self.connect("activate", self.on_activate)
158192

193+
def on_activate(self, app):
194+
win = HackerOSWelcome(application=app)
195+
win.present()
159196

160197
if __name__ == '__main__':
161-
app = QApplication(sys.argv)
162-
window = HackerOSWelcome()
163-
window.show()
164-
sys.exit(app.exec())
198+
app = Application()
199+
app.run(sys.argv)

0 commit comments

Comments
 (0)