Browse Source

limit image size and increase app font size

master
Silberengel 2 weeks ago
parent
commit
afc00ef386
  1. 17
      src/imwald/app.py
  2. 6
      src/imwald/core/md_render.py
  3. 34
      src/imwald/ui/feed_page.py
  4. 7
      src/imwald/ui/markdown_editor_widget.py

17
src/imwald/app.py

@ -5,6 +5,7 @@ from __future__ import annotations @@ -5,6 +5,7 @@ from __future__ import annotations
import logging
import sys
from PySide6.QtGui import QFont
from PySide6.QtWidgets import QApplication
from imwald.config import db_path
@ -13,11 +14,27 @@ from imwald.core.nostr_engine import NostrEngine @@ -13,11 +14,27 @@ from imwald.core.nostr_engine import NostrEngine
from imwald.ui.main_window import MainWindow
def _set_comfortable_default_font(app: QApplication) -> None:
"""Slightly larger UI text than the platform default (lists, menus, dialogs, plain edits)."""
f = QFont(app.font())
ps = f.pointSize()
if ps > 0:
f.setPointSize(ps + 2)
else:
px = f.pixelSize()
if px > 0:
f.setPixelSize(max(int(round(px * 1.12)), 14))
else:
f.setPointSize(13)
app.setFont(f)
def main() -> None:
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
app = QApplication(sys.argv)
app.setApplicationName("imwald")
app.setOrganizationName("imwald")
_set_comfortable_default_font(app)
db = Database(db_path())
db.connect()

6
src/imwald/core/md_render.py

@ -120,13 +120,13 @@ def markdown_to_plain_text(md: str, *, max_source: int = 200_000) -> str: @@ -120,13 +120,13 @@ def markdown_to_plain_text(md: str, *, max_source: int = 200_000) -> str:
_PREVIEW_CSS = """<style>
body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-size:15px;margin:0;padding:12px;line-height:1.45;color:#1a1a1a;}
pre,code{font-family:ui-monospace,"Cascadia Code","Consolas",monospace;font-size:13px;}
body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-size:17px;margin:0;padding:12px;line-height:1.45;color:#1a1a1a;}
pre,code{font-family:ui-monospace,"Cascadia Code","Consolas",monospace;font-size:15px;}
pre{background:#f4f4f4;padding:10px;border-radius:6px;overflow-x:auto;}
blockquote{border-left:3px solid #bbb;margin:8px 0;padding:4px 0 4px 12px;color:#444;}
table{border-collapse:collapse;margin:8px 0;width:100%;}
th,td{border:1px solid #ccc;padding:6px;}
img{max-width:100%;height:auto;}
img{max-width:min(100%,400px);height:auto;}
</style>"""

34
src/imwald/ui/feed_page.py

