From: Neil Brown Date: Thu, 28 Aug 2008 11:32:34 +0000 (+1000) Subject: Enable editting of text X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=820a146f262fdc5a1d570358e821b1ba16ab8530;p=scribble.git Enable editting of text If you tap in a text, that text becomes current and can be editted or extended. --- diff --git a/scribble.py b/scribble.py index 483443f..8d13a91 100755 --- a/scribble.py +++ b/scribble.py @@ -710,6 +710,7 @@ class ScribblePad: name.connect("clicked", self.setname) self.name = name self.page = page + self.redbutton = red self.line = None self.lines = [] self.hist = [] # undo history @@ -800,10 +801,31 @@ class ScribblePad: if len(self.line) == 2: # just set a cursor self.flush_text() - self.textpos = self.line[1] - self.texttoggle.set_sensitive(True) - c.window.draw_rectangle(self.colour_textmode, True, int(ev.x),int(ev.y), - 2,2) + (lineno,index) = self.find_text(self.line[1]) + if lineno == None: + # new text, + self.textpos = self.line[1] + self.texttoggle.set_sensitive(True) + c.window.draw_rectangle(self.colour_textmode, True, int(ev.x),int(ev.y), + 2,2) + self.line = None + else: + # clicked inside an old text. + # shuffle it to the top, open it, edit. + self.texttoggle.set_sensitive(True) + self.texttoggle.set_active(True) + ln = self.lines[lineno] + self.lines = self.lines[:lineno] + self.lines[lineno+1:] + self.textpos = ln[1] + self.textstr = ln[2] + if ln[0] == "red": + self.colour = self.colour_red + self.redbutton.set_active(True) + else: + self.colour = self.colour_black + self.redbutton.set_active(False) + self.textcurs = index + 1 + self.redraw() self.line = None return if self.texttoggle.get_active(): @@ -838,6 +860,27 @@ class ScribblePad: self.line.append([x,y]) return + def find_text(self, pos): + x = pos[0]; y = pos[1] + for i in range(0, len(self.lines)): + p = self.lines[i] + if type(p[2]) != str: + continue + y = pos[1] + self.lineascent + if x >= p[1][0] and y >= p[1][1] and y < p[1][1] + self.lineheight: + # could be this line - check more precisely + layout = self.page.create_pango_layout(p[2]) + (ink, log) = layout.get_pixel_extents() + (ex,ey,ew,eh) = log + if x < p[1][0] + ex or x > p[1][0] + ex + ew or \ + y < p[1][1] + ey or \ + y > p[1][1] + ey + self.lineheight : + continue + # OK, it is in this one. Find out where. + (index, gr) = layout.xy_to_index((x - p[1][0] - ex) * pango.SCALE, + (y - p[1][1] - ey - self.lineheight) * pango.SCALE) + return (i, index) + return (None, None) def flush_text(self): if self.textstr == None: return