示例#1
0
def show_created_repo_gui(gh_repo: Repository):
    sg.theme(THEME)

    # All the stuff inside your window.
    layout = [[
        sg.Text(
            f'The new repo {gh_repo.name} is now available. Click the following link to view:'
        )
    ],
              [
                  sg.Text(gh_repo.url,
                          click_submits=True,
                          text_color='blue',
                          key='url_clicked')
              ], [sg.Button('Ok')]]

    # Create the Window
    window = sg.Window('Successfully Created New Repo', layout)
    # Event Loop to process "events" and get the "values" of the inputs
    while True:
        event, values = window.read()
        if event in (None, 'Ok'):  # if user closes window or clicks cancel
            break
        if event == 'url_clicked':
            webbrowser.open(gh_repo.url)

    window.close()
示例#2
0
def should_push_old_repo_gui(temp_repo_dest: str) -> bool:
    sg.theme(THEME)

    message = f"""
The old repo has the history removed in a temporary repo in {temp_repo_dest}. Please examine 
the history in detail. If everything looks correct, click "Remove History" to remove the 
history from the old repo. This will overwrite the existing remote repo. If there is some issue
or you do not want to push the overwritten history, press "Cancel".
    """.strip()

    # All the stuff inside your window.
    layout = [[sg.Text(message)],
              [sg.Button('Remove History'),
               sg.Button('Cancel')]]

    # Create the Window
    window = sg.Window('Successfully Removed History From Old Repo. Push it?',
                       layout)
    # Event Loop to process "events" and get the "values" of the inputs
    push_history = False
    while True:
        event, values = window.read()
        if event in (None, 'Cancel'):  # if user closes window or clicks cancel
            break
        if event == 'Remove History':
            push_history = True
            break

    window.close()

    return push_history
示例#3
0
def dismiss_message_gui(message: str, title: Optional[str] = 'Notice'):
    sg.theme(THEME)

    # All the stuff inside your window.
    layout = [[sg.Text(message)], [sg.Button('Ok')]]

    # Create the Window
    window = sg.Window(title, layout)
    # Event Loop to process "events" and get the "values" of the inputs
    while True:
        event, values = window.read()
        if event in (None, 'Ok'):  # if user closes window or clicks cancel
            break

    window.close()
示例#4
0
def error_window(exc: TracebackException):
    message = ''.join(exc.format())

    layout = [[sg.Text(message)], [sg.Button('Ok')]]

    window = sg.Window('Error', layout)

    # --------------------- EVENT LOOP ---------------------
    while True:
        event, values = window.Read(
            timeout=100)  # wait for up to 100 ms for a GUI event
        if event is None or event == 'Ok':
            break

    # if user exits the window, then close the window and exit the GUI func
    window.Close()
示例#5
0
def repo_select_gui(
        defaults: Optional[Dict[str,
                                Any]] = None) -> Optional[SelectRepoConfig]:
    expected_defaults = [
        'repo_loc_url',
        'new_repo_name',
        'github_token',
    ]
    if not defaults:
        defaults = {}
    for def_key in expected_defaults:
        if def_key not in defaults:
            defaults[def_key] = ''

    sg.theme(THEME)

    config: Optional[SelectRepoConfig] = None

    # All the stuff inside your window.
    layout = [[
        sg.Text('Please select either a remote repo by URL or a local repo.')
    ],
              [
                  sg.Text('Repo by URL:'),
                  sg.InputText(key='repo_loc_url',
                               default_text=defaults['repo_loc_url'])
              ],
              [
                  sg.Text('Local repo:'),
                  sg.FolderBrowse(key='repo_loc_file_path')
              ],
              [
                  sg.Text('New Repo Name:'),
                  sg.InputText(key='new_repo_name',
                               default_text=defaults['new_repo_name'])
              ],
              [
                  sg.Text('Github Token:'),
                  sg.InputText(key='gh_token',
                               default_text=defaults['github_token'])
              ], [sg.Checkbox('Split all branches', key='all_branches')],
              [sg.Checkbox('Include tags in new repo', key='include_tags')],
              [
                  sg.Checkbox('Create new repo from selected files',
                              key='create_new_repo',
                              default=True)
              ],
              [
                  sg.Checkbox('Remove history from the old repo',
                              key='remove_files_from_old_repo',
                              default=True)
              ],
              [
                  sg.Checkbox('Store Github Token for later use',
                              key='store_gh_token',
                              default=True)
              ], [sg.Button('Ok'), sg.Button('Cancel')]]

    # Create the Window
    window = sg.Window('Repo Splitter - Select Repo', layout)
    # Event Loop to process "events" and get the "values" of the inputs
    while True:
        event, values = window.read()
        if event in (None, 'Cancel'):  # if user closes window or clicks cancel
            break
        elif event == 'Ok':
            try:
                config = SelectRepoConfig(
                    values['new_repo_name'],
                    values['gh_token'],
                    repo_url=values['repo_loc_url'],
                    repo_local_path=values['repo_loc_file_path'],
                    all_branches=values['all_branches'],
                    include_tags=values['include_tags'],
                    remove_files_from_old_repo=values[
                        'remove_files_from_old_repo'],
                    create_new_repo=values['create_new_repo'],
                    store_gh_token=values['store_gh_token'],
                )
                break
            except MustProvideRepoException:
                sg.Popup('Please provide either a repo URL or local repo path')
            except MustProvideOnlyOneRepoException:
                sg.Popup(
                    'Please provide only one of repo URL and local repo path')
            except MustProvideInputException as e:
                sg.Popup(f'Please provide {e.input_name}')
            except MustDoSomethingException:
                sg.Popup(
                    f'Must either create a new repo or remove history from old repo or both, '
                    f'or else what are you trying to do?')

    window.close()
    return config
