| 1 |
module user.torhu_synctest; |
|---|
| 2 |
|
|---|
| 3 |
import dwt.DWT; |
|---|
| 4 |
import dwt.dwthelper.Runnable; |
|---|
| 5 |
import dwt.widgets.Display; |
|---|
| 6 |
import dwt.widgets.Shell; |
|---|
| 7 |
import dwt.widgets.Button; |
|---|
| 8 |
import dwt.widgets.Synchronizer; |
|---|
| 9 |
import dwt.widgets.Text; |
|---|
| 10 |
|
|---|
| 11 |
import tango.core.Thread; |
|---|
| 12 |
import tango.io.Stdout; |
|---|
| 13 |
import tango.math.Math; |
|---|
| 14 |
import tango.text.convert.Format; |
|---|
| 15 |
import tango.util.Convert; |
|---|
| 16 |
import tango.util.PathUtil; |
|---|
| 17 |
import dwt.events.SelectionListener; |
|---|
| 18 |
import dwt.events.SelectionEvent; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
void main(){ |
|---|
| 22 |
|
|---|
| 23 |
try{ |
|---|
| 24 |
|
|---|
| 25 |
Display display = new Display(); |
|---|
| 26 |
Shell shell = new Shell(display); |
|---|
| 27 |
shell.setSize(300, 200); |
|---|
| 28 |
shell.setText("Simple DWT Sample"); |
|---|
| 29 |
auto btn = new Button( shell, DWT.PUSH ); |
|---|
| 30 |
btn.setBounds(40, 50, 100, 50); |
|---|
| 31 |
btn.setText( "test syncExec" ); |
|---|
| 32 |
|
|---|
| 33 |
auto txt = new Text(shell, DWT.BORDER); |
|---|
| 34 |
txt.setBounds(170, 50, 100, 40); |
|---|
| 35 |
|
|---|
| 36 |
auto t = new Thread({Display.getDefault.syncExec(new class Runnable { |
|---|
| 37 |
void run() { txt.setText("inside syncExec"); } |
|---|
| 38 |
});}); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
btn.addSelectionListener(new class () SelectionListener { |
|---|
| 42 |
public void widgetSelected(SelectionEvent event) { |
|---|
| 43 |
|
|---|
| 44 |
t.start(); |
|---|
| 45 |
} |
|---|
| 46 |
public void widgetDefaultSelected(SelectionEvent event) { |
|---|
| 47 |
//txt.setText("No worries!"); |
|---|
| 48 |
} |
|---|
| 49 |
}); |
|---|
| 50 |
|
|---|
| 51 |
shell.open(); |
|---|
| 52 |
while (!shell.isDisposed()) { |
|---|
| 53 |
if (!display.readAndDispatch()) { |
|---|
| 54 |
display.sleep(); |
|---|
| 55 |
Stdout( "." ).flush; |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
catch (Exception e) { |
|---|
| 60 |
Stdout.formatln (e.toString); |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|