moved body of app into main() and build_layout()
This commit is contained in:
parent
83914fa353
commit
e4abc271ed
@ -4,6 +4,7 @@ import os
|
||||
import psutil
|
||||
import PySimpleGUI as sg
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
"""
|
||||
@ -13,6 +14,7 @@ import time
|
||||
on the same row and make only 1 of them active at a time
|
||||
"""
|
||||
|
||||
# ----------- Utility functions -----------
|
||||
def resource_path(relative_path):
|
||||
""" Get absolute path to resource, works for dev and for PyInstaller """
|
||||
try:
|
||||
@ -21,31 +23,40 @@ def resource_path(relative_path):
|
||||
base_path = os.path.abspath(".")
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
def get_service(name):
|
||||
""" return information about services """
|
||||
service = None
|
||||
try:
|
||||
service = psutil.win_service_get(name)
|
||||
service = service.as_dict()
|
||||
except Exception as ex:
|
||||
pass
|
||||
return service
|
||||
|
||||
logo = resource_path("logo.png")
|
||||
|
||||
# ----------- Create the 3 layouts this Window will display -----------
|
||||
layout1 = [
|
||||
def build_layout():
|
||||
logo = resource_path("logo.png")
|
||||
# ----------- Create the 3 layouts this Window will display -----------
|
||||
layout1 = [
|
||||
[sg.Push(), sg.Image(logo), sg.Push()],
|
||||
[sg.Text('This program allows Will B. to remotely control your')],
|
||||
[sg.Text('computer through the internet')],
|
||||
[sg.Text('Is Will waiting for you - *right now* - to run this program?')],
|
||||
]
|
||||
]
|
||||
|
||||
layout2 = [
|
||||
layout2 = [
|
||||
[sg.Text('Remote connection started')],
|
||||
[sg.Text('Allow connection through firewall if asked.')],
|
||||
[sg.Text('')],
|
||||
[sg.Text('Click Exit when finished')],
|
||||
]
|
||||
]
|
||||
|
||||
layout3 = [
|
||||
layout3 = [
|
||||
[sg.Text('Please run this program ONLY when Will is waiting for you')],
|
||||
[sg.Text('Click Exit to continue')],
|
||||
]
|
||||
]
|
||||
|
||||
# ----------- Create actual layout using Columns and a row of Buttons
|
||||
layout = [
|
||||
# ----------- Create actual layout using Columns and a row of Buttons
|
||||
layout = [
|
||||
[
|
||||
sg.Column(layout1, key='-COL1-'),
|
||||
sg.Column(layout2, visible=False, key='-COL2-'),
|
||||
@ -54,7 +65,8 @@ layout = [
|
||||
[sg.VPush()],
|
||||
[sg.Push(), sg.Button('No'), sg.Button('Yes'), sg.Button('Exit', visible=False)]
|
||||
|
||||
]
|
||||
]
|
||||
return layout
|
||||
|
||||
|
||||
def vncdisconnect():
|
||||
@ -71,31 +83,47 @@ def vncdisconnect():
|
||||
# subprocess.call("tvnserver.exe -controlservice -connect remotesupport.pismotek.com", shell=True)
|
||||
# time.sleep(3)
|
||||
|
||||
|
||||
window = sg.Window('Pismotek', layout, size=(380, 350))
|
||||
|
||||
|
||||
layout = 1 # The currently visible layout
|
||||
while True:
|
||||
event, values = window.read()
|
||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||
break
|
||||
elif event == 'No':
|
||||
def tab_no(window):
|
||||
""" handle displaying the no tab/column """
|
||||
window['-COL1-'].update(visible=False)
|
||||
layout = int(3)
|
||||
window['-COL3-'].update(visible=True)
|
||||
window['No'].update(visible=False)
|
||||
window['Yes'].update(visible=False)
|
||||
window['Exit'].update(visible=True)
|
||||
elif event == 'Yes':
|
||||
|
||||
def tab_yes(window):
|
||||
""" handle displaying the yes tab/column"""
|
||||
window['-COL1-'].update(visible=False)
|
||||
layout = int(2)
|
||||
window['-COL2-'].update(visible=True)
|
||||
window['No'].update(visible=False)
|
||||
window['Yes'].update(visible=False)
|
||||
window['Exit'].update(visible=True)
|
||||
# window.perform_long_operation(vncdisconnect, '-VNCCONNECT-')
|
||||
|
||||
def tvn_get_state():
|
||||
""" get current state of tvnserver - retrun stopped if does not exist """
|
||||
status = "stopped"
|
||||
service = get_service('tvnserver')
|
||||
if service:
|
||||
status = service["status"]
|
||||
return status
|
||||
|
||||
def main():
|
||||
tvn_state = tvn_get_state()
|
||||
print(tvn_state)
|
||||
layout = build_layout()
|
||||
window = sg.Window('Pismotek', layout, size=(380, 350))
|
||||
while True:
|
||||
event, values = window.read()
|
||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||
break
|
||||
elif event == 'No':
|
||||
tab_no(window)
|
||||
elif event == 'Yes':
|
||||
tab_yes(window)
|
||||
# elif event == '-VNCCONNECT-':
|
||||
# print("Woot")
|
||||
window.close()
|
||||
window.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user