Example #1
0
    def __init__(self):
        super(ImageViewer, self).__init__(containers.Paned.HORIZONTAL)
        self.set_border_width(5)

        #Drawing Area
        self.drawingarea = drawing_area.DrawingArea()

        self.scrolled = containers.ScrollBox()
        self.scrolled.add_with_viewport(self.drawingarea)

        self.drawingarea.connect_button_press_event(
            self.__drawingarea_button_press_event)
        self.drawingarea.connect_button_release_event(
            self.__drawingarea_button_release_event)
        self.drawingarea.connect_motion_notify_event(
            self.__drawingarea_motion_notify_event)

        self.add(self.scrolled)

        #Drawing List Tree View
        self.treeview = tree_view.TreeView([(_("Selected"), bool, False),
                                            (_("X"), float, True),
                                            (_("Y"), float, True),
                                            (_("Width"), float, True),
                                            (_("Height"), float, True),
                                            (_("Letter"), str, True)],
                                           self.edited_callback)

        self.treeview.connect_cursor_change_function(
            self.treeview_cursor_changed)
        self.treeview.connect_rows_reordered_function(
            self.treeview_rows_reordered)
        self.treeview.set_column_visible(0, False)
        self.treeview.set_reorderable(True)
        scrolled_treeview = containers.ScrollBox()
        scrolled_treeview.add(self.treeview)

        self.rs = []
        self.start_row_index = -1
        self.previus_row_index = -1

        button1 = widget.Button(_("_Delete"))
        button1.set_use_underline(True)
        button1.set_tooltip_text(_("Shortcut Alt+D"))
        button1.connect_function(self.__delete_selection)

        button2 = widget.Button(_("Clear"))
        button2.connect_function(self.clear_selection)

        grid = containers.Grid()
        grid.add_widgets([(scrolled_treeview, 2, 1, containers.Grid.HEXPAND,
                           containers.Grid.VEXPAND), containers.Grid.NEW_ROW,
                          (button1, 1, 1, containers.Grid.HEXPAND,
                           containers.Grid.NO_VEXPAND),
                          (button2, 1, 1, containers.Grid.HEXPAND,
                           containers.Grid.NO_VEXPAND)])
        self.add(grid)

        #Inetial Values
        self.on_select = False
        self.on_resize = False
        self.zoom_list = [0.20, 0.40, 0.60, 0.80, 1, 1.20, 1.40, 1.60, 1.80, 2]
        self.zoom_level = self.ZOOM_FIT
        self.drawingarea.show()

        self.set_position(400)
        self.show()
