09 November 2010

The ultimate colour palette for LibreOffice

Back in 2004, one of the complaints about OpenOffice.org was that it's colour palette was too small. I wrote the following python script, to address that issue.

The resulting colour palette requires roughly one gigabyte of disk space.

#### code starts here ###
#!usr/bin/python
import sys, string

def bump_case(bump_string, bump_direction):
bump_string, atribute_data = clean_string(bump_string, bump_direction)
if atribute_data == "string":
return_string = bump_string
elif atribute_data == "unknown":
bump_string = bump_string[0]
bump_string = convert_unknown_to_string(bump_string)
elif atribute_data == "integer":
return_string = convert_integer_to_string(bump_string)
else:
print " bump_case(bump_string, bump_direction) can not process the following "
print bump_string
print " as it is not a string "
print " It appears to be the following: ", atribute_data
return return_string

def convert_integer_to_string( integer_string ):
integer_string = str(integer_string)
checkpoint = len(integer_string)
return_string, attribute_type = clean_string(integer_string)
return return_string

def convert_unknown_to_string( unknown_string ):
some_string = unknown_string[0]
return_string, attribute_type = clean_string(some_string, "lower" )
return return_string

def clean_string(some_string, bump_direction):
try:
check = len(some_string)
new_string = string.strip ( some_string )
direction_check = string.lower(bump_direction)
if direction_check == "upper":
check_string = string.upper ( new_string)
else:
check_string = string.lower ( new_string )
attribute_type = "string"
except TypeError:
try:
check_string = int(some_string)
attribute_type = "integer"
except:
print "Unknown Error at clean string"
print some_string
print "This is neither a string, nor an integer"
attribute_type = "unknown"
check_string = some_string

def true_false(message_string):
is_valid = "false"
while is_valid == "false":
print_headline(message_string)
print ( 'If this is correct, type "yes". ' )
# , otherwise type "no". ')
temp_string = raw_input()
temp_string = string.strip(temp_string)
temp_string = string.lower(temp_string)
if temp_string in [ "yes", "true", "0", "+", "ja", "y", "good", "g" ]:
check_point = "true"
is_valid = "true"
elif temp_string in [ "no", "false", "1", "-", "nie", "n", "bad", "b" ]:
check_point = "false"
is_valid = "true"
else:
is_valid = "false"
return check_point

def read_input_data( message_string, validation_string ):
check_point = "false"
while check_point == "false":
clear_screen ( 5 )
print message_string
input_string = raw_input()
input_string = string.strip(input_string)
temp_string = ( validation_string + " " + input_string )
check_point = true_false( temp_string )
return input_string

def in_range( check_this_number, low_number, high_number ):
check_this_number = abs(check_this_number)
if check_this_number > high_number:
check_this_number = check_this_number / high_number
if check_this_number < low_number:
check_this_number = check_this_number + high_number
return check_this_number

# file read / write functions

def get_lines_of_file(var_which_file):
check_the_file = (var_which_file, "lower")
try:
input_file_handle = open(check_this_file , "r")
data = input_file_handle.readlines()
break_line_count = len(data)
except:
break_line_count = 0
return break_line_count

def print_a_file(var_which_file, file_suffix, temp_line):
check_point = string.strip(file_suffix)
if check_point == "":
file_suffix = "data"
check_point = string.strip(var_which_file)
if check_point == "":
var_which_file = "default"
file_name = validate_file_name ( var_which_file, file_suffix )
print_to_this_file = file_name
write_line = string.strip(str(temp_line))
data_check = convert_unknown_to_string(print_to_this_file)
print_to_this_file = data_check
check_point = len(write_line)
if check_point > 1:
line_count = get_lines_of_file(print_to_this_file)
if line_count > 0 :
kountry_datafile = open(print_to_this_file, "w")
kountry_datafile.write(write_line + "\n")
kountry_datafile.close()
kounter = 1
else:
kountry_datafile = open(print_to_this_file, "a")
kountry_datafile.write(write_line + "\n")
kountry_datafile.close()
kounter = 0
else:
kounter = 0
return kounter

def validate_file_name( file_prefix, file_suffix ):
file_prefix = clean_string(file_prefix, "lower")
file_suffix = clean_string(file_suffix, "lower")
if len(file_prefix) > 8:
file_prefix = file_prefix[0:7]
if len(file_suffix) > 4:
file_suffix = file_suffix[0:3]
dot = "."
file_suffix = (dot, file_suffix )
return_name = ( file_prefix + file_suffix )
return return_name

def grab_a_file(var_which_file, file_suffix):
file_name = validate_file_name ( var_which_file, file_suffix )
print_to_this_file = file_name
print
print
line_count = get_lines_of_file(print_to_this_file)
if line_count > 0 :
data = open(print_this_file, "r")
datum = data.readlines()
check = len(datum)
if check < line_count:
print " File length mismatch "
elif check > line_count:
print " File length mismatch "
else:
print "file has zero or less lines in it"
print line_count, " is the line_length"
print print_to_this_file
datum = ""
return datum

def initialize_data(size_of_data_field):
initialized_number = -11111
return_list = [ initialized_number ] * size_of_data_field
return return_list


def delete_blanks(check_string):
working_string = string.strip(check_string)
data_length = len(working_string)
date_length = int(data_length)
new_string = " "
for s_checking in range (0, data_length):
am_on = s_checking
s_data = working_string[am_on]
if s_data <> " ":
new_string = (new_string + s_data)
new_string = string.strip(new_string)
return new_string

#
# main sequence starts here
#

def create_hexadecimal_palette(checking_data):
output_file = "ultimate_color_palette.soc"
data_range_2_is = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
palette_string_1 = ''
for first_data in data_range_2_is:
for second_data in data_range_2_is:
for third_data in data_range_2_is:
for fourth_data in data_range_2_is:
for fifth_data in data_range_2_is:
for sixth_data in data_range_2_is:
check_1 = first_data
check_2 = second_data
check_3 = third_data
check_4 = fourth_data
check_5 = fifth_data
check_6 = sixth_data
temp_string = (check_1 + check_2 + check_3 + check_4 + check_5 + check_6)
check_string = (palette_string_1 + temp_string + palette_string_2 + temp_string + palette_string_3)
check_point = print_a_file ( output_file, "data", check_string)
print check_string
return check_point

checking_data = "junk string"
checkpoint = print_a_file ("start_time", "data", checking_data)
b_color = create_hexadecimal_palette(checking_data)
print b_check_data
checkpoint = print_a_file ("end_time", "data", checking_data)
print "The End"
### code ends here ###

Two minor details:
  1. The contents of the file soc_head https://docs.google.com/leaf?id=1sqTcJuFxh8kmZcvBbSrmMWyiTSwVtaF_uFtewVbXfU0&sort=name&layout=list&num=50 needs to be added to the beginning of the file that the script creates;
  2. The contents of the file soc_base https://docs.google.com/leaf?id=1LIkr1-YGFMCIzaM0gNMpL7rajeBMU6Jhe6_5quKKtrQ&sort=name&layout=list&num=50 needs to be added to the end of the file that the script creates;
Finally, Blogger mangled the code written here almost beyond usability. https://docs.google.com/leaf?id=1VjbFsfES_Lgy4HGysyEHuLilocn8W5DYZBds-7Z_1wI&sort=name&layout=list&num=50 has the code, albeit mangled somewhat differently than was done here.

No comments:

Post a Comment