Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes | Static Public Attributes
applet.NewPrinterNotification Class Reference

List of all members.

Public Member Functions

def __init__
def GetReady
def on_notification_closed
def timeout_ready
def NewPrinter
def print_test_page
def configure
def get_newprinterdialog_interface
def ignore_dbus_replies
def find_driver
def setup_printer
def install_driver
def collect_exit_code

Public Attributes

 system_bus
 session_bus
 getting_ready
 notification
 packagekit

Static Public Attributes

int STATUS_SUCCESS = 0
int STATUS_MODEL_MISMATCH = 1
int STATUS_GENERIC_DRIVER = 2
int STATUS_NO_DRIVER = 3

Detailed Description

Definition at line 69 of file applet.py.


Constructor & Destructor Documentation

def applet.NewPrinterNotification.__init__ (   self,
  system_bus,
  session_bus 
)

Definition at line 75 of file applet.py.

00075 
00076     def __init__ (self, system_bus, session_bus):
00077         self.system_bus = system_bus
00078         self.session_bus = session_bus
00079         self.getting_ready = 0
00080         bus_name = dbus.service.BusName (PDS_OBJ, bus=system_bus)
00081         dbus.service.Object.__init__ (self, bus_name, PDS_PATH)
00082         self.notification = None


Member Function Documentation

Definition at line 274 of file applet.py.

00274 
00275     def collect_exit_code (self, pid):
00276         # We do this with timers instead of signals because we already
00277         # have gobject imported, but don't (yet) import signal;
00278         # let's try not to inflate the process size.
00279         import os
00280         try:
00281             print "Waiting for child %d" % pid
00282             (pid, status) = os.waitpid (pid, os.WNOHANG)
00283             if pid == 0:
00284                 # Run this timer again.
00285                 return True
00286         except OSError:
00287             pass
00288 
00289         return False
00290 
PROGRAM_NAME="system-config-printer-applet"
def applet.NewPrinterNotification.configure (   self,
  notification,
  action,
  name 
)

Definition at line 234 of file applet.py.

00234 
00235     def configure (self, notification, action, name):
00236         obj = self.session_bus.get_object (PRINTING_BUS, PRINTING_PATH)
00237         iface = dbus.Interface (obj, PRINTING_IFACE)
00238         return iface.PrinterPropertiesDialog (dbus.UInt32(0), name)

Here is the caller graph for this function:

def applet.NewPrinterNotification.find_driver (   self,
  notification,
  action,
  name,
  devid = "" 
)

Definition at line 250 of file applet.py.

00250 
00251     def find_driver (self, notification, action, name, devid = ""):
00252         try:
00253             iface = self.get_newprinterdialog_interface ()
00254             iface.ChangePPD (dbus.UInt32(0), name, devid,
00255                              reply_handler=self.ignore_dbus_replies,
00256                              error_handler=self.ignore_dbus_replies)
00257         except dbus.DBusException:
00258             pass

Here is the call graph for this function:

Definition at line 239 of file applet.py.

00239 
00240     def get_newprinterdialog_interface (self):
00241         obj = self.session_bus.get_object (PRINTING_BUS, PRINTING_PATH)
00242         iface = dbus.Interface (obj, PRINTING_IFACE)
00243         path = iface.NewPrinterDialog ()
00244         obj = self.session_bus.get_object (PRINTING_BUS, path)
00245         iface = dbus.Interface (obj, NEWPRINTERDIALOG_IFACE)
00246         return iface

Here is the caller graph for this function:

Definition at line 84 of file applet.py.

00084 
00085     def GetReady (self):
00086         TIMEOUT=1200000
00087         if self.getting_ready == 0:
00088             n = pynotify.Notification (_("Configuring new printer"),
00089                                        _("Please wait..."),
00090                                        'printer')
00091             n.set_timeout (TIMEOUT + 5000)
00092             n.set_data ('closed', False)
00093             n.connect ('closed', self.on_notification_closed)
00094             n.show ()
00095             self.notification = n
00096 
00097         self.getting_ready += 1
00098         gobject.timeout_add_seconds (TIMEOUT, self.timeout_ready)

