コード例 #1
0
def _browse_level(type, levels, level, index):
    df = definitionBuilder.Definition()

    _navigation_path(df, type, levels, level, index)
    

    if level is not None:
        # _sl(df)
        lnk, label = _level_link(type, levels, level, index)
        # df.TextElement(label)
        df.setTitle("eBooks by %s (%s)" % (type, label))
    else:
        df.setTitle("eBooks by %s" % type)
        
    df.LineBreakElement()

    if level is None:
        sublevel = 0
        start_index = 0
        end_index = len(levels[0])
    else:
        sublevel = level + 1
        sub_power = levels[sublevel][0][3]
        start_index = int(math.floor(float(levels[level][index][2]) / sub_power))
        end_index = start_index + int(math.floor(float(levels[level][index][3] - sub_power * start_index - 1)/sub_power)) + 1

    subs = levels[sublevel]
    for i in range(start_index, end_index):
        lnk, label = _level_link(type, levels, sublevel, i)
        df.BulletElement(False)
        df.TextElement(label, link = lnk)
        if level is None:
           cnt = subs[i][3] - subs[i][2]
           df.TextElement(" (%s books)" % numPretty(cnt))
        df.PopParentElement()

    df.LineBreakElement()
    df.LineBreakElement(1, 5)
    
    if level is not None:
        prev = False
        if index != 0:
            lnk, lbl = _level_link(type, levels, level, index - 1)
            df.TextElement("Previous", link = lnk).setJustification(definitionBuilder.justCenter)
            prev = True
        
        if index != len(levels[level]) - 1:
            if prev:
                df.TextElement(" ").setJustification(definitionBuilder.justCenter)
            lnk, lbl = _level_link(type, levels, level, index + 1)
            df.TextElement("Next", link = lnk).setJustification(definitionBuilder.justCenter)
    
    return df.serialize()
コード例 #2
0
def _navigation_path(df, type, levels, level, index):
    _home_link(df)

    if level is None:
        txt = "Browse by %s (%s books)" % (type, numPretty(levels[0][-1][3]))
        lnk = None
    else:
        txt = "Browse by %s" % type
        lnk = "eBook: browse: %s" % type
        
    _sl(df)
    df.TextElement(txt, link = lnk)
    if level is None: 
        return

    if level > 0:
        sl = levels[level][index][0][0].upper()
        # el = levels[level][index][1][0].upper()
        zi = 0
        for l in levels[0]:
            if sl >= l[0] and sl <= l[1]:
                zi = levels[0].index(l)
    else:
        zi = index
    
    i = level
    indexes = []
    while i >= 0:
        if i == level:
            indexes.append(index)
        elif i > 0:
            ind = (indexes[-1] * levels[i + 1][0][3]) / levels[i][0][3]
            indexes.append(ind)
        elif 0 == i:
            indexes.append(zi)
        i -= 1
    
    indexes.reverse()
    for i in range(0, len(indexes)):
        lnk, lbl = _level_link(type, levels, i, indexes[i])
        if i == level:
            lnk = None
        _sl(df)
        df.TextElement(lbl, link = lnk)
コード例 #3
0
def _start_page():
    title_levels = _levels_for(BROWSE_TITLE)
    author_levels = _levels_for(BROWSE_AUTHOR)
    total_books = title_levels[0][len(title_levels[0]) - 1][3]

    df = definitionBuilder.Definition()
    df.setTitle("eBooks - Home")
    df.TextElement("%s eBooks available. " % numPretty(total_books))
    df.TextElement("Search", link = "eBook:search")
    df.TextElement(" or browse ")
    df.TextElement("by author", link = "eBook: browse: %s" % (BROWSE_AUTHOR))
    df.TextElement(" or ")
    df.TextElement("by title", link = "eBook: browse: %s" % (BROWSE_TITLE))
    df.TextElement(".")
    df.LineBreakElement()
    df.LineBreakElement(1, 5).setJustification(definitionBuilder.justCenter)
    
    df.TextElement("Browse by author").setJustification(definitionBuilder.justCenter)
    df.LineBreakElement().setJustification(definitionBuilder.justCenter)
    for i in range(0, len(author_levels[0])):
        lnk, label = _level_link(BROWSE_AUTHOR, author_levels, 0, i)
        df.TextElement(label, link = lnk).setJustification(definitionBuilder.justCenter)
        if i != len(author_levels[0]) - 1:
            _dot(df).setJustification(definitionBuilder.justCenter)

    df.LineBreakElement().setJustification(definitionBuilder.justCenter)
    df.LineBreakElement(1, 5).setJustification(definitionBuilder.justCenter)

    df.TextElement("Browse by title").setJustification(definitionBuilder.justCenter)
    df.LineBreakElement().setJustification(definitionBuilder.justCenter)
    for i in range(0, len(title_levels[0])):
        lnk, label = _level_link(BROWSE_TITLE, title_levels, 0, i)
        df.TextElement(label, link = lnk).setJustification(definitionBuilder.justCenter)
        if i != len(title_levels[0]) - 1:
            _dot(df).setJustification(definitionBuilder.justCenter)
    
    df.LineBreakElement().setJustification(definitionBuilder.justCenter)
    df.LineBreakElement(1, 5)
    
    df.TextElement("Manage ")
    df.TextElement("downloaded books", link = "eBook: manage")
    df.TextElement(".")
    return df.serialize()