Tray Icon broken?

Post

Posted
Rating:
#1 (In Topic #1580)
Regular
JMathers is in the usergroup ‘Regular’
 Quick Question, is the Tray Icon broken? or just limited to Left click / middle mouse only?
(gb.gui.trayIcon)

i tried to make a right click tray icon, and there is no code for it.

I can get the left click / middle mouse button, working just fine. but right doesn't seem to work / exist, every time i try, it just crashes outright.

is that intentional? or? bug?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Right click is for the PopupMenu so add a PopupMenu to it.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
JMathers is in the usergroup ‘Regular’
that is what i was saying / doing.

sorry for not being clear about it.
i was trying to create a pop up menu to my app, using the right mouse button.
with the trayicon extention.
here is a small snippet.
(this works for left and middle mouse button, when i change it to the right mouse button, it just straight up crashes)


Code

Private $hPopup As Menu
Public Sub TrayIcon1_Click()
 ' Me.show
 
  $hPopup = New Menu(Me, True)
 Dim hMenu As Menu
  ' we only want right clicks
 
  $hPopup.Children.Clear  ' clear main popup menu parent items
 
' i just make some menus here. i guess for your needs the creation would be more dynamic/varied.
 
  hMenu = New Menu($hPopup) As "POP"  ' make a menu item in $hPopup and use event name POP
  hMenu.Name = "M1"
  hMenu.Text = "Show"  ' make text
 
  hMenu = New Menu($hPopup) As "POP"  ' make another menu item in $hPopup and again use event name POP
  hMenu.Name = "M2"
  hMenu.Text = "Stop"  ' make text
 
  hMenu = New Menu($hPopup)  ' make a menu item in $hPopup with no event as it's a spacer
  ' do not enter any text so it becomes a spacer
 
  hMenu = New Menu($hPopup) As "POP"  ' make another menu item in $hPopup and again use event name POP
  hMenu.Name = "M3"
  hMenu.Text = "Close"  ' make text
 
  $hPopup.Popup  ' show the menu at mouse position
    
End
    
     
Public Sub POP_Click()  ' all menus share event POP so in the event we detect the menu name to distinguish between them
  Select Last.Name
  Case "M1"
  If Me.Visible = False Then Me.Visible = True
  Case "M2"
  btn_stop_Click
  Case "M3"
    TrayIcon1.Hide  
    TrayIcon1.Delete
    Me.Close
 End Select
 End
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
No sorry I guess I was also unclear.

I mean use the TrayIcon.PopupMenu property.

/comp/gb.gui.trayicon/trayicon/popupmenu - Gambas Documentation
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
How to create a dynamically managed menu for trayicon…

Code (gambas)

  1.  
  2. Private $hPopup As Menu
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   $hPopup = New Menu(Me, True) As "POPUP"  ' give the top menu an event name (i chose POPUP)
  7.   $hPopup.Name = "POPUP"  ' Set the Name so it can be found.
  8.   Dim hDummy as Menu = New Menu($hPopup)  ' give the top menu at least 1 child or it might not want to attempt to open.
  9.  
  10.   TrayIcon1.PopupMenu = "POPUP"   ' this adds the menu named "POPUP" to the trayicon.
  11.  
  12.  
  13. Public Sub POPUP_Show() ' this is now called just before $hPopup opens.
  14. ' Note, because it is the trayicon PopupMenu property the right click is automatically detected and does not require any code.
  15.  
  16. ' Dynamically create the children for $hPopup before it shows...
  17.  
  18.  Dim hMenu As Menu
  19.  
  20.   $hPopup.Children.Clear  ' clear main popup menu parent items
  21.  
  22. ' i just make some menus here. i guess for your needs the creation would be more dynamic/varied.
  23.  
  24.   hMenu = New Menu($hPopup) As "POP"  ' make a menu item in $hPopup and use event name POP
  25.   hMenu.Name = "M1"
  26.   hMenu.Text = "Show"  ' make text
  27.  
  28.   hMenu = New Menu($hPopup) As "POP"  ' make another menu item in $hPopup and again use event name POP
  29.   hMenu.Name = "M2"
  30.   hMenu.Text = "Stop"  ' make text
  31.  
  32.   hMenu = New Menu($hPopup)  ' make a menu item in $hPopup with no event as it's a spacer
  33.   ' do not enter any text so it becomes a spacer
  34.  
  35.   hMenu = New Menu($hPopup) As "POP"  ' make another menu item in $hPopup and again use event name POP
  36.   hMenu.Name = "M3"
  37.   hMenu.Text = "Close"  ' make text
  38.  
  39. '  $hPopup.Popup  ' Do not need this as we are in the Menu_Show event.
  40.    
  41.    
  42.      
  43. Public Sub POP_Click()  ' all menus share event POP so in the event we detect the menu name to distinguish between them
  44.   Select Last.Name
  45.   Case "M1"
  46.   If Me.Visible = False Then Me.Visible = True
  47.   Case "M2"
  48.   btn_stop_Click
  49.   Case "M3"
  50.     TrayIcon1.Hide  
  51.     TrayIcon1.Delete
  52.     Me.Close
  53.  End
  54.  
  55.  
  56.  

