Impliment self replication/copy
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
from typing import Any, Optional, cast, overload
|
from typing import Any, Optional, Self, cast, overload
|
||||||
import re
|
import re
|
||||||
from PyQt6.QtCore import QMargins, QPoint, QRect, QSize, QUrl, Qt, pyqtSignal
|
from PyQt6.QtCore import QMargins, QPoint, QRect, QSize, QUrl, Qt, pyqtSignal
|
||||||
from PyQt6.QtGui import QColor, QFont, QFontMetrics, QMouseEvent, QPaintEvent, QPainter, QResizeEvent, QTextOption, QTransform, QBrush
|
from PyQt6.QtGui import QColor, QFont, QFontMetrics, QMouseEvent, QPaintEvent, QPainter, QResizeEvent, QTextOption, QTransform, QBrush
|
||||||
@@ -10,13 +10,19 @@ class Fragment:
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
text: str,
|
which: str|Self,
|
||||||
font: QFont,
|
font: QFont|None = None,
|
||||||
audio: str = "",
|
audio: str = "",
|
||||||
color: Optional[QColor] = None,
|
color: Optional[QColor] = None,
|
||||||
asis: bool = False,
|
asis: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._text = text
|
if isinstance(which, Fragment):
|
||||||
|
for k,v in which.__dict__.items():
|
||||||
|
self.__dict__[k] = v
|
||||||
|
return
|
||||||
|
self._text:str = which
|
||||||
|
if font is None:
|
||||||
|
raise TypeError("Missing required parameter 'font'")
|
||||||
self._font = font
|
self._font = font
|
||||||
self._audio: QUrl = QUrl(audio)
|
self._audio: QUrl = QUrl(audio)
|
||||||
self._align = QTextOption(
|
self._align = QTextOption(
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import copy
|
|
||||||
from importlib.abc import InspectLoader
|
from importlib.abc import InspectLoader
|
||||||
from PyQt6.QtGui import QColor, QFont
|
from PyQt6.QtGui import QColor, QFont
|
||||||
from trycast import trycast
|
from trycast import trycast
|
||||||
@@ -601,7 +600,7 @@ def parseText(frag: Fragment) -> list[Fragment]:
|
|||||||
results.append(frag)
|
results.append(frag)
|
||||||
return results
|
return results
|
||||||
if start > 0:
|
if start > 0:
|
||||||
newFrag = copy.copy(frag)
|
newFrag = Fragment(frag)
|
||||||
newFrag.setText(text[:start])
|
newFrag.setText(text[:start])
|
||||||
results.append(newFrag)
|
results.append(newFrag)
|
||||||
frag.setText(text[start:])
|
frag.setText(text[start:])
|
||||||
@@ -623,7 +622,7 @@ def parseText(frag: Fragment) -> list[Fragment]:
|
|||||||
end = text.find("}")
|
end = text.find("}")
|
||||||
token = text[1:end]
|
token = text[1:end]
|
||||||
frag.setText(text[end + 1 :])
|
frag.setText(text[end + 1 :])
|
||||||
newFrag = copy.copy(frag)
|
newFrag = Fragment(frag)
|
||||||
oldFont = QFont(frag.font())
|
oldFont = QFont(frag.font())
|
||||||
if token == "bc":
|
if token == "bc":
|
||||||
results.append(Fragment(": ", boldFont, color=baseColor))
|
results.append(Fragment(": ", boldFont, color=baseColor))
|
||||||
@@ -729,7 +728,7 @@ def parseText(frag: Fragment) -> list[Fragment]:
|
|||||||
wref = fields[1]
|
wref = fields[1]
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"Unknown code: {token} in {org}")
|
raise NotImplementedError(f"Unknown code: {token} in {org}")
|
||||||
newFrag = copy.copy(frag)
|
newFrag = Fragment(frag)
|
||||||
newFrag.setText(htext)
|
newFrag.setText(htext)
|
||||||
newFrag.setWRef(wref)
|
newFrag.setWRef(wref)
|
||||||
newFrag.setTarget(target)
|
newFrag.setTarget(target)
|
||||||
|
|||||||
Reference in New Issue
Block a user