Tizen 2.1 base
[platform/upstream/hplip.git] / ui4 / printsettingsdialog.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # Author: Don Welch
20 #
21
22 # Local
23 from base.g import *
24 from base import device
25 from prnt import cups
26 from ui_utils import *
27
28 # Qt
29 from PyQt4.QtCore import *
30 from PyQt4.QtGui import *
31
32 # Ui
33 from printsettingsdialog_base import Ui_Dialog
34 from printsettingstoolbox import PrintSettingsToolbox
35 from printernamecombobox import PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX, PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY
36
37
38 class PrintSettingsDialog(QDialog, Ui_Dialog):
39     def __init__(self, parent, printer_name, fax_mode=False):
40         QDialog.__init__(self, parent)
41         self.setupUi(self)
42         self.fax_mode = fax_mode
43         self.printer_name = printer_name
44         self.device_uri = None
45         self.devices = {}
46         self.printer_index = {}
47
48         # User settings
49         self.user_settings = UserSettings()
50         self.user_settings.load()
51         self.user_settings.debug()
52         #self.cur_printer = self.user_settings.last_used_printer
53
54         self.initUi(printer_name)
55         QTimer.singleShot(0, self.updateUi)
56
57
58     def initUi(self, printer_name=None):
59         self.OptionsToolBox.include_print_options = False
60
61         if self.printer_name:
62             self.PrinterName.setInitialPrinter(self.printer_name)
63
64         if self.fax_mode:
65             self.PrinterName.setType(PRINTERNAMECOMBOBOX_TYPE_FAX_ONLY)
66             self.TitleLabel.setText(self.__tr("Fax Settings"))
67         else:
68             self.PrinterName.setType(PRINTERNAMECOMBOBOX_TYPE_PRINTER_AND_FAX)
69
70         self.connect(self.CloseButton, SIGNAL("clicked()"), self.CloseButton_clicked)
71
72         self.connect(self.PrinterName, SIGNAL("PrinterNameComboBox_currentChanged"),
73             self.PrinterNameComboBox_currentChanged)
74
75         self.connect(self.PrinterName, SIGNAL("PrinterNameComboBox_noPrinters"),
76             self.PrinterNameComboBox_noPrinters)
77
78         # Application icon
79         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
80
81
82
83     def updateUi(self):
84         self.PrinterName.updateUi()
85
86
87     def PrinterNameComboBox_noPrinters(self):
88         FailureUI(self, self.__tr("<b>No printers or faxes found.</b><p>Please setup a printer or fax and try again."))
89         self.close()
90
91
92     def PrinterNameComboBox_currentChanged(self, device_uri, printer_name):
93         self.printer_name = printer_name
94         self.device_uri = device_uri
95         try:
96             self.devices[device_uri]
97         except KeyError:
98             self.devices[device_uri] = device.Device(device_uri)
99
100         self.OptionsToolBox.updateUi(self.devices[device_uri], self.printer_name)
101
102
103     #
104     # Misc
105     #
106
107     def CloseButton_clicked(self):
108         self.close()
109
110
111     def __tr(self,s,c = None):
112         return qApp.translate("PrintSettingsDialog",s,c)
113
114