How to use the handprint.styled.styled function in handprint

To help you get started, we’ve selected a few handprint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caltechlibrary / handprint / handprint / manager.py View on Github external
orig_fmt = response.headers.get_content_subtype()
            base = '{}-{}'.format(base_name, index)
            # If we weren't given an output dir, then for URLs, we have no
            # choice but to use the current dir to download the file.
            # Important: don't change self._output_dir because if other
            # inputs *are* files, then those files will need other output dirs.
            if not output_dir:
                output_dir = os.getcwd()
            file = path.realpath(path.join(output_dir, base + '.' + orig_fmt))
            if not download_file(item, file):
                warn('Unable to download {}', item)
                return (None, None)
            url_file = path.realpath(path.join(output_dir, base + '.url'))
            with open(url_file, 'w') as f:
                f.write(url_file_content(item))
                inform('Wrote URL to {}', styled(relative(url_file), 'white_on_gray'))
        else:
            file = path.realpath(path.join(os.getcwd(), item))
            orig_fmt = filename_extension(file)[1:]

        if not path.getsize(file) > 0:
            warn('File has zero length: {}', relative(file))
            return (None, None)

        if __debug__: log('{} has original format {}', relative(file), orig_fmt)
        return (file, orig_fmt)
github caltechlibrary / handprint / handprint / __main__.py View on Github external
def print_intro(ui):
    if ui.use_color():
        cb = ['chartreuse', 'bold']
        name = styled('Handprint', cb)
        acronym = '{}written {}age {}ecognit{}o{} {}est'.format(
            styled('Hand', cb), styled('p', cb), styled('r', cb),
            styled('i', cb), styled('n', cb), styled('t', cb))
    else:
        name = 'Handprint'
        acronym = 'HANDwritten Page RecognItioN Test'
    inform('┏' + '━'*68 + '┓')
    inform('┃    Welcome to {}, the {}!    ┃', name, acronym)
    inform('┗' + '━'*68 + '┛')
github caltechlibrary / handprint / handprint / __main__.py View on Github external
def print_intro(ui):
    if ui.use_color():
        cb = ['chartreuse', 'bold']
        name = styled('Handprint', cb)
        acronym = '{}written {}age {}ecognit{}o{} {}est'.format(
            styled('Hand', cb), styled('p', cb), styled('r', cb),
            styled('i', cb), styled('n', cb), styled('t', cb))
    else:
        name = 'Handprint'
        acronym = 'HANDwritten Page RecognItioN Test'
    inform('┏' + '━'*68 + '┓')
    inform('┃    Welcome to {}, the {}!    ┃', name, acronym)
    inform('┗' + '━'*68 + '┛')
github caltechlibrary / handprint / handprint / main_body.py View on Github external
num_targets = len(targets)

        inform('Will apply {} service{} ({}) to {} image{}.',
               len(services), 's' if len(services) > 1 else '',
               ', '.join(services), num_targets, 's' if num_targets > 1 else '')
        if self._extended:
            inform('Will save extended results.')
        inform('Will use up to {} process threads.', threads)

        # Get to work.
        if __debug__: log('initializing manager and starting processes')
        manager = Manager(services, threads, output_dir, make_grid, compare, extended)
        print_separators = num_targets > 1
        for index, item in enumerate(targets, start = 1):
            if print_separators:
                inform(styled('━'*70, 'dark'))
            manager.run_services(item, index, base_name)
        if print_separators:
            inform(styled('━'*70, 'dark'))
github caltechlibrary / handprint / handprint / manager.py View on Github external
def run_services(self, item, index, base_name):
        '''Run all requested services on the image indicated by "item", using
        "index" and "base_name" to construct a download copy of the item if
        it has to be downloaded from a URL first.
        '''
        # Shortcuts to make the code more readable.
        services = self._services

        inform('Starting on {}', styled(item, 'white'))
        try:
            (item_file, item_fmt) = self._get(item, base_name, index)
            if not item_file:
                return

            dest_dir = self._output_dir if self._output_dir else path.dirname(item_file)
            if not writable(dest_dir):
                alert('Cannot write output in {}.', dest_dir)
                return

            # Normalize input image to the lowest common denominator.
            image = self._normalized(item, item_fmt, item_file, dest_dir)
            if not image.file:
                warn('Skipping {}', relative(item_file))
                return