1 """Sample program handling InterSLIP control and showing off EasyDialogs,
2 Res and Dlg in the process"""
10 # Definitions for our resources
20 status2text
= ["<idle>", "<wait-modem>", "<dialling>", "<logging in>",
21 "<connected>", "<disconnecting>"]
25 """Main routine: open resourcefile, open interslip, call dialog handler"""
27 Res
.OpenResFile("InterslipControl-1.rsrc")
28 except Res
.Error
, arg
:
29 EasyDialogs
.Message("Cannot open resource file InterslipControl-1.rsrc: "+
34 except interslip
.error
, arg
:
35 EasyDialogs
.Message("Cannot open interslip: "+arg
[1])
40 """Post dialog and handle user interaction until quit"""
41 my_dlg
= Dlg
.GetNewDialog(ID_MAIN
, -1)
43 n
= Dlg
.ModalDialog(None)
46 elif n
== ITEM_DISCONNECT
:
48 elif n
== ITEM_UPDATE
:
49 status
, msg
= do_status()
51 # Convert status number to a text string
53 txt
= status2text
[status
]
55 txt
= "<unknown state %d>"%status
57 # Set the status text field
58 tp
, h
, rect
= my_dlg
.GetDialogItem(ITEM_STATUS
)
59 Dlg
.SetDialogItemText(h
, txt
)
61 # Set the message text field
62 tp
, h
, rect
= my_dlg
.GetDialogItem(ITEM_MESSAGE
)
63 Dlg
.SetDialogItemText(h
, msg
)
68 """Connect, posting error message in case of failure"""
71 except interslip
.error
, arg
:
72 EasyDialogs
.Message("Cannot connect: "+arg
[1])
75 """Disconnect, posting error message in case of failure"""
77 interslip
.disconnect()
78 except interslip
.error
, arg
:
79 EasyDialogs
.Message("Cannot disconnect: "+arg
[1])
82 """Get status as (state_index, message),
83 posting error message in case of failure"""
85 status
, msgnum
, msg
= interslip
.status()
86 except interslip
.error
, arg
:
87 EasyDialogs
.Message("Cannot get status: "+arg
[1])