Commit b5e75c09 authored by Kuato's avatar Kuato
Browse files

Ajouté variable DIR et réaménagement

parent 9919b2f4
......@@ -20,11 +20,80 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from sys import argv, exit
import sys
from os import access, R_OK, makedirs, chdir
from os.path import join, isdir, dirname, realpath, split
from sys import argv, exit, getfilesystemencoding
import sys, os
from os import access, R_OK, makedirs, chdir, environ, name
from os.path import join, isdir, dirname, realpath, split, exists, abspath, normpath
from codecs import open
##
def we_are_frozen():
"""Returns whether we are frozen via py2exe.
This will affect how we find out where we are located."""
return hasattr(sys, "frozen")
def data_dir():
"""Renvoie le dossier data, selon qu'on utilise pyromaths à partir des
sources, de l'exécutable win32 ou du paquet deb"""
if we_are_frozen():
return join(normpath(dirname(unicode(executable,
getfilesystemencoding()))), 'data')
elif exists(join(abspath(dirname(__file__)),'../data/')):
return normpath(join(abspath(dirname(__file__)),'../data/'))
else:
return '/usr/share/pyromaths/'
def icon_dir():
"""Renvoie le dossier où se trouve l'icône, selon qu'on utilise pyromaths à
partir des sources, de l'exécutable win32 ou du paquet deb"""
if we_are_frozen() or exists(join(abspath(dirname(__file__)),'../data/')):
return join(DATADIR, 'images', 'pyromaths.png')
else:
return join('/usr/share/pixmaps', 'pyromaths.png')
def home():
if name == 'nt':
return unicode(environ['USERPROFILE'], getfilesystemencoding())
elif sys.platform == "darwin": #Cas de Mac OS X.
return unicode(environ['HOME'], getfilesystemencoding())
else:
try:
return unicode(environ['HOME'], getfilesystemencoding())
except KeyError:
# Pyromaths en ligne, l'user apache n'a pas de $HOME
return ""
def configdir():
if name == 'nt':
return join(unicode(environ['APPDATA'], getfilesystemencoding()),
"pyromaths")
elif sys.platform == "darwin": #Cas de Mac OS X.
return join(home(), "Library", "Application Support", "Pyromaths")
else:
return join(home(), ".config", "pyromaths")
def langue(LANG_NOM):
if sys.platform.startswith('win'):
import locale
if os.getenv('LANG') is None:
lang, enc = locale.getdefaultlocale()
os.environ['LANG'] = lang
else:
lang = os.getenv('LANG')
LANG_temp = [LANG_NOM[i][0] for i in range(len(LANG_NOM))]
LANG_txt = lang[0:2]
if LANG_temp.count(LANG_txt) > 0:
LANG = LANG_temp.index(LANG_txt)
else:
LANG = "0"
return LANG
DATADIR = data_dir()
ICONDIR = icon_dir()
HOME = home()
CONFIGDIR = configdir()
LANG_NOM = [["fr", u"Frances"], ["es", u"Español"]]
DIR_LANG = join(DATADIR, "locale")
def main():
#===============================================================================
......@@ -32,35 +101,37 @@ def main():
#===============================================================================
from outils.System import create_config_file, modify_config_file
from outils.TestEnv import test
from Values import CONFIGDIR
import interface
from PyQt4 import QtGui, QtCore
class StartQT4(QtGui.QMainWindow, interface.Ui_MainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = interface.Ui_MainWindow()
self.ui.setupUi(self)
#===========================================================================
# Création du fichier de configuration si inexistant
#===========================================================================
if not access(join(CONFIGDIR, "pyromaths.xml"), R_OK):
if not isdir(CONFIGDIR): makedirs(CONFIGDIR)
f = open(join(CONFIGDIR, "pyromaths.xml"), encoding='utf-8', mode='w')
f.write(u"" + create_config_file())
LANG = langue(LANG_NOM)
f.write(u"" + create_config_file(HOME, DIR_LANG, LANG_NOM, LANG))
f.close()
modify_config_file(join(CONFIGDIR, "pyromaths.xml"))
modify_config_file(join(CONFIGDIR, "pyromaths.xml"), HOME, CONFIGDIR, DIR_LANG, LANG_NOM)
templatesdir = join(CONFIGDIR, "templates")
if not isdir(templatesdir): makedirs(templatesdir)
packagesdir = join(CONFIGDIR, "packages")
if not isdir(packagesdir): makedirs(packagesdir)
import interface
from PyQt4 import QtGui, QtCore
class StartQT4(QtGui.QMainWindow, interface.Ui_MainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = interface.Ui_MainWindow()
self.ui.setupUi(self, CONFIGDIR, DATADIR, ICONDIR, LANG_NOM)
app = QtGui.QApplication(argv)
pyromaths = StartQT4()
pyromaths.show()
test(pyromaths)
test(pyromaths, CONFIGDIR)
exit(app.exec_())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment