Menu help

Post Reply
User avatar
BruceSteers
Posts: 156
Joined: Thursday 23rd July 2020 5:20pm

Menu help

Post by BruceSteers » Thursday 03rd September 2020 10:07pm

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 :)
If at first you don't succeed , try it differently.

PJBlack
Posts: 29
Joined: Tuesday 09th June 2020 10:26pm

Re: Menu help

Post by PJBlack » Friday 04th September 2020 9:17am

did you reported that behavior to the gambas bugtracker?

User avatar
BruceSteers
Posts: 156
Joined: Thursday 23rd July 2020 5:20pm

Re: Menu help

Post by BruceSteers » Friday 04th September 2020 10:01am

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 ;)
If at first you don't succeed , try it differently.

User avatar
cogier
Site Admin
Posts: 517
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Menu help

Post by cogier » Friday 04th September 2020 1:48pm

It would help if the code you posted actually ran. The 'Sep', 'frm' & 'MFlags' are not setup.

PJBlack
Posts: 29
Joined: Tuesday 09th June 2020 10:26pm

Re: Menu help

Post by PJBlack » Friday 04th September 2020 2:06pm

BruceSteers wrote:
Friday 04th 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 ... ;)

User avatar
BruceSteers
Posts: 156
Joined: Thursday 23rd July 2020 5:20pm

Re: Menu help

Post by BruceSteers » Friday 04th September 2020 4:57pm

cogier wrote:
Friday 04th 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 🤔
If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 156
Joined: Thursday 23rd July 2020 5:20pm

Re: Menu help

Post by BruceSteers » Friday 04th September 2020 5:53pm

BruceSteers wrote:
Friday 04th September 2020 4:57pm
cogier wrote:
Friday 04th 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?
Attachments
GForm.zip
(68.21 KiB) Downloaded 37 times
If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 156
Joined: Thursday 23rd July 2020 5:20pm

Re: Menu help

Post by BruceSteers » Friday 04th September 2020 6:25pm

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?
If at first you don't succeed , try it differently.

Post Reply