def drawTimeLine(self, width=None): if width == None: width = 3.0 tl = self.timeLine for item in tl.find_all(): tl.delete(item) for c in self.clusters: c.canvasItems = [] c.canvas = tl frameNums = range(self.startFrame, self.endFrame+1, self.stride) cluster = startFrame = None f2x = self._frame2x height = 22 for fn in frameNums: c = self.clusterMap[fn] if c == cluster: continue if cluster != None: tkColor = rgba2tk(cluster.color) cluster.canvasItems.append(tl.create_rectangle( f2x(startFrame), 0, f2x(fn)-1, height, fill=tkColor, outline=tkColor)) cluster = c startFrame = fn tkColor = rgba2tk(cluster.color) cluster.canvasItems.append(tl.create_rectangle(f2x(startFrame), 0, f2x(frameNums[-1]+self.stride)-1, height, fill=tkColor, outline=tkColor)) for c in self.clusters: rep = c.representative tkColor = rgba2tk(c.color) c.canvasItems.append(tl.create_rectangle( f2x(rep), 0, f2x(rep+self.stride)-1, -0.5*height, fill=tkColor, outline=tkColor)) tl.resizescrollregion()
def _rectKw(self): kw = {} if self.interiorRGBA: kw['fill'] = rgba2tk(self.interiorRGBA) if self._borderRGBA(): kw['outline'] = rgba2tk(self._borderRGBA()) if self.highlighted: kw['dash'] = '-' else: kw['width'] = 0 kw['outline'] = "" return kw
def setColor(self, color): self.__color = color if hasattr(self, 'canvasItems'): tkColor = rgba2tk(color) for i in self.canvasItems: self.canvas.itemconfigure(i, fill=tkColor, outline=tkColor)
def drawTimeLine(self, width=None): if width == None: width = 3.0 tl = self.timeLine for item in tl.find_all(): tl.delete(item) for c in self.clusters: c.canvasItems = [] c.canvas = tl frameNums = range(self.startFrame, self.endFrame + 1, self.stride) cluster = startFrame = None f2x = self._frame2x height = 22 for fn in frameNums: c = self.clusterMap[fn] if c == cluster: continue if cluster != None: tkColor = rgba2tk(cluster.color) cluster.canvasItems.append( tl.create_rectangle(f2x(startFrame), 0, f2x(fn) - 1, height, fill=tkColor, outline=tkColor)) cluster = c startFrame = fn tkColor = rgba2tk(cluster.color) cluster.canvasItems.append( tl.create_rectangle(f2x(startFrame), 0, f2x(frameNums[-1] + self.stride) - 1, height, fill=tkColor, outline=tkColor)) for c in self.clusters: rep = c.representative tkColor = rgba2tk(c.color) c.canvasItems.append( tl.create_rectangle(f2x(rep), 0, f2x(rep + self.stride) - 1, -0.5 * height, fill=tkColor, outline=tkColor)) tl.resizescrollregion()
def setInteriorRGBA(self, rgba): if rgba: fill = rgba2tk(rgba) else: fill = "" for item in self._items: self.canvas.itemconfigure(item, fill=fill) self.interiorRGBA = rgba
def alternateColors(parent): "Generate an alternate color to the default background color" import Tkinter from CGLtk.color import rgba2tk from CGLtk.color.ColorWell import _tkrgb2rgba w = Tkinter.Button(parent, text="Hello") bg = w.cget("bg") fg = w.cget("fg") disabledColor = w.cget("disabledforeground") b_r, b_g, b_b, b_a = _tkrgb2rgba(w.winfo_rgb(bg)) f_r, f_g, f_b, f_a = _tkrgb2rgba(w.winfo_rgb(fg)) w.destroy() r = b_r + (f_r - b_r) / 10.0 g = b_g + (f_g - b_g) / 10.0 b = b_b + (f_b - b_b) / 10.0 alt_bg = rgba2tk((r, g, b, b_a)) return (bg, alt_bg), disabledColor
def _plotMarkers(self): canvas = self._canvas br = self['boxradius'] markerType = self['markertype'] if markerType == 'line': x1, y1, x2, y2 = self._dragRegion() for m in self.markers: if m['id'] != None: continue x, y = self._canvasXY(m['xy']) color = rgba2tk(m['rgba']) if markerType == 'line': m['id'] = canvas.create_rectangle(x-br, y1, x+br, y2, fill=color) else: m['id'] = canvas.create_rectangle(x-br, y-br, x+br, y+br, fill=color)
def _updateConnections(self): cxy_list = map(lambda m: self._canvasXY(m['xy']), self.markers) canvas = self._canvas color = rgba2tk(self._rgba(self['connectcolor'])) ids = [] for k in range(len(cxy_list) - 1): x0, y0 = cxy_list[k] x1, y1 = cxy_list[k + 1] id = canvas.create_line(x0, y0, x1, y1, fill=color) ids.append(id) for id in self.connectIds: c.delete(id) self.connectIds = ids for m in self.markers: canvas.tag_raise(m['id'])
def _updateConnections(self): cxy_list = map(lambda m: self._canvasXY(m['xy']), self.markers) canvas = self._canvas color = rgba2tk(self._rgba(self['connectcolor'])) ids = [] for k in range(len(cxy_list) - 1): x0, y0 = cxy_list[k] x1, y1 = cxy_list[k+1] id = canvas.create_line(x0, y0, x1, y1, fill=color) ids.append(id) for id in self.connectIds: c.delete(id) self.connectIds = ids for m in self.markers: canvas.tag_raise(m['id'])
def _plotMarkers(self): canvas = self._canvas br = self['boxradius'] markerType = self['markertype'] if markerType == 'line': x1, y1, x2, y2 = self._dragRegion() for m in self.markers: if m['id'] != None: continue x, y = self._canvasXY(m['xy']) color = rgba2tk(m['rgba']) if markerType == 'line': m['id'] = canvas.create_rectangle(x - br, y1, x + br, y2, fill=color) else: m['id'] = canvas.create_rectangle(x - br, y - br, x + br, y + br, fill=color)
def _setRgba(self): if self['id'] == None: return self._canvas.itemconfigure(self['id'], fill=rgba2tk(self['rgba']))
def _hlistKw(self, model, colNum): vt = _valueTypes[self.columnMap[colNum]] vf = _valueFuncs[self.columnMap[colNum]] kw = {'itemtype': vt} txt = None img = None if vt == 'text': txt = vf(model) if not isinstance(txt, basestring): txt, bcolor = txt if bcolor is not None: if not isinstance(bcolor, basestring): if hasattr(bcolor, 'rgba'): rgba = bcolor.rgba() else: rgba = bcolor from CGLtk.color import rgba2tk bcolor = rgba2tk(rgba) fcolor = CGLtk.textForeground( bcolor, self.modelTable) kw['style'] = Tix.DisplayStyle("text", refwindow=self.modelTable, background=bcolor, foreground=fcolor, selectforeground=bcolor) else: kw['style'] = self.textStyle elif vt == 'image': img = vf(model) elif vt == 'imagetext': img, txt = vf(model) elif vt == 'toggle': kw['itemtype'] = 'window' bool, cb = vf(model) togKw = {'command': # avoid holding references to model lambda cb=cb, i=self.models.index(model), b=not bool: cb(self.models[i], b), 'indicatoron': 0, 'borderwidth': 0} if bool: togKw['image'] = self.modelTable.tk.call( 'tix', 'getimage', 'ck_on') else: togKw['image'] = self.modelTable.tk.call( 'tix', 'getimage', 'ck_off') toggle = Tkinter.Checkbutton( self.modelTable.hlist, **togKw) kw['window'] = toggle kw['style'] = self.checkButtonStyle elif vt == 'well': color, noneOkay, alphaOkay, cb = vf(model) if color is False: kw['itemtype'] = 'text' txt = "" else: kw['itemtype'] = 'window' if isinstance(color, chimera.MaterialColor): color = color.rgba() def wellCB(clr, cb=cb, mdl=model): if clr is not None: clr = chimera.MaterialColor( *clr) cb(mdl, clr) from CGLtk.color.ColorWell import ColorWell kw['window'] = ColorWell(self.modelTable.hlist, color, callback=wellCB, width=18, height=18, noneOkay=noneOkay, wantAlpha=alphaOkay) kw['style'] = self.colorWellStyle else: raise ValueError("Unknown column type: '%s'" % vt) if txt != None: kw['text'] = str(txt) if img != None: kw['image'] = self.modelTable.tk.call( 'tix', 'getimage', img) return kw
def writeDemo(self, save_path, tempMode=False): from CGLtk.color import rgba2tk from multiloader2 import Multiloader m = Multiloader() ## GLOBAL options demo = XMLDemo() title = self.gTitleOption.get() if title: demo.title = title else: demo.title = "Chimera Demo" autodelay = self.gAutoDelayOption.get() if autodelay: demo.autodelay = autodelay image = self.gImageOption.get() if image: demo.image = image datadir = self.gDataDirOption.get() if datadir: demo.datadir = datadir else: if tempMode and self.save_path: demo.datadir = os.path.split(self.save_path)[0] bg_color = self.gBgColorOption.get() if bg_color: demo.bg_color = rgba2tk(bg_color.rgba()) autorun_on = self.gAutoRunOption.get() if autorun_on: demo.autorun_on = autorun_on demo.description = '' panel_list = [] panel_id = 0 ##PANEL information for p in self.panels: panel_id += 1 panel = XMLPanel() panel.id = panel_id delay = p.getDelayVar().get() if delay: panel.autodelay = delay title = p.getNameVar().get() if title: if not title[0:9] == "<untitled": panel.title = title if p == self.getCurrentPanel(): panel.text = self.getCurrentText() else: panel.text = p.getText().strip() panel.command = [] for var,entry in p.getCmds(): xmlc = XMLCommand() xmlc.active = ["False","True"][var] xmlc.item = entry panel.command.append(xmlc) panel.undo = [] for var,entry in p.getUndos(): xmlu = XMLUndo() xmlu.active = ["False","True"][var] xmlu.item = entry panel.undo.append(xmlu) panel_list.append(panel) demo.panels = panel_list m.save(save_path, {'Demo':[demo]})
# --- UCSF Chimera Copyright --- # Copyright (c) 2000 Regents of the University of California. # All rights reserved. This software provided pursuant to a # license agreement containing restrictions on its disclosure, # duplication and use. This notice must be embedded in or # attached to all copies, including partial copies, of the # software or any revisions or derivations thereof. # --- UCSF Chimera Copyright --- # # $Id: clustalX.py 26655 2009-01-07 22:02:30Z gregc $ from CGLtk.color import rgba2tk _clustalRed = rgba2tk((0.9, 0.2, 0.1)) _clustalBlue = rgba2tk((0.1, 0.5, 0.9)) _clustalGreen = rgba2tk((0.1, 0.8, 0.1)) _clustalCyan = rgba2tk((0.1, 0.7, 0.7)) _clustalPink = rgba2tk((0.9, 0.5, 0.5)) _clustalMagenta = rgba2tk((0.8, 0.3, 0.8)) #_clustalYellow = rgba2tk((0.8, 0.8, 0.0)) # above is very hard to see on the gray background, so... _clustalYellow = rgba2tk((0.69, 0.69, 0.0)) _clustalOrange = rgba2tk((0.9, 0.6, 0.3)) _clustalCategories = [("wlvimafcyhp", 0.6, '%'), ("wlvimafcyhp", 0.8, '#'), ("ed", 0.5, '-'), ("kr", 0.6, "+"), ("g", 0.5, 'g'), ("n", 0.5, 'n'), ("qe", 0.5, 'q'), ("p", 0.5, 'p'), ("ts", 0.5, 't')] for c in "acdefghiklmnpqrstvwy": _clustalCategories.append((c, 0.85, c.upper())) _clustalColorings = { 'G': [(_clustalOrange, None)], 'P': [(_clustalYellow, None)],
def _hlistKw(self, model, colNum): vt = _valueTypes[self.columnMap[colNum]] vf = _valueFuncs[self.columnMap[colNum]] kw = {'itemtype': vt} txt = None img = None if vt == 'text': txt = vf(model) if not isinstance(txt, basestring): txt, bcolor = txt if bcolor is not None: if not isinstance(bcolor, basestring): if hasattr(bcolor, 'rgba'): rgba = bcolor.rgba() else: rgba = bcolor from CGLtk.color import rgba2tk bcolor = rgba2tk(rgba) fcolor = CGLtk.textForeground(bcolor, self.modelTable) kw['style'] = Tix.DisplayStyle("text", refwindow=self.modelTable, background=bcolor, foreground=fcolor, selectforeground=bcolor) else: kw['style'] = self.textStyle elif vt == 'image': img = vf(model) elif vt == 'imagetext': img, txt = vf(model) elif vt == 'toggle': kw['itemtype'] = 'window' bool, cb = vf(model) togKw = { 'command': # avoid holding references to model lambda cb=cb, i=self.models.index(model), b=not bool: cb( self.models[i], b), 'indicatoron': 0, 'borderwidth': 0 } if bool: togKw['image'] = self.modelTable.tk.call( 'tix', 'getimage', 'ck_on') else: togKw['image'] = self.modelTable.tk.call( 'tix', 'getimage', 'ck_off') toggle = Tkinter.Checkbutton(self.modelTable.hlist, **togKw) kw['window'] = toggle kw['style'] = self.checkButtonStyle elif vt == 'well': color, noneOkay, alphaOkay, cb = vf(model) if color is False: kw['itemtype'] = 'text' txt = "" else: kw['itemtype'] = 'window' if isinstance(color, chimera.MaterialColor): color = color.rgba() def wellCB(clr, cb=cb, mdl=model): if clr is not None: clr = chimera.MaterialColor(*clr) cb(mdl, clr) from CGLtk.color.ColorWell import ColorWell kw['window'] = ColorWell(self.modelTable.hlist, color, callback=wellCB, width=18, height=18, noneOkay=noneOkay, wantAlpha=alphaOkay) kw['style'] = self.colorWellStyle else: raise ValueError("Unknown column type: '%s'" % vt) if txt != None: kw['text'] = str(txt) if img != None: kw['image'] = self.modelTable.tk.call('tix', 'getimage', img) return kw
def clustalInfo(fileName=None): if fileName is None: return _clustalCategories, _clustalColorings from prefs import RC_HYDROPHOBICITY if fileName == RC_HYDROPHOBICITY: import os.path fileName = os.path.join(os.path.dirname(__file__), "kdHydrophob.par") colorInfo = {} for colorName in [ "RED", "BLUE", "GREEN", "CYAN", "PINK", "MAGENTA", "YELLOW", "ORANGE"]: colorInfo[colorName] = eval("_clustal%s" % colorName.capitalize()) from OpenSave import osOpen from chimera import UserError f = osOpen(fileName) section = None colorSeen = False categories = [] colorings = {} for line in f: line = line.strip() if line.startswith("@"): section = line[1:].lower() continue if not line: continue if section == "rgbindex": try: name, sr, sg, sb = line.split() except ValueError: raise UserError("Line in @rgbindex section of" " %s is not color name followed by" " red, green and blue values: '%s'" % (fileName, line)) try: r, g, b = [float(x) for x in [sr, sg, sb]] except ValueError: raise UserError("Line in @rgbindex section of" " %s has non-floating-point" " red, green or blue value: '%s'" % (fileName, line)) if r>1 or g>1 or b>1 or r<0 or g<0 or b<0: raise UserError("Line in @rgbindex section of" " %s has red, green or blue value" " not in the range 0-1: '%s'" % (fileName, line)) colorInfo[name] = rgba2tk((r, g, b)) elif section == "consensus": try: symbol, eq, percent, composition = line.split() except ValueError: raise UserError("Line in @consensus section of" " %s is not of the form 'symbol = " " percentage%% res-list: '%s'" % (fileName, line)) if eq != '=': raise UserError("Line in @consensus section of" " %s doesn't have '=' as second" " component: '%s'" % (fileName, line)) if percent[-1] != '%': raise UserError("Line in @consensus section of" " %s doesn't have '%' as last character" " of third component: '%s'" % (fileName, line)) try: percentage = float(percent[:-1]) except ValueError: raise UserError("Line in @consensus section of" " %s doesn't have a number before the" " '%' of third component: '%s'" % (fileName, line)) if percentage < 0 or percentage > 100: raise UserError("Line in @consensus section of" " %s has a percentage not in the range" " 0-100: '%s'" % (fileName, line)) composition = composition.replace(":", "") categories.append((composition, percentage/100.0, symbol)) elif section == "color": colorSeen = True fields = line.split() if len(fields) not in [3,5]: raise UserError("Line in @color section of" " %s not of the form AA = color" " [if consensus-list]: '%s'" % (fileName, line)) aa, eq, color = fields[:3] if len(aa) > 1 or not aa.islower(): raise UserError("Line in @color section of" " %s uses amino-acid code that is not" " a single lowercase character: '%s'" % (fileName, line)) if eq != '=': raise UserError("Line in @color section of" " %s doesn't have '=' as second" " component: '%s'" % (fileName, line)) if color not in colorInfo: raise UserError("Line in @color section of" " %s uses an unknown color:" " '%s'" % (fileName, line)) if len(fields) == 3: colorings.setdefault(aa.upper(), []).append( (colorInfo[color], None)) continue if fields[3] != 'if': raise UserError("Line in @color section of" " %s doesn't have 'if' as fourth" " component: '%s'" % (fileName, line)) colorings.setdefault(aa.upper(), []).append( (colorInfo[color], fields[-1].replace(":", ""))) f.close() if not colorSeen: raise UserError("'%s' has missing or empty @color section" % fileName) return categories, colorings
def writeDemo(self, save_path, tempMode=False): from CGLtk.color import rgba2tk from multiloader2 import Multiloader m = Multiloader() ## GLOBAL options demo = XMLDemo() title = self.gTitleOption.get() if title: demo.title = title else: demo.title = "Chimera Demo" autodelay = self.gAutoDelayOption.get() if autodelay: demo.autodelay = autodelay image = self.gImageOption.get() if image: demo.image = image datadir = self.gDataDirOption.get() if datadir: demo.datadir = datadir else: if tempMode and self.save_path: demo.datadir = os.path.split(self.save_path)[0] bg_color = self.gBgColorOption.get() if bg_color: demo.bg_color = rgba2tk(bg_color.rgba()) autorun_on = self.gAutoRunOption.get() if autorun_on: demo.autorun_on = autorun_on demo.description = '' panel_list = [] panel_id = 0 ##PANEL information for p in self.panels: panel_id += 1 panel = XMLPanel() panel.id = panel_id delay = p.getDelayVar().get() if delay: panel.autodelay = delay title = p.getNameVar().get() if title: if not title[0:9] == "<untitled": panel.title = title if p == self.getCurrentPanel(): panel.text = self.getCurrentText() else: panel.text = p.getText().strip() panel.command = [] for var, entry in p.getCmds(): xmlc = XMLCommand() xmlc.active = ["False", "True"][var] xmlc.item = entry panel.command.append(xmlc) panel.undo = [] for var, entry in p.getUndos(): xmlu = XMLUndo() xmlu.active = ["False", "True"][var] xmlu.item = entry panel.undo.append(xmlu) panel_list.append(panel) demo.panels = panel_list m.save(save_path, {'Demo': [demo]})