Example #2
0
    def open_text_cleaner(self, *data):
        window_text_cleaner = window.Window(_("Text Cleaner"))
        scroll_box = containers.ScrollBox()
        treeview = tree_view.TreeView([(_("Match"), str, True),
                                       (_("Replace"), str, True)], None)
        scroll_box.add(treeview)
        treeview.set_list(self.text_cleaner_list)

        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_path)
            dlg.destroy()

        def remove_clicked(*data):
            index = treeview.get_selected_row_index()
            treeview.remove(index)
            self.text_cleaner_list = treeview.get_list()
            self.save_text_cleaner_list_to_file(
                macros.local_text_cleaner_list_file_path)

        def export_list(*data):
            self.export_text_cleaner_list()

        def import_list(*data):
            self.import_text_cleaner_list()
            treeview.set_list(self.text_cleaner_list)
            self.save_text_cleaner_list_to_file(
                macros.local_text_cleaner_list_file_path)

        def restore(*data):
            self.set_text_cleaner_list_from_file(
                macros.default_text_cleaner_list_file_path)
            treeview.set_list(self.text_cleaner_list)
            self.save_text_cleaner_list_to_file(
                macros.local_text_cleaner_list_file_path)

        def clear(*data):
            self.text_cleaner_list = []
            treeview.set_list(self.text_cleaner_list)
            self.save_text_cleaner_list_to_file(
                macros.local_text_cleaner_list_file_path)

        def list_updated(*data):
            self.text_cleaner_list = treeview.get_list()
            self.save_text_cleaner_list_to_file(
                macros.local_text_cleaner_list_file_path)

        def close(*data):
            window_text_cleaner.close()

        treeview.connect_update_callback(list_updated)

        button_add = widget.Button(_("Add"))
        button_add.connect_function(add_clicked)
        button_remove = widget.Button(_("Remove"))
        button_remove.connect_function(remove_clicked)

        button_import = widget.Button(_("Import"))
        button_import.connect_function(import_list)
        button_export = widget.Button(_("Export"))
        button_export.connect_function(export_list)

        button_clear = widget.Button(_("Clear"))
        button_clear.connect_function(clear)
        button_restore = widget.Button(_("Restore"))
        button_restore.connect_function(restore)

        button_apply_from_cursor = widget.Button(_("Apply from cursor"))
        button_apply_from_cursor.connect_function(
            self.apply_text_cleaner_from_cursor)

        button_apply = widget.Button(_("Apply on entire text"))
        button_apply.connect_function(self.apply_text_cleaner_entire_text)

        button_close = widget.Button(_("Close"))
        button_close.connect_function(close)

        grid = containers.Grid()
        grid.add_widgets([(scroll_box, 3, 1), containers.Grid.NEW_ROW,
                          (button_add, 1, 1, False, False),
                          (button_remove, 1, 1, False, False),
                          (button_clear, 1, 1, False, False),
                          containers.Grid.NEW_ROW,
                          (button_restore, 1, 1, False, False),
                          (button_apply_from_cursor, 1, 1, False, False),
                          (button_apply, 1, 1, False, False),
                          containers.Grid.NEW_ROW,
                          (button_import, 1, 1, False, False),
                          (button_export, 1, 1, False, False),
                          (button_close, 1, 1, False, False)])

        window_text_cleaner.add(grid)
        window_text_cleaner.set_default_size(400, 500)
        window_text_cleaner.show_all()
