Esempio n. 1
0
    def __openDiagramShapes(self, projdata, the_proj):
        shapes = projdata.getElementsByTagName('shapelib')
        if shapes and shapes[0].hasAttribute('path'):

            plist = self.__getPathWithCommonChecking(shapes[0], the_proj)

            if len(plist) == 2:
                the_proj.shapelib = shapelib.ShapeLib()
                if not the_proj.shapelib.init(plist[1]):
                    print('warning: Can\'t load shape library from \"{0}\".'.format(plist[1]))
                    the_proj.shapelib = None
            elif plist:
                print('warning: Can\'t load shape library from \"{0}\".'.format(plist[0]))
            else:
                print('warning: Can\'t load shape library from \"{0}\".'.format(shapes[0]))

        if the_proj.shapelib is None:
            print('info: Trying to load default diagram shapes...')
            try_paths = []
            if isinstance(globals.applicationShapesPath, list):
                try_paths = globals.applicationShapesPath
            else:
                try_paths.append(globals.applicationShapesPath)

            okay = False
            err = False
            for path in try_paths:
                the_file = path

                if the_file is None:
                    print('error: Unexpected error: empty path to diagram shapes file!')
                    continue

                if not os.path.isabs(the_file):
                    print('debug: generating absPath for \"{0}\" relative to \"{1}\"'.format(the_file, globals.rootDirectory))
                    the_file = absPath(the_file, globals.rootDirectory)  # make full path from relative path
                else:
                    print('debug: the path \"%s\" is abs!' % the_file)
                    the_file = toUnixPath(the_file)

                if the_file is None:
                    err = True
                    print(u'warning: Diagram shapes file \"{0}\" does not exist!'.format(path))
                    continue

                if not os.path.exists(the_file):
                    err = True
                    print(u'warning: Diagram shapes file \"{0}\" does not exist!'.format(the_file))
                    continue

                the_proj.shapelib = shapelib.ShapeLib()
                if not the_proj.shapelib.init(the_file):
                    print('warning: Can\'t load shape library from \"{0}\".'.format(the_file))
                    the_proj.shapelib = None
                    continue

                okay = True
                return
Esempio n. 2
0
    def __openAlphabetFile(self, projdata, the_proj):
        alphs = projdata.getElementsByTagName('alphabet')
        if alphs and alphs[0].hasAttribute('path'):
            plist = self.__getPathWithCommonChecking(alphs[0], the_proj)
            if len(plist) == 2:
                the_proj.alphabet = alphabet.Alphabet()
                if not the_proj.alphabet.load(plist[1]) or len(the_proj.alphabet) < 1:
                    print('warning: Can\'t load alphabet from \'{0}\'!'.format(plist[1]))
                    print('')
                    the_proj.alphabet = None
                else:
                    print('ok: Alphabet file \'{0}\' was loaded successfully'.format(plist[1]))
                    print('')
                    return
            elif plist:
                print('warning: Can\'t load alphabet from \"{0}\".'.format(plist[0]))
            else:
                print('warning: Can\'t load alphabet from \"{0}\".'.format(alphs[0]))

        if the_proj.alphabet is None:
            print('info: Trying to load default behavior alphabet...')
            try_paths = []
            if isinstance(globals.applicationAlphabetPath, list):
                try_paths = globals.applicationAlphabetPath
            else:
                try_paths.append(globals.applicationAlphabetPath)

            okay = False
            err = False
            for path in try_paths:
                the_file = path

                if not os.path.isabs(the_file):
                    the_file = absPath(the_file, globals.rootDirectory)  # make full path from relative path
                else:
                    the_file = toUnixPath(the_file)

                if the_file is None:
                    err = True
                    print(u'warning: Alphabet file \"{0}\" does not exist!'.format(path))
                    continue

                if not os.path.exists(the_file):
                    err = True
                    print(u'warning: Alphabet file \"{0}\" does not exist!'.format(the_file))
                    continue

                the_proj.alphabet = alphabet.Alphabet()
                if not the_proj.alphabet.load(the_file) or len(the_proj.alphabet) < 1:
                    print('warning: Can\'t load alphabet from \'{0}\'!'.format(the_file))
                    print('')
                    the_proj.alphabet = None
                    continue

                okay = True
                print('ok: Alphabet file \'{0}\' was loaded successfully'.format(the_file))
                print('')
                return
Esempio n. 3
0
    def init(self, shapesFile):
        global _defaultScale
        print('INFO: loading shapes from \"{0}\"'.format(shapesFile))

        if os.path.exists(shapesFile):
            dom = parse(shapesFile)
            data = dom.getElementsByTagName('ShapeData')

            if data:
                resourceOk = False

                resdir = ''
                shapePath = ''
                if data[0].hasAttribute('path'):
                    path = absPath(data[0].getAttribute('path'), shapesFile, True)
                    if path is not None and path:
                        resdir = path
                        shapePath = '/'.join([resdir, 'square.pp'])
                        if os.path.exists(shapePath):
                            resourceOk = True

                if resourceOk:
                    self.shapes.clear()

                    self.shapes['default'] = VecShape('default', shapePath, _defaultScale)
                    self.shapes['default'].addPoint(QPointF(-16.0, 0.0), VecShape.horizontal)
                    self.shapes['default'].addPoint(QPointF(16.0, 0.0), VecShape.horizontal)
                    self.shapes['default'].addPoint(QPointF(0.0, -16.0), VecShape.vertical)
                    self.shapes['default'].addPoint(QPointF(0.0, 16.0), VecShape.vertical)

                    shapes = data[0].getElementsByTagName('VecShape')  # data[0].getElementsByTagName('Shape')
                    for shape in shapes:
                        # self.readPolyShape(shape)
                        self.readVecShape(shape, resdir)

                    res = len(self.shapes) > 1
                    if res:
                        self.path = shapesFile
                        self.resdir = resdir

                    return res
                print('ERROR: Resource dir for shapes file \"{0}\" is broken!'.format(shapesFile))
                print('')
            else:
                print('ERROR: Shapes file has no header \"ShapeData\"!')
                print('')
        else:
            print('ERROR: shapes file \"{0}\" does not exist!'.format(shapesFile))
            print('')
        return False
Esempio n. 4
0
def _readConfigIcons(configFile, configData):
    iconsPath = ""
    if configData.hasAttribute("icons"):
        path = configData.getAttribute("icons")
        path = absPath(path, configFile, True)
        if path is None or len(path) < 1 or not os.path.exists(path):
            print(u'warning: icons path "{0}" does not exist!'.format(path))
            print("")
        else:
            iconsPath = path
    else:
        print(u'warning: Config file "{0}" have no icons path! (attribute "<config icons=""/>")'.format(configFile))
        print("")
        return

    if not iconsPath:
        print("warning: no icons will be loaded for application!")
        print("")
        return

    globals.applicationIconsPath = iconsPath
Esempio n. 5
0
def _readConfigIcons(configFile, configData):
    iconsPath = ''
    if configData.hasAttribute('icons'):
        path = configData.getAttribute('icons')
        path = absPath(path, configFile, True)
        if path is None or len(path) < 1 or not os.path.exists(path):
            print(u'warning: icons path \"{0}\" does not exist!'.format(path))
            print('')
        else:
            iconsPath = path
    else:
        print(
            u'warning: Config file \"{0}\" have no icons path! (attribute \"<config icons=""/>\")'
            .format(configFile))
        print('')
        return

    if not iconsPath:
        print('warning: no icons will be loaded for application!')
        print('')
        return

    globals.applicationIconsPath = iconsPath
