Annotation of lise/Extensions/liseScript.py, revision 1.1.1.1

1.1       wischi      1: import os
                      2: 
                      3: def liseScript(mainobj, idclicked="0"):
                      4:    """ liseScript """
                      5:        
                      6:    pictid = int(idclicked) - 1
                      7:    if pictid < 0:
                      8:        pictid = 0
                      9: 
                     10:    session = mainobj.REQUEST.SESSION
                     11:    openchaplist = session.get("openchaplist", [])
                     12:    newopenchaplist = 0
                     13:    if len(openchaplist) < 1:
                     14:        newopenchaplist = 1
                     15:        for i in pagelist:
                     16:            if i.level == 0:
                     17:                openchaplist.append(1)
                     18:            else:
                     19:                openchaplist.append(0)
                     20:        
                     21: #  openchaplist = []
                     22: #  newopenchaplist = 1
                     23:    
                     24:    pagelist = mainobj.pagelist
                     25:    filelist = mainobj.filenames
                     26:    filelistindex = 0;
                     27:    
                     28:    # fetch the current picture
                     29:    pictfile = ''
                     30:    if IsStr(pagelist[pictid].picturelink):
                     31:        if len(pagelist[pictid].picturelink) > 0:
                     32:            pictfile = pagelist[pictid].picturelink
                     33:        else:
                     34:            if IsInt(pagelist[pictid].pictindex):
                     35:                filelistindex = int(pagelist[pictid].pictindex)
                     36:                pictfile = filelist[filelistindex]
                     37:            else:
                     38:                pictfile = 'this_is the_no_fucking_picture_error'
                     39:    else:
                     40:        if IsInt(pagelist[pictid].pictindex):
                     41:            filelistindex = int(pagelist[pictid].pictindex)
                     42:            pictfile = filelist[filelistindex]
                     43:        else:
                     44:            pictfile = 'this_is the_no_fucking_picture_error'
                     45:    mainobj.currpict = pictfile
                     46: 
                     47:    thelength = len(pagelist)
                     48:    counter = 0
                     49:    currlevel = 0;
                     50:    
                     51:    # build the list which is used to open / close the chapters
                     52:    if pagelist[pictid].type == 'C':
                     53:        for i in pagelist:
                     54:            if newopenchaplist == 0:
                     55:                if counter == pictid:
                     56:                    currlevel = pagelist[counter + 1].level
                     57:                    if openchaplist[counter + 1] == 0:
                     58:                        for j in range(counter + 1, thelength):
                     59:                            if pagelist[j].level < currlevel:
                     60:                                break;
                     61:                            else:
                     62:                                if pagelist[j].level == currlevel:
                     63:                                    openchaplist[j] = 1
                     64:                    else:
                     65:                        if openchaplist[counter + 1] == 1:
                     66:                            for j in range(counter + 1, thelength):
                     67:                                if pagelist[j].level < currlevel:
                     68:                                    break;
                     69:                                else:
                     70:                                    openchaplist[j] = 0
                     71:    
                     72:            counter = counter + 1
                     73:        
                     74: #  return str(counter)
                     75:            
                     76:    bid = session.getBrowserIdManager().getBrowserId()
                     77:    outtext = ""
                     78:    counter = 0
                     79:    for i in pagelist:
                     80:        if openchaplist[counter] == 1:
                     81:            for j in range(0, i.level):
                     82:                    outtext = outtext + "&nbsp;&nbsp;&nbsp;"        
                     83:            outtext = outtext + "<a href=\"main?theid=" + str(i.id) +"\">" + i.name + "</a><br>"
                     84:        counter = counter + 1
                     85:        
                     86:    outtext = outtext + "</p>"
                     87:        
                     88:    # write back list of open pages to session
                     89:    session["openchaplist"] = openchaplist
                     90:    
                     91:    return outtext
                     92:    
                     93: 
                     94: 
                     95: ########################################################################################
                     96: def IsInt(str):
                     97:    """ Is the given string an Integer? """
                     98:    try: int(str)
                     99:    except ValueError:
                    100:        return 0
                    101:    else:
                    102:        return 1
                    103: 
                    104: 
                    105: ########################################################################################
                    106: def IsStr(str):
                    107:    """ Is the given string really a string? """
                    108:    try: str + ''
                    109:    except: return 0
                    110:    else: return 1

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>