forked from Podshot/MCEdit-Unified
-
Notifications
You must be signed in to change notification settings - Fork 1
/
splash.py
74 lines (68 loc) · 2.73 KB
/
splash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python
# Taken from http://www.pygame.org/project-Splash+screen-1186-.html by Rock Achu (rockhachu2)
# and tweaked ;)
import os
import directories
if os.sys.platform == 'linux2':
os.sys.path.insert(1, os.path.expanduser('~/.local/lib/python2.7/site-packages'))
os.sys.path.insert(1, os.path.abspath('./lib'))
import pygame
print 'Splash load...'
os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()
pygame.font.init()
no_splash = False
cur_dir = directories.getDataDir()
splash_name = os.path.join(cur_dir, 'splash')
splash = None
try:
found = False
if os.path.exists(splash_name):
splash_img = open(splash_name).read().strip()
if os.path.exists(splash_img) and splash_img.split('.')[-1].lower() in ('jpg', 'png', 'bmp', 'pcx', 'tif', 'lbm', 'pbm', 'pgm', 'ppm', 'xpm'):
found = True
splash = pygame.image.load(open(splash_img, 'rb'))
if not found:
splash = pygame.image.load(open(os.path.join(cur_dir, "splash.png"), 'rb'))
screen = pygame.display.set_mode(splash.get_size(), pygame.NOFRAME)
screen.blit(splash, (0, 0))
except Exception, e:
print e
try:
f = open(os.path.join(cur_dir, 'fonts', 'DejaVuSans-Bold.ttf'), 'rb')
font = pygame.font.Font(f, 48)
buf = font.render("MCEDit is loading...", True, (128, 128, 128))
screen = pygame.display.set_mode((buf.get_width() + 20, buf.get_height() + 20), pygame.NOFRAME)
screen.blit(buf, (10, 10))
splash = pygame.display.get_surface()
except Exception, _e:
print _e
splash = pygame.display.set_mode((1, 1))
no_splash = True
if splash:
pygame.display.update()
#os.environ['SDL_VIDEO_CENTERED'] = '0' # Done later, when initializing MCEdit 'real' display.
# Random splash
#
# Uses a 'splash' file to check the state.
# This file contains the name of the splash to be loaded next time MCEdit starts.
# No splash file means it has to be created.
# An empty file means the 'splash.png' file will always be used.
#
if not os.path.exists(splash_name):
try:
open(splash_name, 'w').write('scrap')
except:
pass
if len(open(splash_name).read()) > 0:
from random import choice
splashes_folder = os.path.join(cur_dir, 'splashes')
if not os.path.exists(splashes_folder):
splashes_folder = os.path.join(cur_dir, splashes_folder)
if os.path.exists(splashes_folder) and os.listdir(splashes_folder):
new_splash = choice(os.listdir(splashes_folder))
if new_splash.split('.')[-1].lower() in ('jpg', 'png', 'bmp', 'pcx', 'tif', 'lbm', 'pbm', 'pgm', 'ppm', 'xpm'):
try:
open(splash_name, 'w').write(os.path.join(cur_dir, splashes_folder, new_splash))
except:
pass