mirror of
https://github.com/aclist/dztui.git
synced 2026-11-03 16:42:13 +01:00
feat: alert button
This commit is contained in:
1 parent
a2231e3cb9
commit
d9ec01d9b0
7 files changed
+72
-20
No files matched your search
@@ -1,13 +1,15 @@
|
||||
from typing import Callable, Literal, Self, TYPE_CHECKING
|
||||
|
||||
from dzgui.util.clip import copy_clipboard
|
||||
from dzgui.util.strings import atomic_buttons, connect_panel
|
||||
from dzgui.util.format import pluralize
|
||||
from dzgui.util.strings import alert_button_tooltip, atomic_buttons, connect_panel
|
||||
from dzgui.const.constants import (
|
||||
CLIPBOARD,
|
||||
INPUT_KEYBOARD,
|
||||
LIST_ADD,
|
||||
REFRESH_ICON,
|
||||
STEAM_ICON,
|
||||
WARNING,
|
||||
WEB_BROWSER,
|
||||
)
|
||||
|
||||
@@ -157,3 +159,26 @@ class AddButton(IconTextButton):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(icon=LIST_ADD, label=connect_panel.add)
|
||||
self.set_tooltip_text(connect_panel.add_tooltip)
|
||||
|
||||
|
||||
class LoggerAlertsButton(IconTextButton):
|
||||
def __init__(self, warnings: int, errors: int) -> None:
|
||||
warnings_text = ""
|
||||
errors_text = ""
|
||||
separator = ""
|
||||
if warnings > 0:
|
||||
warnings_plural = pluralize("warnings", warnings)
|
||||
warnings_text = f"{warnings} {warnings_plural}"
|
||||
if errors > 0:
|
||||
errors_plural = pluralize("errors", errors)
|
||||
errors_text = f" {errors} {errors_plural}"
|
||||
if warnings + errors > 1:
|
||||
separator = ","
|
||||
concat = warnings_text + separator + errors_text
|
||||
super().__init__(
|
||||
icon=WARNING,
|
||||
label=f"Loaded with{concat}",
|
||||
)
|
||||
self.set_halign(Gtk.Align.END)
|
||||
self.set_hexpand(True)
|
||||
self.set_tooltip_text(alert_button_tooltip)
|
||||
@@ -2,6 +2,7 @@ from typing import Self, Union, TYPE_CHECKING
|
||||
|
||||
from dzgui.const.enum import NotebookPage, ServerTab
|
||||
from dzgui.util.strings import esc_to_return, question_to_return
|
||||
from dzgui.views.components.buttons import LoggerAlertsButton
|
||||
|
||||
import gi
|
||||
|
||||
@@ -32,13 +33,22 @@ class Statusbar(Gtk.Grid):
|
||||
self.attach(self.statusbar, 0, 0, 3, 1)
|
||||
self.attach_next_to(self.spinner, self.statusbar, Gtk.PositionType.RIGHT, 3, 1)
|
||||
|
||||
warnings, errors = self.controller.get_alerts()
|
||||
|
||||
if warnings + errors > 0:
|
||||
alert_button = LoggerAlertsButton(warnings, errors)
|
||||
self.attach_next_to(
|
||||
alert_button, self.spinner, Gtk.PositionType.RIGHT, 3, 1
|
||||
)
|
||||
alert_button.connect("clicked", self._on_alerts_clicked)
|
||||
|
||||
# TODO: pack version event box in right panel into hbox with update button
|
||||
# TODO: spawns a modal or just jumps right to install page
|
||||
#from dzgui.views.components.buttons import IconTextButton
|
||||
#b = IconTextButton("dialog-information-symbolic", label="Updates available")
|
||||
#b.set_halign(Gtk.Align.END)
|
||||
#b.set_hexpand(True)
|
||||
#self.attach_next_to(b, self.spinner, Gtk.PositionType.RIGHT, 3, 1)
|
||||
# from dzgui.views.components.buttons import IconTextButton
|
||||
# b = IconTextButton("dialog-information-symbolic", label="Updates available")
|
||||
# b.set_halign(Gtk.Align.END)
|
||||
# b.set_hexpand(True)
|
||||
# self.attach_next_to(b, self.spinner, Gtk.PositionType.RIGHT, 3, 1)
|
||||
|
||||
self.players = ""
|
||||
|
||||
@@ -52,6 +62,12 @@ class Statusbar(Gtk.Grid):
|
||||
self.emitter.connect("servers_loaded", self._on_servers_loaded)
|
||||
self.emitter.connect("mod_page_loaded", self._on_mod_page_loaded)
|
||||
|
||||
def _on_alerts_clicked(self, button: LoggerAlertsButton) -> None:
|
||||
button.hide()
|
||||
# FIXME: hitting ESC from here goes to help list instead of main menu
|
||||
# need some kind of flag
|
||||
self.controller.populate_log()
|
||||
|
||||
def _on_mod_page_loaded(self, emitter: "Emitter") -> None:
|
||||
msg = self.controller.format_mod_statusbar()
|
||||
self.set_by_context(NotebookPage.MODS, msg)
|
||||
@@ -80,13 +96,6 @@ class Statusbar(Gtk.Grid):
|
||||
match enum:
|
||||
case NotebookPage.HELP:
|
||||
bar = self.controller.get_help_row()
|
||||
# TODO: drop
|
||||
# case NotebookPage.MODS:
|
||||
# return
|
||||
# case NotebookPage.SERVERS:
|
||||
# context = self.controller.get_active_context()
|
||||
# # self.emitter.emit("servers_loaded", context)
|
||||
# return
|
||||
case NotebookPage.KEYS:
|
||||
bar = question_to_return
|
||||
case _:
|
||||
|
||||
Reference in new issue
Block a user