def __init__(self, parent):

        self.__errorFound = False

        libPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath)

        #
        # English
        #
        self.enBaseTranslator = QTranslator(parent)
        self.enBaseTranslator.load("qtbase_en", libPath)
        self.enTranslator = QTranslator(parent)
        self.enTranslator.load("ui_en", str(config.LOCALE) + "/en/LC_MESSAGES")

        #
        # Español
        #
        self.esBaseTranslator = QTranslator(parent)
        self.esBaseTranslator.load("qtbase_es", libPath)
        self.esTranslator = QTranslator(parent)
        self.esTranslator.load("ui_es", str(config.LOCALE) + "/es/LC_MESSAGES")

        self.trLast = None
        self.trBaseLast = None
        self.loadedTranslations = []
Beispiel #2
0
def load_translations(app):
    """Load translations

    .. note:: Init ui/locale setting
    """
    # Load locale setting if exists
    # English is the default language
    app_settings = QSettings()
    locale_name = app_settings.value("ui/locale", "en")

    # site-packages/PySide2/Qt/translations
    lib_info = QLibraryInfo.location(QLibraryInfo.TranslationsPath)

    # Qt translations
    qt_translator = QTranslator(app)
    if qt_translator.load("qt_" + locale_name, directory=lib_info):
        app.installTranslator(qt_translator)

    # qtbase_translator = QTranslator(app)
    # if qtbase_translator.load("qtbase_" + locale_name, directory=lib_info):
    #     app.installTranslator(qtbase_translator)

    # App translations
    app_translator = QTranslator(app)
    if app_translator.load(locale_name, directory=cm.DIR_TRANSLATIONS):
        app.installTranslator(app_translator)
    else:
        # Init setting
        app_settings.setValue("ui/locale", "en")
Beispiel #3
0
 def set_language(self, lang):
     self.removeTranslator(self.translator)
     self.removeTranslator(self.qt_trans)
     loc = QLocale(lang)
     self.qt_trans.load(
         loc, 'qt', '_',
         QLibraryInfo.location(QLibraryInfo.TranslationsPath))
     self.installTranslator(self.qt_trans)
     self.translator.load(loc, '', '', ':/lang', '')
     self.installTranslator(self.translator)
Beispiel #4
0
def getQtTranslationsPath(sigil_path):
    isBundled = 'sigil' in sys.prefix.lower()
    print('Python is Bundled: {}'.format(isBundled))
    if isBundled:
        if sys.platform.lower().startswith('darwin'):
            return os.path.normpath(sigil_path + '/../translations')
        else:
            return os.path.join(sigil_path, 'translations')
    else:
        return QLibraryInfo.location(QLibraryInfo.TranslationsPath)
 def initTranslators(self):
     combobox = self.ui.language
     combobox.clear()
     for file in os.listdir(PATHLANGUAGES):
         if os.path.splitext(file)[1] == ".qm":
             translator = QTranslator()
             print('Localization loaded: ',
                   os.path.join(PATHLANGUAGES, file),
                   translator.load(file, PATHLANGUAGES))
             qttranslator = QTranslator()
             print(
                 'Localization loaded: ',
                 os.path.join(
                     QLibraryInfo.location(QLibraryInfo.TranslationsPath),
                     "q" + file),
                 qttranslator.load(
                     "q" + file,
                     QLibraryInfo.location(QLibraryInfo.TranslationsPath)))
             combobox.addItem(file[2:-3],
                              (translator, qttranslator, file[2:-3]))
     for l in sorted(LANGUAGES):
         combobox.addItem(l, (translator, qttranslator, l))
Beispiel #6
0
def find_exec_builder():
    import shutil

    path = os.environ.get('PATH', os.defpath)
    try:
        from PySide2.QtCore import QLibraryInfo as Info

        libex = Info.location(Info.LibraryExecutablesPath)
        if libex not in path.split(os.pathsep):
            path += os.pathsep + libex
    except ImportError:
        pass
    return lambda prog: shutil.which(prog, path=path)