Esempio n. 6
0
def _readConfig(args):
    settings = QSettings('Victor Zarubkin', 'Behavior Studio')

    if socket.gethostname().lower() == 'victor':
        settings.beginGroup('startup')
        value = settings.value('showLogo')
        if value is not None:
            value = value.lower()
            if value in ('true', 'false'):
                globals.showLogo = value == 'true'
        settings.endGroup()
    else:
        globals.showLogo = True

    currDir = os.getcwd(
    )  # os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))

    # Reading application config file:
    configFile = None
    data = None

    try_configs = []
    if isinstance(args.config_file, list):
        try_configs = args.config_file
    else:
        try_configs.append(args.config_file)

    okay = False
    err = False
    for conf in try_configs:
        configFile = conf
        data = None

        if not os.path.isabs(configFile):
            configFile = absPath(configFile,
                                 currDir)  # make full path from relative path
        else:
            configFile = toUnixPath(configFile)

        if configFile is None:
            err = True
            print(u'warning: Config file \"{0}\" does not exist!'.format(conf))
            continue

        if not os.path.exists(configFile):
            err = True
            print(u'warning: Config file \"{0}\" does not exist!'.format(
                configFile))
            continue

        dom = parse(configFile)
        data = dom.getElementsByTagName('config')
        if not data:
            err = True
            print(
                u'warning: Config file \"{0}\" is wrong formatted! It must have header \"<config>\".'
                .format(configFile))
            continue

        okay = True
        break

    if not okay:
        print('error: Can\'t load application configuration!')
        print('')
        return False

    globals.loadedApplicationConfigFile = configFile
    if err:
        print('')

    _readConfigIcons(configFile, data[0])
    return True
Esempio n. 7
0
def _readConfig(args):
    settings = QSettings("Victor Zarubkin", "Behavior Studio")

    if socket.gethostname().lower() == "victor":
        settings.beginGroup("startup")
        value = settings.value("showLogo")
        if value is not None:
            value = value.lower()
            if value in ("true", "false"):
                globals.showLogo = value == "true"
        settings.endGroup()
    else:
        globals.showLogo = True

    currDir = os.getcwd()  # os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))

    # Reading application config file:
    configFile = None
    data = None

    try_configs = []
    if isinstance(args.config_file, list):
        try_configs = args.config_file
    else:
        try_configs.append(args.config_file)

    okay = False
    err = False
    for conf in try_configs:
        configFile = conf
        data = None

        if not os.path.isabs(configFile):
            configFile = absPath(configFile, currDir)  # make full path from relative path
        else:
            configFile = toUnixPath(configFile)

        if configFile is None:
            err = True
            print(u'warning: Config file "{0}" does not exist!'.format(conf))
            continue

        if not os.path.exists(configFile):
            err = True
            print(u'warning: Config file "{0}" does not exist!'.format(configFile))
            continue

        dom = parse(configFile)
        data = dom.getElementsByTagName("config")
        if not data:
            err = True
            print(u'warning: Config file "{0}" is wrong formatted! It must have header "<config>".'.format(configFile))
            continue

        okay = True
        break

    if not okay:
        print("error: Can't load application configuration!")
        print("")
        return False

    globals.loadedApplicationConfigFile = configFile
    if err:
        print("")

    _readConfigIcons(configFile, data[0])
    return True
