Continue conversion
This commit is contained in:
parent
3bda776d90
commit
cd5ee8511e
7
main.py
7
main.py
@ -9,14 +9,16 @@ import gi
|
|||||||
gi.require_version('Clutter', '1.0')
|
gi.require_version('Clutter', '1.0')
|
||||||
|
|
||||||
from gi.repository import Clutter
|
from gi.repository import Clutter
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
from resources import ResourcesCollection
|
from resources import ResourcesCollection
|
||||||
from utils import ensureDirExists
|
from utils import ensureDirExists
|
||||||
|
|
||||||
win32 = False
|
win32 = False
|
||||||
apple = False
|
apple = False
|
||||||
|
developer = True
|
||||||
|
|
||||||
PREFIX = ''
|
PREFIX = '/usr'
|
||||||
# Clutter.init()
|
# Clutter.init()
|
||||||
#
|
#
|
||||||
# stage = Clutter.Stage()
|
# stage = Clutter.Stage()
|
||||||
@ -57,6 +59,9 @@ def loadResources(selfPath):
|
|||||||
dirs.append(PREFIX + "/share/einstein/res")
|
dirs.append(PREFIX + "/share/einstein/res")
|
||||||
dirs.append(os.environ["HOME"] + "/.einstein/res")
|
dirs.append(os.environ["HOME"] + "/.einstein/res")
|
||||||
|
|
||||||
|
if developer:
|
||||||
|
dirs.append(os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
|
||||||
dirs.append("res")
|
dirs.append("res")
|
||||||
dirs.append(".")
|
dirs.append(".")
|
||||||
resources = ResourcesCollection(dirs)
|
resources = ResourcesCollection(dirs)
|
||||||
|
57
resources.py
57
resources.py
@ -1,6 +1,55 @@
|
|||||||
|
from os import listdir
|
||||||
|
|
||||||
|
class ResourceFile(object):
|
||||||
|
|
||||||
|
def __init__(fileName, buf=None):
|
||||||
|
# Ooooh, what does this button do?
|
||||||
|
# name(fileName)
|
||||||
|
|
||||||
|
if buf:
|
||||||
|
buffer = buf
|
||||||
|
ownBuffer = False
|
||||||
|
else:
|
||||||
|
buffer = Buffer()
|
||||||
|
ownBuffer = true
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(fileName, 'rb') as f:
|
||||||
|
try:
|
||||||
|
sign = f.read(4)
|
||||||
|
if sign[0] != 'C' \
|
||||||
|
or sign[1] != 'R' \
|
||||||
|
or sign[2] != 'F' \
|
||||||
|
or sign[3]:
|
||||||
|
raise IOError("Failover")
|
||||||
|
|
||||||
|
major = f.unpack('i', 4)
|
||||||
|
minor = f.unpack('i', 4)
|
||||||
|
priority = f.unpack('i', 4)
|
||||||
|
|
||||||
|
if major != 2 or minor < 0:
|
||||||
|
raise Exception("Incompatible version of resource file '" + name + "'")
|
||||||
|
except IOError:
|
||||||
|
raise Exception("Invalid resource file '" + name + "'")
|
||||||
|
|
||||||
|
# How to reproduce this?
|
||||||
|
# int readed = stream.gcount();
|
||||||
|
|
||||||
|
except IOError:
|
||||||
|
raise Exception("Error loading resource file '" + name + "'")
|
||||||
|
|
||||||
class ResourcesCollection:
|
class ResourcesCollection:
|
||||||
def __init__(self, directories):
|
def __init__(self, directories):
|
||||||
loadResourceFiles(directories);
|
self.__files = []
|
||||||
ResFileMoreThen comparator;
|
self.__buffer = None
|
||||||
std::sort(files.begin(), files.end(), comparator);
|
self.loadResourceFiles(directories)
|
||||||
processFiles();
|
processFiles()
|
||||||
|
|
||||||
|
def loadResourceFiles(self, directories):
|
||||||
|
for directory in directories:
|
||||||
|
try:
|
||||||
|
for name in listdir(directory):
|
||||||
|
if not name.startswith('.') and name.endswith('.res'):
|
||||||
|
self.__files.append(ResourceFile(directory + '/' + name, self.__buffer));
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user