home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.5)
-
- from __future__ import generators
- import sys
- import os
- import os.path as os
- import mmap
- import struct
- import time
- import threading
- import Queue
- import socket
- from cStringIO import StringIO
- from base.g import *
- from base.codes import *
- from base import device, utils, status, pml, msg
- COPY_CANCELED = 1
- STATUS_IDLE = 0
- STATUS_SETTING_UP = 1
- STATUS_WARMING_UP = 2
- STATUS_ACTIVE = 3
- STATUS_DONE = 4
- STATUS_ERROR = 5
-
- class PMLCopyDevice(device.Device):
-
- def __init__(self, device_uri = None, printer_name = None, hpssd_sock = None, hpiod_sock = None, callback = None):
- device.Device.__init__(self, device_uri, printer_name, hpssd_sock, hpiod_sock, callback)
- self.copy_thread = None
-
-
- def copy(self, num_copies = 1, contrast = 0, reduction = 100, quality = pml.COPIER_QUALITY_NORMAL, fit_to_page = pml.COPIER_FIT_TO_PAGE_ENABLED, scan_style = SCAN_STYLE_FLATBED, update_queue = None, event_queue = None):
- if not self.isCopyActive():
- self.copy_thread = PMLCopyThread(self, num_copies, contrast, reduction, quality, fit_to_page, scan_style, update_queue, event_queue)
- self.copy_thread.start()
- return True
- else:
- return False
-
-
- def isCopyActive(self):
- if self.copy_thread is not None:
- return self.copy_thread.isAlive()
- else:
- return False
-
-
- def waitForCopyThread(self):
- if self.copy_thread is not None and self.copy_thread.isAlive():
- self.copy_thread.join()
-
-
-
-
- class PMLCopyThread(threading.Thread):
-
- def __init__(self, dev, num_copies, contrast, reduction, quality, fit_to_page, scan_style, update_queue = None, event_queue = None):
- threading.Thread.__init__(self)
- self.dev = dev
- self.num_copies = num_copies
- self.contrast = contrast
- self.reduction = reduction
- self.quality = quality
- self.fit_to_page = fit_to_page
- self.scan_style = scan_style
- self.event_queue = event_queue
- self.update_queue = update_queue
- self.prev_update = ''
- self.copy_type = self.dev.copy_type
- log.debug('Copy-type = %d' % self.copy_type)
-
-
- def run(self):
- STATE_DONE = 0
- STATE_ERROR = 5
- STATE_ABORTED = 10
- STATE_SUCCESS = 20
- STATE_BUSY = 25
- STATE_SET_TOKEN = 30
- STATE_SETUP_STATE = 40
- STATE_SETUP_PARAMS = 50
- STATE_START = 60
- STATE_ACTIVE = 70
- STATE_RESET_TOKEN = 80
- state = STATE_SET_TOKEN
- while state != STATE_DONE:
- if self.check_for_cancel():
- state = STATE_ABORTED
-
- if state == STATE_ABORTED:
- log.debug('%s State: Aborted' % '********************')
- self.write_queue(STATUS_ERROR)
- state = STATE_RESET_TOKEN
-
- if state == STATE_ERROR:
- log.debug('%s State: Error' % '********************')
- self.write_queue(STATUS_ERROR)
- state = STATE_RESET_TOKEN
- continue
- if state == STATE_SUCCESS:
- log.debug('%s State: Success' % '********************')
- self.write_queue(STATUS_DONE)
- state = STATE_RESET_TOKEN
- continue
- if state == STATE_BUSY:
- log.debug('%s State: Busy' % '********************')
- self.write_queue(STATUS_ERROR)
- state = STATE_RESET_TOKEN
- continue
- if state == STATE_SET_TOKEN:
- log.debug('%s State: Acquire copy token' % '********************')
- self.write_queue(STATUS_SETTING_UP)
-
- try:
- (result_code, token) = self.dev.getPML(pml.OID_COPIER_TOKEN)
- except Error:
- log.debug('Unable to acquire copy token (1).')
- state = STATE_SETUP_STATE
-
- None if result_code > pml.ERROR_MAX_OK else check_token == token
- if state == STATE_SETUP_STATE:
- log.debug('%s State: Setup state' % '********************')
- if self.copy_type == COPY_TYPE_DEVICE:
- (result_code, copy_state) = self.dev.getPML(pml.OID_COPIER_JOB)
- if copy_state == pml.COPIER_JOB_IDLE:
- self.dev.setPML(pml.OID_COPIER_JOB, pml.COPIER_JOB_SETUP)
- state = STATE_SETUP_PARAMS
- else:
- state = STATE_BUSY
- elif self.copy_type == COPY_TYPE_AIO_DEVICE:
- (result_code, copy_state) = self.dev.getPML(pml.OID_SCAN_TO_PRINTER)
- if copy_state == pml.SCAN_TO_PRINTER_IDLE:
- state = STATE_SETUP_PARAMS
- else:
- state = STATE_BUSY
-
- self.copy_type == COPY_TYPE_DEVICE
- if state == STATE_SETUP_PARAMS:
- log.debug('%s State: Setup Params' % '********************')
- if self.num_copies < 0:
- self.num_copies = 1
-
- if self.num_copies > 99:
- self.num_copies = 99
-
- if self.copy_type == COPY_TYPE_DEVICE:
- self.dev.setPML(pml.OID_COPIER_JOB_NUM_COPIES, self.num_copies)
- self.dev.setPML(pml.OID_COPIER_JOB_CONTRAST, self.contrast)
- self.dev.setPML(pml.OID_COPIER_JOB_REDUCTION, self.reduction)
- self.dev.setPML(pml.OID_COPIER_JOB_QUALITY, self.quality)
- if self.scan_style == SCAN_STYLE_FLATBED:
- self.dev.setPML(pml.OID_COPIER_JOB_FIT_TO_PAGE, self.fit_to_page)
-
- else:
- self.dev.setPML(pml.OID_COPIER_NUM_COPIES_AIO, self.num_copies)
- self.contrast = self.contrast * 10 / 25 + 50
- self.dev.setPML(pml.OID_COPIER_CONTRAST_AIO, self.contrast)
- if self.fit_to_page == pml.COPIER_FIT_TO_PAGE_ENABLED:
- self.reduction = 0
-
- self.dev.setPML(pml.OID_COPIER_REDUCTION_AIO, self.reduction)
- self.dev.setPML(pml.OID_COPIER_QUALITY_AIO, self.quality)
- self.dev.setPML(pml.OID_PIXEL_DATA_TYPE, pml.PIXEL_DATA_TYPE_COLOR_24_BIT)
- self.dev.setPML(pml.OID_COPIER_SPECIAL_FEATURES, pml.COPY_FEATURE_NONE)
- self.dev.setPML(pml.OID_COPIER_PHOTO_MODE, pml.ENHANCE_LIGHT_COLORS | pml.ENHANCE_TEXT)
- self.dev.setPML(pml.OID_COPIER_JOB_INPUT_TRAY_SELECT, pml.COPIER_JOB_INPUT_TRAY_1)
- self.dev.setPML(pml.OID_COPIER_MEDIA_TYPE, pml.COPIER_MEDIA_TYPE_AUTOMATIC)
- self.dev.setPML(pml.OID_PIXEL_DATA_TYPE, pml.PIXEL_DATA_TYPE_COLOR_24_BIT)
- self.dev.setPML(pml.OID_COPIER_SPECIAL_FEATURES, pml.COPY_FEATURE_NONE)
- self.dev.setPML(pml.OID_COPIER_JOB_MEDIA_SIZE, pml.COPIER_JOB_MEDIA_SIZE_US_LETTER)
- log.debug('num_copies = %d' % self.num_copies)
- log.debug('contrast= %d' % self.contrast)
- log.debug('reduction = %d' % self.reduction)
- log.debug('quality = %d' % self.quality)
- log.debug('fit_to_page = %d' % self.fit_to_page)
- state = STATE_START
- continue
- if state == STATE_START:
- log.debug('%s State: Start' % '********************')
- if self.copy_type == COPY_TYPE_DEVICE:
- self.dev.setPML(pml.OID_COPIER_JOB, pml.COPIER_JOB_START)
- elif self.copy_type == COPY_TYPE_AIO_DEVICE:
- self.dev.setPML(pml.OID_SCAN_TO_PRINTER, pml.SCAN_TO_PRINTER_START)
-
- state = STATE_ACTIVE
- continue
- if state == STATE_ACTIVE:
- log.debug('%s State: Active' % '********************')
- if self.copy_type == COPY_TYPE_DEVICE:
- while True:
- (result_code, copy_state) = self.dev.getPML(pml.OID_COPIER_JOB)
- if self.check_for_cancel():
- self.dev.setPML(pml.OID_COPIER_JOB, pml.COPIER_JOB_IDLE)
- state = STATE_ABORTED
- break
-
- if copy_state == pml.COPIER_JOB_START:
- log.debug('state = start')
- time.sleep(1)
- continue
-
- if copy_state == pml.COPIER_JOB_ACTIVE:
- self.write_queue(STATUS_ACTIVE)
- log.debug('state = active')
- time.sleep(2)
- continue
- continue
- if copy_state == pml.COPIER_JOB_ABORTING:
- log.debug('state = aborting')
- state = STATE_ABORTED
- break
- continue
- if copy_state == pml.COPIER_JOB_IDLE:
- log.debug('state = idle')
- state = STATE_SUCCESS
- break
- continue
- elif self.copy_type == COPY_TYPE_AIO_DEVICE:
- while True:
- (result_code, copy_state) = self.dev.getPML(pml.OID_SCAN_TO_PRINTER)
- if self.check_for_cancel():
- self.dev.setPML(pml.OID_SCAN_TO_PRINTER, pml.SCAN_TO_PRINTER_IDLE)
- state = STATE_ABORTED
- break
-
- if copy_state == pml.SCAN_TO_PRINTER_START:
- log.debug('state = start')
- time.sleep(1)
- continue
-
- if copy_state == pml.SCAN_TO_PRINTER_ACTIVE:
- self.write_queue(STATUS_ACTIVE)
- log.debug('state = active')
- time.sleep(2)
- continue
- continue
- if copy_state == pml.SCAN_TO_PRINTER_ABORTED:
- log.debug('state = aborting')
- state = STATE_ABORTED
- break
- continue
- if copy_state == pml.SCAN_TO_PRINTER_IDLE:
- log.debug('state = idle')
- state = STATE_SUCCESS
- break
- continue
-
- self.copy_type == COPY_TYPE_DEVICE
- if state == STATE_RESET_TOKEN:
- log.debug('%s State: Release copy token' % '********************')
-
- try:
- self.dev.setPML(pml.OID_COPIER_TOKEN, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
- except Error:
- log.error('Unable to release copier token.')
-
- state = STATE_DONE
- continue
-
-
- def check_for_cancel(self):
- canceled = False
- while self.event_queue.qsize():
-
- try:
- event = self.event_queue.get(0)
- if event == COPY_CANCELED:
- canceled = True
- log.debug('Cancel pressed!')
- continue
- except Queue.Empty:
- break
- continue
-
-
- None<EXCEPTION MATCH>Queue.Empty
- return canceled
-
-
- def write_queue(self, message):
- if self.update_queue is not None and message != self.prev_update:
- self.update_queue.put(message)
- time.sleep(0)
- self.prev_update = message
-
-
-
-