@ -33,13 +33,13 @@ FEED_KINDS = (1, 20, 21, 30023, 9802, 11) @@ -33,13 +33,13 @@ FEED_KINDS = (1, 20, 21, 30023, 9802, 11)
_FEED_DOC_CSS = """
<style>
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px;
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 17px;
margin: 0; padding: 0; line-height: 1.5; color: #1e1b16; background: transparent; }
a { color: #2563eb; }
pre, code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
pre, code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 15px; }
pre { background: #f0ebe3; padding: 10px; border-radius: 8px; overflow-x: auto; }
blockquote { border-left: 3px solid #c4b8a8; margin: 8px 0; padding: 4px 0 4px 12px; color: #4a4236; }
.md img { max-width: 100%; height: auto; border-radius: 8px; margin: 6px 0; }
.md img { max-width: min(100%, 400px); height: auto; border-radius: 8px; margin: 6px 0; }
.md p { margin: 0.45em 0; }
</style>
"""
@ -76,9 +76,9 @@ def _format_engagement_html(stats: dict[str, Any]) -> str: @@ -76,9 +76,9 @@ def _format_engagement_html(stats: dict[str, Any]) -> str:
for em, c in rx[:18]:
e = html.escape(em if em != "+" else "", quote=False)
if c > 1:
emoji_bits.append(f'<span style="font-size:18px" title="{e}×{c}">{e}<sub style="font-size:11px">{c}</sub></span>')
emoji_bits.append(f'<span style="font-size:21px" title="{e}×{c}">{e}<sub style="font-size:13px">{c}</sub></span>')
else:
emoji_bits.append(f'<span style="font-size:18px">{e}</span>')
emoji_bits.append(f'<span style="font-size:21px">{e}</span>')
em_row = " &nbsp; ".join(emoji_bits) if emoji_bits else ""
head = " &nbsp;·&nbsp; ".join(parts) if parts else "no engagement in local DB yet"
if em_row:
@ -106,7 +106,7 @@ class FeedPage(QWidget): @@ -106,7 +106,7 @@ class FeedPage(QWidget):
}
QLabel#ThreadTitle { font-weight: 600; color: #3d3428; padding: 4px 2px; }
QPlainTextEdit#ReplyBody {
border: none; background: transparent; font-size: 14px; color: #2a241c;
border: none; background: transparent; font-size: 16px; color: #2a241c;
}
"""
)
@ -140,7 +140,7 @@ class FeedPage(QWidget): @@ -140,7 +140,7 @@ class FeedPage(QWidget):
op_card_lay.addWidget(self._op, stretch=1)
self._why = QLabel("")
self._why.setStyleSheet("color: #6b5f4f; font-size: 12px;")
self._why.setStyleSheet("color: #6b5f4f; font-size: 14px;")
self._why.setWordWrap(True)
self._thread_title = QLabel(
@ -297,13 +297,13 @@ class FeedPage(QWidget): @@ -297,13 +297,13 @@ class FeedPage(QWidget):
if pic_url
else '<span style="display:inline-block;width:52px;height:52px;border-radius:10px;background:#d9d0c3;margin-right:10px;vertical-align:middle"></span>'
)
nip_line = f"<div style='color:#6b5f4f;font-size:13px;margin-top:4px'>{nip05}</div>" if nip05 else ""
about_line = f"<div style='color:#5c5246;font-size:13px;margin-top:6px'>{about}</div>" if about else ""
nip_line = f"<div style='color:#6b5f4f;font-size:15px;margin-top:4px'>{nip05}</div>" if nip05 else ""
about_line = f"<div style='color:#5c5246;font-size:15px;margin-top:6px'>{about}</div>" if about else ""
tr = ""
sr = ev.get("source_relay") or ""
if sr and "nostrarchives.com" in sr:
tr = "<div style='color:#7a6b55;font-size:13px;margin:6px 0'><i>Trending slice (nostrarchives)</i></div>"
tr = "<div style='color:#7a6b55;font-size:15px;margin:6px 0'><i>Trending slice (nostrarchives)</i></div>"
eid = html.escape(ev["id"])
md_body = markdown_html_fragment(ev.get("content") or "")
@ -312,13 +312,13 @@ class FeedPage(QWidget): @@ -312,13 +312,13 @@ class FeedPage(QWidget):
f"{_FEED_DOC_CSS}</head><body>"
f"<div style='display:flex;align-items:flex-start;margin-bottom:12px'>"
f"{avatar_html}"
f"<div style='flex:1'><div style='font-size:18px;font-weight:600'>{disp}</div>"
f"<div style='color:#6b5f4f;font-size:13px'>{npub_e} · {pk_short}</div>"
f"<div style='flex:1'><div style='font-size:21px;font-weight:600'>{disp}</div>"
f"<div style='color:#6b5f4f;font-size:15px'>{npub_e} · {pk_short}</div>"
f"{nip_line}{about_line}</div></div>"
f"<div style='color:#7a6b55;font-size:13px;margin-bottom:8px'>Kind {int(ev['kind'])} · {int(ev['created_at'])}</div>"
f"<div style='color:#7a6b55;font-size:15px;margin-bottom:8px'>Kind {int(ev['kind'])} · {int(ev['created_at'])}</div>"
f"{tr}"
f"<div class=\"md\">{md_body}</div>"
f"<p style='color:#9a8b78;font-size:12px;margin-top:14px'>{eid}</p>"
f"<p style='color:#9a8b78;font-size:14px;margin-top:14px'>{eid}</p>"
"</body></html>"
)
self._op.setHtml(body)
@ -341,13 +341,13 @@ class FeedPage(QWidget): @@ -341,13 +341,13 @@ class FeedPage(QWidget):
vl.setContentsMargins(8, 6, 8, 8)
rk = int(r["kind"])
head = QLabel(
f"<span style='color:#8a7b6a;font-size:11px'>k{rk}</span> &nbsp; "
f"<b>{rname}</b> &nbsp; <span style='color:#7a6b55;font-size:12px'>{rnpub}</span>"
f"<span style='color:#8a7b6a;font-size:13px'>k{rk}</span> &nbsp; "
f"<b>{rname}</b> &nbsp; <span style='color:#7a6b55;font-size:14px'>{rnpub}</span>"
)
head.setTextFormat(Qt.TextFormat.RichText)
head.setWordWrap(True)
f_small = QFont()
f_small.setPointSize(11)
f_small.setPointSize(13)
head.setFont(f_small)
body_te = QPlainTextEdit()
body_te.setObjectName("ReplyBody")

7
src/imwald/ui/markdown_editor_widget.py

@ -4,7 +4,7 @@ from __future__ import annotations @@ -4,7 +4,7 @@ from __future__ import annotations
from PySide6.QtCore import Qt, QTimer
from PySide6.QtGui import QFont
from PySide6.QtWidgets import QPlainTextEdit, QSizePolicy, QSplitter, QTextBrowser, QVBoxLayout, QWidget
from PySide6.QtWidgets import QApplication, QPlainTextEdit, QSizePolicy, QSplitter, QTextBrowser, QVBoxLayout, QWidget
from imwald.core.md_render import markdown_html_document
@ -20,6 +20,11 @@ class MarkdownBodyEditor(QWidget): @@ -20,6 +20,11 @@ class MarkdownBodyEditor(QWidget):
mono = QFont("monospace")
if not mono.exactMatch():
mono = QFont("Courier New")
app = QApplication.instance()
if isinstance(app, QApplication):
ps = app.font().pointSize()
if ps > 0:
mono.setPointSize(ps)
self._source.setFont(mono)
self._source.setMinimumHeight(260)
self._source.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)

Loading…
Cancel
Save