Skip to content

Commit 220acfc

Browse files
committed
added english name for foreign cards
1 parent b42f433 commit 220acfc

4 files changed

Lines changed: 40 additions & 24 deletions

File tree

‎mtgorg/mtgorg_app.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def on_log(record: logging.LogRecord) -> bool:
7575
self.keyruneFontId = QtGui.QFontDatabase.addApplicationFont(KEYRUNE_FONT_PATH.as_posix()) # Set font
7676
PROXYGLYPH_FONT_PATH = constants.DEFAULT_FONTS_LOCATION / "Proxyglyph.ttf"
7777
self.proxyglyphFontId = QtGui.QFontDatabase.addApplicationFont(PROXYGLYPH_FONT_PATH.as_posix()) # better NDPMTG
78-
# from scryfall website
79-
PHYREXIAN_FONT_PATH = Path("resources/fonts/Phyrexian-Regular.woff2")
78+
# from scryfall website (TTF converted from woff2 — DirectWrite on Windows cannot load woff2)
79+
PHYREXIAN_FONT_PATH = Path("resources/fonts/Phyrexian-Regular.ttf")
8080
self.phyrexianFontId = QtGui.QFontDatabase.addApplicationFont(PHYREXIAN_FONT_PATH.as_posix()) # Phyrexian cards
8181

8282
# Load frontend

‎mtgorg/widgets/cardviewer.py‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from PySide6 import QtWidgets, QtGui, QtCore, QtNetwork, QtSvgWidgets
22
import logging
33
import urllib
4+
import urllib.request
45
import os
56

67
from lib import scryfall, utils, qt
@@ -135,11 +136,17 @@ def setupUi(self):
135136

136137
# Card Img
137138
self.cardImgGraphicsView = qt.ResizingGraphicsView()
138-
self.cardImgGraphicsView.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform)
139+
self.cardImgGraphicsView.setRenderHints(QtGui.QPainter.RenderHint.Antialiasing | QtGui.QPainter.RenderHint.SmoothPixmapTransform)
139140
self.mainLayout.addWidget(self.cardImgGraphicsView, line.postinc(), 0, 1, 2)
140141
self.reloadCardShortcut = QtGui.QShortcut(QtGui.QKeySequence('Ctrl+R'), self)
141142
self.reloadCardShortcut.activated.connect(self.on_reloadCardData)
142143

144+
# English name (shown for non-English cards)
145+
self.englishNameLabel = QtWidgets.QLabel()
146+
self.englishNameLabel.setStyleSheet("font-style: italic; color: gray;")
147+
self.englishNameLabel.setVisible(False)
148+
self.mainLayout.addWidget(self.englishNameLabel, line.postinc(), 0, 1, 2)
149+
143150
# Oracle text
144151
self.cardOracleTextLabel = QtWidgets.QTextEdit()
145152
self.cardOracleTextLabel.setReadOnly(True)
@@ -148,7 +155,7 @@ def setupUi(self):
148155

149156
# Card Link
150157
self.scryfallUriLabel = QtWidgets.QLabel("uri")
151-
self.scryfallUriLabel.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
158+
self.scryfallUriLabel.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.TextBrowserInteraction)
152159
self.scryfallUriLabel.setOpenExternalLinks(True)
153160
# self.scryfallUriLabel.linkActivated.connect(self.on_scryfallLinkClicked)
154161
self.mainLayout.addWidget(self.scryfallUriLabel, line.val(), 0)
@@ -176,7 +183,8 @@ def on_add(self):
176183
qt.findAttrInParents(self, "decklist").cardsList.addCard(self.card)
177184

178185
def on_scryfallLinkClicked(self):
179-
QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.uri))
186+
if hasattr(self, 'card'):
187+
QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.card.get('scryfall_uri', '')))
180188

