
    =	f                         d dl  d dlmZmZ d dlmZ d dl ddl d dl d dl	 d dl
 ddlmZ ddlmZmZ ddlmZ d dlZd dlZd ZdZdZ G d	 d
ee      Zy)    )*)deviceutils)cups   )	Ui_Dialog)	FileTableFILETABLE_TYPE_PRINT)%PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLYNc                   p    e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd ZddZy)PrintDialogNc                    t         j                  | |       | j                  |        || _        t	               | _        | j
                  j                          | j
                  j                          | j                          g | _	        |?|D ]:  }| j                  j                  t        j                  j                  |             < i | _        t         j#                  d| j$                         y )Nr   )QDialog__init__setupUiprinter_nameUserSettingsuser_settingsloaddebuginitUi	file_listFilesaddFileFromUIospathabspathdevicesQTimer
singleShotupdateFilePage)selfparentr   argsas        #/usr/share/hplip/ui5/printdialog.pyr   zPrintDialog.__init__4   s    v&T( *^!  " =

(();<=  	!T001    c                    d| j                   _        | j                  j                  j	                  | j
                         | j                  j                  j	                  | j                         | j                  j                  j	                  | j                         t        j                  t        j                  t        j                         | j                          | j                          | j                  t!        t#        dd                   | j$                  r%| j&                  j)                  | j$                         | j*                  j-                  d       y )NThp_logo128x128r   )OptionsToolBoxinclude_job_optionsCancelButtonclickedconnectCancelButton_clicked
BackButtonBackButton_clicked
NextButtonNextButton_clickedsignalSIGINTSIG_DFLinitFilePageinitOptionsPagesetWindowIconQIconload_pixmapr   PrinterNamesetInitialPrinterStackedWidgetsetCurrentIndexr"   s    r&   r   zPrintDialog.initUiL   s    26/ 	!!))$*C*CD''(?(?@''(?(?@fmmV^^4 	5Y	!BCD..t/@/@A**1-r'   c                 \   | j                   j                  t               | j                   j                  | j                  j
                         | j                   j                  j                  | j                         | j                   j                  j                  | j                         y N)r   setTyper
   setWorkingDirr   working_dirisEmptyr/   Files_isEmpty	isNotEmptFiles_isNotEmptyrA   s    r&   r8   zPrintDialog.initFilePagee   so    

/0

  !3!3!?!?@

""4#5#56

$$T%:%:;r'   c                 R   | j                   j                  | j                  d             | j                   j                  | j                  j                                | j                  j                  d       | j                  t               | j                  j                          y )NzNext >F)
r3   setText_PrintDialog__tr
setEnabledr   
isNotEmptyr1   updateStepText	PAGE_FILEupdateUirA   s    r&   r!   zPrintDialog.updateFilePagem   sl    		( 34""4::#8#8#:;""5)I&

r'   c                 :    | j                   j                  d       y )NFr3   rN   rA   s    r&   rH   zPrintDialog.Files_isEmptyt   s    ""5)r'   c                 :    | j                   j                  d       y NTrT   rA   s    r&   rJ   zPrintDialog.Files_isNotEmptyx   s    ""4(r'   c                 4   | j                   j                  d       | j                  j                  t               | j                  j
                  j                  | j
                         | j                  j                  j                  | j                         y rV   )r1   rN   r=   rD   r   "PrinterNameComboBox_currentChangedr/   PrinterNameComboBox_noPrintersrA   s    r&   r9   zPrintDialog.initOptionsPage   si    ""4(  !FG;;CCDDkDkl77??@c@cdr'   c                 D   t         j                  t        t        j                               	 | j
                  j                          | j                  j                  d       t        | j                  j                        }|dkD  r.| j                  j                  | j                  d|z               n*| j                  j                  | j                  d             | j                  t                t         j#                          y # t         j#                          w xY w)NTr   zPrint %s Filesz
Print File)QApplicationsetOverrideCursorQCursorQt
WaitCursorr=   rR   r1   rN   lenr   r   r3   rL   rM   rP   PAGE_OPTIONSrestoreOverrideCursor)r"   	num_filess     r&   updateOptionsPagezPrintDialog.updateOptionsPage   s    &&wr}}'=>	1%%'OO&&t,DJJ001IA''		2B92L(MN''		,(?@- ..0L..0s   CD	 	Dc                     	 | j                   |    | j                  j                  | j                   |   |       y # t        $ r% t        j                  |      | j                   |<   Y Ww xY wrC   )r   KeyErrorr   Devicer+   rR   )r"   
device_urir   s      r&   rX   z.PrintDialog.PrinterNameComboBox_currentChanged   s_    	ALL$ 	$$T\\*%=|L  	A'-}}Z'@DLL$	As   ; +A)(A)c                 Z    t        | | j                  d             | j                          y )NzA<b>No printers found.</b><p>Please setup a printer and try again.)	FailureUIrM   closerA   s    r&   rY   z*PrintDialog.PrinterNameComboBox_noPrinters   s    $		"efg

r'   c                 4   | j                   j                  | j                  j                        D ]V  }t        j                  |       t        j                  |d      }|dk7  s5t        | | j                  d|d|d             X | j                          y )NT)shellr   z)<b>Print command failed with status code z.</b><p>z</p>)r+   getPrintCommandsr   r   logr   
subprocesscallrj   rM   rk   )r"   cmdstatuss      r&   executePrintzPrintDialog.executePrint   su    &&77

8L8LM 	uCIIcN__S5F{$		gmnq*r st	u 	

r'   c                 $    | j                          y rC   )rk   rA   s    r&   r0   z PrintDialog.CancelButton_clicked   s    

r'   c                     | j                   j                         }|t        k(  r0| j                   j                  t               | j                          y t        j                  d       y )NzInvalid page!)r?   currentIndexra   r@   rQ   r!   ro   errorr"   ps     r&   r2   zPrintDialog.BackButton_clicked   sL    ++-..y9! IIo&r'   c                     | j                   j                         }|t        k(  r0| j                   j                  t               | j                          y |t        k(  r| j                          y y rC   )r?   rw   rQ   r@   ra   rd   rt   ry   s     r&   r4   zPrintDialog.NextButton_clicked   sV    ++-	>..|<""$, r'   c                 v    | j                   j                  | j                  d|dz   t        dz   fz               y )NzStep %d of %dr   )StepTextrL   rM   PAGE_MAXry   s     r&   rP   zPrintDialog.updateStepText   s/    dii!A#xz9J(JKLr'   c                 0    t         j                  d||      S )Nr   )qApp	translate)r"   scs      r&   __trzPrintDialog.__tr   s    ~~mAa00r'   rC   )__name__
__module____qualname__r   r   r8   r!   rH   rJ   r9   rd   rX   rY   rt   r0   r2   r4   rP   rM    r'   r&   r   r   2   sU    20.2<*)e1$M' M1r'   r   )base.gbaser   r   prntr   
base.codesui_utilsPyQt5.QtCorePyQt5.QtGuiPyQt5.QtWidgetsprintdialog_baser   	filetabler	   r
   printernamecomboboxr   r5   rp   rQ   ra   r~   r   r   r   r'   r&   <module>r      sS   0         ( 6 F  	g1'9 g1r'   