from __future__ import division
#import PngImagePlugin
import FileSystem as FS
from ArgumentParser import ArgumentParser
from PIL import Image
import glob, os
import copy
from PIL import ImageDraw, ImageChops, ImageColor, ImageEnhance
import OlexVFS
#import olex_core
import pickle
import RoundedCorners
import sys
#from olexex import OlexVariables
#OV = OlexVariables()
#OV = olexex.OlexFunctions()
import gui
import olexex
from ImageTools import ImageTools
from ImageTools import IT
from olexFunctions import OlexFunctions
from ArgumentParser import ArgumentParser
from ImageTools import IT
OV = OlexFunctions()
import olex_fs
global dpi_scale
if OV.HasGUI():
import olex_gui
dpi_scale = olex_gui.GetPPI()[0]/96
else:
dpi_scale = 1
import olx
import time
global isPro
global timage_blanks
timage_blanks = {}
#debug = bool(OV.GetParam('olex2.debug',False))
debug = False
global dpi_scaling
dpi_scaling = OV.GetParam('gui.dpi_scaling')
olx.banner_slide = {}
try:
import olx
import olex
datadir = olx.DataDir()
basedir = olx.BaseDir()
# newdir = r"%s\etc\$tools" %datadir
# if not os.path.isdir(newdir):
# _mkdir(newdir)
except:
pass
#self.params.html.highlight_colour.rgb = self.params.html.highlight_colour.rgb
#self.params.html.bg_colour.rgb = self.params.html.bg_colour.rgb
#self.params.html.table_bg_colour.rgb = self.params.html.table_bg_colour.rgb
#self.params.html.font_colour.rgb = self.params.html.font_colour.rgb
#self.params.logo_colour.rgb = self.params.logo_colour.rgb
#self.params.html.link_colour.rgb = self.params.html.link_colour.rgb
#self.params.html.input_bg_colour.rgb = self.params.html.input_bg_colour.rgb
#self.params.html.base_colour.rgb = self.params.html.base_colour.rgb
#self.params.html.table_firstcol_colour.rgb = self.params.html.table_firstcol_colour.rgb
#self.params.button_colouring.rgb = self.params.button_colouring.rgb
#self.params.grey.rgb = self.params.grey.rgb
#self.params.green.rgb = self.params.green.rgb
#self.params.red.rgb = self.params.red.rgb
#self.params.html.base_colour.rgb = self.params.html.base_colour.rgb
class ButtonMaker(ImageTools):
def __init__(self, btn_dict, type="Generic"):
super(ButtonMaker, self).__init__()
self.params = OV.GuiParams()
self.type = type
self.btn_dict = btn_dict
self.max_width = OV.FindValue('gui_htmlpanelwidth', 400)
def run(self):
if self.type == "Generic":
im = self.GenericButtonMaker()
if self.type == "cbtn":
im = self.cbtn()
def GenericButtonMaker(self, font_name = "Vera", font_size = 14):
if self.params.image_font_name:
font_name = self.params.image_font_name
if self.params.button_font_name:
font_name = self.params.button_font_name
icon_height = int(OV.GetParam('gui.skin.icon_size')) * 0.9
height = int(icon_height)
width = int(icon_height * 1.1)
font_colours = {'H':(220,220,220),'C':(100,100,100),'N':(0,80,180),'O':(230,0,5),'AddH':(50,255,50),'-H':(230,0,5), }
for btn in self.btn_dict:
width = self.btn_dict[btn].get('width', 18)
font_size = self.btn_dict[btn].get('font_size', 14)
d = self.btn_dict[btn]
image_prefix = d.get("image_prefix", "")
height = d.get("height", height)
bgcolour = d.get("bgcolour", self.params.html.bg_colour.rgb)
txt = d['txt']
name = d.get('name', txt)
fontcolouroff = d.get("fontcolouroff", None)
fontcolouron = d.get("fontcolouron", None)
grad = d.get('grad', False)
grad_colour = IT.adjust_colour(self.params.html.base_colour.rgb, luminosity = 2.1)
outline_colour = d.get("outline_colour", self.params.html.table_bg_colour.rgb)
continue_mark = d.get('continue_mark', False)
states = d.get('states', [""])
vline = d.get('vline', False)
align = d.get('align', 'centre')
valign = d.get('valign', ("middle", 0.8))
font_name = d.get('font_name', 'Vera')
top_left = d.get('top_left', (0,0))
titleCase = d.get('titleCase', False)
lowerCase = d.get('lowerCase', False)
arrow = d.get('arrow', False)
showtxt = d.get('showtxt', True)
whitespace_bottom = d.get('whitespace_bottom', False)
whitespace_right = d.get('whitespace_right', False)
try:
width,number_minus,fixed = d.get("width", (width,(0,0),0))
number = number_minus[0]
minus = number_minus[1]
if width == "auto":
width = int(self.params.htmlpanelwidth)-(number * minus)
width = (width/number-9)
if vline:
vline.setdefault('position', width - 20)
OV.SetParam('olex2.main_toolbar_vline_position', int(width - OV.GetParam('gui.timage.cbtn.vline')))
except:
width = int(width)
size = (int(width), int(height))
for state in states:
font_colour = self.params.html.font_colour.rgb
bgcolour = d.get('bgcolour%s' %state, bgcolour)
if txt in ["report", "solve", "draw", "refine"]:
font_colour = d.get("fontcolour%s" %state, font_colour)
#font_colour = IT.adjust_colour(font_colour, luminosity=0.7)
image = Image.new('RGBA', size, bgcolour)
draw = ImageDraw.Draw(image)
if grad:
IT.gradient_bgr(draw,
width,
height,
colour = grad.get('grad_colour', bgcolour),
fraction=grad.get('fraction', 1),
increment=grad.get('increment', 10),
step=grad.get('step', 1)
)
if continue_mark:
if state == "on":
self.add_continue_triangles(draw, width, height, style=('single', 'up', font_colour))
elif state == 'off':
self.add_continue_triangles(draw, width, height, style=('single', 'down', font_colour))
elif state == 'inactive':
self.add_continue_triangles(draw, width, height, style=('single', 'down', font_colour))
if arrow:
if state == "off":
IT.create_arrows(image, draw, height, direction="down", h_space=8, v_space=8, colour=font_colour, type='simple')
elif state == "on":
IT.create_arrows(image, draw, height, direction="up", h_space=8, v_space=8, colour=font_colour, type='simple')
elif state == "inactive":
IT.create_arrows(image, draw, height, direction="down", h_space=8, v_space=8, colour=font_colour, type='simple')
if vline:
if state == "on" or state == "off":
if grad:
colour = IT.adjust_colour(grad_colour, luminosity=1)
else:
colour = outline_colour
IT.add_vline(draw, height=vline.get('height',10), h_pos=vline.get('position',10), v_pos=vline.get('v_pos',2), colour = colour, weight=1,) # colour = IT.adjust_colour(bgcolour, luminosity=1.8))
else:
IT.add_vline(draw, height=vline.get('height',10), h_pos=vline.get('position',10), v_pos=vline.get('v_pos',2), colour = font_colour, weight=1,)
if showtxt:
IT.write_text_to_draw(draw, txt,
font_name=font_name,
font_size=font_size,
font_colour=font_colour,
top_left=top_left,
align=align,
max_width=image.size[0],
image_size = image.size,
titleCase=titleCase,
lowerCase=lowerCase,
valign=valign,
)
if txt not in ["report", "solve", "draw", "refine"]:
if state == "on":
outline_colour = self.params.html.highlight_colour.rgb
draw.rectangle((0, 0, image.size[0]-1, image.size[1]-1), outline=outline_colour)
#dup = ImageChops.duplicate(image)
#dup = ImageChops.invert(dup)
#dup = ImageChops.offset(dup, 1, 1)
#image = ImageChops.blend(image, dup, 0.05)
if whitespace_right:
image = IT.add_whitespace(image=image, side='right',
weight=whitespace_right.get('weight',0),
colour=whitespace_right.get('colour','#ffffff'))
if whitespace_bottom:
image = IT.add_whitespace(image=image, side='bottom',
weight=whitespace_bottom.get('weight',0),
colour=whitespace_bottom.get('colour','#ffffff'))
#image = IT.add_whitespace(image=image, side='bottom', weight=1, colour = IT.adjust_colour("bg", luminosity = 0.95))
OlexVFS.save_image_to_olex(image,'%s-%s%s.png' %(image_prefix, name, state), 2)
class GuiSkinChanger(ImageTools):
def __init__(self, tool_fun=None, tool_arg=None):
super(GuiSkinChanger, self).__init__()
self.params = OV.GuiParams()
self.fun = tool_fun
self.param = tool_fun
def setOlexColours(self):
import olex
#OV.SetGrad()
def setGuiProperties(self):
olex.m("SetMaterial InfoBox.Text 2309;1,1,1,1;1,1,1,1")
olex.m("SetMaterial InfoBox.Plane 3077;0,0,0,1;1,1,1,0.5")
olex.m("SetFont Notes #olex2.fnt:frb_10")
olex.m("SetFont Default #olex2.fnt:frb_12")
olex.m("htmguifontsize %s" %OV.GetParam('HtmlGuiFontSize'))
olex.m("showwindow help false")
#olex.m("grad true")
def setGuiAttributesDefault(self):
return
def run_GuiSkinChanger(self):
verbose = OV.GetParam('olex2.verbose')
path = r"src/default.png"
skin = self.params.skin.name
skin_extension = self.params.skin.extension
if skin_extension == "None": skin_extension = None
config = {}
if "#" in skin:
#self.set_custom(skin)
#self.setGuiAttributes()
self.setGuiAttributesDefault()
self.setOlexColours()
path = r"src/default.png"
from PIL import PilTools
elif "(" in skin:
self.set_custom(skin)
self.setGuiAttributesDefault()
self.setOlexColours()
path = r"src/default.png"
from PIL import PilTools
#elif skin == "default":
#self.setGuiAttributesDefault()
#self.setGuiAttributes()
#self.setOlexColours()
#path = r"src/default.png"
#import PilTools
## this is a 'named' skin - ie should have a plugin-folder associated with it
else:
self.setGuiAttributesDefault()
skinpath = r"%s/util/pyUtil/PluginLib/skins/plugin-%sSkin" %(self.basedir, skin)
# First try to load the skin extension.
extensionFile = None
files = []
if skin_extension:
try:
extensionFile = open(r"%s/config%s.txt" %(skinpath, skin_extension), 'r')
files.append(extensionFile)
except:
print "Skin definition file\n%s/config%s.txt\nnot found!" %(skinpath, skin_extension)
# Then load the actual named skin.
path = r"%s/config.txt" %(skinpath)
if os.path.exists(path):
rFile = open(path, 'r')
else:
print "The file %s can not be found" %path
extensionFile.close()
return
files.append(rFile)
for file in files:
for line in file:
line= line.strip()
if line.startswith("#"): continue
l = line.split("=")
if len(l) > 1:
config.setdefault(l[0].strip(), l[1].strip())
file.close()
try:
sys.path.append("%s/util/pyUtil/PluginLib/Skins/plugin-%sSkin" %(olx.BaseDir(), skin))
PilTools = __import__("PilTools_%s" %skin)
if verbose:
print "Using %s skin." %"PilTools_%s" %(skin)
except ImportError, err:
print "Import Error: %s (Now Using Default PilTools)" %err
import PilTools
except Exception, err:
raise
#self.params.html.base_colour.rgb = config.get('GUI_HTMLself.params.html.base_colour.rgb', '#0000ff')
self.setGuiAttributes(config)
self.setOlexColours()
self.resize_skin_logo(self.params.htmlpanelwidth)
#sNumTitle_instance.run_sNumTitle()
#timage_instance.run_timage()
width = OV.FindValue('gui_htmlpanelwidth')
#olx.HtmlPanelWidth(width)
self.setGuiProperties()
OV.UpdateHtml()
#olex.m('panel')
def set_custom(self, colour=None):
if not colour:
colour = olx.Color('hex')
else:
if "," in colour:
c = colour.strip("'")
c = c.strip("(")
c = c.strip(")")
c = c.split(",")
l = []
for item in c:
l.append(int(item.strip()))
colour = tuple(l)
if type(colour) != str:
colour = self.RGBToHTMLColor(colour)
#self.params.html.bg_colour.rgb = "#ffffff"
#self.params.html.font_colour.rgb = self.RGBToHTMLColor(IT.adjust_colour(colour, hue = 180, luminosity = 0.8))
#self.params.html.link_colour.rgb = "#6f6f8b"
#self.params.html.table_bg_colour.rgb = self.RGBToHTMLColor(IT.adjust_colour(colour, luminosity = 2))
#self.params.html.table_firstcol_colour.rgb = self.RGBToHTMLColor(IT.adjust_colour(colour, luminosity = 1.8))
#inputself.params.html.bg_colour.rgb = self.RGBToHTMLColor(IT.adjust_colour(colour, luminosity = 1.9))
#self.params.html.base_colour.rgb = self.RGBToHTMLColor(IT.adjust_colour(colour, luminosity = 0.9))
class MatrixMaker(ImageTools):
def __init__(self):
super(MatrixMaker, self).__init__()
self.params = OV.GuiParams()
#from PIL import PngImagePlugin
#from PIL import Image
#from PIL import ImageDraw, ImageChops
def make_3x3_matrix_image(self, name, matrix, text_def="", state=''):
if state == "on":
bgcolor = OV.GetParam('gui.html.highlight_colour').rgb
if state == "off":
bgcolor = '#dedede'
width = 52
height = 55
size = (width, height)
font_name = "Arial"
font_size = 13
font = IT.registerFontInstance(font_name, font_size)
line_heigth = font_size -2
im = Image.new('RGBA', size, bgcolor)
draw = ImageDraw.Draw(im)
m = []
i = 0
max_width = 0
for item in matrix:
if i == 9: break
try:
item = int(item)
except:
item = item
txt_size = draw.textsize(str(item), font=font)
w = txt_size[0]
if w > max_width:
max_width = w
i += 1
if max_width < 15: max_width = 15
i = 0
for item in matrix:
if i == 9: break
try:
item = int(item)
except:
item = item
m.append(item)
i += 1
i = 0
j = 0
k = 0
for item in m:
if i < 3:
j = i
elif i == 3:
j = 0
k = 1
elif i < 6:
j = (i-3)
elif i == 6:
j = 0
k = 2
else:
j = (i-6)
txt_size = draw.textsize(str(item), font=font)
begin = ((j * max_width) + ((max_width - txt_size[0])), k * line_heigth)
if item == -1:
colour = (255, 0, 0)
else:
colour = (100, 100, 100)
draw.text(begin, "%s" %item, font=font, fill=colour)
i += 1
font_size = 10
line_heigth = font_size -2
font_name = "Arial"
font = IT.registerFontInstance(font_name, font_size)
for i in xrange(len(text_def)):
item = text_def[i].get('txt',"")
colour = text_def[i].get('font_colour',"")
w = draw.textsize(str(item), font=font)[0]
draw.text(((width-w)/2, 35 + line_heigth * i), "%s" %item, font=font, fill=(colour))
namestate = r"%s%s.png" %(name, state)
name = r"%s" %(name)
OlexVFS.save_image_to_olex(im, namestate)
if state == "off":
OlexVFS.save_image_to_olex(im, "%s.png" %name)
return name, im
def fade_image(image, frames=5, overlay_colour=(255, 255, 255), filename="out.gif"):
from PIL import Image
import gifmaker
size = image.size
overlay = Image.new('RGBA', size, overlay_colour)
sequence = []
for i in range(frames):
im = Image.blend(overlay, image, 1 - (1/frames) * i)
im.save("C:/t/fred_%i.png" %i)
im = im.convert("P")
sequence.append(im)
fp = open(filename, "wb")
gifmaker.makedelta(fp, sequence)
fp.close()
class BarMaker(object):
def __init__(self, dx, dy, colour):
self.params = OV.GuiParams()
self.dx = int(dx)
self.dy = int(dy)
self.colour = colour
def makeBar(self):
size = (self.dx, self.dy)
colour = self.colour
weight = 15
height = self.dy
if colour == 'purple':
colour = [(162, 69, 162), (154, 53, 154), (142, 47, 142), (128, 43, 128), (115, 38, 115)]
if colour == 'orange':
colour = [(255, 208, 22), (255, 205, 3), (237, 190, 0), (214, 171, 0), (191, 153, 0)]
if colour == 'green':
colour = [(22, 255, 69), (3, 255, 53), (0, 237, 47), (0, 214, 43), (0, 191, 38)]
if colour == 'green':
colour = [(22, 237, 69), (3, 214, 53), (0, 191, 47), (0, 180, 43), (0, 170, 38)]
image = Image.new('RGBA', size, colour[0])
draw = ImageDraw.Draw(image)
j = 0
k = 0
for i in xrange(weight):
draw.line(((i, 0) ,(i, size[1])), fill=colour[k])
j += 1
if j > 3:
k+= 1
j = 0
adjustment_bottom = (1.1, 1.3, 2)
adjustment_top = (0.8, 0.95, 1.03)
#for j in xrange(3):
#for i in xrange(weight):
#c = []
#for item in colour[i]:
#c.append(item/adjustment_bottom[j])
#col = (c[0], c[1], c[2])
#draw.line(((i, height-3+j) ,(i, height-2+j)), fill=col)
#c = []
#for item in colour[i]:
#c.append(item/adjustment_top[j])
#col = (c[0], c[1], c[2])
#draw.line(((i, j) ,(i, j+1)), fill=col)
return image
class BarGenerator(ArgumentParser):
def __init__(self, type='vbar', colour='grey', size=100, basedir=""):
super(BarGenerator, self).__init__()
self.params = OV.GuiParams()
self.thickness = 5
self.type = type
self.colour = colour
self.size = size
def run(self):
if self.type == "vbar":
image = self.make_vBar(self.size, self.colour)
if self.colour == "grey":
name = r"solve.png"
else:
name = r"vBar-%i.png" %(int(self.size))
OlexVFS.save_image_to_olex(image, name, 2)
#image.save(r"%s\etc\$tools\vBar-%s.png" %(datadir, int(self.size)), "PNG")
return name
def make_vBar(self, size, colour):
weight = int(self.thickness)
height = int(size)
size = (int(5), int(height))
if colour == 'purple':
colour = [(162, 69, 162), (154, 53, 154), (142, 47, 142), (128, 43, 128), (115, 38, 115)]
if colour == 'orange':
colour = [(255, 208, 22), (255, 205, 3), (237, 190, 0), (214, 171, 0), (191, 153, 0)]
if colour == 'green':
colour = [(22, 240, 69), (3, 240, 53), (0, 225, 47), (0, 200, 43), (0, 180, 38)]
if colour == 'grey':
colour = [(210, 210, 210), (205, 205, 205), (200, 200, 200), (190, 190, 190), (170, 170, 170)]
image = Image.new('RGBA', size, colour[0])
draw = ImageDraw.Draw(image)
for i in xrange(weight):
draw.line(((i, 0) ,(i, size[1])), fill=colour[i])
adjustment_bottom = (1.1, 1.3, 2)
adjustment_top = (0.8, 0.95, 1.03)
for j in xrange(3):
for i in xrange(weight):
c = []
for item in colour[i]:
c.append(item/adjustment_bottom[j])
col = (int(c[0]), int(c[1]), int(c[2]))
draw.line(((i, height-3+j) ,(i, height-2+j)), fill=col)
c = []
for item in colour[i]:
c.append(item/adjustment_top[j])
col = (int(c[0]), int(c[1]), int(c[2]))
draw.line(((i, j) ,(i, j+1)), fill=col)
return image
def make_RBar(self, R, factor = 300):
if R == 'sol': #grey
colour = [(210, 210, 210), (205, 205, 205), (200, 200, 200), (190, 190, 190), (170, 170, 170)]
colour_a = (210,210,210)
R = 0.23
elif R > 0.2: #purple
colour = [(162, 69, 162), (154, 53, 154), (142, 47, 142), (128, 43, 128), (115, 38, 115)]
colour_a = IT.adjust_colour(OV.FindValue('gui_purple'), luminosity=1.2)
elif R > 0.10: #'orange':
colour = [(255, 208, 22), (255, 205, 3), (237, 190, 0), (214, 171, 0), (191, 153, 0)]
colour_a = IT.adjust_colour(OV.FindValue('gui_orange'), luminosity=1.2)
elif R < 0.11: #'green':
colour = [(22, 240, 69), (3, 240, 53), (0, 225, 47), (0, 200, 43), (0, 180, 38)]
colour_a = IT.adjust_colour(self.params.green.rgb, luminosity=1.2)
size = R * factor
if size < 1:
size = 1
width = int(self.thickness)
self.thickness = 5
height = int(size)
manual = False
if manual:
# Manual adjustment of colours from the list above
size = (width, int(height))
image = Image.new('RGBA', size, colour[0])
draw = ImageDraw.Draw(image)
for i in xrange(weight):
draw.line(((i, 0) ,(i, size[1])), fill=colour[i])
else:
#Automatic adjustment
size = (int(height), width)
image = Image.new('RGBA', size, "#000000")
grad_colour = IT.adjust_colour(colour_a, luminosity = 1)
draw = ImageDraw.Draw(image)
IT.gradient_bgr(draw, height, width, colour = grad_colour, fraction=1, step=0.8) # width and height are swapped!
image = image.rotate(90)
draw = ImageDraw.Draw(image)
adjustment_bottom = (1.1, 1.3, 2)
adjustment_top = (0.8, 0.95, 1.03)
# Create the top and bottom shading for each bar
for j in xrange(3):
for i in xrange(width):
c = []
samplepixheight = int(image.size[1]/2)
cpx = image.getpixel((i,samplepixheight))
for item in cpx:
c.append(item/adjustment_bottom[j])
col = (int(c[0]), int(c[1]), int(c[2]))
draw.line(((i, height-3+j) ,(i, height-2+j)), fill=col)
c = []
for item in cpx:
c.append(item/adjustment_top[j])
col = (int(c[0]), int(c[1]), int(c[2]))
draw.line(((i, j) ,(i, j+1)), fill=col)
return image
class MakeAllRBars(BarGenerator):
def __init__(self, tool_fun=None, tool_arg=None):
super(MakeAllRBars, self).__init__()
self.params = OV.GuiParams()
self.thickness = 5
self.factor = 300
#self.params.html.bg_colour.rgb = OV.FindValue('gui_htmlself.params.html.bg_colour.rgb')
def run_MakeAllRBars(self):
return
name = "vscale.png"
OlexVFS.save_image_to_olex(self.makeRBarScale(), name, 2)
name = "vbar-sol.png"
OlexVFS.save_image_to_olex(self.make_RBar('sol', factor=self.factor), name, 2)
for i in xrange(221):
R = i/1000
name = "vbar-%i.png" %(R*1000)
image_exists = olex_fs.Exists(name)
if image_exists:
image = self.make_RBar(R, factor=self.factor)
image = self.make_RBar(R, factor=self.factor)
if image:
OlexVFS.save_image_to_olex(image, name, 2)
def run_(self):
for i in xrange (100):
size = i + 1
if i >= 20:
colour = 'purple'
size = "22"
if i < 20:
colour = 'orange'
if i <10:
colour = 'green'
image = self.make_vBar(int(size * self.scale), colour)
name = r"vBar-%i.png" %(int(size))
OlexVFS.save_image_to_olex(image, name, 2)
name = "vscale.png"
RBarScale = self.makeRBarScale()
OlexVFS.save_image_to_olex(RBarScale, name, 2)
def makeRBarScale(self):
width = 22
scale = self.factor/100
top = 20
text_width = 14
height = (top * scale) + 10
size = (int(width), int(height))
image = Image.new('RGBA', size, self.params.html.table_bg_colour.rgb)
draw = ImageDraw.Draw(image)
draw.line(((width-2, 0) ,(width-2, height)), fill='#666666')
font_name = "Vera Bold"
font_size = 10
font = IT.registerFontInstance(font_name, font_size)
txt = r"R1"
hStart = self.centre_text(draw, txt, font, text_width)
draw.text((hStart, -1), "%s" %txt, font=font, fill='#666666')
font_name = "Vera"
font_size = 10
font = IT.registerFontInstance(font_name, font_size)
divisions = 4
for i in xrange(divisions):
if i ==0:
continue
txt = str((divisions - (i - 1)) * scale)
txt = str(int((top/divisions)*(divisions - i)))
hStart = self.centre_text(draw, txt, font, text_width)
vpos = int(height/(divisions)*(i))
draw.text((hStart, vpos-5), "%s" %txt, font=font, fill='#666666')
draw.line(((width-5, vpos) ,(width-2, vpos)), fill='#666666')
# draw.line(((width-5, int(height/(i+1)*2) ,(width-1, int(height/4)*2)), fill='#000000')
# draw.line(((width-5, int(height/(i+1)*3) ,(width-1, int(height/4)*3)), fill='#000000')
image = self.makeBackgroundTransparent(image,col=self.params.html.table_bg_colour.rgb)
return image
MakeAllRBars_instance = MakeAllRBars()
OV.registerMacro(MakeAllRBars_instance.run_MakeAllRBars, '')
##greyed out on 1/11/12
#class sNumTitle(ImageTools):
#def __init__(self, width=None, tool_arg=None):
#super(sNumTitle, self).__init__()
#self.params = OV.GuiParams()
#self.have_connection = False
#width = self.params.htmlpanelwidth
#if not width:
#width = 290
#try:
#width = float(width)
#except:
#width = float(tool_arg)
#if self.have_connection:
#try:
#import SQLFactories
#self.ds = SQLFactories.SQLFactory()
#except:
#self.have_connection = False
#pass
#self.sNum = self.filename
#def run_sNumTitle(self, force=False):
##self.params.html.base_colour.rgb = OV.FindValue('gui_htmlself.params.html.base_colour.rgb')
#self.basedir = OV.BaseDir()
#self.filefull = OV.FileFull()
#self.filepath = OV.FilePath()
#self.filename = OV.FileName()
#self.datadir = OV.DataDir()
#self.sNum = self.filename
#self.space_group = OV.olex_function('sg(%h)')
#id_string = self.space_group+self.filefull
#curr_id = OV.GetParam("olex2.sNum_id_string")
#if id_string == curr_id:
#if not force:
#return
#OV.SetParam("olex2.sNum_id_string",id_string)
#items = {}
#if self.filename != 'none':
#if self.have_connection:
#try:
#from DimasInfo import dimas_info
#self.getInfo = dimas_info("info")
#items = self.getInfo.run()
#items.setdefault("sNum", olx.FileName())
#except Exception, ex:
#raise ex
#if not items:
#items.setdefault("operator", "n/a")
#items.setdefault("submitter", "no info")
#items.setdefault("type", "none")
#items.setdefault("sNum", "none")
#try:
#items["type"] = olx.FileExt()
#items["sNum"] = olx.FileName()
#except Exception, ex:
#raise ex
#image = self.sNumTitleStyle1(items)
#name = r"sNumTitle.png"
#OlexVFS.save_image_to_olex(image, name, 1)
#OV.CopyVFSFile(name, 'SNUMTITLE',2)
#def own_sql(self): #not currently used
#sNum = self.sNum
#sql = """SELECT people_status.Nickname
#FROM submission INNER JOIN people_status ON submission.OperatorID = people_status.ID
#WHERE (((submission.ID)="%s"));""" %sNum
#rs = self.ds.run_select_sql(sql)
#nickname = ""
#for record in rs:
#nickname = record[0]
#items.setdefault("nickname", nickname)
#record = ""
#sql = """SELECT people_fullnames.display
#FROM submission INNER JOIN people_fullnames ON submission.SubmitterID = people_fullnames.ID
#WHERE (((submission.ID)="%s"));""" %sNum
#rs = self.ds.run_select_sql(sql)
#submitter = ""
#for record in rs:
#submitter = record[0]
#items.setdefault("submitter", submitter)
#def sNumTitleStyle1(self, items, font_name="Arial Bold", font_size=17):
#sNum = items["sNum"]
#a = timage()
#return a.make_timage('snumtitle', sNum, 'on', titleCase=False)
class timage(ArgumentParser):
def __init__(self, width=None, tool_arg=None):
super(timage, self).__init__()
OV.registerFunction(self.make_images_from_fb_png)
image = Image.new('RGBA', (1,1), (0,0,0,0))
OlexVFS.save_image_to_olex(image, "blank.png", 2)
self.imageSource = None
self.iconSource = None
self.scale = OV.GetParam('gui.internal_scale')
import olex_fs
self.params = OV.GuiParams()
self.advertise_new = False
new_l = open("%s/etc/gui/images/advertise_as_new.txt" %OV.BaseDir(),'r').readlines()
self.new_l = map(lambda s: s.strip(), new_l)
self.width = IT.skin_width
self.max_width = IT.max_width
global timage_blanks
timage_blanks.setdefault(self.params.skin.name,{})
self.abort = False
self.font_name = "Vera"
self.timer = False
self.debug = False
if self.timer:
import time
self.time = time
self.text_time = 0
sf = 4 #images are four times larger than the nominal width of 350
sfs = sf * 350/int(self.params.htmlpanelwidth)
self.sf = sf
self.sfs = sfs
self.no_need_to_refresh_image_type = {}
self.getImageItemsFromTextFile()
#global dpi_scale
#olx.HtmlPanelWidth(int(OV.GetParam('gui.htmlpanelwidth')*dpi_scale))
#print "resize panel!===================="
def run_timage(self,force_images=False):
IT.get_available_width()
global timage_blanks
self.params = OV.GuiParams()
self.width = IT.skin_width
timage_blanks.setdefault(self.params.skin.name,{})
self.force_images = force_images
if force_images:
timage_blanks[self.params.skin.name] = {}
self.highlight_colour = OV.GetParam('gui.html.highlight_colour').rgb
do_these = []
if olx.fs.Exists("logo.png") == 'false':
force_images = True
if not olexex.check_for_recent_update():
if not OV.GetParam('olex2.force_images') and not force_images:
do_these = [
"make_images_from_fb_png",
"make_cbtn_items",
"info_bitmaps",
"make_icon_items",
]
if not do_these:
do_these = ["make_generated_assorted_images",
"make_text_and_tab_items",
"make_label_items",
"make_button_items",
"make_cbtn_items",
"make_icon_items",
"make_element_buttons",
"make_image_items",
"make_images_from_fb_png",
"make_popup_banners",
"info_bitmaps",
"resize_news_image",
"resize_skin_logo",
"create_logo"
]
do_these = ["make_generated_assorted_images",
# "make_text_and_tab_items",
# "make_label_items",
# "make_button_items",
"make_cbtn_items",
"make_icon_items",
# "make_element_buttons",
# "make_image_items",
# "make_images_from_fb_png",
"make_popup_banners",
"info_bitmaps",
"resize_news_image",
"resize_skin_logo",
"create_logo"
]
#self.params.html.base_colour.rgb = OV.FindValue('gui_htmlself.params.html.base_colour.rgb')
#width = int(olx.html.ClientWidth('self'))
self.basedir = OV.BaseDir()
self.filefull = OV.FileFull()
self.filepath = OV.FilePath()
self.filename = OV.FileName()
self.datadir = OV.DataDir()
self.sNum = self.filename
#MakeAllRBars_instance.run_MakeAllRBars()
for item in do_these:
if self.timer:
t1 = self.time.time()
a = getattr(self, item)
a()
if self.timer:
print "\t - %s took %.3f s to complete" %(item, self.time.time()-t1)
def resize_news_image(self, width_adjust=0, width=None, vfs=False):
tag = OV.GetTag().split('-')[0]
name = 'news/news-%s' % tag
if vfs: name += '_tmp@vfs'
else: name += '.png'
IT.resize_to_panelwidth({'i':name}, width=width, width_adjust=width_adjust)
# OV.registerFunction(resize_news_image, False, 'it')
def make_popup_banners(self):
txt_l = [('setup',330), ('help',410), ('tutorial',375)]
image_source = "%s/etc/gui/images/src/banner.png" %self.basedir
for item in txt_l:
txt = item[0]
IM = Image.open(image_source)
width = int(item[1])
height = int(width * IM.size[1]/IM.size[0])
draw = ImageDraw.Draw(IM)
IT.write_text_to_draw(draw,
"%s" %txt,
top_left=(440, 32),
font_name = 'Vera',
font_size=42,
titleCase=False,
font_colour="#525252",
align='left'
)
name = "banner_%s.png" %txt
IM = IT.resize_image(IM, (width, height), name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
def open_icon_source(self):
if not self.iconSource:
icon_source = open("%s/etc/gui/images/src/icons.png" %self.basedir, 'rb')
self.iconSource = Image.open(icon_source)
self.iconSource.load()
icon_source.close()
def open_image_source(self):
if not self.imageSource:
image_source = open("%s/etc/gui/images/src/images.png" %self.basedir,'rb')
self.imageSource = Image.open(image_source)
self.imageSource.load()
image_source.close()
def make_images_from_fb_png(self):
self.image_type = "fb"
sf = self.sf
self.open_image_source()
im = self.imageSource
available_width = IT.skin_width
self.make_buttons()
self.make_round_info_buttons()
cut = 16*sf, 156*sf, 26*sf, 166*sf
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
crop = im.crop(cut)
crop_colouriszed = IT.colourize(crop, (0,0,0), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb,luminosity=0.7))
IM = Image.new('RGBA', crop.size, self.params.html.table_firstcol_colour.rgb)
IM.paste(crop_colouriszed, (0,0), crop)
draw = ImageDraw.Draw(IM)
IT.write_text_to_draw(draw,
"iX",
top_left=(2, 1),
font_name = 'Vera',
font_size=10,
font_colour="#ffffff")
name = "info_tiny_fc.png"
IM = IT.resize_image(IM, size=cut_size, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
cut = 16*sf, 156*sf, 26*sf, 166*sf
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
crop = im.crop(cut)
crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.highlight_colour.rgb)
IM = Image.new('RGBA', crop.size, self.params.html.table_firstcol_colour.rgb)
IM.paste(crop_colouriszed, (0,0), crop)
name = "info_tiny_new.png"
IM = IT.resize_image(IM, size=cut_size, name=name)
draw = ImageDraw.Draw(IM)
IT.write_text_to_draw(draw,
"iY",
top_left=(3, -1),
font_name = 'Vera Bold Italic',
font_size=11,
font_colour="#ffffff")
OlexVFS.save_image_to_olex(IM, name, 2)
## Create big circles with Writing In
#cut = 30*sf, 150*sf, 55*sf, 175*sf
#crop = im.crop(cut)
#crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.table_firstcol_colour.rgb)
for i in xrange(12):
self.makeCharcterCircles(str(i), im, self.params.html.table_firstcol_colour.rgb)
colo = IT.adjust_colour(self.params.green.rgb,saturation=0.7,luminosity=2.1)
l = ["a", "b", "c", "d", "e", "f"]
for letter in l:
self.makeCharcterCircles(letter, im, colo)
up_down_enlarge = 1/self.scale
cut = 186*sf, 154*sf, 204*sf, 172*sf
crop = im.crop(cut)
crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.base_colour.rgb)
IM = Image.new('RGBA', crop.size)
IM.paste(crop_colouriszed, (0,0), crop)
_ = (int((cut[2]-cut[0])/(sf*up_down_enlarge)), int((cut[3]-cut[1])/(sf*up_down_enlarge)))
name = "next.png"
IM = IT.resize_image(IM, size=_, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
name = "right.png"
OlexVFS.save_image_to_olex(IM, name, 2)
cut = 204*sf, 154*sf, 222*sf, 172*sf
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
crop = im.crop(cut)
crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.base_colour.rgb)
IM = Image.new('RGBA', crop.size)
IM.paste(crop_colouriszed, (0,0), crop)
_ = int((cut[2]-cut[0])/(sf*up_down_enlarge)), int((cut[3]-cut[1])/(sf*up_down_enlarge))
name = "previous.png"
IM = IT.resize_image(IM, size=_, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
name = "down.png"
OlexVFS.save_image_to_olex(IM, name, 2)
cut = 222*sf, 154*sf, 240*sf, 172*sf
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
crop = im.crop(cut)
name = "up_raw.png"
_ = int((cut[2]-cut[0])/(sf*up_down_enlarge)), int((cut[3]-cut[1])/(sf*up_down_enlarge))
IM = IT.resize_image(crop, size=_, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.base_colour.rgb)
IM = Image.new('RGBA', crop.size)
IM.paste(crop_colouriszed, (0,0), crop)
_ = int((cut[2]-cut[0])/(sf*up_down_enlarge)), int((cut[3]-cut[1])/(sf*up_down_enlarge))
name = "up.png"
IM = IT.resize_image(IM, size=_, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
cut = 240*sf, 154*sf, 258*sf, 172*sf
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
crop = im.crop(cut)
name = "down_raw.png"
_ = (int((cut[2]-cut[0])/(sf*up_down_enlarge)), int((cut[3]-cut[1])/(sf*up_down_enlarge)))
IM = IT.resize_image(crop, size=_, name=name )
OlexVFS.save_image_to_olex(IM, name, 2)
crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.base_colour.rgb)
IM = Image.new('RGBA', crop.size)
IM.paste(crop_colouriszed, (0,0), crop)
_ = int((cut[2]-cut[0])/(sf*up_down_enlarge)), int((cut[3]-cut[1])/(sf*up_down_enlarge))
name = "down.png"
IM = IT.resize_image(IM, size=_, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
cut = 140*sf, 98*sf, 400*sf, 140*sf
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
max_width = cut[2] - cut[0]
crop = im.crop(cut)
crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.highlight_colour.rgb)
IM = Image.new('RGBA', crop.size, self.params.html.table_bg_colour.rgb)
IM.paste(crop_colouriszed, (0,0), crop)
draw = ImageDraw.Draw(IM)
IT.write_text_to_draw(draw,
"You are in a Mode",
top_left=(5, 1),
font_name = 'Vera Bold',
font_size=90,
font_colour=self.params.html.font_colour.rgb,
align='centre',
max_width=max_width
)
sfm = sf*0.95
name = "pop_background.png"
IM = IT.resize_image(IM, size=cut_size, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
cut = 140*sf, 98*sf, 400*sf, 140*sf
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
max_width = cut[2] - cut[0]
crop = im.crop(cut)
crop_colouriszed = IT.colourize(crop, (0,0,0), self.params.html.highlight_colour.rgb)
IM = Image.new('RGBA', crop.size, self.params.html.table_bg_colour.rgb)
IM.paste(crop_colouriszed, (0,0), crop)
draw = ImageDraw.Draw(IM)
IT.write_text_to_draw(draw,
"You are in a Mode",
top_left=(5, 1),
font_name = 'Vera Bold',
font_size=90,
font_colour=self.params.html.font_colour.rgb,
align='centre',
max_width=max_width
)
sfm = sf*0.95
name = "pop_background.png"
IM = IT.resize_image(IM, size=cut_size, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
d_default = {
'colourize':False,
'text':False
}
t_default = {
'top_left':(1,1),
'font_name':'Vera',
'font_size':6,
'font_colour':self.params.html.font_colour.rgb,
}
d = {
'01':{'name':"settings_small",
'cut':(55*sf, 150*sf, 80*sf, 175*sf),
},
'02':{'name':"delete",
'cut':(80*sf, 154*sf, 100*sf, 171*sf),
},
'03':{'name':"delete_small",
'cut':(101*sf, 154*sf, 117*sf, 165*sf),
},
'04':{'name':"bottom",
'cut':(136*sf, 154*sf, 185*sf, 170*sf),
},
'05':{'name':"warning",
'cut':(116*sf, 154*sf, 135*sf, 175*sf),
},
'06':{'name':"warning_big",
'cut':(90*sf, 95*sf, 140*sf, 140*sf),
},
'07':{'name':"info_tiny",
'cut':(16*sf, 156*sf, 26*sf, 166*sf),
'colourize':1.7,
'text':{
'txt':IT.get_unicode_characters('info'),
'top_left':(1,1),
'font_name':"Vera",
'font_size':6,
'font_colour':(self.params.html.font_colour.rgb),
}
},
}
for _ in d:
d[_].update(d_default)
try:
name = d[_]['name'] + ".png"
except:
pass
cut = d[_]['cut']
cut_size = (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))
crop = im.crop(cut)
if d[_]['colourize']:
crop_colouriszed = IT.colourize(crop, (0,0,0), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb,luminosity=b[colourize]))
IM = Image.new('RGBA', crop.size, self.params.html.table_bg_colour.rgb)
IM.paste(crop_colouriszed, (0,0), crop)
if d[_]['text']:
d[_]['text'].update(text_default)
draw = ImageDraw.Draw(IM)
IT.write_text_to_draw(draw,
d[_]['text']['txt'],
top_left=d[_]['text']['top_left'],
font_name=d[_]['text']['font_name'],
font_size=d[_]['text']['font_size'],
font_colour=d[_]['text']['font_colour'])
IM = Image.new('RGBA', crop.size, self.params.html.table_bg_colour.rgb)
IM.paste(crop, (0,0), crop)
IM = IT.resize_image(IM, size=cut_size, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
for col in ['green', 'orange', 'red', 'purple']:
IM = Image.new('RGBA', (10,10), OV.GetParam('gui.%s' %col).rgb)
name = "bar_%s.png" %col
OlexVFS.save_image_to_olex(IM, name, 2)
def make_buttons(self):
available_width = IT.skin_width_table
scale = self.sf / 1.2
button_names = self.image_items_d.get("TINY BUTTONS")
tiny_width= OV.GetParam('gui.timage.tinybutton.width')
self.produce_buttons(button_names, "_tiny", scale, width=tiny_width)
## SMALL buttons
button_names = self.image_items_d.get("SMALL BUTTONS")
width = OV.GetParam('gui.timage.small_button.width')
self.produce_buttons(button_names, "_small", self.sf, width=width)
available_width = IT.skin_width_table - 44 - OV.GetParam('gui.htmlpanelwidth_margin_adjust')
## TWO buttons in the HTMLpanelWIDTH
button_names = self.image_items_d.get("TWO BUTTONS PER ROW", button_names)
width = int(available_width/2) - 15
self.produce_buttons(button_names, "", self.sf, width=width)
## THREE buttons in the HTMLpanelWIDTH
button_names = self.image_items_d.get("THREE BUTTONS PER ROW", button_names)
width = int(available_width/3) - 12
self.produce_buttons(button_names, "", self.sf, width=width)
## FULL ROW buttons in the HTMLpanelWIDTH
button_names = self.image_items_d.get("FULL ROW", button_names)
width = available_width
self.produce_buttons(button_names,"_full", self.sf, width=width)
## G4 BUTTON
if olx.IsPluginInstalled('g4') == 'true':
button_names = self.image_items_d.get("G4 BUTTON", button_names)
width = available_width - OV.GetParam('gui.timage.g4.width_adjust') - 20
self.produce_buttons(button_names, "_g4", self.sf, width=width)
def make_round_info_buttons(self):
# MAKE ROUND INFO BUTTONS
height = OV.GetParam('gui.timage.h3.height')
fill = '#ffffff'
width = height * 2
height = int(round(width*1.5))
size = (width * self.scale, height * self.scale)
circle_top = 12 * self.scale
IM = Image.new('RGBA', size,(0,0,0,0))
draw = ImageDraw.Draw(IM)
xy = (2 * self.scale, circle_top, 36 * self.scale, circle_top + 36 * self.scale)
draw.ellipse(xy, fill = '#ffffff')
states = ['', 'on', 'off', 'hover', 'hoveron']
r,g,b,a = IM.split()
font_info = IT.registerFontInstance("Serif Bold Italic", 42 * self.scale)
top = circle_top - 13 * self.scale
adjust = 1 * self.scale
if self.width < 400:
adjust = 0.8 * self.scale
for state in states:
if state == "off":
col = IT.colourize(IM, (0,0,0,0), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb,luminosity=0.8))
else:
col = IT.colourize(IM, (0,0,0,0), self.highlight_colour)
fIM = Image.new('RGBA', size, OV.GetParam('gui.html.table_firstcol_colour').rgb)
fIM.paste(col, mask=a)
draw = ImageDraw.Draw(fIM)
draw.text((14*self.scale,top), 'i', font=font_info, fill='#ffffff')
_ = int(round((width*adjust/(self.scale*2.5)))), int(round(height*adjust/(self.scale*2.7)))
name = "btn-info%s.png" %(state)
fIM = IT.resize_image(fIM, size=_, name=name)
OlexVFS.save_image_to_olex(fIM, name, 2)
def produce_buttons(self, button_names, btn_type, scale=None, max_width=None, width=None, crop=None, cut=None, ):
self.params = OV.GuiParams()
if not scale:
scale = self.sf / 1.2
self.image_type = btn_type
if self.no_need_to_refresh_image_type.get(self.image_type):
return
states = ["on", "off", "highlight", "hover", "hoveron"]
auto_name = ""
auto_text = ""
button_type = "button"
for txt in button_names:
w = IT.skin_width_table
if not width:
if "three" in btn_type:
width = int(w/3) - 12
elif "two" in btn_type:
width = int(w/2) - 12
if "full" in btn_type:
auto_name = txt
txt = txt.replace("button_full-","")
auto_text = txt.replace("full-","")
width = w - 12
elif "one" in btn_type:
auto_name = txt
width = w - 12
elif "element" in txt:
element = txt.split("_")[0].lstrip("btn-element")
self.make_element_buttons(element)
return
elif "small" in btn_type:
button_type = 'small_button'
width = OV.GetParam('gui.timage.small_button.width')
elif "tiny" in btn_type:
button_type = 'tinybutton'
width = OV.GetParam('gui.timage.tinybutton.width')
elif "h2" in btn_type:
button_type = 'h1'
width = OV.GetParam('gui.timage.h2.width')
auto_name = txt
auto_text = txt.replace("h2-", "")
elif "h3" in btn_type:
button_type = 'h3'
elif "cbtn" in btn_type:
button_type = 'cbtn'
self.make_cbtn_items()
return
#width = OV.GetParam('gui.cbtn.width')
#width = int(self.available_width/4) - 12
elif "tab" in btn_type:
self.make_tab_items()
return
elif "info" in txt:
self.make_images_from_fb_png()
return
elif "small" in txt:
button_type = 'small_button'
elif "toolbar" in txt:
button_type = "toolbar"
self.make_icon_items()
return
if not auto_name:
auto_name = txt.split("@")[0]
if width is None: width = IT.skin_width
if txt in self.new_l:
self.advertise_new = True
if auto_name:
if not auto_text:
if "-" in auto_name:
t = auto_name.lstrip("%s-" %btn_type)
else:
t = auto_name
else:
t = auto_text
else:
t = txt.strip("%s-" %btn_type)
for state in states:
if state == "on":
colour = IT.adjust_colour(self.params.html.highlight_colour.rgb,luminosity=1.3)
elif state == "off":
#colour = IT.adjust_colour(self.params.html.base_colour.rgb,luminosity=1.9)
colour = self.params.button_colouring.rgb
elif state == "":
#colour = IT.adjust_colour(self.params.html.base_colour.rgb,luminosity=1.9)
colour = self.params.button_colouring.rgb
elif state == "hover":
colour = IT.adjust_colour(self.params.button_colouring.rgb,luminosity=1.1)
elif state == "hoveron":
colour = IT.adjust_colour(self.params.button_colouring.rgb,luminosity=0.5)
self.image = image = self.make_timage(item_type=button_type, item=t.replace('_', ' '),
state=state, width=width, colour=colour, titleCase=False)
if not auto_name:
self.name = name = "button%s-%s%s.png" %(btn_type, txt.replace(" ", "_"), state)
else:
self.name = name = "%s%s.png" %(auto_name.replace(" ", "_"), state)
if not image:
print "Image %s has not been created" %name
self.save_with_checking_for_needed()
self.advertise_new = False
def makeTestBanner(self):
if not OV.FindValue('user_refinement_gui2'):
return
name = "banner.png"
if not OV.GetParam('olex2.force_images'):
timestamp = olex_fs.Timestamp(name)
if timestamp:
if time.time() - timestamp < time.clock():
return
bannerbg = "#fdff72"
bannerbg = self.params.html.base_colour.rgb
col_0 = IT.adjust_colour(bannerbg,luminosity=0.85)
col_1 = IT.adjust_colour(bannerbg,luminosity=1.7)
cmd_col = "#fff600"
font_size_l = [42, 13, 13]
font_l = ["Vera Bold", "Vera", "Vera"]
txt_items = {"Olex2":{'name':'olex2','pix':0,'row':0,'colour':col_0,
'itemstate':"aio-olex2* 1 "},
"Prepare":{'name':'prepare','pix':150,'row':0,'colour':col_0,
'itemstate':"aio-prepare* 2 "},
"Solve":{'name':'solve','pix':390,'row':0,'colour':col_0,
'itemstate':"aio-solve* 2 "},
"Refine":{'name':'refine','pix':550,'row':0,'colour':col_0,
'itemstate':"aio-refine* 2 "},
"Analyze":{'name':'analyze','pix':750,'row':0,'colour':col_0,
'itemstate':"aio-analyze* 2 "},
"Publish":{'name':'publish','pix':1050,'row':0,'colour':col_0,
'itemstate':"aio-report* 2 "},
"recent":{'name':'recent','pix':-40,'row':1,'colour':col_1,
'itemstate':"aio-olex2* 2 aio-olex2-recent* 1"},
"history":{'name':'history','pix':-10,'row':2,'colour':col_1,
'itemstate':"aio-olex2* 2 aio-olex2-history 1"},
"setup":{'name':'setup','pix':20,'row':1,'colour':cmd_col,
'itemstate':"aio-olex2* 2 ", 'cmd':'setup'},
"configuration":{'name':'configuration','pix':40,'row':2,'colour':cmd_col,
'itemstate':"aio-olex2* 2 ", 'cmd':'config'},
"settings":{'name':'settings','pix':80,'row':1,'colour':col_1,
'itemstate':"aio-olex2* 2 aio-olex2-settings 1"},
"reflections":{'name':'reflections','pix':150,'row':1,'colour':col_1,
'itemstate':"aio-prepare* 2 aio-prepare-reflections 1", 'cmd':""},
"space group":{'name':'space group','pix':190,'row':2,'colour':col_1,
'itemstate':"aio-prepare* 2 aio-prepare-space* 1", 'cmd':"sg"},
"formula":{'name':'formula','pix':290,'row':1,'colour':col_1,'cmd':"",
'itemstate':"aio-prepare* 2 aio-prepare-formula 1", 'cmd':""},
"solve":{'name':'solve now','pix':370,'row':2,'colour':col_1,
'itemstate':"aio-solve* 2 aio-solve-solve 1"},
"assign solution":{'name':'assign solution','pix':430,'row':1,'colour':cmd_col,'cmd':"",
'itemstate':"aio-solve* 2 aio-solve-solve 1", 'cmd':"vss(True)"},
"refine":{'name':'refine now','pix':530,'row':2,'colour':col_1,
'itemstate':"aio-refine* 2 aio-refine-refine 1", 'Xcmd':"refine>>compaq"},
"assemble":{'name':'refine now','pix':560,'row':1,'colour':cmd_col,
'itemstate':"aio-refine* 2 aio-refine-refine 1", 'cmd':"compaq"},
"assign":{'name':'assign','pix':600,'row':2,'colour':cmd_col,'cmd':"",
'itemstate':"aio-refine* 2 aio-refine-refine 1", 'cmd':"ata(1)>>refine>>ata(1)>>compaq"},
"anisotropic":{'name':'anisotropic','pix':630,'row':1,'colour':cmd_col,
'itemstate':"aio-refine* 2 aio-refine-refine 1", 'cmd':"anis>>refine>>compaq"},
"add hydrogen":{'name':'add hydrogen','pix':670,'row':2,'colour':cmd_col,'cmd':"",
'itemstate':"aio-refine* 2 aio-refine-refine 1", 'cmd':"hadd>>refine>>compaq"},
"disorder":{'name':'disorder','pix':760,'row':2,'colour':col_1,'cmd':"",
'itemstate':"aio-disorder* 2 aio-disorder-disorder 1", 'cmd':""},
"contraints&restraints":{'name':'constraints&restraints','pix':850,'row':1,'colour':col_1,'cmd':"",
'itemstate':"aio-disorder* 1 ", 'cmd':""},
"name atoms":{'name':'atom naming','pix':950,'row':2,'colour':col_1,
'itemstate':"aio-publish* 2 aio-publish-naming* 1", 'cmd':""},
"measure":{'name':'geometric measurements','pix':1000,'row':1,'colour':col_1,
'itemstate':"aio-geometry* 1", 'cmd':""},
"match":{'name':'matching','pix':1050,'row':2,'colour':col_1,
'itemstate':"aio-analyze* 2 aio-analyze-match* 1", 'cmd':""},
}
for item in txt_items:
row = txt_items[item].get("row",0)
txt = item
font_size = font_size_l[row]
font_name = font_l[row]
txt_dimensions = self.getTxtWidthAndHeight(txt, font_name=font_name, font_size=font_size)
txt_items[item].setdefault('txt_dimensions',txt_dimensions)
# bannerbg = self.params.html.font_colour.rgb
offset = 180
height = 44
width = 1700
size = (width,height)
IM = Image.new('RGBA', size, self.params.html.table_bg_colour.rgb)
IM = Image.new('RGBA', size, bannerbg)
#IM = Image.new('RGBA', size, "#aaaa00")
draw = ImageDraw.Draw(IM)
for i in xrange(22):
lum = 1.00 - ((5-i) * (0.02))
draw.line(((0,i),(width,i)), fill=IT.adjust_colour(bannerbg,luminosity=lum,saturation = lum))
for i in xrange(22):
lum = 1.00 - ((5 -i) * (0.02))
draw.line(((0,height - i),(width,height - i)), fill=IT.adjust_colour(bannerbg,luminosity=lum, saturation = lum))
margin_top_l = [-3, 12, 26]
title_l = [True, False, False]
lower_l = [False, True, True]
for i in xrange(3):
for item in txt_items:
row = txt_items[item].get("row",0)
if row != i:
continue
txt = item
x_pos = txt_items[item].get("pix",0) + offset
font_colour = txt_items[item].get("colour")
font_size = font_size_l[row]
font_name = font_l[row]
titleCase = title_l[row]
lower_case = lower_l[row]
wX = txt_items[item].get('txt_dimensions')[0]
wY = txt_items[item].get('txt_dimensions')[1]
olex_pos = x_pos + wX/2 - (int(self.params.htmlpanelwidth) - 24)/2
olex_pos = "%.0f" %(olex_pos/10.0)
if row != 0:
olx.banner_slide.setdefault(int(olex_pos),txt_items[item])
OV.SetVar("snum_slide_%s" %txt.lower(),olex_pos)
IT.write_text_to_draw(draw,
"%s" %(txt),
top_left=(x_pos,margin_top_l[row]),
font_name = font_name,
font_size=font_size,
titleCase=titleCase,
lowerCase=lower_case,
font_colour=font_colour)
width = int(self.params.htmlpanelwidth) - 24
size = (width, height)
self.banner_make_decoration_image(size)
for j in xrange(129):
self.banner_map = "
'''
self.banner_map += txt
def banner_write_file(self, i):
htm_location = "banner_%i.htm" %i
OlexVFS.write_to_olex(htm_location, self.banner_map)
if i == 0:
htm_location = "banner.htm"
OlexVFS.write_to_olex(htm_location, self.banner_map)
def banner_make_decoration_image(self, size):
marker_colour = "#ff0000"
width, height = size
heigth = height -1
IM = Image.new('RGBA', size, (0,0,0,0))
draw = ImageDraw.Draw(IM)
#for i in xrange(22):
#trans = 255 - (2 * (22 - i))
#draw.line(((i,0),(i,height)), fill=(0,0,0, trans))
#for i in xrange(22):
#trans = 255 - (2 * i)
#draw.line(((width -i,0),(width - i,height)), fill=(0,0,0, trans))
draw.line(((width/2 + 2,0),(width/2 + 2,height)), fill=(0,0,0,125))
#Draw triangle shadow
begin = (width/2 - 3, height)
middle = (width/2,height -6)
end = (width/2 + 7, height)
draw.polygon((begin, middle, end), (0,0,0,90))
begin = (width/2 - 5, height)
middle = (width/2,height -6)
end = (width/2 + 5, height)
draw.polygon((begin, middle, end), marker_colour)
begin = (width/2 - 3, 0)
middle = (width/2,6)
end = (width/2 + 7, 0)
draw.polygon((begin, middle, end), (0,0,0,90))
begin = (width/2 - 5, 0)
middle = (width/2,6)
end = (width/2 + 5, 0)
draw.polygon((begin, middle, end), marker_colour)
draw.line(((width/2,0),(width/2,height)), fill=marker_colour)
division_col = IT.HTMLColorToRGB(self.params.html.base_colour.rgb) + (255,)
left = width/2
right = width/2
for j in xrange(40):
y1 = 1
if j % 2:
y1 = 2
right += 8
draw.line(((right,(height/2)-y1), (right, (height/2)+y1)), fill=division_col)
left -= 10
draw.line(((left,(height/2)-y1),(left,(height/2)+y1)), fill=division_col)
r,g,b,a = IM.split()
#paste the overlay into the base image in the boundingBox using mask as a filter
self.banner_decoration_image = (IM,a)
def decorate_banner_image(self, crop, size, bannerbg, i):
marker_colour = "#ff0000"
width, height = size
heigth = height -1
draw = ImageDraw.Draw(crop)
#for j in xrange(22):
#region = (j,0,j+1,height)
#region_im = crop.crop(region)
#region_im = region_im.point(lambda i: i * 1 - 0.01 * (22-j))
#region_im = ImageEnhance.Brightness(region_im).enhance(1 - j * 0.01)
#crop.paste(region_im, region)
#for j in xrange(22):
#region = (width - j - 2 ,0,width - j , height)
#region_im = crop.crop(region)
#region_im = region_im.point(lambda i: i * 1 - 0.01 * j)
#crop.paste(region_im, region)
## Shadow Marker Line
region = (int(width/2) + 2,0,int(width/2) + 3,height)
region_im = crop.crop(region)
# region_im = region_im.point(lambda i: i * 0.8)
region_im = ImageEnhance.Brightness(region_im).enhance(1.1)
crop.paste(region_im, region)
begin = (width/2 - 5, height)
middle = (width/2,height -6)
end = (width/2 + 5, height)
draw.polygon((begin, middle, end), marker_colour)
begin = (width/2 - 5, 0)
middle = (width/2,6)
end = (width/2 + 5, 0)
draw.polygon((begin, middle, end), marker_colour)
draw.line(((width/2,0),(width/2,height)), fill=marker_colour)
#division_col = "#ababab"
division_col = self.params.html.base_colour.rgb
left = width/2
right = width/2
for j in xrange(40):
y1 = 1
if j % 2:
y1 = 2
right += 8
draw.line(((right,(height/2)-y1), (right, (height/2)+y1)), fill=division_col)
left -= 10
draw.line(((left,(height/2)-y1),(left,(height/2)+y1)), fill=division_col)
return crop
def makeCharcterCircles(self, character, im, colour, resize = True):
cut = 30*self.sf, 150*self.sf, 55*self.sf, 175*self.sf
crop = im.crop(cut)
IM = Image.new('RGBA', crop.size, self.params.html.table_bg_colour.rgb)
#IM = Image.new('RGBA', crop.size)
crop_colouriszed = IT.colourize(crop, (0,0,0,0), colour)
IM.paste(crop_colouriszed, (0,0), crop)
draw = ImageDraw.Draw(IM)
IT.write_text_to_draw(draw,
"%s" %(character),
top_left=(24, 6),
font_name = 'Vera Bold',
font_size=70,
font_colour=self.params.html.font_colour.rgb)
name = "circle_%s.png" %character
if resize:
_ = int((cut[2]-cut[0])/self.sf), int((cut[3]-cut[1])/self.sf)
IM = IT.resize_image(IM, size=_, name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
return IM
def getImageItemsFromTextFile(self):
path = "%s/etc/gui/images/image_items.txt" %self.basedir
im_d = {}
if not os.path.exists(path):
return
rFile = open(path, 'r')
lines = rFile.readlines()
for line in lines:
if line.startswith("["):
key = line.strip().strip('[').strip(']')
im_d.setdefault(key,[])
elif line.startswith("#"):
continue
else:
if key:
im_d[key].append(line.strip())
rFile.close()
self.image_items_d = im_d
def create_logo(self):
factor = 4
#create a new image
width = IT.skin_width * factor
size = (width, 55 * factor)
IM = Image.new('RGBA', size, OV.GetParam('gui.html.bg_colour').rgb)
#this is the source of the images required for the logo
self.open_image_source()
im = self.imageSource
#first cut the small logo picture from the source
cut_right = (int(OV.GetParam('gui.htmlpanelwidth')) - 213) * factor
if cut_right > 1400:
cut_right = 1400
cut = 0, 228, cut_right, 430 * factor #the area of the small image
crop = im.crop(cut)
#crop_colourised = IT.colourize(crop, (0,0,0), self.params.logo_colour.rgb)
IM.paste(crop, (0,0), crop)
#then cut the actual logo
cut = 200 * factor, 0, 372 * factor, 55 * factor #the area of the olex writing
crop = im.crop(cut)
if OV.GetParam('gui.skin.logo_is_colourised'):
crop_colouriszed = IT.colourize(crop, (0,0,0), OV.GetParam('gui.logo_colour').rgb)
else:
crop_colouriszed = crop
IM.paste(crop_colouriszed, (width-(175 * factor),0), crop)
# Add Version and Tag info
size = (203,95)
new = Image.new('RGB', size, self.params.html.highlight_colour.rgb)
draw = ImageDraw.Draw(new)
x = 0
y = 0
# Add Tag
txt = "%s" %OV.GetTag()
IT.write_text_to_draw(draw,
"%s" %(txt),
top_left=(5, 5),
font_name = 'Vera',
font_size=38,
font_colour=IT.adjust_colour(self.params.html.font_colour.rgb, luminosity = 0.8))
# font_colour='#ffffff')
# Add version Number
txt = "%s" %OV.GetSVNVersion()
IT.write_text_to_draw(draw,
"%s" %(txt),
top_left=(5, 45),
font_name = 'Vera Bold',
font_size=43,
font_colour='#ffffff')
new = new.rotate(90)
IM.paste(new, (0, 0))
name = r"logo.png"
IM = IT.resize_image(IM, (IT.skin_width,55), name=name)
OlexVFS.save_image_to_olex(IM, name, 2)
def run(self):
self.params = OV.GuiParams()
do_these = ["make_generated_assorted_images",
"make_text_and_tab_items",
"make_label_items",
"make_button_items",
"make_cbtn_items",
"make_icon_items",
"make_image_items",
"make_note_items",
]
#do_these = []
self.create_logo()
for item in do_these:
if self.timer:
t1 = self.time.time()
a = getattr(self, item)
a()
if self.timer:
print "/t%s took %.3f s to complete" %(item, self.time.time()-t1)
def save_with_checking_for_needed(self):
name = self.name#.lower()
image = self.image
OlexVFS.save_image_to_olex(image, name, 2)
return
if olex_fs.Exists(name):
_ = OlexVFS.read_from_olex(name)
OlexVFS.save_image_to_olex(image, name, 2)
if _ == OlexVFS.read_from_olex(name):
self.no_need_to_refresh_image_type.setdefault(self.image_type,True)
else:
OlexVFS.save_image_to_olex(image, name, 2)
def make_generated_assorted_images(self):
image_type = 'assorted'
size = (6,15)
colour = self.params.html.table_firstcol_colour.rgb
#colour = "#00ff00"
image = Image.new('RGBA', size, colour)
draw = ImageDraw.Draw(image)
font_name = "Times Bold Italic"
IT.write_text_to_draw(draw,
"iZ",
top_left=(1, -1),
font_name=font_name,
font_size=14,
font_colour=self.params.html.font_colour.rgb)
name = "infos.png"
OlexVFS.save_image_to_olex(image, name, 2)
## Make the wedges for the Q-Peak slider
scale = 4
width = (int(self.params.htmlpanelwidth) - 81)
height = 8
size = (width*scale, height*scale)
colour = self.params.html.table_bg_colour.rgb
image = Image.new('RGBA', size, colour)
draw = ImageDraw.Draw(image)
left = 8*scale
right = (int(width/2) -3) *scale
top = 1*scale
bottom = height*scale
begin = (left, bottom)
middle = (right, top)
end = (right, bottom)
draw.polygon((begin, middle, end), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb, luminosity = 0.9))
begin = (left, top)
middle = (right, top)
end = (left, bottom)
draw.polygon((begin, middle, end), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb, luminosity = 1.1))
left = (int(width/2)+ 10)*scale
right = width*scale
begin = (left, top)
middle = (right, top)
end = (left, bottom)
draw.polygon((begin, middle, end), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb, luminosity = 0.9))
begin = (left, bottom)
middle = (right, top)
end = (right, bottom)
draw.polygon((begin, middle, end), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb, luminosity = 1.1))
begin = ((int(width/2)+ 2)*scale, (1*scale) + 1)
m1 = ((int(width/2)+ 5)*scale, (1*scale) +1)
m2 = ((int(width/2)+ 5)*scale, (height*scale) -1)
end = ((int(width/2)+ 2)*scale, (height*scale) -1)
draw.polygon((begin, m1, m2, end), IT.adjust_colour(self.params.html.table_firstcol_colour.rgb, luminosity = 0.8))
image = image.resize((width, height),Image.ANTIALIAS)
name = "qwedges.png"
OlexVFS.save_image_to_olex(image, name, 2)
def make_text_items(self):
textItems = []
textItems += self.image_items_d.get('H1',[])
textItems += self.image_items_d.get('H2',[])
for item in self.image_items_d.get('H3',[]):
textItems.append("h3-%s" %item)
directories = ["etc/gui", "etc/news", "etc/gui/blocks", "etc/gui/snippets", "etc/gui/g3", "etc/tutorials"]
for directory in directories:
for htmfile in OV.ListFiles("%s/%s/*.htm" %(self.basedir, directory)):
f = (htmfile.replace('\\', '/').split('/')[-1:])
f = f[0].split(".")[0]
if f.split("-")[0] != "index" and f[0] != "_":
f = f.replace("-and-", "-&-")
if f not in textItems:
textItems.append(f)
#elif f[0] != "_":
# tabItems.append(f)
for item in ('solution-settings-h3-solution-settings-extra', 'refinement-settings-h3-refinement-settings-extra',
'report-settings',):
textItems.append(item)
for item in textItems:
image_types = ['h3', 'h2']
if 'h3' in item:
self.image_type = 'h3'
else:
self.image_type = 'h2'
if self.no_need_to_refresh_image_type.get(self.image_type):
continue
if self.timer:
t1 = time.time()
states = ["on", "off", "highlight", "", "hover", "hoveron"]
name = ""
for state in states:
if self.no_need_to_refresh_image_type.get(self.image_type):
break
if "h3" in item:
if "-h3-" in item:
img_txt = item.split("-h3-")[1]
else:
img_txt = item.replace('h3-','')
if img_txt.lower() in self.new_l:
self.advertise_new = True
name = "h3-%s%s.png" %(item, state)
name = name.replace("h3-h3-","h3-")
name = name.replace("h3-h3-","h3-")
image = self.make_timage('h3', img_txt, state)
self.advertise_new = False
else:
img_txt = item
if img_txt in self.new_l:
self.advertise_new = True
image = self.make_timage('h1', img_txt, state)
self.advertise_new = False
name = "h2-%s%s.png" %(item, state)
name = name.replace(".new.","")
if name:
self.name = name
self.image = image
self.save_with_checking_for_needed()
#name = "h2-%s-%s.png" %(item, state)
#image.save("C:/tmp/%s" %name)
if self.timer:
t = self.time.time()-t1
self.text_time += t
print "\t\t - %.3f [%.1f]- to complete %s" %(self.time.time()-t1, self.text_time, item)
def make_tab_items(self):
tabItems = []
rFile = open("%s/etc/gui/blocks/index-tabs.htm" %(self.basedir), 'r')
for line in rFile:
t = line.split("