Program Works

This commit is contained in:
Fredrcik W. Warren 2024-05-27 02:30:04 -06:00
parent dcc55d8aee
commit 21b4c6bae4

View File

@ -66,26 +66,11 @@ def build_layout():
sg.Column(layout3, visible=False, key='-COL3-') sg.Column(layout3, visible=False, key='-COL3-')
], ],
[sg.VPush()], [sg.VPush()],
[sg.Push(), sg.Button('No'), sg.Button('Yes'), sg.Button('Exit', visible=False)] [sg.Push(), sg.Button('No'), sg.Button('Yes', focus=True), sg.Button('Exit', visible=False)]
] ]
return layout return layout
def vncdisconnect():
print("Starting TightVNC")
subprocess.call("tvnserver.exe -run", shell=True)
time.sleep(3)
print("Starting Disconnecting TightVNC")
subprocess.call("tvnserver.exe -controlservice -disconnectall", shell=True)
print("Did we get an error")
time.sleep(15)
# def vncconnect():
# print("This one as well")
# subprocess.call("tvnserver.exe -controlservice -connect remotesupport.pismotek.com", shell=True)
# time.sleep(3)
def tab_no(window): def tab_no(window):
""" handle displaying the no tab/column """ """ handle displaying the no tab/column """
window['-COL1-'].update(visible=False) window['-COL1-'].update(visible=False)
@ -94,14 +79,14 @@ def tab_no(window):
window['Yes'].update(visible=False) window['Yes'].update(visible=False)
window['Exit'].update(visible=True) window['Exit'].update(visible=True)
def tab_yes(window): def tab_yes(window, tvn_mode, tvn_state):
""" handle displaying the yes tab/column""" """ handle displaying the yes tab/column"""
window['-COL1-'].update(visible=False) window['-COL1-'].update(visible=False)
window['-COL2-'].update(visible=True) window['-COL2-'].update(visible=True)
window['No'].update(visible=False) window['No'].update(visible=False)
window['Yes'].update(visible=False) window['Yes'].update(visible=False)
window['Exit'].update(visible=True) window['Exit'].update(visible=True)
# window.perform_long_operation(vncdisconnect, '-VNCCONNECT-') window.perform_long_operation(lambda : vncconnect(tvn_mode, tvn_state), '-VNCCONNECT-')
def tvn_get_state(): def tvn_get_state():
""" get current state of tvnserver - retrun stopped if does not exist """ """ get current state of tvnserver - retrun stopped if does not exist """
@ -118,18 +103,34 @@ def get_tvnserver_info():
application running - can use as is application running - can use as is
application stopped - need to start application application stopped - need to start application
""" """
mode = "application" mode = "-controlapp"
state = tvn_get_state() state = tvn_get_state()
if state == "running": if state == "running":
mode = "service" mode = "-controlservice"
elif "tvnserver.exe" in (p.name() for p in psutil.process_iter()): elif "tvnserver.exe" in (p.name() for p in psutil.process_iter()):
state = "running" state = "running"
return mode, state return mode, state
def vncconnect(tvn_mode, tvn_state):
""" start tvnserver if needed, kill any connection and attempt to connect """
app = resource_path("tvnserver.exe")
# print(tvn_mode, tvn_state, app)
if tvn_state == "stopped":
print("Starting Service")
# subprocess.call([app, "-run"], shell=True)
sg.execute_command_subprocess(app, *["-run"], wait=False)
time.sleep(3)
# print("Disconnectiong")
sg.execute_command_subprocess(app, *[tvn_mode, "-disconnectall"], wait=False)
time.sleep(3)
# print("Connecting")
sg.execute_command_subprocess(app, *[tvn_mode, "-connect 192.168.0.94"], wait=False)
def main(): def main():
tvn_mode, tvn_state = get_tvnserver_info() tvn_mode, tvn_state = get_tvnserver_info()
icon_file=resource_path('remotedesktop.ico')
layout = build_layout() layout = build_layout()
window = sg.Window('Pismotek', layout, size=(380, 350)) window = sg.Window('Pismotek', layout, size=(380, 350), icon=icon_file)
while True: while True:
event, values = window.read() event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'): if event in (sg.WIN_CLOSED, 'Exit'):
@ -137,8 +138,8 @@ def main():
elif event == 'No': elif event == 'No':
tab_no(window) tab_no(window)
elif event == 'Yes': elif event == 'Yes':
tab_yes(window) tab_yes(window, tvn_mode, tvn_state)
window.close() # window.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()