Ejemplo n.º 1
0
    def show_decoded(self):
        def _str_gr(gr):
            if not gr == '-':
                gr = 'gr%s' % gr
            return gr

        col_width = 8
        data = self.decode()
        for day, schedule in data.iteritems():
            print '\n', WEEK_DAYS[day]
            print len(WEEK_DAYS[day]) * '='
            header = [['sala %s' % room, col_width] for room in schedule[0].keys()]
            puts(columns(*header))
            for room_group in schedule.itervalues():
                row = [[_str_gr(gr), col_width] for gr in room_group.itervalues()]
                puts(columns(*row))
Ejemplo n.º 2
0
def print_goal(goal, achieved=False, level=None, indent=2):
    """ Print a goals description with its icon. Achieved (True/False) will choose the correct icon
    from the goal. If a level is specified, a tracker line will be added under the icon showing
    the current level out of the required level for the goal. If level is > the required level,
    achieved will be set to true.
    """
    from clint.textui import puts
    from clint.textui import indent as _indent
    from clint.textui.cols import columns, console_width
    if level is not None and level >= goal['level']:
        achieved = True
    icon = (goal['icon'].achieved() if achieved else goal['icon'].unachieved()).split('\n')
    maxiw = max([len(str(_)) for _ in icon])
    descw = console_width({})-maxiw-(indent + 4)
    desc = '{0}\n{1}\n\n{2}'.format(goal['name'], '-'*len(goal['name']),
                                    columns([goal['description'], descw])).split('\n')
    if level is not None:
        if level > goal['level']:
            level = goal['level']
        maxitw = max([len(_) for _ in icon])
        icon.append(("%d/%d" % (level, goal['level'])).center(maxitw))
    with _indent(indent):
        for i, d in _zip_longest(icon, desc):
            puts("{1:{0}}    {2}".format(maxiw, str(i) if i is not None else "",
                                         d.strip() if d is not None else ""))
Ejemplo n.º 3
0
def print_goal(goal, achieved=False, level=None, indent=2):
    """ Print a goals description with its icon. Achieved (True/False) will choose the correct icon
    from the goal. If a level is specified, a tracker line will be added under the icon showing
    the current level out of the required level for the goal. If level is > the required level,
    achieved will be set to true.
    """
    from clint.textui import puts
    from clint.textui import indent as _indent
    from clint.textui.cols import columns, console_width
    if level is not None and level >= goal['level']:
        achieved = True
    icon = (goal['icon'].achieved()
            if achieved else goal['icon'].unachieved()).split('\n')
    maxiw = max([len(str(_)) for _ in icon])
    descw = console_width({}) - maxiw - (indent + 4)
    desc = '{0}\n{1}\n\n{2}'.format(goal['name'], '-' * len(goal['name']),
                                    columns([goal['description'],
                                             descw])).split('\n')
    if level is not None:
        if level > goal['level']:
            level = goal['level']
        maxitw = max([len(_) for _ in icon])
        icon.append(("%d/%d" % (level, goal['level'])).center(maxitw))
    with _indent(indent):
        for i, d in _zip_longest(icon, desc):
            puts("{1:{0}}    {2}".format(maxiw,
                                         str(i) if i is not None else "",
                                         d.strip() if d is not None else ""))
Ejemplo n.º 4
0
    def _render_category_choice_view(self, paginator, current_page, info,
                                     highlighted_item):
        self._clear_screen()

        puts_header("Choose a category")

        puts_key_value("Current category", colored.yellow(info['Category']))

        puts(colored.green("-" * 80))

        puts_key_value("Main categories", "[A]ll, [I]nstalled")
        puts_key_value("Order by", "Na[m]e, Pac[K]ages")

        categories = paginator.page(current_page)
        starting_index = paginator.pagination * (current_page - 1)

        pagination_tpl = "Page %s of %s" % (current_page, paginator.num_pages)

        puts(colored.green("-" * 80), newline=False)
        puts(pagination_tpl)
        puts(colored.green("-" * 80))

        for index, category in enumerate(categories):

            quote = "%s)" % str(starting_index + index + 1)
            if index + 1 == highlighted_item:
                quote += " * "

            with indent(indent=6, quote=quote):
                title = colored.green(category.title)

                #title += "[%s]" %len(category.packages)

                puts(columns([title, 40], [
                    colored.yellow("[%s packages]" % len(category.packages)),
                    40
                ]),
                     newline=False)

            #puts("%s" %category.description or "")

            puts()

            #with indent(indent=6):
            #    puts_key_value("Packages", "%s" %len(category.packages))
            #puts("%s" %category.description)

        puts(colored.green("-" * 80), newline=False)
        puts(pagination_tpl)
        puts(colored.green("-" * 80))
    def _render_category_choice_view(self, paginator, current_page, info, highlighted_item):
        self._clear_screen()

        puts_header("Choose a category")

        puts_key_value("Current category", colored.yellow(info['Category']))

        puts(colored.green("-"*80))

        puts_key_value("Main categories", "[A]ll, [I]nstalled")
        puts_key_value("Order by","Na[m]e, Pac[K]ages")


        categories = paginator.page(current_page)
        starting_index = paginator.pagination*(current_page-1)

        pagination_tpl = "Page %s of %s" %(current_page, paginator.num_pages)

        puts(colored.green("-"*80), newline=False)
        puts(pagination_tpl)
        puts(colored.green("-"*80))

        for index, category in enumerate(categories):

            quote = "%s)" %str(starting_index+index+1)
            if index+1 == highlighted_item:
                quote += " * "

            with indent(indent=6, quote=quote):
                title = colored.green(category.title)

                #title += "[%s]" %len(category.packages)

                puts(columns([title, 40], [colored.yellow("[%s packages]" %len(category.packages)), 40]), newline=False)

            #puts("%s" %category.description or "")

            puts()

            #with indent(indent=6):
            #    puts_key_value("Packages", "%s" %len(category.packages))
                #puts("%s" %category.description)

        puts(colored.green("-"*80), newline=False)
        puts(pagination_tpl)
        puts(colored.green("-"*80))
