Skip to content

Add add in-window notifications #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions wingetui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,12 @@ def updateIfPossible(self):
font-family: "Segoe UI Variable Text";
outline: none;
}}
#InWindowNotification {{
background-color: #181818;
border-radius: 16px;
height: 32px;
border: 1px solid #101010;
}}
*::disabled {{
color: gray;
}}
Expand Down Expand Up @@ -1390,6 +1396,12 @@ def updateIfPossible(self):
*::disabled {{
color: gray;
}}
#InWindowNotification {{
background-color: #dddddd;
border-radius: 16px;
height: 32px;
border: 1px solid #bbbbbb;
}}
QInputDialog {{
background-color: #f5f5f5;
}}
Expand Down
67 changes: 66 additions & 1 deletion wingetui/genericCustomWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,6 @@ def resizeEvent(self, event: QResizeEvent) -> None:
self.resized.emit()
return super().resizeEvent(event)


class VerticallyDraggableWidget(QLabel):
pressed = False
oldPos = QPoint(0, 0)
Expand Down Expand Up @@ -1226,5 +1225,71 @@ def mousePressEvent(self, ev: QMouseEvent) -> None:
self.clicked.emit()
return super().mousePressEvent(ev)

class InWindowNotification(QMainWindow):
callInMain = Signal(object)
def __init__(self, parent: QWidget, text: str):
super().__init__(parent.window())
self.callInMain.emit(lambda f: f())
if parent.window():
self.baseGeometry = parent.window().geometry()
else:
self.baseGeometry = QApplication.primaryScreen().geometry()
self.setWindowFlag(Qt.WindowType.Window, False)
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self.label = QLabel(text, self)
self.setCentralWidget(self.label)
self.label.setObjectName("InWindowNotification")
self.setObjectName("bg")
self.setStyleSheet("#bg{background-color: transparent;}")
self.setWindowOpacity(0)
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.opacity = QGraphicsOpacityEffect()
self.opacity.setOpacity(0)
self.label.setGraphicsEffect(self.opacity)
self.setMouseTracking(True)
effect = QGraphicsDropShadowEffect()
effect.setBlurRadius(5)
effect.setXOffset(0)
effect.setYOffset(0)
effect.setColor(Qt.GlobalColor.black)

self.setGraphicsEffect(effect)


def show(self, timeout: int = 5):
super().show()
self.update()
self.repaint()
self.setFixedHeight(34)
self.setFixedWidth(self.sizeHint().width()+32)
self.move(self.baseGeometry.width()//2 - self.sizeHint().width()//2, self.baseGeometry.height()-100)

self.hideAnim = QVariantAnimation()
self.hideAnim.setEasingCurve(QEasingCurve.Type.InOutQuart)
self.hideAnim.setStartValue(100)
self.hideAnim.setEndValue(0)
self.hideAnim.setDuration(300)
self.hideAnim.valueChanged.connect(lambda v: (self.opacity.setOpacity(v/100)))
self.hideAnim.finished.connect(lambda: self.hide())

self.showAnim = QVariantAnimation()
self.showAnim.setEasingCurve(QEasingCurve.Type.InOutQuart)
self.showAnim.setStartValue(0)
self.showAnim.setEndValue(100)
self.showAnim.setDuration(300)
self.showAnim.valueChanged.connect(lambda v: self.opacity.setOpacity(v/100))
self.timer = QTimer(self)
self.timer.setInterval(timeout*1000)
self.timer.start()
self.timer.timeout.connect(lambda: (print(""), self.hideAnim.start(), self.timer.stop()))
self.showAnim.start()

def mousePressEvent(self, event: QMouseEvent) -> None:
print("")
self.timer.stop()
self.hideAnim.start()
return super().mousePressEvent(event)


if __name__ == "__main__":
import __init__
2 changes: 1 addition & 1 deletion wingetui/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def ConvertMarkdownToHtml(text: str) -> str:

if (getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')):
sys.stdout = stdout_buffer = io.StringIO()
sys.stderr = stderr_buffer = io.StringIO()
sys.stderr = stdout_buffer

if hasattr(sys, 'frozen'):
realpath = sys._MEIPASS
Expand Down
34 changes: 19 additions & 15 deletions wingetui/uiSections.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ def uninstallPackage():
self.UninstallAction.triggered.connect(lambda: uninstallPackage())
self.IgnoreUpdates = QAction(_("Ignore updates for this package"))
self.IgnoreUpdates.setIcon(QIcon(getMedia("pin")))

self.IgnoreUpdates.triggered.connect(lambda: (IgnorePackageUpdates_Permanent(self.packageList.currentItem().text(2), self.packageList.currentItem().text(5)), self.packageList.currentItem().setHidden(True), self.packageItems.remove(self.packageList.currentItem()), self.showableItems.remove(self.packageList.currentItem()), self.packageList.takeTopLevelItem(self.packageList.indexOfTopLevelItem(self.packageList.currentItem())), self.updatePackageNumber()))
self.SkipVersionAction = QAction(_("Skip this version"))
self.SkipVersionAction.setIcon(QIcon(getMedia("skip")))
Expand Down Expand Up @@ -1006,9 +1007,10 @@ def blacklistSelectedPackages():
try:
if program.checkState(0) == Qt.CheckState.Checked:
IgnorePackageUpdates_Permanent(program.text(2), program.text(4))
# TODO: Needs labels
except AttributeError:
pass
self.notif = InWindowNotification(self, _("The selected packages have been blacklisted"))
self.notif.show()
self.updatePackageNumber()

def showInfo():
Expand Down Expand Up @@ -1736,15 +1738,15 @@ def resetAdminRightsCache():

dontUseBuiltInGsudo = SectionCheckBox(_("Use installed GSudo instead of the bundled one (requires app restart)"))
dontUseBuiltInGsudo.setChecked(getSettings("UseUserGSudo"))
dontUseBuiltInGsudo.stateChanged.connect(lambda v: setSettings("UseUserGSudo", bool(v)))
dontUseBuiltInGsudo.stateChanged.connect(lambda v: (setSettings("UseUserGSudo", bool(v)), self.inform(_("Restart WingetUI to fully apply changes"))))
dontUseBuiltInGsudo.setStyleSheet("QWidget#stChkBg{border-bottom-left-radius: 8px;border-bottom-right-radius: 8px;border-bottom: 1px;}")
self.advancedOptions.addWidget(dontUseBuiltInGsudo)

self.advancedOptions = CollapsableSection(_("Experimental settings and developer options"), getMedia("testing"), _("Beta features and other options that shouldn't be touched"))
self.layout.addWidget(self.advancedOptions)
disableShareApi = SectionCheckBox(_("Disable new share API (port 7058)"))
disableShareApi.setChecked(getSettings("DisableApi"))
disableShareApi.stateChanged.connect(lambda v: setSettings("DisableApi", bool(v)))
disableShareApi.stateChanged.connect(lambda v: (setSettings("DisableApi", bool(v)), self.inform(_("Restart WingetUI to fully apply changes"))))
self.advancedOptions.addWidget(disableShareApi)
parallelInstalls = SectionCheckBox(_("Allow parallel installs (NOT RECOMMENDED)"))
parallelInstalls.setChecked(getSettings("AllowParallelInstalls"))
Expand All @@ -1753,14 +1755,14 @@ def resetAdminRightsCache():

enableSystemWinget = SectionCheckBox(_("Use system Winget (Needs a restart)"))
enableSystemWinget.setChecked(getSettings("UseSystemWinget"))
enableSystemWinget.stateChanged.connect(lambda v: setSettings("UseSystemWinget", bool(v)))
enableSystemWinget.stateChanged.connect(lambda v: (setSettings("UseSystemWinget", bool(v)), self.inform(_("Restart WingetUI to fully apply changes"))))
self.advancedOptions.addWidget(enableSystemWinget)
disableLangUpdates = SectionCheckBox(_("Do not download new app translations from GitHub automatically"))
disableLangUpdates.setChecked(getSettings("DisableLangAutoUpdater"))
disableLangUpdates.stateChanged.connect(lambda v: setSettings("DisableLangAutoUpdater", bool(v)))
self.advancedOptions.addWidget(disableLangUpdates)
resetyWingetUICache = SectionButton(_("Reset WingetUI icon and screenshot cache"), _("Reset"))
resetyWingetUICache.clicked.connect(lambda: (shutil.rmtree(os.path.join(os.path.expanduser("~"), ".wingetui/cachedmeta/")), notify("WingetUI", _("Cache was reset successfully!"))))
resetyWingetUICache.clicked.connect(lambda: (shutil.rmtree(os.path.join(os.path.expanduser("~"), ".wingetui/cachedmeta/")), self.inform(_("Cache was reset successfully!"))))
resetyWingetUICache.setStyleSheet("QWidget#stBtn{border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;border-bottom: 0px;}")
self.advancedOptions.addWidget(resetyWingetUICache)

Expand Down Expand Up @@ -1791,7 +1793,7 @@ def resetWingetUIStore():
self.layout.addWidget(self.wingetPreferences)
disableWinget = SectionCheckBox(_("Enable {pm}").format(pm = "Winget"))
disableWinget.setChecked(not getSettings(f"Disable{Winget.NAME}"))
disableWinget.stateChanged.connect(lambda v: (setSettings(f"Disable{Winget.NAME}", not bool(v)), parallelInstalls.setEnabled(v), button.setEnabled(v), enableSystemWinget.setEnabled(v)))
disableWinget.stateChanged.connect(lambda v: (setSettings(f"Disable{Winget.NAME}", not bool(v)), parallelInstalls.setEnabled(v), button.setEnabled(v), enableSystemWinget.setEnabled(v), self.inform(_("Restart WingetUI to fully apply changes"))))
self.wingetPreferences.addWidget(disableWinget)
disableWinget = SectionCheckBox(_("Enable Microsoft Store package source"))
disableWinget.setChecked(not getSettings(f"DisableMicrosoftStore"))
Expand All @@ -1809,15 +1811,15 @@ def resetWingetUIStore():
enableSystemWinget.setEnabled(disableWinget.isChecked())

resetCache = SectionButton(_("Reset {pm} cache").format(pm=Winget.NAME), _("Reset"))
resetCache.clicked.connect(lambda: (os.remove(Winget.CAHCE_FILE), notify("WingetUI", _("Cache was reset successfully!"))))
resetCache.clicked.connect(lambda: (os.remove(Winget.CACHE_FILE), self.inform(_("Cache was reset successfully!"))))
self.wingetPreferences.addWidget(resetCache)

self.scoopPreferences = CollapsableSection(_("{pm} preferences").format(pm = "Scoop"), getMedia("scoop"), _("{pm} package manager specific preferences").format(pm = "Scoop"))
self.layout.addWidget(self.scoopPreferences)

disableScoop = SectionCheckBox(_("Enable {pm}").format(pm = "Scoop"))
disableScoop.setChecked(not getSettings(f"Disable{Scoop.NAME}"))
disableScoop.stateChanged.connect(lambda v: (setSettings(f"Disable{Scoop.NAME}", not bool(v)), scoopPreventCaps.setEnabled(v), bucketManager.setEnabled(v), uninstallScoop.setEnabled(v), enableScoopCleanup.setEnabled(v)))
disableScoop.stateChanged.connect(lambda v: (setSettings(f"Disable{Scoop.NAME}", not bool(v)), scoopPreventCaps.setEnabled(v), bucketManager.setEnabled(v), uninstallScoop.setEnabled(v), enableScoopCleanup.setEnabled(v), self.inform(_("Restart WingetUI to fully apply changes"))))
self.scoopPreferences.addWidget(disableScoop)
scoopPreventCaps = SectionCheckBox(_("Show Scoop packages in lowercase"))
scoopPreventCaps.setChecked(getSettings("LowercaseScoopApps"))
Expand All @@ -1840,43 +1842,41 @@ def resetWingetUIStore():
self.scoopPreferences.addWidget(uninstallScoop)
uninstallScoop.setStyleSheet("QWidget#stBtn{border-bottom-left-radius: 0;border-bottom-right-radius: 0;border-bottom: 0;}")


scoopPreventCaps.setEnabled(disableScoop.isChecked())
bucketManager.setEnabled(disableScoop.isChecked())
uninstallScoop.setEnabled(disableScoop.isChecked())
enableScoopCleanup.setEnabled(disableScoop.isChecked())
resetCache = SectionButton(_("Reset {pm} cache").format(pm=Scoop.NAME), _("Reset"))
resetCache.clicked.connect(lambda: (os.remove(Scoop.CAHCE_FILE), notify("WingetUI", _("Cache was reset successfully!"))))
resetCache.clicked.connect(lambda: (os.remove(Scoop.CACHE_FILE), self.inform(_("Cache was reset successfully!"))))
self.scoopPreferences.addWidget(resetCache)

self.chocoPreferences = CollapsableSection(_("{pm} preferences").format(pm = "Chocolatey"), getMedia("choco"), _("{pm} package manager specific preferences").format(pm = "Chocolatey"))
self.layout.addWidget(self.chocoPreferences)
disableChocolatey = SectionCheckBox(_("Enable {pm}").format(pm = "Chocolatey"))
disableChocolatey.setChecked(not getSettings(f"Disable{Choco.NAME}"))
disableChocolatey.stateChanged.connect(lambda v: (setSettings(f"Disable{Choco.NAME}", not bool(v))))
disableChocolatey.stateChanged.connect(lambda v: (setSettings(f"Disable{Choco.NAME}", not bool(v)), self.inform(_("Restart WingetUI to fully apply changes"))))
self.chocoPreferences.addWidget(disableChocolatey)
enableSystemChocolatey = SectionCheckBox(_("Use system Chocolatey (Needs a restart)"))
enableSystemChocolatey.setChecked(getSettings("UseSystemChocolatey"))
enableSystemChocolatey.stateChanged.connect(lambda v: setSettings("UseSystemChocolatey", bool(v)))
self.chocoPreferences.addWidget(enableSystemChocolatey)
resetCache = SectionButton(_("Reset {pm} cache").format(pm=Choco.NAME), _("Reset"))
resetCache.clicked.connect(lambda: (os.remove(Choco.CAHCE_FILE), notify("WingetUI", _("Cache was reset successfully!"))))
resetCache.clicked.connect(lambda: (os.remove(Choco.CACHE_FILE), self.inform(_("Cache was reset successfully!"))))
self.chocoPreferences.addWidget(resetCache)


self.pipPreferences = CollapsableSection(_("{pm} preferences").format(pm = "Pip"), getMedia("python"), _("{pm} package manager specific preferences").format(pm = "Pip"))
self.layout.addWidget(self.pipPreferences)
disablePip = SectionCheckBox(_("Enable {pm}").format(pm = "Pip"))
disablePip.setChecked(not getSettings(f"Disable{Pip.NAME}"))
disablePip.stateChanged.connect(lambda v: (setSettings(f"Disable{Pip.NAME}", not bool(v))))
disablePip.stateChanged.connect(lambda v: (setSettings(f"Disable{Pip.NAME}", not bool(v)), self.inform(_("Restart WingetUI to fully apply changes"))))
self.pipPreferences.addWidget(disablePip)
disablePip.setStyleSheet("QWidget#stChkBg{border-bottom-left-radius: 8px;border-bottom-right-radius: 8px;border-bottom: 1px;}")

self.npmPreferences = CollapsableSection(_("{pm} preferences").format(pm = "Npm"), getMedia("node"), _("{pm} package manager specific preferences").format(pm = "Npm"))
self.layout.addWidget(self.npmPreferences)
disableNpm = SectionCheckBox(_("Enable {pm}").format(pm = Npm.NAME))
disableNpm.setChecked(not getSettings(f"Disable{Npm.NAME}"))
disableNpm.stateChanged.connect(lambda v: (setSettings(f"Disable{Npm.NAME}", not bool(v))))
disableNpm.stateChanged.connect(lambda v: (setSettings(f"Disable{Npm.NAME}", not bool(v)), self.inform(_("Restart WingetUI to fully apply changes"))))
self.npmPreferences.addWidget(disableNpm)
disableNpm.setStyleSheet("QWidget#stChkBg{border-bottom-left-radius: 8px;border-bottom-right-radius: 8pc;border-bottom: 1px;}")

Expand All @@ -1888,6 +1888,10 @@ def resetWingetUIStore():
def showEvent(self, event: QShowEvent) -> None:
Thread(target=self.announcements.loadAnnouncements, daemon=True, name="Settings: Announce loader").start()
return super().showEvent(event)

def inform(self, text: str) -> None:
self.notif = InWindowNotification(self, text)
self.notif.show()

class BaseLogSection(QWidget):
def __init__(self):
Expand Down