import PySimpleGUI as sg import http.client import json import webbrowser terminal_colors = { "RESET": "\033[0m", "RED": "\033[1;31;40m", "GREEN": "\033[1;32;40m", "YELLOW": "\033[1;33;40m", "BLUE": "\033[1;34;40m", } terminal_status = { "ERROR": "RED", "SUCCESS": "GREEN", "WARNING": "YELLOW", "INFO": "BLUE", } def customPrint(text, status): print_start = f"{terminal_colors[terminal_status[status]]}{status}{terminal_colors['RESET']}: " print_end = f"{terminal_colors['RESET']}" print(f"{print_start}{text}{print_end}") print("Launching") customPrint("Fetching projects", "INFO") ismpety = False # GITEA API repo_name = "alexveebee/py_projects" conn = http.client.HTTPSConnection("git.alexveebee.nl") payload = '' headers = {} try: conn.request("GET", "/api/v1/repos/"+repo_name, payload, headers) res = conn.getresponse() data = res.read() project_list = json.loads(data.decode("utf-8")) # print(project_list) customPrint("Fetched projects", "SUCCESS") # is empty if project_list["empty"]: customPrint("No projects found", "WARNING") ismpety = True except Exception as e: customPrint("Unexpected error", "ERROR") print("Error: ") print(e) def main(): # define the window layout layout = [ [sg.Text("Project Manager"), sg.Text("Located in: "+repo_name, key="-REPO-", click_submits=True)], [sg.Text("Select a project to open:")], # list [sg.Listbox(values=(), size=(30, 6), key="-PROJECTS-", expand_x=True, expand_y=True)], [sg.Button("OK", key="-OK-"), sg.Button("Cancel", key="-CANCEL-")], ] # create the window window = sg.Window("Alex's Projects", layout, size=(300, 500)) # create an event loop while True: event, values = window.read() # end program if user closes window or # presses the OK button if event == sg.WIN_CLOSED: break if event == "-OK-": if ismpety: customPrint("No project found", "WARNING") else: customPrint("Opening project", "INFO") print(values["-PROJECTS-"]) webbrowser.open_new_tab("https://git.alexveebee.nl/"+repo_name+"/src/branch/master/"+values["-PROJECTS-"][0]) if event == "-CANCEL-": break if event == "-REPO-": webbrowser.open_new_tab("https://git.alexveebee.nl/"+repo_name) window.close() if __name__ == '__main__': try: main() print("Close") except Exception as e: print('Error: ', end='') print(e) print() input('Press Enter to continue...')