summaryrefslogtreecommitdiffstats
path: root/Mac/IDE scripts/Widget demos
diff options
context:
space:
mode:
authorJust van Rossum <just@lettererror.com>1999-09-26 12:25:06 (GMT)
committerJust van Rossum <just@lettererror.com>1999-09-26 12:25:06 (GMT)
commita840fca15590f2369bb5381be86d13ce12563f73 (patch)
tree799bb9ec5ffb6efb132ffd8c8256eb8b8710818e /Mac/IDE scripts/Widget demos
parentb7ad821f022a62656677b03f1d081e1e284047ea (diff)
downloadcpython-a840fca15590f2369bb5381be86d13ce12563f73.zip
cpython-a840fca15590f2369bb5381be86d13ce12563f73.tar.gz
cpython-a840fca15590f2369bb5381be86d13ce12563f73.tar.bz2
Initial checkin of IDE scripts. (jvr)
Diffstat (limited to 'Mac/IDE scripts/Widget demos')
-rw-r--r--Mac/IDE scripts/Widget demos/ActivateWindowDemo.py21
-rw-r--r--Mac/IDE scripts/Widget demos/KeyTester.py34
-rw-r--r--Mac/IDE scripts/Widget demos/ListWindow.py17
-rw-r--r--Mac/IDE scripts/Widget demos/ModalDialog.py10
-rw-r--r--Mac/IDE scripts/Widget demos/PaneDemo.py14
-rw-r--r--Mac/IDE scripts/Widget demos/PaneDemo2.py16
-rw-r--r--Mac/IDE scripts/Widget demos/ScrollbarWindow.py17
-rw-r--r--Mac/IDE scripts/Widget demos/TwoLists.py22
-rw-r--r--Mac/IDE scripts/Widget demos/WidgetTest.py85
9 files changed, 236 insertions, 0 deletions
diff --git a/Mac/IDE scripts/Widget demos/ActivateWindowDemo.py b/Mac/IDE scripts/Widget demos/ActivateWindowDemo.py
new file mode 100644
index 0000000..3cd832b
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/ActivateWindowDemo.py
@@ -0,0 +1,21 @@
+import W
+
+# this demoscript illustrates how to tie a callback to activating or clicking away of the window.
+# evb 22 4 99
+
+class ActivateDemo:
+
+ def __init__(self):
+ self.w = W.Window((200, 200), 'Activate demo')
+ self.w.bind("<activate>", self.my_activate_callback)
+ self.w.open()
+
+ def my_activate_callback(self, onoff):
+ '''the callback gets 1 parameter which indicates whether the window
+ has been activated (1) or clicked to the back (0)'''
+ if onoff == 1:
+ print "I'm in the front now!"
+ else:
+ print "I've been clicked away, Oh No!"
+
+ad = ActivateDemo()
diff --git a/Mac/IDE scripts/Widget demos/KeyTester.py b/Mac/IDE scripts/Widget demos/KeyTester.py
new file mode 100644
index 0000000..ec66966
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/KeyTester.py
@@ -0,0 +1,34 @@
+"""Simple W demo -- shows how to make a window, and bind a function to a "key" event."""
+
+import W
+
+# key callback function
+def tester(char, event):
+ text = `char` + "\r" + `ord(char)` + "\r" + hex(ord(char)) + "\r" + oct(ord(char))
+ window.keys.set(text)
+
+# close callback
+def close():
+ window.close()
+
+# new window
+window = W.Dialog((180, 100), "Type a character")
+
+# make a frame (a simple rectangle)
+window.frame = W.Frame((5, 5, -5, -33))
+
+# some labels, static text
+window.captions = W.TextBox((10, 9, 43, -36), "char:\rdecimal:\rhex:\roctal:")
+
+# another static text box
+window.keys = W.TextBox((60, 9, 40, -36))
+
+# a button
+window.button = W.Button((-69, -24, 60, 16), "Done", close)
+
+# bind the callbacks
+window.bind("<key>", tester)
+window.bind("cmdw", window.button.push)
+
+# open the window
+window.open()
diff --git a/Mac/IDE scripts/Widget demos/ListWindow.py b/Mac/IDE scripts/Widget demos/ListWindow.py
new file mode 100644
index 0000000..ef066b9
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/ListWindow.py
@@ -0,0 +1,17 @@
+import W
+
+def listhit(isdbl):
+ if isdbl:
+ print "double-click in list!"
+ else:
+ print "click in list."
+
+window = W.Window((200, 400), "Window with List", minsize = (150, 200))
+
+window.list = W.List((-1, 20, 1, -14), [], listhit)
+
+# or (equivalent):
+# window.list = W.List((-1, 20, 1, -14), callback = listhit)
+
+window.list.set(range(13213, 13350))
+window.open()
diff --git a/Mac/IDE scripts/Widget demos/ModalDialog.py b/Mac/IDE scripts/Widget demos/ModalDialog.py
new file mode 100644
index 0000000..683a76a
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/ModalDialog.py
@@ -0,0 +1,10 @@
+import W
+import Windows
+
+
+w = W.ModalDialog((100, 100))
+
+w.ed = W.EditText((10, 10, 80, 50))
+w.ok = W.Button((10, 70, 80, 16), "Ok", w.close)
+w.setdefaultbutton(w.ok)
+w.open()
diff --git a/Mac/IDE scripts/Widget demos/PaneDemo.py b/Mac/IDE scripts/Widget demos/PaneDemo.py
new file mode 100644
index 0000000..5d991b0
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/PaneDemo.py
@@ -0,0 +1,14 @@
+import W
+
+w = W.Window((600, 400), "Ha!", minsize = (240, 200))
+
+w.panes = W.HorizontalPanes((8, 8, -30, -8), (0.3, 0.3, 0.4))
+w.panes.blah1 = W.EditText(None, "eehhh...")
+w.panes.blah2 = W.EditText((8, 8, -8, -8), "xxx nou...")
+w.panes.panes = W.VerticalPanes(None, (0.3, 0.4, 0.3))
+w.panes.panes.blah1 = W.EditText(None, "eehhh...")
+w.panes.panes.blah2 = W.Frame(None)
+w.panes.panes.blah2.t = W.EditText((0, 0, 0, 0), "nou...")
+w.panes.panes.blah3 = W.List(None, ["eehhh...", 'abc', 'def'])
+
+w.open()
diff --git a/Mac/IDE scripts/Widget demos/PaneDemo2.py b/Mac/IDE scripts/Widget demos/PaneDemo2.py
new file mode 100644
index 0000000..7ed06de
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/PaneDemo2.py
@@ -0,0 +1,16 @@
+import W
+
+w = W.Window((600, 400), "Ha!", minsize = (240, 200))
+
+w.panes = W.HorizontalPanes((8, 8, -8, -20), (0.6, 0.4))
+
+w.panes.panes = W.VerticalPanes(None, (0.3, 0.4, 0.3))
+w.panes.panes.blah1 = W.EditText(None, "eehhh...")
+w.panes.panes.blah2 = W.EditText(None, "nou...")
+w.panes.panes.blah3 = W.List(None, ["eehhh...", 'abc', 'def'])
+
+w.panes.group = W.Group(None)
+w.panes.group.mytext = W.EditText((0, 24, 0, 0), "eehhh...")
+w.panes.group.button1 = W.Button((0, 0, 80, 16), "A Button")
+
+w.open()
diff --git a/Mac/IDE scripts/Widget demos/ScrollbarWindow.py b/Mac/IDE scripts/Widget demos/ScrollbarWindow.py
new file mode 100644
index 0000000..5fc1b96
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/ScrollbarWindow.py
@@ -0,0 +1,17 @@
+import W
+
+# make a non-sizable window
+#window = W.Window((200, 200), "Fixed Size")
+
+# make a sizable window
+window = W.Window((200, 300), "Variable Size!", minsize = (200, 200))
+
+# make some edit text widgets
+# a scrollbar
+window.hbar = W.Scrollbar((-1, -15, -14, 16), max = 100)
+window.vbar = W.Scrollbar((-15, -1, 16, -14), max = 100)
+#window.vbar = W.Scrollbar((-15, -1, 1, -14), max = 100)
+
+
+# open the window
+window.open()
diff --git a/Mac/IDE scripts/Widget demos/TwoLists.py b/Mac/IDE scripts/Widget demos/TwoLists.py
new file mode 100644
index 0000000..ee52c89
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/TwoLists.py
@@ -0,0 +1,22 @@
+import W
+
+def twothird(width, height):
+ return (8, 8, width - 8, 2*height/3 - 4)
+
+def onethird(width, height):
+ return (8, 2*height/3 + 4, width - 8, height - 22)
+
+def halfbounds1(width, height):
+ return (0, 0, width/2 - 4, height)
+
+def halfbounds2(width, height):
+ return (width/2 + 4, 0, width, height)
+
+window = W.Window((400, 400), "Sizable window with two lists", minsize = (200, 200))
+
+window.listgroup = W.Group(twothird)
+window.listgroup.list1 = W.List(halfbounds1, range(13213, 13310))
+window.listgroup.list2 = W.List(halfbounds2, range(800, 830))
+window.et = W.EditText(onethird, "Wat nu weer?")
+
+window.open()
diff --git a/Mac/IDE scripts/Widget demos/WidgetTest.py b/Mac/IDE scripts/Widget demos/WidgetTest.py
new file mode 100644
index 0000000..edef140
--- /dev/null
+++ b/Mac/IDE scripts/Widget demos/WidgetTest.py
@@ -0,0 +1,85 @@
+import W
+
+# define some callbacks
+def callback():
+ window.close()
+
+def checkcallback(value):
+ print "hit the checkbox", value
+
+def radiocallback(value):
+ print "hit radiobutton #3", value
+
+def scrollcallback(value):
+ widget = window.hbar
+ if value == "+":
+ widget.set(widget.get() - 1)
+ elif value == "-":
+ widget.set(widget.get() + 1)
+ elif value == "++":
+ widget.set(widget.get() - 10)
+ elif value == "--":
+ widget.set(widget.get() + 10)
+ else: # in thumb
+ widget.set(value)
+ print "scroll...", widget.get()
+
+def textcallback():
+ window.et3.set(window.et1.get())
+
+def cancel():
+ import EasyDialogs
+ EasyDialogs.Message("Cancel!")
+
+# make a non-sizable window
+#window = W.Window((200, 300), "Fixed Size")
+
+# make a sizable window
+window = W.Window((200, 300), "Variable Size!", minsize = (200, 300))
+
+# make some edit text widgets
+window.et1 = W.EditText((10, 10, 110, 110), "Hallo!", textcallback)
+window.et2 = W.EditText((130, 40, 60, 30), "one!")
+window.et3 = W.EditText((130, 80, -10, 40), "two?")
+
+# a button
+window.button = W.Button((-70, 10, 60, 16), "Close", callback)
+
+# a checkbox
+window.ch = W.CheckBox((10, 130, 160, 16), "Check (command §)", checkcallback)
+
+# set of radio buttons (should become easier/nicer)
+thebuttons = []
+window.r1 = W.RadioButton((10, 150, 180, 16), "Radio 1 (cmd 1)", thebuttons)
+window.r2 = W.RadioButton((10, 170, 180, 16), "Radio 2 (cmd 2)", thebuttons)
+window.r3 = W.RadioButton((10, 190, 180, 16), "Radio 3 (cmd 3)", thebuttons, radiocallback)
+window.r1.set(1)
+
+# a normal button
+window.cancelbutton = W.Button((10, 220, 60, 16), "Cancel", cancel)
+
+# a scrollbar
+window.hbar = W.Scrollbar((-1, -15, -14, 16), scrollcallback, max = 100)
+
+# some static text
+window.static = W.TextBox((10, 260, 110, 16), "Schtatic")
+
+# bind some keystrokes to functions
+window.bind('cmd§', window.ch.push)
+window.bind('cmd1', window.r1.push)
+window.bind('cmd2', window.r2.push)
+window.bind('cmd3', window.r3.push)
+window.bind('cmdw', window.button.push)
+window.bind('cmd.', window.cancelbutton.push)
+
+window.setdefaultbutton(window.button)
+# open the window
+window.open()
+
+if 0:
+ import time
+ for i in range(20):
+ window.et2.set(`i`)
+ #window.et2.SetPort()
+ #window.et2.draw()
+ time.sleep(0.1)