Posts: 8
Threads: 2
Joined: Sep 2023
Sep-28-2023, 06:39 PM
(This post was last modified: Sep-28-2023, 07:03 PM by Larz60+.)
I have created the code to search, modify tables. I have created two windows, the second has two issues in the table.
1. The click event is not working, it's not returning any values. Hence not able to perform any update or edit.
2. When clicking the view button, the table values are updated as many time clicked. Not sure why it's happening like this.
I have attached the main fille, but not the dbconnect file.
Code Snippet:
view_table = PG.Table(values=table_rows,
headings=table_toprow, max_col_width=25,
auto_size_columns=True,
display_row_numbers=True,
alternating_row_color='lightgreen',
justification='center',
key='-TABLE-',
selected_row_colors='red on yellow',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True
)
window1 = PG.Window('Inbound Operations', layout=[[col1, col2, col3, col4],
[view_button, add_button, update_button, delete_button],
[view_table]], resizable=True) Thanks,
RS
Larz60+ write Sep-28-2023, 07:03 PM:Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I modified for you. Please use BBCode tags on future posts.
Attached Files
dbcongui.py (Size: 9.59 KB / Downloads: 168)
Posts: 6,799
Threads: 20
Joined: Feb 2020
Sep-29-2023, 07:53 PM
(This post was last modified: Sep-29-2023, 07:53 PM by deanhystad.)
This is the problem with the clicked event in the view table.
while True:
event1, values1 = window1.read()
. . .
elif '+CLICKED+' in event:
PG.popup("You clicked row:{} Column: {}".format(event[2][0], event[2][1])) You check if '+CLICKED+' is in event, not event1.
I don't understand Q2. If you click the View button multiple times, shouldn't the view update multiple times?
ranjansanyal2007 likes this post
Posts: 8
Threads: 2
Joined: Sep 2023
(Sep-29-2023, 07:53 PM)deanhystad Wrote: This is the problem with the clicked event in the view table.
while True:
event1, values1 = window1.read()
. . .
elif '+CLICKED+' in event:
PG.popup("You clicked row:{} Column: {}".format(event[2][0], event[2][1])) You check if '+CLICKED+' is in event, not event1.
I don't understand Q2. If you click the View button multiple times, shouldn't the view update multiple times?
Thanks for your response.
1. This '+CLICKED' in event is not working if I try as event1 == '+CLICKED+', As per your code it's working, but failing while closing with TypeError: argument of type 'NoneType' is not iterable
2. Question 2: If I select view it is showing table. Now If I select another value in the text box and click view, the previous values stays. Not sure how remove previous and get the new values.
Posts: 6,799
Threads: 20
Joined: Feb 2020
Quote:1. This '+CLICKED' in event is not working if I try as event1 == '+CLICKED+', As per your code it's working, but failing while closing with TypeError: argument of type 'NoneType' is not iterable
Looks like you'll need to check if event[2] is None.
Quote:2. Question 2: If I select view it is showing table. Now If I select another value in the text box and click view, the previous values stays. Not sure how remove previous and get the new values.
You only append. You do not reset the list.
for result in results:
table_rows.append(list(result)) # <- Appending here You should do this instead.
table_rows = result
Posts: 8
Threads: 2
Joined: Sep 2023
(Oct-03-2023, 12:54 PM)deanhystad Wrote: Quote:1. This '+CLICKED' in event is not working if I try as event1 == '+CLICKED+', As per your code it's working, but failing while closing with TypeError: argument of type 'NoneType' is not iterable
Looks like you'll need to check if event[2] is None.
Quote:2. Question 2: If I select view it is showing table. Now If I select another value in the text box and click view, the previous values stays. Not sure how remove previous and get the new values.
You only append. You do not reset the list.
for result in results:
table_rows.append(list(result)) # <- Appending here You should do this instead.
table_rows = result
Thanks again.
Can you please little elaborate, I am very new to this.
"Looks like you'll need to check if event[2] is None." How and when to check this.
Posts: 8
Threads: 2
Joined: Sep 2023
(Oct-03-2023, 03:47 PM)ranjansanyal2007 Wrote: (Oct-03-2023, 12:54 PM)deanhystad Wrote: Looks like you'll need to check if event[2] is None.
You only append. You do not reset the list.
for result in results:
table_rows.append(list(result)) # <- Appending here You should do this instead.
table_rows = result
Thanks again.
Can you please little elaborate, I am very new to this.
"Looks like you'll need to check if event[2] is None." How and when to check this.
table_rows = result is not working. throwing error.
value = [i + self.StartingRowNumber] + value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
TypeError: can only concatenate list (not "str") to list
Posts: 6,799
Threads: 20
Joined: Feb 2020
Oct-03-2023, 04:05 PM
(This post was last modified: Oct-03-2023, 04:05 PM by deanhystad.)
if event[2]:
do_something In the context of your code:
elif '+CLICKED+' in event:
if event[2]:
PG.popup("You clicked row:{} Column: {}".format(event[2][0], event[2][1])) Next time expend some effort trying to figure it out yourself. You'll learn faster that way.
Posts: 6,799
Threads: 20
Joined: Feb 2020
Quote:table_rows = result is not working. throwing error.
Guess you need to figure out why.
This is the code you had:
for result in results:
table_rows.append(list(result)) This worked, but items kept getting added on to the table instead of the table being reset to show the new items.
This didn't work:
table_rows = result I think result was a typo, and I meant "results".
But results is probably not what we want either, because results contains multiple result, and result needed to be converted to a list to work. So somehow you need to reset table_rows to be empty, then call your for loop to add on the new rows.
Posts: 8
Threads: 2
Joined: Sep 2023
(Oct-03-2023, 05:05 PM)deanhystad Wrote: Quote:table_rows = result is not working. throwing error.
Guess you need to figure out why.
This is the code you had:
for result in results:
table_rows.append(list(result)) This worked, but items kept getting added on to the table instead of the table being reset to show the new items.
This didn't work:
table_rows = result I think result was a typo, and I meant "results".
But results is probably not what we want either, because results contains multiple result, and result needed to be converted to a list to work. So somehow you need to reset table_rows to be empty, then call your for loop to add on the new rows. rt
As the result coming as tuple, I had to convert it to a list and it worked with comprehension.
Also the table I am taking the -TABLE- from the event and it is working as expected.
Posts: 8
Threads: 2
Joined: Sep 2023
Oct-11-2023, 03:33 PM
(This post was last modified: Oct-11-2023, 03:33 PM by ranjansanyal2007.)
(Oct-03-2023, 05:48 PM)ranjansanyal2007 Wrote: (Oct-03-2023, 05:05 PM)deanhystad Wrote: Guess you need to figure out why.
This is the code you had:
for result in results:
table_rows.append(list(result)) This worked, but items kept getting added on to the table instead of the table being reset to show the new items.
This didn't work:
table_rows = result I think result was a typo, and I meant "results".
But results is probably not what we want either, because results contains multiple result, and result needed to be converted to a list to work. So somehow you need to reset table_rows to be empty, then call your for loop to add on the new rows. rt
As the result coming as tuple, I had to convert it to a list and it worked with comprehension.
Also the table I am taking the -TABLE- from the event and it is working as expected.
Quote:I have made some success, but still struggling to create a button, which can refresh the table and clear. I have created the "Clear" button. Sharing the code below.
import dbconnect
import PySimpleGUI as PG
def outbound_ops():
PG.theme("LightBlue3")
label_TPID = PG.Text("ISA RCV ID: ")
ib_TPID = PG.InputText(key="TPID", tooltip="Enter TP ISA ID", size=30)
label_TPQUAL = PG.Text("ISA RCV QUAL: ")
ib_TPQUAL = PG.InputText(key="TPQUAL", tooltip="Enter TP ISA Qualifier", size=20)
label_sndq = PG.Text("ISA SND QUAL: ")
ib_sndq = PG.InputText(key="SNDQUAL", tooltip="Enter Sender Qualifier", size=20)
label_TPNN = PG.Text("TP NICKNAME: ")
ib_TPNN = PG.InputText(key="TPNN", tooltip="Enter TP NickName", size=30)
label_TPINTID = PG.Text("TP INTPID: ")
ib_TPINTID = PG.InputText(key="TPINTPID", tooltip="Enter INTPID", size=30)
label_MAP = PG.Text("MAP NAME: ")
ib_MAP = PG.InputText(key="MAP", tooltip="Enter MAP NAME", size=30)
label_ISASND = PG.Text("ISA SENDER ID: ")
ib_ISASND = PG.InputText(key="ISASND", tooltip="Enter ISA Sender", size=30)
label_GSRCV = PG.Text("GS RCV ID: ")
ib_GSRCV = PG.InputText(key="GSRCV", tooltip="Enter GS Receiver", size=30)
label_gssnd = PG.Text("GS SND ID: ")
ib_gssnd = PG.InputText(key="GSSND", tooltip="Enter GS Sender", size=30)
label_gsver = PG.Text("GS VERS: ")
ib_gsver = PG.InputText(key="GSVER", tooltip="Enter GS Version", size=30)
label_isaver = PG.Text("ISA VERS: ")
ib_isaver = PG.InputText(key="ISAVER", tooltip="Enter ISA Version", size=30)
label_desc = PG.Text("DESCRIPTION: ")
ib_desc = PG.InputText(key="DESC", tooltip="Enter Description: NickName_X12", size=30)
add_button = PG.Button("Add")
view_button = PG.Button("View")
delete_button = PG.Button("Delete")
update_button = PG.Button("Update")
clear_button = PG.Button("Clear")
col1 = PG.Column([[label_TPID], [label_TPNN], [label_MAP], [label_GSRCV]])
col2 = PG.Column([[ib_TPID, ], [ib_TPNN], [ib_MAP], [ib_GSRCV]])
col3 = PG.Column([[label_TPQUAL], [label_TPINTID], [label_ISASND], [label_sndq]])
col4 = PG.Column([[ib_TPQUAL], [ib_TPINTID], [ib_ISASND], [ib_sndq]])
col5 = PG.Column([[label_isaver], [label_gssnd], [label_gsver], [label_desc]])
col6 = PG.Column([[ib_isaver], [ib_gssnd], [ib_gsver], [ib_desc]])
table_toprow = ["NICKNAME", "INTPID", "ISA RCV ID", "ISA RCV QUAL", "ISA SND QUAL",
"GS VERS", "DESCRIPTION", "GS VER", "GS RCV ID", "ISA SND ID",
"GS SND ID", "MAP"]
table_rows = []
view_table = PG.Table(values=table_rows,
headings=table_toprow, max_col_width=25,
auto_size_columns=True,
display_row_numbers=False,
alternating_row_color='lightblue',
justification='center',
key='-TABLE-',
selected_row_colors='white on blue',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True
)
window = PG.Window('Outbound Operations', layout=[[col1, col2, col3, col4, col5, col6],
[view_button, add_button, update_button,
delete_button, clear_button],
[view_table]], resizable=True)
while True:
event, values = window.read()
print(event)
print(values)
if event in (PG.WIN_CLOSED, "Exit"):
break
elif event == "View":
try:
if values["TPNN"] != "":
get_query = (f"SELECT * FROM CODELIST_XREF_ITEM A, CODELIST_XREF_VERS B "
f"WHERE A.LIST_NAME=B.LIST_NAME "
f"and A.LIST_VERSION=B.DEFAULT_VERSION "
f"and A.LIST_NAME= 'TST_CDLST_OB_FF_EDI_LKUP' "
f"and SENDER_ITEM like '%{values['TPNN']}%'")
results = dbconnect.dbconn_func(get_query)
table_rows = [list(result[4:16]) for result in results]
elif values["TPID"] != "":
get_query = (f"SELECT * FROM CODELIST_XREF_ITEM A, CODELIST_XREF_VERS B "
f"WHERE A.LIST_NAME=B.LIST_NAME "
f"and A.LIST_VERSION=B.DEFAULT_VERSION "
f"and A.LIST_NAME= TST_CDLST_OB_FF_EDI_LKUP' "
f"and TEXT1 like '%{values['TPID']}%'")
results = dbconnect.dbconn_func(get_query)
table_rows = [list(result[4:16]) for result in results]
window['-TABLE-'].update(values=table_rows)
window['TPID'].update(value='')
window['TPQUAL'].update(value='')
window['TPNN'].update(value='')
window['TPINTPID'].update(value='')
window['MAP'].update(value='')
window['ISASND'].update(value='')
window['GSRCV'].update(value='')
window['SNDQUAL'].update(value='')
window['GSSND'].update(value='')
window['GSVER'].update(value='')
window['ISAVER'].update(value='')
window['DESC'].update(value='')
add_button.update(disabled=True)
update_button.update(disabled=True)
delete_button.update(disabled=True)
except NameError:
PG.popup("Enter Any Value")
elif event == "Add":
if values["TPID"] != "" and values["TPQUAL"] != "":
ins_query = (f"INSERT INTO "
f"newdb.tpinfo_outbound"
f"(`tpisarcvid`,`tpisarcvqual`,`tpnickname`,`tpgsid`,"
f"`tpinternalid`,`map_name`,`tpisasenderid`) "
f"VALUES('{values['TPID']}','{values['TPQUAL']}',"
f"'{values['TPNN']}','{values['GSRCV']}',"
f"'{values['TPINTPID']}','{values['MAP']}',{values['ISASND']})")
dbconnect.dbconn_func(ins_query)
PG.popup_quick("Value Added")
window['-TABLE-'].update(values=table_rows, select_rows=None,)
window['TPID'].update(value='')
window['TPQUAL'].update(value='')
window['TPNN'].update(value='')
window['TPINTPID'].update(value='')
window['MAP'].update(value='')
window['ISASND'].update(value='')
window['GSRCV'].update(value='')
window['SNDQUAL'].update(value='')
window['GSSND'].update(value='')
window['GSVER'].update(value='')
window['ISAVER'].update(value='')
window['DESC'].update(value='')
elif values["TPID"] == "":
PG.popup("ISA ID Can't be BLank")
elif values["TPNN"] == "":
PG.popup("Nickname Can't be Blank")
elif event == "Update":
if values["TPID"] != "" and values["TPQUAL"] != "":
sel_index = values["-TABLE-"][0]
print(sel_index)
print("Update")
elif values["TPID"] == "":
PG.popup("ISA ID Can't be BLank")
elif values["TPNN"] == "":
PG.popup("Nickname Can't be Blank")
elif event == '-TABLE-':
tb_index = values['-TABLE-'][0]
window['TPID'].update(value=table_rows[tb_index][2])
window['TPQUAL'].update(value=table_rows[tb_index][3])
window['TPNN'].update(value=table_rows[tb_index][0])
window['TPINTPID'].update(value=table_rows[tb_index][1])
window['MAP'].update(value=table_rows[tb_index][11])
window['ISASND'].update(value=table_rows[tb_index][9])
window['GSRCV'].update(value=table_rows[tb_index][8])
window['SNDQUAL'].update(value=table_rows[tb_index][4])
window['GSSND'].update(value=table_rows[tb_index][10])
window['GSVER'].update(value=table_rows[tb_index][5])
window['ISAVER'].update(value=table_rows[tb_index][7])
window['DESC'].update(value=table_rows[tb_index][6])
update_button.update(disabled=False)
delete_button.update(disabled=False)
window['TPNN'].update(disabled=True)
elif event == "Clear":
window['-TABLE-'].update(values='', select_rows=None)
window['TPID'].update(value='')
window['TPQUAL'].update(value='')
window['TPNN'].update(value='', disabled=False)
window['TPINTPID'].update(value='')
window['MAP'].update(value='')
window['ISASND'].update(value='')
window['GSRCV'].update(value='')
window['SNDQUAL'].update(value='')
window['GSSND'].update(value='')
window['GSVER'].update(value='')
window['ISAVER'].update(value='')
window['DESC'].update(value='')
update_button.update(disabled=True)
delete_button.update(disabled=True)
add_button.update(disabled=False)
window.close()
|