Menu help

Post

Posted
Rating:
#1 (In Topic #453)
Guru
BruceSteers is in the usergroup ‘Guru’
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

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  :)
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
did you reported that behavior to the gambas bugtracker?
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
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 ;)
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
 It would help if the code you posted actually ran. The 'Sep', 'frm' & 'MFlags' are not setup.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’

BruceSteers said

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 … ;)
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’

cogier said

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 <EMOJI seq="1f914" tseq="1f914">🤔</EMOJI>
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

BruceSteers said

cogier said

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 <EMOJI seq="1f914" tseq="1f914">🤔</EMOJI>

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?
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
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

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?
Online now: No Back to the top
1 guest and 0 members have just viewed this.