Example #1
0
def pulse(sheet, stage=0):

    try:

        total_stages = 20

        f = 1.0 * stage / total_stages

        lightFontColour = shadeN([cs.background, cs.lightText], [0, 1],
                                 cs.fontOpacity)
        darkFontColour = shadeN([(1, 1, 1), cs.darkText], [0, 1],
                                cs.fontOpacity)

        if stage <= total_stages:
            sheetColour = shadeN([(1, 1, 1), cs.background], [0, 1], f)

            textColour = shadeN([darkFontColour, lightFontColour], [0, 1], f)

            sheet.configure(bg=toHex(sheetColour), fg=toHex(textColour))

        if stage < total_stages:
            t = threading.Timer(0.01, pulse, [sheet, stage + 1])
            t.daemon = True
            t.start()
    except:
        pass
Example #2
0
    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 = shadeN([(1, 1, 1), self.cs.highlight2], [0, 3],
                                importance + 2)
            if importance == 1:
                self.canvas.itemconfig(self.smallCircleIndex,
                                       fill=toHex(holdColour))
            else:
                self.canvas.itemconfig(self.smallCircleIndex,
                                       fill=toHex(holdColour))
        elif self.parentSheet.linkB == -1:
            self.parentSheet.linkB = self.index

            self.parentSheet.addLink()
Example #3
0
    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  # utils.shadeN([self.tA.colour, self.cs.background],[0,1],0.5)  #

        if importance != 1:
            self.colour = utils.shadeN([self.colour, self.cs.background],
                                       [0, 1], 0.75)

            self.width = 5

        #print "importance =", importance

        self.setZooms()

        self.initDrawing()
Example #4
0
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 = toHex(shadeN([(1, 1, 1), cs.darkText], [0, 1],
                              cs.fontOpacity))

    tk_text.configure(font=(settings.MAIN_FONT, fontSize, "normal"),
                      fg=fontColour,
                      bg="white")

    tk_root.update()
Example #5
0
    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 = shadeN([HIC, self.parentSheet.cs.background],
                                 [1, max_shades + 1], int(shadeChar))

        self.recolour()

        self.updateFont()
    def step(self, dt):

        self.cur_angles += self.speeds * dt

        # compute displacement vectors of each gear
        compounded_delta = (0, 0)
        for rad, theta in zip(self.radii, self.cur_angles):
            dx = rad * math.cos(theta)
            dy = rad * math.sin(theta)
            #vectors.append((dx, ))
            compounded_delta = (compounded_delta[0] + dx,
                                compounded_delta[1] + dy)

        # compute speed
        dx = compounded_delta[0] - self.cur_loc[0]
        dy = compounded_delta[1] - self.cur_loc[1]
        v = ((dx**2 + dy**2)**0.5) / dt
        self.current_speed = v

        self.cur_loc = compounded_delta

        angle = (math.atan2(dy, dx) - math.pi / 4) % (2 * math.pi)
        # scale angle to 0 -> 1
        angle = angle / (2 * math.pi)

        self.current_colour = shadeN(colours=(self.cur_color_range[0],
                                              self.cur_color_range[1],
                                              self.cur_color_range[0]),
                                     centers=(0, 0.5, 1),
                                     v=angle)

        if random.random() < dt * 0.005:
            if random.random() < 0.5:
                self.speeds += np.random.normal(
                    0, np.random.choice([0.002, 0.01, 0.05]), self.n_gears)
                #if random.random() < 0.25:
                #	self.current_colour = random.choice(self.colour_options)
            else:
                mask = np.random.choice([0, 1], self.n_gears)
                self.speeds = 1. * self.speeds * mask + (
                    1 - mask) * np.random.choice(
                        [-1, 1], self.n_gears) * np.random.choice(
                            [0, 0, 1, 2, 4, 8, 16], self.n_gears)

                self.performed_regime_switch = True

                #self.current_colour = random.choice(self.colour_options)
                self.cur_color_range = random.choice(self.colour_options)

        else:
            self.performed_regime_switch = False
