root / pykoticon / trunk / tests / test.py @ 1153

Revision 176, 3.7 kB (checked in by jerome, 18 years ago)

Changed copyright years.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3
4# PyKotIcon - Client side helper for PyKota and other applications
5#
6# (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com>
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.
16#
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
25"""This test program demonstrates the functionnalities of PyKotIcon.
26
27Launch pykoticon with no arguments on the same host, then launch
28this test program this way :
29
30        $ python ./test.py localhost 7654
31
32Then you should see the demonstration begin.
33
34Please send bug reports or feedback to : alet@librelogiciel.com"""
35
36import sys
37import socket
38import xmlrpclib
39
40
41def main(arguments) :
42    """Main function."""
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."
72       
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 ?"
84       
85if __name__ == "__main__" :
86    if len(sys.argv) < 3 :
87        sys.stderr.write("usage : %s pykoticon_hostname_or_ip_address pykoticon_TCPPort\n" % sys.argv[0])
88    else :   
89        try :
90            main(sys.argv[1:])
91        except socket.error, msg :   
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")
94           
Note: See TracBrowser for help on using the browser.