mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
example button for the upgrade confirmation dialog
This commit is contained in:
@@ -41,7 +41,7 @@ class IconButton(QWidget):
|
||||
|
||||
class UpdateToggleButton(QWidget):
|
||||
|
||||
def __init__(self, app_view: ApplicationView, root: QWidget, locale_keys: dict, checked: bool = True):
|
||||
def __init__(self, app_view: ApplicationView, root: QWidget, locale_keys: dict, checked: bool = True, clickable: bool = True):
|
||||
super(UpdateToggleButton, self).__init__()
|
||||
|
||||
self.app_view = app_view
|
||||
@@ -53,12 +53,14 @@ class UpdateToggleButton(QWidget):
|
||||
self.setLayout(layout)
|
||||
|
||||
self.bt = QToolButton()
|
||||
self.bt.setCheckable(True)
|
||||
self.bt.clicked.connect(self.change_state)
|
||||
self.bt.setCheckable(clickable)
|
||||
|
||||
if clickable:
|
||||
self.bt.clicked.connect(self.change_state)
|
||||
|
||||
self.bt.setIcon(QIcon(resource.get_path('img/app_update.svg')))
|
||||
self.bt.setStyleSheet('QToolButton { background: #20A435 } ' +
|
||||
'QToolButton:checked { background: gray }')
|
||||
('QToolButton:checked { background: gray }' if clickable else ''))
|
||||
layout.addWidget(self.bt)
|
||||
|
||||
self.setToolTip(locale_keys['manage_window.apps_table.upgrade_toggle.tooltip'])
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from typing import List
|
||||
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
from PyQt5.QtWidgets import QMessageBox, QLabel, QWidget, QHBoxLayout
|
||||
from bauh_api.abstract.view import MessageType
|
||||
|
||||
from bauh.core import resource
|
||||
@@ -23,13 +25,22 @@ def show_message(title: str, body: str, type_: MessageType, icon: QIcon = QIcon(
|
||||
popup.exec_()
|
||||
|
||||
|
||||
def ask_confirmation(title: str, body: str, locale_keys: dict, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))):
|
||||
def ask_confirmation(title: str, body: str, locale_keys: dict, icon: QIcon = QIcon(resource.get_path('img/logo.svg')), widgets: List[QWidget] = None):
|
||||
dialog_confirmation = QMessageBox()
|
||||
dialog_confirmation.setIcon(QMessageBox.Question)
|
||||
dialog_confirmation.setWindowTitle(title)
|
||||
dialog_confirmation.setText(body)
|
||||
dialog_confirmation.setStyleSheet('QLabel { margin-right: 25px; }')
|
||||
|
||||
wbody = QWidget()
|
||||
wbody.setLayout(QHBoxLayout())
|
||||
wbody.layout().addWidget(QLabel(body))
|
||||
|
||||
if widgets:
|
||||
for w in widgets:
|
||||
wbody.layout().addWidget(w)
|
||||
|
||||
dialog_confirmation.layout().addWidget(wbody, 0, 1)
|
||||
|
||||
bt_yes = dialog_confirmation.addButton(locale_keys['popup.button.yes'], QMessageBox.YesRole)
|
||||
dialog_confirmation.addButton(locale_keys['popup.button.no'], QMessageBox.NoRole)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from bauh.core import resource
|
||||
from bauh.util import util
|
||||
from bauh.view.qt import dialog
|
||||
from bauh.view.qt.about import AboutDialog
|
||||
from bauh.view.qt.apps_table import AppsTable
|
||||
from bauh.view.qt.apps_table import AppsTable, UpdateToggleButton
|
||||
from bauh.view.qt.components import new_spacer
|
||||
from bauh.view.qt.confirmation import ConfirmationDialog
|
||||
from bauh.view.qt.history import HistoryDialog
|
||||
@@ -581,9 +581,11 @@ class ManageWindow(QWidget):
|
||||
if self.manager.requires_root('update', app_v.model):
|
||||
requires_root = True
|
||||
|
||||
bt_ex = UpdateToggleButton(None, self, self.locale_keys, clickable=False)
|
||||
if to_update and dialog.ask_confirmation(title=self.locale_keys['manage_window.upgrade_all.popup.title'],
|
||||
body=self.locale_keys['manage_window.upgrade_all.popup.body'],
|
||||
locale_keys=self.locale_keys):
|
||||
locale_keys=self.locale_keys,
|
||||
widgets=[bt_ex]):
|
||||
pwd = None
|
||||
|
||||
if not is_root() and requires_root:
|
||||
|
||||
Reference in New Issue
Block a user