from __future__ import division #import PngImagePlugin import FileSystem as FS from ArgumentParser import ArgumentParser import Image import glob, os import copy import ImageDraw, ImageChops, ImageColor, ImageEnhance import OlexVFS #import olex_core import pickle import RoundedCorners import sys #from olexex import OlexVariables #OV = OlexVariables() import olexex #OV = olexex.OlexFunctions() from ImageTools import ImageTools IT = ImageTools() from olexFunctions import OlexFunctions OV = OlexFunctions() import olex_fs import olx import time olx.banner_slide = {} try: import olx import olex datadir = olx.DataDir() basedir = olx.BaseDir() # newdir = r"%s\etc\gui\images\tools" %datadir # if not os.path.isdir(newdir): # _mkdir(newdir) except: pass class ButtonMaker(ImageTools): def __init__(self, btn_dict, type="Generic"): super(ButtonMaker, self).__init__() 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.gui_image_font_name: font_name = self.gui_image_font_name if self.gui_button_font_name: font_name = self.gui_button_font_name icon_height = int(OV.FindValue('gui_html_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.gui_html_bg_colour) 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 = self.adjust_colour(self.gui_timage_colour, luminosity = 2.1) outline_colour = d.get("outline_colour", self.gui_html_table_bg_colour) 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', 'Verdana') 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.gui_htmlpanelwidth)-(number * minus) width = (width/number-9) if vline: vline.setdefault('position', width - 20) olx.SetVar('olex2_main_toolbar_vline_position', int(width - 20)) except: width = int(width) size = (int(width), int(height)) for state in states: font_colour = self.gui_html_font_colour bgcolour = d.get('bgcolour%s' %state, bgcolour) if txt in ["report", "solve", "refine"]: font_colour = d.get("fontcolour%s" %state, font_colour) #font_colour = self.adjust_colour(font_colour, luminosity=0.7) image = Image.new('RGBA', size, bgcolour) draw = ImageDraw.Draw(image) if grad: self.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": self.create_arrows(draw, height, direction="down", h_space=8, v_space=8, colour=font_colour, type='simple') elif state == "on": self.create_arrows(draw, height, direction="up", h_space=8, v_space=8, colour=font_colour, type='simple') elif state == "inactive": self.create_arrows(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 = self.adjust_colour(grad_colour, luminosity=1) else: colour = outline_colour self.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: self.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: self.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", "refine"]: if state == "on": outline_colour = self.gui_html_highlight_colour 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 = self.add_whitespace(image=image, side='right', weight=whitespace_right.get('weight',0), colour=whitespace_right.get('colour','#ffffff')) if whitespace_bottom: image = self.add_whitespace(image=image, side='bottom', weight=whitespace_bottom.get('weight',0), colour=whitespace_bottom.get('colour','#ffffff')) #image = self.add_whitespace(image=image, side='bottom', weight=1, colour = self.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.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 Console #olex2.fnt:frb_12") olex.m("htmguifontsize %s" %self.gui_html_font_size) olex.m("showwindow help false") #olex.m("grad true") def setGuiAttributesDefault(self): #self.gui_html_base_colour = "#ffffff" self.gui_html_bg_colour = "#ffffff" self.gui_html_font_colour = "#6f6f8b" self.gui_html_font_name = 'Arial' self.gui_html_font_size = '2' self.gui_html_icon_size = '20' self.gui_html_link_colour = "#6f6f8b" self.gui_html_table_bg_colour = "#F3F3F3" self.gui_html_table_firstcol_colour = "#E9E9E9" self.gui_table_rows = "#F3F3F3" self.gui_html_input_bg_colour="#efefef" self.gui_timage_colour = "#6464a0" self.gui_html_base_colour = "#6464a0" self.gui_logo_colour = "#6464a0" self.gui_skin_logo_name = "basedir()\etc\gui\images\src\default.png" self.gui_skin_extension="None" self.gui_html_panelwidth = '400' self.gui_snumtitle_colour='#6464a0' self.gui_html_highlight_colour = '#ff7800' self.gui_grad_top_left = '#05053c' self.gui_grad_top_right = '#05053c' self.gui_grad_bottom_left = '#ffffff' self.gui_grad_bottom_right = '#ffffff' self.gui_htmlpanelwidth = '400' def run_GuiSkinChanger(self): verbose = OV.GetParam('olex2.verbose') path = r"gui/images/src/default.png" skin = self.gui_skin_name skin_extension = self.gui_skin_extension if skin_extension == "None": skin_extension = None config = {} if "#" in skin: #self.getVariables('gui') #self.set_custom(skin) #self.setGuiAttributes() self.getVariables('gui') self.setGuiAttributesDefault() self.setOlexColours() path = r"gui/images/src/default.png" import PilTools elif "(" in skin: #self.getVariables('gui') self.set_custom(skin) self.getVariables('gui') self.setGuiAttributesDefault() self.setVariables("gui") self.setOlexColours() path = r"gui/images/src/default.png" import PilTools #elif skin == "default": #self.setGuiAttributesDefault() #self.setGuiAttributes() #self.setVariables('gui') #self.setOlexColours() #path = r"gui/images/src/default.png" #import PilTools ## this is a 'named' skin - ie should have a plugin-folder associated with it else: self.getVariables('gui') self.setGuiAttributesDefault() self.setVariables("gui") 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 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()) 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.gui_html_base_colour = config.get('GUI_HTML_BASE_COLOUR', '#0000ff') self.setGuiAttributes(config) self.setVariables('gui') self.setOlexColours() self.resize_skin_logo(self.gui_htmlpanelwidth) self.setVariables("gui") #sNumTitle_instance.run_sNumTitle() #timage_instance.run_timage() width = OV.FindValue('gui_htmlpanelwidth') olx.HtmlPanelWidth(width) self.setGuiProperties() OV.HtmlReload() #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.gui_html_bg_colour = "#ffffff" self.gui_html_font_colour = self.RGBToHTMLColor(self.adjust_colour(colour, hue = 180, luminosity = 0.8)) self.gui_html_link_colour = "#6f6f8b" self.gui_html_table_bg_colour = self.RGBToHTMLColor(self.adjust_colour(colour, luminosity = 2)) self.gui_html_table_firstcol_colour = self.RGBToHTMLColor(self.adjust_colour(colour, luminosity = 1.8)) self.gui_html_input_bg_colour = self.RGBToHTMLColor(self.adjust_colour(colour, luminosity = 1.9)) self.gui_timage_colour = self.RGBToHTMLColor(self.adjust_colour(colour, luminosity = 0.9)) class MatrixMaker(ImageTools): def __init__(self): super(MatrixMaker, self).__init__() #import PngImagePlugin #import Image #import ImageDraw, ImageChops def make_3x3_matrix_image(self, name, matrix, text_def=""): width = 52 height = 55 size = (width, height) font_name = "Arial" font_size = 13 font = self.registerFontInstance(font_name, font_size) line_heigth = font_size -2 im = Image.new('RGBA', size, '#dedede') 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 = self.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)) name = r"%s.png" %(name) OlexVFS.save_image_to_olex(im, name, 2) return name, im def fade_image(image, frames=5, overlay_colour=(255, 255, 255), filename="out.gif"): 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.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(ImageTools): def __init__(self, type='vbar', colour='grey', size=100, basedir=""): super(BarGenerator, self).__init__() 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\gui\images\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 = self.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 = self.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 = self.adjust_colour(OV.FindValue('gui_green'), 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 = self.adjust_colour(colour_a, luminosity = 1) draw = ImageDraw.Draw(image) self.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.thickness = 5 self.factor = 300 #self.gui_html_bg_colour = OV.FindValue('gui_html_bg_colour') def run_MakeAllRBars(self): 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.gui_html_table_bg_colour) draw = ImageDraw.Draw(image) draw.line(((width-2, 0) ,(width-2, height)), fill='#666666') font_name = "Verdana Bold" font_size = 10 font = self.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 = self.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.gui_html_table_bg_colour) return image MakeAllRBars_instance = MakeAllRBars() OV.registerMacro(MakeAllRBars_instance.run_MakeAllRBars, '') class sNumTitle(ImageTools): def __init__(self, width=None, tool_arg=None): super(sNumTitle, self).__init__() self.have_connection = False width = self.gui_htmlpanelwidth if not width: width = 290 try: width = float(width) except: width = float(tool_arg) if tool_arg: args = tool_arg.split(";") if args[0] == "None": self.gui_html_base_colour = OV.FindValue('gui_html_base_colour') elif args[0][:1] == "#": self.gui_html_base_colour = self.HTMLColorToRGB(args[0]) else: self.gui_html_base_colour = args[0] else: self.gui_html_base_colour = OV.FindValue('gui_html_base_colour') if self.have_connection: try: import SQLFactories self.ds = SQLFactories.SQLFactory() except: self.have_connection = False pass self.sNum = self.filename try: width = float(width) except: width = float(tool_arg) self.width = int((width) - 22) def run_sNumTitle(self, force=False): self.gui_html_base_colour = OV.FindValue('gui_html_base_colour') self.width = int(OV.FindValue('gui_htmlpanelwidth')) - 22 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.FindValue("olex2_sNum_id_string","") if id_string == curr_id: if not force: return OV.SetVar("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) 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): if self.gui_sNumTitle_font_name: font_name = self.gui_sNumTitle_font_name width = self.width height = 24 self.height = height gap = 0 bgap = height - gap size = (int(width), int(height)) #cs = copy.deepcopy(cS1) if olx.IsFileType("cif") == 'true': base = (255, 0, 0) base = self.gui_timage_colour image = Image.new('RGBA', size, base) draw = ImageDraw.Draw(image) grad_colour = self.adjust_colour("base", luminosity = 1.1) self.gradient_bgr(draw, width, height, colour = grad_colour, fraction=1, step=0.7) cache = {} pos = (('Rounded'),('Rounded'),('Square'),('Square')) #pos = (('Rounded'),('Rounded'),('Rounded'),('Rounded')) #pos = (('Square'),('Square'),('Square'),('Square')) image = RoundedCorners.round_image(image, cache, 2, pos=pos) #used to be 10 #border_rad=20 #self.make_border(rad=border_rad, #draw=draw, #width=width, #height=height, #bg_colour=base, #border_colour=base, #cBottomLeft=False, #cBottomRight=False, #border_hls = (0, 1.2, 1) #) sNum = items["sNum"] if sNum == "none": sNum = "No Structure" self.write_text_to_draw(draw, sNum, top_left=(6, 1), font_name=font_name, font_size=17, image_size = image.size, valign=("middle", 0.8), font_colour=self.adjust_colour("base", luminosity = 2.0)) self.drawFileFullInfo(draw, luminosity=1.8, right_margin=3, bottom_margin=0) self.drawSpaceGroupInfo(draw, luminosity=1.8, right_margin=3) ### Draw this info ONLY if there is a connection to the MySQL database #if self.have_connection: #self.drawDBInfo() dup = ImageChops.duplicate(image) dup = ImageChops.invert(dup) dup = ImageChops.offset(dup, 1, 1) image = ImageChops.blend(image, dup, 0.05) return image def drawFileFullInfo(self, draw, luminosity=1.8, right_margin=0, bottom_margin=0, font_name="Verdana", font_size=8): left_start = 120 txt = self.filefull if len(txt) > 26: txtbeg = txt[:5] txtend = txt [-25:] txt = "%s...%s" %(txtbeg, txtend) font = self.registerFontInstance(font_name, font_size) tw = (draw.textsize(txt, font)[0]) left_start = (self.width-tw) - right_margin bottom = self.height - bottom_margin - 9 self.write_text_to_draw(draw, txt, top_left=(left_start, 12), font_name=font_name, font_size=font_size, font_colour=self.adjust_colour("base", luminosity=luminosity)) def drawSpaceGroupInfo(self, draw, luminosity=1.9, right_margin=12, font_name="Times Bold"): left_start = 120 font_colour = self.adjust_colour("base", luminosity=luminosity) try: txt_l = [] txt_sub = [] txt_norm = [] try: txt = OV.olex_function('sg(%h)') except: pass if not txt: txt="ERROR" txt = txt.replace(" 1", "") txt = txt.replace(" ", "") txt_l = txt.split("") if len(txt_l) == 1: txt_norm = [(txt,0)] try: font_base = "Times" #font_slash = self.registerFontInstance("Times Bold", 18) #font_number = self.registerFontInstance("Times Bold", 14) #font_letter = self.registerFontInstance("Times Bold Italic", 15.5) #font_sub = self.registerFontInstance("Times Bold", 10) font_bar = self.registerFontInstance("%s Bold" %font_base, 11) font_slash = self.registerFontInstance("%s Bold" %font_base, 18) font_number = self.registerFontInstance("%s Bold" %font_base, 14) font_letter = self.registerFontInstance("%s Bold Italic" %font_base, 15) font_sub = self.registerFontInstance("%s Bold" %font_base, 10) norm_kern = 2 sub_kern = 0 except: font_name = "Arial" font_bar = self.registerFontInstance("%s Bold" %font_base, 12) font_slash = self.registerFontInstance("%s Bold" %font_base, 18) font_number = self.registerFontInstance("%s Bold" %font_base, 14) font_letter = self.registerFontInstance("%s Bold Italic" %font_base, 15) font_norm = self.registerFontInstance(font_name, 13) font_sub = self.registerFontInstance(font_name, 10) norm_kern = 0 sub_kern = 0 textwidth = 0 for item in txt_l: if item: try: sub = item.split("")[1] except: sub = "" norm = item.split("")[0] tw_s = (draw.textsize(sub, font=font_sub)[0]) + sub_kern tw_n = (draw.textsize(norm, font=font_number)[0]) + norm_kern txt_sub.append((sub, tw_s)) txt_norm.append((norm, tw_n)) textwidth += (tw_s + tw_n) except: txt_l = [] if txt_l: i = 0 left_start = (self.width-textwidth) - right_margin -5 cur_pos = left_start advance = 0 after_kern = 0 for item in txt_l: if item: text_normal = txt_norm[i][0] for character in text_normal: if character == "": continue cur_pos += advance cur_pos += after_kern after_kern = 2 advance = 0 try: int(character) font = font_number top = 0 after_kern = 2 except: font = font_letter top = -1 if character == "P" or character == "I" or character == "C": norm_kern = -2 after_kern = 0 character = " %s" %character if character == "-": draw.text((cur_pos + 1, -10), "_", font=font_bar, fill=font_colour) draw.text((cur_pos + 1, -9), "_", font=font_bar, fill=font_colour) advance = -1 norm_kern = 0 elif character == "/": norm_kern = 0 after_kern = 0 draw.text((cur_pos -2, -3), "/", font=font_slash, fill=font_colour) advance = ((draw.textsize("/", font=font_slash)[0]) + norm_kern) - 1 else: draw.text((cur_pos + norm_kern, top), "%s" %character, font=font, fill=font_colour) advance = (draw.textsize(character, font=font)[0]) + norm_kern text_in_superscript = txt_sub[i][0] if text_in_superscript: cur_pos += advance draw.text((cur_pos + sub_kern, 5), "%s" %text_in_superscript, font=font_sub, fill=font_colour) advance = (draw.textsize(text_in_superscript, font=font_sub)[0]) + sub_kern after_kern = -2 cur_pos += advance i+= 1 class timage(ImageTools): def __init__(self, width=None, tool_arg=None): super(timage, self).__init__() self.getVariables('gui') self.advertise_new = False self.new_l = ['images'] #from PilTools import ButtonMaker self.abort = False width = self.gui_htmlpanelwidth if not width: width = 350 else: try: width = float(width) except: width = float(tool_arg) self.font_name = "Vera" self.timer = False if self.timer: import time self.time = time if tool_arg: args = tool_arg.split(";") if args[0] == "None": self.gui_html_base_colour = OV.FindValue('gui_html_base_colour') else: self.gui_html_base_colour = self.HTMLColorToRGB(args[0]) self.width = int((width) - 22) if self.width <= 0: self.width = 10 icon_source = "%s/etc/gui/images/src/icons.png" %self.basedir image_source = "%s/etc/gui/images/src/images.png" %self.basedir self.iconSource = Image.open(icon_source) self.imageSource = Image.open(image_source) self.olex2_has_recently_updated = OV.GetParam('olex2.has_recently_updated') sf = 4 #images are four times larger than the nominal width of 350 sfs = sf * 350/int(self.gui_htmlpanelwidth) self.sf = sf self.sfs = sfs def resize_news_image(self): IT.resize_to_panelwidth({'i':'news/news.png'}) def run_timage(self): do_these = [] if not self.olex2_has_recently_updated: if not OV.GetParam('olex2.force_images'): do_these = [ "make_cbtn_items", "info_bitmaps", ] 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_image_items", "make_note_items", "make_images_from_fb_png", "make_popup_banners", "info_bitmaps", #"makeTestBanner", "resize_news_image", "create_logo" ] self.getVariables('gui') self.gui_html_base_colour = OV.FindValue('gui_html_base_colour') self.width = int(OV.FindValue('gui_htmlpanelwidth')) - 22 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 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) self.write_text_to_draw(draw, "%s" %txt, top_left=(440, 32), font_name = 'Vera', font_size=42, titleCase=False, font_colour="#525252", align='left' ) IM = self.resize_image(IM, (width, height)) name = "banner_%s.png" %txt OlexVFS.save_image_to_olex(IM, name, 2) def make_images_from_fb_png(self): sf = self.sf image_source = self.imageSource self.getImageItemsFromTextFile() im = image_source cut = 0, 52*sf, 27*sf, 76*sf crop = im.crop(cut) self.warning = Image.new('RGBA', crop.size, self.gui_html_bg_colour) self.warning.paste(crop, (0,0), crop) name = "warning.png" self.warning = self.resize_image(self.warning, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) OlexVFS.save_image_to_olex(self.warning, name, 2) cut = 140*sf, 58*sf, 170*sf, 81*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size, self.gui_html_table_firstcol_colour) IM.paste(crop, (0,0), crop) #draw = ImageDraw.Draw(IM) #draw.rectangle((0, 0, IM.size[0]-1, IM.size[1]-1), outline='#bcbcbc') IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "HelpImage.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 201*sf, 58*sf, 227*sf, 81*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size, self.gui_html_bg_colour) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop, (0,0), crop) #draw = ImageDraw.Draw(IM) #draw.rectangle((0, 0, IM.size[0]-1, IM.size[1]-1), outline='#bcbcbc') IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "popout.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 227*sf, 58*sf, 300*sf, 81*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop, (0,0), crop) #draw = ImageDraw.Draw(IM) #draw.rectangle((0, 0, IM.size[0]-1, IM.size[1]-1), outline='#bcbcbc') IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "return.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 0*sf, 0*sf, 275*sf, 55*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size, self.gui_html_bg_colour) IM.paste(crop, (0,0), crop) cut = 0*sf, 95*sf, 100*sf, 150*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_html_highlight_colour) IM.paste(crop_colouriszed, (190,10), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "olex_help_logo.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 140*sf, 154*sf, 220*sf, 175*sf max_width = cut[2] - cut[0] crop = im.crop(cut) txt_l= ("Prepare", "Solve", "Refine", "Analyze", ) states = ["on", "off", ""] for state in states: if state == "on": colour = self.adjust_colour(self.gui_html_highlight_colour,luminosity=1.3) elif state == "off": colour = self.adjust_colour(self.gui_html_base_colour,luminosity=1.9) elif state == "": colour = self.adjust_colour(self.gui_html_base_colour,luminosity=1.9) for txt in txt_l: #IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) #crop_colouriszed = self.colourize(crop, (0,0,0), colour) crop_colouriszed = crop IM = Image.new('RGBA', crop.size) circle = self.makeCharcterCircles(str('1'), im, self.gui_html_table_firstcol_colour, resize = False) IM.paste(crop_colouriszed, (0,0), crop) IM.paste(circle,(0,0), circle) draw = ImageDraw.Draw(IM) t = txt.replace("blank"," _ ") self.write_text_to_draw(draw, "%s" %t, top_left=(10, 6), font_name = 'Vera', font_size=48, titleCase=True, font_colour="#ff0000", max_width = max_width, align='centre' ) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "comp-%s%s.png" %(txt.replace(" ", "_"), state) name = name.lower() OlexVFS.save_image_to_olex(IM, name, 2) if name == "button_small-blank.png": OlexVFS.save_image_to_olex(IM, name, 2) # filename = r"%s/button_small-blank.png" %self.datadir # IM.save(filename) IM = Image.new('RGBA', crop.size) IM.paste(crop, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "test.png" OlexVFS.save_image_to_olex(IM, name, 2) ## TINY buttons cut = 138*sf, 178*sf, 158*sf, 195*sf max_width = cut[2] - cut[0] crop = im.crop(cut) button_names = self.image_items_d.get("TINY BUTTONS") scale = self.sf / 1.2 self.produce_buttons(button_names, crop, cut, max_width, scale,"_tiny") ## SMALL buttons cut = 90*sf, 178*sf, 138*sf, 193*sf max_width = cut[2] - cut[0] crop = im.crop(cut) button_names = self.image_items_d.get("SMALL BUTTONS") self.produce_buttons(button_names, crop, cut, max_width,self.sf,"_small") ## THREEE buttons in the HTMLpanelWIDTH cut = 0*sf, 178*sf, 91*sf, 195*sf max_width = cut[2] - cut[0] crop = im.crop(cut) button_names = self.image_items_d.get("THREE BUTTONS PER ROW", button_names) self.produce_buttons(button_names, crop, cut, max_width,self.sfs,"") ## FULL ROW buttons in the HTMLpanelWIDTH cut = 0*sf, 193*sf, 275*sf, 211*sf max_width = cut[2] - cut[0] crop = im.crop(cut) button_names = self.image_items_d.get("FULL ROW", button_names) self.produce_buttons(button_names, crop, cut, max_width,self.sfs,"_full") cut = 0*sf, 152*sf, 15*sf, 167*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.adjust_colour(self.gui_html_table_firstcol_colour,luminosity=1.98)) #crop_colouriszed = self.colourize(crop, (0,0,0), self.adjust_colour(self.gui_green,luminosity=1.3,saturation=0.7)) #crop_colouriszed = self.colourize(crop, (0,0,0), self.adjust_colour(self.gui_html_base_colour,luminosity=1.7)) #crop_colouriszed = self.colourize(crop, (0,0,0), self.adjust_colour(self.gui_html_base_colour,luminosity=1.5)) IM = Image.new('RGBA', crop.size, self.gui_html_table_firstcol_colour) IM.paste(crop_colouriszed, (0,0), crop) name = "info.png" IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) draw = ImageDraw.Draw(IM) txt = IT.get_unicode_characters('info') #txt = "i" self.write_text_to_draw(draw, txt, top_left=(5, 0), font_name = 'Vera', font_size=14, translate=False, font_colour=self.adjust_colour(self.gui_html_table_firstcol_colour,luminosity=0.7)) OlexVFS.save_image_to_olex(IM, name, 2) cut = 16*sf, 156*sf, 26*sf, 166*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.adjust_colour(self.gui_html_table_firstcol_colour,luminosity=1.7)) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop_colouriszed, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "info_tiny.png" draw = ImageDraw.Draw(IM) txt = IT.get_unicode_characters('info') self.write_text_to_draw(draw, txt, top_left=(1, 1), font_name = 'Vera', font_size=6, font_colour=self.gui_html_font_colour) OlexVFS.save_image_to_olex(IM, name, 2) cut = 16*sf, 156*sf, 26*sf, 166*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.adjust_colour(self.gui_html_table_firstcol_colour,luminosity=0.7)) IM = Image.new('RGBA', crop.size, self.gui_html_table_firstcol_colour) IM.paste(crop_colouriszed, (0,0), crop) draw = ImageDraw.Draw(IM) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) self.write_text_to_draw(draw, "i", top_left=(2, 1), font_name = 'Vera', font_size=10, font_colour="#ffffff") name = "info_tiny_fc.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 16*sf, 156*sf, 26*sf, 166*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_html_highlight_colour) IM = Image.new('RGBA', crop.size, self.gui_html_table_firstcol_colour) IM.paste(crop_colouriszed, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) draw = ImageDraw.Draw(IM) self.write_text_to_draw(draw, "i", top_left=(3, -1), font_name = 'Vera Bold Italic', font_size=11, font_colour="#ffffff") name = "info_tiny_new.png" 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 = self.colourize(crop, (0,0,0), self.gui_html_table_firstcol_colour) for i in xrange(12): self.makeCharcterCircles(str(i), im, self.gui_html_table_firstcol_colour) colo = self.adjust_colour(self.gui_green,saturation=0.7,luminosity=2.1) l = ["a", "b", "c", "d", "e", "f"] for letter in l: self.makeCharcterCircles(letter, im, colo) cut = 55*sf, 150*sf, 80*sf, 175*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "settings_small.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 80*sf, 154*sf, 100*sf, 171*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "delete.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 101*sf, 154*sf, 117*sf, 165*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "delete_small.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 136*sf, 154*sf, 185*sf, 170*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_html_base_colour) IM = Image.new('RGBA', crop.size) IM.paste(crop_colouriszed, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "bottom.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 185*sf, 154*sf, 205*sf, 170*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_html_highlight_colour) IM = Image.new('RGBA', crop.size) IM.paste(crop_colouriszed, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "next.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 205*sf, 154*sf, 220*sf, 170*sf crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_html_highlight_colour) IM = Image.new('RGBA', crop.size) IM.paste(crop_colouriszed, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "previous.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 120*sf, 154*sf, 135*sf, 175*sf crop = im.crop(cut) IM = Image.new('RGBA', crop.size) IM.paste(crop, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "warning.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 140*sf, 98*sf, 400*sf, 140*sf max_width = cut[2] - cut[0] crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_html_highlight_colour) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop_colouriszed, (0,0), crop) draw = ImageDraw.Draw(IM) self.write_text_to_draw(draw, "You are in a Mode", top_left=(5, 1), font_name = 'Vera Bold', font_size=90, font_colour=self.gui_html_font_colour, align='centre', max_width=max_width ) sfm = sf*0.95 IM = self.resize_image(IM, (int((cut[2]-cut[0])/sfm), int((cut[3]-cut[1])/sfm))) name = "pop_background.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 140*sf, 98*sf, 400*sf, 140*sf max_width = cut[2] - cut[0] crop = im.crop(cut) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_html_highlight_colour) IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM.paste(crop_colouriszed, (0,0), crop) draw = ImageDraw.Draw(IM) self.write_text_to_draw(draw, "You are in a Mode", top_left=(5, 1), font_name = 'Vera Bold', font_size=90, font_colour=self.gui_html_font_colour, align='centre', max_width=max_width ) sfm = sf*0.95 IM = self.resize_image(IM, (int((cut[2]-cut[0])/sfm), int((cut[3]-cut[1])/sfm))) name = "pop_background.png" OlexVFS.save_image_to_olex(IM, name, 2) cut = 90*sf, 95*sf, 140*sf, 140*sf crop = im.crop(cut) # IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) IM = Image.new('RGBA', crop.size) IM.paste(crop, (0,0), crop) IM = self.resize_image(IM, (int((cut[2]-cut[0])/sf), int((cut[3]-cut[1])/sf))) name = "warning_big.png" OlexVFS.save_image_to_olex(IM, name, 2) def produce_buttons(self, button_names, crop, cut, max_width,scale,btn_type): states = ["on", "off", ""] for state in states: if state == "on": colour = self.adjust_colour(self.gui_html_highlight_colour,luminosity=1.3) elif state == "off": #colour = self.adjust_colour(self.gui_html_base_colour,luminosity=1.9) colour = self.gui_button_colouring elif state == "": #colour = self.adjust_colour(self.gui_html_base_colour,luminosity=1.9) colour = self.gui_button_colouring for txt in button_names: #IM = Image.new('RGBA', crop.size, self.gui_html_table_bg_colour) crop_colouriszed = self.colourize(crop, (0,0,0), colour) IM = Image.new('RGBA', crop.size) IM.paste(crop_colouriszed, (0,0), crop) draw = ImageDraw.Draw(IM) t = txt.replace("blank"," _ ") self.write_text_to_draw(draw, "%s" %t, top_left=(4, 7), font_name = 'Vera', font_size=40, titleCase=False, font_colour=self.gui_button_writing, max_width = max_width, align='centre' ) IM = self.resize_image(IM, (int((cut[2]-cut[0])/scale), int((cut[3]-cut[1])/scale))) name = "button%s-%s%s.png" %(btn_type, txt.replace(" ", "_"), state) name = name.lower() OlexVFS.save_image_to_olex(IM, name, 2) 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.gui_html_base_colour col_0 = self.adjust_colour(bannerbg,luminosity=0.85) col_1 = self.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.gui_html_font_colour offset = 180 height = 44 width = 1700 size = (width,height) IM = Image.new('RGBA', size, self.gui_html_table_bg_colour) 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=self.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=self.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.gui_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) self.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.gui_htmlpanelwidth) - 24 size = (width, height) self.banner_make_decoration_image(size) for j in xrange(129): self.banner_map = "" step = 10 x1 = 0 + j * step x2 = x1 + width cut = (x1, 0, x2, height) crop = IM.crop(cut) # crop = Image.new('RGBA', (width, height), bannerbg) draw = ImageDraw.Draw(crop) margin_top_l = [-3, 8, 24] font_size_l = [42, 13, 13] font_l = ["Vera Bold", "Vera", "Vera"] 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 x_pos = (txt_items[item].get("pix",0) + offset) - (j * step) y_pos = margin_top_l[row] wX = txt_items[item].get('txt_dimensions')[0] wY = txt_items[item].get('txt_dimensions')[1] if row != 0: self.banner_map_add_area(txt_items[item], x_pos, y_pos, wX, wY) self.banner_map_complete() self.banner_write_file(j) #crop = self.decorate_banner_image(crop, size, bannerbg, j) crop.paste(self.banner_decoration_image[0], mask = self.banner_decoration_image[1]) name = "banner_%s.png" %j OlexVFS.save_image_to_olex(crop, name, 2) if j == 0: OlexVFS.save_image_to_olex(crop, "banner.png", 2) return "Done" def banner_map_add_area(self, d, x_pos, y_pos, wX, wY): itemstate = d.get('itemstate', "") cmd = d.get('cmd', "") name = d.get('name',"No Name Found") txt = ''' '''%(x_pos, y_pos, (x_pos + wX), (y_pos + wY), itemstate, cmd, name) self.banner_map += txt def banner_map_complete(self): txt = ''' ''' 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.gui_html_base_colour) + (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.gui_html_base_colour 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.gui_html_table_bg_colour) #IM = Image.new('RGBA', crop.size) crop_colouriszed = self.colourize(crop, (0,0,0,0), colour) IM.paste(crop_colouriszed, (0,0), crop) draw = ImageDraw.Draw(IM) self.write_text_to_draw(draw, "%s" %(character), top_left=(24, 6), font_name = 'Vera Bold', font_size=70, font_colour=self.gui_html_font_colour) if resize: IM = self.resize_image(IM, (int((cut[2]-cut[0])/self.sf), int((cut[3]-cut[1])/self.sf))) name = "circle_%s.png" %character 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()) self.image_items_d = im_d def create_logo(self): factor = 4 #create a new image width = self.width * factor size = (width, 55 * factor) IM = Image.new('RGBA', size, self.gui_html_bg_colour) #this is the source of the images required for the logo image_source = "%s/etc/gui/images/src/images.png" %self.basedir im = Image.open(image_source) #first cut the small logo picture from the source cut_left = 200 * factor - (int(self.gui_htmlpanelwidth) - 200) * factor if cut_left <= 0: cut_left = 0 cut = cut_left, 0, 200 * factor, 55 * factor #the area of the small image crop = im.crop(cut) #crop_colourised = self.colourize(crop, (0,0,0), self.gui_logo_colour) 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) crop_colouriszed = self.colourize(crop, (0,0,0), self.gui_logo_colour) IM.paste(crop_colouriszed, (width-(175 * factor),0), crop) # Add Version and Tag info size = (203,95) new = Image.new('RGB', size, self.gui_html_highlight_colour) draw = ImageDraw.Draw(new) x = 0 y = 0 # Add Tag txt = "%s" %OV.GetTag() self.write_text_to_draw(draw, "%s" %(txt), top_left=(5, 5), font_name = 'Vera', font_size=38, font_colour=self.adjust_colour(self.gui_html_font_colour, luminosity = 0.8)) # font_colour='#ffffff') # Add version Number txt = "%s" %OV.GetSVNVersion() self.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)) #finally resize and save the final image IM = self.resize_image(IM, (self.width, 55)) name = r"gui/images/logo.png" OlexVFS.save_image_to_olex(IM, name, 2) def run(self): 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 make_generated_assorted_images(self): size = (6,15) colour = self.gui_html_table_firstcol_colour #colour = "#00ff00" image = Image.new('RGBA', size, colour) draw = ImageDraw.Draw(image) font_name = "Times Bold Italic" self.write_text_to_draw(draw, "i", top_left=(1, -1), font_name=font_name, font_size=14, font_colour=self.gui_html_font_colour) name = "infos.png" OlexVFS.save_image_to_olex(image, name, 2) ## Make the wedges for the Q-Peak slider scale = 4 width = (int(self.gui_htmlpanelwidth) - 81) height = 8 size = (width*scale, height*scale) colour = self.gui_html_table_bg_colour 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), self.adjust_colour(self.gui_html_table_firstcol_colour, luminosity = 0.9)) begin = (left, top) middle = (right, top) end = (left, bottom) draw.polygon((begin, middle, end), self.adjust_colour(self.gui_html_table_firstcol_colour, 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), self.adjust_colour(self.gui_html_table_firstcol_colour, luminosity = 0.9)) begin = (left, bottom) middle = (right, top) end = (right, bottom) draw.polygon((begin, middle, end), self.adjust_colour(self.gui_html_table_firstcol_colour, 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), self.adjust_colour(self.gui_html_table_firstcol_colour, luminosity = 0.8)) image = image.resize((width, height),Image.ANTIALIAS) name = "qwedges.png" OlexVFS.save_image_to_olex(image, name, 2) def make_text_and_tab_items(self): bitmap = "working" olx.CreateBitmap('-r %s %s' %(bitmap, bitmap)) textItems = [] tabItems = [] directories = ["etc/gui", "etc/news", "etc/gui/blocks", "etc/gui/snippets"] rFile = open("%s/etc/gui/blocks/index-tabs.htm" %(self.basedir), 'r') for line in rFile: t = line.split("