Example #7
0
def init_pages():
    global tk_sheets

    # destroy any sheets in list so that we can update it (ex. after deletion)
    for s in tk_sheets:
        s.destroy()

    font_colour = toHex(
        shadeN([cs.background, cs.lightText], [0, 1], cs.fontOpacity))

    tk_sheets = []

    sheets_info = get_sheet_list()

    for s in sheets_info:
        s_box = tk.Label(tk_root,
                         text=s['name'],
                         font=settings.FONT,
                         bg=toHex(cs.background),
                         fg=font_colour,
                         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>',
                   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 = tk.Label(tk_root,
                          text='+',
                          font=settings.FONT,
                          bg=toHex(cs.background),
                          fg=font_colour,
                          cursor='hand1',
                          anchor=tk.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)

    resize_layout()
Example #8
0
def addLeave(event=[], stage=0):

    #try:

    total_stages = 20

    f = 1.0 * stage / total_stages

    if stage <= total_stages:
        bgColour = shadeN([(1.0, 1.0, 1.0), cs.background], [0, 1], f)
        textColour = shadeN([cs.darkText, cs.lightText], [0, 1], f)

        fontColour = shadeN([bgColour, textColour], [0, 1], cs.fontOpacity)

        tk_text.configure(fg=toHex(fontColour),
                          bg=toHex(bgColour))  #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()
Example #9
0
    def pulse(self, stage=0):

        #try:

        total_stages = 20

        f = 1.0 * stage / total_stages

        if stage <= total_stages:
            bkgColour = shadeN([
                self.cs.background, self.cs.backgroundPulse, self.cs.background
            ], [0, 0.5, 1], f)

            self.canvas.configure(bg=toHex(bkgColour))

        if stage < total_stages:
            t = threading.Timer(0.01, self.pulse, [stage + 1])
            t.daemon = True
            t.start()
        #except:
        #	pass
Example #10
0
    def updateFont(self, fromZoom=False):

        # dynamically optimize text colour
        textColour = self.textColour
        lum = utils.luminance(self.colour)
        if lum >= 0.5:
            #print "light background"

            # 87% opacity for important black text on coloured background
            textColour = shadeN([self.colour, self.cs.darkText], [0, 1],
                                self.cs.fontOpacity)
        else:
            #print "dark background"
            #textColour=self.cs.lightText

            textColour = 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=toHex(textColour),
                                   insertbackground=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=(settings.MAIN_FONT,
                                     int(self.z_fontSize // 1), fontThickness))
        self.canvas.itemconfig(self.labelIndex,
                               font=(settings.MAIN_FONT,
                                     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=(settings.MAIN_FONT,
                                                  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=(settings.MAIN_FONT,
                                                  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=(settings.MAIN_FONT,
                                                  int(fontSize // 1),
                                                  fontThickness))

            pos += 1
Example #11
0
    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 = 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 = toHex(self.colour), 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=(settings.MAIN_FONT,
                                         int(self.z_labelFontSize), "normal"),
                                   bg=toHex(self.colour),
                                   fg=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 = toHex(self.cs.ring1)
            self.mainRingIndex = self.canvas.create_oval(
                x0p,
                y0p,
                x1p,
                y1p,
                fill='',
                outline=outline,
                activeoutline=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=(settings.MAIN_FONT, int(self.z_fontSize), "normal"),
                fill=toHex(
                    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 = toHex(self.cs.ring1), toHex(self.cs.smallCircle)
            self.smallCircleIndex = self.canvas.create_oval(
                x0p,
                y0p,
                x1p,
                y1p,
                fill=fill,
                outline=outline,
                width=0,
                activefill=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 = 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=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)
Example #12
0
def labelEnter(sheet, event=[]):

    sheet.configure(bg="white",
                    fg=toHex(
                        shadeN([(1, 1, 1), cs.darkText], [0, 1],
                               cs.fontOpacity)))
Example #13
0
if __name__ == "__main__":

    cs = ColourScheme()

    tk_root = tk.Tk()

    graphics_init(cs)

    tk_root.bind("<Configure>", resize_layout)

    # create list of files on canvas
    sheets = get_sheet_list()

    tk_sheets = []
    font_colour = toHex(
        shadeN([cs.background, cs.lightText], [0, 1], cs.fontOpacity))
    for s in sheets:
        s_box = tk.Label(tk_root,
                         text=s['name'],
                         font=settings.FONT,
                         bg=toHex(cs.background),
                         fg=font_colour,
                         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>',