diff --git a/PySimpleGUIWeb/PySimpleGUIWeb.py b/PySimpleGUIWeb/PySimpleGUIWeb.py index f49ab1a0..f2288bcc 100644 --- a/PySimpleGUIWeb/PySimpleGUIWeb.py +++ b/PySimpleGUIWeb/PySimpleGUIWeb.py @@ -1083,8 +1083,11 @@ class MultilineOutput(Element): elif value is not None and append: self.CurrentValue = self.CurrentValue + '\n' + str(value) self.Widget.set_value(self.CurrentValue) - app = self.ParentForm.App - # app.execute_javascript("document.getElementById('%s').scrollTop=%s;" % (self.Widget.identifier, 9999)) # 9999 number of pixel to scroll + if self.Autoscroll: + app = self.ParentForm.App + if hasattr(app, "websockets"): + app.execute_javascript("document.getElementById('%s').scrollTop=%s;" % ( + self.Widget.identifier, 9999)) # 9999 number of pixel to scroll super().Update(self.Widget, background_color=background_color, text_color=text_color, font=font, visible=visible) @@ -2394,9 +2397,20 @@ class Table(Element): self.Values = values self.SelectedRows = [] + def on_table_row_click(self, table, row, item): - self.SelectedRow = row # type: remi.gui.TableRow + # self.SelectedRow = row # type: remi.gui.TableRow self.SelectedItem = item.get_text() + index = -1 + # each widget (and specifically in this case the table) has a _render_children_list attribute that + # is an ordered list of the children keys + # first, we search for the row in the children dictionary + for key, value in table.children.items(): + if value == row: + # if the row is found, we get the index in the ordered list + index = table._render_children_list.index(key) + break + self.SelectedRow = index if self.ChangeSubmits: self.ParentForm.LastButtonClicked = self.Key if self.Key is not None else '' self.ParentForm.MessageQueue.put(self.ParentForm.LastButtonClicked) @@ -2618,7 +2632,7 @@ class Window: alpha_channel=1, return_keyboard_events=False, use_default_focus=True, text_justification=None, no_titlebar=False, grab_anywhere=False, keep_on_top=False, resizable=True, disable_close=False, disable_minimize=False, background_image=None, - web_debug=False, web_ip='0.0.0.0', web_port=0, web_start_browser=True, web_update_interval=.00001, web_multiple_instance=False ): + web_debug=False, web_ip='0.0.0.0', web_port=0, web_start_browser=True, web_update_interval=0, web_multiple_instance=False ): ''' :param title: @@ -3219,12 +3233,12 @@ class Window: self.window = userdata[0] # type: Window else: self.window = userdata2 # type: Window - self.window.App = self self.master_widget = None if userdata2 is None: res_path = os.path.dirname(os.path.abspath(__file__)) # print('res path', res_path) super(Window.MyApp, self).__init__(*args, static_file_path={'C':'c:','c':'c:','D':'d:', 'd':'d:', 'E':'e:', 'e':'e:', 'dot':'.', '.':'.'}) + self.window.App = self def main(self, name='world'): # margin 0px auto allows to center the app to the screen @@ -3740,7 +3754,7 @@ def BuildResultsForSubform(form, initialize_only, top_level_form): value = None elif element.Type == ELEM_TYPE_TABLE: element = element # type:Table - value = [element.SelectedItem,] + value = [element.SelectedRow,] elif element.Type == ELEM_TYPE_TREE: value = element.SelectedRows elif element.Type == ELEM_TYPE_GRAPH: @@ -6586,7 +6600,7 @@ def main(): [T('Up Time'), Text('Text', key='_TEXT_UPTIME_', font='Arial 18', text_color='black', size=(30,1))], [Input('Single Line Input', do_not_clear=True, enable_events=False, size=(30, 1), text_color='red')], [Multiline('Multiline Input', do_not_clear=True, size=(40, 4), enable_events=True, key='_MULTI_IN_')], - [MultilineOutput('Multiline Output', size=(80, 8), text_color='blue', font='Courier 12', key='_MULTIOUT_', autoscroll=True)], + [MultilineOutput('Multiline Output', size=(80, 8), text_color='blue', font='Courier 12', key='_MULTIOUT_', autoscroll=False)], [Checkbox('Checkbox 1', enable_events=True, key='_CB1_'), Checkbox('Checkbox 2', default=True, key='_CB2_', enable_events=True)], [Combo(values=['Combo 1', 'Combo 2', 'Combo 3'], default_value='Combo 2', key='_COMBO_', enable_events=True, readonly=False, tooltip='Combo box', disabled=False, size=(12, 1))],