Page 1 of 1
TreeGadget problem[resolved]
Posted: Fri May 18, 2007 11:39 am
by Mikro
Hi All.
This is most likely a really stupid error on my part but I've had a look through the forum and haven't found out what I should do.
Basically, I have a treegadget with a few items added. These are URLs that I intend to click on and open the relevant page with runprogram.
This all works fine if IE isn't already opened. If it is already opened it opens 2 or 3 (or 4 or 5!) identical tabs rather than only one.
What I need to do in my code is ensure that my runprogram statement is fired only once but I don't know how to 'deselect' the treeitem I've just clicked on so that it doesn't get fired again next time through the event loop.
Hope some of this makes sense.
Thanks in advance.
M.
Posted: Fri May 18, 2007 12:51 pm
by Trond
We can't fix your code if we can't see it.
Posted: Fri May 18, 2007 1:43 pm
by Dare
As Trond said.
Without knowing exactly what you're doing - can't you just keep track of it via you own code? Store the value, check to see if the returned value has been used, don't do it again if already done.
Posted: Fri May 18, 2007 2:32 pm
by Mikro
Thanks guys.
I didn't want to list my beginner code!
Anyway, here is a snippet of the code in question. As I say, it's probably something silly I've done.
I don't know how to 'reset' the treegadget. I mean, after clicking on an entry once, the browser will open. But if I click anywhere on the treegadget again (to expand it say, it will still fire the runprogram line as the previous selection is still active). I'm just not sure of how to differentiate between me ckicking on a node or an actual item. NB. This is in addition to the browser sometimes firing twice on each click.
Code: Select all
For x=0 To 9
AddGadgetItem(2,-1,"Test" + Str(x),0,0)
AddGadgetItem(2,-1,"www.google.com",0,1)
AddGadgetItem(2,-1,"www.bbc.co.uk",0,1)
Next x
Repeat
MainEvent = WaitWindowEvent()
Select MainEvent
Case #PB_Event_Gadget
Select EventGadget()
Case 2 ;this is the treegadget
item =GetGadgetState(2)
If Left(GetGadgetItemText(2,item,0),3)="www"
RunProgram(GetGadgetItemText(2,item,0))
SetGadgetItemState(2,item,#PB_Tree_Checked) ;this is probably wrong, trying to reset the gadget
EndIf
EndSelect
EndSelect
Until MainEvent = #PB_Event_CloseWindow
Thanks for any help you have. It's not for a particular project or anything. I was just playing around in a bit of freetime I had, never get a good chance to use my PB!

Posted: Fri May 18, 2007 4:06 pm
by Trond
Check for the event type:
Code: Select all
OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
TreeGadget(2, 10, 10, 400, 300)
For x=0 To 9
AddGadgetItem(2,-1,"Test" + Str(x),0,0)
AddGadgetItem(2,-1,"www.google.com",0,1)
AddGadgetItem(2,-1,"www.bbc.co.uk",0,1)
Next x
Repeat
MainEvent = WaitWindowEvent()
Select MainEvent
Case #PB_Event_Gadget
Select EventGadget()
Case 2
If EventType() = #PB_EventType_LeftDoubleClick
item = GetGadgetState(2)
If Left(GetGadgetItemText(2,item,0),3)="www"
Debug (GetGadgetItemText(2,item,0))
EndIf
EndIf
EndSelect
EndSelect
Until MainEvent = #PB_Event_CloseWindow
Posted: Fri May 18, 2007 7:35 pm
by Mikro
Thanks Trond.
EventType was what I was missing.
Seems glaringly obvious now!
Thanks again.