32 | | printername = os.environ.get("PYKOTAPRINTERNAME", "Unknown") |
33 | | username = os.environ.get("PYKOTAUSERNAME", "Unknown") |
34 | | jobid = os.environ.get("PYKOTAJOBID", "Unknown") |
35 | | jobtitle = os.environ.get("PYKOTATITLE", "Unknown") |
36 | | jobsize = os.environ.get("PYKOTAPRECOMPUTEDJOBSIZE", "Unknown") |
37 | | billingcode = os.environ.get("PYKOTAJOBBILLING", "") |
38 | | if len(arguments) < 3 : |
39 | | message = """Hello %(username)s, |
| 43 | # Opens the connection to the PyKotIcon server : |
| 44 | server = xmlrpclib.ServerProxy("http://%s:%s" % (arguments[0], arguments[1])) |
| 45 | |
| 46 | # Now display something on the PyKotIcon host : |
| 47 | message1 = "You are about to test PyKotIcon\n\nPyKotIcon is really great software !" |
| 48 | server.showDialog(xmlrpclib.Binary(message1.encode("UTF-8")), False) |
| 49 | |
| 50 | # Now ask the end user if he really wants to do this : |
| 51 | message2 = "Are you sure you want to do this ?" |
| 52 | result = server.showDialog(xmlrpclib.Binary(message2.encode("UTF-8")), True) |
| 53 | print "The remote user said : %s" % result |
| 54 | |
| 55 | # Displays the answer back : |
| 56 | answer = "You have clicked on the %s button" % result |
| 57 | server.showDialog(xmlrpclib.Binary(answer.encode("UTF-8")), False) |
| 58 | |
| 59 | # Now we will ask some datas : |
| 60 | result = server.askDatas([xmlrpclib.Binary(v) for v in ["Username", "Password", "Country"]], \ |
| 61 | ["username", "password", "country"], \ |
| 62 | {"username": xmlrpclib.Binary(""), \ |
| 63 | "password": xmlrpclib.Binary(""), \ |
| 64 | "country" : xmlrpclib.Binary("")}) |
| 65 | if result["isValid"] : |
| 66 | print "Answers :" |
| 67 | print "\n".join(["\t%s => '%s'" % (k, v.data) for (k, v) in result.items() if k != "isValid"]) |
| 68 | answer = "You answered :\n%s" % "\n".join(["%s => '%s'" % (k, v.data) for (k, v) in result.items() if k != "isValid"]) |
| 69 | server.showDialog(xmlrpclib.Binary(answer.encode("UTF-8")), False) |
| 70 | else : |
| 71 | print "The answers are not valid." |
41 | | You sent job %(jobid)s (%(jobtitle)s) to printer %(printername)s. |
42 | | |
43 | | This job seems to be %(jobsize)s pages long. |
44 | | |
45 | | Do you really want to print it ?""" % locals() |
46 | | yesno = True |
47 | | else : |
48 | | message = "\n".join(arguments[2:]) |
49 | | yesno = False |
50 | | |
51 | | server = xmlrpclib.ServerProxy("http://%s:%s" % (arguments[0], arguments[1])) |
52 | | #result = server.showDialog(xmlrpclib.Binary(message), yesno) |
53 | | #""" |
54 | | result = server.askDatas([xmlrpclib.Binary(v) for v in ["Username", "Password", "Billing code"]], \ |
55 | | ["username", "password", "billingcode"], \ |
56 | | {"username": xmlrpclib.Binary(username), \ |
57 | | "password": xmlrpclib.Binary(""), \ |
58 | | "billingcode" : xmlrpclib.Binary(billingcode)}) |
59 | | #""" |
60 | | #server.quitApplication() |
61 | | if result["isValid"] : |
62 | | print "\n".join(["%s => '%s'" % (k, v.data) for (k, v) in result.items() if k != "isValid"]) |
63 | | else : |
64 | | print "the end user closed the dialog box !" |
| 73 | # Now do nothing : |
| 74 | server.nop() |
| 75 | |
| 76 | # Finally we will cause PyKotIcon to die |
| 77 | message3 = "As soon as you'll click on the button below, PyKotIcon will die." |
| 78 | server.showDialog(xmlrpclib.Binary(message3.encode("UTF-8")), False) |
| 79 | server.quitApplication() |
| 80 | |
| 81 | # That's all folks ! |
| 82 | print |
| 83 | print "This demo is finished. Did you like it ?" |