Replace 'tap' to 'spaces' to make gbs build succeed
[platform/upstream/hplip.git] / print.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 # Author: Don Welch
21 #
22
23 __version__ = '4.0'
24 __title__ = 'Print Utility'
25 __mod__ = 'hp-print'
26 __doc__ = "A simple print UI front-end to lp/lpr."
27
28 # Std Lib
29 import sys
30 import os
31 import getopt
32
33 # Local
34 from base.g import *
35 from base import utils, device, tui, module
36 from prnt import cups
37
38 log.set_module('hp-print')
39
40 app = None
41 printdlg = None
42
43
44 mod = module.Module(__mod__, __title__, __version__, __doc__, None,
45                     (GUI_MODE,), (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4))
46
47 mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS | module.USAGE_FLAG_FILE_ARGS,
48              see_also_list=['hp-printsettings'])
49
50 opts, device_uri, printer_name, mode, ui_toolkit, loc = \
51     mod.parseStdOpts()
52
53 printer_name, device_uri = mod.getPrinterName(printer_name, device_uri)
54
55 if ui_toolkit == 'qt3':
56     if not utils.canEnterGUIMode():
57         log.error("%s requires GUI support (try running with --qt4). Exiting." % __mod__)
58         sys.exit(1)
59 else:
60     if not utils.canEnterGUIMode4():
61         log.error("%s requires GUI support (try running with --qt3). Exiting." % __mod__)
62         sys.exit(1)
63
64 if ui_toolkit == 'qt3':
65     try:
66         from qt import *
67         from ui.printerform import PrinterForm
68     except ImportError:
69         log.error("Unable to load Qt3 support. Is it installed?")
70         sys.exit(1)
71
72     # create the main application object
73     app = QApplication(sys.argv)
74
75     if loc is None:
76         loc = user_conf.get('ui', 'loc', 'system')
77         if loc.lower() == 'system':
78             loc = str(QTextCodec.locale())
79             log.debug("Using system locale: %s" % loc)
80
81     if loc.lower() != 'c':
82         e = 'utf8'
83         try:
84             l, x = loc.split('.')
85             loc = '.'.join([l, e])
86         except ValueError:
87             l = loc
88             loc = '.'.join([loc, e])
89
90         log.debug("Trying to load .qm file for %s locale." % loc)
91         trans = QTranslator(None)
92
93         qm_file = 'hplip_%s.qm' % l
94         log.debug("Name of .qm file: %s" % qm_file)
95         loaded = trans.load(qm_file, prop.localization_dir)
96
97         if loaded:
98             app.installTranslator(trans)
99         else:
100             loc = 'c'
101
102     if loc == 'c':
103         log.debug("Using default 'C' locale")
104     else:
105         log.debug("Using locale: %s" % loc)
106         QLocale.setDefault(QLocale(loc))
107         prop.locale = loc
108         try:
109             locale.setlocale(locale.LC_ALL, locale.normalize(loc))
110         except locale.Error:
111             pass
112
113     #print printer_name
114     printdlg = PrinterForm(printer_name, mod.args)
115     printdlg.show()
116     app.setMainWidget(printdlg)
117
118     try:
119         log.debug("Starting GUI loop...")
120         app.exec_loop()
121     except KeyboardInterrupt:
122         pass
123
124
125 else: # qt4
126     try:
127         from PyQt4.QtGui import QApplication
128         from ui4.printdialog import PrintDialog
129     except ImportError:
130         log.error("Unable to load Qt4 support. Is it installed?")
131         sys.exit(1)
132
133     if 1:
134         app = QApplication(sys.argv)
135
136         dlg = PrintDialog(None, printer_name, mod.args)
137         dlg.show()
138         try:
139             log.debug("Starting GUI loop...")
140             app.exec_()
141         except KeyboardInterrupt:
142             sys.exit(0)
143
144
145 sys.exit(0)
146
147