v0.6.0 BigUpdate
Example document / build (push) Has been cancelled
Python application / build (push) Has been cancelled

This commit is contained in:
Igor20264
2026-10-20 11:38:06 +03:00
parent daa84f8bce
commit 8223e0ac14
77 changed files with 12158 additions and 117 deletions
+79 -16
View File
@@ -189,6 +189,65 @@ def _tip(widget, text: str) -> None:
_Tooltip(widget, text)
def import_output_path(docx_path: str) -> str:
"""Markdown path written by DOCX → MD for this document."""
return os.path.splitext(os.path.abspath(docx_path))[0] + ".md"
def _same_path(left: str, right: str) -> bool:
return os.path.normcase(os.path.abspath(left)) == os.path.normcase(os.path.abspath(right))
def output_tracks_source(source: str, current: str) -> bool:
"""True when the output field is still the automatic path for this source.
Markdown sources track ``name.docx``. DOCX sources (import) track ``name.md``.
``default_output_path`` always appends ``.docx``, so it must not be used to
decide whether an import path is still automatic.
"""
if not source:
return False
current = (current or "").strip()
if not current:
return True
if source.lower().endswith(".docx"):
auto = import_output_path(source)
else:
auto = default_output_path(source)
return _same_path(current, auto)
def next_markdown_output(source_md: str, current: str, auto: bool) -> tuple[str, bool]:
"""DOCX output after the user picks a markdown source.
A non-``.docx`` path is leftover from DOCX → MD and is not a chosen
conversion target, even if the auto-output flag was cleared.
"""
current = (current or "").strip()
if auto or not current.lower().endswith(".docx"):
return default_output_path(source_md), True
return current, auto
def next_import_output(docx_path: str, current: str, auto: bool) -> tuple[str, bool]:
"""Markdown output after the user picks a DOCX to import.
A ``.docx`` path is the previous MD → DOCX target and must not be reused.
"""
current = (current or "").strip()
if auto or not current.lower().endswith(".md"):
return import_output_path(docx_path), True
return current, auto
def coerce_docx_output(source_md: str, current: str) -> str:
"""Output path for an MD → DOCX run. Non-docx paths fall back to the default."""
current = (current or "").strip()
if current.lower().endswith(".docx"):
return current
return default_output_path(source_md) if source_md else current
class Md2GostApp:
def __init__(self, initial: ConvertRequest | None = None):
self.req = initial or ConvertRequest()
@@ -1693,18 +1752,21 @@ class Md2GostApp:
def _on_output_edited(self, *_args) -> None:
if not self._last_md:
return
current = self.output_var.get().strip()
auto = default_output_path(self._last_md)
self._auto_output = (not current) or os.path.normcase(os.path.abspath(current)) == os.path.normcase(auto)
self._auto_output = output_tracks_source(self._last_md, self.output_var.get())
def _apply_output(self, path: str, auto: bool) -> None:
if path != self.output_var.get().strip():
self.output_var.set(path)
self._auto_output = auto
def _set_markdown(self, path: str, from_user_output: bool = False) -> None:
path = os.path.abspath(path)
self._last_md = path
self.zone_label.configure(text=os.path.basename(path))
self.zone_path.configure(text=path)
if not from_user_output and self._auto_output:
self.output_var.set(default_output_path(path))
self._auto_output = True
if not from_user_output:
output, auto = next_markdown_output(path, self.output_var.get(), self._auto_output)
self._apply_output(output, auto)
self._append_log(f"Файл: {path}")
def _set_docx(self, path: str) -> None:
@@ -1712,10 +1774,8 @@ class Md2GostApp:
self._last_md = path
self.zone_label.configure(text=os.path.basename(path))
self.zone_path.configure(text=path)
if self._auto_output:
stem = os.path.splitext(path)[0]
self.output_var.set(stem + ".md")
self._auto_output = True
output, auto = next_import_output(path, self.output_var.get(), self._auto_output)
self._apply_output(output, auto)
self._append_log(f"DOCX для импорта: {path}")
def _import_docx(self) -> None:
@@ -1847,10 +1907,10 @@ class Md2GostApp:
return
if is_docx:
target = (req.output or "").strip()
if target.lower().endswith(".docx"):
target = os.path.splitext(req.filename)[0] + ".md"
if not target.lower().endswith(".md"):
target = import_output_path(req.filename)
req.output = target
self.output_var.set(target)
self._apply_output(target, True)
if target and os.path.isfile(target):
if not messagebox.askyesno(
"md2gost", f"Файл уже есть:\n{target}\n\nПерезаписать?"
@@ -1862,9 +1922,12 @@ class Md2GostApp:
self.output_var.set(target)
self._append_log("Импорт DOCX → Markdown…")
elif not req.check_only:
target = (req.output or "").strip() or (
default_output_path(req.filename) if req.filename else ""
)
raw = (req.output or "").strip()
target = coerce_docx_output(req.filename, raw)
if raw and not raw.lower().endswith(".docx"):
self._append_log(f"После импорта выход был не .docx, для сборки беру {target}")
req.output = target
self._apply_output(target, True)
if target and os.path.isfile(target):
if not messagebox.askyesno(
"md2gost", f"Файл уже есть:\n{target}\n\nПерезаписать?"