1
## /*******************************************************************************
2
## * Copyright (c) 2000, 2004 IBM Corporation and others.
3
## * All rights reserved. This program and the accompanying materials
4
## * are made available under the terms of the Eclipse Public License v1.0
5
## * which accompanies this distribution, and is available at
6
## * http://www.eclipse.org/legal/epl-v10.html
9
## * IBM Corporation - initial API and implementation
10
## *******************************************************************************/
12
## * Tree example snippet: create a tree
14
## * For a list of all SWT example snippets see
15
## * http://www.eclipse.org/swt/snippets/
17
from org.eclipse.swt import *
18
from org.eclipse.swt.widgets import *
19
from org.eclipse.swt.layout import *
20
from org.eclipse.jface.fieldassist import ControlDecoration
23
shell = Shell(display)
24
shell.setLayout(FillLayout())
26
bar = Menu(shell, SWT.BAR)
28
fileItem = MenuItem(bar, SWT.CASCADE)
29
fileItem.setText("&File")
30
submenu = Menu(shell, SWT.DROP_DOWN)
31
fileItem.setMenu(submenu)
32
item = MenuItem(submenu, SWT.PUSH)
33
item.setText("Describe")
35
composite = Composite(shell, SWT.NONE)
36
layout = GridLayout(2, False)
37
composite.setLayout(layout)
39
label = Label(composite, SWT.NONE)
41
text = Text(composite, SWT.NONE)
42
text.setToolTipText("Your Full Name Please!")
44
from org.eclipse.jface.fieldassist import FieldDecorationRegistry
46
deco = ControlDecoration(text, SWT.TOP | SWT.LEFT)
47
image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();
48
deco.setDescriptionText("Name may not be empty")
52
label2 = Label(composite, SWT.NONE)
53
label2.setText("City")
54
text2 = Text(composite, SWT.NONE)
56
deco2 = ControlDecoration(text2, SWT.TOP | SWT.RIGHT)
57
image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage();
61
class PrintListener(Listener):
62
def handleEvent(self, e):
63
print "You are", text.getText(), "and you live in", text2.getText()
65
item.addListener(SWT.Selection, PrintListener())
67
class NameListener(Listener):
68
def handleEvent(self, e):
69
if e.widget.getText():
74
text.addListener(SWT.Modify, NameListener())
76
class CityListener(Listener):
77
def handleEvent(self, e):
78
if e.widget.getText() == "London":
80
deco2.setDescriptionText("London is in England!")
84
text2.addListener(SWT.Modify, CityListener())
86
shell.setSize(200, 200)
88
while not shell.isDisposed():
89
if not display.readAndDispatch():