MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / _table_clicked

Method _table_clicked

PySimpleGUI/PySimpleGUI.py:9085–9138  ·  view source on GitHub ↗

Not user callable. Callback function that is called a click happens on a table. Stores the selected rows in Element as they are being selected. If events enabled, then returns from Read :param event: event information from tkinter :type event: (unknown)

(self, event)

Source from the content-addressed store, hash-verified

9083 _exit_mainloop(self.ParentForm, self)
9084
9085 def _table_clicked(self, event):
9086 """
9087 Not user callable. Callback function that is called a click happens on a table.
9088 Stores the selected rows in Element as they are being selected. If events enabled, then returns from Read
9089
9090 :param event: event information from tkinter
9091 :type event: (unknown)
9092 """
9093 self.last_table_event = event
9094 if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow
9095 return
9096 # popup(obj_to_string_single_obj(event))
9097 try:
9098 region = self.Widget.identify('region', event.x, event.y)
9099 if region == 'heading':
9100 row = -1
9101 elif region == 'cell':
9102 row = int(self.Widget.identify_row(event.y))-1
9103 elif region == 'separator':
9104 row = None
9105 else:
9106 row = None
9107 col_identified = self.Widget.identify_column(event.x)
9108 if col_identified: # Sometimes tkinter returns a value of '' which would cause an error if cast to an int
9109 column = int(self.Widget.identify_column(event.x)[1:])-1-int(self.DisplayRowNumbers is True)
9110 else:
9111 column = None
9112 except Exception as e:
9113 warnings.warn('Error getting table click data for table with key= {}\nError: {}'.format(self.Key, e), UserWarning)
9114 if not SUPPRESS_ERROR_POPUPS:
9115 _error_popup_with_traceback('Unable to complete operation getting the clicked event for table with key {}'.format(self.Key), _create_error_message(), e, 'Event data:', obj_to_string_single_obj(event))
9116 row = column = None
9117
9118 self.last_clicked_position = (row, column)
9119
9120 # update the rows being selected if appropriate
9121 self.ParentForm.TKroot.update()
9122 # self.TKTreeview.()
9123 selections = self.TKTreeview.selection()
9124 if self.right_click_selects and len(selections) <= 1:
9125 if (event.num == 3 and not running_mac()) or (event.num == 2 and running_mac()):
9126 if row != -1 and row is not None:
9127 selections = [row+1]
9128 self.TKTreeview.selection_set(selections)
9129 # print(selections)
9130 self.SelectedRows = [int(x) - 1 for x in selections]
9131 # print('The new selected rows = ', self.SelectedRows)
9132 if self.enable_click_events is True:
9133 if self.Key is not None:
9134 self.ParentForm.LastButtonClicked = (self.Key, TABLE_CLICKED_INDICATOR, (row, column))
9135 else:
9136 self.ParentForm.LastButtonClicked = ''
9137 self.ParentForm.FormRemainedOpen = True
9138 _exit_mainloop(self.ParentForm, self)
9139
9140
9141 def disable_edit_for_cells(self, list_of_cells_to_disable=None):

Callers

nothing calls this directly

Calls 7

_create_error_messageFunction · 0.85
obj_to_string_single_objFunction · 0.85
running_macFunction · 0.85
_exit_mainloopFunction · 0.85
_widget_was_createdMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected