Ejemplo n.º 1
0
def main():
    ## -- log --
    settings = QtCore.QSettings(osp.join(pjpath, "config/setting.ini"),
                                QtCore.QSettings.IniFormat)
    #
    # logFolder = settings.value("logFolder")
    # logLevel = settings.value("logLevel")
    # logDays = settings.value("logDays")
    #
    # if logFolder is None or len(logFolder) == 0:
    #     logFolder = osp.normcase(osp.join(pjpath, "log"))
    # if not osp.exists(logFolder):
    #     os.makedirs(logFolder)
    #
    # if logLevel:
    #     logLevel = eval(logLevel)
    # else:
    #     logLevel = logging.DEBUG
    # if logDays:
    #     logDays = int(logDays)
    # else:
    #     logDays = 7
    # # TODO: 删除大于logDays 的 log
    #
    # t = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
    # logging.basicConfig(
    #     level=logging.DEBUG,
    #     filename=osp.normcase(osp.join(logFolder, f"eiseg-{t}.log")),
    #     format="%(levelname)s - %(asctime)s - %(filename)s - %(funcName)s - %(message)s",
    # )
    # logger = logging.getLogger("EISeg Logger")
    # handler = logging.FileHandler(osp.normcase(osp.join(logFolder, f"eiseg-{t}.log")))
    #
    # handler.setFormatter(
    #     logging.Formatter(
    #         "%(levelname)s - %(asctime)s - %(filename)s - %(funcName)s - %(message)s"
    #     )
    # )
    # logger.addHandler(handler)
    # logger.info("test info")
    #
    app = QApplication(sys.argv)
    lang = settings.value("language")
    if lang != "中文":
        trans = QtCore.QTranslator(app)
        trans.load(osp.join(pjpath, f"util/translate/{lang}"))
        app.installTranslator(trans)

    window = APP_EISeg()  # 创建对象
    window.currLanguage = lang
    window.showMaximized()  # 全屏显示窗口
    # 加载近期模型
    QApplication.processEvents()
    window.loadRecentModelParam()
    sys.exit(app.exec())
Ejemplo n.º 2
0
def main():
    app = QApplication(sys.argv)
    lang = QtCore.QSettings(osp.join(pjpath, "config/setting.ini"),
                            QtCore.QSettings.IniFormat).value("language")
    if lang != "中文":
        trans = QtCore.QTranslator(app)
        trans.load(osp.join(pjpath, f"util/translate/{lang}"))
        app.installTranslator(trans)

    window = APP_EISeg()  # 创建对象
    window.showMaximized()  # 全屏显示窗口
    # 加载近期模型
    QApplication.processEvents()
    window.loadRecentModelParam()
    sys.exit(app.exec_())
Ejemplo n.º 3
0
def main():
    app = QApplication(sys.argv)

    app.setWindowIcon(QIcon(':/icons/app.svg'))

    fontDB = QFontDatabase()
    fontDB.addApplicationFont(':/fonts/Roboto-Regular.ttf')
    app.setFont(QFont('Roboto'))

    f = QFile(':/style.qss')
    f.open(QFile.ReadOnly | QFile.Text)
    app.setStyleSheet(QTextStream(f).readAll())
    f.close()

    translator = QTranslator()
    translator.load(':/translations/' + QLocale.system().name() + '.qm')
    app.installTranslator(translator)

    mw = MainWindow()
    mw.show()

    sys.exit(app.exec_())
