Skip to content

Commit

Permalink
Update getMedia function
Browse files Browse the repository at this point in the history
  • Loading branch information
panther7 committed Jan 22, 2023
1 parent b94c508 commit 3f09fe7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions wingetui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self):
titlewidget = QHBoxLayout()
titlewidget.addStretch()
icon = QLabel()
icon.setPixmap(QPixmap(realpath+"/resources/icon.png").scaledToWidth(128, Qt.TransformationMode.SmoothTransformation))
icon.setPixmap(QPixmap(getMedia("icon", autoIconMode = False)).scaledToWidth(128, Qt.TransformationMode.SmoothTransformation))
text = QLabel("WingetUI")
text.setStyleSheet(f"font-family: \"{globals.dispfont}\";font-weight: bold; color: {'white' if isDark() else 'black'};font-size: 50pt;")
titlewidget.addWidget(icon)
Expand Down Expand Up @@ -285,7 +285,7 @@ def loadMainUI(self):
globals.trayIcon = QSystemTrayIcon()
self.trayIcon = globals.trayIcon
globals.app = self
self.trayIcon.setIcon(QIcon(realpath+"/resources/icon.png"))
self.trayIcon.setIcon(QIcon(getMedia("icon", autoIconMode = False)))
self.trayIcon.setToolTip("WingetUI")
self.trayIcon.setVisible(True)

Expand Down
2 changes: 1 addition & 1 deletion wingetui/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self):
self.setWindowTitle("WingetUI")
self.setMinimumSize(700, 560)
self.setObjectName("micawin")
self.setWindowIcon(QIcon(realpath+"/resources/icon.png"))
self.setWindowIcon(QIcon(getMedia("icon", autoIconMode = False)))
self.resize(QSize(1100, 700))
try:
rs = getSettingsValue("OldWindowGeometry").split(",")
Expand Down
18 changes: 9 additions & 9 deletions wingetui/storeEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ def __init__(self, title: str, store: str, version: list = [], parent=None, cust
self.finishInstallation.connect(self.finish)
self.layout.addWidget(self.info)
self.counterSignal.connect(self.counter)
self.liveOutputButton = QPushButton(QIcon(realpath+"/resources/console.png"), _(""))
self.liveOutputButton = QPushButton(QIcon(getMedia("console", autoIconMode = False)), "")
self.liveOutputButton.clicked.connect(lambda: (self.liveOutputWindow.show(), ApplyMica(self.liveOutputWindow.winId(), isDark())))
self.liveOutputButton.setFixedHeight(30)
self.liveOutputButton.setFixedWidth(30)
self.liveOutputButton.setToolTip(_("Show the live output"))
self.liveOutputButton.setIcon(QIcon(getMedia("console")))
self.layout.addWidget(self.liveOutputButton)
self.cancelButton = QPushButton(QIcon(realpath+"/resources/cancel.png"), _("Cancel"))
self.cancelButton = QPushButton(QIcon(getMedia("cancel", autoIconMode = False)), _("Cancel"))
self.cancelButton.clicked.connect(self.cancel)
self.cancelButton.setFixedHeight(30)
self.info.setFixedHeight(30)
Expand Down Expand Up @@ -191,7 +191,7 @@ def cancel(self):
self.info.setText(_("Installation canceled by the user!"))
self.cancelButton.setEnabled(True)
self.cancelButton.setText(_("Close"))
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.cancelButton.setIcon(QIcon(getMedia("warn", autoIconMode = False)))
self.cancelButton.clicked.connect(self.close)
self.onCancel.emit()
self.progressbar.setValue(1000)
Expand Down Expand Up @@ -230,10 +230,10 @@ def finish(self, returncode: int, output: str = "") -> None:
self.progressbar.setValue(1000)
if (returncode == 0 or returncode == 3):
if returncode == 0:
self.cancelButton.setIcon(QIcon(realpath+"/resources/tick.png"))
self.cancelButton.setIcon(QIcon(getMedia("tick", autoIconMode = False)))
self.info.setText(_("{action} was successfully!").format(action = self.actionDone))
if returncode == 3: # if the installer need restart computer
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.cancelButton.setIcon(QIcon(getMedia("warn", autoIconMode = False)))
self.info.setText(_("Restart your PC to finish installation"))
self.callInMain.emit(lambda: globals.trayIcon.showMessage(_("{0} succeeded").format(self.actionName.capitalize()), _("{0} was {1} successfully!").format(self.programName, self.actionDone), QIcon(getMedia("notif_info"))))
if type(self) == PackageInstallerWidget:
Expand All @@ -243,7 +243,7 @@ def finish(self, returncode: int, output: str = "") -> None:
self.startCoolDown()
return
globals.trayIcon.setIcon(QIcon(getMedia("yellowicon")))
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.cancelButton.setIcon(QIcon(getMedia("warn", autoIconMode = False)))
self.err = ErrorMessage(self.window())
warnIcon = QIcon(getMedia("notif_warn"))
dialogData = {
Expand Down Expand Up @@ -479,7 +479,7 @@ def cancel(self):
self.finishedInstallation = True
self.cancelButton.setEnabled(True)
self.cancelButton.setText(_("Close"))
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.cancelButton.setIcon(QIcon(getMedia("warn", autoIconMode = False)))
self.cancelButton.clicked.connect(self.close)
self.onCancel.emit()
self.progressbar.setValue(1000)
Expand Down Expand Up @@ -523,15 +523,15 @@ def finish(self, returncode: int, output: str = "") -> None:
if(returncode == 0):
self.callInMain.emit(lambda: globals.trayIcon.showMessage(_("{0} succeeded").format(self.actionName.capitalize()), _("{0} was {1} successfully!").format(self.programName, self.actionDone), QIcon(getMedia("notif_info"))))
self.cancelButton.setText(_("OK"))
self.cancelButton.setIcon(QIcon(realpath+"/resources/tick.png"))
self.cancelButton.setIcon(QIcon(getMedia("tick", autoIconMode = False)))
self.cancelButton.clicked.connect(self.close)
self.info.setText(_("{action} was successfully!").format(action = self.actionDone))
self.progressbar.setValue(1000)
self.startCoolDown()
else:
globals.trayIcon.setIcon(QIcon(getMedia("yellowicon")))
self.cancelButton.setText(_("OK"))
self.cancelButton.setIcon(QIcon(realpath+"/resources/warn.png"))
self.cancelButton.setIcon(QIcon(getMedia("warn", autoIconMode = False)))
self.cancelButton.clicked.connect(self.close)
self.progressbar.setValue(1000)
self.err = ErrorMessage(self.window())
Expand Down
10 changes: 6 additions & 4 deletions wingetui/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,16 @@ def ApplyMenuBlur(hwnd: int, window: QWidget, smallCorners: bool = False, avoidO


def getPath(s):
return os.path.join(os.path.join(realpath, "resources"), s).replace("\\", "/")
return os.path.join(realpath, "resources", s).replace("\\", "/")

def getIconMode() -> str:
return "white" if isDark() else "black"

def getMedia(m: str) -> str:
filename = getPath(m+"_"+getIconMode()+".png")
if not os.path.exists(filename):
def getMedia(m: str, autoIconMode = True) -> str:
filename = ""
if autoIconMode == True:
filename = getPath(m+"_"+getIconMode()+".png")
if not filename or not os.path.exists(filename):
filename = getPath(m+".png")
return filename

Expand Down

0 comments on commit 3f09fe7

Please sign in to comment.