Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.__config = config
def do(self):
SimpleAction.do(self)
for scheduler in self.__main_win.schedulers.values():
scheduler.stop()
self.__config.write()
Gtk.main_quit()
def on_window_close_cb(self, window):
self.do()
class ActionRefreshIndex(SimpleAction):
def __init__(self, main_window, config, force=False):
SimpleAction.__init__(self, "Refresh index")
self.__main_win = main_window
self.__config = config
self.__force = force
self.__connect_handler_id = None
def do(self):
SimpleAction.do(self)
self.__main_win.schedulers['main'].cancel_all(
self.__main_win.job_factories['index_reloader'])
self.__main_win.schedulers['main'].cancel_all(
self.__main_win.job_factories['doc_examiner'])
self.__main_win.schedulers['main'].cancel_all(
self.__main_win.job_factories['index_updater'])
docsearch = self.__main_win.docsearch
"""
if not ask_confirmation(self.__main_win.window):
return
SimpleAction.do(self)
logger.info("Deleting ...")
self.__main_win.page.destroy()
logger.info("Deleted")
self.__main_win.page = None
for widget in self.__main_win.need_page_widgets:
widget.set_sensitive(False)
self.__main_win.refresh_docs([self.__main_win.doc])
self.__main_win.refresh_page_list()
self.__main_win.refresh_label_list()
class ActionRedoDocOCR(SimpleAction):
def __init__(self, main_window):
SimpleAction.__init__(self, "Redoing doc ocr")
self.__main_win = main_window
def do(self):
if not ask_confirmation(self.__main_win.window):
return
SimpleAction.do(self)
doc = self.__main_win.doc[1]
job = self.__main_win.job_factories['ocr_redoer'].make(doc)
self.__main_win.schedulers['main'].schedule(job)
class ActionRedoAllOCR(SimpleAction):
def __init__(self, main_window):
assert(current_idx >= 0)
# apply the change
current_idx += self.__offset
if (current_idx < 0 or current_idx >= len(zoom_liststore)):
return
if zoom_list[current_idx][0] == 0.0:
return
self.__main_win.lists['zoom_levels']['gui'].set_active(
zoom_list[current_idx][1])
class ActionZoomSet(SimpleAction):
def __init__(self, main_window, value):
SimpleAction.__init__(self, ("Zoom = %f" % value))
self.__main_win = main_window
self.__value = value
def do(self):
SimpleAction.do(self)
zoom_liststore = self.__main_win.lists['zoom_levels']['model']
new_idx = -1
for zoom_idx in range(0, len(zoom_liststore)):
if (zoom_liststore[zoom_idx][1] == self.__value):
new_idx = zoom_idx
break
assert(new_idx >= 0)
0,
[
doc.name,
doc,
None,
None,
Gtk.IconSize.DIALOG,
])
path = Gtk.TreePath(0)
self.__main_win.lists['matches']['gui'].select_path(path)
self.__main_win.lists['matches']['gui'].scroll_to_path(
path, False, 0.0, 0.0)
class ActionOpenSelectedDocument(SimpleAction):
"""
Starts a new document.
"""
def __init__(self, main_window):
SimpleAction.__init__(self, "Open selected document")
self.__main_win = main_window
def do(self):
SimpleAction.do(self)
match_list = self.__main_win.lists['matches']['gui']
selection_path = match_list.get_selected_items()
if len(selection_path) <= 0:
logger.info("No document selected. Can't open")
return
doc_idx = selection_path[0].get_indices()[0]
self.__main_win.export['pageFormat']['widget'],
self.__main_win.export['pageFormat']['label'],
]),
]
for (sensitive, widgets) in widgets:
for widget in widgets:
widget.set_sensitive(sensitive)
if exporter.can_change_quality or exporter.can_select_format:
self.__main_win.actions['change_export_property'][1].do()
else:
size_txt = sizeof_fmt(exporter.estimate_size())
self.__main_win.export['estimated_size'].set_text(size_txt)
class ActionChangeExportProperty(SimpleAction):
def __init__(self, main_window):
SimpleAction.__init__(self, "Export property changed")
self.__main_win = main_window
def do(self):
SimpleAction.do(self)
assert(self.__main_win.export['exporter'] is not None)
if self.__main_win.export['exporter'].can_select_format:
page_format_widget = self.__main_win.export['pageFormat']['widget']
format_idx = page_format_widget.get_active()
if (format_idx < 0):
return
page_format_model = self.__main_win.export['pageFormat']['model']
(name, x, y) = page_format_model[format_idx]
self.__main_win.export['exporter'].set_page_format((x, y))
if self.__main_win.export['exporter'].can_change_quality:
SimpleAction.do(self)
check_workdir(self.__config)
if not check_scanner(self.__main_win, self.__config):
return
ms = MultiscanDialog(self.__main_win, self.__config)
ms.connect("need-show-page",
lambda ms_dialog, page:
GObject.idle_add(self.__show_page, page))
def __show_page(self, page):
self.__main_win.refresh_doc_list()
self.__main_win.refresh_page_list()
self.__main_win.show_page(page)
class ActionImport(SimpleAction):
def __init__(self, main_window, config):
SimpleAction.__init__(self, "Import file(s)")
self.__main_win = main_window
self.__config = config
def __select_file(self):
widget_tree = load_uifile("import.glade")
dialog = widget_tree.get_object("filechooserdialog")
dialog.set_local_only(False)
dialog.set_select_multiple(False)
response = dialog.run()
if response != 0:
logger.info("Import: Canceled by user")
dialog.destroy()
return None
def do(self):
SimpleAction.do(self)
zoom_liststore = self.__main_win.lists['zoom_levels']['model']
new_idx = -1
for zoom_idx in range(0, len(zoom_liststore)):
if (zoom_liststore[zoom_idx][1] == self.__value):
new_idx = zoom_idx
break
assert(new_idx >= 0)
self.__main_win.lists['zoom_levels']['gui'].set_active(new_idx)
class ActionEditDoc(SimpleAction):
def __init__(self, main_window, config):
SimpleAction.__init__(self, "Edit doc")
self.__main_win = main_window
self.__config = config
def do(self):
SimpleAction.do(self)
DocEditDialog(self.__main_win, self.__config, self.__main_win.doc[1])
class ActionAbout(SimpleAction):
def __init__(self, main_window):
SimpleAction.__init__(self, "Opening about dialog")
self.__main_win = main_window
def do(self):
self.__main_win.show_doc(doc_idx, doc)
class ActionStartSearch(SimpleAction):
"""
Let the user type keywords to do a document search
"""
def __init__(self, main_window):
SimpleAction.__init__(self, "Focus on search field")
self.__main_win = main_window
def do(self):
self.__main_win.search_field.grab_focus()
class ActionUpdateSearchResults(SimpleAction):
"""
Update search results
"""
def __init__(self, main_window, refresh_pages=True):
SimpleAction.__init__(self, "Update search results")
self.__main_win = main_window
self.__refresh_pages = refresh_pages
def do(self):
SimpleAction.do(self)
self.__main_win.refresh_doc_list()
if self.__refresh_pages:
# Don't call self.__main_win.refresh_page_list():
# it will redo the list from scratch. We just want to update
lambda job, page:
GObject.idle_add(self.__main_win.on_page_editing_ocr_cb,
job, page))
job.connect('page-editing-index-upd',
lambda job, page:
GObject.idle_add(
self.__main_win.on_page_editing_index_upd_cb,
job, page))
job.connect('page-editing-done',
lambda job, page:
GObject.idle_add(self.__main_win.on_page_editing_done_cb,
job, page))
return job
class ActionNewDocument(SimpleAction):
"""
Starts a new document.
"""
def __init__(self, main_window, config):
SimpleAction.__init__(self, "New document")
self.__main_win = main_window
self.__config = config
def do(self):
SimpleAction.do(self)
must_insert_new = False
doclist = self.__main_win.lists['matches']['doclist']
if (len(doclist) <= 0):
must_insert_new = True
if not ask_confirmation(self.__main_win.window):
return
label_list = self.__main_win.lists['labels']['gui']
selection_path = label_list.get_selection().get_selected()
if selection_path[1] is None:
logger.warn("No label selected")
return True
label = selection_path[0].get_value(selection_path[1], 2)
job = self.__main_win.job_factories['label_deleter'].make(
self.__main_win.docsearch, label)
self.__main_win.schedulers['main'].schedule(job)
class ActionOpenDocDir(SimpleAction):
def __init__(self, main_window):
SimpleAction.__init__(self, "Open doc dir")
self.__main_win = main_window
def do(self):
SimpleAction.do(self)
os.system('xdg-open "%s"' % (self.__main_win.doc[1].path))
class ActionPrintDoc(SimpleAction):
def __init__(self, main_window):
SimpleAction.__init__(self, "Open print dialog")
self.__main_win = main_window
def do(self):
SimpleAction.do(self)