Here is the call graph for this function:

Definition at line 247 of file applet.py.

00247 
00248     def ignore_dbus_replies (self, *args):
00249         pass

Here is the caller graph for this function:

def applet.NewPrinterNotification.install_driver (   self,
  notification,
  action,
  missing_pkgs 
)

Definition at line 268 of file applet.py.

00268 
00269     def install_driver (self, notification, action, missing_pkgs):
00270         try:
00271             self.packagekit.InstallPackageName (0, 0, missing_pkgs[0])
00272         except:
00273             pass

def applet.NewPrinterNotification.NewPrinter (   self,
  status,
  name,
  mfg,
  mdl,
  des,
  cmd 
)

Definition at line 113 of file applet.py.

00113 
00114     def NewPrinter (self, status, name, mfg, mdl, des, cmd):
00115         if name.find("/") >= 0:
00116             # name is a URI, no queue was generated, because no suitable
00117             # driver was found
00118             title = _("Missing printer driver")
00119             devid = "MFG:%s;MDL:%s;DES:%s;CMD:%s;" % (mfg, mdl, des, cmd)
00120             if (mfg and mdl) or des:
00121                 if (mfg and mdl):
00122                     device = "%s %s" % (mfg, mdl)
00123                 else:
00124                     device = des
00125                 text = _("No printer driver for %s.") % device
00126             else:
00127                 text = _("No driver for this printer.")
00128             n = pynotify.Notification (title, text, 'printer')
00129             if "actions" in pynotify.get_server_caps():
00130                 n.set_urgency (pynotify.URGENCY_CRITICAL)
00131                 n.set_timeout (pynotify.EXPIRES_NEVER)
00132                 n.add_action ("setup-printer", _("Search"),
00133                               lambda x, y:
00134                                   self.setup_printer (x, y, name, devid))
00135             else:
00136                 self.setup_printer (None, None, name, devid)
00137 
00138         else:
00139             # name is the name of the queue which hal_lpadmin has set up
00140             # automatically.
00141             c = cups.Connection ()
00142             try:
00143                 printer = c.getPrinters ()[name]
00144             except KeyError:
00145                 return
00146 
00147             try:
00148                 filename = c.getPPD (name)
00149             except cups.IPPError:
00150                 return
00151 
00152             del c
00153 
00154             # Check for missing packages
00155             cups.ppdSetConformance (cups.PPD_CONFORM_RELAXED)
00156             ppd = cups.PPD (filename)
00157             import os
00158             os.unlink (filename)
00159             import sys
00160             sys.path.append (APPDIR)
00161             import cupshelpers
00162             (missing_pkgs,
00163              missing_exes) = cupshelpers.missingPackagesAndExecutables (ppd)
00164 
00165             from cupshelpers.ppds import ppdMakeModelSplit
00166             (make, model) = ppdMakeModelSplit (printer['printer-make-and-model'])
00167             driver = make + " " + model
00168             if status < self.STATUS_GENERIC_DRIVER:
00169                 title = _("Printer added")
00170             else:
00171                 title = _("Missing printer driver")
00172 
00173             if len (missing_pkgs) > 0:
00174                 pkgs = reduce (lambda x,y: x + ", " + y, missing_pkgs)
00175                 title = _("Install printer driver")
00176                 text = _("`%s' requires driver installation: %s.") % (name, pkgs)
00177                 n = pynotify.Notification (title, text)
00178                 import installpackage
00179                 if "actions" in pynotify.get_server_caps():
00180                     try:
00181                         self.packagekit = installpackage.PackageKit ()
00182                         n.set_timeout (pynotify.EXPIRES_NEVER)
00183                         n.add_action ("install-driver", _("Install"),
00184                                       lambda x, y:
00185                                           self.install_driver (x, y,
00186                                                                missing_pkgs))
00187                     except:
00188                         pass
00189                 else:
00190                     try:
00191                         self.packagekit = installpackage.PackageKit ()
00192                         self.packagekit.InstallPackageName (0, 0,
00193                                                             missing_pkgs[0])
00194                     except:
00195                         pass
00196 
00197             elif status == self.STATUS_SUCCESS:
00198                 devid = "MFG:%s;MDL:%s;DES:%s;CMD:%s;" % (mfg, mdl, des, cmd)
00199                 text = _("`%s' is ready for printing.") % name
00200                 n = pynotify.Notification (title, text)
00201                 if "actions" in pynotify.get_server_caps():
00202                     n.set_urgency (pynotify.URGENCY_NORMAL)
00203                     n.add_action ("test-page", _("Print test page"),
00204                                   lambda x, y:
00205                                       self.print_test_page (x, y, name))
00206                     n.add_action ("configure", _("Configure"),
00207                                   lambda x, y: self.configure (x, y, name))
00208             else: # Model mismatch
00209                 devid = "MFG:%s;MDL:%s;DES:%s;CMD:%s;" % (mfg, mdl, des, cmd)
00210                 text = (_("`%s' has been added, using the `%s' driver.") %
00211                         (name, driver))
00212                 n = pynotify.Notification (title, text, 'printer')
00213                 if "actions" in pynotify.get_server_caps():
00214                     n.set_urgency (pynotify.URGENCY_CRITICAL)
00215                     n.add_action ("test-page", _("Print test page"),
00216                                   lambda x, y:
00217                                       self.print_test_page (x, y, name, devid))
00218                     n.add_action ("find-driver", _("Find driver"),
00219                                   lambda x, y: 
00220                                   self.find_driver (x, y, name, devid))
00221                     n.set_timeout (pynotify.EXPIRES_NEVER)
00222                 else:
00223                     self.configure (None, None, name)
00224 
00225         self.timeout_ready ()
00226         n.show ()
00227         self.notification = n

