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 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 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 __init__(self, parentSheet, tA, tB, importance): self.root = parentSheet.root self.canvas = parentSheet.canvas self.parentSheet = parentSheet self.cs = self.parentSheet.cs self.tA = tA self.tB = tB self.importance = importance self._layers = [] #self.colour = tuple([v*0.5 + 1.0*0.5 for v in self.parentSheet.colour]) self.colour = self.cs.link # g.shadeN([self.tA.colour, self.cs.background],[0,1],0.5) # if importance != 1: self.colour = g.shadeN([self.colour, self.cs.background], [0, 1], 0.75) self.width = 5 #print "importance =", importance self.setZooms() self.initDrawing()
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 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 handleHashTags(self, event=[]): # check for hashtags text = self.getText() + ' ' if len(text) < 3: return LIC = self.parentSheet.cs.background # low importance colour max_shades = 5 HIC = (0, 0, 0) shadeChar = '1' foundTag = True if '#b' in text: shadeChar = text[text.rfind('#b') + 2] HIC = self.cs.blue elif '#r' in text: shadeChar = text[text.rfind('#r') + 2] HIC = self.cs.red elif '#g' in text: shadeChar = text[text.rfind('#g') + 2] HIC = self.cs.green elif '#y' in text: shadeChar = text[text.rfind('#y') + 2] HIC = self.cs.yellow elif '#o' in text: shadeChar = text[text.rfind('#o') + 2] HIC = self.cs.orange elif '#p' in text: shadeChar = text[text.rfind('#p') + 2] HIC = self.cs.purple elif '#w' in text: shadeChar = text[text.rfind('#w') + 2] HIC = self.cs.white elif '#k' in text: shadeChar = text[text.rfind('#k') + 2] HIC = self.cs.black elif '#h' in text: shadeChar = text[text.rfind('#h') + 2] HIC = self.cs.highlight else: self.colour = self.parentSheet.cs.def_thought #background self.recolour() foundTag = False if foundTag and not shadeChar.isdigit(): shadeChar = '1' # shades for for 1, 2, 3, 4, 5 if foundTag and shadeChar.isdigit(): self.colour = g.shadeN([HIC, self.parentSheet.cs.background], [1, max_shades + 1], int(shadeChar)) self.recolour() self.updateFont()
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()
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 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 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()
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>',