11from PySide6 import QtWidgets , QtGui , QtCore , QtNetwork , QtSvgWidgets
22import logging
33import urllib
4+ import urllib .request
45import os
56
67from 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
436452def 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 )
0 commit comments