News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
screen corruption issue
Author Message
roydobbins
Junior Member
**


Posts: 7
Group: Registered
Joined: Nov 2010
Status: Offline
Reputation: 0
Post: #1
screen corruption issue

i have the following test case which either illustrates a screen corruption issue, or i am doing something wrong:

testindex.lua to launch the script
testadmin.lua shows screen corruption when you click on one of the
entries in the (left) list box; -but- uncommenting the last two lines:-
--window:show()
--Fl:run()

then works fine!


here are the code snippets

any comments, or pointers to the problem would be appreciated

regards,
--roy dobbins


-- testindex.lua

local window = fltk:Fl_Double_Window(366, 500,"MurgaLua Test Manager")

local button=fltk:Fl_Button(50,27,24,24)
button:callback(function()
require "testadmin"
testadmin.window:show()
end)

window:show()
Fl:run()

-- testadmin.lua

module("testadmin", package.seeall)

local ww=400 --window width
local wh=350 --window height
local col=ww/4
local col2=ww-col -- column widths
local b
local br_two

function list_callback(w)
local colnames={'a','b','c','d','e','f'}
local colcount = # colnames
local colwidths = {}
for i=1,colcount do colwidths[i] = string.len(colnames[i]) * b:labelsize() end
table.insert(colwidths,0)

b:clear()
b:column_widths(colwidths)
b:column_char(string.byte('|'))

local header=""
for i=1,colcount do
if i> 1 then header=header.."|" end
header=header.."@B12@C7@b@."..colnames[i]
end
b:add(header)

for r=1,2500 do
local data=""
for i=1,colcount do
if i> 1 then data=data.."|" end
data=data..string.format("rc%d %d", r,i)
end
b:add(data)
end

window:redraw()
end

window = fltk:Fl_Double_Window(ww, wh, "test admin")

local nameedit = fltk:Fl_Input(200,0,100,25,'Name of this view...........:')
br_two=fltk:Fl_Hold_Browser(0,50,col,wh-75,"Fl_Hold_Browser")
br_two:add('1')
br_two:add('2')
br_two:add('3')
br_two:callback(list_callback)

b = fltk:Fl_Hold_Browser(col,50,col2,wh-75,"Table Browser")

fltk:Fl_End() -- end of window

--following two lines are significant to the problem!
--window:show()
--Fl:run()

-- if above two lines commented out, problem shows up
--otherwise works ok

07-29-2011 04:12 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: screen corruption issue

My guess from a quick look, it's not the last TWO lines that are causing the trouble, but the last line by itself. You already did Fl:run() once, and that is sufficient. It is, as far as I can tell, trying to run twice, trying to create two windows both called "window".

07-30-2011 12:10 AM
Find all posts by this user Quote this message in a reply
roydobbins
Junior Member
**


Posts: 7
Group: Registered
Joined: Nov 2010
Status: Offline
Reputation: 0
Post: #3
RE: screen corruption issue

mikshaw Wrote:
My guess from a quick look, it's not the last TWO lines that are causing the trouble, but the last line by itself. You already did Fl:run() once, and that is sufficient. It is, as far as I can tell, trying to run twice, trying to create two windows both called "window".


Thanks for the ideas...

I do believe though, that the problem is the other way round:

if i call Fl:run() only once, that is when the screen gets corrupted - the program works fine except for corrupting some label areas

