Back to index

system-config-printer  1.3.9+20120706
Classes | Functions | Variables
cupshelpers.openprinting Namespace Reference

Classes

class  _QueryThread
class  OpenPrinting

Functions

def _normalize_space
def _simple_gui

Variables

list __all__ = ['OpenPrinting']
 openprinting
 main
 entry
 tv

Function Documentation

Definition at line 29 of file openprinting.py.

00029 
00030 def _normalize_space (text):
00031     result = text.strip ()
00032     result = result.replace ('\n', ' ')
00033     i = result.find ('  ')
00034     while i != -1:
00035         result = result.replace ('  ', ' ')
00036         i = result.find ('  ')
00037     return result

Definition at line 375 of file openprinting.py.

00375 
00376 def _simple_gui ():
00377     import gtk, pprint
00378     gtk.gdk.threads_init ()
00379     class QueryApp:
00380         def __init__(self):
00381             self.openprinting = OpenPrinting()
00382             self.main = gtk.Dialog ("OpenPrinting query application",
00383                                     None,
00384                                     gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR,
00385                                     (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE,
00386                                      "Search", 10,
00387                                      "List", 20))
00388             self.main.set_border_width (6)
00389             self.main.vbox.set_spacing (2)
00390             vbox = gtk.VBox (False, 6)
00391             self.main.vbox.pack_start (vbox, True, True, 0)
00392             vbox.set_border_width (6)
00393             self.entry = gtk.Entry ()
00394             vbox.pack_start (self.entry, False, False, 6)
00395             sw = gtk.ScrolledWindow ()
00396             self.tv = gtk.TextView ()
00397             sw.add (self.tv)
00398             vbox.pack_start (sw, True, True, 6)
00399             self.main.connect ("response", self.response)
00400             self.main.show_all ()
00401 
00402         def response (self, dialog, response):
00403             if (response == gtk.RESPONSE_CLOSE or
00404                 response == gtk.RESPONSE_DELETE_EVENT):
00405                 gtk.main_quit ()
00406 
00407             if response == 10:
00408                 # Run a query.
00409                 self.openprinting.searchPrinters (self.entry.get_text (),
00410                                                   self.search_printers_callback)
00411 
00412             if response == 20:
00413                 self.openprinting.listDrivers (self.entry.get_text (),
00414                                                self.list_drivers_callback)
00415 
00416         def search_printers_callback (self, status, user_data, printers):
00417             if status != 0:
00418                 raise printers[1]
00419 
00420             text = ""
00421             for printer in printers.values ():
00422                 text += printer + "\n"
00423             gtk.gdk.threads_enter ()
00424             self.tv.get_buffer ().set_text (text)
00425             gtk.gdk.threads_leave ()
00426 
00427         def list_drivers_callback (self, status, user_data, drivers):
00428             if status != 0:
00429                 raise drivers[1]
00430 
00431             text = pprint.pformat (drivers)
00432             gtk.gdk.threads_enter ()
00433             self.tv.get_buffer ().set_text (text)
00434             gtk.gdk.threads_leave ()
00435 
00436         def query_callback (self, status, user_data, result):
00437             gtk.gdk.threads_enter ()
00438             self.tv.get_buffer ().set_text (str (result))
00439             file ("result.xml", "w").write (str (result))
00440             gtk.gdk.threads_leave ()
00441 
00442     q = QueryApp()
00443     gtk.main ()

Variable Documentation

Definition at line 27 of file openprinting.py.

Definition at line 392 of file openprinting.py.

Definition at line 381 of file openprinting.py.

Definition at line 380 of file openprinting.py.

Definition at line 395 of file openprinting.py.