Esempio n. 8
0
    def __openAlphabetFile(self, projdata, the_proj):
        alphs = projdata.getElementsByTagName('alphabet')
        if alphs and alphs[0].hasAttribute('path'):
            plist = self.__getPathWithCommonChecking(alphs[0], the_proj)
            if len(plist) == 2:
                the_proj.alphabet = alphabet.Alphabet()
                if not the_proj.alphabet.load(
                        plist[1]) or len(the_proj.alphabet) < 1:
                    print('warning: Can\'t load alphabet from \'{0}\'!'.format(
                        plist[1]))
                    print('')
                    the_proj.alphabet = None
                else:
                    print('ok: Alphabet file \'{0}\' was loaded successfully'.
                          format(plist[1]))
                    print('')
                    return
            elif plist:
                print('warning: Can\'t load alphabet from \"{0}\".'.format(
                    plist[0]))
            else:
                print('warning: Can\'t load alphabet from \"{0}\".'.format(
                    alphs[0]))

        if the_proj.alphabet is None:
            print('info: Trying to load default behavior alphabet...')
            try_paths = []
            if isinstance(globals.applicationAlphabetPath, list):
                try_paths = globals.applicationAlphabetPath
            else:
                try_paths.append(globals.applicationAlphabetPath)

            okay = False
            err = False
            for path in try_paths:
                the_file = path

                if not os.path.isabs(the_file):
                    the_file = absPath(the_file, globals.rootDirectory
                                       )  # make full path from relative path
                else:
                    the_file = toUnixPath(the_file)

                if the_file is None:
                    err = True
                    print(u'warning: Alphabet file \"{0}\" does not exist!'.
                          format(path))
                    continue

                if not os.path.exists(the_file):
                    err = True
                    print(u'warning: Alphabet file \"{0}\" does not exist!'.
                          format(the_file))
                    continue

                the_proj.alphabet = alphabet.Alphabet()
                if not the_proj.alphabet.load(the_file) or len(
                        the_proj.alphabet) < 1:
                    print('warning: Can\'t load alphabet from \'{0}\'!'.format(
                        the_file))
                    print('')
                    the_proj.alphabet = None
                    continue

                okay = True
                print(
                    'ok: Alphabet file \'{0}\' was loaded successfully'.format(
                        the_file))
                print('')
                return
Esempio n. 9
0
    def __openDiagramShapes(self, projdata, the_proj):
        shapes = projdata.getElementsByTagName('shapelib')
        if shapes and shapes[0].hasAttribute('path'):

            plist = self.__getPathWithCommonChecking(shapes[0], the_proj)

            if len(plist) == 2:
                the_proj.shapelib = shapelib.ShapeLib()
                if not the_proj.shapelib.init(plist[1]):
                    print('warning: Can\'t load shape library from \"{0}\".'.
                          format(plist[1]))
                    the_proj.shapelib = None
            elif plist:
                print(
                    'warning: Can\'t load shape library from \"{0}\".'.format(
                        plist[0]))
            else:
                print(
                    'warning: Can\'t load shape library from \"{0}\".'.format(
                        shapes[0]))

        if the_proj.shapelib is None:
            print('info: Trying to load default diagram shapes...')
            try_paths = []
            if isinstance(globals.applicationShapesPath, list):
                try_paths = globals.applicationShapesPath
            else:
                try_paths.append(globals.applicationShapesPath)

            okay = False
            err = False
            for path in try_paths:
                the_file = path

                if the_file is None:
                    print(
                        'error: Unexpected error: empty path to diagram shapes file!'
                    )
                    continue

                if not os.path.isabs(the_file):
                    print(
                        'debug: generating absPath for \"{0}\" relative to \"{1}\"'
                        .format(the_file, globals.rootDirectory))
                    the_file = absPath(the_file, globals.rootDirectory
                                       )  # make full path from relative path
                else:
                    print('debug: the path \"%s\" is abs!' % the_file)
                    the_file = toUnixPath(the_file)

                if the_file is None:
                    err = True
                    print(
                        u'warning: Diagram shapes file \"{0}\" does not exist!'
                        .format(path))
                    continue

                if not os.path.exists(the_file):
                    err = True
                    print(
                        u'warning: Diagram shapes file \"{0}\" does not exist!'
                        .format(the_file))
                    continue

                the_proj.shapelib = shapelib.ShapeLib()
                if not the_proj.shapelib.init(the_file):
                    print('warning: Can\'t load shape library from \"{0}\".'.
                          format(the_file))
                    the_proj.shapelib = None
                    continue

                okay = True
                return