summaryrefslogtreecommitdiff
path: root/source3/python/gprinterdata
blob: 52c6e42719b76e0a1e94c0e65398a7e52d7d0b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python

import sys
from gtkdictbrowser import GtkDictBrowser, hex_string
import gtk
import spoolss
import string

class printerdata:
    def __init__(self, host):
        host = string.replace(host, "/", "\\")
        self.hnd = spoolss.openprinter(host)

    def keys(self):
        return self.hnd.enumprinterdata().keys()

    def __getitem__(self, key):
        return self.hnd.getprinterdata(key)['data']
        
# Initialise printerdata dictionary

if len(sys.argv) != 2:
    print "Usage: gprinterdata <printer>"
    print "where <printer> is a UNC printer name."
    sys.exit(1)

try:
    t = printerdata(sys.argv[1])
except:
    print "gprinterdata: error opening %s" % sys.argv[1]
    sys.exit(1)

# Create interface

db = GtkDictBrowser(t)
db.register_get_value_text_fn("", hex_string)
db.build_ui('gprinterdata')

# Override Python's handling of ctrl-c so we can break out of the
# gui from the command line.

import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)

gtk.mainloop()