summaryrefslogtreecommitdiffstats
path: root/Mac/Demo/example2
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1999-12-03 15:15:28 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1999-12-03 15:15:28 (GMT)
commit2450a25fcd146ddaaec6b0f1e962c482396f372d (patch)
tree44b09855a410be89002b4be3735191cfd66941af /Mac/Demo/example2
parent43fd1f75db89d38010dd118b98f0460e958b5b99 (diff)
downloadcpython-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/example2')
-rw-r--r--Mac/Demo/example2/InterslipControl-2.py116
-rw-r--r--Mac/Demo/example2/InterslipControl-2.rsrcbin3423 -> 0 bytes
-rw-r--r--Mac/Demo/example2/dnslookup-2.gifbin0 -> 2984 bytes
-rw-r--r--Mac/Demo/example2/dnslookup-2.py92
-rw-r--r--Mac/Demo/example2/dnslookup-2.rsrcbin0 -> 707 bytes
5 files changed, 92 insertions, 116 deletions
diff --git a/Mac/Demo/example2/InterslipControl-2.py b/Mac/Demo/example2/InterslipControl-2.py
deleted file mode 100644
index 90d57dd..0000000
--- a/Mac/Demo/example2/InterslipControl-2.py
+++ /dev/null
@@ -1,116 +0,0 @@
-import FrameWork
-import EasyDialogs
-import Res
-import Dlg
-import sys
-import interslip
-#
-# Definitions for our resources
-ID_MAIN=512
-ID_ABOUT=513
-
-ITEM_CONNECT=1
-ITEM_DISCONNECT=2
-ITEM_STATUS=3
-ITEM_MESSAGE=4
-
-status2text = ["<idle>", "<wait-modem>", "<dialling>", "<logging in>",
- "<connected>", "<disconnecting>"]
-
-def main():
- try:
- interslip.open()
- except interslip.error, arg:
- EasyDialogs.Message("Cannot open interslip: "+arg[1])
- sys.exit(1)
- try:
- dummy = Res.GetResource('DLOG', ID_MAIN)
- except Res.Error:
- try:
- Res.OpenResFile("InterslipControl-2.rsrc")
- except Res.error:
- EasyDialogs.Message("Cannot open InterslipControl-2.rsrc: "+arg[1])
- sys.exit(1)
- InterslipControl()
-
-class InterslipControl(FrameWork.Application):
- "Application class for InterslipControl"
-
- def __init__(self):
- # First init menus, etc.
- FrameWork.Application.__init__(self)
- # Next create our dialog
- self.main_dialog = MyDialog(self)
- # Now open the dialog
- self.main_dialog.open(ID_MAIN)
- # Finally, go into the event loop
- self.mainloop()
-
- def makeusermenus(self):
- self.filemenu = m = FrameWork.Menu(self.menubar, "File")
- self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit)
-
- def quit(self, *args):
- self._quit()
-
- def do_about(self, *args):
- f = Dlg.GetNewDialog(ID_ABOUT, -1)
- while 1:
- n = Dlg.ModalDialog(None)
- if n == 1:
- return
-
- def idle(self, event):
- "Idle routine - update status"
- self.main_dialog.updatestatus()
-
-class MyDialog(FrameWork.DialogWindow):
- "Main dialog window for InterslipControl"
- def __init__(self, parent):
- FrameWork.DialogWindow.__init__(self, parent)
- self.last_status = None
- self.last_msgnum = None
-
- def do_itemhit(self, item, event):
- if item == ITEM_DISCONNECT:
- self.disconnect()
- elif item == ITEM_CONNECT:
- self.connect()
-
- def connect(self):
- try:
- interslip.connect()
- except interslip.error, arg:
- EasyDialogs.Message("Cannot connect: "+arg[1])
-
- def disconnect(self):
- try:
- interslip.disconnect()
- except interslip.error, arg:
- EasyDialogs.Message("Cannot disconnect: "+arg[1])
-
- def updatestatus(self):
- try:
- status, msgnum, msg = interslip.status()
- except interslip.error, arg:
- EasyDialogs.Message("Cannot get status: "+arg[1])
- sys.exit(1)
- if status == self.last_status and msgnum == self.last_msgnum:
- return
- self.last_status = status
- self.last_msgnum = msgnum
- if msgnum == 0:
- msg = ''
-
- try:
- txt = status2text[status]
- except IndexError:
- txt = "<unknown state %d>"%status
-
- tp, h, rect = self.wid.GetDialogItem(ITEM_STATUS)
- Dlg.SetDialogItemText(h, txt)
-
- tp, h, rect = self.wid.GetDialogItem(ITEM_MESSAGE)
- Dlg.SetDialogItemText(h, msg)
-
-main()
diff --git a/Mac/Demo/example2/InterslipControl-2.rsrc b/Mac/Demo/example2/InterslipControl-2.rsrc
deleted file mode 100644
index 432d547..0000000
--- a/Mac/Demo/example2/InterslipControl-2.rsrc
+++ /dev/null
Binary files differ
diff --git a/Mac/Demo/example2/dnslookup-2.gif b/Mac/Demo/example2/dnslookup-2.gif
new file mode 100644
index 0000000..cd5fe5f
--- /dev/null
+++ b/Mac/Demo/example2/dnslookup-2.gif
Binary files differ
diff --git a/Mac/Demo/example2/dnslookup-2.py b/Mac/Demo/example2/dnslookup-2.py
new file mode 100644
index 0000000..970b2ab
--- /dev/null
+++ b/Mac/Demo/example2/dnslookup-2.py
@@ -0,0 +1,92 @@
+import FrameWork
+import EasyDialogs
+import Res
+import Dlg
+import sys
+import socket
+import string
+#
+# Definitions for our resources
+ID_MAIN=512
+ID_ABOUT=513
+
+ITEM_LOOKUP_ENTRY=1
+ITEM_RESULT=2
+ITEM_LOOKUP_BUTTON=3
+
+def main():
+ try:
+ dummy = Res.GetResource('DLOG', ID_MAIN)
+ except Res.Error:
+ try:
+ Res.OpenResFile("dnslookup-2.rsrc")
+ except Res.Error:
+ EasyDialogs.Message("Cannot open dnslookup-2.rsrc")
+ sys.exit(1)
+ DNSLookup()
+
+class DNSLookup(FrameWork.Application):
+ "Application class for DNS Lookup"
+
+ def __init__(self):
+ # First init menus, etc.
+ FrameWork.Application.__init__(self)
+ # Next create our dialog
+ self.main_dialog = MyDialog(self)
+ # Now open the dialog
+ self.main_dialog.open(ID_MAIN)
+ # Finally, go into the event loop
+ self.mainloop()
+
+ def makeusermenus(self):
+ self.filemenu = m = FrameWork.Menu(self.menubar, "File")
+ self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit)
+
+ def quit(self, *args):
+ self._quit()
+
+ def do_about(self, *args):
+ f = Dlg.GetNewDialog(ID_ABOUT, -1)
+ while 1:
+ n = Dlg.ModalDialog(None)
+ if n == 1:
+ return
+
+class MyDialog(FrameWork.DialogWindow):
+ "Main dialog window for DNSLookup"
+ def __init__(self, parent):
+ FrameWork.DialogWindow.__init__(self, parent)
+ self.parent = parent
+
+ def do_itemhit(self, item, event):
+ if item == ITEM_LOOKUP_BUTTON:
+ self.dolookup()
+
+ def dolookup(self):
+ """Get text entered in the lookup entry area. Place result of the
+ call to dnslookup in the result entry area."""
+ tp, h, rect = self.wid.GetDialogItem(ITEM_LOOKUP_ENTRY)
+ txt = Dlg.GetDialogItemText(h)
+
+ tp, h, rect = self.wid.GetDialogItem(ITEM_RESULT)
+ Dlg.SetDialogItemText(h, self.dnslookup(txt))
+
+ def dnslookup(self, 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/example2/dnslookup-2.rsrc b/Mac/Demo/example2/dnslookup-2.rsrc
new file mode 100644
index 0000000..5276ee2
--- /dev/null
+++ b/Mac/Demo/example2/dnslookup-2.rsrc
Binary files differ