From 48739df19b1f04520c70a1e21e0231ad117b2675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Mon, 23 Jan 2023 19:06:21 +0100 Subject: [PATCH 1/3] add thr basic structure --- wingetui/mainWindow.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/wingetui/mainWindow.py b/wingetui/mainWindow.py index 71174da76..1efbffe81 100644 --- a/wingetui/mainWindow.py +++ b/wingetui/mainWindow.py @@ -54,6 +54,7 @@ def __init__(self): }} QGroupBox:title{{ max-width: 0; max-height: 0; }} """) + self.askAboutPackageManagers() print("🟢 Main application loaded...") @@ -174,7 +175,39 @@ def resetSelectionIndex(): sct = QShortcut(QKeySequence("Ctrl+Shift+Tab"), self) sct.activated.connect(lambda: (self.mainWidget.setCurrentIndex((self.mainWidget.currentIndex() - 1) if self.mainWidget.currentIndex() > 0 else 3), self.buttonBox.buttons()[self.mainWidget.currentIndex()].setChecked(True))) - + def askAboutPackageManagers(self): + self.w = QWidget(self) + self.w.setWindowFlag(Qt.WindowType.Window) + self.w.setWindowTitle(_("\x20")) + self.w.setWindowIcon(self.windowIcon()) + self.w.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + self.w.setWindowFlag(Qt.WindowType.WindowMaximizeButtonHint, False) + self.w.setWindowFlag(Qt.WindowType.WindowMinimizeButtonHint, False) + self.w.setWindowFlag(Qt.WindowType.WindowCloseButtonHint, False) + self.w.setWindowModality(Qt.WindowModality.WindowModal) + + mainLayout = QVBoxLayout() + mainLayout.addWidget(QLabel("

"+_("Welcome to WingetUI - You may now choose your weapons. ")+"

")) + mainLayout.addWidget(QLabel(_("WingetUI is based on package managers, that are the actual engines to load, install update and remove software from your computer.
Now you can choose which ones you want to use."))) + + + + mainLayout.addStretch() + + + blayout = QHBoxLayout() + mainLayout.addLayout(blayout) + blayout.addStretch() + + okbutton = QPushButton("Apply and start WingetUI") + okbutton.setFixedSize(190, 30) + okbutton.setObjectName("AccentButton") + okbutton.clicked.connect(self.w.close) + blayout.addWidget(okbutton) + + self.w.setLayout(mainLayout) + self.w.show() + ApplyMica(self.w.winId(), MICAMODE.DARK if isDark() else MICAMODE.LIGHT) def addTab(self, widget: QWidget, label: str, addToMenu: bool = False, actionIcon: str = "") -> QPushButton: i = self.mainWidget.addWidget(widget) From 246f0a4688291323d4b70e026b129fdd523c60fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Tue, 24 Jan 2023 20:41:56 +0100 Subject: [PATCH 2/3] Finish implementing the welcome window for the package managers --- wingetui/__init__.py | 66 ++++++++++++++++++++++++++++++++++-- wingetui/customWidgets.py | 70 ++++++++++++++++++++++++++++++++++----- wingetui/mainWindow.py | 35 -------------------- 3 files changed, 126 insertions(+), 45 deletions(-) diff --git a/wingetui/__init__.py b/wingetui/__init__.py index acafec185..071e6e44f 100644 --- a/wingetui/__init__.py +++ b/wingetui/__init__.py @@ -97,11 +97,73 @@ def __init__(self): os.chdir(os.path.expanduser("~")) self.kill.connect(lambda: (self.popup.hide(), sys.exit(0))) self.callInMain.connect(lambda f: f()) - Thread(target=self.loadStuffThread, daemon=True).start() - self.loadingText.setText(_("Checking for other running instances...")) + if getSettings("AskedAbout3PackageManagers") == False: + self.askAboutPackageManagers(onclose=lambda: Thread(target=self.loadStuffThread, daemon=True).start()) + else: + Thread(target=self.loadStuffThread, daemon=True).start() + self.loadingText.setText(_("Checking for other running instances...")) except Exception as e: raise e + def askAboutPackageManagers(self, onclose: object): + self.w = NotClosableWidget() + self.w.setWindowFlag(Qt.WindowType.Window) + self.w.setWindowTitle(_("\x20")) + pixmap = QPixmap(4, 4) + pixmap.fill(Qt.GlobalColor.transparent) + self.w.setWindowIcon(pixmap) + self.w.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + self.w.setWindowFlag(Qt.WindowType.WindowMaximizeButtonHint, False) + self.w.setWindowFlag(Qt.WindowType.WindowMinimizeButtonHint, False) + self.w.setWindowFlag(Qt.WindowType.WindowCloseButtonHint, False) + self.w.setWindowModality(Qt.WindowModality.WindowModal) + + self.w.setMinimumWidth(750) + self.w.setContentsMargins(20, 0, 20, 10) + mainLayout = QVBoxLayout() + label = (QLabel("

"+_("Welcome to WingetUI")+"

"+("You may now choose your weapons. ")+"

")) + label.setAlignment(Qt.AlignmentFlag.AlignCenter) + label.setWordWrap(True) + mainLayout.addWidget(label) + label = (QLabel(_("WingetUI is based on package managers. They are the engines used to load, install update and remove software from your computer. Please select the desired package managers and hit \"Apply\" to continue. The default ones are Winget and Chocolatey"))) + label.setAlignment(Qt.AlignmentFlag.AlignCenter) + label.setWordWrap(True) + mainLayout.addWidget(label) + + + winget = PackageManager(_("Enable {pm}").format(pm="Winget"), _("Microsoft's official package manager. It contains well known software such as browsers, PDF readers, windows add-ons and other utilities, as well as other less-known but useful software, such as Microsoft Visual C++ Redistributables. Packages from winget have been carefully validated"), getMedia("winget")) + winget.setChecked(True) + scoop = PackageManager(_("Enable {pm}").format(pm="Scoop"), _("From scoop you will be able to download utilities that might not be suitable for everybody. Install CLI utilities such as nano, sudo or nmap for Windows. And with the ability to add custom buckets, you will be able to download unlimited amounts of different utilities, apps, fonts, games, and any other thing you can dream of."), getMedia("scoop")) + scoop.setChecked(False) + if getSettings("ScoopAlreadySetup") and not getSettings("DisableScoop"): + scoop.setChecked(True) + choco = PackageManager(_("Enable {pm}").format(pm="Chocolatey"), _("The package manager for Windows by default. With more than {0} packages on their repositories, you will find anything you want to install. From Firefox to Sysinternals, almost every package is available to download from Chocolatey servers.").format("9500"), getMedia("choco")) + choco.setChecked(True) + + mainLayout.addSpacing(20) + mainLayout.addWidget(winget) + mainLayout.addWidget(scoop) + mainLayout.addWidget(choco) + mainLayout.addSpacing(20) + + mainLayout.addStretch() + + + blayout = QHBoxLayout() + mainLayout.addLayout(blayout) + blayout.addStretch() + + okbutton = QPushButton(_("Apply and start WingetUI")) + okbutton.setFixedSize(190, 30) + okbutton.setObjectName("AccentButton") + okbutton.clicked.connect(lambda: (self.w.close(), onclose(), setSettings("AskedAbout3PackageManagers", True), setSettings("DisableWinget", not winget.isChecked()), setSettings("DisableScoop", not scoop.isChecked()), setSettings("DisableChocolatey", not choco.isChecked()))) + blayout.addWidget(okbutton) + + self.w.setLayout(mainLayout) + self.setStyleSheet(darkCSS if isDark() else lightCSS) + self.w.show() + ApplyMica(self.w.winId(), MICAMODE.DARK if isDark() else MICAMODE.LIGHT) + def loadStuffThread(self): try: self.loadStatus = 0 # There are 9 items (preparation threads) diff --git a/wingetui/customWidgets.py b/wingetui/customWidgets.py index 8777a54b5..022939814 100644 --- a/wingetui/customWidgets.py +++ b/wingetui/customWidgets.py @@ -998,19 +998,21 @@ def text(self) -> str: class QSettingsCheckBox(QWidget): stateChanged = Signal(bool) - def __init__(self, text="", parent=None): + def __init__(self, text="", parent=None, margin=70, bigfont = False): + self.margin = margin super().__init__(parent) self.setAttribute(Qt.WA_StyledBackground) self.setObjectName("stChkBg") self.checkbox = QCheckBox(text, self) if lang["locale"] == "zh_TW": - self.checkbox.setStyleSheet("font-size: 11pt;background: none;font-family: \"Microsoft JhengHei UI\";font-weight: 450;") + self.checkbox.setStyleSheet(f"font-size: {14 if bigfont else 11}pt;background: none;font-family: \"Microsoft JhengHei UI\";font-weight: {700 if bigfont else 450};") elif lang["locale"] == "zh_CN": - self.checkbox.setStyleSheet("font-size: 11pt;background: none;font-family: \"Microsoft YaHei UI\";font-weight: 450;") + self.checkbox.setStyleSheet(f"font-size: {14 if bigfont else 11}pt;background: none;font-family: \"Microsoft YaHei UI\";font-weight: {700 if bigfont else 450};") else: - self.checkbox.setStyleSheet("font-size: 9pt;background: none;font-family: \"Segoe UI Variable Text\";font-weight: 450;") + self.checkbox.setStyleSheet(f"font-size: {14 if bigfont else 9}pt;background: none;font-family: \"Segoe UI Variable {'Display' if bigfont else 'Text'}\";font-weight: {700 if bigfont else 450};") self.checkbox.setObjectName("stChk") self.checkbox.stateChanged.connect(self.stateChanged.emit) + self.setFixedHeight(50) def setChecked(self, checked: bool) -> None: self.checkbox.setChecked(checked) @@ -1022,10 +1024,12 @@ def get6px(self, i: int) -> int: return round(i*self.screen().devicePixelRatio()) def resizeEvent(self, event: QResizeEvent) -> None: - self.checkbox.move((70), 10) + if self.height() != 30: + self.checkbox.move((self.margin), 10) + else: + self.checkbox.move((self.margin), 0) self.checkbox.setFixedHeight(30) - self.checkbox.setFixedWidth(self.width()-(70)) - self.setFixedHeight(50) + self.checkbox.setFixedWidth(self.width()-(self.margin)) return super().resizeEvent(event) def text(self) -> str: @@ -1110,7 +1114,57 @@ def setText(self, text: str) -> None: def setIcon(self, icon: QIcon) -> None: self.image.setPixmap(icon.pixmap(QSize(self.image.size()))) - +class NotClosableWidget(QWidget): + def closeEvent(self, event: QCloseEvent) -> None: + if event.spontaneous(): + event.ignore() + return False + else: + event.accept() + return super().closeEvent(event) + +class PackageManager(QWidget): + def __init__(self, text, description, image) -> None: + super().__init__() + mainw = QWidget(self) + mainw.setContentsMargins(0, 0, 0, 0) + mainw.setObjectName("bgwidget") + mainw.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True) + self.checkbox = QSettingsCheckBox(text, mainw, margin=0, bigfont=True) + self.checkbox.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, False) + self.checkbox.stateChanged.connect(lambda v: (self.description.setEnabled(v), self.image.setEnabled(v))) + self.checkbox.setFixedHeight(30) + self.description = QLabel(description) + self.description.setWordWrap(True) + self.description.setEnabled(False) + self.image = QLabel() + self.image.setPixmap(QPixmap(image).scaledToHeight(64, Qt.TransformationMode.SmoothTransformation)) + h = QHBoxLayout() + v = QVBoxLayout() + v.addWidget(self.checkbox) + v.addWidget(self.description, stretch=1) + h.addLayout(v, stretch=1) + h.addWidget(self.image) + h.setContentsMargins(16, 16, 16, 16) + h2 = QHBoxLayout() + h.addStretch() + mainw.setLayout(h) + h2.addStretch() + h2.addWidget(mainw) + h2.setContentsMargins(0, 0, 0, 0) + h2.addStretch() + mainw.setFixedWidth(600) + self.setLayout(h2) + if isDark(): + self.setStyleSheet("""#bgwidget{background-color: rgba(255, 255, 255, 5%); border: 1px solid #101010; padding: 16px; border-radius: 16px;}""") + else: + self.setStyleSheet("""#bgwidget{background-color: rgba(255, 255, 255, 50%); border: 1px solid #eeeeee; padding: 16px; border-radius: 16px;}""") + + def setChecked(self, v: bool) -> None: + self.checkbox.setChecked(v) + + def isChecked(self) -> bool: + return self.checkbox.isChecked() if __name__ == "__main__": import __init__ \ No newline at end of file diff --git a/wingetui/mainWindow.py b/wingetui/mainWindow.py index 1efbffe81..38a471b4d 100644 --- a/wingetui/mainWindow.py +++ b/wingetui/mainWindow.py @@ -54,7 +54,6 @@ def __init__(self): }} QGroupBox:title{{ max-width: 0; max-height: 0; }} """) - self.askAboutPackageManagers() print("🟢 Main application loaded...") @@ -175,40 +174,6 @@ def resetSelectionIndex(): sct = QShortcut(QKeySequence("Ctrl+Shift+Tab"), self) sct.activated.connect(lambda: (self.mainWidget.setCurrentIndex((self.mainWidget.currentIndex() - 1) if self.mainWidget.currentIndex() > 0 else 3), self.buttonBox.buttons()[self.mainWidget.currentIndex()].setChecked(True))) - def askAboutPackageManagers(self): - self.w = QWidget(self) - self.w.setWindowFlag(Qt.WindowType.Window) - self.w.setWindowTitle(_("\x20")) - self.w.setWindowIcon(self.windowIcon()) - self.w.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) - self.w.setWindowFlag(Qt.WindowType.WindowMaximizeButtonHint, False) - self.w.setWindowFlag(Qt.WindowType.WindowMinimizeButtonHint, False) - self.w.setWindowFlag(Qt.WindowType.WindowCloseButtonHint, False) - self.w.setWindowModality(Qt.WindowModality.WindowModal) - - mainLayout = QVBoxLayout() - mainLayout.addWidget(QLabel("

