home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 116
/
FreelogNo116-JuilletSeptembre2013.iso
/
Bureautique
/
gImageReader
/
gimagereader_0.9-1_win32.exe
/
bin
/
gimagereader
/
filelist.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2011-03-24
|
9KB
|
196 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import os
import sys
import gtk
import gobject
import gettext
import dialogs
import re
import tempfile
import shutil
import subprocess
import glob
import urllib
import platform
_ = gettext.gettext
import dialogs
import threadtools
class FileList:
def __init__(self, builder, main):
self.main = main
self.drawingarea = main.get_drawingarea()
self.conf = main.get_config()
self.files = []
self.currentfile = None
self.curdir = os.path.expanduser('~')
self.timeouttag = None
self.builder = builder
self.vbox_filelist = builder.get_object('vbox_filelist')
self.FileList = builder.get_object('fileList')
self.tb_remove_image = builder.get_object('tb_remove_image')
self.tb_clear_filelist = builder.get_object('tb_clear_filelist')
self.window = self.builder.get_object('main')
self.status = self.builder.get_object('status_msg')
self.image_open_dialog = dialogs.image_open_dialog(self.window)
self.menu_toggle_sources = builder.get_object('menu_toggle_sources')
self.notebook_sources = builder.get_object('notebook_sources')
self.FileStore = gtk.ListStore(str, str)
self.FileList.set_model(self.FileStore)
column = gtk.TreeViewColumn(_('Images'), gtk.CellRendererText(), text = 0)
column.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
column.set_sort_column_id(0)
self.FileList.append_column(column)
self.FileStore.set_sort_column_id(0, gtk.SORT_ASCENDING)
self.FileList.set_headers_clickable(True)
self.FileList.set_property('rules-hint', True)
self.tb_remove_image.set_sensitive(False)
self.tb_clear_filelist.set_sensitive(False)
recentfilter = gtk.RecentFilter()
recentfilter.add_pixbuf_formats()
recentfilter.add_mime_type('application/pdf')
recentfilter.add_pattern('*.pdf')
recentchooser = gtk.RecentChooserMenu()
recentchooser.set_local_only(False)
recentchooser.set_show_not_found(False)
recentchooser.set_show_tips(True)
recentchooser.set_sort_type(gtk.RECENT_SORT_MRU)
recentchooser.set_show_icons(platform.system() != 'Windows')
recentchooser.add_filter(recentfilter)
self.builder.get_object('menu_recent').set_submenu(recentchooser)
builder.get_object('tb_openimg').connect('clicked', self.open_images)
builder.get_object('menu_open').connect('activate', self.open_images)
builder.get_object('tb_add_image').connect('clicked', self.open_images)
self.FileList.get_selection().connect('changed', self._FileList__on_entry_selected)
self.tb_remove_image.connect('clicked', self.remove_image)
self.tb_clear_filelist.connect('clicked', self.clear)
recentchooser.connect(('item-activated',), (lambda w: self.open_images(None, [
urllib.url2pathname(w.get_current_uri()[7:])])))
def __on_entry_selected(self, widget):
''' Called when an entry in the list is selected. '''
selection = self.FileList.get_selection()
(model, iter) = selection.get_selected()
if iter == None or not self.FileStore.iter_is_valid(iter):
return None
if None.FileStore.get_value(iter, 1) != self.currentfile:
self._FileList__load_image(self.FileStore.get_value(iter, 1))
self.tb_remove_image.set_sensitive(True)
def suggest_output(self):
''' Suggest an output file for the recognized text based on the current file. '''
return os.path.splitext(self.currentfile)[0] + '.txt'
def show(self):
''' Shows the filelist in the left pane. '''
self.menu_toggle_sources.set_active(True)
self.notebook_sources.set_current_page(0)
def clear(self, widget = None):
''' Clears the filelist. '''
self.FileStore.clear()
self.tb_remove_image.set_sensitive(False)
self.tb_clear_filelist.set_sensitive(False)
self.main.set_status(_('Select an image to begin...'))
self.window.set_title('gImageReader')
for obj in ('tb_zoomin', 'tb_zoomout', 'tb_resetzoom', 'tb_rrotate', 'tb_lrotate', 'menu_zoomin', 'menu_zoomout', 'menu_resetzoom', 'menu_rrotate', 'menu_lrotate', 'tb_doocr', 'toolbar_controls'):
self.builder.get_object(obj).set_sensitive(False)
self.drawingarea.clear_image()
self.currentfile = None
self.files = []
def remove_image(self, widget = None):
''' Removes the currently selected item from the filelist. '''
selection = self.FileList.get_selection()
(model, iter) = selection.get_selected()
path = int(model.get_string_from_iter(iter))
if path - 1 >= 0:
i = model.get_iter_from_string(str(path - 1))
self._FileList__load_image(self.FileStore.get_value(i, 1))
selection.select_path(path - 1)
elif path + 1 < len(model):
i = model.get_iter_from_string(str(path + 1))
self._FileList__load_image(self.FileStore.get_value(i, 1))
selection.select_path(path + 1)
else:
self.clear()
return None
None.files.remove(self.FileStore.get_value(iter, 1))
self.FileStore.remove(iter)
def open_images(self, widget = None, files = None):
''' Opens the specified files. '''
if files == None:
files = self.image_open_dialog.run(self.curdir)
if not files:
return None
files = [ os.path.abspath(file) for file in files ]
newfiles = []
badfiles = []
for item in files:
if not os.path.isfile(item):
badfiles.append(item)
continue
if item not in self.files:
newfiles.append(item)
continue
if badfiles:
dialogs.error_dialog(_('Unable to open files'), _('Following files could not be opened:\n%s') % '\n'.join(badfiles))
for item in newfiles:
gtk.recent_manager_get_default().add_item('file:' + urllib.pathname2url(item))
if not newfiles:
if self.currentfile in files:
self._FileList__load_image(self.currentfile)
return None
None.files += newfiles
self.FileList.get_selection().select_iter(self.FileStore.append((newfiles[0].rsplit(os.sep)[-1], newfiles[0])))
for file in newfiles[1:]:
self.FileStore.append((file.rsplit(os.sep)[-1], file))
self.tb_clear_filelist.set_sensitive(True)
if len(self.files) > 1:
self.show()
def __load_image(self, filename):
''' Loads the specified file in the drawingarea. '''
if self.timeouttag != None:
return None
self.currentfile = None
threadtools.SubprocessThread(self.drawingarea.set_image, self._FileList__load_image_done, self.currentfile).start()
self.timeouttag = gobject.timeout_add(500, self.main.set_busy, True, _("Loading '%s'...") % self.currentfile)
def __load_image_done(self, result):
''' Called when the image has finished loading. '''
try:
gobject.source_remove(self.timeouttag)
except:
pass
self.timeouttag = None
self.main.set_busy(False)
if result == False:
dialogs.error_dialog(_('Failed to load image'), _('The file might not be an image or be corrupted.'), self.window)
return None
self.curdir = None.path.dirname(self.currentfile)
self.window.set_title(os.path.basename(self.currentfile) + ' - gImageReader')
for obj in ('tb_zoomin', 'tb_zoomout', 'tb_resetzoom', 'tb_rrotate', 'tb_lrotate', 'menu_zoomin', 'menu_zoomout', 'menu_resetzoom', 'menu_rrotate', 'menu_lrotate', 'tb_doocr', 'toolbar_controls'):
self.builder.get_object(obj).set_sensitive(True)
self.main.set_status(_('To recognize a specific area, drag a rectangle over it.'))