예제 #1
0
파일: editor.py 프로젝트: 2php/lios-3
    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 __init__(self,update_handler):
		containers.Box.__init__(self,containers.Box.VERTICAL)
		self.imageview = imageview.ImageViewer()
		self.imageview.connect("list_updated",self.list_updated_event_handler);
		self.update_handler = update_handler

		self.image_name = ""

		button_zoom_in = widget.Button(_("Zoom-In"))
		button_zoom_in.connect_function(self.imageview.zoom_in)
		button_zoom_fit = widget.Button(_("Zoom-Fit"))
		button_zoom_fit.connect_function(self.imageview.zoom_fit)
		button_zoom_out = widget.Button(_("Zoom-Out"))
		button_zoom_out.connect_function(self.imageview.zoom_out)
		button_save = widget.Button(_("Export-Boxes"))
		button_save.connect_function(self.save_boxes_dialog)
		button_load = widget.Button(_("Load-Boxes"))
		button_load.connect_function(self.load_boxes_dialog)
		self.add(self.imageview)
		box1 = containers.Box(containers.Box.HORIZONTAL)
		box1.add(button_zoom_in)
		box1.add(button_zoom_fit)
		box1.add(button_zoom_out)
		box1.add(button_save)
		box1.add(button_load)
		box1.set_hexpand(True)
		button_zoom_in.set_hexpand(True)
		button_zoom_fit.set_hexpand(True)
		button_zoom_out.set_hexpand(True)
		button_save.set_hexpand(True)
		button_load.set_hexpand(True)
		self.add(box1)
		#self.connect_configure_event_handler(self.configure_event)
		self.imageview.show()
		self.show_all()
예제 #3
0
    def __init__(self):
        window.Window.__init__(self, title="Hello World")

        self.iv = ImageViewer()
        li = [(0, 10, 10, 10, 10, "a"), (0, 30, 30, 10, 10, "b"),
              (0, 50, 50, 10, 10, "c")]
        self.iv.load_image("/usr/share/lios/lios.png", li,
                           ImageViewer.ZOOM_FIT)

        button1 = widget.Button("Get List")
        button1.connect_function(self.on_button1_clicked)

        button2 = widget.Button(label="Set List")
        button2.connect_function(self.on_button2_clicked)

        button3 = widget.Button(label="Zoom-In")
        button3.connect_function(self.on_button3_clicked)

        button4 = widget.Button(label="Zoom-Out")
        button4.connect_function(self.on_button4_clicked)

        grid = containers.Grid()
        grid.add_widgets([(self.iv, 2, 1, True, True), containers.Grid.NEW_ROW,
                          (button1, 1, 1, True, False),
                          (button2, 1, 1, True, False),
                          containers.Grid.NEW_ROW,
                          (button3, 1, 1, True, False),
                          (button4, 1, 1, True, False)])

        self.add(grid)
        grid.show()
        self.set_default_size(700, 600)
예제 #4
0
	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()
예제 #5
0
    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()
예제 #6
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()
예제 #7
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()
예제 #8
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()
예제 #9
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()
예제 #10
0
	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()
예제 #11
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")