def pulse(sheet, stage=0): try: total_stages=20 f = 1.0*stage/total_stages lightFontColour = g.shadeN([cs.background, cs.lightText], [0,1], cs.fontOpacity) darkFontColour = g.shadeN([(1,1,1), cs.darkText], [0,1], cs.fontOpacity) if stage<=total_stages: sheetColour = g.shadeN([(1,1,1), cs.background], [0,1], f) textColour = g.shadeN([darkFontColour, lightFontColour], [0,1], f) sheet.configure(bg=g.toHex(sheetColour), fg=g.toHex(textColour)) if stage < total_stages: t = threading.Timer(0.01, pulse, [sheet, stage+1]) t.daemon = True t.start() except: pass
def togglePinned(self, event=[]): #print "here" self.pinned = not self.pinned if self.pinned: self.canvas.itemconfig(self.canvasIndex, fill=g.toHex(self.pinColour)) else: self.canvas.itemconfig(self.canvasIndex, fill=g.toHex(self.colour))
def initPages(): global tk_sheets fontColour = g.toHex(g.shadeN([cs.background, cs.lightText], [0,1], cs.fontOpacity)) for s in tk_sheets: s.destroy() tk_sheets=[] sheets = getFileList() for s in sheets: s_box = Label(tk_root, text=s['name'], font=g.FONT, bg=g.toHex(cs.background), fg=fontColour, cursor='hand1', anchor=CENTER) s_box.bind('<Button-1>', lambda event, filename=s['filename']: sheetClick(filename, event)) s_box.bind('<Button-3>', lambda event, sheet=s: sheetRightClick(sheet, event)) s_box.bind('<Enter>', lambda event, sheet=s_box: labelEnter(sheet, event)) s_box.bind('<Leave>', lambda event, sheet=s_box: labelLeave(sheet, event)) tk_sheets.append(s_box) s_box_plus = Label(tk_root, text='+', font=g.FONT, bg=g.toHex(cs.background), fg=fontColour, cursor='hand1', anchor=CENTER) s_box_plus.bind('<Button-1>', addFile) s_box_plus.bind('<Enter>', lambda event, sheet=s_box_plus: labelEnter(sheet, event)) s_box_plus.bind('<Leave>', lambda event, sheet=s_box_plus: labelLeave(sheet, event)) tk_sheets.append(s_box_plus) resizeLayout()
def linkAdd(self, importance=1): # see which link end is free to assign if importance == 0: #print "double click!" self.parentSheet.resetLinkData() #else: # print "single click" if self.parentSheet.linkA == -1: self.parentSheet.linkA = self.index self.parentSheet.linkImportance = importance #random.randint(1,2) # hold circle colour holdColour = g.shadeN([(1, 1, 1), self.cs.highlight2], [0, 3], importance + 2) if importance == 1: self.canvas.itemconfig(self.smallCircleIndex, fill=g.toHex(holdColour)) else: self.canvas.itemconfig(self.smallCircleIndex, fill=g.toHex(holdColour)) elif self.parentSheet.linkB == -1: self.parentSheet.linkB = self.index self.parentSheet.addLink()
def addLeave(event=[], stage=0): #try: total_stages=20 f = 1.0*stage/total_stages if stage<=total_stages: bgColour = g.shadeN([(1.0,1.0,1.0), cs.background], [0,1], f) textColour = g.shadeN([g.darkText, g.lightText], [0,1], f) fontColour = g.shadeN([bgColour, textColour], [0,1], cs.fontOpacity) tk_text.configure(fg=g.toHex(fontColour), bg=g.toHex(bgColour))#g.toHex(textColour)) if stage < total_stages: t = threading.Timer(0.01, addLeave, [[], stage+1]) t.daemon = True t.start() else: tk_text.place(x=-1, y=-1,width=0, height=0) tk_root.focus()
def initDrawing(self): canvasW=self.root.winfo_width() canvasH=self.root.winfo_height() r = self.r # center of circle x = int(1.0*canvasW*self.loc[0]) y = int(1.0*canvasH*self.loc[1]) self.pixLoc=(x,y) if self.drawLine and self.attractor!=[]: attractorCoords = self.attractor.canvasCoords() l2x = ((1.0-self.lineDist)*x + self.lineDist*attractorCoords[0]) l2y = ((1.0-self.lineDist)*y + self.lineDist*attractorCoords[1]) lColour = g.toHex(tuple([v*0.3+0.0 for v in self.colour])) l = self.canvas.create_line(x, y, l2x, l2y, fill=lColour, activefill="white", width=self.lineWidth) self.canvasLineIndex=l x0p, y0p = x-r, y-r x1p, y1p = x+r, y+r fill, outline = g.toHex(self.colour), "black" p = self.canvas.create_oval(x0p, y0p, x1p, y1p, fill=fill, outline=outline, activeoutline="white") self.canvasIndex=p if not self.fixed: self.canvas.tag_bind(self.canvasIndex, '<ButtonPress-1>', self.togglePinned)
def addFile(event=[]): global sheets, addLabelGeom, tk_text pixelX = tk_root.winfo_width() pixelY = tk_root.winfo_height() num = len(tk_sheets) gridSide = int(math.ceil(math.sqrt(num))) tk_text.focus() fontSize = addLabelGeom[4] tk_text.place(x=addLabelGeom[0], y=addLabelGeom[1], width=addLabelGeom[2], height=addLabelGeom[3]) fontColour = g.toHex( g.shadeN([(1, 1, 1), cs.darkText], [0, 1], cs.fontOpacity)) tk_text.configure(font=(g.mainFont, fontSize, "normal"), fg=fontColour, bg="white") tk_root.update()
def __init__(self, root, canvas, fileName): self.root=root self.canvas=canvas self.cs=cs.ColourScheme() self.thoughts = [] self.links = [] self.canvas.bind("<Double-Button-1>",self.addAtCoord) self.canvas.bind('<Button-1>', self.startDrag) self.canvas.bind('<B1-Motion>', self.onDrag) self.canvas.bind('<ButtonRelease-1>', self.endThoughtDrag) self.root.bind('<Control-Key-s>', self.saveData) self.canvas.bind('<4>', lambda event : self.zoom('in', event)) self.canvas.bind('<5>', lambda event : self.zoom('out', event)) self.canvas.configure(bg=g.toHex(self.cs.background)) self.curIndex=0 #keep track of index most recently assigned (first thought=1) self.fileName=fileName self.imageList=[] self.initDrawing() self.root.update() self.resize() self.loadFile()
def graphicsInit(): global cs tk_root.title("MindMap Wrapper") tk_root.geometry("%dx%d%+d%+d" % (g.WIDTH / 2, g.HEIGHT / 2, g.WIDTH / 4, g.HEIGHT / 4)) tk_root.config(bg=g.toHex(cs.background))
def graphicsInit(): global cs tk_root.title("MindMap Wrapper") tk_root.geometry("%dx%d%+d%+d" % (g.WIDTH/2, g.HEIGHT/2, g.WIDTH/4, g.HEIGHT/4)) tk_root.config(bg=g.toHex(cs.background))
def initDrawing(self): # draw the save button self.saveIcon, self.imageList = g.loadImage(fileName=h.DIR+"/icons/save.png", size=(20,20), imageList=self.imageList, root=self.root, background=g.toHex(self.cs.background)) self.saveIcon.bind("<Button-1>", self.handleSavePress) return
def flash(self, stage=0): if stage==0: self.canvas.itemconfig(self.canvasIndex, fill=g.toHex((1,1,1))) elif stage==1: self.canvas.itemconfig(self.canvasIndex, fill=g.toHex((0,0,0))) elif stage==2: self.canvas.itemconfig(self.canvasIndex, fill=g.toHex((1,1,1))) else: if not self.pinned: self.canvas.itemconfig(self.canvasIndex, fill=g.toHex(self.colour)) else: self.canvas.itemconfig(self.canvasIndex, fill=g.toHex(self.pinColour)) self.root.update() if stage <= 2: t = threading.Timer(0.1, self.flash, [stage+1]) t.daemon = True t.start()
def initDrawing(self): #self.canvasIndex = self.canvas.create_line(self.tA.pixLoc[0], self.tA.pixLoc[1], # self.tB.pixLoc[0], self.tB.pixLoc[1], # fill="white", width=5) x0, y0, x1, y1 = self.getCoords() #xb0,yb0,xb1,yb1 = self.getHeadCoords() self.canvasIndex = self.add_to_layer( self.importance, self.canvas.create_line, (x0, y0, x1, y1), fill=g.toHex(self.colour), activefill=g.toHex(self.cs.highlight2), width=int(self.z_width), activewidth=5) self.canvas.tag_bind(self.canvasIndex, '<Button-3>', self.remove) #self.canvas.tag_bind(self.canvasIndex2, '<ButtonRelease-3>', self.endDrag) self.grow()
def addLink(self): tA = self.linkA tB = self.linkB if tA == -1 or tB == -1: print("ERROR: a link end not assigned") if tA != tB and not self.hasLink(tA, tB): self.links.append(Link(self, self.getThought(tA), self.getThought(tB), importance=self.linkImportance)) #print "Creating a link!" # set circle colour back to white TA = self.getThought(tA) TA.canvas.itemconfig(TA.smallCircleIndex, fill=g.toHex(self.cs.smallCircle)) # reset link assignments self.resetLinkData() self.lowerLinks()
def pulse(self, stage=0): #try: total_stages=20 f = 1.0*stage/total_stages if stage<=total_stages: bkgColour = g.shadeN([self.cs.background, self.cs.backgroundPulse, self.cs.background], [0,0.5,1], f) self.canvas.configure(bg=g.toHex(bkgColour)) if stage < total_stages: t = threading.Timer(0.01, self.pulse, [stage+1]) t.daemon = True t.start() #except: # pass
def addFile(event=[]): global sheets, addLabelGeom, tk_text pixelX=tk_root.winfo_width() pixelY=tk_root.winfo_height() num = len(tk_sheets) gridSide = int(math.ceil(math.sqrt(num))) tk_text.focus() fontSize = addLabelGeom[4] tk_text.place(x=addLabelGeom[0], y=addLabelGeom[1], width=addLabelGeom[2], height=addLabelGeom[3]) fontColour = g.toHex(g.shadeN([(1,1,1), cs.darkText], [0,1], cs.fontOpacity)) tk_text.configure(font=(g.mainFont, fontSize, "normal"), fg=fontColour, bg="white") tk_root.update()
cs = ColourScheme() tk_root = tk.Tk() #tk_canvas = Canvas(tk_root) graphicsInit() tk_root.bind("<Configure>", resizeLayout) # create list of files on canvas sheets = getFileList() #sheets.append({'filename':'', 'name':'+', 'special':True}) tk_sheets = [] fontColour = g.toHex( g.shadeN([cs.background, cs.lightText], [0, 1], cs.fontOpacity)) for s in sheets: s_box = tk.Label(tk_root, text=s['name'], font=g.FONT, bg=g.toHex(cs.background), fg=fontColour, cursor='hand1', anchor=tk.CENTER) s_box.bind( '<Button-1>', lambda event, filename=s['filename']: sheetClick(filename, event)) s_box.bind('<Button-3>', lambda event, sheet=s: sheetRightClick(sheet, event)) s_box.bind('<Enter>',
def recolour(self, event=[]): self.canvas.itemconfig(self.mainCircleIndex, fill=g.toHex(self.colour), outline=g.toHex(self.colour)) self.tk_text.configure(bg=g.toHex(self.colour))
def reDraw(self, init=False, r=-1, pixChange=False, fromZoom=False): canvasW = self.root.winfo_width() canvasH = self.root.winfo_height() # r : radius of main circle if init: r = self.z_r else: if r == -1: r = self.z_r # prevent bubbles from moving when screen resized if pixChange: self.loc = (1.0 * self.pixLoc[0] / canvasW, 1.0 * self.pixLoc[1] / canvasH) r = int(r) # center of circle x = 1.0 * canvasW * self.loc[0] y = 1.0 * canvasH * self.loc[1] self.pixLoc = (x, y) ''' curTime = time.time() draw = (curTime - self.prevDrawTime)>1./60 if draw or init: self.prevDrawTime = curTime else: return ''' ''' draw filled circle for pulse animation ''' offset = 0 #10*self.curZoom rFrac = 0.5 #1.1 x0p, y0p = (x + offset) - r * rFrac, ( y + offset) - r * rFrac #x-r/2, y-r/2 x1p, y1p = (x + offset) + r * rFrac, ( y + offset) + r * rFrac #x+r/2, y+r/2 if init: fill = g.toHex(self.cs.lightGrey) self.pulseCircleIndex = self.canvas.create_oval(x0p, y0p, x1p, y1p, fill=fill, width=0, activewidth=0, tags="pulseCircle") #self.canvas.tag_lower(self.pulseCircleIndex, "all") else: self.canvas.coords(self.pulseCircleIndex, x0p, y0p, x1p, y1p) ''' draw main filled circle ''' x0p, y0p = x - r, y - r x1p, y1p = x + r, y + r if init: fill, outline = g.toHex(self.colour), g.toHex(self.cs.highlight2) self.mainCircleIndex = self.canvas.create_oval( x0p, y0p, x1p, y1p, fill=fill, outline=fill, activeoutline=outline, width=2, activewidth=2, tags="mainCircle") #self.canvas.itemconfigure("mainCircle", cursor="hand1") else: self.canvas.coords(self.mainCircleIndex, x0p, y0p, x1p, y1p) ''' now create and draw text box ''' if init: self.tk_text = tk.Text(self.root, bd=0, highlightthickness=0, wrap="word", font=(g.mainFont, int(self.z_labelFontSize), "normal"), bg=g.toHex(self.colour), fg=g.toHex(self.cs.lightText)) self.tk_text.insert(tk.END, self.text) # set initial text self.tk_text.tag_configure("center", justify='center') self.tk_text.tag_add("center", 1.0, "end") tr = (r * 0.7) tx = x ty = y tx0p, ty0p = tx - tr, ty - tr self.tk_text.place(x=tx0p, y=ty0p, width=2 * tr, height=2 * tr) if fromZoom: self.updateFont(fromZoom=True) ''' draw ring around main filled circle ''' ring1_r = r + int(self.z_ringSpacing[0]) x0p, y0p = x - ring1_r, y - ring1_r x1p, y1p = x + ring1_r, y + ring1_r if init: outline = g.toHex(self.cs.ring1) self.mainRingIndex = self.canvas.create_oval( x0p, y0p, x1p, y1p, fill='', outline=outline, activeoutline=g.toHex(self.cs.highlight2), width=self.z_ringWidths[0], activewidth=self.z_ringWidths[0] * 2) else: self.canvas.coords(self.mainRingIndex, x0p, y0p, x1p, y1p) if fromZoom: self.canvas.itemconfig(self.mainRingIndex, width=self.z_ringWidths[0], activewidth=self.z_ringWidths[0] * 2) ''' draw text for times above ring ''' tx = x ty = y - r - int(self.z_ringSpacing[0]) - 10 * self.curZoom if init: self.labelIndex = self.canvas.create_text( tx, ty, text="", font=(g.mainFont, int(self.z_fontSize), "normal"), fill=g.toHex( g.shadeN([self.cs.background, self.cs.lightText], [0, 1], 0.54))) self.canvas.coords(self.labelIndex, tx, ty) #if fromZoom: # self.updateFont(fromZoom=True) ''' draw small circle on outer ring ''' pRad = r + int(self.z_ringSpacing[0]) pa = pRad #*1.0/math.sqrt(2.0) pb = math.sqrt(pRad * pRad - pa * pa) s_x, s_y = x - pa, y + pb s_r = int(self.z_smallRad) x0p, y0p = s_x - s_r, s_y - s_r x1p, y1p = s_x + s_r, s_y + s_r if init: outline, fill = g.toHex(self.cs.ring1), g.toHex( self.cs.smallCircle) self.smallCircleIndex = self.canvas.create_oval( x0p, y0p, x1p, y1p, fill=fill, outline=outline, width=0, activefill=g.toHex(self.cs.highlight2)) else: self.canvas.coords(self.smallCircleIndex, x0p, y0p, x1p, y1p) ''' draw circles under main circle for shadow ''' if init: self.shadowCircleIndex = [] self.numShadow = 10 ns = 1.0 * self.numShadow #reDraw = (time.time() - self.prevDrawTime)>0.1 for i in range(0, self.numShadow): x_offset = 0 y_offset = self.z_height rFrac = 1.0 + (1.0 + 0.01 * self.z_height) * (0.02 * i) * ( self.std_r / self.r) x0p, y0p = (x + x_offset) - r * rFrac, (y + y_offset) - r * rFrac x1p, y1p = (x + x_offset) + r * rFrac, (y + y_offset) + r * rFrac if init: fill = g.shadeN([self.cs.shadow, self.cs.background], [0, 1.0], 1.0 * math.sqrt(i / ns)) shadowIndex = self.canvas.create_oval(x0p, y0p, x1p, y1p, fill=g.toHex(fill), width=0) self.shadowCircleIndex.append(shadowIndex) self.canvas.tag_lower(shadowIndex, "all") else: #if reDraw: self.canvas.coords(self.shadowCircleIndex[i], x0p, y0p, x1p, y1p)
def pulse2(self, event=[], stage=0): if self.pulsePause and stage == 0: return if stage == 0: if time.time() - self.prevPulseTime <= 1: return if self.colour == self.cs.def_thought: return #if self.parentSheet.fastGraphics: return canvasW = self.root.winfo_width() canvasH = self.root.winfo_height() if stage == 0: self.canvas.tag_lower(self.pulseCircleIndex, "all") #for i in range(self.numShadow): # self.canvas.tag_raise(self.pulseCircleIndex, self.shadowCircleIndex[i]) total_stages = 10 f = 1.0 * stage / total_stages r = self.z_r # center of circle x = 1.0 * canvasW * self.loc[0] y = 1.0 * canvasH * self.loc[1] #print "here" if stage <= total_stages: self.pulsePause = True pRad = 40 * self.curZoom curRad = r + f * pRad x0p, y0p = x - curRad, y - curRad x1p, y1p = x + curRad, y + curRad fill = g.shadeN([self.colour, self.cs.def_thought], [0, 1], f) self.canvas.coords(self.pulseCircleIndex, x0p, y0p, x1p, y1p) self.canvas.itemconfig(self.pulseCircleIndex, fill=g.toHex(fill)) t = threading.Timer(0.04, self.pulse, [[], stage + 1]) t.daemon = True t.start() else: offset = 0 #10*self.curZoom rFrac = 0.5 #1.1 x0p, y0p = (x + offset) - r * rFrac, ( y + offset) - r * rFrac #x-r/2, y-r/2 x1p, y1p = (x + offset) + r * rFrac, ( y + offset) + r * rFrac #x+r/2, y+r/2 self.canvas.coords(self.pulseCircleIndex, x0p, y0p, x1p, y1p) #self.canvas.itemconfig(self.pulseCircleIndex, fill = g.toHex(self.cs.lightGrey)) self.pulsePause = False self.prevPulseTime = time.time()
def updateFont(self, fromZoom=False): # dynamically optimize text colour textColour = self.textColour lum = calc.luminance(self.colour) if lum >= 0.5: #print "light background" # 87% opacity for important black text on coloured background textColour = g.shadeN([self.colour, self.cs.darkText], [0, 1], self.cs.fontOpacity) else: #print "dark background" #textColour=self.cs.lightText textColour = g.shadeN([self.colour, self.cs.lightText], [0, 1], self.cs.fontOpacity) #if textColour != self.textColour: self.textColour = textColour insertbg = [ v * 0.5 + w * 0.5 for v, w in zip(self.textColour, self.cs.def_thought) ] if not fromZoom: self.tk_text.configure(fg=g.toHex(textColour), insertbackground=g.toHex(insertbg)) if not fromZoom: tags = list(self.tk_text.tag_names(index=None)) tags.remove("sel") tags.remove("center") for t in tags: self.tk_text.tag_delete(t) text = self.getText() # check for bolding fontThickness = "normal" if '#B' in text: fontThickness = "bold" elif '#I' in text: fontThickness = "italic" self.tk_text.configure(font=(g.mainFont, int(self.z_fontSize // 1), fontThickness)) self.canvas.itemconfig(self.labelIndex, font=(g.mainFont, max(1, int(self.z_labelFontSize // 1)), "normal")) if '#' not in text and '*' not in text: return pos = 1 LINES = text.splitlines() for l in range(len(LINES)): line = LINES[l] #print "line: ", line if line.strip() == "" or ('#' not in line and '*' not in line): pos += 1 continue fontSize = self.z_fontSize if len(line) >= 2: #if line[0:2] == '##': if '##' in line: fontSize = fontSize / 2 locLS = 0 locRS = len(line) - 1 # also colour each word by its importance words = split2(line) for W in words: word = W[0] wStart = W[1] wEnd = W[2] if W[0][0] == '#': tagName = '%s.%s' % (pos, wStart) + 'WF' self.tk_text.tag_add(tagName, '%s.%s' % (pos, wStart), '%s.%s' % (pos, wStart + len(word))) self.tk_text.tag_config(tagName, font=(g.mainFont, int(self.z_fontSize // 2), fontThickness)) elif W[0][0] == '*' and W[0][len(W[0]) - 1] == '*': tagName = '%s.%s' % (pos, wStart) + 'BF' self.tk_text.tag_add(tagName, '%s.%s' % (pos, wStart), '%s.%s' % (pos, wStart + len(word))) self.tk_text.tag_config(tagName, font=(g.mainFont, int(fontSize // 1), "bold")) else: tagName = '%s.%s' % (pos, wStart) + 'norm' self.tk_text.tag_add(tagName, '%s.%s' % (pos, wStart), '%s.%s' % (pos, wStart + len(word))) self.tk_text.tag_config(tagName, font=(g.mainFont, int(fontSize // 1), fontThickness)) pos += 1
def labelEnter(sheet, event=[]): sheet.configure(bg="white", fg=g.toHex(g.shadeN([(1,1,1),cs.darkText],[0,1],cs.fontOpacity)))
graphicsInit() tk_root.bind("<Configure>", resizeLayout) # create list of files on canvas sheets = getFileList() #sheets.append({'filename':'', 'name':'+', 'special':True}) tk_sheets=[] fontColour = g.toHex(g.shadeN([cs.background, cs.lightText], [0,1], cs.fontOpacity)) for s in sheets: s_box = Label(tk_root, text=s['name'], font=g.FONT, bg=g.toHex(cs.background), fg=fontColour, cursor='hand1', anchor=CENTER) s_box.bind('<Button-1>', lambda event, filename=s['filename']: sheetClick(filename, event)) s_box.bind('<Button-3>', lambda event, sheet=s: sheetRightClick(sheet, event)) s_box.bind('<Enter>', lambda event, sheet=s_box: labelEnter(sheet, event)) s_box.bind('<Leave>', lambda event, sheet=s_box: labelLeave(sheet, event)) tk_sheets.append(s_box) s_box_plus = Label(tk_root, text='+', font=g.FONT, bg=g.toHex(cs.background), fg=fontColour, cursor='hand1', anchor=CENTER) s_box_plus.bind('<Button-1>', addFile) s_box_plus.bind('<Enter>', lambda event, sheet=s_box_plus: labelEnter(sheet, event)) s_box_plus.bind('<Leave>', lambda event, sheet=s_box_plus: labelLeave(sheet, event))
def setOutlineColour(self, colour): self.canvas.itemconfig(self.canvasIndex, outline=g.toHex(colour))
def setFillolour(self, colour): self.canvas.itemconfig(self.canvasIndex, fill=g.toHex(colour))