Skip to content
Permalink
Browse files

Merge pull request #1220 from PySimpleGUI/Dev-latest

Dev latest
  • Loading branch information...
MikeTheWatchGuy committed Mar 15, 2019
2 parents 6e99142 + 97c717d commit 8d84838c5a5f9d17caf9ad98fbd0dc98650257c5
Showing with 81 additions and 12 deletions.
  1. +48 −0 PySimpleGUIWeb/Demo Programs/Web_Table_Element.py
  2. +7 −11 PySimpleGUIWeb/PySimpleGUIWeb.py
  3. +26 −1 PySimpleGUIWeb/readme.md
@@ -0,0 +1,48 @@
import PySimpleGUIWeb as sg
import random
import string

# ------------------ Create a fake table ------------------
class Fake():
@classmethod
def word(self):
return ''.join(random.choice(string.ascii_lowercase) for i in range(10))

@classmethod
def number(self, max=1000):
return random.randint(0,max)


def make_table(num_rows, num_cols):
data = [[j for j in range(num_cols)] for i in range(num_rows)]
data[0] = [Fake.word() for _ in range(num_cols)]
for i in range(1, num_rows):
data[i] = [Fake.word(), *[Fake.number() for i in range(num_cols - 1)]]
return data

table_data = make_table(num_rows=15, num_cols=6)

# ------------------ Create a window layout ------------------
layout = [[sg.Table(values=table_data,
enable_events=True,
display_row_numbers=True,
font='Courier 14',
row_header_text='Row #',
key='_table_',
text_color='red')],
[sg.Button('Exit')],
[sg.T('Selected rows = '), sg.T('', size=(30,1), key='_selected_rows_')],
[sg.T('Selected value = '), sg.T('', size=(30,1), key='_selected_value_')]]

# ------------------ Create the window ------------------
window = sg.Window('Table Element Example').Layout(layout)

# ------------------ The Event Loop ------------------
while True:
event, values = window.Read()
if event in (None, 'Exit'):
break
window.Element('_selected_rows_').Update(values['_table_'])
window.Element('_selected_value_').Update(window.Element('_table_').SelectedItem)
# ------------------ User closed window so exit ------------------
window.Close()
@@ -2316,7 +2316,7 @@ def __del__(self):
# ---------------------------------------------------------------------- #
class Table(Element):
def __init__(self, values, headings=None, visible_column_map=None, col_widths=None, def_col_width=10,
auto_size_columns=True, max_col_width=20, select_mode=None, display_row_numbers=False, num_rows=None, row_height=None, font=None, justification='right', text_color=None, background_color=None, alternating_row_color=None, row_colors=None, vertical_scroll_only=True, disabled=False,
auto_size_columns=True, max_col_width=20, select_mode=None, display_row_numbers=False, row_header_text='Row', num_rows=None, row_height=None, font=None, justification='right', text_color=None, background_color=None, alternating_row_color=None, row_colors=None, vertical_scroll_only=True, disabled=False,
size=(None, None), change_submits=False, enable_events=False, bind_return_key=False, pad=None, key=None, tooltip=None, right_click_menu=None, visible=True, size_px=(None, None)):
'''
Table
@@ -2368,7 +2368,7 @@ def __init__(self, values, headings=None, visible_column_map=None, col_widths=No
self.ChangeSubmits = change_submits or enable_events
self.BindReturnKey = bind_return_key
self.StartingRowNumber = 0 # When displaying row numbers, where to start
self.RowHeaderText = 'Row'
self.RowHeaderText = row_header_text
self.RightClickMenu = right_click_menu
self.RowColors = row_colors
self.Disabled = disabled
@@ -4696,16 +4696,12 @@ def do_font_and_color(widget):
elif element_type == ELEM_TYPE_TABLE:
element = element # type: Table
new_table = []
for row in element.Values: # convert entire table to strings
new_row=[str(indiv_value) for indiv_value in row]
for row_num, row in enumerate(element.Values): # convert entire table to strings
new_row= [str(item) for item in row]
if element.DisplayRowNumbers:
new_row = [element.RowHeaderText if row_num == 0 else str(row_num) ,] + new_row
new_table.append(new_row)
element.Widget = remi.gui.Table.new_from_list(new_table)
# element.Widget = remi.gui.Table.new_from_list([('ID', 'First Name', 'Last Name'),
# ('101', 'Danny', 'Young'),
# ('102', 'Christine', 'Holand'),
# ('103', 'Lars', 'Gordon'),
# ('104', 'Roberto', 'Robitaille'),
# ('105', 'Maria', 'Papadopoulos')], width=300, height=200, margin='10px')
do_font_and_color(element.Widget)
tk_row_frame.append(element.Widget)
element.Widget.on_table_row_click.connect(element.on_table_row_click)
@@ -6600,7 +6596,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=False)],
[MultilineOutput('Multiline Output', size=(80, 8), text_color='blue', font='Courier 12', key='_MULTIOUT_', autoscroll=True)],
[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))],
@@ -8,7 +8,7 @@

![Python Version](https://img.shields.io/badge/Python-3.x-yellow.svg)

![Python Version](https://img.shields.io/badge/PySimpleGUIWeb_-0.12.0-orange.svg?longCache=true&style=for-the-badge)
![Python Version](https://img.shields.io/badge/PySimpleGUIWeb_-0.17.0-orange.svg?longCache=true&style=for-the-badge)



@@ -84,6 +84,9 @@ PySimpleGUIWeb runs only on Python 3. Legacy Python (2.7) is not supported.
* Spinner Element (sorta... numbers 0 to 100 only now)
* Column Element
* Image Element
* Multiline Input Element
* Multiline Output Element
* Table Element (yes, tables! even if limited)
* Window background color
* Element padding
* Read with timeout
@@ -240,6 +243,28 @@ New features

* Made the multiple_instance parameter FALSE by default (was messing up badly with True)

## 0.16.0 13-Mar-2019

* TABLES!
* The bare minimum, basic tables are supported
* Things like alternating colors are not done
* Enabling Events DOES work so that you can get immediate clicks
* Value returned is a list of 1ength 1 and contains the value of the cell that was clicked
* Removed use of CloseButton from Popups

## 0.17.0 14-Mar-2019

* More Table features supported
* Option to display row numbers
* New parameter `row_header_text`
* Can turn on / off displaying row numbers
* `enable_events`
* `text_color`
* Font
* Can get the value of the item clicked using Table.SelectedItem. Can be coded as window.Element('_table_').SelectedItem



# Design
# Author
Mike B.

0 comments on commit 8d84838

Please sign in to comment.
You can’t perform that action at this time.