mirror of
https://github.com/aclist/dztui.git
synced 2026-10-31 23:22:44 +01:00
Merge branch 'feat/error-details' of github.com:aclist/dztui into feat/error-details
This commit is contained in:
commit
c037cf9c40
2 files changed
+52
-18
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from importlib import resources
|
from importlib import resources
|
||||||
@@ -31,20 +32,40 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
|
|||||||
logger.critical(e)
|
logger.critical(e)
|
||||||
changelog = missing_changelog
|
changelog = missing_changelog
|
||||||
|
|
||||||
# TODO: should long text be wrapped?
|
# FIXME: wrap long text
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.box = Gtk.Box(
|
self.box = Gtk.Box(
|
||||||
orientation=Gtk.Orientation.VERTICAL, spacing=5, margin_top=10
|
orientation=Gtk.Orientation.VERTICAL, spacing=5, margin_top=10
|
||||||
)
|
)
|
||||||
self.add(self.box)
|
self.add(self.box)
|
||||||
|
|
||||||
|
expand_all = Gtk.Button(
|
||||||
|
label="Expand all", halign=Gtk.Align.START, margin_start=20
|
||||||
|
)
|
||||||
|
expand_all.connect("clicked", self._on_expand_all_clicked)
|
||||||
|
self.box.add(expand_all)
|
||||||
|
|
||||||
|
self.expanded = False
|
||||||
|
self.expanders: list[Gtk.Expander] = []
|
||||||
self.connect("key-press-event", self._on_keypress)
|
self.connect("key-press-event", self._on_keypress)
|
||||||
self.connect("key-press-event", self._on_esc_keypress)
|
self.connect("key-press-event", self._on_esc_keypress)
|
||||||
|
|
||||||
changes = self._parse(changelog)
|
changes = self._parse(changelog)
|
||||||
self._generate_nodes(changes)
|
self._generate_nodes(changes)
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
def _on_expand_all_clicked(self, button: Gtk.Button) -> None:
|
||||||
|
self.expanded = not self.expanded
|
||||||
|
for expander in self.expanders:
|
||||||
|
# NOTE: simply setting set_expanded() does not trigger activate() signal,
|
||||||
|
# so margins are not applied
|
||||||
|
if expander.get_expanded() == self.expanded:
|
||||||
|
continue
|
||||||
|
expander.activate()
|
||||||
|
label = "Collapse all" if self.expanded else "Expand all"
|
||||||
|
button.set_label(label)
|
||||||
|
|
||||||
def grab_content_area(self) -> None:
|
def grab_content_area(self) -> None:
|
||||||
self.grab_focus()
|
self.grab_focus()
|
||||||
|
|
||||||
@@ -65,9 +86,7 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
|
|||||||
text = "\n".join(changes)
|
text = "\n".join(changes)
|
||||||
formatted = format_pango(text)
|
formatted = format_pango(text)
|
||||||
|
|
||||||
container = Gtk.Box(
|
container = Gtk.Box(valign=Gtk.Align.START, halign=Gtk.Align.START)
|
||||||
valign=Gtk.Align.START, halign=Gtk.Align.START
|
|
||||||
)
|
|
||||||
label = Gtk.Label()
|
label = Gtk.Label()
|
||||||
label.set_markup(formatted)
|
label.set_markup(formatted)
|
||||||
container.add(label)
|
container.add(label)
|
||||||
@@ -81,6 +100,7 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
|
|||||||
expander.add(container)
|
expander.add(container)
|
||||||
expander.connect("activate", self._on_expand, container)
|
expander.connect("activate", self._on_expand, container)
|
||||||
self.box.add(expander)
|
self.box.add(expander)
|
||||||
|
self.expanders.append(expander)
|
||||||
|
|
||||||
def _on_expand(self, expander: Gtk.Box, container: Gtk.Box) -> None:
|
def _on_expand(self, expander: Gtk.Box, container: Gtk.Box) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -94,6 +114,7 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
|
|||||||
container.set_margin_bottom(15)
|
container.set_margin_bottom(15)
|
||||||
|
|
||||||
def _parse(self, changelog: str) -> list[tuple[str, list[str]]]:
|
def _parse(self, changelog: str) -> list[tuple[str, list[str]]]:
|
||||||
|
|
||||||
release = ""
|
release = ""
|
||||||
releases: list[tuple[str, list[str]]] = []
|
releases: list[tuple[str, list[str]]] = []
|
||||||
release_notes: list[str] = []
|
release_notes: list[str] = []
|
||||||
@@ -107,5 +128,5 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
|
|||||||
release = ""
|
release = ""
|
||||||
release = line
|
release = line
|
||||||
continue
|
continue
|
||||||
release_notes.append(line.rstrip())
|
release_notes.append(textwrap.fill(line.rstrip(), width=120))
|
||||||
return releases
|
return releases
|
||||||
+26
-13
@@ -1,20 +1,33 @@
|
|||||||
|
import re
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from importlib import resources
|
from pathlib import Path
|
||||||
from dzgui.const.constants import APP_NAME_LOWER, CHANGELOG_PATH
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def changelog():
|
def changelog(request) -> None:
|
||||||
path = resources.files(APP_NAME_LOWER).joinpath(CHANGELOG_PATH)
|
root = request.config.rootpath
|
||||||
return path
|
changelog = Path(root).joinpath("CHANGELOG.md").read_text()
|
||||||
|
return changelog
|
||||||
|
|
||||||
|
|
||||||
def test_headings(changelog):
|
def count_hash(line: str) -> int:
|
||||||
with open(changelog, "r") as f:
|
cnt = 0
|
||||||
lines = f.readlines()
|
for c in line:
|
||||||
for line in lines:
|
if c == "#":
|
||||||
if line.startswith("#"):
|
cnt += 1
|
||||||
pass
|
return cnt
|
||||||
# TODO: use regex
|
|
||||||
pass
|
|
||||||
|
def test_changelog_prefix(changelog) -> None:
|
||||||
|
r = r".*(\[.*\]).*"
|
||||||
|
lines = changelog.splitlines()
|
||||||
|
sort = sorted(lines)
|
||||||
|
match = [line for line in sort if line.startswith("#")]
|
||||||
|
for m in match:
|
||||||
|
if "Changelog" in m:
|
||||||
|
assert count_hash(m) == 1
|
||||||
|
elif re.match(r, m) is not None:
|
||||||
|
assert count_hash(m) == 2
|
||||||
|
else:
|
||||||
|
assert count_hash(m) == 3
|
||||||
Reference in new issue
Block a user