Down click color hilighting in help browser
This commit is contained in:
parent
38a20ab16d
commit
afa9d7a62d
@ -32,6 +32,7 @@ class HelpBrowserWindow(yutani.Window):
|
||||
self.special = {}
|
||||
self.special['contents'] = self.special_contents
|
||||
self.special['demo'] = self.special_demo
|
||||
self.down_text = None
|
||||
|
||||
def get_title(self, document):
|
||||
if document.startswith("special:"):
|
||||
@ -182,15 +183,50 @@ You can also <link target=\"special:contents\">check the Table of Contents</link
|
||||
self.text_offset -= self.tr.line_height
|
||||
self.update_text_buffer()
|
||||
|
||||
def text_under_cursor(self, msg):
|
||||
"""Get the text unit under the cursor."""
|
||||
x = msg.new_x - self.decorator.left_width()
|
||||
y = msg.new_y - self.decorator.top_height() + self.text_offset
|
||||
return self.tr.click(x,y)
|
||||
|
||||
def mouse_event(self, msg):
|
||||
if d.handle_event(msg) == yutani.Decor.EVENT_CLOSE:
|
||||
window.close()
|
||||
sys.exit(0)
|
||||
if msg.command == yutani.MouseEvent.CLICK:
|
||||
e = self.tr.click(msg.new_x-self.decorator.left_width(),msg.new_y-self.decorator.top_height()+self.text_offset)
|
||||
if e and 'link' in e.extra:
|
||||
if msg.command == yutani.MouseEvent.DOWN:
|
||||
e = self.text_under_cursor(msg)
|
||||
r = False
|
||||
if self.down_text and e != self.down_text:
|
||||
for u in self.down_text.tag_group:
|
||||
u.set_font(self.down_font[u])
|
||||
del self.down_font
|
||||
self.down_text = None
|
||||
self.update_text_buffer()
|
||||
r = True
|
||||
if e and 'link' in e.extra and e.tag_group:
|
||||
self.down_font = {}
|
||||
for u in e.tag_group:
|
||||
new_font = toaru_fonts.Font(u.font.font_number,u.font.font_size,0xFFFF0000)
|
||||
self.down_font[u] = u.font
|
||||
u.set_font(new_font)
|
||||
self.update_text_buffer()
|
||||
r = True
|
||||
self.down_text = e
|
||||
else:
|
||||
self.down_text = None
|
||||
return r
|
||||
if msg.command == yutani.MouseEvent.CLICK or msg.command == yutani.MouseEvent.RAISE:
|
||||
e = self.text_under_cursor(msg)
|
||||
if self.down_text and e == self.down_text:
|
||||
self.navigate(e.extra['link'])
|
||||
return True
|
||||
elif self.down_text:
|
||||
for u in self.down_text.tag_group:
|
||||
u.set_font(self.down_font[u])
|
||||
del self.down_font
|
||||
self.down_text = None
|
||||
self.update_text_buffer()
|
||||
return True
|
||||
if msg.buttons & yutani.MouseButton.SCROLL_UP:
|
||||
self.scroll(-30)
|
||||
return True
|
||||
|
@ -9,6 +9,11 @@ class TextUnit(object):
|
||||
self.font = font
|
||||
self.width = font.width(self.string)
|
||||
self.extra = {}
|
||||
self.tag_group = None
|
||||
|
||||
def set_tag_group(self, tag_group):
|
||||
self.tag_group = tag_group
|
||||
self.tag_group.append(self)
|
||||
|
||||
def set_font(self, font):
|
||||
self.font = font
|
||||
@ -180,6 +185,7 @@ class TextRegion(object):
|
||||
self.units = []
|
||||
self.link_stack = []
|
||||
self.current_link = None
|
||||
self.tag_group = None
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
def make_bold(n):
|
||||
@ -219,6 +225,7 @@ class TextRegion(object):
|
||||
for attr in attrs:
|
||||
if attr[0] == "target":
|
||||
target = attr[1]
|
||||
self.tag_group = []
|
||||
self.link_stack.append(self.current_link)
|
||||
self.current_link = target
|
||||
self.font_stack.append(self.current_font)
|
||||
@ -244,12 +251,16 @@ class TextRegion(object):
|
||||
self.current_font = self.font_stack.pop()
|
||||
if tag in ["link"]:
|
||||
self.current_link = self.link_stack.pop()
|
||||
self.tag_group = None
|
||||
|
||||
def handle_data(self, data):
|
||||
units = tr.units_from_text(data, self.current_font)
|
||||
if self.current_link:
|
||||
for u in units:
|
||||
u.set_extra('link',self.current_link)
|
||||
if self.tag_group is not None:
|
||||
for u in units:
|
||||
u.set_tag_group(self.tag_group)
|
||||
self.units.extend(units)
|
||||
|
||||
parser = RichTextParser()
|
||||
|
Loading…
x
Reference in New Issue
Block a user