def add_clicked(*data): entry_match = widget.Entry() entry_replace = widget.Entry() dlg = dialog.Dialog(_("Give match and replace"),(_("Ok"), dialog.Dialog.BUTTON_ID_1,_("Close!"), dialog.Dialog.BUTTON_ID_2)) dlg.add_widget_with_label(entry_match,_("Match : ")) dlg.add_widget_with_label(entry_replace,_("Replace : ")) entry_match.grab_focus() dlg.show_all() response = dlg.run() if (response == dialog.Dialog.BUTTON_ID_1): treeview.append((entry_match.get_text(),entry_replace.get_text())) self.text_cleaner_list = treeview.get_list() self.save_text_cleaner_list_to_file(macros.local_text_cleaner_list_file); dlg.destroy()
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()
def create_bookmark(self,*data): try: self.save_file_name except: dlg = dialog.Dialog(_("Warning!"),(_("Close!"), dialog.Dialog.BUTTON_ID_2)) label = widget.Label(_("File must be saved inorder to bookmark the text!")) dlg.add_widget(label) dlg.show_all() response = dlg.run() dlg.destroy() return entry_sentence = widget.Entry() text = self.get_current_line_text() entry_sentence.set_text(text) dlg = dialog.Dialog(_("Create new Bookmark"),(_("Bookmark"), dialog.Dialog.BUTTON_ID_1,_("Close!"), dialog.Dialog.BUTTON_ID_2)) dlg.add_widget_with_label(entry_sentence,_("Name : ")) entry_sentence.grab_focus() dlg.show_all() response = dlg.run() if response == dialog.Dialog.BUTTON_ID_1: # Note that this ### string will be deleted automatically # Because it's considered as line number sentence = entry_sentence.get_text() # Note that this mark can't be used directly # Because it will always hold cursor position mark = self.get_cursor_mark() line_number = self.get_line_number_of_mark(mark) real_mark = self.get_mark_at_line(line_number) self.bookmark_list.append((sentence,real_mark)) self.save_bookmark_table("None") dlg.destroy() else: dlg.destroy()
def __init__(self): containers.Box.__init__(self,containers.Box.HORIZONTAL) label = widget.Label("Font "); label.set_hexpand(True) self.entry = widget.Entry() self.entry.set_hexpand(True) self.fontbutton = widget.FontButton(); self.fontbutton.set_hexpand(True) self.fontbutton.set_font("Sans 10") self.entry.set_text("Sans") self.fontbutton.connect_function(self.font_changed) self.cb_italic = widget.CheckButton("Italic") self.cb_bold = widget.CheckButton("Bold") self.cb_fixed = widget.CheckButton("Fixed") self.cb_serif = widget.CheckButton("Serif") self.cb_fraktur = widget.CheckButton("Fraktur") self.add(label) self.add(self.entry) self.add(self.fontbutton) self.add(self.cb_italic) self.add(self.cb_bold) self.add(self.cb_fixed) self.add(self.cb_serif) self.add(self.cb_fraktur) self.show_all()
def button_ambiguous_add_clicked(self,*data): dlg = dialog.Dialog(_("Add new ambiguous"), (_("Close"), dialog.Dialog.BUTTON_ID_1,_("Add"), dialog.Dialog.BUTTON_ID_2)) entry_match = widget.Entry() entry_replace = widget.Entry() combobox_mandatory = widget.ComboBox() combobox_mandatory.add_item(_("No")) combobox_mandatory.add_item(_("Yes")) combobox_mandatory.set_active(0) dlg.add_widget_with_label(entry_match,_("Match ")) dlg.add_widget_with_label(entry_replace,_("Replace ")) dlg.add_widget_with_label(combobox_mandatory,_("Mandatory")) response = dlg.run() if(response == dialog.Dialog.BUTTON_ID_2): self.treeview_ambiguous.append((entry_match.get_text(), entry_replace.get_text(),combobox_mandatory.get_active())) dlg.destroy()
def place_traineddata(self,source,language): if (os.path.isfile(self.tessdata_dir+"/"+language+".traineddata")): dlg = dialog.Dialog(language+_(" Alrady exist! Please edit name to avoid replacing"), (_("Place it"), dialog.Dialog.BUTTON_ID_1)) entry = widget.Entry() dlg.add_widget_with_label(entry,_("File Name : ")) entry.set_text(language) response = dlg.run() language = entry.get_text() dlg.destroy() command = "cp {0} {1}/{2}.traineddata".format(source,self.tessdata_dir,language) self.run_command_in_super_user_mode(command,self.tessdata_dir) self.update_language_list()
def __init__(self,file_path): containers.Box.__init__(self,containers.Box.VERTICAL) self.file_path = file_path box = containers.Box(containers.Box.HORIZONTAL) label = widget.Label(_("Find :")) box.add(label) self.entry = widget.Entry() self.entry.connect_activate_function(self.entry_activated) self.entry.set_hexpand(True) box.add(self.entry) self.add(box) self.textview = text_view.TextView() self.textview.set_highlight_color("#1572ffff0000") scrolled = containers.ScrollBox() scrolled.add(self.textview) scrolled.set_vexpand(True) self.add(scrolled)
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()
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()
def button_generate_image_clicked(self,*data): #Create image (using fonts) label_font_automatic = widget.Label(_("Font")); entry_font_automatic = widget.Entry() fontbutton_automatic = widget.FontButton(); fontbutton_automatic.set_font("FreeMono") entry_font_automatic.set_editable(False) entry_font_automatic.set_text(fontbutton_automatic.get_font_name()) button_choose_font_automatic = widget.Button(_("Choose-Font-File")); generate_and_train_text_view = text_view.TextView() scroll_box = containers.ScrollBox() scroll_box.set_size_request(-1,100); scroll_box.set_border_width(20); scroll_box.add(generate_and_train_text_view) def fontbutton_automatic_clicked(*data): fontname = fontbutton_automatic.get_font_name() entry_font_automatic.set_text(fontname) generate_and_train_text_view.set_font(fontname) spin_font_size.set_value(int(fontname.split()[-1])) def button_choose_font_automatic_clicked(*data): file_chooser = FileChooserDialog(_("Select font file"), FileChooserDialog.OPEN,"*", "/usr/share/fonts/") response = file_chooser.run() if response == FileChooserDialog.ACCEPT: font_file = file_chooser.get_filename() file_chooser.destroy() if (os.path.isfile(font_file)): entry_font_automatic.set_text(font_file) generate_and_train_text_view.set_font("FreeMono") else: file_chooser.destroy() def button_select_input_text_clicked(*data): file_chooser = FileChooserDialog(_("Select input file"), FileChooserDialog.OPEN,macros.supported_text_formats,macros.home_dir) response = file_chooser.run() if response == FileChooserDialog.ACCEPT: input_file = file_chooser.get_filename() file_chooser.destroy() if (os.path.isfile(input_file)): entry_input_text_automatic.set_text(input_file) generate_and_train_text_view.set_text(open(input_file).read()) else: file_chooser.destroy() fontbutton_automatic.connect_function(fontbutton_automatic_clicked) button_choose_font_automatic.connect_function(button_choose_font_automatic_clicked) label_font_size = widget.Label(_("Font Size")); spin_font_size = widget.SpinButton(10,8,96) label_select_input_text = widget.Label(_("Input Text File")); entry_input_text_automatic = widget.Entry() entry_input_text_automatic.set_editable(False) button_select_input_text = widget.Button(_("Choose")); button_select_input_text.connect_function(button_select_input_text_clicked) label_writing_mode = widget.Label(_("Writing Mode")); combobox_writing_mode = widget.ComboBox(); combobox_writing_mode.add_item("horizontal") combobox_writing_mode.add_item("vertical") combobox_writing_mode.add_item("vertical-upright") combobox_writing_mode.set_active(0) label_writing_char_spacing_automatic = widget.Label(_("Inter-character space")); spinbutton_writing_char_spacing_automatic = widget.SpinButton(5,0,50) label_writing_resolution_automatic = widget.Label(_("Resolution")); spinbutton_writing_resolution_automatic = widget.SpinButton(300,100,1200) check_button_writing_degrade_image_automatic = widget.CheckButton(_("Degrade-image")) label_writing_exposure_level_automatic = widget.Label(_("Exposure-Level")); spinbutton_writing_exposure_level_automatic = widget.SpinButton(0,0,50) check_button_writing_ligature_mode_automatic = widget.CheckButton(_("Ligatur-Mode")) grid_manual_methord = containers.Grid() grid_manual_methord.add_widgets([(label_font_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND,containers.Grid.ALIGN_START), (entry_font_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), (fontbutton_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), (button_choose_font_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (label_font_size,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND,containers.Grid.ALIGN_START), (spin_font_size,3,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (label_select_input_text,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND,containers.Grid.ALIGN_START), (entry_input_text_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), (button_select_input_text,2,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (scroll_box,4,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (label_writing_mode,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND,containers.Grid.ALIGN_START), (combobox_writing_mode,3,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (label_writing_char_spacing_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND,containers.Grid.ALIGN_START), (spinbutton_writing_char_spacing_automatic,3,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (label_writing_resolution_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND,containers.Grid.ALIGN_START), (spinbutton_writing_resolution_automatic,3,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (label_writing_exposure_level_automatic,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND,containers.Grid.ALIGN_START), (spinbutton_writing_exposure_level_automatic,3,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), containers.Grid.NEW_ROW, (check_button_writing_degrade_image_automatic,2,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND), (check_button_writing_ligature_mode_automatic,2,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND)]) dlg = dialog.Dialog(_("Generate-Image"),(_("Generate"), dialog.Dialog.BUTTON_ID_1,_("Close!"), dialog.Dialog.BUTTON_ID_2)) dlg.add_widget(grid_manual_methord) grid_manual_methord.show_all() response = dlg.run(); if(response == dialog.Dialog.BUTTON_ID_1): self.show_progress_bar("Generating image..."); #saving the text in textview to /tmp/tesseract-train/input_file.txt open("/tmp/tesseract-train/input_file.txt","w").write(generate_and_train_text_view.get_text()) font = entry_font_automatic.get_text() font = font.split(" ")[0] fonts_dir = "/usr/share/fonts" if("/" in font): fonts_dir = "/".join(font.split("/")[:-1]) font = font.split("/")[-1].split(".")[0] font_size = spin_font_size.get_value() input_file = entry_input_text_automatic.get_text() active = combobox_writing_mode.get_active() writing_mode = ["horizontal","vertical","vertical-upright"][active] char_space = spinbutton_writing_char_spacing_automatic.get_value() resolution = spinbutton_writing_resolution_automatic.get_value() exposure = spinbutton_writing_exposure_level_automatic.get_value() degrade = int(check_button_writing_degrade_image_automatic.get_active()) ligature = int(check_button_writing_ligature_mode_automatic.get_active()) self.generate_image_with_spec(font,font_size,writing_mode,char_space,resolution,exposure,degrade,ligature,fonts_dir) dlg.destroy()