Here is the call graph for this function:

def applet.NewPrinterNotification.on_notification_closed (   self,
  notification 
)

Definition at line 99 of file applet.py.

00099 
00100     def on_notification_closed (self, notification):
00101         notification.set_data ('closed', True)

Here is the caller graph for this function:

def applet.NewPrinterNotification.print_test_page (   self,
  notification,
  action,
  name 
)

Definition at line 228 of file applet.py.

00228 
00229     def print_test_page (self, notification, action, name):
00230         path = self.configure (None, None, name)
00231         obj = self.session_bus.get_object (PRINTING_BUS, path)
00232         iface = dbus.Interface (obj, PRINTERPROPERTIESDIALOG_IFACE)
00233         iface.PrintTestPage ()

Here is the call graph for this function:

def applet.NewPrinterNotification.setup_printer (   self,
  notification,
  action,
  uri,
  devid = "" 
)

Definition at line 259 of file applet.py.

00259 
00260     def setup_printer (self, notification, action, uri, devid = ""):
00261         try:
00262             iface = self.get_newprinterdialog_interface ()
00263             iface.NewPrinterFromDevice (dbus.UInt32(0), uri, devid,
00264                                         reply_handler=self.ignore_dbus_replies,
00265                                         error_handler=self.ignore_dbus_replies)
00266         except dbus.DBusException:
00267             pass

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 102 of file applet.py.

00102 
00103     def timeout_ready (self):
00104         if self.getting_ready > 0:
00105             self.getting_ready -= 1
00106         if (self.getting_ready == 0 and
00107             self.notification and
00108             not self.notification.get_data ('closed')):
00109             self.notification.close ()
00110 
00111         return False

Here is the caller graph for this function:


Member Data Documentation

Definition at line 78 of file applet.py.

Definition at line 81 of file applet.py.

Definition at line 180 of file applet.py.

Definition at line 77 of file applet.py.

Definition at line 72 of file applet.py.

Definition at line 71 of file applet.py.

Definition at line 73 of file applet.py.

Definition at line 70 of file applet.py.

Definition at line 76 of file applet.py.


The documentation for this class was generated from the following file: