TreeGadget problem[resolved]

Just starting out? Need help? Post your questions and find answers here.
Mikro
New User
New User
Posts: 7
Joined: Sun Sep 17, 2006 12:53 pm
Location: Ireland

TreeGadget problem[resolved]

Post 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.
Last edited by Mikro on Fri May 18, 2007 7:31 pm, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

We can't fix your code if we can't see it.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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.
Dare2 cut down to size
Mikro
New User
New User
Posts: 7
Joined: Sun Sep 17, 2006 12:53 pm
Location: Ireland

Post by Mikro »

Thanks guys.
I didn't want to list my beginner code! :oops:
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! :(
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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
Mikro
New User
New User
Posts: 7
Joined: Sun Sep 17, 2006 12:53 pm
Location: Ireland

Post by Mikro »

Thanks Trond.
EventType was what I was missing.

Seems glaringly obvious now!

Thanks again.
Post Reply