-
Notifications
You must be signed in to change notification settings - Fork 0
/
SugarCubesUtils.py
69 lines (60 loc) · 1.77 KB
/
SugarCubesUtils.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
def initUtils(ps_moduleName, pClass_baseProgram):
global gs_moduleSugarCubes, gClass_baseProgram
gs_moduleSugarCubes = ps_moduleName
gClass_baseProgram = pClass_baseProgram
def getGlobalByName(ps_moduleName, ps_name):
import sys
lModule = sys.modules[ps_moduleName]
lGlobal = getattr(lModule, ps_name)
return lGlobal
def getLocalsCaller():
import inspect
return inspect.currentframe().f_back.f_back.f_locals
def deLive(ps_genre): # ps_genre = 'simple' | 'double'
def lFunc_temp(pClass):
ls_sansLive = pClass.__name__[4:]
import sys
lModule = sys.modules[gs_moduleSugarCubes]
lNewClass = type(ls_sansLive, (gClass_baseProgram,), {})
setattr(
lModule,
ls_sansLive,
lNewClass
)
if ps_genre == 'double':
ls_sansLive_sansProg = ls_sansLive[4:]
setattr(
lModule,
ls_sansLive_sansProg,
lNewClass
)
return pClass
return lFunc_temp
def getObjectById(pn_id):
import ctypes
return ctypes.cast(pn_id, ctypes.py_object).value
def printErr(ps_texte):
import sys
sys.stderr.write(str(ps_texte) + '\n')
def printErrExit(ps_texte):
import sys
sys.stderr.write(ps_texte + '\n')
sys.exit()
def getAvecTab(ps_texte, pn_nombreTab):
TAB='\t'
# TAB=' '
# TAB='..'
ps_texte = TAB*pn_nombreTab + ps_texte
ls_newlineALaFin = '\n' if ps_texte[-1] == '\n' else ''
if ps_texte[-1] == '\n': ps_texte = ps_texte[:-1]
ps_texte = ps_texte.replace('\n', '\n' + TAB*pn_nombreTab)
return ps_texte + ls_newlineALaFin
def writeTab(pFunc_write, pn_nombreTab, ps_texte):
ps_texte = getAvecTab(ps_texte, pn_nombreTab)
pFunc_write(ps_texte)
def setParent(pList_children, p_parent):
for child in pList_children:
try:
child.a_parent = p_parent
except AttributeError: pass
except TypeError: pass