JVc@swddlZddlZddlZddlZddlTddlmZddlmZddl m Z dZ idej 6dej 6d ej6d ej6d ej6d ej6Zid ej6dej6dej6dej6dej6dej6dej6ZdZdd!dYZdd"dYZdejfdYZdZ dZ!dZ"ddZ#d Z$dS(#iN(t*(tutils(t to_bytes_utf8(tqueueit TYPE_BOOLtTYPE_INTt TYPE_FIXEDt TYPE_STRINGt TYPE_BUTTONt TYPE_GROUPt UNIT_NONEt UNIT_PIXELtUNIT_BITtUNIT_MMtUNIT_DPIt UNIT_PERCENTtUNIT_MICROSECONDitOptioncBs;eZdZdZdZdZdZdZRS(sNClass representing a SANE option. Attributes: index -- number from 0 to n, giving the option number name -- a string uniquely identifying the option title -- single-line string containing a title for the option desc -- a long string describing the option; useful as a help message type -- type of this option. Possible values: TYPE_BOOL, TYPE_INT, TYPE_STRING, and so forth. unit -- units of this option. Possible values: UNIT_NONE, UNIT_PIXEL, etc. size -- size of the value in bytes cap -- capabilities available; CAP_EMULATED, CAP_SOFT_SELECT, etc. constraint -- constraint on values. Possible values: None : No constraint (min,max,step) Integer values, from min to max, stepping by list of integers or strings: only the listed values are allowed c Csddl}||_|\ |_|_|_|_|_|_|_|_ |_ t|jtdkrt |j|_ndS(Nit( tstringt cur_devicetindextnamettitletdescttypetunittsizetcapt constrainttstr(tselftargsRR((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyt__init__is   <cCstj|jS(N(tscanexttisOptionActiveR(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pytisActivesscCstj|jS(N(R"tisOptionSettableR(R((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyt isSettablevsc Cs|jrd}nd}|jrEd}|jj|j}n d}d}d|j||j|j|jt|j t |j |j ||f S(Ntyestnos s Name: %s Cur value: %s Index: %d Title: %s Desc: %s Type: %s Unit: %s Constr: %s isActive: %s isSettable: %s (R&R$Rt getOptionRRRRtTYPE_STRRtUNIT_STRRRts(RtsettabletactivetcurValue((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyt__repr__ys    cCs|dk r|jdk rt|jtdkr||jdkr||jd}tjd|j|j||fnF||jdkr|jd}tjd|j|j||fn|jj|j|qt|jtgkr||jkr|jd}tj }x@|jD]5}t |||kr%t ||}|}q%q%Wtjd|j|j|dj |j|f|jj|j|qqn|jj |j}|S(Nis6Invalid value for %s (%s < min value of %d). Using %d.is6Invalid value for %s (%s > max value of %d). Using %d.s?Invalid value for %s (%s not in constraint list: %s). Using %d.s, (( tNoneRRtlogtwarnRRt setOptiontsystmaxsizetabstjoinR)(Rtvaluetvtmin_disttx((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyt limitAndSets0        )(t__name__t __module__t__doc__R!R$R&R0R=(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRVs    t ScanDevicecBseZdZdZdZdZdZdZdZdZ dddd Z d Z d Z d Zd ZdZdZdZRS(sClass representing a SANE device. Methods: startScan() -- initiate a scan, using the current settings cancelScan() -- cancel an in-progress scanning operation Also available, but rather low-level: getParameters() -- get the current parameter settings of the device getOptions() -- return a list of tuples describing all the options. Attributes: optlist -- list of option names You can also access an option name to retrieve its value, and to set it. For example, if one option has a .name attribute of imagemode, and scanner is a ScanDevice object, you can do: print scanner.imagemode scanner.imagemode = 'Full frame' scanner.['imagemode'] returns the corresponding Option object. cCs2d|_tj||_i|_|jdS(N(R1t scan_threadR"t openDevicetdevtoptionst_ScanDevice__load_options_dict(RRD((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyR!s  cCs^|j}|jj}x?|D]7}t||}|jtjkr|||jR?R@R!RFR4R)RYRZRGR1R]RoRtRzR\R}RR(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRAs   !       RecBs5eZddddZdZdZdZRS(R[cCstjj|t|_||_||_||_tj dd\|_ |_ t j |j d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_||_d|_dS(Ntprefixthpscansw+biRi(t threadingtThreadR!RfRgRDRlRmRtmake_temp_filet buffer_fdRxRvtfdopenRpR^R_R`RaRbRcRdRqRrRkRs(RtdeviceRkRlRm((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyR!s$              cCs\|jdk rXyt|}Wnttfk r>d}nX|jj||fndS(Ni(RlR1RNt ValueErrort TypeErrortput(RRnt bytes_read((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyt updateQueues  c Cs ddlm}|jj\|_|_|_|_|_|_ |_ t j d|jt j d|jt j d|jt j d|jt j d|jt j d|j t j d |j t j d |j |jj}|j }|jtjkr|j d kr|j d |j|_t j d |jd}|j dkrhd}ny|jj|\}}Wn3tjk r}|jd}|j|dnXx@|tjkr|rt|}|djgtd||jd D]!} || | d |d^q|j|7_|j|||jd 7_|j||jt j d|jn tjdy|jj|\}}Wn7tjk r}|jd}|j||jPnX|jrPqqWqn|jtj kr|j dkr|j |jdd |_t j d |jy|jj|\}}Wn3tjk r}|jd}|j|dnXx;|tjkr|rt|}|djgtd||jD]a} djgddddd dddgD]-} | t!|| | d!@r8dnd^q^q|j|7_|j||jd7_|j||jt j d|jn tjdy|jj|\}}Wn7tjk r}|jd}|j||jPnX|jrPqqWq|j d kr|j |j|_t j d |jy|jj|\}}Wn3tjk r}|jd}|j|dnXx7|tjkr|rft|}|djgtd||jD]} d || | d!d^q|j|7_|j||jd7_|j||jt j d|jn tjdy|jj|\}}Wn7tjk r}|jd}|j||jPnX|jrPqqWqn|jj"dt#|_$t j d dS(!Ni(Rs format=%dsformat_name=%ss last_frame=%dsppl=%dslines=%dsdepth=%dsbpl=%dsbyte_format=%siis pad_bytes=%dtRGBAiiRssColor Read %d bytesg?iii@i iiitssLineart Read %d bytessGray Read %d bytessScan thread exiting...(%t base.sixextRRDRZR^R_R`RaRbRcRdR2tdebugRkRptwriteR"t FRAME_RGBRqtreadScanRMR RtSANE_STATUS_GOODtlenR8trangeRrRsR~Rt checkCancelt FRAME_GRAYtordtseekRiRg( RRtwt readbuffertdirtstRJtstObjtlen_tRtk((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pytruns9     N           I    cCs}t}xp|jjrxyE|jjd}|tkr\t}tjd|jj nWq t j k rtPq Xq W|S(NisCancel pressed!( RiRmtqsizetgettEVENT_SCAN_CANCELEDRfR2RRDt canclScanRtEmpty(Rtcanceledtevent((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRDs   N(R>R?R1R!RRR(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRes ~cCs tjS(N(R"tinit(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRVscCs tjS(N(R"tdeInit(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRZscCs t|S(sOpen a device for scanning(RA(RD((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRC^sicCs tj|S(N(R"t getDevices(t local_only((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyRcscCs$tjdtj||fdS(NsSANE: %s (code=%d)(R2RMR"tgetErrorMessage(tcode((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyt reportErrorgs(((%R"RR~Rvtbase.gtbaseRRRtbase.sixext.movesRRRRRRRR R*R R R R RRRR+t MAX_READSIZERRARReRRRCRR(((sY/builds/ul11u3sru-gate/components/hplip/build/prototype/i386/usr/share/hplip/scan/sane.pyt:s6            }