def text_box(msg, x1, y1, x2, y2, *justify): """re-create a text_clip-like element with text_clip and zoom_clamp""" # determine justification originx = (x1+x2)/ 2.0 originy = (y1+y2)/2.0 for j in justify: if j == "center": originx = (x1+x2)/ 2.0 elif j == "left": originx = x1 elif j == "right": originx = x2 elif j == "middle": originy = (y1+y2)/2.0 elif j == "top": originy = y2 elif j == "bottom": originy = y1 return group(colors.blue, shapes.box(x1, y1, x2, y2, fill=False), zoom_clamp( colors.red, shapes.box(x1, y1, x2, y2, fill=False), text_scale(msg, x1, y1, x2, y2, *justify), minx=.1, miny=.1, maxx=1, maxy=1, origin=(originx, originy), clip=True, link=True, link_type="smaller"))
def draw_marking(self, shape, col, y, x1, x2, direction=1, height=1.0): mid = y + .5 y1 = mid - height / 2.0 y2 = mid + height / 2.0 if shape == "box": return group(col, shapes.box(x1, y1, x2, y2, fill=False)) elif shape == "half_box": if direction == 1: return group(col, shapes.box(x1, mid, x2, y2, fill=False)) else: return group(col, shapes.box(x1, y1, x2, mid, fill=False)) elif shape == "fill": return group(col, quads( x1, y1, x1, y2, x2, y2, x2, y1), lines(x1, y1, x1, y2)) elif shape == "half_fill": if direction == 1: return group(col, quads( x1, mid, x1, y2, x2, y2, x2, mid), lines(x1, mid, x1, y2)) else: return group(col, quads( x1, y1, x1, mid, x2, mid, x2, y1), lines(x1, y1, x1, mid)) elif shape == "cross": return group(lines(col, x1, y1, x2, y2, x1, y2, x2, y1)) elif shape == "flag": x = min(x1, x2) return group(lines(col, x, y1, x, 6)) elif shape == "hash": return group(col, lines(x1, y1, x1, y2)) elif shape == "half_hash": if direction == 1: return group(col, lines(x1, mid, x1, y2)) else: return group(col, lines(x1, y1, x1, mid)) else: raise "unknown shape '%s'" % shape
def drag(self): """process drag event""" # do nothing if selection is not enabled if not self.enabled: return self.pos2 = list(self.win.get_mouse_pos("screen")) self.worldpos2 = list(self.win.get_mouse_pos("world")) # do nothing if drag is not large enough if abs(self.pos1[0] - self.pos2[0]) < self.mindrag and abs(self.pos1[1] - self.pos2[1]) < self.mindrag: return if self.selbox == None: self.selbox = self.win.screen.add_group(group()) else: self.selbox = self.win.screen.replace_group( self.selbox, group( color(*self.fillColor), shapes.box(self.pos1[0], self.pos1[1], self.pos2[0], self.pos2[1], fill=True), color(*self.strokeColor), shapes.box(self.pos1[0], self.pos1[1], self.pos2[0], self.pos2[1], fill=False), ), )
def draw_trace(self, dotplot): vis = [] # get current view view = dotplot.win.get_visible() for region in self.regions1: if region in dotplot.layout1: start = dotplot.layout1[region] else: continue # only draw regions in view end = start + region.length() if util.overlap(view[0], view[2], start, end): vis.extend([color(* self.trace_color), lines(start, 0, start, dotplot.plot_size[1]), shapes.box(start, 0, end, dotplot.plot_size[1])]) for region in self.regions2: if region in dotplot.layout2: start = dotplot.layout2[region] else: continue # only draw regions in view end = start + region.length() if util.overlap(view[1], view[3], start, end): vis.extend([color(* self.trace_color), lines(0, start, dotplot.plot_size[0], start), shapes.box(0, start, dotplot.plot_size[0], end)]) return group(*vis)
def makeButton(string, x, y, width, boxColor, kind): # use my_vars to keep track of the visibility of the color quad my_vars = {"visible": True} def callback(): print "HOTSPOT '%s' was clicked!" % string # toggle the visibility of a drawing element my_vars["visible"] = not my_vars["visible"] win.show_group(shape_color, my_vars["visible"]) if kind == "square": # create color quad separately # this will allow us to refer to later to toggle its visibility shape_color = group(boxColor, shapes.box(x, y, x + width, y + width)) return group( shape_color, colors.white, shapes.box(x, y, x + width, y + width, fill=False), text_scale(string, x + width * 0.1, y + width * 0.1, x + width * 0.9, y + width * 0.9, "center", "middle"), color(1, 1, 1), hotspot("click", x, y, x + width, y + width, callback), ) elif kind == "circle": # create color shape separately # this will allow us to refer to later to toggle its visibility shape_color = group(boxColor, shapes.regular_polygon(x, y, 50, width)) return group( shape_color, colors.white, shapes.regular_polygon(x, y, 50, width, fill=False), text_scale(string, x - width * 0.7, y - width * 0.7, x + width * 0.7, y + width * 0.7, "center", "middle"), color(1, 1, 1), hotspot_circle("click", x, y, width, callback), ) elif kind == "polygon": # create color shape separately # this will allow us to refer to later to toggle its visibility pts = [0, 0, 30, 100, 50, 100, 80, 0] shape_color = group(boxColor, polygon(*pts)) return translate( x, y, scale( 0.1, 0.1, shape_color, colors.white, line_strip(80, 0, *pts), text_scale(string, 0, 20, 80, 80, "center", "middle"), color(1, 1, 1), hotspot_polygon("click", pts, callback), ), )
def box(pos1, pos2): x1, y1 = pos1 x2, y2 = pos2 return shapes.draggable( summon.Region(x1, y1, x2, y2), group(color(0, 0, 0, .5), shapes.box(x1+4, y1-4, x2+4, y2-4), color(0, 1, 0), shapes.box(x1, y1, x2, y2), color(1, 1, 1), shapes.box(x1, y1, x2, y2, fill=False)))
def draw_events(self): # draw duplications dups = [color(*self.dup_color)] for node in self.tree: if self.events[node] == "dup": dups.append( zoom_clamp( shapes.box(node.x - .5, node.y - .5, node.x + .5, node.y + .5), link=True, link_type="smaller", maxx=8, minx=1, maxy=8, miny=1, origin=(node.x, node.y), prezoom=(self.xscale, 1.0))) # draw losses losses_per_branch = util.hist_dict([node for node, schild in self.losses]) losses = [color(*self.loss_color)] for node, nlosses in losses_per_branch.iteritems(): if node.parent == None: continue x1 = node.parent.x x2 = node.x step = (x2 - x1) / float(nlosses + 1) for x in util.frange(x1 + step, x2-(step/2.0), step): losses.append(lines(x, node.y - .2, x, node.y + .2)) return group(group(*dups), group(*losses))
def __init__(self, game_size=[400, 400], nballs=3): self.game_size = game_size[:] self.win = summon.Window("Filler", size=self.game_size) self.start = time.time() self.frames = 0 self.growing_bubble = None self.bubbles = [] self.objects = [] # make balls for i in xrange(nballs): angle = frand(0, 2*pi) self.objects.append(Ball(self, pos=[frand(5, self.game_size[0]-5), frand(5, self.game_size[1]-5)], vel=[5*cos(angle), 5*sin(angle)], size=4.5)) self.win.add_group(group(colors.white, shapes.box(0, 0, self.game_size[0], self.game_size[1], fill=False))) self.objects_vis = self.win.add_group(self.draw_objects()) self.enable_updating(True, 1/100.) self.win.set_binding(input_click("left", "down"), self.start_bubble) self.win.set_binding(input_motion("left", "down"), self.move_bubble) self.win.set_binding(input_click("left", "up"), self.end_bubble) self.win.set_binding(input_click("left", "click"), self.end_bubble)
def draw_marking(self, shape, col, y, x1, x2, direction=1, height=1.0): mid = y + .5 y1 = mid - height / 2.0 y2 = mid + height / 2.0 if shape == "box": return group(col, shapes.box(x1, y1, x2, y2, fill=False)) elif shape == "half_box": if direction == 1: return group(col, shapes.box(x1, mid, x2, y2, fill=False)) else: return group(col, shapes.box(x1, y1, x2, mid, fill=False)) elif shape == "fill": return group(col, quads(x1, y1, x1, y2, x2, y2, x2, y1), lines(x1, y1, x1, y2)) elif shape == "half_fill": if direction == 1: return group(col, quads(x1, mid, x1, y2, x2, y2, x2, mid), lines(x1, mid, x1, y2)) else: return group(col, quads(x1, y1, x1, mid, x2, mid, x2, y1), lines(x1, y1, x1, mid)) elif shape == "cross": return group(lines(col, x1, y1, x2, y2, x1, y2, x2, y1)) elif shape == "flag": x = min(x1, x2) return group(lines(col, x, y1, x, 6)) elif shape == "hash": return group(col, lines(x1, y1, x1, y2)) elif shape == "half_hash": if direction == 1: return group(col, lines(x1, mid, x1, y2)) else: return group(col, lines(x1, y1, x1, mid)) else: raise "unknown shape '%s'" % shape
def drawobj(self, obj, x=0.0, y=0.0): if id(obj) in self.vars: return group() else: self.vars[id(obj)] = VarDisplay(obj, x=x, y=y) if isinstance(obj, dict): keys = map(str, obj.keys()) vals = obj.values() elif isinstance(obj, list) or isinstance(obj, tuple): keys = map(str, range(len(obj))) vals = obj elif hasattr(obj, "__dict__"): keys = map(str, obj.__dict__.keys()) vals = obj.__dict__.values() else: keys = [str(obj)] vals = [NOVALUE] type_name = type(obj).__name__ width = len(type_name) if len(keys) > 0: width = max(width, max(map(len, keys))) height = len(keys) attr_vis = [] for i, (key, val) in enumerate(izip(keys, vals)): if val == NOVALUE: attr_vis.append(group(color(1, .8, .8), shapes.box(x, y-1-i, x+width, y-2-i))) attr_vis.append(color(0, 0, 0)) attr_vis.append(text_clip(key, x, y-1-i, x+width, y-2-i, 4, 12, "left", "middle")) if val != NOVALUE: attr_vis.append(self.makeObjHotspot(val, x, y-1-i, width)) return group(color(.5, .5, 1), shapes.box(x, y, x+width, y-1), color(0, 0, 0), text_clip(type_name, x, y, x+width, y-1, 4, 12, "left", "middle"), color(.8, .8, 1), shapes.box(x, y-1, x+width, y-1-height), *attr_vis)
def draw(self): x1, y1, x2, y2 = self.x, self.y, self.x+self.width, self.y+self.height midy = (y1 + y2) / 2.0 self.vis = group(color(0, 0, 1), shapes.box(x1, y1, x2, y2), color(1, 1, 1), shapes.box(x1, y1, x2, y2, fill=False), zoom_clamp( text_scale(self.element.__class__.__name__, x1, midy, x2, y2, "center", "middle"), maxx=2, maxy=2, minx=.1, miny=.1, link=True, link_type="smaller", origin=((x1+x2)/2.0, y2-(y1+y2)/4.0)), hotspot("click", x1, midy, x2, y2, self.expand)) return self.vis
def draw(self): self.drawGroup = group( color(*self.button_color), shapes.box(0, 0, self.width, self.height), color(*self.button_highlight), lines(0, self.height - 1, self.width - 1, self.height - 1, self.width, 0, self.width - 1, self.height - 1), color(*self.text_color), text(self.name, 0, 2, self.width, self.height + 20, "bottom", "center"), hotspot("click", 0, 0, self.width, self.height, self.onClick), ) return self.drawGroup
def draw_summon(): t = 150 # thickness w = 200 # width s = 50 # spacing top = w bottom = -3*w+t return translate(-7*w+t-2.5*s, -(top + bottom) / 2.0, # S curve(0, 0, 0, 1.5*math.pi, w, t), curve(0, -2*w+t, -math.pi, .5*math.pi, w, t), # U translate(2*w+s, 0, draw_u(top, bottom, w, t)), # M translate(4*w+2*s, 0, draw_m(top, bottom, w, t)), # M translate(8*w-t+3*s, 0, draw_m(top, bottom, w, t)), # 0 translate(12*w-2*t+4*s, 0, curve(0, 0, 0.0, math.pi, w, t), shapes.box(-w,top-w, -w+t, bottom+w), shapes.box(w,top-w, w-t, bottom+w), curve(0, bottom+w, -math.pi, 0.0, w, t)), # N translate(14*w-2*t+5*s, 0, translate(0, -2*w+t, rotate(180, draw_u(top, bottom, w, t)))) )
def draw_trace(self, dotplot): vis = [] # get current view view = dotplot.win.get_visible() for region in self.regions1: if region in dotplot.layout1: start = dotplot.layout1[region] else: continue # only draw regions in view end = start + region.length() if util.overlap(view[0], view[2], start, end): vis.extend([ color(*self.trace_color), lines(start, 0, start, dotplot.plot_size[1]), shapes.box(start, 0, end, dotplot.plot_size[1]) ]) for region in self.regions2: if region in dotplot.layout2: start = dotplot.layout2[region] else: continue # only draw regions in view end = start + region.length() if util.overlap(view[1], view[3], start, end): vis.extend([ color(*self.trace_color), lines(0, start, dotplot.plot_size[0], start), shapes.box(0, start, dotplot.plot_size[0], end) ]) return group(*vis)
def draw(self, winwidth, winheight): height = self.get_height() vis = [ color(*self.shadow_color), shapes.box( winwidth, winheight, winwidth - self.width - self.shadow_size[0], winheight - height - self.shadow_size[1], ), color(*self.base_color), shapes.box(winwidth, winheight, winwidth - self.width, winheight - height), ] x = winwidth - self.width + self.xmargin y = winheight - self.ymargin for item in self.items: y -= item.height item.set_model(self.win.screen) vis.append(translate(x, y, item.draw())) y -= self.ymargin return group(*vis)
def draw_mark(x, y, col=(1,0,0), size=.5, func=None): """Draw a mark at (x, y)""" if func: h = hotspot("click", x-size, y-size, x+size, y+size, func) else: h = group() return zoom_clamp( color(*col), box(x-size, y-size, x+size, y+size, fill=True), h, color(1,1,1), origin=(x, y), minx=10.0, miny=10.0, maxx=20.0, maxy=20.0, link=True)
def show_coal_track2(tree_track): win = summon.Window() bgcolor = (1, 1, 1, .1) cmap = util.rainbow_color_map(low=0.0, high=1.0) tracks = {} maxage = 0 for (start, end), tree in tree_track: print start l = [] times = treelib.get_tree_timestamps(tree) nleaves = len(tree.leaves()) maxage2 = 0 for node in tree: if len(node.children) > 1: age = times[node] freq = len(node.leaves()) / float(nleaves) #sizes = [len(x.leaves()) for x in node.children] #m = max(sizes) #n = sum(sizes) #pval = 2 * (n - m) / float(n - 1) l.extend([color(*cmap.get(freq)), start, age, end, age]) if age > maxage2: maxage2 = age win.add_group(group(lines(*l), color(*bgcolor), box(start, 0, end, maxage2, fill=True))) if maxage2 > maxage: maxage = maxage2 def func(): x, y = win.get_mouse_pos() print "pos=%s age=%f" % (util.int2pretty(int(x)), y) win.add_group(hotspot("click", 0, 0, end, maxage, func)) win.home("exact") return win
def show_coal_track2(tree_track): win = summon.Window() bgcolor = (1, 1, 1, .1) cmap = util.rainbow_color_map(low=0.0, high=1.0) tracks = {} maxage = 0 for (start, end), tree in tree_track: print(start) l = [] times = treelib.get_tree_timestamps(tree) nleaves = len(tree.leaves()) maxage2 = 0 for node in tree: if len(node.children) > 1: age = times[node] freq = len(node.leaves()) / float(nleaves) #sizes = [len(x.leaves()) for x in node.children] #m = max(sizes) #n = sum(sizes) #pval = 2 * (n - m) / float(n - 1) l.extend([color(*cmap.get(freq)), start, age, end, age]) if age > maxage2: maxage2 = age win.add_group(group(lines(*l), color(*bgcolor), box(start, 0, end, maxage2, fill=True))) if maxage2 > maxage: maxage = maxage2 def func(): x, y = win.get_mouse_pos() print("pos=%s age=%f" % (util.int2pretty(int(x)), y)) win.add_group(hotspot("click", 0, 0, end, maxage, func)) win.home("exact") return win
translate(0, 100, zoom_clamp(colors.red, shapes.regular_polygon(0, 0, 10, 10), translate(0, 10, color(1, .5, .5), shapes.regular_polygon(0, 0, 10, 2)), translate(0, -10, zoom_clamp( color(1, .5, .5), shapes.regular_polygon(0, 0, 10, 2), maxx=5, maxy=5, minx=1, miny=1)), maxx=3, maxy=3, minx=1, miny=1, link=True)), rotate(30, colors.white, lines(0, 0, 100, 0), translate(100, 0, lines(0, 0, -30, -30), zoom_clamp(colors.yellow, shapes.box(-20, -20, 20, 20), colors.blue, lines(0, 0, -20, -20), link=True, maxx=1, maxy=1, minx=1, miny=1, axis=(-1, -1)))), translate(100, 0, colors.green, shapes.regular_polygon(0, 0, 10, 10)), colors.white, shapes.box(0, 0, 100, 100, fill=False))) win.home()
#!/usr/bin/env python-i import summon from summon.core import * from summon import shapes, colors step = 50 win = summon.Window("zoom_clamp2") vis = [] for i in xrange(101): for j in xrange(101): s = .01 * i vis.append(translate(i*step, j*step, zoom_clamp(colors.red, shapes.regular_polygon(0, 0, 10, 5), minx=s, miny=s, maxx=1, maxy=1))) win.add_group(group(*vis)) win.add_group(group(colors.white, shapes.box(0, 0, 100*step, 100*step, fill=False))) win.home()
#!/usr/bin/env python-i import sys, os, time import summon from summon.core import * from summon import shapes, colors vis = group(colors.red, shapes.box(0, 0, 100, 100), colors.white, text("hello", 0, 0, 100, 100), translate(0, 200, colors.orange, shapes.box(0, 0, 100, 100), colors.white, text_scale("hello", 0, 0, 100, 100), ), translate(300, 300, colors.purple, shapes.box(0, 0, 200, 200), colors.white, text_clip("hello", 0, 0, 200, 200), ), translate(200, 200, zoom_clamp(
#!/usr/bin/env python-i from summon.core import * import summon from summon import shapes, colors win = summon.Window() win.add_group(shapes.box(0, 0, 50, 100, fill=False)) win.add_group(text_clip("hello", 0, 0, 50, 100, 4, 20, "bottom")) win.add_group(group(color(1, 0, 0), text_clip("hello", 0, 0, 50, 100, 4, 20, "bottom"))) win.add_group( translate( 300, 300, rotate( 20, color(1, 1, 1), shapes.box(0, 0, 5000, 100, fill=False), text_clip("hello", 0, 0, 5000, 100, 4, 20, "bottom"), group(color(1, 0, 0), text_clip("hello", 0, 0, 5000, 100, 4, 20, "bottom")), ), ) ) win.add_group(
for i in range(nballs): angle = random.random() vx = 5 * math.cos(angle) vy = 5 * math.sin(angle) size = maxballsize * i/ float(nballs) x = size + (winsize - 2 * size) * random.random() y = size + (winsize - 2 * size) * random.random() balls.append(Ball(x, y, size, vx, vy)) # create window win = summon.Window("15_animation") # draw bounding box win.add_group(group(color(1,1,1), shapes.box(0, 0, winsize, winsize, fill=False))) # draw frame per second display fps_vis = win.screen.add_group( group( color(1, 1, 1), text("FPS: 0", 5, 5, 300, 25, "left", "bottom"))) # center view win.home() # setup timer to call the draw frame function timer = summon.add_timer(draw_frame, interval=rate, window=win)
#!/usr/bin/env python-i from summon.core import * import summon from summon import shapes win = summon.Window() win.add_group(shapes.box(0, 0, 100, 100)) win.add_group(shapes.draggable( # region that detects drags summon.Region(0, 0, 100, 100), # draw group group(color(1, 0, 0), shapes.round_box(0, 0, 100, 100, 10)))) win.add_group(translate(200, 200, rotate(30, shapes.draggable( # region that detects drags summon.Region(0, 0, 100, 100), # draw group group( color(0, 0, 1), shapes.round_box(0, 0, 100, 100, 10), shapes.message_bubble(50, 50, 150, 40, text("hello", 0, 0, 150, 40,
def draw_matrix(self, mat, mouse_click=None): win = self.win # set default colormap if mat.colormap == None: mat.colormap = colors.RainbowColorMap() # customize colormap to matrix if mat.maxval == None or mat.minval == None: mat.maxval = max(mat.vals) mat.minval = min(mat.vals) mat.colormap.max = mat.maxval mat.colormap.min = mat.minval mat.colormap.range = mat.maxval - mat.minval if mat.colormap.range == 0.0: mat.colormap.range = 1.0 getcolor = mat.colormap.get chunksize = 10000 rows, cols, vals = (mat.rows, mat.cols, mat.vals) rinv, cinv = (mat.rinv, mat.cinv) # draw zeros if self.drawzeros: win.add_group(group(color(*getcolor(0)), shapes.box(-.5,.5,mat.ncols-.5, -mat.nrows+.5))) # draw non-zeros vis = [] vis2 = [] for chunk in xrange(0, len(rows), chunksize): if self.style == "points": if getcolor == None: for k in xrange(chunk, min(len(rows), chunk+chunksize)): vis.append(cinv[cols[k]]) vis.append(-rinv[rows[k]]) else: for k in xrange(chunk, min(len(rows), chunk+chunksize)): vis.append(color(* getcolor(vals[k]))) vis.append(cinv[cols[k]]) vis.append(-rinv[rows[k]]) win.add_group(group(points(* vis))) elif self.style == "quads": for k in xrange(chunk, min(len(rows), chunk+chunksize)): vis.extend([color(* getcolor(vals[k])), cinv[cols[k]] - .5, -rinv[rows[k]] - .5, cinv[cols[k]] - .5, -rinv[rows[k]] + .5, cinv[cols[k]] + .5, -rinv[rows[k]] + .5, cinv[cols[k]] + .5, -rinv[rows[k]] - .5 ]) vis2.append(group(quads(* vis))) else: raise Exception("unknown style '%s'" % self.style) vis = [] win.add_group(group(*vis2)) if mouse_click != None: win.add_group(group(hotspot('click', -.5, .5, mat.ncols-.5, -mat.nrows+.5, mouse_click))) # draw extra self.draw_border(mat.nrows, mat.ncols) self.draw_partitions(mat) if self.show_labels: if self.show_label_windows: self.open_label_windows() self.draw_labels() if self.show_tree_windows: self.open_tree_windows()
################## # Bitmap Text # # Always the same on-screen size. Clips when text cannot fit in bounding box # x = 0 y = 0 win.add_group(translate(x, y, # draw white box and title text color(1,1,1), shapes.box(0, 0, width, width, fill=False), text("bitmap (text)", a, d+b/2, d, d+d, "bottom", "center"), # draw demo text with each justification text("NW", a, c, b, d, "top", "left"), text("N", b, c, c, d, "top", "center"), text("NE", c, c, d, d, "top", "right"), text("W", a, b, b, c, "middle", "left"), text("X", b, b, c, c, "middle", "center"), text("E", c, b, d, c, "middle", "right"), text("SW", a, a, b, b, "bottom", "left"), text("S", b, a, c, b, "bottom", "center"), text("SE", c, a, d, b, "bottom", "right"))) ##################
def draw_plot(self, dotplot): if self.style not in ("line", "box") and not callable(self.style): return group() vis = group() line_pts = [] # draw hits for hit in self.hits: set1 = [] set2 = [] # split genes into sets (possibily overlapping) for region in hit: if region in dotplot.layout1: set1.append(region) if region in dotplot.layout2: set2.append(region) # draw all pairs of hits for region1 in set1: chrom1 = dotplot.chrom1lookup[(region1.species, region1.seqname)] for region2 in set2: if not self.selfhits and \ region1.data["ID"] == region2.data["ID"]: continue chrom2 = dotplot.chrom2lookup[(region2.species, region2.seqname)] s1 = dotplot.layout1[region1] e1 = dotplot.layout1[region1] + region1.length() s2 = dotplot.layout2[region2] e2 = dotplot.layout2[region2] + region2.length() # styles if self.style == "line": if region1.strand == region2.strand: line_pts.extend([s1, s2, e1, e2]) else: line_pts.extend([s1, e2, e1, s2]) elif self.style == "box": vis.append(shapes.box(s1, s2, e1, e2, fill=False)) if self.fill_color: vis.append(color(*self.fill_color)) vis.append(shapes.box(s1, s2, e1, e2, fill=True)) vis.append(color(*self.color)) elif callable(self.style): vis.append(self.style(region1, s1, s2, region2, e1, e2)) else: raise Exception("unknown plot style '%s'" % self.style) if self.style == "line": return group(color(*self.color), lines(*line_pts)) elif self.style == "box": return group(color(*self.color), vis) elif callable(self.style): return vis
# 09_key_bindings.py - example use of bindings # # Also see summon/lib/summon_config.py file for example use of set_binding() # and input_*(). # from summon.core import * from summon import shapes import summon win = summon.Window("09_key_bindings") # color background boxes # save a reference to each box so we can manipulate it later groupa = win.add_group(group(color(1,0,0), shapes.box(0,0,200,-50))) groupb = win.add_group(group(color(0,1,0), shapes.box(0,-50,200,-100))) groupc = win.add_group(group(color(0,0,1), shapes.box(0,-100,200,-150))) # text win.add_group(group(color(1,1,1), text_scale("press 'a'", 0, 0, 200, -50))) win.add_group(group(color(1,1,1), text_scale("press 'b'", 0, -50, 200, -100))) win.add_group(group(color(1,1,1), text_scale("press 'c'", 0, -100, 200, -150))) # use the shapes module to make a simple box shape win.add_group(shapes.box(0, 0, 200, -150, fill=False)) win.home() # variable to keep track of the visibility of colored boxes show_groupa = True
def func(): self.win.add_group(group(color(0,0,0), shapes.box(x, y, x+width, y-1, fill=False), lines(x+width, y-.5, x+width+2, y-.5), self.drawobj(obj, x+width+2, y)))
def draw_u(top, bottom, w, t): return group(shapes.box(-w,top, -w+t, bottom+w), shapes.box(w,top, w-t, bottom+w), curve(0, bottom+w, -math.pi, 0.0, w, t))
def draw_border(self, nrows, ncols): """draws the matrix boarder""" # draw boundary self.win.add_group(group(color(* getDrawColor(self.bgcolor)), shapes.box(-.5,.5,ncols-.5, -nrows+.5, fill=False)))
def draw_plot(self, dotplot): if self.style not in ("line", "box") and not callable(self.style): return group() vis = group() line_pts = [] # draw hits for hit in self.hits: set1 = [] set2 = [] # split genes into sets (possibily overlapping) for region in hit: if region in dotplot.layout1: set1.append(region) if region in dotplot.layout2: set2.append(region) # draw all pairs of hits for region1 in set1: chrom1 = dotplot.chrom1lookup[(region1.species, region1.seqname)] for region2 in set2: if not self.selfhits and \ region1.data["ID"] == region2.data["ID"]: continue chrom2 = dotplot.chrom2lookup[(region2.species, region2.seqname)] s1 = dotplot.layout1[region1] e1 = dotplot.layout1[region1] + region1.length() s2 = dotplot.layout2[region2] e2 = dotplot.layout2[region2] + region2.length() # styles if self.style == "line": if region1.strand == region2.strand: line_pts.extend([s1, s2, e1, e2]) else: line_pts.extend([s1, e2, e1, s2]) elif self.style == "box": vis.append(shapes.box(s1, s2, e1, e2, fill=False)) if self.fill_color: vis.append(color(*self.fill_color)) vis.append(shapes.box(s1, s2, e1, e2, fill=True)) vis.append(color(*self.color)) elif callable(self.style): vis.append(self.style( region1, s1, s2, region2, e1, e2)) else: raise Exception("unknown plot style '%s'" % self.style) if self.style == "line": return group(color(*self.color), lines(*line_pts)) elif self.style == "box": return group(color(*self.color), vis) elif callable(self.style): return vis
#!/usr/bin/env python-i import summon from summon.core import * from summon import shapes, colors win = summon.Window() win.add_group( group(colors.white, shapes.round_box(0, 0, 100, 100, 20, fill=False), shapes.box(0, 0, 100, 100, fill=False))) win.add_group(translate(200, 0, colors.red, shapes.round_box(0, 0, 100, 100, [20, 20, 40, 40]))) win.add_group(translate(400, 0, colors.white, shapes.message_bubble(0, 0, 150, 100, group(colors.blue, text("hello world", 0, 0, 150, 100, "center", "middle")), close_button=True))) win.add_group(translate(400, -400, colors.white, shapes.message_bubble(0, 0, 150, 40, group(colors.blue, text("hello world", 0, 0, 150, 40, "center", "middle")),