def test_invalid_file(self): """Valid path but not an image fails to create the image or pixmaps""" img = simplequi.load_image(__file__) self.catch_finish(img, fail=False) self.assertIsNone(_IMAGE_CACHE[img]) self.assertIsNone(get_pixmap(img, (10, 10), (10, 10), (10, 10))) self.assertNotIn(_IMAGE_CACHE[img], _PIXMAP_CACHE)
def test_valid_image_and_pixmaps(self): img = simplequi.load_image(get_example_resource_path('sample_image.png')) self.catch_finish(img, fail=False, width=1000, height=1200) self.assertIsNotNone(_IMAGE_CACHE[img]) self.assertIsNotNone(get_pixmap(img, (10, 10), (10, 10), (10, 10))) small_unscaled = pixmap_data(img, 0, 0, 20, 20) small_scaled = pixmap_data(img, 0, 0, 20, 20, size=(30, 25)) full_scaled = pixmap_data(img, 0, 0, 1000, 1200, size=(50, 60)) middle = pixmap_data(img, 307, 293, 250, 302) self.assertNotEqual(small_unscaled, small_scaled) self.assertEqual(pixmap_to_bytes(get_pixmap(img, (10, 10), (20, 20), (20, 20))), small_unscaled) self.assertEqual(pixmap_to_bytes(get_pixmap(img, (10, 10), (20, 20), (30, 25))), small_scaled) self.assertEqual(pixmap_to_bytes(get_pixmap(img, (500, 600), (1000, 1200), (50, 60))), full_scaled) self.assertEqual(pixmap_to_bytes(get_pixmap(img, (432, 444), (250, 302), (250, 302))), middle)
# Mini-project #6 - Blackjack import simplequi as simplegui import random # load card sprite - 936x384 - source: jfitz.com CARD_SIZE = (72, 96) CARD_CENTER = (36, 48) card_images = simplegui.load_image( "http://storage.googleapis.com/codeskulptor-assets/cards_jfitz.png") CARD_BACK_SIZE = (72, 96) CARD_BACK_CENTER = (36, 48) card_back = simplegui.load_image( "http://storage.googleapis.com/codeskulptor-assets/card_jfitz_back.png") # initialize some useful global variables in_play = False outcome = "" score = 0 # define globals for cards SUITS = ('C', 'S', 'H', 'D') RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K') VALUES = { 'A': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7,
def test_invalid_path(self): """Non-existent path fails with a network error""" img = simplequi.load_image('not_a_file.png') self.catch_finish(img) self.assertEqual(self.error, QNetworkReply.ProtocolUnknownError)
# <*****@*****.**> # # This file is part of simplequi. # # simplequi is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # simplequi is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with simplequi. If not, see <https://www.gnu.org/licenses/>. # ----------------------------------------------------------------------------- """Draw a portion of an image in a frame""" import simplequi as simplegui def draw(canvas): canvas.draw_image(im, (500, 300), (1000, 600), (500, 300), (1000, 600)) im = simplegui.load_image('resources/sample_image.png') frame = simplegui.create_frame('Sample', 1000, 600) frame.set_draw_handler(draw) frame.start()