Пример #1
0
def build_menu():
    """
    Build the 'mmSolver' menu.
    """
    LOG.info('Building mmSolver Menu...')

    func_config_name = const.CONFIG_FILE_FUNCTIONS_NAME
    func_config = config_utils.get_config(func_config_name)
    if func_config is None:
        LOG.warning('Could not find %s config file', func_config_name)

    menu_config_name = const.CONFIG_FILE_MENU_NAME
    menu_config = config_utils.get_config(menu_config_name)
    if menu_config is None:
        LOG.warning('Could not find %s config file', menu_config_name)

    main_funcs = func_config.get_value('data', default_value={})
    menu_funcs = menu_config.get_value('data/functions', default_value={})
    funcs = [menu_funcs, main_funcs]

    # Create main menu.
    main_parent = menu_utils.get_maya_window_parent()
    mm_menu = menu_utils.create_menu(parent=main_parent,
                                     name=const.MENU_NAME,
                                     tearOff=const.MENU_TEAR_OFF)

    # Create the menu items
    items = menu_config.get_value('data/items', default_value=[])
    items_to_create = lib.compile_items(items, funcs)
    lib.create_items(items_to_create, mm_menu)
    return mm_menu
Пример #2
0
def build(shelf, func_config_name, shelf_config_name):
    """
    Build shelf items with configuration file names.

    :param shelf: Maya shelf UI path.
    :type shelf: str

    :param func_config_name: Function configuration file name.
    :type func_config_name: str

    :param shelf_config_name: Shelf configuration file name.
    :type shelf_config_name: str

    :returns: The Maya shelf UI path.
    :rtype: str
    """
    func_config = config_utils.get_config(func_config_name)
    if func_config is None:
        LOG.warning('Could not find %s config file', func_config_name)

    shelf_config = config_utils.get_config(shelf_config_name)
    if shelf_config is None:
        LOG.warning('Could not find %s config file', shelf_config_name)

    main_funcs = func_config.get_value('data', default_value={})
    shelf_funcs = shelf_config.get_value('data/functions', default_value={})
    funcs = [shelf_funcs, main_funcs]

    # Create the shelf buttons items
    items = shelf_config.get_value('data/items', default_value=[])
    items_to_create = compile_items(items, funcs)
    create_items(items_to_create, shelf)
    return shelf
Пример #3
0
    def test_class_usage3(self):
        """
        Read and write functions using the Config class.

        Turn Auto-Read/Write OFF.
        """
        original_name = 'general.json'
        name = 'general_class_usage3.json'
        path = self.get_data_path('config')
        dir_list = [path]

        src = os.path.join(path, original_name)
        dst = os.path.join(path, name)
        shutil.copy2(src, dst)
        
        config = utils_config.get_config(name, search=dir_list)
        assert config is not None
        config.set_autoread(False)
        config.set_autowrite(False)
        config.read()
        value = config.get_value('myVar')
        assert value == None

        new_value = 42
        config.set_value('myVar', new_value)
        config.write()

        config.read()
        value = config.get_value('myVar')
        assert value == new_value
        return
Пример #4
0
    def test_class_key_hierarchy(self):
        """
        Read and write functions with hierarchy of key values using the
        Config class.

        Using default Auto-Read/Write values.
        """
        original_name = 'general.json'
        name = 'general_class_key_hierarchy.json'
        path = self.get_data_path('config')
        dir_list = [path]

        src = os.path.join(path, original_name)
        dst = os.path.join(path, name)
        shutil.copy2(src, dst)

        config = utils_config.get_config(name, search=dir_list)
        assert config is not None
        key = 'key/subkey/subsubkey'
        value = config.get_value(key)
        assert value == None

        new_value = 42
        config.set_value(key, new_value)

        value = config.get_value(key)
        assert value == new_value

        config.write()
        return
Пример #5
0
    def test_class_usage1(self):
        """
        The easiest read and write functions using the Config class.

        Using default Auto-Read/Write values.
        """
        original_name = 'general.json'
        name = 'general_class_usage1.json'
        path = self.get_data_path('config')
        dir_list = [path]

        src = os.path.join(path, original_name)
        dst = os.path.join(path, name)
        shutil.copy2(src, dst)
        
        config = utils_config.get_config(name, search=dir_list)
        assert config is not None
        value = config.get_value('myVar')
        assert value == None

        new_value = 42
        config.set_value('myVar', new_value)

        value = config.get_value('myVar')
        assert value == new_value
        return