def open_bookmark_table(self,*data): window_bookmark = window.Window(_("Bookmark Table")) list_view = widget.ListView(_("Select the bookmark")) for item in self.bookmark_list: name = item[0] list_view.add_item(name) def jump(*data): index = list_view.get_selected_item_index() self.move_cursor_to_mark(self.bookmark_list[index][1]) self.highlights_cursor_line() window_bookmark.destroy() def scroll_to_position(*data): index = list_view.get_selected_item_index() self.move_cursor_to_mark(self.bookmark_list[index][1]) self.highlights_cursor_line() def delete(*data): index = list_view.get_selected_item_index() self.bookmark_list.pop(index) list_view.remove_selected_item() self.save_bookmark_table("None") def close(*data): window_bookmark.destroy() scroll_box_bookmark = containers.ScrollBox() scroll_box_bookmark.add(list_view) button_jump = widget.Button(_("Jump")) button_jump.connect_function(jump) button_scroll_to_position = widget.Button(_("Scroll Text to position")) button_scroll_to_position.connect_function(scroll_to_position) button_delete = widget.Button(_("Delete")) button_delete.connect_function(delete) button_close = widget.Button(_("Close")) button_close.connect_function(close) list_view.connect_on_select_callback(jump) grid_bookmark = containers.Grid() grid_bookmark.add_widgets([(scroll_box_bookmark,4,1),containers.Grid.NEW_ROW, (button_jump,1,1,False,False),(button_scroll_to_position,1,1,False,False), (button_delete,1,1,False,False),(button_close,1,1,False,False)]) window_bookmark.add(grid_bookmark) window_bookmark.set_default_size(500,200) window_bookmark.show_all()
def open_all_bookmark_table(self, *data): all_bookmark_list = [] window_bookmark = window.Window(_("Bookmark Table")) list_view = widget.ListView(_("Select the bookmark")) for bookmark_file in os.listdir(macros.bookmarks_dir): with open(macros.bookmarks_dir + bookmark_file) as file: for line in file: all_bookmark_list.append(bookmark_file + "~" + line) list_view.add_item( bookmark_file.split("|")[-1] + " : " + line) def jump(*data): index = list_view.get_selected_item_index() item = all_bookmark_list[index] filename = item.split("~")[0].replace("|", "/").replace("#", " ") line_number = item.split("~")[1].split()[0] text = open(filename).read() self.set_text(text) #self.move_cursor_to_line(int(line_number)) print(int(line_number), filename) self.save_file_name = filename self.import_bookmarks_using_filename() mark = self.get_mark_at_line(int(line_number)) self.move_cursor_to_mark(mark) self.highlights_cursor_line() window_bookmark.destroy() def close(*data): window_bookmark.destroy() scroll_box_bookmark = containers.ScrollBox() scroll_box_bookmark.add(list_view) button_jump = widget.Button(_("Jump")) button_jump.connect_function(jump) button_close = widget.Button(_("Close")) button_close.connect_function(close) list_view.connect_on_select_callback(jump) grid_bookmark = containers.Grid() grid_bookmark.add_widgets([(scroll_box_bookmark, 2, 1), containers.Grid.NEW_ROW, (button_jump, 1, 1, False, False), (button_close, 1, 1, False, False)]) window_bookmark.add(grid_bookmark) window_bookmark.set_default_size(500, 200) window_bookmark.show_all()
def open_spell_check(self, *data): entry = widget.Entry() list_view = widget.ListView(_("Suggestions")) statusbar_context = widget.Statusbar() statusbar_context.set_text(_("Context label")) statusbar_context.set_line_wrap(True) change_all_dict = {} self.word = "" def find_next_mispeleed_word(*data): while (not self.is_cursor_at_end()): self.word = self.get_next_word() if self.word in change_all_dict.keys(): self.replace_last_word(change_all_dict[self.word]) continue if (not self.dict.check(self.word)): entry.set_text(self.word) statusbar_context.set_text(self.get_context_text()) list_view.clear() for item in self.dict.suggest(self.word): list_view.add_item(item) break if (self.is_cursor_at_end()): entry.set_text("") statusbar_context.set_text(_("Spell Check finished")) def ignore_all(*data): word = entry.get_text() self.dict.add_to_session(word) find_next_mispeleed_word() def change(*data): replace_word = entry.get_text() self.replace_last_word(replace_word) find_next_mispeleed_word() def change_all(*data): replace_word = entry.get_text() change_all_dict[self.word] = replace_word self.replace_last_word(replace_word) find_next_mispeleed_word() def delete(*data): self.delete_last_word() find_next_mispeleed_word() def on_suggestion_selected(*data): item = list_view.get_selected_item() entry.set_text(item) def close(*data): window1.destroy() grid = containers.Grid() label = widget.Label(_("<b> Misspelled word : </b>")) label.set_use_markup(True) label.set_mnemonic_widget(entry) scroll_box = containers.ScrollBox() scroll_box.add(list_view) change_button = widget.Button(_("Change")) change_button.connect_function(change) change_all_button = widget.Button(_("Change All")) change_all_button.connect_function(change_all) delete_button = widget.Button(_("Delete")) delete_button.connect_function(delete) ignore_button = widget.Button(_("Ignore")) ignore_button.connect_function(find_next_mispeleed_word) ignore_all_button = widget.Button(_("Ignore All")) ignore_all_button.connect_function(ignore_all) add_to_dict_button = widget.Button(_("Add to user dict")) close_button = widget.Button(_("Close")) close_button.connect_function(close) list_view.connect_on_select_callback(on_suggestion_selected) entry.connect_activate_function(change) grid.add_widgets([(label, 1, 1, False, False), (entry, 6, 1, False, False), containers.Grid.NEW_ROW, (scroll_box, 1, 3, False, False), (change_button, 1, 1, False, False), (change_all_button, 1, 1, False, False), (delete_button, 1, 1, False, False), containers.Grid.NEW_ROW, (ignore_button, 1, 1, False, False), (ignore_all_button, 1, 1, False, False), (add_to_dict_button, 1, 1, False, False), containers.Grid.NEW_ROW, (statusbar_context, 1, 1), containers.Grid.NEW_ROW, (close_button, 4, 1, False, False)]) find_next_mispeleed_word() window1 = window.Window(_("Spell-Check")) window1.add(grid) window1.set_default_size(500, 200) window1.show_all()