Beispiel #7
0
def start():
    app = QApplication(sys.argv)
    app.setOrganizationName('Quring')
    app.setOrganizationDomain('Quring')
    app.setApplicationName('Quring')

    qt_translator = QTranslator()
    qt_translator.load('qt_' + QLocale.system().name(),
                       QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    app.installTranslator(qt_translator)

    main_window = MainWindow()
    logger.info('Showing main window')
    main_window.show()
    sys.exit(app.exec_())
Beispiel #8
0
def main():
    # app disexec теперь на pyqt
    app = QApplication(sys.argv)
    app.setStyle('Fusion')
    # Здесь будем работать со стилями(пока в разработке)
    #QApplication.setStyle(QStyleFactory.create("windowsvista"))

    # Русифицируем наше приложение
    translator = QTranslator()
    if (translator.load("qt_ru",
                        QLibraryInfo.location(QLibraryInfo.TranslationsPath))):
        app.installTranslator(translator)

    # Если всё хорошо запускаем приложение
    window = TreeCard(AllTables('database/objects'), 0)
    window.show()
    sys.exit(app.exec_())
Beispiel #9
0
def main():
    # app disexec теперь на pyqt
    app = QApplication(sys.argv)
    app.setStyle('Fusion')
    # Здесь будем работать со стилями(пока в разработке)
    #QApplication.setStyle(QStyleFactory.create("windowsvista"))

    # Русифицируем наше приложение
    translator = QTranslator()
    if (translator.load("qt_ru",
                        QLibraryInfo.location(QLibraryInfo.TranslationsPath))):
        app.installTranslator(translator)

    # Получим строку подключения к БД
    connection = {}

    # Если всё хорошо запускаем приложение
    window = TdisMainForm(connection)
    window.show()
    sys.exit(app.exec_())
Beispiel #10
0
 def __init__(self, argv):
     params = parse(sys.argv[1:])[0]
     super().__init__(argv)
     self.setOrganizationName('SBA')
     self.setApplicationName('QtImgren')
     if params.lang is None:
         settings = QSettings()
         lang = settings.value('MainWindow/lang')
         loc = QLocale() if lang is None else QLocale(lang)
     elif params.lang == 'native':
         loc = QLocale(None)
     else:
         loc = QLocale(params.lang)
     self.qt_trans = QTranslator()
     self.qt_trans.load(
         loc, 'qtbase', '_',
         QLibraryInfo.location(QLibraryInfo.TranslationsPath))
     self.installTranslator(self.qt_trans)
     self.translator = QTranslator()
     self.translator.load(loc, '', '', ':/lang', '')
     self.installTranslator(self.translator)
     self.setWindowIcon(QIcon(':/icon/app.ico'))
     self.main_window = MainWindow()
Beispiel #11
0
import sys
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QTranslator, QLocale, QLibraryInfo
from gui import Window

if __name__ == '__main__':
    app = QApplication(sys.argv)

    traductor = QTranslator()
    traductor.load("qtbase_" + QLocale.system().name(),
                   QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    app.installTranslator(traductor)

    win = Window()
    win.parent = app

    win.show()

    sys.exit(app.exec_())
Beispiel #12
0
import os
from PySide2.QtCore import QLibraryInfo


def make_symlink(source, target):
    if os.path.islink(target):
        os.unlink(target)

    os.symlink(source, target)


QT_LIB_PATH = QLibraryInfo.location(QLibraryInfo.LibrariesPath)

frameworks = [elem for elem in os.listdir(QT_LIB_PATH) if '.framework' in elem]

os.chdir(QT_LIB_PATH)

for fr in frameworks:
    fr_path = os.path.join(QT_LIB_PATH, fr)
    fr_name = fr.split('.framework')[0]
    os.chdir(fr_path)
    if 'Versions' in os.listdir('.'):
        make_symlink(f'Versions/Current/{fr_name}', fr_name)
        os.chdir(os.path.join(fr_path, 'Versions'))
        make_symlink('5', 'Current')
    os.chdir(QT_LIB_PATH)
Beispiel #13
0
def fedit(data
         ,result            = "list"
         ,type              = "form"
         ,title             = ""
         ,comment           = ""
         ,icon              = None
         ,parent            = None
         ,apply             = None
         ,ok                = True
         ,cancel            = True
         ,outfile           = None
         ,scrollbar         = False
         ,background_color  = None
         ,widget_color      = None
         # DJB added
         ,size              = None
         ,position          = None
         ,style             = None
         ):
    """
    Create form dialog and return result
    (if Cancel button is pressed, return None)

    :param tuple    data             : datalist, datagroup (see below)
    :param str      title            : form title
    :param str      comment          : header comment
    :param QIcon    icon             : dialog box icon
    :param QWidget  parent           : parent widget
    :param str      ok               : customized ok button label
    :param str      cancel           : customized cancel button label
    :param tuple    apply            : (label, function) customized button label and callback
    :param function apply            : function taking two arguments (result, widgets)
    :param str      result           : result serialization ('list', 'dict', 'OrderedDict','JSON' or 'XML')
    :param str      outfile          : write result to the file outfile.[py|json|xml]
    :param str      type             : layout type ('form' or 'questions')
    :param bool     scrollbar        : vertical scrollbar
    :param str      background_color : color of the background
    :param str      widget_color     : color of the widgets

    :return: Serialized result (data type depends on `result` parameter)
    
    datalist: list/tuple of (field_name, field_value)
    datagroup: list/tuple of (datalist *or* datagroup, title, comment)
    
    Tips:
      * one field for each member of a datalist
      * one tab for each member of a top-level datagroup
      * one page (of a multipage widget, each page can be selected with a 
        combo box) for each member of a datagroup inside a datagroup
       
    Supported types for field_value:
      - int, float, str, unicode, bool
      - colors: in Qt-compatible text form, i.e. in hex format or name (red,...)
                (automatically detected from a string)
      - list/tuple:
          * the first element will be the selected index (or value)
          * the other elements can be couples (key, value) or only values
    """
    # Create a QApplication instance if no instance currently exists
    # (e.g. if the module is used directly from the interpreter)
    test_travis = os.environ.get('TEST_CI_WIDGETS', None)
    if test_travis is not None:
        app = QApplication.instance()
        if app is None:
            app = QApplication([])
        timer = QTimer(app)
        timer.timeout.connect(app.quit)
        timer.start(1000)
    elif QApplication.startingUp():
        _app = QApplication([])
        translator_qt = QTranslator()
        translator_qt.load('qt_' + QLocale.system().name(),QLibraryInfo.location(QLibraryInfo.TranslationsPath))
        _app.installTranslator(translator_qt)

    serial = ['list', 'dict', 'OrderedDict', 'JSON', 'XML']
    if result not in serial:
        print(f"Warning: '{result}' not in {', '.join(serial)}, default to list", file=sys.stderr)
        result = 'list'

    layouts = ['form', 'questions']
    if type not in layouts:
        print(f"Warning: '{type}' not in {', '.join(layouts)}, default to form", file=sys.stderr)
        type = 'form'

    dialog = FormDialog(data, title, comment, icon, parent, apply, ok, cancel, result, outfile, type, scrollbar, background_color, widget_color)
    # djb added
    if size is not None:
        dialog.resize(size[0],size[1])
    if position is not None:
        dialog.move(position[0],position[1])
    if style is not None:
        dialog.setStyleSheet(style)
    if dialog.exec_():
        return dialog.get()
Beispiel #14
0
# This Python file uses the following encoding: utf-8
import sys

from PySide2 import QtWidgets
from PySide2.QtCore import QCoreApplication, Qt, QTranslator, QLibraryInfo
from view import Ui_MainWindow
from typing import List
from model import *
from assets import icons


class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.issues: List[Issue] = []
        self.setupUi(self)


if __name__ == "__main__":
    QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
    app = QtWidgets.QApplication(sys.argv)

    translator = QTranslator()
    translator.load("qt_pl", QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    app.installTranslator(translator)

    widget = MainWindow()
    widget.show()
    sys.exit(app.exec_())