Start transitioning to Python

This commit is contained in:
Gergely Polonkai 2015-10-04 14:34:09 +02:00
parent 311bdf84bc
commit 3bda776d90
4 changed files with 88 additions and 0 deletions

0
__init__.py Normal file
View File

77
main.py Executable file
View File

@ -0,0 +1,77 @@
#! /usr/bin/env python3
from random import randint
import os
import sys
import gi
gi.require_version('Clutter', '1.0')
from gi.repository import Clutter
from resources import ResourcesCollection
from utils import ensureDirExists
win32 = False
apple = False
PREFIX = ''
# Clutter.init()
#
# stage = Clutter.Stage()
# stage.connect('destroy', lambda x: Clutter.main_quit())
# stage.title = 'Test'
# background = Clutter.Color()
# background.red, background.blue, background.green, background.alpha = 10, 10, 10, 255
# stage.set_background_color(background)
#
# actorRectangle = Clutter.Actor()
# actorRectangle.set_size(100, 100)
# actorRectangle.set_position(100, 100)
# rectColor = Clutter.Color()
# rectColor.red, rectColor.blue, rectColor.green, rectColor.alpha = 100, 100, 100, 255
# actorRectangle.set_background_color(rectColor)
#
# def changeRectanglePosition(x, y):
# sizex, sizey = stage.get_size()
# newx = randint(0, sizex)
# newy = randint(0, sizey)
# actorRectangle.set_position(newx, newy)
#
# actorRectangle.set_reactive(True)
# actorRectangle.connect('enter-event', changeRectanglePosition)
#
# stage.add_actor(actorRectangle)
# stage.show()
# Clutter.main()
def loadResources(selfPath):
dirs = []
if win32:
dirs.append(getStorage().get("path", "") + "\\res")
elif apple:
dirs.append(getResourcesPath(selfPath))
else:
dirs.append(PREFIX + "/share/einstein/res")
dirs.append(os.environ["HOME"] + "/.einstein/res")
dirs.append("res")
dirs.append(".")
resources = ResourcesCollection(dirs)
msg.load()
if __name__ == '__main__':
ensureDirExists(os.environ["HOME"] + "/.einstein")
try:
loadResources(sys.argv[0])
initScreen()
initAudio()
menu()
getStorage().flush()
except Exception as e:
sys.stderr.write("ERROR: {0}".format(e))
# screen.doneCursors();

6
resources.py Normal file
View File

@ -0,0 +1,6 @@
class ResourcesCollection:
def __init__(self, directories):
loadResourceFiles(directories);
ResFileMoreThen comparator;
std::sort(files.begin(), files.end(), comparator);
processFiles();

5
utils.py Normal file
View File

@ -0,0 +1,5 @@
import os
def ensureDirExists(path):
if not os.path.exists(path):
os.makedirs(path)