1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
Description: Pop up a message when no scanner is present
This is instead of exiting/failing with an exception.
Author: Oron Peled <oron@actcom.co.il>
Origin: https://bugzilla.redhat.com/show_bug.cgi?id=574259
--- a/examples/hocr-gtk/sane-pygtk
+++ b/examples/hocr-gtk/sane-pygtk
@@ -39,14 +39,14 @@
# set gettext support
locale_dir = '/usr/share/locale'
-try:
- import locale
- import gettext
- locale.setlocale(locale.LC_ALL, "")
- gtk.glade.bindtextdomain(app_name, locale_dir)
- gettext.install(app_name, locale_dir, unicode=1)
+try:
+ import locale
+ import gettext
+ locale.setlocale(locale.LC_ALL, "")
+ gtk.glade.bindtextdomain(app_name, locale_dir)
+ gettext.install(app_name, locale_dir, unicode=1)
except (IOError,locale.Error), e:
- print "WARNING: Can't load locale"
+ print "WARNING: Can't load locale"
_ = lambda x : x
# set global functions
@@ -152,7 +152,6 @@
# get scanners in system
self.sane_devices = sane.get_devices()
- self.sane_devices_counter = len(self.sane_devices)
# set the scanners combobox
for device in self.sane_devices:
@@ -205,13 +204,22 @@
dialog.destroy()
- def button_preview_clicked_cb(self, obj):
- "button_preview_clicked_cb activated"
-
+ def open_scanner(self):
+ if len(self.sane_devices) <= 0:
+ show_error_message(_("No scanners reported by sane"))
+ raise RuntimeError("No scanners reported by sane\nRecheck your sane configuration")
# open scanner
scanner_number = self.config.getint('settings', 'scanner') - 1
+ if scanner_number < 0 or scanner_number >= len(self.sane_devices):
+ show_error_message(_("Bad scanner number %d configured.\nPlease select a valid scanner from the list") % scanner_number)
+ raise RuntimeError("Invalid scanner %d" % scanner_number)
scanner = sane.open(self.sane_devices[scanner_number][0])
-
+ return scanner
+
+ def button_preview_clicked_cb(self, obj):
+ "button_preview_clicked_cb activated"
+ # open scanner
+ scanner = self.open_scanner()
# options
options = get_scanner_option (scanner, 'mode')
if options:
@@ -278,9 +286,7 @@
def button_scan_clicked_cb(self, obj):
"button_scan_clicked_cb activated"
# open scanner
- scanner_number = self.config.getint('settings', 'scanner') - 1
- scanner = sane.open(self.sane_devices[scanner_number][0])
-
+ scanner = self.open_scanner()
# options
options = get_scanner_option (scanner, 'mode')
if options:
@@ -529,7 +535,7 @@
# reset settings options
if scanner_number < len(self.sane_devices):
try:
- scanner = sane.open(self.sane_devices[scanner_number][0])
+ scanner = self.open_scanner()
# if scanner exist fill in all the settings
|