commit
9a7eef2f6b
|
@ -48,7 +48,9 @@ def main():
|
||||||
key="-GRAPH-",
|
key="-GRAPH-",
|
||||||
enable_events=True,
|
enable_events=True,
|
||||||
background_color='lightblue',
|
background_color='lightblue',
|
||||||
drag_submits=True), sg.Col(col, key='-COL-') ],
|
drag_submits=True,
|
||||||
|
right_click_menu=[[],['Erase item',]]
|
||||||
|
), sg.Col(col, key='-COL-') ],
|
||||||
[sg.Text(key='-INFO-', size=(60, 1))]]
|
[sg.Text(key='-INFO-', size=(60, 1))]]
|
||||||
|
|
||||||
window = sg.Window("Drawing and Moving Stuff Around", layout, finalize=True)
|
window = sg.Window("Drawing and Moving Stuff Around", layout, finalize=True)
|
||||||
|
@ -59,7 +61,7 @@ def main():
|
||||||
|
|
||||||
dragging = False
|
dragging = False
|
||||||
start_point = end_point = prior_rect = None
|
start_point = end_point = prior_rect = None
|
||||||
graph.bind('<Button-3>', '+RIGHT+')
|
# graph.bind('<Button-3>', '+RIGHT+')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
event, values = window.read()
|
event, values = window.read()
|
||||||
|
@ -112,7 +114,6 @@ def main():
|
||||||
for fig in drag_figures:
|
for fig in drag_figures:
|
||||||
graph.send_figure_to_back(fig)
|
graph.send_figure_to_back(fig)
|
||||||
window["-INFO-"].update(value=f"mouse {values['-GRAPH-']}")
|
window["-INFO-"].update(value=f"mouse {values['-GRAPH-']}")
|
||||||
|
|
||||||
elif event.endswith('+UP'): # The drawing has ended because mouse up
|
elif event.endswith('+UP'): # The drawing has ended because mouse up
|
||||||
window["-INFO-"].update(value=f"grabbed rectangle from {start_point} to {end_point}")
|
window["-INFO-"].update(value=f"grabbed rectangle from {start_point} to {end_point}")
|
||||||
start_point, end_point = None, None # enable grabbing a new rect
|
start_point, end_point = None, None # enable grabbing a new rect
|
||||||
|
@ -120,10 +121,18 @@ def main():
|
||||||
prior_rect = None
|
prior_rect = None
|
||||||
elif event.endswith('+RIGHT+'): # Righ click
|
elif event.endswith('+RIGHT+'): # Righ click
|
||||||
window["-INFO-"].update(value=f"Right clicked location {values['-GRAPH-']}")
|
window["-INFO-"].update(value=f"Right clicked location {values['-GRAPH-']}")
|
||||||
|
elif event.endswith('+MOTION+'): # Righ click
|
||||||
|
window["-INFO-"].update(value=f"mouse freely moving {values['-GRAPH-']}")
|
||||||
elif event == '-SAVE-':
|
elif event == '-SAVE-':
|
||||||
# filename = sg.popup_get_file('Choose file (PNG, JPG, GIF) to save to', save_as=True)
|
# filename = sg.popup_get_file('Choose file (PNG, JPG, GIF) to save to', save_as=True)
|
||||||
filename=r'test.jpg'
|
filename=r'test.jpg'
|
||||||
save_element_as_file(window['-GRAPH-'], filename)
|
save_element_as_file(window['-GRAPH-'], filename)
|
||||||
|
elif event == 'Erase item':
|
||||||
|
window["-INFO-"].update(value=f"Right click erase at {values['-GRAPH-']}")
|
||||||
|
if values['-GRAPH-'] != (None, None):
|
||||||
|
drag_figures = graph.get_figures_at_location(values['-GRAPH-'])
|
||||||
|
for figure in drag_figures:
|
||||||
|
graph.delete_figure(figure)
|
||||||
|
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
version = __version__ = "4.34.0.15 Unreleased\nSDK Help Expanded to init & update parms, SDK Help function search, files_delimiter added to FilesBrowse & popup_get_file, SDK help sort by case, popup_get_file fixed default_extension not being passed to button correctly, changed themes so that spaces can be used in defined name, addition of subprocess non-blocking launcher, fix for Debug button color, set_option for default user_settings path to override normal default, define a truly global PySimpleGUI settings path, theme_global() gets the theme for all progams, execute_subprocess_nonblocking bug fix, mark when strout/stderr is restored in multiline elem, Listbox element convert values to list when updated, Column will expand row if y expand set to True, Added color/c parm to debug print, update graph coordinates if a user bound event happens, another attempt at graphs with user events"
|
version = __version__ = "4.34.0.16 Unreleased\nSDK Help Expanded to init & update parms, SDK Help function search, files_delimiter added to FilesBrowse & popup_get_file, SDK help sort by case, popup_get_file fixed default_extension not being passed to button correctly, changed themes so that spaces can be used in defined name, addition of subprocess non-blocking launcher, fix for Debug button color, set_option for default user_settings path to override normal default, define a truly global PySimpleGUI settings path, theme_global() gets the theme for all progams, execute_subprocess_nonblocking bug fix, mark when strout/stderr is restored in multiline elem, Listbox element convert values to list when updated, Column will expand row if y expand set to True, Added color/c parm to debug print, update graph coordinates if a user bound event happens, another attempt at graphs with user events, update mouse location when right click menu item selected"
|
||||||
|
|
||||||
__version__ = version.split()[0] # For PEP 396 and PEP 345
|
__version__ = version.split()[0] # For PEP 396 and PEP 345
|
||||||
|
|
||||||
|
@ -845,7 +845,8 @@ class Element():
|
||||||
"""
|
"""
|
||||||
self.TKRightClickMenu.tk_popup(event.x_root, event.y_root, 0)
|
self.TKRightClickMenu.tk_popup(event.x_root, event.y_root, 0)
|
||||||
self.TKRightClickMenu.grab_release()
|
self.TKRightClickMenu.grab_release()
|
||||||
|
if self.Type == ELEM_TYPE_GRAPH:
|
||||||
|
self._update_position_for_returned_values(event)
|
||||||
|
|
||||||
def _MenuItemChosenCallback(self, item_chosen): # TEXT Menu item callback
|
def _MenuItemChosenCallback(self, item_chosen): # TEXT Menu item callback
|
||||||
"""
|
"""
|
||||||
|
@ -1067,7 +1068,7 @@ class Element():
|
||||||
key_suffix = self.user_bind_dict.get(bind_string, '')
|
key_suffix = self.user_bind_dict.get(bind_string, '')
|
||||||
self.user_bind_event = event
|
self.user_bind_event = event
|
||||||
if self.Type == ELEM_TYPE_GRAPH:
|
if self.Type == ELEM_TYPE_GRAPH:
|
||||||
self._user_bound_event_callback(event)
|
self._update_position_for_returned_values(event)
|
||||||
if self.Key is not None:
|
if self.Key is not None:
|
||||||
if isinstance(self.Key, str):
|
if isinstance(self.Key, str):
|
||||||
key = self.Key + str(key_suffix)
|
key = self.Key + str(key_suffix)
|
||||||
|
@ -5079,16 +5080,16 @@ class Graph(Element):
|
||||||
self.MouseButtonDown = True
|
self.MouseButtonDown = True
|
||||||
|
|
||||||
|
|
||||||
# user bound event callback
|
def _update_position_for_returned_values(self, event):
|
||||||
def _user_bound_event_callback(self, event):
|
|
||||||
"""
|
"""
|
||||||
Not a user callable method. Indirectly called by tkinter when any user bound event happens
|
Updates the variable that's used when the values dictionary is returned from a window read.
|
||||||
|
|
||||||
|
Not called by the user. It's called from another method/function that tkinter calledback
|
||||||
|
|
||||||
:param event: (event) event info from tkinter. Contains the x and y coordinates of a click
|
:param event: (event) event info from tkinter. Contains the x and y coordinates of a click
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.ClickPosition = self._convert_canvas_xy_to_xy(event.x, event.y)
|
self.ClickPosition = self._convert_canvas_xy_to_xy(event.x, event.y)
|
||||||
self.ParentForm.LastButtonClickedWasRealtime = self.DragSubmits
|
|
||||||
|
|
||||||
|
|
||||||
# button callback
|
# button callback
|
||||||
|
|
Loading…
Reference in New Issue