Changeset 167

Show
Ignore:
Timestamp:
06/09/06 11:31:02 (18 years ago)
Author:
jerome
Message:

Rewrote the demo. --Cette ligne, et les suivantes ci-dessous, seront
ignorées--

M tests/test.py
M bin/pykoticon
M NEWS

Location:
pykoticon/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykoticon/trunk/bin/pykoticon

    r160 r167  
    2323# 
    2424 
    25 __version__ = "1.02" 
     25__version__ = "1.03" 
    2626__author__ = "Jerome Alet" 
    2727__author_email__ = "alet@librelogiciel.com" 
  • pykoticon/trunk/NEWS

    r160 r167  
    2222PyKotIcon NEWS : 
    2323 
     24  - 1.03 (2006-06-09) : 
     25     
     26    - Rewrote the tests/test.py program to give a better 
     27      experience to testers. 
     28       
    2429  - 1.02 (2006-06-07) : 
    2530     
  • pykoticon/trunk/tests/test.py

    r107 r167  
    22# -*- coding: ISO-8859-15 -*- 
    33 
    4 # PyKotIcon - an end-user companion for PyKota 
     4# PyKotIcon - Client side helper for PyKota and other applications 
    55# 
    66# (c) 2003, 2004, 2005, 2006 Jerome Alet <alet@librelogiciel.com> 
     
    2323# 
    2424 
     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        $ ./test.py localhost 7654 
     31 
     32Then you should see the demonstration begin. 
     33 
     34Please send bug reports or feedback to : alet@librelogiciel.com""" 
     35 
    2536import sys 
    26 import os 
    27 import time 
     37import socket 
    2838import xmlrpclib 
     39 
    2940 
    3041def main(arguments) : 
    3142    """Main function.""" 
    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." 
    4072         
    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 ?" 
    6584         
    6685if __name__ == "__main__" : 
    6786    if len(sys.argv) < 3 : 
    68         sys.stderr.write("usage : %s printing_client_hostname_or_ip_address printing_client_TCPPort\n" % sys.argv[0]) 
     87        sys.stderr.write("usage : %s pykoticon_hostname_or_ip_address pykoticon_TCPPort\n" % sys.argv[0]) 
    6988    else :     
    70         main(sys.argv[1:]) 
     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