Impliment self replication/copy
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import re
|
||||
from typing import Any, Optional, cast, overload
|
||||
from typing import Any, Optional, Self, cast, overload
|
||||
import re
|
||||
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
|
||||
@@ -10,13 +10,19 @@ class Fragment:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
text: str,
|
||||
font: QFont,
|
||||
which: str|Self,
|
||||
font: QFont|None = None,
|
||||
audio: str = "",
|
||||
color: Optional[QColor] = None,
|
||||
asis: bool = False,
|
||||
) -> 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._audio: QUrl = QUrl(audio)
|
||||
self._align = QTextOption(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import copy
|
||||
from importlib.abc import InspectLoader
|
||||
from PyQt6.QtGui import QColor, QFont
|
||||
from trycast import trycast
|
||||
@@ -601,7 +600,7 @@ def parseText(frag: Fragment) -> list[Fragment]:
|
||||
results.append(frag)
|
||||
return results
|
||||
if start > 0:
|
||||
newFrag = copy.copy(frag)
|
||||
newFrag = Fragment(frag)
|
||||
newFrag.setText(text[:start])
|
||||
results.append(newFrag)
|
||||
frag.setText(text[start:])
|
||||
@@ -623,7 +622,7 @@ def parseText(frag: Fragment) -> list[Fragment]:
|
||||
end = text.find("}")
|
||||
token = text[1:end]
|
||||
frag.setText(text[end + 1 :])
|
||||
newFrag = copy.copy(frag)
|
||||
newFrag = Fragment(frag)
|
||||
oldFont = QFont(frag.font())
|
||||
if token == "bc":
|
||||
results.append(Fragment(": ", boldFont, color=baseColor))
|
||||
@@ -729,7 +728,7 @@ def parseText(frag: Fragment) -> list[Fragment]:
|
||||
wref = fields[1]
|
||||
else:
|
||||
raise NotImplementedError(f"Unknown code: {token} in {org}")
|
||||
newFrag = copy.copy(frag)
|
||||
newFrag = Fragment(frag)
|
||||
newFrag.setText(htext)
|
||||
newFrag.setWRef(wref)
|
||||
newFrag.setTarget(target)
|
||||
|
||||
Reference in New Issue
Block a user