@@ -20,7 +20,8 @@ def __init__(self,
2020 command : Callable = None ,
2121 image = None ,
2222 image_zoom_visibility : tuple = (13 , float ("inf" )),
23- data : any = None ):
23+ data : any = None ,
24+ menu : any = None ):
2425
2526 self .map_widget = map_widget
2627 self .position = position
@@ -33,7 +34,9 @@ def __init__(self,
3334 self .image_zoom_visibility = image_zoom_visibility
3435 self .deleted = False
3536 self .command = command
37+ self .menu = menu
3638 self .data = data
39+ self .mouse_over = False
3740
3841 self .polygon = None
3942 self .big_circle = None
@@ -70,6 +73,7 @@ def hide_image(self, image_hidden):
7073 self .draw ()
7174
7275 def mouse_enter (self , event = None ):
76+ self .mouse_over = True
7377 if sys .platform == "darwin" :
7478 self .map_widget .canvas .config (cursor = "pointinghand" )
7579 elif sys .platform .startswith ("win" ):
@@ -78,12 +82,23 @@ def mouse_enter(self, event=None):
7882 self .map_widget .canvas .config (cursor = "hand2" ) # not tested what it looks like on Linux!
7983
8084 def mouse_leave (self , event = None ):
85+ self .mouse_over = False
8186 self .map_widget .canvas .config (cursor = "arrow" )
8287
8388 def click (self , event = None ):
8489 if self .command is not None :
8590 self .command (self )
8691
92+ def click_right (self , event = None ):
93+ if self .menu is not None :
94+ m = tkinter .Menu (self .map_widget , tearoff = 0 )
95+ for title , cmd in self .menu .items ():
96+ if title == '-' :
97+ m .add_separator ()
98+ continue
99+ m .add_command (label = f"{ title } " , command = cmd )
100+ m .tk_popup (event .x_root , event .y_root ) # display menu
101+
87102 def get_canvas_pos (self , position ):
88103 tile_position = decimal_to_osm (* position , round (self .map_widget .zoom ))
89104
@@ -110,6 +125,10 @@ def draw(self, event=None):
110125 self .map_widget .canvas .tag_bind (self .polygon , "<Enter>" , self .mouse_enter )
111126 self .map_widget .canvas .tag_bind (self .polygon , "<Leave>" , self .mouse_leave )
112127 self .map_widget .canvas .tag_bind (self .polygon , "<Button-1>" , self .click )
128+ if sys .platform == "darwin" :
129+ self .map_widget .canvas .tag_bind (self .polygon , "<Button-2>" , self .click_right )
130+ else :
131+ self .map_widget .canvas .tag_bind (self .polygon , "<Button-3>" , self .click_right )
113132 else :
114133 self .map_widget .canvas .coords (self .polygon ,
115134 canvas_pos_x - 14 , canvas_pos_y - 23 ,
@@ -124,6 +143,10 @@ def draw(self, event=None):
124143 self .map_widget .canvas .tag_bind (self .big_circle , "<Enter>" , self .mouse_enter )
125144 self .map_widget .canvas .tag_bind (self .big_circle , "<Leave>" , self .mouse_leave )
126145 self .map_widget .canvas .tag_bind (self .big_circle , "<Button-1>" , self .click )
146+ if sys .platform == "darwin" :
147+ self .map_widget .canvas .tag_bind (self .big_circle , "<Button-2>" , self .click_right )
148+ else :
149+ self .map_widget .canvas .tag_bind (self .big_circle , "<Button-3>" , self .click_right )
127150 else :
128151 self .map_widget .canvas .coords (self .big_circle ,
129152 canvas_pos_x - 14 , canvas_pos_y - 45 ,
@@ -141,6 +164,10 @@ def draw(self, event=None):
141164 self .map_widget .canvas .tag_bind (self .canvas_text , "<Enter>" , self .mouse_enter )
142165 self .map_widget .canvas .tag_bind (self .canvas_text , "<Leave>" , self .mouse_leave )
143166 self .map_widget .canvas .tag_bind (self .canvas_text , "<Button-1>" , self .click )
167+ if sys .platform == "darwin" :
168+ self .map_widget .canvas .tag_bind (self .canvas_text , "<Button-2>" , self .click_right )
169+ else :
170+ self .map_widget .canvas .tag_bind (self .canvas_text , "<Button-3>" , self .click_right )
144171 else :
145172 self .map_widget .canvas .coords (self .canvas_text , canvas_pos_x , canvas_pos_y - 56 )
146173 self .map_widget .canvas .itemconfig (self .canvas_text , text = self .text )
0 commit comments