181189
def on_randomCardPBClicked(self):
182190
self._random_thread = QtCore.QThread()
@@ -206,7 +214,7 @@ def displayPixmapCard(self, image):
206214
self.cardImgGraphicsView.scene().clear()
207215
self.cardImgGraphicsView.scene().addPixmap(self.cardImgPixMap)
208216
bounds = self.cardImgGraphicsView.scene().itemsBoundingRect()
209-
self.cardImgGraphicsView.fitInView(bounds, QtCore.Qt.KeepAspectRatio)
217+
self.cardImgGraphicsView.fitInView(bounds, QtCore.Qt.AspectRatioMode.KeepAspectRatio)
210218

211219
def setManaFont(self):
212220
if self.manacostLabel.font().family() != "Proxyglyph":
@@ -215,12 +223,14 @@ def setManaFont(self):
215223
font.setPointSize(24)
216224
self.manacostLabel.setFont(font)
217225

218-
def colorSetIcon(self, data: QtCore.QByteArray, rarity: str = "C"):
226+
def colorSetIcon(self, data: str | None, rarity: str = "C") -> str | None:
227+
color: str
219228
if rarity in constants.RARITIES.keys():
220229
try:
221230
color = constants.RARITIES[rarity]["color"]
222231
except TypeError:
223-
logging.warning()
232+
logging.warning(f"could not find color for {rarity=}")
233+
color = "#00F"
224234
else:
225235
logging.warning(f"could not find color for {rarity=}")
226236
color = "#00F"
@@ -273,6 +283,12 @@ def _on_display_data_ready(self, data: dict):
273283
self.nameLabel.setFont(QtGui.QFont())
274284
self.nameLabel.setStyleSheet("font-size: 16pt;")
275285

286+
if self.card["lang"] != "en" and "printed_name" in self.card:
287+
self.englishNameLabel.setText(self.card["name"])
288+
self.englishNameLabel.setVisible(True)
289+
else:
290+
self.englishNameLabel.setVisible(False)
291+
276292
if "card_faces" in self.card.keys():
277293
manaCost = self.card["card_faces"][0]["mana_cost"]
278294
else:
@@ -283,8 +299,8 @@ def _on_display_data_ready(self, data: dict):
283299

284300
setIconSvgData = self.colorSetIcon(setIconSvgData, self.card["rarity"])
285301
if setIconSvgData is not None:
286-
self.setIconSvg.load(QtCore.QByteArray(setIconSvgData))
287-
self.setIconSvg.renderer().setAspectRatioMode(QtCore.Qt.KeepAspectRatio)
302+
self.setIconSvg.load(QtCore.QByteArray(setIconSvgData.encode("utf-8")))
303+
self.setIconSvg.renderer().setAspectRatioMode(QtCore.Qt.AspectRatioMode.KeepAspectRatio)
288304

289305
try:
290306
self.setSelect.currentIndexChanged.disconnect()
@@ -413,7 +429,7 @@ def start_download(self, url, cardId):
413429
self.manager.get(QtNetwork.QNetworkRequest(url))
414430

415431
def handle_finished(self, reply):
416-
if reply.error() != QtNetwork.QNetworkReply.NoError:
432+
if reply.error() != QtNetwork.QNetworkReply.NetworkError.NoError:
417433
print("error: ", reply.errorString())
418434
return
419435
image = QtGui.QImage()
@@ -435,5 +451,5 @@ def getCardImageFromUrl(url, cardId) -> str:
435451

436452
def saveCardImg(image: QtGui.QImage, cardId: str):
437453
path = constants.DEFAULT_CARDIMAGES_LOCATION / cardId
438-
writer = QtGui.QImageWriter(path.as_posix(), format=QtCore.QByteArray("jpg"))
454+
writer = QtGui.QImageWriter(path.as_posix(), b"jpg")
439455
writer.write(image)

‎mtgorg/widgets/dbbrowser.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ def initUi(self):
1818
self.mainLayout = QtWidgets.QHBoxLayout()
1919
self.setLayout(self.mainLayout)
2020

21-
self.splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal, self)
21+
self.splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Horizontal, self)
2222
self.mainLayout.addWidget(self.splitter)
2323

