Skip to content

Commit e59b006

Browse files
Merge pull request PySimpleGUI#1631 from cclauss/identity-is-not-equality-in-python
Use ==/!= to compare str literals
2 parents c549307 + b2ba8ac commit e59b006

26 files changed

+52
-60
lines changed

DemoPrograms/Demo_Button_States.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':True}.items()]
4747
recording = False
4848
have_data = False
49-
elif event is '_Submit_' and have_data:
49+
elif event == '_Submit_' and have_data:
5050
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':False}.items()]
5151
recording = False

DemoPrograms/Demo_Canvas.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@
1818
event, values = window.Read()
1919
if event is None:
2020
break
21-
if event is 'Blue':
22-
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill = "Blue")
23-
elif event is 'Red':
24-
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill = "Red")
21+
if event in ('Blue', 'Red'):
22+
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill=event)

DemoPrograms/Demo_Chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
To see this program RUN on the web go here:
1212
https://repl.it/@PySimpleGUI/Chat-Application-Demo
1313
14-
Note that the size of the display on repl.it is smaller than most, so the sizes of the
14+
Note that the size of the display on repl.it is smaller than most, so the sizes of the
1515
Multiline and Output text areas were reduced in the online version. Nothing else was changed
1616
'''
1717

@@ -31,7 +31,7 @@
3131
# ---===--- Loop taking in user input and using it --- #
3232
while True:
3333
event, value = window.Read()
34-
if event is 'SEND':
34+
if event == 'SEND':
3535
query = value['query'].rstrip()
3636
# EXECUTE YOUR COMMAND HERE
3737
print('The command you entered was {}'.format(query))

DemoPrograms/Demo_Chat_With_History.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def ChatBotWithHistory():
3333
history_offset = 0
3434
while True:
3535
(event, value) = window.Read()
36-
if event is 'SEND':
36+
if event == 'SEND':
3737
query = value['query'].rstrip()
3838
# EXECUTE YOUR COMMAND HERE
3939
print('The command you entered was {}'.format(query))
4040
command_history.append(query)
4141
history_offset = len(command_history)-1
4242
window.FindElement('query').Update('') # manually clear input because keyboard events blocks clear
4343
window.FindElement('history').Update('\n'.join(command_history[-3:]))
44-
elif event is None or event is 'EXIT': # quit if exit event or X
44+
elif event in (None, 'EXIT'): # quit if exit event or X
4545
break
4646
elif 'Up' in event and len(command_history):
4747
command = command_history[history_offset]

DemoPrograms/Demo_Chatterbot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'''
1313
Demo_Chatterbot.py
1414
A GUI wrapped arouind the Chatterbot package.
15-
The GUI is used to show progress bars during the training process and
15+
The GUI is used to show progress bars during the training process and
1616
to collect user input that is sent to the chatbot. The reply is displayed in the GUI window
1717
'''
1818

@@ -67,7 +67,7 @@ def print_progress_bar(description, iteration_counter, total_items, progress_bar
6767
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
6868
while True:
6969
event, (value,) = window.Read()
70-
if event is not 'SEND':
70+
if event != 'SEND':
7171
break
7272
string = value.rstrip()
7373
print(' '+string)

DemoPrograms/Demo_Chatterbot_With_TTS.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
'''
1717
Demo_Chatterbot.py
1818
A GUI wrapped arouind the Chatterbot package.
19-
The GUI is used to show progress bars during the training process and
19+
The GUI is used to show progress bars during the training process and
2020
to collect user input that is sent to the chatbot. The reply is displayed in the GUI window
2121
'''
2222

@@ -87,7 +87,7 @@ def speak(text):
8787
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
8888
while True:
8989
event, (value,) = window.Read()
90-
if event is not 'SEND':
90+
if event != 'SEND':
9191
break
9292
string = value.rstrip()
9393
print(' '+string)

DemoPrograms/Demo_Desktop_Widget_Timer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
"""
1010
Timer Desktop Widget Creates a floating timer that is always on top of other windows You move it by grabbing anywhere on the window Good example of how to do a non-blocking, polling program using SimpleGUI Can be used to poll hardware when running on a Pi
11-
11+
1212
While the timer ticks are being generated by PySimpleGUI's "timeout" mechanism, the actual value
1313
of the timer that is displayed comes from the system timer, time.time(). This guarantees an
1414
accurate time value is displayed regardless of the accuracy of the PySimpleGUI timer tick. If
1515
this design were not used, then the time value displayed would slowly drift by the amount of time
16-
it takes to execute the PySimpleGUI read and update calls (not good!)
17-
16+
it takes to execute the PySimpleGUI read and update calls (not good!)
17+
1818
NOTE - you will get a warning message printed when you exit using exit button.
1919
It will look something like: invalid command name \"1616802625480StopMove\"
2020
"""
@@ -46,9 +46,9 @@
4646
if event == 'button':
4747
event = window.FindElement(event).GetText()
4848
# --------- Do Button Operations --------
49-
if event is None or event == 'Exit': # ALWAYS give a way out of program
49+
if event in (None, 'Exit'): # ALWAYS give a way out of program
5050
break
51-
if event is 'Reset':
51+
if event == 'Reset':
5252
start_time = int(round(time.time() * 100))
5353
current_time = 0
5454
paused_time = start_time

DemoPrograms/Demo_EXE_Maker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def Launcher():
2525
# ---===--- Loop taking in user input --- #
2626
while True:
2727
(button, values) = window.Read()
28-
if button is 'Quit' or button is None:
28+
if button in ('Quit', None):
2929
break # exit button clicked
3030

3131
source_file = values['_sourcefile_']
@@ -40,7 +40,7 @@ def Launcher():
4040
file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
4141
command_line = 'pyinstaller -wF "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)
4242

43-
if button is 'Make EXE':
43+
if button == 'Make EXE':
4444
try:
4545
print(command_line)
4646
print('Making EXE... this will take a while.. the program has NOT locked up...')

DemoPrograms/Demo_Fill_Form.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def Everything():
4848
while True:
4949
event, values = window.Read()
5050

51-
if event is 'SaveSettings':
51+
if event == 'SaveSettings':
5252
filename = sg.PopupGetFile('Save Settings', save_as=True, no_window=True)
5353
window.SaveToDisk(filename)
5454
# save(values)
55-
elif event is 'LoadSettings':
55+
elif event == 'LoadSettings':
5656
filename = sg.PopupGetFile('Load Settings', no_window=True)
5757
window.LoadFromDisk(filename)
5858
# load(form)
59-
elif event in ['Exit', None]:
59+
elif event in ('Exit', None):
6060
break
6161

6262
# window.CloseNonBlocking()

DemoPrograms/Demo_Graph_Drawing.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
event, values = window.Read()
2222
if event is None:
2323
break
24-
if event is 'Blue':
25-
graph.TKCanvas.itemconfig(circle, fill = "Blue")
26-
elif event is 'Red':
27-
graph.TKCanvas.itemconfig(circle, fill = "Red")
28-
elif event is 'Move':
24+
if event in ('Blue', 'Red'):
25+
graph.TKCanvas.itemconfig(circle, fill=event)
26+
elif event == 'Move':
2927
graph.MoveFigure(point, 10,10)
3028
graph.MoveFigure(circle, 10,10)
3129
graph.MoveFigure(oval, 10,10)

0 commit comments

Comments
 (0)