"+_("Welcome to WingetUI - You may now choose your weapons. ")+"

")) - mainLayout.addWidget(QLabel(_("WingetUI is based on package managers, that are the actual engines to load, install update and remove software from your computer.
Now you can choose which ones you want to use."))) - - - - mainLayout.addStretch() - - - blayout = QHBoxLayout() - mainLayout.addLayout(blayout) - blayout.addStretch() - - okbutton = QPushButton("Apply and start WingetUI") - okbutton.setFixedSize(190, 30) - okbutton.setObjectName("AccentButton") - okbutton.clicked.connect(self.w.close) - blayout.addWidget(okbutton) - - self.w.setLayout(mainLayout) - self.w.show() - ApplyMica(self.w.winId(), MICAMODE.DARK if isDark() else MICAMODE.LIGHT) - def addTab(self, widget: QWidget, label: str, addToMenu: bool = False, actionIcon: str = "") -> QPushButton: i = self.mainWidget.addWidget(widget) btn = PushButtonWithAction(label) From b81a681baecd1c78c1478494e9ad10d164bb0ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Tue, 24 Jan 2023 20:43:19 +0100 Subject: [PATCH 3/3] remove .  --- wingetui/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wingetui/__init__.py b/wingetui/__init__.py index 071e6e44f..a4c087df7 100644 --- a/wingetui/__init__.py +++ b/wingetui/__init__.py @@ -121,7 +121,7 @@ def askAboutPackageManagers(self, onclose: object): self.w.setMinimumWidth(750) self.w.setContentsMargins(20, 0, 20, 10) mainLayout = QVBoxLayout() - label = (QLabel("

"+_("Welcome to WingetUI")+"

"+("You may now choose your weapons. ")+"

")) + label = (QLabel("

"+_("Welcome to WingetUI")+"

"+("You may now choose your weapons")+"

")) label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setWordWrap(True) mainLayout.addWidget(label)