Beispiel #1
0
        # line has content, now test if it's valid
        data = line.split("=")
        if len(data) == 2:
            # two items means there was an "=", now make sure the bit on the right is a valid color
            colorcode = data[1].strip()
            if RGBcolor.match( colorcode ) : # only checks first 6 digits; junk afterwards can be ignored
                # we now have a valid color (we haven't checked for valid alpha yet)
                color = r"\x" + colorcode[0:2] + r"\x" + colorcode[2:4] + r"\x" + colorcode[4:6]
                if (len(colorcode) > 7) and (AAlpha.match(colorcode[6:8])): color += r"\x" + colorcode[6:8] # add alpha data
                else: color += r"\xff" # if no alpha data, default to ff (no transparency)
                # add the new named color to the palette
                palette[data[0].strip()] = eval("b'"+color+"'") #turn this text string into a byte string when adding to palette dictionary
                print(".",end="")
                sys.stdout.flush()
            else:
                error_log("invalid color: ",colorcode)
        else:
            error_log("invalid palette entry: ",data)
print(" done.")

# COLORIZE THE ASCII ALPHABETS (THE FIRST 256 CHARACTERS) IN THE DEFAULT TEXT COLORS
print("Colorizing fonts.",end="")
alphabets = [ [], [], [] ] # plain, highlighted, and inverted text
for i in range(256):
    alphabets[0].append( generate_colorized_tile( i , palette["plaintext"] , palette["bg"] ) )
    alphabets[1].append( generate_colorized_tile( i , palette["highlight"] , palette["bg"] ) )
    alphabets[2].append( generate_colorized_tile( i , palette["bg"] , palette["plaintext"] ) )
    print(".",end="")
    sys.stdout.flush()
print(" done.")
Beispiel #2
0
from debug import error_log
import sys



# PARSE prefs.txt AND LOAD THE DICTIONARY OF PREFERENCES
print("Loading preferences.",end="")
prefs = {} # a dictionary of preferences
prefsfile = pyglet.resource.file('prefs.txt',"r")
for line in prefsfile:
    line = line.strip().lower()
    if line.find("#") > -1: line = line[:line.find("#")] # remove first "#" and everything after
    if len(line):
        # line has content, now test if it's valid
        data = line.split("=")
        if len(data) == 2:
            # two items means there was an "="
            prefs[ data[0].strip() ] = data[1].strip() # capture the preference (TO DO: better error checking)
            print(".",end="")
            sys.stdout.flush()
        else:
            error_log("invalid preferences entry: ",data)
print(" done.")




if __name__ == "__main__":
    # UNIT TEST CODE
    print(prefs)