[90] | 1 | #! /usr/bin/env python |
---|
[3439] | 2 | # -*- coding: iso-8859-15 -*- |
---|
[90] | 3 | |
---|
[167] | 4 | # PyKotIcon - Client side helper for PyKota and other applications |
---|
[90] | 5 | # |
---|
[3480] | 6 | # (c) 2003-2009 Jerome Alet <alet@librelogiciel.com> |
---|
[90] | 7 | # This program is free software; you can redistribute it and/or modify |
---|
| 8 | # it under the terms of the GNU General Public License as published by |
---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 10 | # (at your option) any later version. |
---|
| 11 | # |
---|
| 12 | # This program is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
[3439] | 16 | # |
---|
[90] | 17 | # You should have received a copy of the GNU General Public License |
---|
| 18 | # along with this program; if not, write to the Free Software |
---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
| 20 | # |
---|
| 21 | # $Id$ |
---|
| 22 | # |
---|
| 23 | # |
---|
| 24 | |
---|
[167] | 25 | """This test program demonstrates the functionnalities of PyKotIcon. |
---|
| 26 | |
---|
| 27 | Launch pykoticon with no arguments on the same host, then launch |
---|
| 28 | this test program this way : |
---|
| 29 | |
---|
[168] | 30 | $ python ./test.py localhost 7654 |
---|
[167] | 31 | |
---|
| 32 | Then you should see the demonstration begin. |
---|
| 33 | |
---|
| 34 | Please send bug reports or feedback to : alet@librelogiciel.com""" |
---|
| 35 | |
---|
[90] | 36 | import sys |
---|
[167] | 37 | import socket |
---|
[90] | 38 | import xmlrpclib |
---|
| 39 | |
---|
[167] | 40 | |
---|
[90] | 41 | def main(arguments) : |
---|
| 42 | """Main function.""" |
---|
[167] | 43 | # Opens the connection to the PyKotIcon server : |
---|
[100] | 44 | server = xmlrpclib.ServerProxy("http://%s:%s" % (arguments[0], arguments[1])) |
---|
[3439] | 45 | |
---|
[167] | 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) |
---|
[3439] | 49 | |
---|
| 50 | # Now ask the end user if he really wants to do this : |
---|
[167] | 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 |
---|
[3439] | 54 | |
---|
[167] | 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) |
---|
[3439] | 58 | |
---|
| 59 | # Now we will ask some datas : |
---|
[167] | 60 | result = server.askDatas([xmlrpclib.Binary(v) for v in ["Username", "Password", "Country"]], \ |
---|
| 61 | ["username", "password", "country"], \ |
---|
| 62 | {"username": xmlrpclib.Binary(""), \ |
---|
[107] | 63 | "password": xmlrpclib.Binary(""), \ |
---|
[167] | 64 | "country" : xmlrpclib.Binary("")}) |
---|
[106] | 65 | if result["isValid"] : |
---|
[167] | 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) |
---|
[3439] | 70 | else : |
---|
[167] | 71 | print "The answers are not valid." |
---|
[3439] | 72 | |
---|
| 73 | # Now do nothing : |
---|
[167] | 74 | server.nop() |
---|
[3439] | 75 | |
---|
[167] | 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() |
---|
[3439] | 80 | |
---|
[167] | 81 | # That's all folks ! |
---|
| 82 | print |
---|
| 83 | print "This demo is finished. Did you like it ?" |
---|
[3439] | 84 | |
---|
[90] | 85 | if __name__ == "__main__" : |
---|
[100] | 86 | if len(sys.argv) < 3 : |
---|
[167] | 87 | sys.stderr.write("usage : %s pykoticon_hostname_or_ip_address pykoticon_TCPPort\n" % sys.argv[0]) |
---|
[3439] | 88 | else : |
---|
[167] | 89 | try : |
---|
| 90 | main(sys.argv[1:]) |
---|
[3439] | 91 | except socket.error, msg : |
---|
[167] | 92 | sys.stderr.write("ERROR : Network error : %s\n" % msg) |
---|
| 93 | sys.stderr.write("Are you sure that PyKotIcon is running and accepts incoming connections ?\n") |
---|