digitalmars.D.dwt - Timer in DWT?
- Sam Hu (5/5) Sep 08 2008 Hi Frank,
- Bill Baxter (7/12) Sep 08 2008 What's a timer control in your parlance?
- Sam Hu (3/3) Sep 08 2008 Thanks BB,
- Frank Benoit (9/26) Sep 08 2008 I would understand that as the callback thing.
- Sam Hu (22/22) Sep 08 2008 Hi Frank,
- Bill Baxter (14/32) Sep 08 2008 This only executes the timer once. You have to call timerExec again
- Sam Hu (45/45) Sep 08 2008 Thanks BB,now it works when the run() method is invoked in the Initializ...
- Frank Benoit (4/54) Sep 08 2008 the call to run() in the ctor is not executed, because the program is
- Sam Hu (2/2) Sep 08 2008 Ah ~~ So stupid question...while(){}...
- Bill Baxter (3/5) Sep 08 2008 FB gets the credit for that one. :-)
Hi Frank, Just a stupid question:is there a timer control in DWT?If no,then how to implement the same ? Thanks, Regards, Sam
Sep 08 2008
On Mon, Sep 8, 2008 at 4:42 PM, Sam Hu <samhu.samhu gmail.com> wrote:Hi Frank, Just a stupid question:is there a timer control in DWT?If no,then how to implement the same ? Thanks, Regards, SamWhat's a timer control in your parlance? Is that like a progress meter? Or do you mean just a timer object that can trigger a callback after a fixed interval (and not a GUI control)? Or something else? --bb
Sep 08 2008
Thanks BB, I mean just a timer object or something like that which can trigger a callback after a fixed interval (and not a GUI control). Sam
Sep 08 2008
Bill Baxter schrieb:On Mon, Sep 8, 2008 at 4:42 PM, Sam Hu <samhu.samhu gmail.com> wrote:I would understand that as the callback thing. There is in dwt.widgets.Display public void timerExec(int milliseconds, Runnable runnable) Search through the dwt-samples and you will find several hits. Tip: Use the dgRunnable template function: Display.getCurrent.timerExec( 500, dgRunnable({ // handler code }));Hi Frank, Just a stupid question:is there a timer control in DWT?If no,then how to implement the same ? Thanks, Regards, SamWhat's a timer control in your parlance? Is that like a progress meter? Or do you mean just a timer object that can trigger a callback after a fixed interval (and not a GUI control)? Or something else? --bb
Sep 08 2008
Hi Frank, For example,I want to draw a line of text on the form which indicate the current date and time,very second it changes.Below is the code I tried,when I run the program,the drawn text does not change every second if I won't resize the form.I think it is the canvas.redraw method which is the problem,but I don't know which method shoud I use instead. //************************* Display display=new Display; Shell shell=new Shell(display); Canvas canvas=new Canvas(shell,DWT.NONE); canvas.addPaintListener(new class PaintListener{ public void paintControl(PaintEvent e) { auto layout=new Locale; e.gc.drawText(layout("{:ddd,dd MMMM yyyy HH':'mm':'ss z}", WallClock.now),100,100); } }); display.getCurrent.timerExec( 500, dgRunnable({ canvas.redraw; })); //***************************** Please help.Thanks. Sam
Sep 08 2008
On Tue, Sep 9, 2008 at 9:41 AM, Sam Hu <samhu.samhu gmail.com> wrote:Hi Frank, For example,I want to draw a line of text on the form which indicate the current date and time,very second it changes.Below is the code I tried,when I run the program,the drawn text does not change every second if I won't resize the form.I think it is the canvas.redraw method which is the problem,but I don't know which method shoud I use instead. //************************* Display display=new Display; Shell shell=new Shell(display); Canvas canvas=new Canvas(shell,DWT.NONE); canvas.addPaintListener(new class PaintListener{ public void paintControl(PaintEvent e) { auto layout=new Locale; e.gc.drawText(layout("{:ddd,dd MMMM yyyy HH':'mm':'ss z}", WallClock.now),100,100); } }); display.getCurrent.timerExec( 500, dgRunnable({ canvas.redraw; })); //*****************************This only executes the timer once. You have to call timerExec again in the delegate to get it to display again. So I think you /may/ need to go ahead and create a Runnable subclass to make it work. Like this: class EverySecond : Runnable { void run() { canvas.redraw; display.getCurrent.timerExec(500, this); } } That may also require you to make canvas and display members of EverySecond. --bb
Sep 08 2008
Thanks BB,now it works when the run() method is invoked in the InitializeComponents() method,but it does not work when invoked in the ctor.How come? Thanks,Sam class MainForm:Runnable { private: Display display; Shell shell; Canvas canvas; void InitializeComponents() { display=new Display; shell=new Shell(display); canvas=new Canvas(shell,DWT.NONE); canvas.addPaintListener(new class PaintListener{ public void paintControl(PaintEvent e) { auto layout=new Locale; e.gc.drawText(layout("{:dddd,dd MMMM yyyy HH':'mm':'ss z}", WallClock.now),100,100); }}); run; shell.open; while(! shell.isDisposed) { if(! display.readAndDispatch) display.sleep; } display.dispose; } public: this() { InitializeComponents; run;//invoke run() method here does not work? } void run() { canvas.redraw; display.getCurrent.timerExec(1000, this); } } int main(char[][] args) { MainForm mainForm=new MainForm; return 0; }
Sep 08 2008
Sam Hu schrieb:Thanks BB,now it works when the run() method is invoked in the InitializeComponents() method,but it does not work when invoked in the ctor.How come? Thanks,Sam class MainForm:Runnable { private: Display display; Shell shell; Canvas canvas; void InitializeComponents() { display=new Display; shell=new Shell(display); canvas=new Canvas(shell,DWT.NONE); canvas.addPaintListener(new class PaintListener{ public void paintControl(PaintEvent e) { auto layout=new Locale; e.gc.drawText(layout("{:dddd,dd MMMM yyyy HH':'mm':'ss z}", WallClock.now),100,100); }}); run; shell.open; while(! shell.isDisposed) { if(! display.readAndDispatch) display.sleep; } display.dispose; } public: this() { InitializeComponents; run;//invoke run() method here does not work? } void run() { canvas.redraw; display.getCurrent.timerExec(1000, this); } } int main(char[][] args) { MainForm mainForm=new MainForm; return 0; }the call to run() in the ctor is not executed, because the program is hanging in the InitializeComponents() while loop. Only if the window is closed, the loop is left and then the run is called ... too late.
Sep 08 2008
Ah ~~ So stupid question...while(){}... Thanks BB!
Sep 08 2008
On Tue, Sep 9, 2008 at 3:50 PM, Sam Hu <samhu.samhu gmail.com> wrote:Ah ~~ So stupid question...while(){}... Thanks BB!FB gets the credit for that one. :-) --bb
Sep 08 2008