Use ==/!= to compare str literals

This commit is contained in:
cclauss 2019-06-25 22:46:32 +02:00
parent 6680820360
commit b2ba8acb34
26 changed files with 52 additions and 60 deletions

View File

@ -46,6 +46,6 @@ while True:
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':True}.items()]
recording = False
have_data = False
elif event is '_Submit_' and have_data:
elif event == '_Submit_' and have_data:
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':False}.items()]
recording = False

View File

@ -18,7 +18,5 @@ while True:
event, values = window.Read()
if event is None:
break
if event is 'Blue':
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill = "Blue")
elif event is 'Red':
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill = "Red")
if event in ('Blue', 'Red'):
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill=event)

View File

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

View File

@ -33,7 +33,7 @@ def ChatBotWithHistory():
history_offset = 0
while True:
(event, value) = window.Read()
if event is 'SEND':
if event == 'SEND':
query = value['query'].rstrip()
# EXECUTE YOUR COMMAND HERE
print('The command you entered was {}'.format(query))
@ -41,7 +41,7 @@ def ChatBotWithHistory():
history_offset = len(command_history)-1
window.FindElement('query').Update('') # manually clear input because keyboard events blocks clear
window.FindElement('history').Update('\n'.join(command_history[-3:]))
elif event is None or event is 'EXIT': # quit if exit event or X
elif event in (None, 'EXIT'): # quit if exit event or X
break
elif 'Up' in event and len(command_history):
command = command_history[history_offset]

View File