示例#6
0
def select_files_gui(files: List[str], repo: Repo) -> List[str]:
    sg.theme(THEME)

    orig_to_select = files
    orig_selected = []
    all_items = orig_to_select + orig_selected

    # All the stuff inside your window.
    layout = [
        [sg.Text('Please select which files should be split from the repo.')],
        [
            sg.Text('Enter a glob pattern:'),
            sg.InputText(key='file_pattern'),
            sg.Checkbox('Include renames', default=True,
                        key='include_renames'),
            sg.Button('Match'),
        ],
        [
            sg.Col([
                [sg.Text("Don't Split"),
                 sg.Button('Sort', key='sort_left')],
                [
                    sg.Listbox(orig_to_select,
                               **FILES_LISTBOX_SETTINGS,
                               key='files_to_select')
                ],
            ]),
            sg.Col([
                [sg.Text('')],
                [sg.Text('')],
                [sg.Button('>')],
                [sg.Button('<')],
                [sg.Button('>>')],
                [sg.Button('<<')],
            ]),
            sg.Col([
                [sg.Text("Split"),
                 sg.Button('Sort', key='sort_right')],
                [
                    sg.Listbox(orig_selected,
                               **FILES_LISTBOX_SETTINGS,
                               key='files_selected')
                ],
            ]),
        ], [sg.Button('Ok'), sg.Button('Cancel')]
    ]

    # Create the Window
    window = sg.Window('Repo Splitter - Select Files', layout)
    # Event Loop to process "events" and get the "values" of the inputs
    exit_on_close = True
    while True:
        event, values = window.read()
        if event in (None, 'Cancel'):  # if user closes window or clicks cancel
            break
        if event == 'Ok':
            exit_on_close = False
            break
        left_selected = deepcopy(values['files_to_select'])
        right_selected = deepcopy(values['files_selected'])
        left_listbox = window['files_to_select']
        right_listbox = window['files_selected']
        left_all_values = left_listbox.Values
        right_all_values = right_listbox.Values
        if event == 'Match':
            # Handle glob match to move files to right
            file_pattern = values['file_pattern']
            include_renames = values['include_renames']
            matched_files = get_desired_files_from_patterns(
                repo, [file_pattern], follow_renames=include_renames)
            for item in matched_files:
                if item in left_all_values:
                    left_all_values.remove(item)
                if item in all_items and item not in right_all_values:
                    right_all_values.append(item)
        elif event == 'sort_left':
            left_all_values.sort()
        elif event == 'sort_right':
            right_all_values.sort()
        elif event == '>':
            # Add left selected items to right listbox
            for item in left_selected:
                left_all_values.remove(item)
                right_all_values.append(item)
        elif event == '<':
            # Add right selected items to left listbox
            for item in right_selected:
                left_all_values.append(item)
                right_all_values.remove(item)
        elif event == '>>':
            # Add all left items to right listbox
            left_all_values = []
            right_all_values = all_items
        elif event == '<<':
            # Add all right items to left listbox
            left_all_values = all_items
            right_all_values = []

        left_listbox.update(left_all_values)
        right_listbox.update(right_all_values)

    right_listbox = window['files_selected']
    final_selected_values = right_listbox.Values

    window.close()

    if exit_on_close:
        exit(0)

    return final_selected_values