Page 1 of 1

Menu help

Posted: Thursday 3rd September 2020 10:07pm
by BruceSteers
Hi folks :)

I'm adding menu's to Gform and i have a problem :(
the following code works , i pass the arguments
menu name|parent to attach to|Menu Text|flags
I create the first menu using this function and give it no parent name so it attaches top level to the form
Then the next menu i pass the first menu name as the parent.
It all works , i get a menu at the top of the form and get the MENU_Click() event.

Code: Select all

Private Function makeMenu(txt As String)  '  name|parent|Menu Text|flags
Dim m As Menu, s As String, a As Array
s = Replace(txt, "\"", "")
a = Split(s, Sep)
If a[1] = "" Or a[1] = "form" Then
 m = New Menu(frm) 'As "MENU"
Else
 m = New Menu(FindMenu(a[1])) As "MENU"
Endif
m.Name = a[0]
m.Enabled = True
If a.count > 2 Then m.Text = a[2]
If a.Count = 4 Then MFlags(m, a[a.Max])
End

Private Sub FindMenu(n As String) As Menu
Dim c, c2 As Integer
For c = 0 To frm.Menus.Count - 1
  If frm.Menus[c].Name = n Then Return frm.Menus[c]
  For c2 = 0 To frm.Menus[c].Children.Count - 1
   If frm.Menus[c].Children[c2].Name = n Then Return frm.Menus[c].Children[c2]
  Next
Next
Return Null
End
But...
The problem is if i set the first top level menu .Visible setting to False and give any of the objects a .PopupMenu setting of the menu name (Like i would in the IDE) I get the popup menu okay attached to the object but it doesn't fire the MENU_Click() event :(
If i leave the .Visible flag as True the menu shows on both the form and on the control and i get the click event from the main menu but not the popup one on the control ?

Any help appreciated :)

Re: Menu help

Posted: Friday 4th September 2020 9:17am
by PJBlack
did you reported that behavior to the gambas bugtracker?

Re: Menu help

Posted: Friday 4th September 2020 10:01am
by BruceSteers
Didn't know there was a bugtracker.

Wasn't sure if i'd found a bug or was doing something wrong. thought I'd ask the experts first ;)

Re: Menu help

Posted: Friday 4th September 2020 1:48pm
by cogier
It would help if the code you posted actually ran. The 'Sep', 'frm' & 'MFlags' are not setup.

Re: Menu help

Posted: Friday 4th September 2020 2:06pm
by PJBlack
BruceSteers wrote: Friday 4th September 2020 10:01am Didn't know there was a bugtracker.
http://gambas.sourceforge.net/en/main.html

only minisini can tell if it's a feature or a bug ... ;)

Re: Menu help

Posted: Friday 4th September 2020 4:57pm
by BruceSteers
cogier wrote: Friday 4th September 2020 1:48pm It would help if the code you posted actually ran. The 'Sep', 'frm' & 'MFlags' are not setup.
I think it's an ide bug.
I just made a test script to post with full source for and found the menu works as expected, both main and popup working when running the exe with a script. Through the ide, setting arguments and running that way I get the error 🤔

Re: Menu help

Posted: Friday 4th September 2020 5:53pm
by BruceSteers
BruceSteers wrote: Friday 4th September 2020 4:57pm
cogier wrote: Friday 4th September 2020 1:48pm It would help if the code you posted actually ran. The 'Sep', 'frm' & 'MFlags' are not setup.
I think it's an ide bug.
I just made a test script to post with full source for and found the menu works as expected, both main and popup working when running the exe with a script. Through the ide, setting arguments and running that way I get the error 🤔
Scrap what i said there..
I've done some more testing , it seems the difference in it working or not is if i've used the "listen=/tmp/fifo2" arg that sets up the listening pipe and uses the File_Read() event.

I've attached the complete source and a test script with the listen arg commented out.
uncomment the listen arg to see the difference in opperation (run in terminal to see messages)

Functions relevant in the Script are..
SetUpListen() opens the listening pipe , sets hFile.Blocking to false as this allows using if Eof() on the pipe
without locking up. possibly a relevant flag.
File_Read() the listening pipe read event (is there a way to set a custom read event and leave File_Read() be?

MakeMenu() creates the menu items ' not sure if the problem is the menu making as main menu seems to work.

seems using the File_Read() event is blocking the popup menu event message or something?

Re: Menu help

Posted: Friday 4th September 2020 6:25pm
by BruceSteers
Phew..
I've been 2 days trying to figure this out lol.

I finally found a fix. Still not sure I'm doing it right but it's working now at least.

I don't get the error if i don't use the 'Write' parameter when opening the pipe.
But without using the Write arg the pipe would hang.
So , found if I 'Shell' an echo command to the pipe before opening it for Read only this freed the lockup and also cured my menu issue.

Code: Select all

Public Sub SetUpListen(fname As String)
listen = True
listenFile = fname
Shell "echo '' >'" & listenfile & "'"
hFile = Pipe listenFile For Read Watch
hFile.Blocking = False
End
I tried all sorts of combinations of Open Pipe listenfile For Read Write Create Watch Blah Blah
Only solution i found was a manual echo before the open , That can't be right though?