示例#1
0
def merge_dxfs(dxf_paths=None, merged_path=None):
    """ Merging all dxfs from dxf_list to merged_path
    """

    def import_and_save(dxf, target_dxf):
        try:
            source_dwg = ezdxf.readfile(dxf)
        except ezdxf.DXFStructureError:
            print('ФАЙЛ %s НЕ БЫЛ ДОБАВЛЕН!' % dxf)
            print('УДАЛИТЕ ЕГО И ПЕРЕКОНВЕРТИРУЙТЕ ЗАНОВО!')
            return
        importer = ezdxf.Importer(source_dwg, target_dxf)
        importer.import_all()
        target_dxf.save()

    # getting paths from settings (for console version mainly)
    if dxf_paths is None:
        dxf_paths = Settings().get_file_list('xml_folder', '.dxf')
    if merged_path is None:
        merged_path = Settings().merged_dxf

    # Creating clear dxf file
    dwg = ezdxf.new('R2000')
    dwg.saveas(merged_path)

    target_dxf = ezdxf.readfile(merged_path)
    list_of_tasks = [(import_and_save, (dxf, target_dxf)) for dxf in dxf_paths]
    logging.info('merging %s in %s' % (dxf_paths, merged_path))
    execute_list_of_tasks(list_of_tasks, 1)
示例#2
0
def checks_to_formatted_string(checks_list=None, formatted_txt_path=None):
    """ Convert all checks from checks_list and returns result"""
    # getting dict from settings (for console version mainly)
    if checks_list is None:
        checks_list = []
        file_list = Settings().get_file_list('mydxf_folder', '.txt')
        for file in file_list:
            with open(file) as f:
                j = json.load(f)
                checks_list.append(j)

    checks_dict = {}  # Will contain merged checks from checks_list
    # start populating checks_dict
    for j in checks_list:
        for k, v in j.items():
            if k in checks_dict:
                checks_dict[k] |= set(v)
            else:
                checks_dict[k] = set(v)
    # converting values from list to string, formatted with '; '
    for k, v in checks_dict.items():
        checks_dict[k] = '; '.join(sort_result(v))
    # saving to file
    if formatted_txt_path is not None:
        with open(Settings().formatted_txt, 'w') as f:
            json.dump(checks_dict, f, indent=' ')

    return json.dumps(checks_dict, indent=' ')
示例#3
0
def check_mydxfs(mydxf_paths=None, xml_paths=None):
    """ Checks all mydxf files from mydxf_paths in xml files from xml_paths """

    # getting paths from settings (for console version mainly)
    if mydxf_paths is None:
        mydxf_paths = Settings().get_file_list('mydxf_folder', '.dxf')
    if xml_paths is None:
        xml_paths = Settings().get_file_list('xml_folder', '.xml')

    list_of_MyDxfFiles = get_list_of_MyDxfFiles(mydxf_paths)
    list_of_tasks = [(i.checks, (xml_paths,)) for i in list_of_MyDxfFiles]
    logging.info('checking %s in %s' % (mydxf_paths, xml_paths))
    execute_list_of_tasks(list_of_tasks, 5)
    checks_to_formatted_string(formatted_txt_path=Settings().formatted_txt)
示例#4
0
def menu():
    cls()
    settings = Settings()

    help_screen(settings)

    while True:
        inp = short_input()
        settings.check_paths()
        if inp == '1':
            cls()
            actions.check_mydxfs()
        elif inp == '2':
            cls()
            actions.pretty_rename_xmls()
        elif inp == '3':
            cls()
            actions.convert_xmlfiles_to_dxffiles()
        elif inp == '4':
            cls()
            actions.merge_dxfs()
        elif inp in ('q', 'Q'):
            cls()
            break
        elif inp in ('h', 'H'):
            cls()
            help_screen(settings)
示例#5
0
 def save_checks_to_file(self, checks):
     """ Saves SORTED check() result to file and prints in console """
     basename = os.path.basename(self.file_path).replace('.dxf', '.txt')
     output_path = os.path.join(
         Settings().settings['paths']['mydxf_folder'], basename)
     logging.info('checks for file %s saved to %s' %
                  (self.file_path, output_path))
     with open(output_path, 'w') as file:
         json.dump(checks, file, indent=' ')
示例#6
0
def get_list_of_MyDxfFiles(mydxf_paths=None):
    """ Returns list of XmlFile class objects from mydxf_paths """
    # getting paths from settings (for console version mainly)
    if mydxf_paths is None:
        mydxf_list = Settings().get_file_list('mydxf_folder', '.dxf')
    else:
        mydxf_list = mydxf_paths

    res = []
    for file in mydxf_list:
        mydxf_file = MyDxfFile(file)
        res.append(mydxf_file)
    return res
示例#7
0
def get_list_of_XmlFiles(xml_paths=None):
    """ Returns list of XmlFile class objects from xml_paths """

    # getting paths from settings (for console version mainly)
    if xml_paths is None:
        xml_paths = Settings().get_file_list('xml_folder', '.xml')
    logging.info('getting list of XmlFiles from %s' % xml_paths)

    res = []
    for file in xml_paths:
        xml_file = XmlFile(file)
        res.append(xml_file)
    return res
}

sg.LOOK_AND_FEEL_TABLE['MagicMagnetDark'] = {
    'BACKGROUND': '#292929',
    'TEXT': '#cccccc',
    'INPUT': '#dfe2e8',
    'TEXT_INPUT': '#000000',
    'SCROLL': '#c7e78b',
    'BUTTON': ('white', '#ff0000'),
    'PROGRESS': ('white', 'black'),
    'BORDER': 0,
    'SLIDER_DEPTH': 0,
    'PROGRESS_DEPTH': 0,
}

settings = Settings()
setting = settings.read_settings()

sg.change_look_and_feel(setting['theme'])

mainLayout = [
    [sg.Text('\n', font=('Segoe UI Light', 5))],
    [
        sg.Text('  Magic Magnet',
                font=('Segoe UI Light', 24),
                text_color='#ff0000',
                justification='left'),
        sg.Image('icon.png')
    ], [sg.Text('    Search for something', font=('Segoe UI Light', 14))],
    [sg.Text('\n', font=('Segoe UI Light', 1))],
    [