@ -67,7 +67,7 @@ window = sg.Window('Chat Window', auto_size_text=True, default_element_size=(30,
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
while True:
event, (value,) = window.Read()
if event is not 'SEND':
if event != 'SEND':
break
string = value.rstrip()
print(' '+string)

View File

@ -87,7 +87,7 @@ window = sg.Window('Chat Window', auto_size_text=True, default_element_size=(30,
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
while True:
event, (value,) = window.Read()
if event is not 'SEND':
if event != 'SEND':
break
string = value.rstrip()
print(' '+string)

View File

@ -46,9 +46,9 @@ while (True):
if event == 'button':
event = window.FindElement(event).GetText()
# --------- Do Button Operations --------
if event is None or event == 'Exit': # ALWAYS give a way out of program
if event in (None, 'Exit'): # ALWAYS give a way out of program
break
if event is 'Reset':
if event == 'Reset':
start_time = int(round(time.time() * 100))
current_time = 0
paused_time = start_time

View File

@ -25,7 +25,7 @@ def Launcher():
# ---===--- Loop taking in user input --- #
while True:
(button, values) = window.Read()
if button is 'Quit' or button is None:
if button in ('Quit', None):
break # exit button clicked
source_file = values['_sourcefile_']
@ -40,7 +40,7 @@ def Launcher():
file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
command_line = 'pyinstaller -wF "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)
if button is 'Make EXE':
if button == 'Make EXE':
try:
print(command_line)
print('Making EXE... this will take a while.. the program has NOT locked up...')

View File

@ -48,15 +48,15 @@ def Everything():
while True:
event, values = window.Read()
if event is 'SaveSettings':
if event == 'SaveSettings':
filename = sg.PopupGetFile('Save Settings', save_as=True, no_window=True)
window.SaveToDisk(filename)
# save(values)
elif event is 'LoadSettings':
elif event == 'LoadSettings':
filename = sg.PopupGetFile('Load Settings', no_window=True)
window.LoadFromDisk(filename)
# load(form)
elif event in ['Exit', None]:
elif event in ('Exit', None):
break
# window.CloseNonBlocking()

View File

@ -21,11 +21,9 @@ while True:
event, values = window.Read()
if event is None:
break
if event is 'Blue':
graph.TKCanvas.itemconfig(circle, fill = "Blue")
elif event is 'Red':
graph.TKCanvas.itemconfig(circle, fill = "Red")
elif event is 'Move':
if event in ('Blue', 'Red'):
graph.TKCanvas.itemconfig(circle, fill=event)
elif event == 'Move':
graph.MoveFigure(point, 10,10)
graph.MoveFigure(circle, 10,10)
graph.MoveFigure(oval, 10,10)

View File

@ -37,7 +37,7 @@ def main():
dpts = [randint(0, 10) for x in range(10000)]
for i in range(len(dpts)):
event, values = window.Read(timeout=10)
if event is 'Exit' or event is None:
if event in ('Exit', None):
exit(69)
slider_elem.Update(i)

View File

@ -27,7 +27,7 @@ def main():
while True:
event, values = window.Read(timeout=10)
if event is 'Exit' or event is None:
if event in ('Exit', None):
exit(69)
def PyplotScatterWithLegend():

View File

@ -889,7 +889,7 @@ while True:
event, values = window.Read()
print(event)
# show it all again and get buttons
if event is None or event is 'Exit':
if event in (None, 'Exit'):
break
try:

View File

@ -892,7 +892,7 @@ while True:
event, values = window.Read()
# print(event)
# show it all again and get buttons
if event is None or event is 'Exit':
if event in (None, 'Exit'):
break
try:

View File

@ -663,7 +663,7 @@ def main():
while True:
event, values = window.Read(timeout=0)
if event is 'Exit' or event is None:
if event in ('Exit', None):
exit(0)
run_a_ping_and_graph()

View File

@ -97,7 +97,7 @@ def main():
while True:
event, values = window.Read(timeout=0)
if event is 'Exit' or event is None:
if event in ('Exit', None):
break
run_a_ping_and_graph()
@ -106,5 +106,3 @@ def main():
if __name__ == '__main__':
main()

View File

@ -28,7 +28,7 @@ def StatusOutputExample():
# This is the code that reads and updates your window
event, values = window.Read(timeout=10)
window.FindElement('output').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
if event == 'Quit' or event is None:
if event in ('Quit', None):
break
if event == 'LED On':
print('Turning on the LED')
@ -63,9 +63,9 @@ def RemoteControlExample():
while (True):
# This is the code that reads and updates your window
event, values = window.Read(timeout=0, timeout_key='timeout')
if event is not 'timeout':
if event != 'timeout':
print(event)
if event == 'Quit' or event is None:
if event in ('Quit', None):
break
window.Close()

View File

@ -41,7 +41,7 @@ def main():
i = 0
while vidFile.isOpened():
event, values = window.Read(timeout=0)
if event is 'Exit' or event is None:
if event in ('Exit', None):
exit(69)
ret, frame = vidFile.read()
if not ret: # if out of data stop looping

View File

@ -45,9 +45,9 @@ while True:
if event is None:
break
if event is 'Switch LED':
if event == 'Switch LED':
window.FindElement('output').Update(SwitchLED())
elif event is 'Flash LED':
elif event == 'Flash LED':
window.FindElement('output').Update('LED is Flashing')
window.Refresh()
FlashLED()

View File

@ -62,7 +62,7 @@ def Launcher2():
print('Quickly launch your favorite programs using these shortcuts')
print('Or copy files to your github folder. Or anything else you type on the command line')
# copyfile(source, dest)
elif event is 'Run':
elif event == 'Run':
for index, file in enumerate(values['demolist']):
print('Launching %s'%file)
window.Refresh() # make the print appear immediately

View File

@ -27,9 +27,9 @@ def Timer():
if values is None or button == 'Exit':
break
if button is 'Reset':
if button == 'Reset':
i=0
elif button is 'Pause':
elif button == 'Pause':
paused = not paused
if not paused:

View File

@ -45,9 +45,7 @@ def DownloadSubtitlesGUI():
print('Done')
elif event == 'Download':
lang = values['lang']
if lang is '':
lang = 'en'
lang = values['lang'] or 'en'
print(f'Downloading subtitle for {lang}...')
window.Refresh()
command = [f'C:\\Python\\Anaconda3\\Scripts\\youtube-dl.exe --sub-lang {lang} --write-sub {link}',]

View File

@ -47,7 +47,7 @@ def HowDoI():
history_offset = 0
while True:
(button, value) = window.Read()
if button is 'SEND':
if button == 'SEND':
query = value['query'].rstrip()
print(query)
QueryHowDoI(query, value['Num Answers'], value['full text']) # send the string to HowDoI
@ -55,7 +55,7 @@ def HowDoI():
history_offset = len(command_history)-1
window.FindElement('query').Update('') # manually clear input because keyboard events blocks clear
window.FindElement('history').Update('\n'.join(command_history[-3:]))
elif button is None or button is 'EXIT': # if exit button or closed using X
elif button in (None, 'EXIT'): # if exit button or closed using X
break
elif 'Up' in button and len(command_history): # scroll back in history
command = command_history[history_offset]

View File

@ -48,9 +48,9 @@ while (True):
if event == 'button':
event = window.FindElement(event).GetText()
# --------- Do Button Operations --------
if event is None or event == 'Exit': # ALWAYS give a way out of program
if event in (None, 'Exit'): # ALWAYS give a way out of program
break
if event is 'Reset':
if event == 'Reset':
start_time = int(round(time.time() * 100))
current_time = 0
paused_time = start_time

View File

@ -30,9 +30,9 @@ while (True):
if event == 'button':
event = window.FindElement(event).GetText()
# --------- Do Button Operations --------
if event is None or event == 'Exit': # ALWAYS give a way out of program
if event in (None, 'Exit'): # ALWAYS give a way out of program
break
if event is 'Reset':
if event == 'Reset':
start_time = int(round(time.time() * 100))
current_time = 0
paused_time = start_time

View File

@ -25,7 +25,7 @@ def Launcher():
# ---===--- Loop taking in user input --- #
while True:
(button, values) = window.Read()
if button is 'Quit' or button is None:
if button in ('Quit', None):
break # exit button clicked
source_file = values['_sourcefile_']
@ -40,7 +40,7 @@ def Launcher():
file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
command_line = 'pyinstaller -wF "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)
if button is 'Make EXE':
if button == 'Make EXE':
out=''
try:
print(command_line)