home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / nodevicesdialog.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  3.2 KB  |  104 lines

  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. # Authors: Don Welch
  20. #
  21.  
  22.  
  23. # Local
  24. from base.g import *
  25. from base import device, utils
  26. from ui_utils import *
  27.  
  28. # Qt
  29. from PyQt4.QtCore import *
  30. from PyQt4.QtGui import *
  31.  
  32. # Ui
  33. from nodevicesdialog_base import Ui_NoDevicesDialog_base
  34.  
  35.  
  36. class NoDevicesDialog(QDialog, Ui_NoDevicesDialog_base):
  37.     def __init__(self, parent):
  38.         QDialog.__init__(self, parent)
  39.         self.setupUi(self)
  40.         self.initUi()
  41.  
  42.  
  43.     def initUi(self):
  44.         self.connect(self.SetupButton, SIGNAL("clicked()"), self.SetupButton_clicked)
  45.         self.connect(self.CUPSButton, SIGNAL("clicked()"), self.CUPSButton_clicked)
  46.         self.connect(self.CloseButton, SIGNAL("clicked()"), self.CloseButton_clicked)
  47.         self.Icon.setPixmap(load_pixmap("warning", '32x32'))
  48.  
  49.  
  50.     def SetupButton_clicked(self):
  51.         self.close()
  52.         su_sudo = None
  53.  
  54.         if utils.which('kdesu'):
  55.             su_sudo = 'kdesu -- %s'
  56.  
  57.         elif utils.which('kdesudo'):
  58.             su_sudo = 'kdesudo -- %s'
  59.  
  60.         elif utils.which('gnomesu'):
  61.             su_sudo = 'gnomesu -c "%s"'
  62.  
  63.         elif utils.which('gksu'):
  64.             su_sudo = 'gksu "%s"'
  65.  
  66.         if su_sudo is None:
  67.             QMessageBox.critical(self,
  68.                                 self.windowTitle(),
  69.                                 self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-setup.</b>"),
  70.                                 QMessageBox.Ok,
  71.                                 QMessageBox.NoButton,
  72.                                 QMessageBox.NoButton)
  73.  
  74.         else:
  75.             if utils.which('hp-setup'):
  76.                 cmd = su_sudo % 'hp-setup -u'
  77.             else:
  78.                 cmd = su_sudo % 'python ./setup.py -u'
  79.  
  80.             log.debug(cmd)
  81.             utils.run(cmd, log_output=True, password_func=None, timeout=1)
  82.  
  83.             try:
  84.                 self.parent().rescanDevices()
  85.             except Error:
  86.                 QMessageBox.critical(self,
  87.                                     self.windowTitle(),
  88.                                     self.__tr("<b>An error occurred.</b><p>Please re-start the Device Manager and try again."),
  89.                                     QMessageBox.Ok,
  90.                                     QMessageBox.NoButton,
  91.                                     QMessageBox.NoButton)
  92.  
  93.  
  94.     def CUPSButton_clicked(self):
  95.         self.close()
  96.         utils.openURL("http://localhost:631/admin?op=add-printer")
  97.  
  98.  
  99.     def CloseButton_clicked(self):
  100.         self.close()
  101.  
  102.  
  103.  
  104.