Merge pull request #219 from MikeTheWatchGuy/Dev-latest

Dev latest
This commit is contained in:
MikeTheWatchGuy 2018-09-13 20:09:21 -04:00 committed by GitHub
commit 9caa62fe5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 15 deletions

View File

@ -16,8 +16,8 @@ ROOT_PATH = './'
def Launcher(): def Launcher():
def print(line): # def print(line):
form.FindElement('output').Update(line) # form.FindElement('output').Update(line)
sg.ChangeLookAndFeel('Dark') sg.ChangeLookAndFeel('Dark')
@ -56,11 +56,15 @@ def ExecuteCommandSubprocess(command, *args, wait=False):
try: try:
if sys.platform == 'linux': if sys.platform == 'linux':
arg_string = '' arg_string = ''
for arg in args: arg_string = ' '.join([str(arg) for arg in args])
arg_string += ' ' + str(arg) # for arg in args:
sp = subprocess.Popen(['python3' + arg_string, ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # arg_string += ' ' + str(arg)
print('python3 ' + arg_string)
sp = subprocess.Popen(['python3 ', arg_string ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else: 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: if wait:
out, err = sp.communicate() out, err = sp.communicate()

View File

@ -19,8 +19,8 @@ sg.ChangeLookAndFeel('Black')
form_rows = [[sg.Text('', size=(8,1), font=('Helvetica', 20),text_color=sg.YELLOWS[0], justification='center', key='text')], 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.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')]] [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 = sg.FlexForm('CPU Utilization', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True)
form.Layout(form_rows) form.Layout(form_rows)
# ---------------- main loop ---------------- # ---------------- main loop ----------------
@ -38,16 +38,17 @@ while (True):
cpu_percent = psutil.cpu_percent(interval=interval) 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 = {proc.name() : proc.cpu_percent() for proc in psutil.process_iter()}
top_sorted = sorted(top.items(), key=operator.itemgetter(1), reverse=True) top_sorted = sorted(top.items(), key=operator.itemgetter(1), reverse=True)
top_sorted.pop(0) top_sorted.pop(0)
display_string = '' display_string = ''
for proc, cpu in top_sorted: for proc, cpu in top_sorted:
display_string += f'{cpu:2.0f} {proc}\n' display_string += '{} {}\n'.format(cpu, proc)
# --------- Display timer in window --------
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('\n'.join(top_sorted))
form.FindElement('processes').Update(display_string) form.FindElement('processes').Update(display_string)

View File

@ -16,17 +16,16 @@ import time
# ---------------- Create Form ---------------- # ---------------- Create Form ----------------
sg.ChangeLookAndFeel('Black') sg.ChangeLookAndFeel('Black')
sg.SetOptions(element_padding=(0, 0)) sg.SetOptions(element_padding=(0, 0))
# Make a form, but don't use context manager
# Create the form layout
form_rows = [[sg.Text('')], form_rows = [[sg.Text('')],
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')], [sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')],
[sg.ReadFormButton('Pause', key='button', button_color=('white', '#001480')), [sg.ReadFormButton('Pause', key='button', button_color=('white', '#001480')),
sg.ReadFormButton('Reset', button_color=('white', '#007339')), sg.ReadFormButton('Reset', button_color=('white', '#007339')),
sg.Exit(button_color=('white', 'firebrick4'))]] 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 = sg.FlexForm('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True)
form.Layout(form_rows) form.Layout(form_rows)
#
# ---------------- main loop ---------------- # ---------------- main loop ----------------
current_time = 0 current_time = 0
paused = False paused = False

View File

@ -1749,6 +1749,8 @@ class FlexForm:
# Another name for ReadNonBlocking. # Another name for ReadNonBlocking.
PrepareForUpdate = ReadNonBlocking PrepareForUpdate = ReadNonBlocking
Finalize = ReadNonBlocking
PreRead = ReadNonBlocking
def Refresh(self): def Refresh(self):