diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1999-12-03 15:15:28 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1999-12-03 15:15:28 (GMT) |
commit | 2450a25fcd146ddaaec6b0f1e962c482396f372d (patch) | |
tree | 44b09855a410be89002b4be3735191cfd66941af /Mac/Demo/example1 | |
parent | 43fd1f75db89d38010dd118b98f0460e958b5b99 (diff) | |
download | cpython-2450a25fcd146ddaaec6b0f1e962c482396f372d.zip cpython-2450a25fcd146ddaaec6b0f1e962c482396f372d.tar.gz cpython-2450a25fcd146ddaaec6b0f1e962c482396f372d.tar.bz2 |
New examples by Tony Ingraldi, using dns-lookup in stead of the funny interslip
module.
Diffstat (limited to 'Mac/Demo/example1')
-rw-r--r-- | Mac/Demo/example1/InterslipControl-1.py | 92 | ||||
-rw-r--r-- | Mac/Demo/example1/InterslipControl-1.rsrc | bin | 649 -> 0 bytes | |||
-rw-r--r-- | Mac/Demo/example1/dnslookup-1.gif | bin | 0 -> 2570 bytes | |||
-rw-r--r-- | Mac/Demo/example1/dnslookup-1.py | 61 | ||||
-rw-r--r-- | Mac/Demo/example1/dnslookup-1.rsrc | bin | 0 -> 604 bytes |
5 files changed, 61 insertions, 92 deletions
diff --git a/Mac/Demo/example1/InterslipControl-1.py b/Mac/Demo/example1/InterslipControl-1.py deleted file mode 100644 index 14fc59c..0000000 --- a/Mac/Demo/example1/InterslipControl-1.py +++ /dev/null @@ -1,92 +0,0 @@ -"""Sample program handling InterSLIP control and showing off EasyDialogs, -Res and Dlg in the process""" - -import EasyDialogs -import Res -import Dlg -import sys -import interslip -# -# Definitions for our resources -ID_MAIN=512 - -ITEM_CONNECT=1 -ITEM_DISCONNECT=2 -ITEM_UPDATE=3 -ITEM_QUIT=4 -ITEM_STATUS=5 -ITEM_MESSAGE=6 - -status2text = ["<idle>", "<wait-modem>", "<dialling>", "<logging in>", - "<connected>", "<disconnecting>"] - - -def main(): - """Main routine: open resourcefile, open interslip, call dialog handler""" - try: - Res.OpenResFile("InterslipControl-1.rsrc") - except Res.Error, arg: - EasyDialogs.Message("Cannot open resource file InterslipControl-1.rsrc: "+ - arg[1]) - sys.exit(1) - try: - interslip.open() - except interslip.error, arg: - EasyDialogs.Message("Cannot open interslip: "+arg[1]) - sys.exit(1) - do_dialog() - -def do_dialog(): - """Post dialog and handle user interaction until quit""" - my_dlg = Dlg.GetNewDialog(ID_MAIN, -1) - while 1: - n = Dlg.ModalDialog(None) - if n == ITEM_CONNECT: - do_connect() - elif n == ITEM_DISCONNECT: - do_disconnect() - elif n == ITEM_UPDATE: - status, msg = do_status() - - # Convert status number to a text string - try: - txt = status2text[status] - except IndexError: - txt = "<unknown state %d>"%status - - # Set the status text field - tp, h, rect = my_dlg.GetDialogItem(ITEM_STATUS) - Dlg.SetDialogItemText(h, txt) - - # Set the message text field - tp, h, rect = my_dlg.GetDialogItem(ITEM_MESSAGE) - Dlg.SetDialogItemText(h, msg) - elif n == ITEM_QUIT: - break - -def do_connect(): - """Connect, posting error message in case of failure""" - try: - interslip.connect() - except interslip.error, arg: - EasyDialogs.Message("Cannot connect: "+arg[1]) - -def do_disconnect(): - """Disconnect, posting error message in case of failure""" - try: - interslip.disconnect() - except interslip.error, arg: - EasyDialogs.Message("Cannot disconnect: "+arg[1]) - -def do_status(): - """Get status as (state_index, message), - posting error message in case of failure""" - try: - status, msgnum, msg = interslip.status() - except interslip.error, arg: - EasyDialogs.Message("Cannot get status: "+arg[1]) - return 0, '' - return status, msg - - -main() diff --git a/Mac/Demo/example1/InterslipControl-1.rsrc b/Mac/Demo/example1/InterslipControl-1.rsrc Binary files differdeleted file mode 100644 index 7d290a8..0000000 --- a/Mac/Demo/example1/InterslipControl-1.rsrc +++ /dev/null diff --git a/Mac/Demo/example1/dnslookup-1.gif b/Mac/Demo/example1/dnslookup-1.gif Binary files differnew file mode 100644 index 0000000..3cd70b2 --- /dev/null +++ b/Mac/Demo/example1/dnslookup-1.gif diff --git a/Mac/Demo/example1/dnslookup-1.py b/Mac/Demo/example1/dnslookup-1.py new file mode 100644 index 0000000..a59fb8e --- /dev/null +++ b/Mac/Demo/example1/dnslookup-1.py @@ -0,0 +1,61 @@ +"""Sample program performing domain name lookups and showing off EasyDialogs, +Res and Dlg in the process""" + +import EasyDialogs +import Res +import Dlg +import sys +import socket +import string +# +# Definitions for our resources +ID_MAIN=512 + +ITEM_LOOKUP_ENTRY=1 +ITEM_RESULT=2 +ITEM_LOOKUP_BUTTON=3 +ITEM_QUIT_BUTTON=4 + + +def main(): + """Main routine: open resource file, call dialog handler""" + try: + Res.OpenResFile("dnslookup-1.rsrc") + except Res.Error: + EasyDialogs.Message("Cannot open dnslookup-1.rsrc") + sys.exit(1) + do_dialog() + +def do_dialog(): + """Post dialog and handle user interaction until quit""" + my_dlg = Dlg.GetNewDialog(ID_MAIN, -1) + while 1: + n = Dlg.ModalDialog(None) + if n == ITEM_LOOKUP_BUTTON: + tp, h, rect = my_dlg.GetDialogItem(ITEM_LOOKUP_ENTRY) + txt = Dlg.GetDialogItemText(h) + + tp, h, rect = my_dlg.GetDialogItem(ITEM_RESULT) + Dlg.SetDialogItemText(h, dnslookup(txt)) + elif n == ITEM_QUIT_BUTTON: + break + +def dnslookup(str): + """ Perform DNS lookup on str. If first character of digit is numeric, + assume that str contains an IP address. Otherwise, assume that str + contains a hostname.""" + if str == '': str = ' ' + if str[0] in string.digits: + try: + value = socket.gethostbyaddr(str)[0] + except: + value = 'Lookup failed' + else: + try: + value = socket.gethostbyname(str) + except: + value = 'Lookup failed' + return value + +main() + diff --git a/Mac/Demo/example1/dnslookup-1.rsrc b/Mac/Demo/example1/dnslookup-1.rsrc Binary files differnew file mode 100644 index 0000000..2514f56 --- /dev/null +++ b/Mac/Demo/example1/dnslookup-1.rsrc |