1. wxEuphoria woes
- Posted by D. Newhall <derek_newhall at yahoo.com>
Sep 08, 2005
-
Last edited Sep 09, 2005
I've been messing around with wxEuphoria recently trying to learn it (if I'm
going to use GUIs they're going to have to be cross-platform) and I've writen a
simple program that just displays my TODO list in a window. However, after
leaving it running for a few seconds in MS Windows or moving the window the
Windows Task Manager says that EXW.EXE is using around 50% of my CPU (it starts
at 0%) which causes the screen to lock up at times (I have to ctrl-alt-delete and
kill it when that happens). All the program does is open a file and show its
contents so I'm wondering if this is caused by a bug in wxEuphoria or my code or
if that's just how wxEuphoria acts.
Here's my code:
without warning
include wxEuphoria.e
include wxGraphics.e
constant TASKS_FILE = "TODO.txt"
integer fn
fn = open(TASKS_FILE, "r")
if fn = -1 then
fn = message_box( sprintf("Can't open file %s.", {TASKS_FILE}), "", 0 )
abort(1)
end if
sequence tasks
tasks = {}
object line
line = gets(fn)
while sequence(line) do
tasks = append(tasks, line)
line = gets(fn)
end while
constant FRAME = create(wxFrame, {0, -1, "TODO list", -1, -1, 200, 200})
constant WINDOW = create(wxPanel, {FRAME})
procedure print_tasks(atom this, atom event, atom it, atom event_type)
atom dc
dc = create( wxPaintDC, {this})
for i=1 to length(tasks) do
wx_puts({this, 0, (i-1) * 15, dc}, tasks[i])
end for
end procedure
set_event_handler(WINDOW, get_id(WINDOW), wxEVT_PAINT,
routine_id("print_tasks"))
wxMain(FRAME)
The Euphoria Standard Library project :
http://esl.sourceforge.net/
The Euphoria Standard Library mailing list :
https://lists.sourceforge.net/lists/listinfo/esl-discussion
2. Re: wxEuphoria woes
- Posted by cklester <cklester at yahoo.com>
Sep 08, 2005
-
Last edited Sep 09, 2005
D. Newhall wrote:
>
>
> integer fn
> fn = open(TASKS_FILE, "r")
You never close this file... maybe that's the problem.
close(fn)
I just tried it and closing the file doesn't matter... :/
-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/
3. Re: wxEuphoria woes
- Posted by cklester <cklester at yahoo.com>
Sep 08, 2005
-
Last edited Sep 09, 2005
D. Newhall wrote:
> set_event_handler(WINDOW, get_id(WINDOW), wxEVT_PAINT,
> routine_id("print_tasks"))
Okay, you've set it so that every time your window gets repainted, you
run the "print_tasks" item. Probably not a good idea, because it gets
repainted a billion times a second.
Try putting that in the wxEVT_RESIZE or wxEVT_OPEN (or whatever is
appropriate).
-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/
4. Re: wxEuphoria woes
- Posted by cklester <cklester at yahoo.com>
Sep 08, 2005
-
Last edited Sep 09, 2005
D. Newhall wrote:
>
> procedure print_tasks(atom this, atom event, atom it, atom event_type)
> atom dc
> dc = create( wxPaintDC, {this})
>
> for i=1 to length(tasks) do
> wx_puts({this, 0, (i-1) * 15, dc}, tasks[i])
> end for
-- ADD THIS
delete_instance(dc)
> end procedure
That fixed it.
-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/
5. Re: wxEuphoria woes
- Posted by cklester <cklester at yahoo.com>
Sep 08, 2005
-
Last edited Sep 09, 2005
cklester wrote:
> D. Newhall wrote:
> > set_event_handler(WINDOW, get_id(WINDOW), wxEVT_PAINT,
> > routine_id("print_tasks"))
> Okay, you've set it so that every time your window gets repainted, you
> run the "print_tasks" item. Probably not a good idea, because it gets
> repainted a billion times a second.
> Try putting that in the wxEVT_RESIZE or wxEVT_OPEN (or whatever is
> appropriate).
PSA: Always ignore all my helpful posts, except the very last one. 8)
-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/
6. Re: wxEuphoria woes
- Posted by D. Newhall <derek_newhall at yahoo.com>
Sep 08, 2005
-
Last edited Sep 09, 2005
cklester wrote:
>
> D. Newhall wrote:
> >
> > procedure print_tasks(atom this, atom event, atom it, atom event_type)
> > atom dc
> > dc = create( wxPaintDC, {this})
> >
> > for i=1 to length(tasks) do
> > wx_puts({this, 0, (i-1) * 15, dc}, tasks[i])
> > end for
> -- ADD THIS
> delete_instance(dc)
>
> > end procedure
>
> That fixed it.
>
> -=ck
> "Programming in a state of EUPHORIA."
> <a
> href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a>
>
Yep, that did it. Thanks!
The Euphoria Standard Library project :
http://esl.sourceforge.net/
The Euphoria Standard Library mailing list :
https://lists.sourceforge.net/lists/listinfo/esl-discussion
7. Re: wxEuphoria woes
D. Newhall wrote:
>
> cklester wrote:
> >
> > D. Newhall wrote:
> > >
> > > procedure print_tasks(atom this, atom event, atom it, atom event_type)
> > > atom dc
> > > dc = create( wxPaintDC, {this})
> > >
> > > for i=1 to length(tasks) do
> > > wx_puts({this, 0, (i-1) * 15, dc}, tasks[i])
> > > end for
> > -- ADD THIS
> > delete_instance(dc)
> >
> > > end procedure
> >
> > That fixed it.
> >
> > -=ck
> > "Programming in a state of EUPHORIA."
> > <a
> > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a>
> >
>
> Yep, that did it. Thanks!
>
It's usually better to put these sorts of things into a wxListBox or
something, which will handle all the repainting for you. Of course, I
understand this is a learning exercise, but generally you probably don't
want to do your own painting/printing.
Matt Lewis