Example #3
0
	def __init__(self,image_list=None):
		window.Window.__init__(self, title=_("Tesseract Trainer"))
		self.set_taskbar_icon(macros.logo_file)
		grid = containers.Grid()
		
		if( not ocr.ocr_engine_tesseract.OcrEngineTesseract.is_available()):
			label = widget.Label(_("Tesseract is not installed"))
			self.add(label)
			label.show()
			self.set_default_size(400,200)
			return

		if( not ocr.ocr_engine_tesseract.OcrEngineTesseract.is_training_executables_available()):
			label = widget.Label(_("""Tesseract training executable are not installed. 
Please make sure following exicutables are installed
\ncombine_tessdata, unicharset_extractor, shapeclustering, mftraining, cntraining and text2image.
\nIf you forget to build training tools then use 'make training' and 'sudo make training-install' to build it """))
			self.add(label)
			label.show()
			self.set_default_size(400,200)
			return

		if(not os.path.isdir("/tmp/tesseract-train/")):
			os.mkdir("/tmp/tesseract-train/")

		self.output_terminal = terminal.Terminal("")
		self.output_terminal.set_scrollback_lines(10000)
		scroll_box_output = containers.ScrollBox()
		scroll_box_output.add(self.output_terminal)
		self.output_terminal.connect_context_menu_button_callback(self.terminal_popup_context_menu)
		self.context_menu_terminal = menu.ContextMenu(
			[(_("Copy"),self.terminal_copy_clipboard),
			(_("Paste"),self.terminal_paste_clipboard)])

		#Notebook
		notebook = containers.NoteBook()
		notebook.show_all()
		
		paned_notebook_and_output_terminal = containers.Paned(containers.Paned.VERTICAL)
		paned_notebook_and_output_terminal.add(notebook)
		paned_notebook_and_output_terminal.add(scroll_box_output)
		

		# Train image-box pairs
		seperator_select_images = widget.Separator()
		
		self.icon_view_image_list = icon_view.IconView()
		self.icon_view_image_list.connect_on_selected_callback(self.on_iconview_item_selected)
		scroll_box_iconview = containers.ScrollBox()
		self.icon_view_image_list.set_vexpand(True)
		scroll_box_iconview.add(self.icon_view_image_list)
		
		for item in image_list:
			self.icon_view_image_list.add_item(item);
		self.icon_view_image_list.show()
		
		box_buttons = containers.Box(containers.Box.VERTICAL)

		button_add_image_box_pair = widget.Button("Add Image-Box pairs");
		button_add_image_box_pair.connect_function(self.button_add_image_box_pair_clicked);
		box_buttons.add(button_add_image_box_pair)

		button_generate_image = widget.Button("Generate-Image-Using-Fonts");
		button_generate_image.connect_function(self.button_generate_image_clicked);
		box_buttons.add(button_generate_image)

		button_remove_image_box_pair = widget.Button("Remove Image-Box pair");
		button_remove_image_box_pair.connect_function(self.button_remove_image_box_pair_clicked);
		box_buttons.add(button_remove_image_box_pair)

		button_annotate_image = widget.Button("Annotate(Detect boxes)");
		button_annotate_image.connect_function(self.button_annotate_image_clicked);
		box_buttons.add(button_annotate_image)

		button_re_annotate_image = widget.Button("Re-Annotate(Detect boxes)");
		button_re_annotate_image.connect_function(self.button_annotate_image_clicked);
		box_buttons.add(button_re_annotate_image)

		button_ocr_and_view = widget.Button("OCR & View Output");
		button_ocr_and_view.connect_function(self.button_ocr_and_view_clicked);
		box_buttons.add(button_ocr_and_view)

		button_train_image_box_pairs = widget.Button("Train Image-Box pairs");
		button_train_image_box_pairs.connect_function(self.train_image_box_pairs_clicked);

		self.box_editor = BoxEditor(self.on_image_view_box_list_updated)
		self.font_box = FontBox()
		self.font_box.connect_change_handler(self.font_changed)
		
		box_font_and_box = containers.Box(containers.Box.VERTICAL)
		box_font_and_box.add(self.font_box)
		box_font_and_box.add(self.box_editor)
		box_font_and_box.add(button_train_image_box_pairs)

		box_iconview_and_buttons = containers.Box(containers.Box.VERTICAL) 
		box_iconview_and_buttons.add(scroll_box_iconview)
		box_iconview_and_buttons.add(box_buttons)

		paned_iconview_and_image_view = containers.Paned(containers.Paned.HORIZONTAL)
		paned_iconview_and_image_view.add(box_iconview_and_buttons)
		paned_iconview_and_image_view.add(box_font_and_box)

		notebook.add_page(_("Train images-box"),paned_iconview_and_image_view);		


		#Ambiguous Editor
		self.treeview_ambiguous = tree_view.TreeView([("match",str,True),
		("Replacement",str,True),("Mandatory",int,True)],self.ambiguous_edited_callback)

		button_ambiguous_train = widget.Button(_("Train"));
		button_ambiguous_train.connect_function(self.button_ambiguous_train_clicked)

		button_ambiguous_add = widget.Button(_("Add"));
		button_ambiguous_add.connect_function(self.button_ambiguous_add_clicked)

		button_ambiguous_delete = widget.Button(_("Delete"));
		button_ambiguous_delete.connect_function(self.button_ambiguous_delete_clicked)

		button_ambiguous_delete_all = widget.Button(_("Delete-All"));
		button_ambiguous_delete_all.connect_function(self.button_ambiguous_delete_all_clicked)

		button_ambiguous_import = widget.Button(_("Import"));
		button_ambiguous_import.connect_function(self.button_ambiguous_import_clicked)

		button_ambiguous_export = widget.Button(_("Export"));
		button_ambiguous_export.connect_function(self.button_ambiguous_export_clicked)

		scrolled_ambiguous = containers.ScrollBox()
		scrolled_ambiguous.add(self.treeview_ambiguous)

		box_ambiguous_buttons = containers.Box(containers.Box.VERTICAL)
		box_ambiguous_buttons.add(button_ambiguous_add),
		box_ambiguous_buttons.add(button_ambiguous_delete)
		box_ambiguous_buttons.add(button_ambiguous_delete_all)
		box_ambiguous_buttons.add(button_ambiguous_import)
		box_ambiguous_buttons.add(button_ambiguous_export)
		box_ambiguous_buttons.set_homogeneous(True)

		self.combobox_ambiguous_write_format = widget.ComboBox()
		self.combobox_ambiguous_write_format.add_item("Write in V1")
		self.combobox_ambiguous_write_format.add_item("Write in V2")

		grid_set_ambiguous = containers.Grid()
		grid_set_ambiguous.add_widgets([
		(scrolled_ambiguous,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND),
		(box_ambiguous_buttons,1,1,containers.Grid.NO_HEXPAND,containers.Grid.VEXPAND),
		containers.Grid.NEW_ROW,
		(self.combobox_ambiguous_write_format,2,1,containers.Grid.NO_HEXPAND,containers.Grid.NO_VEXPAND),
		containers.Grid.NEW_ROW,
		(button_ambiguous_train,2,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND)])

		notebook.add_page("Ambiguous",grid_set_ambiguous);


		#Dictionary Editor
		notebook_dicts = containers.NoteBook()
		self.dictionary_objects = []
		for item in DICT_LIST+[macros.home_dir+"/lios/user-words"]:
			dict_object = Dictionary(item)
			notebook_dicts.add_page(item.split("/")[-1],dict_object)
			self.dictionary_objects.append(dict_object)

		button_bind_dictionarys = widget.Button("Bind Dictionary's ")
		button_bind_dictionarys.connect_function(self.button_bind_dictionarys_clicked)

		grid_set_dictionary = containers.Grid()
		grid_set_dictionary.add_widgets([(notebook_dicts,1,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND),
		containers.Grid.NEW_ROW,
		(button_bind_dictionarys,2,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND)]);
		notebook.add_page(_("Dictionary's"),grid_set_dictionary);	

		label_language = widget.Label(_("Language "));
		self.combobox_language = widget.ComboBox();
		self.combobox_language.connect_change_callback_function(self.language_combobox_changed);

		label_tessdata_dir = widget.Label(_("Tessdata directory "));
		self.combobox_tessdata_dir = widget.ComboBox();
		self.combobox_tessdata_dir.connect_change_callback_function(self.tessdata_dir_combobox_changed);

		button_import_language = widget.Button(_("Import"))
		button_import_language.connect_function(self.button_import_language_clicked)
		button_export_language = widget.Button(_("Export"))
		button_export_language.connect_function(self.button_export_language_clicked)
		button_remove_language = widget.Button(_("Remove"))
		button_remove_language.connect_function(self.button_remove_language_clicked)

		self.progress_bar = widget.ProgressBar()
		self.progress_bar.set_show_text(True)
		
		button_close = widget.Button(_("Close"));
		button_close.connect_function(self.close_trainer);
		
		grid.add_widgets([(label_tessdata_dir,1,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND),
		(self.combobox_tessdata_dir,4,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND),
		containers.Grid.NEW_ROW,
		(label_language,1,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND),
		(self.combobox_language,1,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND),
		(button_import_language,1,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND),
		(button_export_language,1,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND),
		(button_remove_language,1,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND),
		containers.Grid.NEW_ROW,(paned_notebook_and_output_terminal,5,1,containers.Grid.HEXPAND,containers.Grid.VEXPAND),
		containers.Grid.NEW_ROW,(self.progress_bar,4,1,containers.Grid.NO_HEXPAND,containers.Grid.NO_VEXPAND),
		(button_close,1,1,containers.Grid.HEXPAND,containers.Grid.NO_VEXPAND)])
		
		
		self.add(grid)
		grid.show_all()
		self.maximize()

		dlg = dialog.Dialog(_("Search entire filesystem for tessdata ?"),
		(_("No"), dialog.Dialog.BUTTON_ID_2,_("Yes"), dialog.Dialog.BUTTON_ID_1))
		label = widget.Label(_("Do you want to search entire filesystem for tessdata ?\nThis may take awhile!"))
		dlg.add_widget(label)
		label.show()
		response = dlg.run()
		if (response == dialog.Dialog.BUTTON_ID_1):
			dir_list = ocr.ocr_engine_tesseract.OcrEngineTesseract.get_all_available_dirs()
		else:
			dir_list = ocr.ocr_engine_tesseract.OcrEngineTesseract.get_available_dirs()
		dlg.destroy()

		self.tessdata_dir_available_list = []
		for item in dir_list:
			self.combobox_tessdata_dir.add_item(item)
			self.tessdata_dir_available_list.append(item)
		self.combobox_tessdata_dir.set_active(0)
		self.box_editor.set_image("/usr/share/lios/lios.png")