diff --git a/kcardgame/binding-example/main.py b/kcardgame/binding-example/main.py index a45bfa29..401e0d77 100644 --- a/kcardgame/binding-example/main.py +++ b/kcardgame/binding-example/main.py @@ -1,7 +1,8 @@ -from Shiboken2QtExample import * +from Shiboken2QtExample import QObjectWithEnum a = QObjectWithEnum() a.someSignal.connect(lambda x: print("Signal emitted: %s" % x)) a.aSlot() -print("int(QObjectWithEnum.MyEnum.Values) =", int(QObjectWithEnum.MyEnum.Values)) +print("int(QObjectWithEnum.MyEnum.Values) =", + int(QObjectWithEnum.MyEnum.Values)) a.nonSlotFunction(QObjectWithEnum.MyEnum.Some) diff --git a/pysollib/images.py b/pysollib/images.py index 996b3fcf..287e122d 100644 --- a/pysollib/images.py +++ b/pysollib/images.py @@ -82,13 +82,15 @@ class Images: def __loadCard(self, filename, check_w=1, check_h=1, rec=None): # print '__loadCard:', filename f = os.path.join(self.cs.dir, filename) + img = None if rec and 'suit' in rec: # img = PIL_Image(image=self.svg.render_fragment("6_heart")) img = self.svg.render_fragment( rank=rec['rank'], suit=rec['suit'], width=self.CARDW, height=self.CARDH) - img = PIL_Image(image=img) - else: + if img: + img = PIL_Image(image=img) + if not img: if not os.path.exists(f): print('card image path %s does not exist' % (f)) return None diff --git a/pysollib/ui/tktile/svg.py b/pysollib/ui/tktile/svg.py index 24b0f5d2..62bb6ec6 100644 --- a/pysollib/ui/tktile/svg.py +++ b/pysollib/ui/tktile/svg.py @@ -5,18 +5,18 @@ # https://stackoverflow.com/questions/22583035 # Thanks! -from PySide2.QtGui import QPixmap # noqa: F401 - -from Shiboken2QtExample import MyKCardDeck +try: + from PySide2.QtGui import QPixmap # noqa: F401 + from Shiboken2QtExample import MyKCardDeck +except BaseException: + def MyKCardDeck(): + return None import cairo # from gi import require_version # require_version('Rsvg', '2.0') # from gi.repository import Rsvg # noqa: E402 -import pysnooper # noqa: E402 - - from pysollib.mfxutil import Image # noqa: E402 @@ -29,7 +29,6 @@ class SVGManager: # Taken from https://stackoverflow.com/questions/44471795 # Under MIT License - thanks. - @pysnooper.snoop() def pixbuf2image(self, pxb): """ Convert GdkPixbuf.Pixbuf to PIL image """ data = pxb.get_pixels() @@ -43,6 +42,8 @@ class SVGManager: return img def render_fragment(self, rank, suit, width, height): + if not self.d: + return None image = Image.fromqpixmap( self.d.get_card_pixmap( rank + 1 + {'c': 0, 'd': 1, 'h': 2, 's': 3}[suit]*0x100))