Пример #1
0
    def open_find_dialog(self, *data):
        entry = widget.Entry()
        statusbar_context = widget.Statusbar()
        statusbar_context.set_text(_("Context label"))

        def find_next(*data):
            word = entry.get_text()
            if (not self.is_cursor_at_end()):
                if (self.move_forward_to_word(word)):
                    statusbar_context.set_text(self.get_context_text())

        def find_previous(*data):
            word = entry.get_text()
            if (not self.is_cursor_at_start()):
                if (self.move_backward_to_word(word)):
                    statusbar_context.set_text(self.get_context_text())

        label = widget.Label(_("<b> Find word  : </b>"))
        label.set_use_markup(True)
        label.set_mnemonic_widget(entry)

        next_button = widget.Button(_("Next"))
        next_button.connect_function(find_next)
        previous_button = widget.Button(_("Previous"))
        previous_button.connect_function(find_previous)

        grid = containers.Grid()
        grid.add_widgets([(label, 1, 1),
                          (entry, 1, 1), containers.Grid.NEW_ROW,
                          (statusbar_context, 2, 1), containers.Grid.NEW_ROW,
                          (next_button, 1, 1, False, False),
                          (previous_button, 1, 1, False, False)])
        window_find = window.Window(_("Find Dialog"))
        window_find.add(grid)
        window_find.show_all()
Пример #2
0
    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()
Пример #3
0
    def open_find_and_replace_dialog(self, *data):
        entry_word = widget.Entry()
        entry_replace_word = widget.Entry()
        statusbar_context = widget.Statusbar()
        statusbar_context.set_text(_("Context label"))

        def find_next(*data):
            word = entry_word.get_text()
            if (not self.is_cursor_at_end()):
                if (self.move_forward_to_word(word)):
                    statusbar_context.set_text(self.get_context_text())

        def find_previous(*data):
            word = entry_word.get_text()
            if (not self.is_cursor_at_start()):
                if (self.move_backward_to_word(word)):
                    statusbar_context.set_text(self.get_context_text())
                else:
                    dialog.Dialog(_("No match found")).run()

        def replace(*data):
            word_replace = entry_replace_word.get_text()
            self.replace_last_word(word_replace)

        def replace_all(*data):
            word = entry_word.get_text()
            word_replace = entry_replace_word.get_text()
            while (not self.is_cursor_at_end()):
                if (self.move_forward_to_word(word)):
                    self.replace_last_word(word_replace)
                else:
                    break

        label_word = widget.Label(_("<b> Word: </b>"))
        label_word.set_use_markup(True)
        label_word.set_mnemonic_widget(entry_word)
        label_replace_word = widget.Label(_("<b> Replace word: </b>"))
        label_replace_word.set_use_markup(True)
        label_replace_word.set_mnemonic_widget(entry_replace_word)

        entry_word.connect_activate_function(find_next)
        entry_replace_word.connect_activate_function(find_next)

        button_next = widget.Button(_("Next"))
        button_next.connect_function(find_next)
        button_previous = widget.Button(_("Previous"))
        button_previous.connect_function(find_previous)
        button_replace = widget.Button(_("Replace"))
        button_replace.connect_function(replace)
        button_replace_all = widget.Button(_("Replace All"))
        button_replace_all.connect_function(replace_all)

        grid = containers.Grid()
        grid.add_widgets([(label_word, 2, 1), (entry_word, 4, 1),
                          containers.Grid.NEW_ROW, (label_replace_word, 2, 1),
                          (entry_replace_word, 4, 1), containers.Grid.NEW_ROW,
                          (button_next, 3, 1, False, False),
                          (button_previous, 3, 1, False,
                           False), containers.Grid.NEW_ROW,
                          (statusbar_context, 6, 1), containers.Grid.NEW_ROW,
                          (button_replace, 3, 1, False, False),
                          (button_replace_all, 3, 1, False, False)])
        window_find = window.Window(_("Find Dialog"))
        window_find.add(grid)
        window_find.show_all()