diff options
| author | Papoteur <papoteur@mageia.org> | 2025-05-22 13:25:22 +0200 |
|---|---|---|
| committer | Papoteur <papoteur@mageia.org> | 2025-05-22 13:25:22 +0200 |
| commit | 618ed3725bfa0354d9892260a80270401aa35b8a (patch) | |
| tree | bb6dca6f35b8bf18877770d4f80333718498ade6 /src/ui.py | |
| parent | efe82e845a66e6c8e9bab9124d3d0b10cb1fbd46 (diff) | |
| download | mageiawelcome-618ed3725bfa0354d9892260a80270401aa35b8a.tar mageiawelcome-618ed3725bfa0354d9892260a80270401aa35b8a.tar.gz mageiawelcome-618ed3725bfa0354d9892260a80270401aa35b8a.tar.bz2 mageiawelcome-618ed3725bfa0354d9892260a80270401aa35b8a.tar.xz mageiawelcome-618ed3725bfa0354d9892260a80270401aa35b8a.zip | |
Move qml directory to src
adapt setup.py
Diffstat (limited to 'src/ui.py')
| -rw-r--r-- | src/ui.py | 1367 |
1 files changed, 1367 insertions, 0 deletions
diff --git a/src/ui.py b/src/ui.py new file mode 100644 index 0000000..1431770 --- /dev/null +++ b/src/ui.py @@ -0,0 +1,1367 @@ +import sys +import os +import pwd +from PyQt6.QtWidgets import ( + QApplication, + QCheckBox, + QMainWindow, + QWidget, + QStackedWidget, + QVBoxLayout, + QHBoxLayout, + QGridLayout, + QPushButton, + QLabel, + QScrollArea, + QMessageBox, + QStyledItemDelegate, + QListView, +) +from PyQt6.QtCore import ( + Qt, + QPropertyAnimation, + QEasingCurve, + QPoint, + QTimer, + QSize, + QObject, + pyqtSlot, + pyqtSignal, +) +from PyQt6.QtGui import ( + QColor, + QPalette, + QFont, + QPixmap, + QImage, + QPainter, + QLinearGradient, + QColorConstants, +) +import webbrowser +import subprocess +from functools import partial +from helpers import ( + get_desktop_name, + get_desktop_name2, + is_installed, + NetworkState, + ConfList, + Autostart, +) +from AppList import AppList + +DEFAULT_WIDTH = 900 +_ = QApplication.translate + + +class SlidePage(QWidget): + """Widget pour une page individuelle du diaporama""" + + def __init__(self, title): + super().__init__() + + # Stocker le titre pour référence + self.title = title + + def paintEvent(self, event): + painter = QPainter(self) + gradient = QLinearGradient(0, 0, 0, self.height()) + gradient.setColorAt(0.0, QColor("#262F45")) + gradient.setColorAt(1.0, QColor("#2397D4")) + painter.setBrush(gradient) + painter.setPen(Qt.PenStyle.NoPen) + painter.drawRect(self.rect()) + + def resizeEvent(self, event): + self.paintEvent(event) + + def weblink(self, url): + webbrowser.open_new_tab(url) + + def command(self, app): + if type(app) == list: + cmd = app + try: + subprocess.Popen(cmd) + except FileNotFoundError as e: + print(f"Exception running {cmd}") + print(e) + message = QMessageBox( + QMessageBox.Icon.Warning, + _("mw-ui", "Launching command"), + _("mw-ui", "This command is not installed"), + ) + message.exec() + + def install(self, app): + if type(app) == list: + cmd = app + repo = cmd[1] + # Check if repositories are enabled + core = False + updates = False + tainted = False + t_updates = False + nonfree = False + nf_updates = False + core32 = False + core32_updates = False + try: + active = subprocess.run( + ["urpmq", "--list-media", "active"], capture_output=True, text=True + ) + active.check_returncode() + except subprocess.CalledProcessError: + print("Error with urpmq") + return + for line in active.stdout.splitlines(): + if line.startswith("Core Release"): + core = True + if line.startswith("Core Updates"): + updates = True + if line.startswith("Tainted Release"): + tainted = True + if line.startswith("Tainted Updates"): + t_updates = True + if line.startswith("Nonfree Release"): + nonfree = True + if line.startswith("Nonfree Updates"): + nf_updates = True + if line.startswith("Core 32bit Release"): + core32 = True + if line.startswith("Core 32bit Updates"): + core32_updates = True + if repo == "tainted" and not (tainted and t_updates): + # repo tainted not enabled + self.needed.emit(repo) + return + if repo == "non-free" and not (nonfree and nf_updates): + # repo nonfree not enabled + self.needed.emit(repo) + return + if repo == "steam" and not ( + core32 and core32_updates and nonfree and nf_updates + ): + # repo not enabled + self.needed.emit(repo) + return + if repo == "" and not (core and updates): + # repo not enabled + self.repo.emit() + return + proc = subprocess.Popen(["/usr/bin/gurpmi", cmd[0]]) + proc.wait() + # Give the signal to reload the applist + self.installed.emit() + + def install_and_launch(self, app): + """ + app should be an array with the package name to install and then the command to launch + """ + if type(app) == list: + cmd = app + # app should contain package, repository + is_app_installed, inst_repo = is_installed(cmd[0]) + if not is_app_installed: + proc = subprocess.Popen(["/usr/bin/gurpmi", cmd[0]]) + proc.wait() + self.command([cmd[1]]) + + +class Links(SlidePage): + """Widget pour une page individuelle du diaporama""" + + def __init__(self): + super().__init__(_("Links", "More information")) + + data = [ + { + "name": _("Links", "Release notes"), + "url": + # Translate only if the link is to a specific page for your language + _("Links", "https://wiki.mageia.org/en/Mageia_9_Release_Notes"), + }, + { + "name": _("Links", "Forums"), + "url": + # Translate only if the link is to a specific page for your language + _("Links", "https://forums.mageia.org/en/"), + }, + { + "name": _("Links", "Community Center"), + "url": "https://www.mageia.org/community/", + }, + { + "name": _("Links", "Errata"), + "url": + # Translate only if the link is to a specific page for your language + _("Links", "https://wiki.mageia.org/en/Mageia_9_Errata"), + }, + { + "name": _("Links", "Wiki"), + "url": + # Translate only if the link is to a specific page for your language + _("Links", "https://wiki.mageia.org/en/Documentation"), + }, + { + "name": _("Links", "Contribute"), + "url": "https://www.mageia.org/contribute/", + }, + { + "name": _("Links", "Newcomers Howto"), + "url": + # Translate only if the link is to a specific page for your language + _("Links", "https://wiki.mageia.org/en/Newcomers_start_here"), + }, + { + "name": _("Links", "Chat Room"), + # Translate only if the link is to a specific page for your language + "url": _("Links", "ircs://irc.libera.chat:6697/#mageia"), + }, + {"name": _("Links", "Donations"), "url": "https://www.mageia.org/donate/"}, + {"name": _("Links", "Documentation"), "url": "https://www.mageia.org/doc/"}, + {"name": _("Links", "Bugs tracker"), "url": "https://bugs.mageia.org/"}, + {"name": _("Links", "Join us!"), "url": "https://identity.mageia.org/"}, + ] + layout = QGridLayout() + + layout.setSpacing(30) + col = 1 + for title in ("Documentation", "Support", "Community"): + button = QLabel(_("Links", title)) + button.setAlignment(Qt.AlignmentFlag.AlignCenter) + button.setWordWrap(True) + button.setStyleSheet( + "color: white; font-size: 18px; padding: 2px 8px; font-weight: bold;" + ) + layout.addWidget(button, 0, col) + col += 1 + + iter_data = iter(data) + for row in range(2, 6): + for col in range(1, 4): + item = next(iter_data) + button = MyPushButton(item["name"]) + button.clicked.connect(partial(self.weblink, item["url"])) + layout.addWidget(button, row, col) + # Dummy widgets at corner to center the buttons + layout.addWidget(QWidget(), 6, 4) + layout.addWidget(QWidget(), 0, 0) + + self.setLayout(layout) + + +class Welcome(SlidePage): + def __init__(self, user): + super().__init__(_("Welcome", "Welcome")) + + # # vertical layout + layout = QVBoxLayout() + + # Add title + if user == "live": + title = _("Welcome", "Welcome to Mageia") + else: + title = _("Welcome", "Welcome to Mageia, {}".format(user)) + title_label = QLabel(title) + title_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + title_label.setStyleSheet("font-size: 28px; color: white; font-weight: bold;") + layout.addWidget(title_label) + + # Add the content + if user == "live": + content = _( + "Welcome", + "We are going to guide you through a few important pieces of information and<BR />help you to go further with Mageia.<BR /><BR />Now, click on <i> {} </i> to go to the first step.", + ).format(_("Welcome", "Live mode")) + else: + content = _( + "Welcome", + "We are going to guide you through some important steps and help<BR />you with the configuration of your newly installed system.<BR /><BR />Now, click on <i>{}</i> to go to the first step.", + ).format(_("Sources", "Media sources")) + content_label = QLabel(content) + content_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + content_label.setStyleSheet("font-size: 22px; color: white;") + layout.addWidget(content_label) + + self.setLayout(layout) + + +class Sources(SlidePage): + def __init__(self): + super().__init__(_("Sources", "Media sources")) + + # vertical layout + layout = QVBoxLayout() + layout.addStretch(0) + grid = QGridLayout() + + title_label = QLabel(_("Sources", "Configure software repositories")) + title_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + title_label.setStyleSheet("font-size: 28px; color: white; font-weight: bold;") + layout.addWidget(title_label) + + explain_label = QLabel(_("Sources", "Mageia official repositories contain:")) + explain_label.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(explain_label) + + core_legend = GradientLegend( + _("Sources", "core"), QColor("lightgreen"), QColor("green") + ) + grid.addWidget(core_legend, 2, 0) + core_label = QLabel(_("Sources", "- the free-open-source packages")) + core_label.setStyleSheet("font-size: 14px; color: white;") + core_label.setWordWrap(True) + grid.addWidget(core_label, 2, 1) + + nonfree_legend = GradientLegend( + _("Sources", "nonfree"), QColor("red"), QColor("darkred") + ) + grid.addWidget(nonfree_legend, 3, 0) + nonfree_label = QLabel( + _( + "Sources", + "- closed-source programs, e.g. Nvidia proprietary drivers, non-free drivers for some Wi-Fi cards, etc", + ) + ) + nonfree_label.setWordWrap(True) + nonfree_label.setStyleSheet("font-size: 14px; color: white;") + grid.addWidget(nonfree_label, 3, 1) + + tainted_legend = GradientLegend( + _("Sources", "tainted"), QColor("red"), QColor("darkred") + ) + grid.addWidget(tainted_legend, 4, 0) + tainted_label = QLabel( + _( + "Sources", + "- these packages (eg audio and video codecs needed for certain multimedia files or commercial DVDs) may infringe on patents or copyright laws in certain countries. ", + ) + ) + tainted_label.setWordWrap(True) + tainted_label.setStyleSheet("font-size: 14px; color: white;") + grid.addWidget(tainted_label, 4, 1) + + backports_legend = GradientLegend( + _("Sources", "backports"), QColor("lightgrey"), QColor("darkgrey") + ) + grid.addWidget(backports_legend, 5, 0) + backports_label = QLabel( + _( + "Sources", + "- include new versions of packages, and new packages, that do not meet the updates policy.", + ) + ) + backports_label.setWordWrap(True) + backports_label.setStyleSheet("font-size: 14px; color: white;") + grid.addWidget(backports_label, 5, 1) + + note_legend = GradientLegend( + _("Sources", "Note! "), QColor("#e6c200"), QColor("#e6c200") + ) + grid.addWidget(note_legend, 6, 0) + note_label = QLabel( + _( + "Sources", + """If you enabled the online repositories during installation, some media sources should be installed already. Otherwise, we will now configure these online repositories. If this computer will have access to the Internet, you can delete the <i>Local</i> entry from the list of repositories.""", + ) + ) + note_label.setWordWrap(True) + note_label.setStyleSheet("font-size: 14px; color: white;") + grid.addWidget(note_label, 6, 1) + note_legend = GradientLegend( + _("Sources", "Note! "), QColor("#e6c200"), QColor("#e6c200") + ) + layout.addLayout(grid) + content_label = QLabel( + _( + "Sources", + "Now, please enable or disable the online repositories of your choice: click on the <i>Edit software repositories</i> button. Select at least the <i>release</i> and <i>updates</i> pair. <i>Debug</i> and <i>Testing</i> are for special cases.", + ) + + "<BR />" + + _( + "Sources", + "After you have checked and enabled the repositories you need, you can go to the next slide.", + ) + ) + content_label.setWordWrap(True) + content_label.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label) + ns = NetworkState() + if not ns.isOffLine: + net_layout = QHBoxLayout() + net_layout.addStretch(1) + network_button = MyPushButton(_("Sources", "Configure network")) + net_layout.addWidget(network_button) + net_layout.addStretch(1) + network_button.clicked.connect( + partial( + self.command, + [ + "/usr/bin/draknetcenter", + ], + ) + ) + layout.addLayout(net_layout) + button_layout = QHBoxLayout() + button_layout.addStretch(1) + configure_button = MyPushButton(_("Sources", "Edit software sources") + " *") + configure_button.clicked.connect( + partial( + self.command, + [ + "/usr/bin/drakrpm-edit-media", + ], + ) + ) + button_layout.addWidget(configure_button) + button_layout.addStretch(1) + layout.addLayout(button_layout) + layout.addStretch(0) + + self.setLayout(layout) + + +class Updates(SlidePage): + def __init__(self): + super().__init__(_("Updates", "Update")) + + # vertical layout + layout = QVBoxLayout() + layout.addStretch(0) + + title_label = QLabel(_("Updates", "How Mageia manages updates")) + title_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + title_label.setStyleSheet("font-size: 28px; color: white; font-weight: bold;") + layout.addWidget(title_label) + + content_label = QLabel( + _( + "Updates", + "Mageia provides software which may be updated in order to fix bugs or security issues. It is highly recommended that you update your system regularly. \ +An Update icon will appear in your task bar when new updates are available. To run the updates, just click on the icon below and give your user password - or use the Software Manager (root password). \ +This is a background process and you will be able to use your computer normally during the updates.", + ) + ) + content_label.setWordWrap(True) + content_label.setStyleSheet("font-size: 16px; color: white; padding: 0px 60px") + layout.addWidget(content_label) + + button_layout = QHBoxLayout() + button_layout.addStretch(1) + check_button = MyPushButton(_("Updates", "Check system updates") + " *") + check_button.clicked.connect( + partial( + self.command, + [ + "/usr/bin/drakrpm-update", + ], + ) + ) + button_layout.addWidget(check_button) + button_layout.addStretch(1) + layout.addLayout(button_layout) + button2_layout = QHBoxLayout() + button2_layout.addStretch(1) + advisories_button = MyPushButton(_("Updates", "Advisories of updates (en)")) + advisories_button.clicked.connect( + partial(self.weblink, "https://advisories.mageia.org/") + ) + button2_layout.addWidget(advisories_button) + button2_layout.addStretch(1) + layout.addLayout(button2_layout) + layout.addStretch(0) + + self.setLayout(layout) + + +class Mcc(SlidePage): + def __init__(self): + # The button in the buttons bar, shortcut for Mageia Control Center + super().__init__(_("Mcc", "MCC")) + + # vertical layout + layout = QVBoxLayout() + layout.addStretch(0) + + title_label = QLabel(_("Mcc", "Mageia Control Center")) + title_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + title_label.setStyleSheet("font-size: 28px; color: white; font-weight: bold;") + layout.addWidget(title_label) + + entries_list = [ + "Software Management", + "Hardware", + "Network and Internet", + "System", + "Network Sharing", + "Local Disks", + "Security", + "Boot", + ] + + content_label = QLabel( + _( + "Mcc", + "<b>Mageia Control Center</b> (aka drakconf) is a set of tools to help you configure your system.", + ) + + "<BR>• " + + "<BR>• ".join([_("Mcc", x) for x in entries_list]) + ) + content_label.setWordWrap(True) + content_label.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label) + + button_layout = QHBoxLayout() + button_layout.addStretch(1) + mcc_button = MyPushButton(_("Mcc", "Mageia Control Center") + " *") + mcc_button.clicked.connect( + partial( + self.command, + [ + "/usr/bin/drakconf", + ], + ) + ) + button_layout.addWidget(mcc_button) + button_layout.addStretch(1) + layout.addLayout(button_layout) + button2_layout = QHBoxLayout() + button2_layout.addStretch(1) + doc_button = MyPushButton(_("Mcc", "MCC documentation")) + doc_button.clicked.connect(partial(self.weblink, "https://www.mageia.org/doc")) + button2_layout.addWidget(doc_button) + button2_layout.addStretch(1) + layout.addLayout(button2_layout) + layout.addStretch(0) + + self.setLayout(layout) + + +class InstallSoftware(SlidePage): + def __init__(self, user): + # The button in the buttons bar, shortcut for Mageia Control Center + super().__init__(_("InstallSoftware", "Install software")) + + # vertical layout + layout = QVBoxLayout() + layout.addStretch(0) + + title_label = QLabel(_("InstallSoftware", "Install and remove software")) + title_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + title_label.setStyleSheet("font-size: 28px; color: white; font-weight: bold;") + layout.addWidget(title_label) + + content_label = QLabel( + _( + "InstallSoftware", + "With Mageia, you will find the software in the media repositories. Mageia users simply access these media via one of the Software Managers.", + ) + ) + content_label.setWordWrap(True) + content_label.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label) + + button_layout = QHBoxLayout() + button_layout.addStretch(1) + button = MyPushButton(_("InstallSoftware", "RPMdrake") + " *") + button.clicked.connect( + partial( + self.command, + [ + "/usr/bin/drakconf", + ], + ) + ) + button_layout.addWidget(button) + button_layout.addStretch(1) + layout.addLayout(button_layout) + button2_layout = QHBoxLayout() + button2_layout.addStretch(1) + doc_button = MyPushButton(_("InstallSoftware", "Dnfdragora")) + doc_button.clicked.connect( + partial(self.install_and_launch, ["dnfdragora", "/usr/bin/dnfdragora"]) + ) + button2_layout.addWidget(doc_button) + button2_layout.addStretch(1) + layout.addLayout(button2_layout) + + if user != "live": + text = _( + "InstallSoftware", + "The next slide shows a small selection of popular applications - any of which may be installed at this point.<BR/>", + ) + text += _("InstallSoftware", "You can find a more detailed list here:") + else: + text = _("InstallSoftware", "You can find a more detailed list here:") + content_label2 = QLabel(text) + content_label2.setWordWrap(True) + content_label2.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label2) + + button3_layout = QHBoxLayout() + button3_layout.addStretch(1) + app_button = MyPushButton(_("InstallSoftware", "List of applications (wiki)")) + app_button.clicked.connect( + partial( + self.weblink, + _("InstallSoftware", "https://wiki.mageia.org/en/List_of_applications"), + ) + ) + button3_layout.addWidget(app_button) + button3_layout.addStretch(1) + layout.addLayout(button3_layout) + layout.addStretch(0) + + self.setLayout(layout) + + +class Applications(SlidePage): + def __init__(self): + # The button in the buttons bar, shortcut for Mageia Control Center + super().__init__(_("mw-ui", "Applications")) + + self.items = [] + layout = QVBoxLayout() + content_layout = QHBoxLayout() + nav_layout = QVBoxLayout() + content_label = QLabel( + "<b>" + + _( + "mw-ui", + "Here is a small selection of popular applications - any of which may be installed or launched at this point.", + ) + + "<BR />" + + _("mw-ui", "Ensure that you have enabled the <i>Media sources</i>.") + + "</b>" + ) + content_label.setWordWrap(True) + content_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + content_label.setStyleSheet( + "font-size: 12px; color: black; background-color: gold;" + ) + layout.addWidget(content_label) + + self.nav = Breadcrumb(lateral=True) + entries = [ + {"name": _("mw-ui", "Featured"), "group": "featured"}, + {"name": _("mw-ui", "Games"), "group": "games"}, + {"name": _("mw-ui", "Internet"), "group": "internet"}, + {"name": _("mw-ui", "Video"), "group": "video"}, + {"name": _("mw-ui", "Audio"), "group": "audio"}, + {"name": _("mw-ui", "Office"), "group": "office"}, + {"name": _("mw-ui", "Graphics"), "group": "graphics"}, + {"name": _("mw-ui", "System"), "group": "system"}, + {"name": _("mw-ui", "Programming"), "group": "programming"}, + ] + i = 0 + for entry in entries: + self.nav.add_item(entry["name"], i) + i += 1 + self.nav.setFixedWidth(int(content_label.width() / 4)) + nav_layout.addWidget(self.nav) + nav_layout.addStretch(0) + + content_layout.addLayout(nav_layout) + layout.addLayout(content_layout) + self.stack = AppListStack(entries, self.nav) + self.nav.set_slideshow(self.stack) + content_layout.addWidget(self.stack) + self.setLayout(layout) + + def showEvent(self, event): + self.stack.goto_slide(0) + + +class AppListStack(QStackedWidget): + """Collection of stacked pages of applications lists""" + + def __init__(self, entries, nav): + super().__init__() + self.applist = [] + self.nav = nav + self.current_index = 0 + for entry in entries: + self.addWidget(AppListPage(entry["group"])) + + def goto_slide(self, index): + self.current_index = index + self.setCurrentIndex(index) + self.nav.set_active_item(index) + + +class AppListPage(QWidget): + """Page of applications lists for a group""" + + def __init__(self, group): + super().__init__() + list_layout = QVBoxLayout() + for item in AppList: + if group in item["group"]: + list_layout.addWidget( + ApplistItem( + item["group"], + item["icon"], + item["name"], + item["title"], + item["description"], + item["repo"], + item["command"], + ) + ) + list_layout.addStretch(0) + self.setLayout(list_layout) + + +class Configuration(SlidePage): + def __init__(self): + # The button in the buttons bar, shortcut for Mageia Control Center + super().__init__(_("Configuration", "Your configuration")) + + # vertical layout + layout = QVBoxLayout() + layout.addStretch(0) + ns = NetworkState() + cf = ConfList(ns) + for config in cf.configuration: + content_label = QLabel(config) + content_label.setWordWrap(True) + content_label.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label) + + # About button + button_layout = QHBoxLayout() + button_layout.addStretch(1) + about_button = MyPushButton(_("Configuration", "About")) + about_button.clicked.connect(self.about) + button_layout.addWidget(about_button) + button_layout.addStretch(1) + layout.addLayout(button_layout) + layout.addStretch(0) + + self.setLayout(layout) + + def about(self): + message = QMessageBox( + QMessageBox.Icon.Warning, + _("Configuration", "About Mageiawelcome"), + # %1 will be replaced with the release number, %2 with author's names + _("Configuration", "Release %1<br />Authors : %2") + % (version.version, "Daniel Napora, Papoteur, Antony Baker<br />"), + ) + # Replace with the list of translator's names + messaget.setDetailedText( + _("Configuration", "Translators: English is the source language") + ) + message.exec() + + +class Live(SlidePage): + def __init__(self): + # The button in the buttons bar, shortcut for Mageia Control Center + super().__init__(_("Live", "Live mode")) + + # vertical layout + layout = QVBoxLayout() + content_label = QLabel( + _( + "Live", + "This mode allows you to try out Mageia without having to actually install it, or make any changes to your computer. However, the Live media also includes an Installer, which can be started when booting the media, or after booting into Live mode, like now.", + ) + ) + content_label.setWordWrap(True) + content_label.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label) + + content_label2 = QLabel( + _( + "Live", + "Any customization, including installation of additional software, will only survive until you reboot the system, unless you have added a persistence partition.", + ) + ) + content_label2.setWordWrap(True) + content_label2.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label2) + + + button_layout = QHBoxLayout() + button_layout.addStretch(1) + doc_button = MyPushButton(_("Live", "Installer documentation")) + doc_button.clicked.connect( + partial( + self.weblink, + # the link to the local file can be adapted to your language if the documentation is translated + _("Live", "file:///usr/share/doc/mageia/en/draklive/index.html"), + ) + ) + button_layout.addWidget(doc_button) + button_layout.addStretch(1) + layout.addLayout(button_layout) + + self.setLayout(layout) + + +class Install(SlidePage): + def __init__(self): + # The button in the buttons bar, shortcut for Mageia Control Center + super().__init__(_("Install", "Install")) + + # vertical layout + layout = QVBoxLayout() + content_label = QLabel( + _( + "Install", + "Here you can choose to permanently install this Mageia system on your computer. Any customizations you have made before launching the installer will be included.", + ) + ) + content_label.setWordWrap(True) + content_label.setStyleSheet("font-size: 14px; color: white;") + layout.addWidget(content_label) + + image = QPixmap("file:/usr/share/icons/draklive-install.png") + content_image = QLabel() + content_image.setPixmap(image) + layout.addWidget(content_image) + + button_layout = QHBoxLayout() + button_layout.addStretch(1) + install_button = MyPushButton(_("Install", "Launch installation")) + install_button.clicked.connect( + partial(self.command, ["/usr/bin/draklive-install"]) + ) + button_layout.addWidget(install_button) + button_layout.addStretch(1) + layout.addLayout(button_layout) + + self.setLayout(layout) + + +class GradientLegend(QWidget): + def __init__(self, label, top_color, bottom_color): + super().__init__() + self.top_color = top_color + self.bottom_color = bottom_color + layout = QHBoxLayout() + label_widget = QLabel(label) + label_widget.setStyleSheet("font-size: 14px; color: white; font-weight: bold;") + label_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) + layout.addWidget(label_widget) + self.setLayout(layout) + self.setAutoFillBackground(True) + self.setFixedWidth(100) + self.setFixedHeight(40) + + def paintEvent(self, event): + painter = QPainter(self) + gradient = QLinearGradient(0, 0, 0, 20) + gradient.setColorAt(0.0, self.top_color) + gradient.setColorAt(1.0, self.bottom_color) + painter.setBrush(gradient) + painter.setPen(Qt.PenStyle.NoPen) + painter.drawRect(self.rect()) + + +class ApplistItem(QWidget): + """An element in application list""" + + def __init__(self, group, icon, name, title, description, repo, command): + super().__init__() + + layout = QHBoxLayout() + layout.setContentsMargins(2, 2, 2, 2) + image = QPixmap(icon) + icon_widget = QLabel() + icon_widget.setPixmap(image.scaled(32, 32)) + icon_widget.setFixedWidth(32) + icon_widget.setFixedHeight(32) + layout.addWidget(icon_widget) + + desc_layout = QVBoxLayout() + name_label = QLabel(f"<b>{title}</b><br /><i>{description}</i>") + name_label.setStyleSheet( + """ + QLabel { + color: white; + font-size: 14px; + } + """ + ) + desc_layout.addWidget(name_label) + layout.addLayout(desc_layout) + release, inst_repo = is_installed(name) + if (not release) or (repo != inst_repo and inst_repo == ""): + # the application is not yet installed, we display an Install button + button = MyPushButton(_("mw-ui", "Install")) + else: + if command == "": + # there is no command associated, we display it is installed + button = QLabel(_("mw-ui", "Installed")) + button.setAlignment(Qt.AlignmentFlag.AlignCenter) + button.setStyleSheet( + """ + QLabel { + color: white; + font-size: 12px; + padding: 0px 0px; + } + """ + ) + else: + # display a button for launching command associated + button = MyPushButton(_("mw-ui", "Launch")) + button.setFixedWidth(QApplication.font().pointSize() * 10) + layout.addWidget(button) + # label for repository + repo_label = QLabel(repo) + repo_label.setFixedWidth(QApplication.font().pointSize() * 8) + repo_label.setFixedHeight(int(QApplication.font().pointSize() * 2)) + repo_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + if repo != "": + repo_label.setStyleSheet( + """ + QWidget { + background-color: "#FF4C4C"; + radius: 3 + } + QLabel { + color: white; + font-size: 14px; + } + """ + ) + layout.addWidget(repo_label) + self.setLayout(layout) + +class MyPushButton(QPushButton): + def __init__(self, label): + super().__init__(label) + + self.setStyleSheet( + """ + QWidget {background-color: lightgray; border-radius: 5px; padding: 8px 8px;} + QLabel {font-size: 18px;} + """ + ) + + +class BreadcrumbItem(QWidget): + """Un élément du fil d'Ariane""" + + def __init__(self, title, index, parent=None, lateral=False): + super().__init__(parent) + self.title = title + self.index = index + self.active = False + self.lateral = lateral + + # Layout horizontal pour l'élément + layout = QHBoxLayout(self) + + # Étiquette pour le titre + self.label = QLabel(title) + self.label.setAlignment(Qt.AlignmentFlag.AlignCenter) + self.label.setWordWrap(True) + self.update_style() + + layout.addWidget(self.label) + self.setLayout(layout) + + # Rendre l'élément cliquable + self.setCursor(Qt.CursorShape.PointingHandCursor) + + def set_active(self, active): + """Définit si cet élément est actif ou non""" + self.active = active + self.update_style() + + def set_width(self, width): + self.setMinimumWidth(width) + + def update_style(self): + """Met à jour le style en fonction de l'état actif""" + if self.lateral: + if self.active: + self.setStyleSheet( + """ + QLabel { + color: white; + background-color: #262F45; + font-size: 14px; + border-radius: 5px; + min-height: 30px; + } + """ + ) + else: + self.setStyleSheet( + """ + QWidget:hover { + background-color: #2397D4; + border-radius: 5px; + min-height: 30px; + } + QLabel { + color: white; + font-size: 14px; + } + """ + ) + + else: + if self.active: + self.setStyleSheet( + """ + QWidget { + background-color: #2397D4; + border-radius: 5px; + min-height: 40px; + } + QLabel { + color: white; + font-size: 12px; + padding: 2px 8px; + } + """ + ) + else: + self.setStyleSheet( + """ + QWidget:hover { + background-color: #2397D4; + border-radius: 5px; + min-height: 40px; + } + QLabel { + background-color: white; + border-radius: 5px; + color: #2c3e50; + font-size: 12px; + padding: 2px 8px; + margins: 5px; + } + """ + ) + + def mousePressEvent(self, event): + """Détecte le clic sur l'élément""" + if event.button() == Qt.MouseButton.LeftButton: + # Émettre un signal personnalisé pour indiquer que cet élément a été cliqué + self.parent().item_clicked(self.index) + + def showEvent(self, event): + self.update_style() + + +class Breadcrumb(QWidget): + """Fil d'Ariane for navigation in pages or in application groups (lateral)""" + + def __init__(self, parent=None, lateral=False): + super().__init__(parent) + + # Container for elements + self.lateral = lateral + self.container = self + palette = QPalette() + palette.setColor( + QPalette.ColorRole.Window, QColor("#20FFFFFF" if lateral else "#262F45") + ) + self.container.setPalette(palette) + self.container.setAutoFillBackground(True) + + self.layout = ( + QVBoxLayout(self.container) if lateral else QHBoxLayout(self.container) + ) + self.layout.setSpacing(5) + self.layout.setContentsMargins(5, 0, 5, 0) + + # List for storing elements + self.items = [] + + # reference to slideshow + self.slideshow = None + + def set_slideshow(self, slideshow): + """Associe le fil d'Ariane à un diaporama""" + self.slideshow = slideshow + + def add_item(self, title, index): + """Ajoute un élément au fil d'Ariane""" + item = BreadcrumbItem(title, index, self, lateral=self.lateral) + self.layout.addWidget(item) + self.items.append(item) + if not self.lateral: + width = int(DEFAULT_WIDTH / len(self.items)) + for item in self.items: + item.set_width(width) + + def set_active_item(self, index): + """Définit l'élément actif""" + for i, item in enumerate(self.items): + item.set_active(i == index) + + def item_clicked(self, index): + """Appelé quand un élément est cliqué""" + if self.slideshow: + self.slideshow.goto_slide(index) + + +class SlideShowWidget(QStackedWidget): + """Widget de diaporama avec animations de transition""" + + def __init__(self): + super().__init__() + + self.current_index = 0 + self.next_index = 0 + self.in_transition = False + self.animation_duration = 800 + + self.setContentsMargins(0, 0, 0, 0) + + # Fil d'Ariane associé + self.breadcrumb = None + self.admin_rights = [] + + def set_breadcrumb(self, breadcrumb): + """Associe un fil d'Ariane au diaporama""" + self.breadcrumb = breadcrumb + self.breadcrumb.set_slideshow(self) + + def add_slide(self, slide, admin_rights=False): + """Ajoute une diapositive au diaporama""" + self.addWidget(slide) + if self.breadcrumb: + width = self.breadcrumb.add_item(slide.title, self.count() - 1) + self.admin_rights.append(admin_rights) + + def next_slide(self): + """Passe à la diapositive suivante avec animation""" + if self.in_transition or self.count() <= 1: + return + + self.next_index = (self.current_index + 1) % self.count() + self._animate_horizontal_transition(True) # True = at right + self.admin_widget.show() if self.admin_rights[ + index + ] else self.admin_widget.hide() + + def previous_slide(self): + """Passe à la diapositive précédente avec animation""" + if self.in_transition or self.count() <= 1: + return + + self.next_index = (self.current_index - 1) % self.count() + self._animate_horizontal_transition(False) # False = at left + self.admin_widget.show() if self.admin_rights[ + index + ] else self.admin_widget.hide() + + def goto_slide(self, index): + """Va directement à une diapositive spécifique""" + if ( + self.in_transition + or index == self.current_index + or index < 0 + or index >= self.count() + ): + return + + self.next_index = index + + # Déterminer la direction de l'animation + forward = self.next_index > self.current_index + if self.next_index == 0 and self.current_index == self.count() - 1: + forward = True + elif self.next_index == self.count() - 1 and self.current_index == 0: + forward = False + + self._animate_horizontal_transition(forward) + self.admin_widget.show() if self.admin_rights[ + index + ] else self.admin_widget.hide() + + def _animate_horizontal_transition(self, forward=True): + """Anime la transition horizontale entre deux diapositives""" + self.in_transition = True + + # Mettre à jour le fil d'Ariane + if self.breadcrumb: + self.breadcrumb.set_active_item(self.next_index) + + # Widget actuel + current_widget = self.widget(self.current_index) + + # Widget suivant (à afficher) + next_widget = self.widget(self.next_index) + + # S'assurer que le widget suivant est visible mais pas encore au premier plan + next_widget.setGeometry(current_widget.geometry()) + next_widget.show() + next_widget.raise_() + + # Positionner les widgets pour l'animation + offset = self.width() + + # Position de départ du widget suivant (en dehors de l'écran) + if forward: # Glissement vers la gauche (la nouvelle diapo vient de droite) + next_widget.move(offset, 0) + else: # Glissement vers la droite (la nouvelle diapo vient de gauche) + next_widget.move(-offset, 0) + + # Animation pour le widget actuel + self.current_anim = QPropertyAnimation(current_widget, b"pos") + self.current_anim.setDuration(self.animation_duration) + self.current_anim.setStartValue(current_widget.pos()) + if forward: # Glissement vers la gauche + self.current_anim.setEndValue(QPoint(-offset, 0)) + else: # Glissement vers la droite + self.current_anim.setEndValue(QPoint(offset, 0)) + self.current_anim.setEasingCurve(QEasingCurve.Type.OutCubic) + + # Animation pour le nouveau widget + self.next_anim = QPropertyAnimation(next_widget, b"pos") + self.next_anim.setDuration(self.animation_duration) + self.next_anim.setStartValue(next_widget.pos()) + self.next_anim.setEndValue(QPoint(0, 0)) + self.next_anim.setEasingCurve(QEasingCurve.Type.OutCubic) + + # Connecter le signal de fin d'animation + self.next_anim.finished.connect(self._finish_transition) + + # Démarrer les animations + self.current_anim.start() + self.next_anim.start() + + def _finish_transition(self): + """Nettoie après la fin de l'animation""" + # Mettre à jour l'indice courant + self.current_index = self.next_index + + # Cacher tous les widgets sauf celui à l'indice courant + for i in range(self.count()): + if i != self.current_index: + self.widget(i).hide() + + # Terminer la transition + self.in_transition = False + + def set_admin_rights(self, admin_widget): + # used to display note at bottom + self.admin_widget = admin_widget + + +class SlideShowApp(QMainWindow): + """Application principale de diaporama""" + + def __init__(self): + super().__init__() + self.setWindowTitle(_("mw-ui", _("Welcome", "Welcome to Mageia"))) + self.setGeometry(100, 100, 100 + DEFAULT_WIDTH, 700) + + # central Widget + central_widget = QWidget() + main_layout = QGridLayout(central_widget) + main_layout.setContentsMargins(0, 0, 0, 0) + banner = QLabel() + picture = self.createGradientBanner(self.width(), 120) + banner.setPixmap(QPixmap.fromImage(picture)) + main_layout.addWidget(banner, 0, 0) + + # Créer le fil d'Ariane + self.breadcrumb = Breadcrumb() + main_layout.addWidget(self.breadcrumb, 1, 0) + + # Créer le diaporama + self.slideshow = SlideShowWidget() + self.slideshow.set_breadcrumb(self.breadcrumb) + + self.slideshow.add_slide(Welcome(self.username())) + if self.username() != "live": + self.slideshow.add_slide(Sources(), admin_rights=True) + self.slideshow.add_slide(Updates(), admin_rights=True) + self.slideshow.add_slide(Mcc(), admin_rights=True) + self.slideshow.add_slide( + InstallSoftware(self.username()), admin_rights=True + ) + self.slideshow.add_slide(Applications()) + self.slideshow.add_slide(Configuration()) + else: + # Live mode + self.slideshow.add_slide(Live()) + self.slideshow.add_slide(Mcc()) + self.slideshow.add_slide(InstallSoftware(self.username())) + # Install on HD + self.slideshow.add_slide(Install()) + self.slideshow.add_slide(Links()) + + # Mettre à jour le fil d'Ariane pour la première diapositive + self.breadcrumb.set_active_item(0) + + # Ajouter au layout principal + main_layout.addWidget(self.slideshow, 2, 0) + + # background color at bottom + widget = QWidget() + bottom_layout = QHBoxLayout() + palette = QPalette() + palette.setColor(QPalette.ColorRole.Window, QColor("#2397D4")) + widget.setPalette(palette) + widget.setAutoFillBackground(True) + widget.setLayout(bottom_layout) + widget.setContentsMargins(0, 0, 0, 0) + self.admin_rights = QLabel( + _("Sources", "(*) Administrator password is needed.") + ) + bottom_layout.addWidget(self.admin_rights) + self.slideshow.set_admin_rights(self.admin_rights) + bottom_layout.addStretch(1) + self.admin_rights.hide() + self.cb_launch = QCheckBox(_("mw-ui", "Show this window at startup")) + self.cb_launch.clicked.connect(self.toogle_start) + bottom_layout.setAlignment(Qt.AlignmentFlag.AlignJustify) + bottom_layout.addWidget(self.cb_launch) + main_layout.addWidget(widget, 3, 0) + + self.setCentralWidget(central_widget) + + self.autostart = Autostart() + self.cb_launch.setChecked(self.autostart.isEnabled()) + + def username(self): + user = pwd.getpwuid(os.getuid())[4] # pw_gecos, i e the real name + if user == "": + user = pwd.getpwuid(os.getuid())[0] # login + return user + + def createGradientBanner(self, width, height): + image = QImage(width, height, QImage.Format.Format_ARGB32) + image.fill(QColorConstants.Transparent) + + painter = QPainter(image) + logo = QPixmap("img/mageia-2013-black-alpha.png") + gradient = QLinearGradient(0, 0, width, 0) + gradient.setColorAt(0.0, QColorConstants.Svg.lightgray) + gradient.setColorAt(1.0, QColorConstants.White) + + painter.fillRect(0, 0, width, height, gradient) + painter.setCompositionMode(QPainter.CompositionMode.CompositionMode_SourceOver) + painter.drawPixmap( + QPoint((width - logo.width()) // 2, (height - logo.height()) // 2), logo + ) + painter.end() + + return image + + def toogle_start(self): + if self.cb_launch.isChecked(): + self.autostart.enable() + else: + self.autostart.disable() + + +if __name__ == "__main__": + app = QApplication(sys.argv) + window = SlideShowApp() + window.show() + sys.exit(app.exec()) |