Ejemplo n.º 4
0
def opensesame():

    import os, sys, platform
    # Add the folder that contains the OpenSesame modules to the path. This is
    # generally only necessary if OpenSesame is directly run from source,
    # instead from an installation.
    if os.path.exists(os.path.join(os.getcwd(), 'libopensesame')):
        sys.path.insert(0, os.getcwd())
    # Support for multiprocessing when packaged
    # In OS X the multiprocessing module is horribly broken, but a fixed
    # version has been released as the 'billiard' module
    if platform.system() == 'Darwin':
        # Use normal multirpocessing module from python 3.4 and on
        if sys.version_info >= (3, 4):
            from multiprocessing import freeze_support, set_start_method
            freeze_support()
            set_start_method('forkserver')
        else:
            from billiard import freeze_support, forking_enable
            freeze_support()
            forking_enable(0)
    else:
        from multiprocessing import freeze_support
        freeze_support()
    # Parse the (optional) environment file that contains special paths, etc.
    from libopensesame.misc import resource, filesystem_encoding, \
     parse_environment_file
    parse_environment_file()
    # Force the new-style Qt API
    import sip
    import qtpy
    sip.setapi('QString', 2)
    sip.setapi('QVariant', 2)
    # Load debug package (this must be after the working directory change)
    from libopensesame import debug
    # Do the basic window initialization
    from qtpy.QtWidgets import QApplication

    # From Qt 5.6 on, QtWebEngine is the default way to render web pages
    # QtWebEngineWidgets must be imported before a QCoreApplication instance is created
    try:
        from qtpy import QtWebEngineWidgets
    except ImportError:
        pass

    app = QApplication(sys.argv)
    # Enable High DPI display with PyQt5
    if hasattr(qtpy.QtCore.Qt, 'AA_UseHighDpiPixmaps'):
        app.setAttribute(qtpy.QtCore.Qt.AA_UseHighDpiPixmaps)
    from libqtopensesame.qtopensesame import qtopensesame
    opensesame = qtopensesame(app)
    opensesame.__script__ = __file__
    app.processEvents()
    # Import the remaining modules
    from qtpy.QtCore import QObject, QLocale, QTranslator
    import os.path
    # Load the locale for UI translation. The locale can be specified on the
    # command line using the --locale parameter
    locale = QLocale().system().name()
    for i in range(len(sys.argv) - 1):
        if sys.argv[i] == '--locale':
            locale = sys.argv[i + 1]
    qm = resource(os.path.join(u'locale', locale) + u'.qm')
    # Say that we're trying to load de_AT, and it is not found, then we'll try
    # de_DE as fallback.
    if qm is None:
        l = locale.split(u'_')
        if len(l):
            _locale = l[0] + u'_' + l[0].upper()
            qm = resource(os.path.join(u'locale', _locale + u'.qm'))
            if qm is not None:
                locale = _locale
    opensesame._locale = locale
    if qm is not None:
        debug.msg(u'installing %s translator' % qm)
        translator = QTranslator()
        translator.load(qm)
        app.installTranslator(translator)
    else:
        debug.msg(u'no translator found for %s' % locale)
    # Now that the window is shown, load the remaining modules and resume the
    # GUI initialization.
    opensesame.resume_init()
    opensesame.restore_window_state()
    opensesame.refresh()
    opensesame.show()
    # Added for OS X, otherwise Window will not appear
    opensesame.raise_()
    # Exit using the application exit status
    sys.exit(app.exec_())
Ejemplo n.º 5
0
def opensesame():

	import os, sys, platform
	# Add the folder that contains the OpenSesame modules to the path. This is
	# generally only necessary if OpenSesame is directly run from source,
	# instead from an installation.
	if os.path.exists(os.path.join(os.getcwd(), 'libopensesame')):
		sys.path.insert(0, os.getcwd())
	# Support for multiprocessing when packaged
	# In OS X the multiprocessing module is horribly broken, but a fixed
	# version has been released as the 'billiard' module
	if platform.system() == 'Darwin':
		# Use normal multirpocessing module from python 3.4 and on
		if sys.version_info >= (3,4):
			from multiprocessing import freeze_support, set_start_method
			freeze_support()
			set_start_method('forkserver')
		else:
			from billiard import freeze_support, forking_enable
			freeze_support()
			forking_enable(0)
	else:
		from multiprocessing import freeze_support
		freeze_support()
	# Parse the (optional) environment file that contains special paths, etc.
	from libopensesame.misc import resource, filesystem_encoding, \
		parse_environment_file
	parse_environment_file()
	# Force the new-style Qt API
	import sip
	import qtpy
	sip.setapi('QString', 2)
	sip.setapi('QVariant', 2)
	# Load debug package (this must be after the working directory change)
	from libopensesame import debug
	# Do the basic window initialization
	from qtpy.QtWidgets import QApplication

	# From Qt 5.6 on, QtWebEngine is the default way to render web pages
	# QtWebEngineWidgets must be imported before a QCoreApplication instance is created
	try:
		from qtpy import QtWebEngineWidgets
	except ImportError:
		pass
	
	app = QApplication(sys.argv)
	# Enable High DPI display with PyQt5
	if hasattr(qtpy.QtCore.Qt, 'AA_UseHighDpiPixmaps'):
		app.setAttribute(qtpy.QtCore.Qt.AA_UseHighDpiPixmaps)
	from libqtopensesame.qtopensesame import qtopensesame
	opensesame = qtopensesame(app)
	opensesame.__script__ = __file__
	app.processEvents()
	# Import the remaining modules
	from qtpy.QtCore import QObject, QLocale, QTranslator
	import os.path
	# Load the locale for UI translation. The locale can be specified on the
	# command line using the --locale parameter
	locale = str(QLocale().system().name())
	for i in range(len(sys.argv)-1):
		if sys.argv[i] == '--locale':
			locale = sys.argv[i+1]
	opensesame._locale = locale
	qm = resource(os.path.join(u'locale', locale) + u'.qm')
	if qm is not None:
		debug.msg(u'installing %s translator' % qm)
		translator = QTranslator()
		translator.load(qm)
		app.installTranslator(translator)
	else:
		debug.msg(u'no translator found for %s' % locale)
	# Now that the window is shown, load the remaining modules and resume the
	# GUI initialization.
	opensesame.resume_init()
	opensesame.restore_window_state()
	opensesame.refresh()
	opensesame.show()
	# Added for OS X, otherwise Window will not appear
	opensesame.raise_()
	# Exit using the application exit status
	sys.exit(app.exec_())