~geoff.bache/storytext/selftest-trunk

« back to all changes in this revision

Viewing changes to swt/jface/text_decoration/target_ui.py

  • Committer: Geoff Bache
  • Date: 2011-10-31 16:53:18 UTC
  • Revision ID: geoff.bache@jeppesen.com-20111031165318-j0vj5mpxl2pkee18
New test for jface text decorations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
##  *
 
8
##  * Contributors:
 
9
##  *     IBM Corporation - initial API and implementation
 
10
##  *******************************************************************************/
 
11
## /*
 
12
##  * Tree example snippet: create a tree
 
13
##  *
 
14
##  * For a list of all SWT example snippets see
 
15
##  * http://www.eclipse.org/swt/snippets/
 
16
## */
 
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
 
21
 
 
22
display = Display()
 
23
shell = Shell(display)
 
24
shell.setLayout(FillLayout())
 
25
 
 
26
bar = Menu(shell, SWT.BAR)
 
27
shell.setMenuBar(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")
 
34
 
 
35
composite = Composite(shell, SWT.NONE)
 
36
layout = GridLayout(2, False)
 
37
composite.setLayout(layout)
 
38
 
 
39
label = Label(composite, SWT.NONE)
 
40
label.setText("Name")
 
41
text = Text(composite, SWT.NONE)
 
42
text.setToolTipText("Your Full Name Please!")
 
43
 
 
44
from org.eclipse.jface.fieldassist import FieldDecorationRegistry
 
45
 
 
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")
 
49
deco.setImage(image)
 
50
 
 
51
 
 
52
label2 = Label(composite, SWT.NONE)
 
53
label2.setText("City")
 
54
text2 = Text(composite, SWT.NONE)
 
55
 
 
56
deco2 = ControlDecoration(text2, SWT.TOP | SWT.RIGHT)
 
57
image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage();
 
58
deco2.setImage(image)
 
59
deco2.hide()
 
60
 
 
61
class PrintListener(Listener):
 
62
    def handleEvent(self, e):
 
63
        print "You are", text.getText(), "and you live in", text2.getText()
 
64
        
 
65
item.addListener(SWT.Selection, PrintListener())
 
66
 
 
67
class NameListener(Listener):
 
68
    def handleEvent(self, e):
 
69
        if e.widget.getText():
 
70
            deco.hide()
 
71
        else:
 
72
            deco.show()
 
73
 
 
74
text.addListener(SWT.Modify, NameListener())
 
75
 
 
76
class CityListener(Listener):
 
77
    def handleEvent(self, e):
 
78
        if e.widget.getText() == "London":
 
79
            deco2.show()
 
80
            deco2.setDescriptionText("London is in England!")
 
81
        else:
 
82
            deco2.hide()
 
83
 
 
84
text2.addListener(SWT.Modify, CityListener())
 
85
 
 
86
shell.setSize(200, 200)
 
87
shell.open()
 
88
while not shell.isDisposed():
 
89
    if not display.readAndDispatch():
 
90
        display.sleep()
 
91
 
 
92
display.dispose()