def mouse_event(self, size, event, button, col, row, focus): """ Pass mouse event to appropriate part of frame. Focus may be changed on button 1 press. """ (maxcol, maxrow) = size (htrim, ftrim), (hrows, frows) = self.frame_top_bottom((maxcol, maxrow), focus) if row < htrim: # within header focus = focus and self.focus_part == "header" if is_mouse_press(event) and button == 1: if self.header.selectable(): self.set_focus("header") if not hasattr(self.header, "mouse_event"): return False return self.header.mouse_event((maxcol,), event, button, col, row, focus) if row >= maxrow - ftrim: # within footer focus = focus and self.focus_part == "footer" if is_mouse_press(event) and button == 1: if self.footer.selectable(): self.set_focus("footer") if not hasattr(self.footer, "mouse_event"): return False return self.footer.mouse_event((maxcol,), event, button, col, row - maxrow + frows, focus) # within body focus = focus and self.focus_part == "body" if is_mouse_press(event) and button == 1: if self.body.selectable(): self.set_focus("body") if not hasattr(self.body, "mouse_event"): return False return self.body.mouse_event((maxcol, maxrow - htrim - ftrim), event, button, col, row - htrim, focus)
def mouse_event(self, size, event, button, col, row, focus): """ Pass the event to the contained widgets. May change focus on button 1 press. """ (maxcol, maxrow) = size middle, top, bottom = self.calculate_visible((maxcol, maxrow), focus=True) if middle is None: return False _ignore, focus_widget, focus_pos, focus_rows, cursor = middle trim_top, fill_above = top _ignore, fill_below = bottom fill_above.reverse() # fill_above is in bottom-up order w_list = fill_above + [(focus_widget, focus_pos, focus_rows)] + fill_below wrow = -trim_top for w, w_pos, w_rows in w_list: if wrow + w_rows > row: break wrow += w_rows else: return False focus = focus and w == focus_widget if is_mouse_press(event) and button == 1: if w.selectable(): self.change_focus((maxcol, maxrow), w_pos, wrow) if not hasattr(w, "mouse_event"): return False return w.mouse_event((maxcol,), event, button, col, row - wrow, focus)
def mouse_event(self, size, event, button, col, row, focus): """ Send event to appropriate column. May change focus on button 1 press. """ widths = self.column_widths(size) x = 0 for i in range(len(widths)): if col < x: return False w = self.widget_list[i] end = x + widths[i] if col >= end: x = end + self.dividechars continue focus = focus and self.focus_col == i if is_mouse_press(event) and button == 1: if w.selectable(): self.set_focus(w) if not hasattr(w,'mouse_event'): return False return w.mouse_event((end-x,)+size[1:], event, button, col - x, row, focus) return False
def mouse_event(self, size, event, button, x, y, focus): if is_mouse_press(event): if button == 4 or button == 5: self.keypress(size, 'up' if button == 4 else 'down') return True if button == 1: self.select() return True return super().mouse_event(size, event, button, x, y, focus)
def mouse_event(self, size, event, button, col, row, focus): from urwid.util import is_mouse_press if is_mouse_press(event): if button == 5: return self.keypress(size, 'down') elif button == 4: return self.keypress(size, 'up') return super(WheelableListBox, self).mouse_event( size, event, button, col, row, focus)
def mouse_event(self, size, event, button, col, row, focus): from urwid.util import is_mouse_press if is_mouse_press(event): if button == 5: return self.keypress(size, 'down') elif button == 4: return self.keypress(size, 'up') return super(WheelableListBox, self).mouse_event(size, event, button, col, row, focus)
def mouse_event(self, size, event, button, col, row, focus): """ Pass mouse event to appropriate part of frame. Focus may be changed on button 1 press. """ (maxcol, maxrow) = size (htrim, ftrim),(hrows, frows) = self.frame_top_bottom( (maxcol, maxrow), focus) if row < htrim: # within header focus = focus and self.focus_part == 'header' if is_mouse_press(event) and button==1: if self.header.selectable(): self.set_focus('header') if not hasattr(self.header, 'mouse_event'): return False return self.header.mouse_event( (maxcol,), event, button, col, row, focus ) if row >= maxrow-ftrim: # within footer focus = focus and self.focus_part == 'footer' if is_mouse_press(event) and button==1: if self.footer.selectable(): self.set_focus('footer') if not hasattr(self.footer, 'mouse_event'): return False return self.footer.mouse_event( (maxcol,), event, button, col, row-maxrow+frows, focus ) # within body focus = focus and self.focus_part == 'body' if is_mouse_press(event) and button==1: if self.body.selectable(): self.set_focus('body') if not hasattr(self.body, 'mouse_event'): return False return self.body.mouse_event( (maxcol, maxrow-htrim-ftrim), event, button, col, row-htrim, focus )
def mouse_event(self, size, event, button, x, y, focus): if is_mouse_press(event): if button == 4 or button == 5: #! not works correctly # self._w.set_focus( # self._w.body.get_shifted(self._w.body.focus, (-1 if button==4 else 1)*self.MOUSE_WHEEL_SPEED)[1], # coming_from='above' if button==4 else 'below', # ) # return True pass self.keypress(size, 'up' if button == 4 else 'down') return True return super().mouse_event(size, event, button, x, y, focus)
def mouse_event(self, size, event, button, x, y, focus): """Handle mouse events! """ if button != 1 or not is_mouse_press(event): return False rendered = self.render(size).content() total_text = b"\n".join(row_text(x) for x in rendered) total_offset = (y * size[0]) + x text, chunk_stylings = self.get_text() curr_offset = 0 found_style = None found_text = None found_idx = 0 found_length = 0 for idx, info in enumerate(chunk_stylings): style, length = info if curr_offset < total_offset <= curr_offset + length: found_text = text[curr_offset:curr_offset + length] found_style = style found_idx = idx found_length = length break curr_offset += length if found_style is None or not isinstance(found_style, LinkIndicatorSpec): self._emit('click') return True # it's a link, so change the text and update the RLE! if found_text == found_style.link_label: new_text = found_style.link_target else: new_text = found_style.link_label text = text[:curr_offset] + new_text + text[curr_offset+found_length:] new_rle = len(new_text) chunk_stylings[found_idx] = (found_style, new_rle) self._text = text self._attrib = chunk_stylings self._invalidate() self._emit("change") return True
def mouse_event(self, size, event, button, x, y, focus): if button != 1 or not is_mouse_press(event): return False self.state = not self.state tmp = self.button_left self.button_left =self.button_right self.button_right = tmp self.__init__(self.get_label(), self.callback_func, self.user_data, self.mod) self.mod.parent.refresh_screen() log.debug(str(self.button_right)) #self._emit('click') return True
def mouse_event(self, size, event, button, x, y, focus): """ Toggle state on button 1 press. >>> size = (20,) >>> cb = CheckBox("clickme") >>> cb.state False >>> cb.mouse_event(size, 'mouse press', 1, 2, 0, True) True >>> cb.state True """ if button != 1 or not is_mouse_press(event): return False self.toggle_state() return True
def mouse_event(self, size, event, button, x, y, focus): """ Send 'click' signal on button 1 press. >>> size = (15,) >>> b = Button(u"Ok") >>> clicked_buttons = [] >>> def handle_click(button): ... clicked_buttons.append(button.label) >>> connect_signal(b, 'click', handle_click) >>> b.mouse_event(size, 'mouse press', 1, 4, 0, True) True >>> b.mouse_event(size, 'mouse press', 2, 4, 0, True) # ignored False >>> clicked_buttons # ... = u in Python 2 [...'Ok'] """ if button != 1 or not is_mouse_press(event): return False self._emit('click') return True
def mouse_event(self, size, event, button, x, y, focus): if button != 1 or not is_mouse_press(event): return False else: (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: 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) self._invalidate() self._emit("change") return True
def mouse_event(self, size, event, button, col, row, focus): """ Pass the event to the contained widgets. May change focus on button 1 press. """ (maxcol, maxrow) = size middle, top, bottom = self.calculate_visible((maxcol, maxrow), focus=True) if middle is None: return False _ignore, focus_widget, focus_pos, focus_rows, cursor = middle trim_top, fill_above = top _ignore, fill_below = bottom fill_above.reverse() # fill_above is in bottom-up order w_list = ( fill_above + [ (focus_widget, focus_pos, focus_rows) ] + fill_below ) wrow = -trim_top for w, w_pos, w_rows in w_list: if wrow + w_rows > row: break wrow += w_rows else: return False focus = focus and w == focus_widget if is_mouse_press(event) and button==1: if w.selectable(): self.change_focus((maxcol,maxrow), w_pos, wrow) if not hasattr(w,'mouse_event'): return False return w.mouse_event((maxcol,), event, button, col, row-wrow, focus)
def mouse_event(self, size, event, button, col, row, focus): """ Pass the event to the contained widget. May change focus on button 1 press. """ wrow = 0 item_rows = self.get_item_rows(size, focus) for r, w in zip(item_rows, self.widget_list): if wrow + r > row: break wrow += r focus = focus and self.focus_item == w if is_mouse_press(event) and button == 1: if w.selectable(): self.set_focus(w) if not hasattr(w, 'mouse_event'): return False i = self.widget_list.index(w) tsize = self.get_item_size(size, i, focus, item_rows) return w.mouse_event(tsize, event, button, col, row - wrow, focus)
def mouse_event(self, size, event, button, col, row, focus): """ Pass the event to the contained widget. May change focus on button 1 press. """ wrow = 0 item_rows = self.get_item_rows(size, focus) for r, w in zip(item_rows, self.widget_list): if wrow + r > row: break wrow += r focus = focus and self.focus_item == w if is_mouse_press(event) and button == 1: if w.selectable(): self.set_focus(w) if not hasattr(w, "mouse_event"): return False i = self.widget_list.index(w) tsize = self.get_item_size(size, i, focus, item_rows) return w.mouse_event(tsize, event, button, col, row - wrow, focus)