mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-03-27 09:08:21 -04:00
Added error handling to micron parser mouse event translator. Fixes #32.
This commit is contained in:
parent
22a7acf259
commit
34b3987ded
@ -751,41 +751,45 @@ class LinkableText(urwid.Text):
|
|||||||
return x, y
|
return x, y
|
||||||
|
|
||||||
def mouse_event(self, size, event, button, x, y, focus):
|
def mouse_event(self, size, event, button, x, y, focus):
|
||||||
if button != 1 or not is_mouse_press(event):
|
try:
|
||||||
return False
|
if button != 1 or not is_mouse_press(event):
|
||||||
else:
|
return False
|
||||||
(maxcol,) = size
|
|
||||||
translation = self.get_line_translation(maxcol)
|
|
||||||
line_offset = 0
|
|
||||||
|
|
||||||
if self.align == "center":
|
|
||||||
line_offset = translation[y][1][1]-translation[y][0][0]
|
|
||||||
if x < translation[y][0][0]:
|
|
||||||
x = translation[y][0][0]
|
|
||||||
|
|
||||||
if x > translation[y][1][0]+translation[y][0][0]:
|
|
||||||
x = translation[y][1][0]+translation[y][0][0]
|
|
||||||
|
|
||||||
elif self.align == "right":
|
|
||||||
line_offset = translation[y][1][1]-translation[y][0][0]
|
|
||||||
if x < translation[y][0][0]:
|
|
||||||
x = translation[y][0][0]
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
line_offset = translation[y][0][1]
|
(maxcol,) = size
|
||||||
if x > translation[y][0][0]:
|
translation = self.get_line_translation(maxcol)
|
||||||
x = translation[y][0][0]
|
line_offset = 0
|
||||||
|
|
||||||
pos = line_offset+x
|
if self.align == "center":
|
||||||
|
line_offset = translation[y][1][1]-translation[y][0][0]
|
||||||
|
if x < translation[y][0][0]:
|
||||||
|
x = translation[y][0][0]
|
||||||
|
|
||||||
self._cursor_position = pos
|
if x > translation[y][1][0]+translation[y][0][0]:
|
||||||
item = self.find_item_at_pos(self._cursor_position)
|
x = translation[y][1][0]+translation[y][0][0]
|
||||||
|
|
||||||
if item != None:
|
elif self.align == "right":
|
||||||
if isinstance(item, LinkSpec):
|
line_offset = translation[y][1][1]-translation[y][0][0]
|
||||||
self.handle_link(item.link_target, item.link_fields)
|
if x < translation[y][0][0]:
|
||||||
|
x = translation[y][0][0]
|
||||||
|
|
||||||
self._invalidate()
|
else:
|
||||||
self._emit("change")
|
line_offset = translation[y][0][1]
|
||||||
|
if x > translation[y][0][0]:
|
||||||
|
x = translation[y][0][0]
|
||||||
|
|
||||||
|
pos = line_offset+x
|
||||||
|
|
||||||
|
self._cursor_position = pos
|
||||||
|
item = self.find_item_at_pos(self._cursor_position)
|
||||||
|
|
||||||
|
if item != None:
|
||||||
|
if isinstance(item, LinkSpec):
|
||||||
|
self.handle_link(item.link_target, item.link_fields)
|
||||||
|
|
||||||
|
self._invalidate()
|
||||||
|
self._emit("change")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
return True
|
except Exception as e:
|
||||||
|
return False
|
Loading…
x
Reference in New Issue
Block a user