Ejemplo n.º 6
0
    def _render_package_list(self, paginator, current_page, info,
                             highlighted_item):
        self._clear_screen()

        puts_header("Listing packages")
        for key, val in info.items():
            if key == 'Category':
                puts_key_value(key, colored.magenta(str(val)))
            else:
                puts_key_value(key, str(val))

        puts(colored.green("-" * 80))

        #puts_key_value("Main categories", "[A]ll, [I]nstalled")
        puts_key_value("Order by", "Na[m]e, [I]nstalled, [U]sage, [W]atchers")

        packages = paginator.page(current_page)
        starting_index = paginator.pagination * (current_page - 1)

        pagination_tpl = "Page " + colored.yellow(
            "%s" % current_page) + " of %s" % paginator.num_pages

        if self.main_view.get('ordering'):
            pagination_tpl += " - Ordering by: " + colored.yellow(
                self.main_view.get('ordering'))

        puts(colored.green('-' * 80), newline=False)
        puts(pagination_tpl)
        puts(colored.green('-' * 80))

        for index, package in enumerate(packages):

            with indent(indent=6,
                        quote="%s)" % str(starting_index + index + 1)):
                title = colored.green(package.title)

                if index + 1 == highlighted_item:
                    title = " * " + title

                if package.installed:
                    if not package.installed_version:
                        # There is no package version! We can't deduce if a new version is really available.
                        title += colored.yellow(" [Installed] ")
                    else:
                        # Package version is there. Everything normal and good!
                        title += colored.yellow(" [Installed %s] " %
                                                package.installed_version)
                        if versioner(package.installed_version) < versioner(
                                package.pypi_version):
                            title += colored.red(" [New version %s] " %
                                                 package.pypi_version)
                puts(title)

            info = {
                "downloads": package.pypi_downloads,
                #"forks": package.repo_forks,
                "watching": package.repo_watchers,
                "using": package.usage_count,
            }
            cols = [[colored.white("%s %s" % (value, key)), 20]
                    for key, value in info.items()]

            with indent(indent=6):
                #puts()
                puts(columns(*cols))

            puts()

        puts(colored.green('-' * 80), newline=False)
        puts(pagination_tpl)
        puts(colored.green('-' * 80))
    def _render_package_list(self, paginator, current_page, info, highlighted_item):
        self._clear_screen()

        puts_header("Listing packages")
        for key,val in info.items():
            if key == 'Category':
                puts_key_value(key, colored.magenta(str(val)))
            else:
                puts_key_value(key, str(val))

        puts(colored.green("-"*80))

        #puts_key_value("Main categories", "[A]ll, [I]nstalled")
        puts_key_value("Order by","Na[m]e, [I]nstalled, [U]sage, [W]atchers")


        packages = paginator.page(current_page)
        starting_index = paginator.pagination*(current_page-1)

        pagination_tpl = "Page " + colored.yellow("%s" %current_page) + " of %s" %paginator.num_pages

        if self.main_view.get('ordering'):
            pagination_tpl += " - Ordering by: " + colored.yellow(self.main_view.get('ordering'))

        puts(colored.green('-'*80), newline=False)
        puts(pagination_tpl)
        puts(colored.green('-'*80))

        for index, package in enumerate(packages):

            with indent(indent=6, quote="%s)" %str(starting_index+index+1)):
                title = colored.green(package.title)

                if index+1 == highlighted_item:
                    title = " * " + title


                if package.installed:
                    if not package.installed_version:
                        # There is no package version! We can't deduce if a new version is really available.
                        title += colored.yellow(" [Installed] ")
                    else:
                        # Package version is there. Everything normal and good!
                        title += colored.yellow(" [Installed %s] " %package.installed_version)
                        if versioner(package.installed_version) < versioner(package.pypi_version):
                            title += colored.red(" [New version %s] " %package.pypi_version)
                puts(title)

            info = {
                "downloads": package.pypi_downloads,
                #"forks": package.repo_forks,
                "watching": package.repo_watchers,
                "using": package.usage_count,
                }
            cols = [[colored.white("%s %s" %(value, key)), 20] for key,value in info.items()]

            with indent(indent=6):
                #puts()
                puts(columns(*cols))

            puts()


        puts(colored.green('-'*80), newline=False)
        puts(pagination_tpl)
        puts(colored.green('-'*80))