2424
self.searchForm = SearchForm(parent=self)
2525
# self.searchForm.setMaximumWidth(300)
2626
self.searchForm.setMinimumWidth(300)
27-
self.searchForm.find.connect(self.on_searchRequest)
27+
self.searchForm.searched.connect(self.on_searchRequest)
2828
self.qscroll = QtWidgets.QScrollArea()
2929
self.qscroll.setWidgetResizable(True)
30-
self.qscroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
30+
self.qscroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
3131
self.qscroll.setWidget(self.searchForm)
3232
self.splitter.addWidget(self.qscroll)
3333
# QListWidget on the right for results
@@ -44,17 +44,17 @@ def on_searchRequest(self, searchDict: dict):
4444
def on_dbSelectChanged(self):
4545
if len(self.dbResultsList.selectedItems()) == 1:
4646
selectedItem = self.dbResultsList.selectedItems()[0]
47-
self.cardSelected.emit(selectedItem.data(QtCore.Qt.UserRole)["data"]["id"])
47+
self.cardSelected.emit(selectedItem.data(QtCore.Qt.ItemDataRole.UserRole)["data"]["id"])
4848
else:
4949
selectedItem = None
5050

5151

5252
class SearchForm(QtWidgets.QWidget):
5353

54-
find: QtCore.Signal = QtCore.Signal(dict) # ? replace with search dict object ?
54+
searched: QtCore.Signal = QtCore.Signal(dict) # ? replace with search dict object ?
5555

5656
# To Build
57-
def __init__(self, parent: QtWidgets.QWidget = None) -> None:
57+
def __init__(self, parent: QtWidgets.QWidget | None = None) -> None:
5858
super().__init__(parent)
5959

6060
self.mainLayout = QtWidgets.QFormLayout()
@@ -207,7 +207,7 @@ def __init__(self, parent: QtWidgets.QWidget = None) -> None:
207207
self.on_mainTypeChange()
208208

209209
def on_searchAction(self):
210-
self.find.emit(self.getSearchData())
210+
self.searched.emit(self.getSearchData())
211211

212212
def on_mainTypeChange(self):
213213
# TODO setRowVisible() only available on lates pyside6 versions
@@ -281,7 +281,7 @@ def getSearchData(self):
281281

282282

283283
class ManaColorSelectorWidget(QtWidgets.QWidget):
284-
def __init__(self, parent: QtWidgets.QWidget = None) -> None:
284+
def __init__(self, parent: QtWidgets.QWidget | None = None) -> None:
285285
super().__init__(parent)
286286
self.mainLayout = QtWidgets.QHBoxLayout()
287287
self.setLayout(self.mainLayout)
@@ -330,7 +330,7 @@ class ManaColorWidget(QtWidgets.QWidget):
330330
"G": "P",
331331
}
332332

333-
def __init__(self, color: str, parent: QtWidgets.QWidget = None) -> None:
333+
def __init__(self, color: str, parent: QtWidgets.QWidget | None = None) -> None:
334334
super().__init__(parent)
335335
self.color = color
336336
self.mainLayout = QtWidgets.QHBoxLayout()
@@ -339,9 +339,9 @@ def __init__(self, color: str, parent: QtWidgets.QWidget = None) -> None:
339339
self.state = self.STATES[0]
340340
self.manaSymbolLabel = QtWidgets.QLabel("")
341341
self.mainLayout.addWidget(self.manaSymbolLabel)
342-
self.font = QtGui.QFont(QtGui.QFontDatabase.applicationFontFamilies(
342+
self._labelFont = QtGui.QFont(QtGui.QFontDatabase.applicationFontFamilies(
343343
qt.findAttrInParents(self, "proxyglyphFontId")))
344-
self.font.setPointSize(16)
344+
self._labelFont.setPointSize(16)
345345
self.mainLayout.setContentsMargins(0, 0, 0, 0)
346346
self.draw()
347347

@@ -352,7 +352,7 @@ def draw(self):
352352
else: # May is half symbol NOT USED
353353
text = self.HALF_MANA_EQU[self.color]
354354
self.manaSymbolLabel.setText(text)
355-
self.manaSymbolLabel.setFont(self.font)
355+
self.manaSymbolLabel.setFont(self._labelFont)
356356

357357
if self.state in ["NS"]:
358358
self.manaSymbolLabel.setStyleSheet(
12.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)