def check_winner(self): if self._score1 == 21: if self._game1 == 1: self._state = 4 # Player 1 wins match self._player1.game_played() self._player1.game_won() self._winner = self._player1 self._player2.game_played() u.set_background(self._screen, "assets/backgrounds/match_menu.png") else: self._state = 2 # Player 1 wins game self._game1 += 1 self.on_reset_score() m.clear_screen() if self._score2 == 21: if self._game2 == 1: self._state = 5 # Player 2 wins match self._player1.game_played() self._player2.game_played() self._player2.game_won() self._winner = self._player2 m.clear_screen() else: self._state = 3 # Player 1 wins game self._game2 += 1 self.on_reset_score() m.clear_screen()
def _item_activated(self, iconview, path, group_index): # liststore = iconview.get_model() # print(liststore[path][1]) wallpaper_index = path[0] # print(self.wallpaper_paths[group_index][wallpaper_index]) set_background( self.wallpaper_paths[group_index][wallpaper_index]) # working!
def main(): logger.info("Updating...") latest_timestamp = get_latest_timestamp(JSON_URL) logger.info("Latest version: {} GMT" .format(strftime(DATE_FMT_ISO, latest_timestamp))) time_as_url = strftime(DATE_FMT_URL, latest_timestamp) with create_png() as image: build_png(image, time_as_url) set_background() logger.info("Done!")
def main(): logger.info("Updating...") latest_timestamp = get_latest_timestamp(JSON_URL) logger.info("Latest version: {} GMT".format( strftime(DATE_FMT_ISO, latest_timestamp))) time_as_url = strftime(DATE_FMT_URL, latest_timestamp) with create_png() as image: build_png(image, time_as_url) set_background() logger.info("Done!")
def run(self): ''' main function ''' ''' get background picture from momentumdash.com ''' print("Updating infinity new tab image...") success = 0 #ljx print("download...") while success == 0: index = random.randint(1000, 20000) filename = "/home/ljx/Pictures/infinity/" + str(index) + ".jpg" self.get_bg_picture(index) r = os.system("cat " + filename + " |grep error") if r != 0: success = 1 break print("failed,again...") os.system("rm " + filename) #xjl print("\nSaving to '%s'..." % (filename)) ''' set background picture as wallpaper ''' ''' scaled, wallpaper, stretched, spanned ''' if not set_background(filename, "stretched"): exit("Your desktop environment '{}' is not supported.".format( get_desktop_environment())) print("Done!")
def main(): ''' main function ''' global counter ''' check if setting data is correct or not ''' if auto_offset and hour_offset: exit( "You can not set `auto_offset` to True and `hour_offset` to a value that is different than zero." ) elif hour_offset < 0: exit( "`hour_offset` must be greater than or equal to zero. I can't get future images of Earth for now." ) ''' start to download picture ''' print("Updating...") ''' get latest updating time ''' url = 'http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json' latest_json = urllib2.urlopen(url) latest = strptime( loads(latest_json.read().decode("utf-8"))["date"], "%Y-%m-%d %H:%M:%S") print("Latest version: {} GMT".format(strftime("%Y/%m/%d %H:%M:%S", latest))) if auto_offset or hour_offset > 0: requested_time = get_time_offset(latest) print("Offset version: {} GMT".format( strftime("%Y/%m/%d %H:%M:%S", requested_time))) else: requested_time = latest print ''' use Python Imaging Library (PIL) to generate png ''' png = Image.new('RGB', (width * level, height * level)) counter = multiprocessing.Value("i", 0) p = multiprocessing.Pool(multiprocessing.cpu_count() * level) print("Downloading tiles: 0/%s completed" % (level * level)) res = p.map(download_chunk, product(range(level), range(level), (requested_time, ))) for (x, y, tiledata) in res: tile = Image.open(BytesIO(tiledata)) png.paste(tile, (width * x, height * y, width * (x + 1), height * (y + 1))) print("\nSaving to '%s'..." % (output_file)) if not os.path.exists(os.path.dirname(output_file)): os.makedirs(os.path.dirname(output_file)) png.save(output_file, "PNG") if not set_background(output_file): exit("Your desktop environment '{}' is not supported.".format( get_desktop_environment())) print("Done!")
def run(self): ''' main function ''' ''' get background picture from momentumdash.com ''' print("Updating momentumdash image...") self.get_bg_picture() print("\nSaving to '%s'..." % (momentumdash_output_file)) ''' set background picture as wallpaper ''' ''' scaled, wallpaper, stretched, spanned ''' if not set_background(momentumdash_output_file, "stretched"): exit("Your desktop environment '{}' is not supported.".format( get_desktop_environment())) print("Done!")
def thread_main(args): global counter global LATEST_JSON counter = mp.Value("i", 0) level = args.level # since we are going to use it a lot of times print("Updating...") latest_json = download("http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json") latest = strptime(json.loads(latest_json.decode("utf-8"))["date"], "%Y-%m-%d %H:%M:%S") print("Latest version: {} GMT.".format(strftime("%Y/%m/%d %H:%M:%S", latest))) if latest_json == LATEST_JSON: print('Skip...') return LATEST_JSON = latest_json requested_time = calculate_time_offset(latest, args.auto_offset, args.offset) if args.auto_offset or args.offset != 10: print("Offset version: {} GMT.".format(strftime("%Y/%m/%d %H:%M:%S", requested_time))) png = Image.new("RGB", (WIDTH * level, HEIGHT * level)) p = mp_dummy.Pool(level * level) print("Downloading tiles...") res = p.map(download_chunk, it.product(range(level), range(level), (requested_time,), (args.level,))) for (x, y, tiledata) in res: tile = Image.open(io.BytesIO(tiledata)) png.paste(tile, (WIDTH * x, HEIGHT * y, WIDTH * (x + 1), HEIGHT * (y + 1))) for file in iglob(path.join(args.output_dir, "himawari-*.png")): os.remove(file) output_file = path.join(args.output_dir, strftime("himawari-%Y%m%dT%H%M%S.png", requested_time)) print("Saving to '%s'..." % (output_file,)) os.makedirs(path.dirname(output_file), exist_ok=True) png.save(output_file, "PNG") if sys.platform == 'win32': return if not set_background(output_file): sys.exit("Your desktop environment '{}' is not supported!\n".format(get_desktop_environment()))
def on_event(self, event): if event.type == pygame.KEYDOWN: if self._state == 0: if event.key == pygame.K_RETURN: self._state = 1 u.set_background(self._screen, "assets/backgrounds/match_menu.png") elif self._state == 1: if event.key == pygame.K_RETURN: self._score1 += 1 self.check_winner() u.set_background(self._screen, "assets/backgrounds/match_menu.png") if event.key == pygame.K_BACKSPACE: self._score2 += 1 self.check_winner() u.set_background(self._screen, "assets/backgrounds/match_menu.png") elif self._state == 2 or self._state == 3: if event.key == pygame.K_RETURN: self._state = 1 u.set_background(self._screen, "assets/backgrounds/match_menu.png") elif self._state == 4 or self._state == 5: if event.key == pygame.K_RETURN: m.back_to_menu()
def load_config(config_file): with open(config_file, 'r') as f: image_struct = yaml.load(f.read(), Loader=yaml.FullLoader) return image_struct def save_config(config_file, config_data): with open(config_file, 'w') as f: yaml.dump(config_data, f) if __name__ == "__main__": image_struct = { 'element': 'src', 'url': r'http://image.baidu.com/search/detail?ct=503316480&z=0&ipn=false&word=%E5%A3%81%E7%BA%B8&step_word=&hs=0&pn=0&spn=0&di=168330&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=&lm=-1&st=undefined&cs=3062374190%2C3164523231&os=609645438%2C61978557&simid=4067838971%2C577556431&adpicid=0&lpn=0&ln=3538&fr=&fmq=1589782577879_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined©right=undefined&se=&sme=&tab=0&width=1920&height=1080&face=undefined&ist=&jit=&cg=wallpaper&bdtype=11&oriquery=%E5%A3%81%E7%BA%B8&objurl=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2Fd22bbcc815668a3244e4237c1731b98d8ee370a3.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bktstktst_z%26e3Bv54AzdH3F6jw1AzdH3Fveccca8bc&gsm=1&rpstart=0&rpnum=0&islist=&querylist=&force=undefined', 'xpath': r'.//img[@id="currentImg"]', } if os.path.exists(CONFIG_PATH): image_struct = load_config(CONFIG_PATH) downloader = image_downloader(image_struct['url']) image_url, image_struct = downloader.url_generator(image_struct, interval=1) save_config(CONFIG_PATH, image_struct) if not image_url: raise Exception('image did not loaded!') url_request.get_save(image_url, IMAGE_PATH) set_background(IMAGE_PATH)
def update_background(self): if hasattr(self._current, '_menu') and self._current._menu.bg_path: set_background(self._screen, self._current._menu.bg_path) pygame.display.update()
return mask def mask_image(image, mask): background = Image.new('RGB', image.size, 0) return Image.composite(background, image, mask) def create_wallpaper(image, width, height, size=1000): image = image.resize((size, size)) x0, x1 = int(width / 2 - (size / 2)), int(width / 2 + (size / 2)) y0, y1 = int(height / 2 - (size / 2)), int(height / 2 + (size / 2)) background = Image.new('RGB', (width, height), 0) background.paste(image, (x0, y0, x1, y1)) return background if __name__ == "__main__": sun_image = get_current_image() screen_width, screen_height = get_resolution() sun_width, sun_height = sun_image.size mask = generate_mask(sun_width, sun_height) image_masked = mask_image(sun_image, mask) wallpaper = create_wallpaper(image_masked, width=screen_width, height=screen_height) image_masked.save('teste', "PNG") set_background('teste')