def __check_value_to_mark(self): """ Look at visible treeview range, and mark char as needed """ try: (start, end) = self.__view.get_visible_range() # As start may not really visible, use next # start.next() if start is not None and end is not None: # Check if start is really visible area = self.__view.get_cell_area(start) if area.y + area.height / 2 < 0: start.next() # Check if start is non static: value = self.__get_value_for_path(start, 0) while value is not None and value < 0: start.next() value = self.__get_value_for_path(start, 0) # Check if end is really visible area = self.__view.get_cell_area(end) scrolled_allocation = self.__scrolled.get_allocation() if area.y + area.height / 2 > scrolled_allocation.height: end.prev() start_value = self.__get_value_for_path(start, 3) end_value = self.__get_value_for_path(end, 3) if start_value is not None and end_value is not None: start_value = noaccents(index_of(start_value[0])).upper() end_value = noaccents(index_of(end_value[0])).upper() self.__mark_values(start_value, end_value) except: pass # get_visible_range() == None
def __on_button_press_event(self, eventbox, event): """ Scroll to activated child char """ char = None row = None for child in self.__grid.get_children(): allocation = child.get_allocation() if allocation.y <= event.y <= allocation.y + allocation.height: char = child.get_text() break if char is not None: if char == "▲": row = self.__listbox.get_children()[0] elif char == "▼": row = self.__listbox.get_children()[-1] else: for child in self.__listbox.get_children(): if child.id < 0: continue if noaccents(index_of(child.sortname))[0].upper() == char: row = child break if row is not None: values = row.translate_coordinates(self.__listbox, 0, 0) if values is not None: adj = self.__scrolled.get_vadjustment() adj.set_value(values[1])
def __on_button_press(self, eventbox, event): """ Scroll to activated child char """ char = None for child in self.__grid.get_children(): allocation = child.get_allocation() if event.y >= allocation.y and\ event.y <= allocation.y + allocation.height: char = child.get_text() break if char is not None: if char == "▲": self.__view.scroll_to_cell( self.__model.get_path(self.__model[0].iter), None, True, 0, 0) elif char == "▼": self.__view.scroll_to_cell( self.__model.get_path(self.__model[-1].iter), None, True, 0, 0) else: for row in self.__model: if row[0] < 0: continue if noaccents(index_of(row[3]))[0].upper() == char: self.__view.scroll_to_cell( self.__model.get_path(row.iter), None, True, 0, 0) break
def add_char(self, c): """ Add a char to widget, will not be shown @param c as char """ to_add = noaccents(index_of(c)).upper() if to_add not in self.__chars: self.__chars.append(to_add)
def __mark_values(self, start, end): """ Mark values @param start as char @param end as char """ start = noaccents(index_of(start)).upper() end = noaccents(index_of(end)).upper() chars = sorted(self.__chars, key=strxfrm) start_idx = chars.index(start) end_idx = chars.index(end) selected = chars[start_idx:end_idx + 1] + ["▲", "▼"] for child in self.__grid.get_children(): label = child.get_text() mark = True if label in selected else False if mark: child.set_opacity(0.9) if label == chars[start_idx]: values = child.translate_coordinates(self.__grid, 0, 0) if values is not None: self.get_vadjustment().set_value(values[1]) else: child.set_opacity(0.4)