From f112907e894896a945ecc4eb635c061df8612a05 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 13 Sep 2018 19:57:58 -0400 Subject: [PATCH 1/2] Removed f-strings, fixed Raspberry Pi launching issue. New function names for ReadNonBlocking - Finalize, PreRead --- Demo_Desktop_Floating_Toolbar.py | 16 ++++++++++------ Demo_Desktop_Widget_CPU_Utilization.py | 9 +++++---- PySimpleGUI.py | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Demo_Desktop_Floating_Toolbar.py b/Demo_Desktop_Floating_Toolbar.py index 5b17d327..07d806f5 100644 --- a/Demo_Desktop_Floating_Toolbar.py +++ b/Demo_Desktop_Floating_Toolbar.py @@ -16,8 +16,8 @@ ROOT_PATH = './' def Launcher(): - def print(line): - form.FindElement('output').Update(line) + # def print(line): + # form.FindElement('output').Update(line) sg.ChangeLookAndFeel('Dark') @@ -56,11 +56,15 @@ def ExecuteCommandSubprocess(command, *args, wait=False): try: if sys.platform == 'linux': arg_string = '' - for arg in args: - arg_string += ' ' + str(arg) - sp = subprocess.Popen(['python3' + arg_string, ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + arg_string = ' '.join([str(arg) for arg in args]) + # for arg in args: + # arg_string += ' ' + str(arg) + print('python3 ' + arg_string) + sp = subprocess.Popen(['python3 ', arg_string ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: - sp = subprocess.Popen([command, list(args)], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + arg_string = ' '.join([str(arg) for arg in args]) + sp = subprocess.Popen([command, arg_string], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # sp = subprocess.Popen([command, list(args)], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if wait: out, err = sp.communicate() diff --git a/Demo_Desktop_Widget_CPU_Utilization.py b/Demo_Desktop_Widget_CPU_Utilization.py index 00d09d6e..79540a13 100644 --- a/Demo_Desktop_Widget_CPU_Utilization.py +++ b/Demo_Desktop_Widget_CPU_Utilization.py @@ -19,7 +19,7 @@ sg.ChangeLookAndFeel('Black') form_rows = [[sg.Text('', size=(8,1), font=('Helvetica', 20),text_color=sg.YELLOWS[0], justification='center', key='text')], [sg.Text('', size=(30, 8), font=('Courier', 10),text_color='white', justification='left', key='processes')], [sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0)), sg.Spin([x+1 for x in range(10)], 1, key='spin')]] -# Layout the rows of the form and perform a read. Indicate the form is non-blocking! + form = sg.FlexForm('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True) form.Layout(form_rows) @@ -38,16 +38,17 @@ while (True): cpu_percent = psutil.cpu_percent(interval=interval) + # --------- Create list of top % CPU porocesses -------- top = {proc.name() : proc.cpu_percent() for proc in psutil.process_iter()} top_sorted = sorted(top.items(), key=operator.itemgetter(1), reverse=True) top_sorted.pop(0) display_string = '' for proc, cpu in top_sorted: - display_string += f'{cpu:2.0f} {proc}\n' - # --------- Display timer in window -------- + display_string += '{} {}\n'.format(cpu, proc) - form.FindElement('text').Update(f'CPU {cpu_percent:02.0f}%') + # --------- Display timer in window -------- + form.FindElement('text').Update('CPU {}'.format(cpu_percent)) # form.FindElement('processes').Update('\n'.join(top_sorted)) form.FindElement('processes').Update(display_string) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 8f3e4716..e90589dd 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -1749,6 +1749,8 @@ class FlexForm: # Another name for ReadNonBlocking. PrepareForUpdate = ReadNonBlocking + Finalize = ReadNonBlocking + PreRead = ReadNonBlocking def Refresh(self): From 317f90b0c51d6d941e4ab2558729b43f500c7f25 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 13 Sep 2018 20:08:35 -0400 Subject: [PATCH 2/2] Typos --- Demo_Desktop_Widget_CPU_Utilization.py | 2 +- Demo_Desktop_Widget_Timer.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Demo_Desktop_Widget_CPU_Utilization.py b/Demo_Desktop_Widget_CPU_Utilization.py index 79540a13..8710b157 100644 --- a/Demo_Desktop_Widget_CPU_Utilization.py +++ b/Demo_Desktop_Widget_CPU_Utilization.py @@ -20,7 +20,7 @@ form_rows = [[sg.Text('', size=(8,1), font=('Helvetica', 20),text_color=sg.YELLO [sg.Text('', size=(30, 8), font=('Courier', 10),text_color='white', justification='left', key='processes')], [sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0)), sg.Spin([x+1 for x in range(10)], 1, key='spin')]] -form = sg.FlexForm('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True) +form = sg.FlexForm('CPU Utilization', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True) form.Layout(form_rows) # ---------------- main loop ---------------- diff --git a/Demo_Desktop_Widget_Timer.py b/Demo_Desktop_Widget_Timer.py index 76040c50..c0221999 100644 --- a/Demo_Desktop_Widget_Timer.py +++ b/Demo_Desktop_Widget_Timer.py @@ -16,17 +16,16 @@ import time # ---------------- Create Form ---------------- sg.ChangeLookAndFeel('Black') sg.SetOptions(element_padding=(0, 0)) -# Make a form, but don't use context manager -# Create the form layout + form_rows = [[sg.Text('')], [sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')], [sg.ReadFormButton('Pause', key='button', button_color=('white', '#001480')), sg.ReadFormButton('Reset', button_color=('white', '#007339')), sg.Exit(button_color=('white', 'firebrick4'))]] -# Layout the rows of the form and perform a read. Indicate the form is non-blocking! + form = sg.FlexForm('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True) form.Layout(form_rows) -# + # ---------------- main loop ---------------- current_time = 0 paused = False