2 # -*- coding: utf-8 -*-
4 # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
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.
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.
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
24 __title__ = 'Print Utility'
26 __doc__ = "A simple print UI front-end to lp/lpr."
35 from base import utils, device, tui, module
38 log.set_module('hp-print')
44 mod = module.Module(__mod__, __title__, __version__, __doc__, None,
45 (GUI_MODE,), (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4))
47 mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS | module.USAGE_FLAG_FILE_ARGS,
48 see_also_list=['hp-printsettings'])
50 opts, device_uri, printer_name, mode, ui_toolkit, loc = \
53 printer_name, device_uri = mod.getPrinterName(printer_name, device_uri)
55 if ui_toolkit == 'qt3':
56 if not utils.canEnterGUIMode():
57 log.error("%s requires GUI support (try running with --qt4). Exiting." % __mod__)
60 if not utils.canEnterGUIMode4():
61 log.error("%s requires GUI support (try running with --qt3). Exiting." % __mod__)
64 if ui_toolkit == 'qt3':
67 from ui.printerform import PrinterForm
69 log.error("Unable to load Qt3 support. Is it installed?")
72 # create the main application object
73 app = QApplication(sys.argv)
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)
81 if loc.lower() != 'c':
85 loc = '.'.join([l, e])
88 loc = '.'.join([loc, e])
90 log.debug("Trying to load .qm file for %s locale." % loc)
91 trans = QTranslator(None)
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)
98 app.installTranslator(trans)
103 log.debug("Using default 'C' locale")
105 log.debug("Using locale: %s" % loc)
106 QLocale.setDefault(QLocale(loc))
109 locale.setlocale(locale.LC_ALL, locale.normalize(loc))
114 printdlg = PrinterForm(printer_name, mod.args)
116 app.setMainWidget(printdlg)
119 log.debug("Starting GUI loop...")
121 except KeyboardInterrupt:
127 from PyQt4.QtGui import QApplication
128 from ui4.printdialog import PrintDialog
130 log.error("Unable to load Qt4 support. Is it installed?")
134 app = QApplication(sys.argv)
136 dlg = PrintDialog(None, printer_name, mod.args)
139 log.debug("Starting GUI loop...")
141 except KeyboardInterrupt: