Package horizons :: Package util :: Module atlasloading
[hide private]
[frames] | no frames]

Source Code for Module horizons.util.atlasloading

 1  # ################################################### 
 2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
 3  # team@unknown-horizons.org 
 4  # This file is part of Unknown Horizons. 
 5  # 
 6  # Unknown Horizons is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the 
18  # Free Software Foundation, Inc., 
19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
20  # ################################################### 
21   
22  import os 
23  import subprocess 
24  import sys 
25  import time 
26   
27  import horizons 
28  import horizons.globals 
29  from horizons.constants import GFX, PATHS 
30   
31   
32 -def generate_atlases():
33 """ 34 Generate atlases in dev mode. Shows a TK window during the process. 35 """ 36 try: 37 import tkinter 38 from PIL import Image, ImageTk 39 except ImportError: 40 # tkinter or PIL may be missing, abort 41 return 42 43 horizons_path = os.path.dirname(horizons.__file__) 44 args = [sys.executable, os.path.join(horizons_path, 'engine', 'generate_atlases.py'), 45 str(horizons.globals.fife.get_uh_setting('MaxAtlasSize'))] 46 process = subprocess.Popen(args, stdout=None, stderr=subprocess.STDOUT) 47 48 try: 49 window = tkinter.Tk() 50 # iconify window instead of closing 51 window.protocol("WM_DELETE_WINDOW", window.iconify) 52 window.wm_withdraw() 53 window.attributes("-topmost", 1) 54 window.title("Unknown Horizons") 55 window.maxsize(300, 150) 56 57 logo = Image.open(PATHS.UH_LOGO_FILE) 58 res_logo = logo.resize((116, 99), Image.ANTIALIAS) 59 res_logo_image = ImageTk.PhotoImage(res_logo) 60 logo_label = tkinter.Label(window, image=res_logo_image) 61 logo_label.pack(side="left") 62 label = tkinter.Label(window, padx=10, text="Generating atlases!") 63 label.pack(side="right") 64 65 window.deiconify() 66 window.attributes("-topmost", 0) 67 while process.poll() is None: 68 if not window.state() == "iconic": 69 window.update() 70 time.sleep(0.1) 71 window.destroy() 72 73 if process.returncode != 0: 74 print('Atlas generation failed. Continuing without atlas support.') 75 print('This just means that the game will run a bit slower.') 76 print('It will still run fine unless there are other problems.') 77 print() 78 else: 79 GFX.USE_ATLASES = True 80 PATHS.DB_FILES = PATHS.DB_FILES + (PATHS.ATLAS_DB_PATH, ) 81 except tkinter.TclError: 82 # catch #2298 83 pass
84