PS.
You could also just have used the IDE if you do not need a "dynamic" menu…
1 Make a hidden menu using the IDE Menu editor.
2 Drag a TrayIcon object to the form.
3 Select the TrayIcon and use the properties editor to set the PopupMenu property.
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 I really like your code there Bruce. So often we can forget the control naming trick!
b

Online now: No Back to the top

Post

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

thatbruce said

I really like your code there Bruce. So often we can forget the control naming trick!
b

Why thank you kind sir :)

I think more a necessity than a trick in this case though.
a statement like TrayIcon1.PopupMenu = "POPUP" makes the interpreter search the application menus for one specifically named POPUP and won't find it if not named.
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
JMathers is in the usergroup ‘Regular’
ah, nice, so i was close,

thanks for showing me how to do it.
appreciate it  :D

but i prefer to write it then going in the properties tab and such
because gambas3 has a clear button, right next to the blank space, and you wouldn't believe how many times, i hit the x, and wiped out all the data i put in.
so i kind of avoid it like the pest  :lol:
Online now: No Back to the top

Post

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

JMathers said

ah, nice, so i was close,

thanks for showing me how to do it.
appreciate it  :D

but i prefer to write it then going in the properties tab and such
because gambas3 has a clear button, right next to the blank space, and you wouldn't believe how many times, i hit the x, and wiped out all the data i put in.
so i kind of avoid it like the pest  :lol:

No worries.

If the menu is fixed and does not need to be dynamic you could always create it at program start..

Like this…

Code (gambas)

  1.  
  2. Private $hPopup As Menu
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   Dim hMenu As Menu
  7.  
  8.   $hPopup = New Menu(Me, True) As "POPUP"  ' give the top menu an event name (i chose POPUP)
  9.   $hPopup.Name = "POPUP"  ' Set the Name so it can be found.
  10.  
  11. ' create the children for $hPopup...  
  12. ' i just make some menus here. i guess for your needs the creation would be more dynamic/varied.
  13.  
  14.   hMenu = New Menu($hPopup) As "POP"  ' make a menu item in $hPopup and use event name POP
  15.   hMenu.Name = "M1"
  16.   hMenu.Text = "Show"  ' make text
  17.  
  18.   hMenu = New Menu($hPopup) As "POP"  ' make another menu item in $hPopup and again use event name POP
  19.   hMenu.Name = "M2"
  20.   hMenu.Text = "Stop"  ' make text
  21.  
  22.   hMenu = New Menu($hPopup)  ' make a menu item in $hPopup with no event as it's a spacer
  23.   ' do not enter any text so it becomes a spacer
  24.  
  25.   hMenu = New Menu($hPopup) As "POP"  ' make another menu item in $hPopup and again use event name POP
  26.   hMenu.Name = "M3"
  27.   hMenu.Text = "Close"  ' make text
  28.  
  29.   TrayIcon1.PopupMenu = "POPUP"
  30.  
  31.      
  32.      
  33. Public Sub POP_Click()  ' all menus share event POP so in the event we detect the menu name to distinguish between them
  34.   Select Last.Name
  35.   Case "M1"
  36.   If Me.Visible = False Then Me.Visible = True
  37.   Case "M2"
  38.   btn_stop_Click
  39.   Case "M3"
  40.     TrayIcon1.Hide  
  41.     TrayIcon1.Delete
  42.     Me.Close
  43.  End
  44.  
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
JMathers is in the usergroup ‘Regular’
i got it working just fine now :D

but i avoid adding things like that in the form_start section.
to avoid slowing down the app.
only absolute essentials for me go in the form_start
and the trayicon menu can wait until the app is loaded


but total side question for you.

can linux mint (22.01) do 2 wallpapers, 1 per screen, i see an option in the "Monitor Preferences" "same image in all monitors"
but i can't seem to find any documentation on how to assign 1 picture per monitor.
Online now: No Back to the top
1 guest and 0 members have just viewed this.