if i call Fl:run() twice, (that is, each script has a Fl:run(), then it seems to work fine

it does seem logically that one call to Fl:run() should normally be required, but in experimenting with this program, I accidentally came across this "solution"

-what i am trying to achieve here is to have a program which can open several related windows, so that the user can view them all at once -- if there is only one window open at a time there wouldnt be a problem?

07-30-2011 07:52 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: screen corruption issue

Truly I believe Fl:run() needs to be used only once, assuming you continuously have at least one window in use. Fl:run() is essentially just a way for Fltk to stay alive...as long as there is an active window, Fltk waits. When all windows have been closed, Fltk quits.

There shouldn't be a problem opening as many windows as you want. The biggest issue in my opinion is the organization and separation of those windows within your code. Make sure your windows have unique names. If you have them all in the same level (Global table) in the same script, or loaded as code chunks into the same level, include fltk:Fl_End() to tell Fltk where each window group ends. I'd suggest either sticking with modules or other form of loaded file, as you are doing now, or creating a table for each window. If you have your windows all uniquely named and separated, you should be able to open and close them at will with show() and hide().

This post was last modified: 07-31-2011 12:41 AM by mikshaw.

07-31-2011 12:40 AM
Find all posts by this user Quote this message in a reply
roydobbins
Junior Member
**


Posts: 7
Group: Registered
Joined: Nov 2010
Status: Offline
Reputation: 0
Post: #5
RE: screen corruption issue

mikshaw Wrote:
Truly I believe Fl:run() needs to be used only once, assuming you continuously have at least one window in use. Fl:run() is essentially just a way for Fltk to stay alive...as long as there is an active window, Fltk waits. When all windows have been closed, Fltk quits.

There shouldn't be a problem opening as many windows as you want. The biggest issue in my opinion is the organization and separation of those windows within your code. Make sure your windows have unique names. If you have them all in the same level (Global table) in the same script, or loaded as code chunks into the same level, include fltk:Fl_End() to tell Fltk where each window group ends. I'd suggest either sticking with modules or other form of loaded file, as you are doing now, or creating a table for each window. If you have your windows all uniquely named and separated, you should be able to open and close them at will with show() and hide().


Thanks Mik:

yes, what you say definitely makes intuitive sense...

regarding multiple windows, yes i get that to work fine via the show hide, and i havent seen any problems with that scheme

-except- for that screen corruption scenario

right now i am baffled to explain what is going on!!!!

i tried to reduce the problem down to those two small modules
but nothing leaps out at me, eg the global naming issue you mentioned

if i come up with anything, will post the details,

--roy

07-31-2011 04:43 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: screen corruption issue

Sometimes widgets don't seem to redraw properly even when explicitly calling redraw()....I assume that would be a bug, unless there's some cases where the redraw is called too soon, maybe...just guessing. I sometimes include Fl:check() when things behave oddly like that, and sometimes it actually helps.

07-31-2011 10:26 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #7
RE: screen corruption issue

Okay, taking another look at it I'm finally seeing the corruption you were talking about. I thought that might have been intended behavior, and thought the corruption was the window failing to redraw. When uncommenting those two lines in testadmin, the corruption doesn't appear, as you said, but having Fl:run() twice does still cause a problem....after closing the main window, a second testadmin window appears.

I replaced window:redraw() with Fl:check() in testadmin.lua, leaving out the window:show() and Fl:run() at the end, and it seems to look okay.

07-31-2011 10:46 AM
Find all posts by this user Quote this message in a reply
roydobbins
Junior Member
**


Posts: 7
Group: Registered
Joined: Nov 2010
Status: Offline
Reputation: 0
Post: #8
RE: screen corruption issue

mikshaw Wrote:
Okay, taking another look at it I'm finally seeing the corruption you were talking about. I thought that might have been intended behavior, and thought the corruption was the window failing to redraw. When uncommenting those two lines in testadmin, the corruption doesn't appear, as you said, but having Fl:run() twice does still cause a problem....after closing the main window, a second testadmin window appears.

I replaced window:redraw() with Fl:check() in testadmin.lua, leaving out the window:show() and Fl:run() at the end, and it seems to look okay.


Mik:

thanks for the observations...

tried this, and as you indicated, works fine

however, the problem returns when i call up the admin window a second time (by clicking the button on the testindex screen)

07-31-2011 12:06 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #9
RE: screen corruption issue

That's odd.

I looked at it again, quickly, and can't see anything wrong with it. I have no experience using Fltk in modules, so for all I know maybe there's an issue with that. I tried moving the require to the start of the file and that didn't help. Tried adding your window:redraw() back in, and that didn't help.

One thing you can do that seems to work is use dofile() instead of require. This would mean having to make sure your variable names are unique, which for the most part they are. Personally I think modules seem to be a lot cleaner, but I don't have enough experience with them to do much debugging.

My test changes:

Code:
-- testindex.lua

local win = fltk:Fl_Double_Window(366, 500,"MurgaLua Test Manager")

local button=fltk:Fl_Button(50,27,24,24)
button:callback(function()
--require "testadmin"
--testadmin.window:show()
dofile("testadmin.lua")
end)

win:show()
Fl:run()

Code:
-- testadmin.lua

--module("testadmin", package.seeall)

local ww=400 --window width
local wh=350 --window height
local col=ww/4
local col2=ww-col -- column widths
local b
local br_two

function list_callback(w)
local colnames={'a','b','c','d','e','f'}
local colcount = # colnames
local colwidths = {}
for i=1,colcount do colwidths[i] = string.len(colnames[i]) * b:labelsize() end
table.insert(colwidths,0)

b:clear()
b:column_widths(colwidths)
b:column_char(string.byte('|'))

local header=""
for i=1,colcount do
if i> 1 then header=header.."|" end
header=header.."@B12@C7@b@."..colnames[i]
end
b:add(header)

for r=1,2500 do
local data=""
for i=1,colcount do
if i> 1 then data=data.."|" end
data=data..string.format("rc%d %d", r,i)
end
b:add(data)
end

Fl:check()
--window:redraw()
end

window = fltk:Fl_Double_Window(ww, wh, "test admin")

local nameedit = fltk:Fl_Input(200,0,100,25,'Name of this view...........:')
br_two=fltk:Fl_Hold_Browser(0,50,col,wh-75,"Fl_Hold_Browser")
br_two:add('1')
br_two:add('2')
br_two:add('3')
br_two:callback(list_callback)

b = fltk:Fl_Hold_Browser(col,50,col2,wh-75,"Table Browser")

fltk:Fl_End() -- end of window

--following two lines are significant to the problem!
window:show()
Fl:run()

07-31-2011 01:40 PM
Find all posts by this user Quote this message in a reply
roydobbins
Junior Member
**


Posts: 7
Group: Registered
Joined: Nov 2010
Status: Offline
Reputation: 0
Post: #10
RE: screen corruption issue

Thanks for the effort!

This has given me some ideas to work on...
am distracted by other projects right now, but will follow up when i have some substantial methodology for this type of (multiple window) app

08-02-2011 12:22 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: