/usr/share/pyshared/Eikazo/devices/fujitsu.py is in eikazo 0.5.2-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | """
Copyright (c) Abel Deuring 2006 <adeuring@gmx.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
device plugin for the Fujitsu fi-5120/5220. Should also be
useful for the f1-4120/4220
"""
import time
import sane, gtk
from Eikazo import Widgets, SaneThread, Config, I18n, Plugins
# FIXME: may be reasonable to use domain sane-backends too
t = I18n.get_translation('eikazo')
if t:
_ = t.gettext
else:
_ = lambda x: x
class FujitsuCapStatus:
def widgets(self, device, mainwidget, config):
_plugin_info.details = """\
Special functions for Fujitsu fi-4120, fi-4220, fi-5120, fi-5220
(used)"""
return [('status', 'gtksane_status', FujitsuStatusBox(device, mainwidget))]
class FujitsuStatusBox(gtk.Frame):
def __init__(self, device, actionwidget):
gtk.Frame.__init__(self, label="Scanner status")
self.device = device
tbl = gtk.Table(2,2)
self.add(tbl)
tbl.set_col_spacing(0,6)
tbl.show()
lbl = gtk.Label("ADF")
tbl.attach(lbl, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0)
lbl.set_alignment(0, 0.5)
lbl.show()
lbl = gtk.Label("Hardware")
tbl.attach(lbl, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0)
lbl.set_alignment(0, 0.5)
lbl.show()
self.adfstat = gtk.Label()
tbl.attach(self.adfstat, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0)
self.adfstat.set_alignment(0, 0.5)
self.adfstat.show()
self.adfstat.set_justify(gtk.JUSTIFY_LEFT)
self.hwstat = gtk.Label()
tbl.attach(self.hwstat, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0)
self.hwstat.set_alignment(0, 0.5)
self.hwstat.show()
self.hwstat.set_justify(gtk.JUSTIFY_LEFT)
self.update()
FujitsuPollStatus(device, self, actionwidget).start()
_hwtext = {0x00: 'OK',
0x01: 'Booting',
0x10: 'Shipping lock',
0x4a: 'Imprinter cover open',
0x55: 'Multifeed detected: overlapping paper',
0x56: 'Multifeed detected: paper length',
0x5a: 'Imprinter paper jam',
0x74: 'AGC control failure (ADF front)',
0x75: 'AGC control failure (ADF back)',
0x7e: 'AGC control failure (flatbed)',
0x84: 'Lamp fuse blown',
0x87: 'FB motor cannot move',
0xb1: 'Imprinter fuse error (scanner fuse)',
0xb2: 'Imprinter control board error',
0xb3: 'Imprinter communication timeout error',
0xb4: 'Imprinter ink cartidge uninstalled',
0xb5: 'Imprinter head error',
0xb6: 'Imprinter EEPROM error',
0xb7: 'Imprinter cover motor error or sensor error',
0xb8: 'Imprinter ROM error',
0xb9: 'Imprinter paper detection error or printing range error',
0xc2: 'Front side background changeover unit error',
0xc3: 'Back side background changeover unit error',
}
def update(self):
dev = self.device._device
if dev.button_doublefeed:
self.adfstat.set_markup('<span background="#FF0000">double feed detected (1)</span>')
elif dev.button_omrdf:
self.adfstat.set_markup('<span background="#FF0000">double feed detected (2)</span>')
elif dev.button_adfopen:
self.adfstat.set_label("ADF cover open")
elif dev.button_adfloaded:
self.adfstat.set_label("ADF loaded")
else:
self.adfstat.set_label("ADF empty")
hwstat = dev.button_errorcode
if hwstat in self._hwtext.keys():
self.hwstat.set_label(self._hwtext[hwstat])
else:
self.hwstat.set_label('Unknown status code: %02x' % hwstat)
class FujitsuPollStatus(SaneThread.Thread):
def __init__(self, device, statuswidget, mainwidget):
self.device = device
self.statuswidget = statuswidget
self.mainwidget = mainwidget
self.scan_callback = None
SaneThread.Thread.__init__(self)
def run(self):
device = self.device
statuswidget = self.statuswidget
mainwidget = self.mainwidget
while not self.abort:
if device._devicelock.acquire(0):
try:
gtk.gdk.threads_enter()
try:
statuswidget.update()
scanstart = device._device.button_scan
if scanstart:
mainwidget.do_scan(None)
finally:
gtk.gdk.threads_leave()
finally:
device._devicelock.release()
# the fujitsu backend polls the scanner at most once per second,
# so it is pointless to ask more often here
time.sleep(1)
class FujitsuCapOverscan:
def widgets(self, device, mainwidget, config):
ctrl = FujitsuOverscanController(device, config)
ctrl.setWidthWidgets([FujitsuPageScale(ctrl, config, True),
FujitsuPageNumField(ctrl, config, True)])
ctrl.setHeightWidgets([FujitsuPageScale(ctrl, config, False),
FujitsuPageNumField(ctrl, config, False)])
ctrl.setOverscanButton(FujitsuOverscanButton(ctrl))
return [('pagewidth', 'main', ctrl.getWidthWidgets()),
('pageheight', 'main', ctrl.getHeightWidgets()),
('overscan', 'main', ctrl.getOverscanButton()),
]
class FujitsuOverscanController(Config.ConfigAware):
def __init__(self, device, config):
self.device = device
# overscan mode. start: off
self.overscan = False
Config.ConfigAware.__init__(self, config)
def readConfig(self):
val = self.config.getboolean('device', 'fujitsu-overscan')
if val != None:
self.overscanWidget.set_active(val)
self.set_overscan(self.overscanWidget)
def writeConfig(self):
val = self.overscanWidget.get_active()
self.config.set('device', 'fujitsu-overscan', str(val))
def setWidthWidgets(self, widgets):
self.widthWidgets = widgets
for w in widgets:
self.device._registerWidget('pagewidth', w)
def getWidthWidgets(self):
return self.widthWidgets
def setHeightWidgets(self, widgets):
self.heightWidgets = widgets
for w in widgets:
self.device._registerWidget('pageheight', w)
def getHeightWidgets(self):
return self.heightWidgets
def setOverscanButton(self, widget):
self.overscanWidget = widget
def getOverscanButton(self):
return [self.overscanWidget]
def set_overscan(self, button):
active = self.overscan = button.get_active()
self.device._device.overscan = active
for name in ('tl_x', 'tl_y', 'br_x', 'br_y'):
wlist = self.device.widgets(name)
for w in wlist:
if active:
w.hide()
else:
w.show()
if active:
self.adjust_scansize()
def adjust_scansize(self):
""" in overscan mode, adjust the scan window to the
paper size.
"""
if self.overscan:
self.device.tl_x = 0
self.device.tl_y = 0
self.device.br_x = self.device._device.pagewidth + 32
self.device.br_y = self.device._device.pageheight + 32
for name in ('tl_x', 'tl_y', 'br_x', 'br_y'):
wlist = self.device.widgets(name)
for w in wlist:
w.Reload()
d = self.device
class xxxFujitsuPageSizeWidget(gtk.VBox):
def __init__(self, ctrl, config, width):
gtk.VBox.__init__(self)
self.ctrl = ctrl
if width:
label = gtk.Label("Page Width")
wh = "pagewidth"
else:
label = gtk.Label("Page Height")
wh = "pageheight"
self.add(label)
label.show()
self.scale = FujitsuPageScale(ctrl, config, wh)
self.add(self.scale)
self.scale.show()
self.textfield = FujitsuPageNumField(ctrl, config, wh)
self.add(self.textfield)
self.textfield.show()
def Reload(self):
self.scale.Reload()
self.textfield.Reload()
def enable_option(self, value):
self.scale.enable_option(value)
self.textfield.enable_option(value)
class FujitsuPageScale(Widgets.HScale):
def __init__(self, ctrl, config, wh):
if wh:
optname = 'pagewidth'
else:
optname = 'pageheight'
Widgets.HScale.__init__(self, optname, ctrl.device, config)
self.ctrl = ctrl
self.set_draw_value(False)
def ChangeDeviceValue(self):
Widgets.HScale.ChangeDeviceValue(self)
self.ctrl.adjust_scansize()
class FujitsuPageNumField(Widgets.NumberField):
def __init__(self, ctrl, config, wh):
if wh:
optname = 'pagewidth'
else:
optname = 'pageheight'
Widgets.NumberField.__init__(self, optname, ctrl.device, config)
self.ctrl = ctrl
def ChangeDeviceValue(self):
Widgets.NumberField.ChangeDeviceValue(self)
self.ctrl.adjust_scansize()
class FujitsuOverscanButton(gtk.CheckButton):
def __init__(self, ctrl):
self.ctrl = ctrl
gtk.Button.__init__(self, label="Overscan Mode")
self.connect("toggled", ctrl.set_overscan)
self.tLabel = None
def titleWidget(self):
if not self.tLabel:
self.tLabel = gtk.Label(_('Overscan'))
return self.tLabel
def show(self):
self.tLabel.show()
gtk.CheckButton.show(self)
def hide(self):
self.tLabel.hide()
gtk.CheckButton.hide(self)
_vendors = ['FUJITSU']
_models = ['fi-5120', 'fi-5220', 'fi-4120', 'fi-4220']
_fi4120_5220 = [
# What does this option mean??
{'name': 'button_topedge',
'type': 'info',
'usage': None,
'widget': None,
},
# paper size info is not implemented for these devices
{'name': 'button_a3',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'button_b4',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'button_a4',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'button_b5',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'button_adfloaded',
'type': 'info',
'usage': None, # in FujitsuStatusBox
'widget': None
},
{'name': 'button_omrdf',
'type': 'info',
'usage': None, # in FujitsuStatusBox
'widget': None
},
{'name': 'button_adfopen',
'type': 'info',
'usage': None, # in FujitsuStatusBox
'widget': None
},
# really not that important for a GUI...
{'name': 'button_powersave',
'type': 'info',
'usage': None,
'widget': None
},
# somwhat arbitrary to choose "copy". But sending emails
# (if this is it, what is intended for by Fujitsu)
# seems to be a bit pointless for a quite fast ADF scanner
{'name': 'button_send',
'type': 'button',
'usage': 'copy',
'widget': None
},
{'name': 'button_manualfeed',
'type': 'button',
'usage': None,
'widget': None
},
{'name': 'button_scan',
'type': 'button',
'usage': 'scan',
'widget': None
},
{'name': 'button_function',
'type': 'selection',
'usage': None, # not very useful as a simple display
'widget': None
},
# FIXME: this one is tricky. We don't know, if an imprinter is
# installed. Would depend on some other option. For now, let's
# simply disable the option. The backend has anyway not yet (June 2006)
# an option to define the text to be printed.
{'name': 'button_inklow',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'button_doublefeed',
'type': 'info',
'usage': None, # in FujitsuStatusBox
'widget': None
},
{'name': 'button_errorcode',
'type': 'info',
'usage': None, # in FujitsuStatusBox
'widget': None
},
# not available
{'name': 'button_skewangle',
'type': 'info',
'usage': None,
'widget': None
},
# see above: when to display?
{'name': 'button_inkremain',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'button_density',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'button_duplex',
'type': 'info',
'usage': None,
'widget': None
},
{'name': 'overscan',
'type': 'cap',
'usage': FujitsuCapOverscan,
'widget': None
},
{'name': 'status',
'type': 'cap',
'usage': FujitsuCapStatus,
'widget': None
},
]
class Fujitsu:
def vendor_names(self):
return _vendors
def model_names(self):
return _models
def options(self, devicename):
devs = sane.get_devices()
for dev in devs:
if dev[0] == devicename:
if dev[1] in _vendors and \
[x for x in _models if dev[2].find(x)==0]:
return _fi4120_5220
return None
_plugin_info = Plugins.Plugin('fujitsu',
"""Special functions for Fujitsu fi-4120, fi-4220, fi-5120, fi-5220
(not used)""",
'device', None)
def register():
return (Fujitsu, )
|