예제 #1
0
def start_xterm():
    tab = tabs.Tab(get_tab_manager())
    tab.title = "Terminal"
    content = tkinter.Frame(tab, container=True)
    content.pack(fill='both', expand=True)

    try:
        process = subprocess.Popen(['xterm', '-into', str(content.winfo_id())])
    except FileNotFoundError:
        messagebox.showerror("xterm not found", (
            "Seems like xterm is not installed. " +
            "Please install it and try again."))
        return

    def close_if_not_closed(junk):
        if tab in get_tab_manager().tabs:
            get_tab_manager().close_tab(tab)

    # the content is destroyed when the terminal wants to exit
    content.bind('<Destroy>', close_if_not_closed, add=True)

    # the tab is destroyed when the user wants to close it
    tab.bind('<Destroy>', lambda event: process.terminate(), add=True)

    get_tab_manager().add_tab(tab)
예제 #2
0
def test_filetype_names(porcusession, tabmanager, action_path, filetypes):
    # make sure these filetypes exist
    filetypes.get_filetype_by_name('C')
    filetypes.get_filetype_by_name('Java')
    filetypes.get_filetype_by_name('Python')
    filetypes.get_filetype_by_name('Plain Text')

    filetab = tabs.FileTab(tabmanager)
    othertab = tabs.Tab(tabmanager)

    action = actions.add_yesno(action_path, True,
                               filetype_names=['C', 'Python'])
    assert not action.enabled

    tabmanager.add_tab(othertab)
    assert tabmanager.select() is othertab
    assert not action.enabled

    tabmanager.add_tab(filetab)
    assert tabmanager.select() is filetab
    assert not action.enabled

    filetab.filetype = filetypes.get_filetype_by_name('Java')
    assert not action.enabled
    filetab.filetype = filetypes.get_filetype_by_name('C')
    assert action.enabled

    tabmanager.close_tab(filetab)
    tabmanager.update()
    assert not action.enabled
    tabmanager.close_tab(othertab)
    tabmanager.update()
    assert not action.enabled
예제 #3
0
def test_set_enabled_based_on_tab(porcusession, tabmanager):
    tab1 = tabs.Tab(tabmanager)
    tab2 = tabs.Tab(tabmanager)

    menubar.get_menu("Foo").add_command(label="Spam")
    menubar.set_enabled_based_on_tab("Foo/Spam", (lambda tab: tab is tab2))
    assert menubar.get_menu("Foo").entrycget('end', 'state') == 'disabled'

    tabmanager.add_tab(tab1)
    assert menubar.get_menu("Foo").entrycget('end', 'state') == 'disabled'

    tabmanager.add_tab(tab2)
    assert menubar.get_menu("Foo").entrycget('end', 'state') == 'normal'

    tabmanager.select(tab1)
    tabmanager.update()
    assert menubar.get_menu("Foo").entrycget('end', 'state') == 'disabled'

    tabmanager.close_tab(tab1)
    tabmanager.close_tab(tab2)
    assert menubar.get_menu("Foo").entrycget('end', 'state') == 'disabled'
예제 #4
0
def test_set_enabled_based_on_tab(tabmanager):
    tab1 = tabs.Tab(tabmanager)
    tab2 = tabs.Tab(tabmanager)

    menubar.get_menu("Foo").add_command(label="Spam")
    menubar.set_enabled_based_on_tab("Foo/Spam", (lambda tab: tab is tab2))
    assert menubar.get_menu("Foo").entrycget("end", "state") == "disabled"

    tabmanager.add_tab(tab1)
    assert menubar.get_menu("Foo").entrycget("end", "state") == "disabled"

    tabmanager.add_tab(tab2)
    assert menubar.get_menu("Foo").entrycget("end", "state") == "normal"

    tabmanager.select(tab1)
    tabmanager.update()
    assert menubar.get_menu("Foo").entrycget("end", "state") == "disabled"

    tabmanager.close_tab(tab1)
    tabmanager.close_tab(tab2)
    assert menubar.get_menu("Foo").entrycget("end", "state") == "disabled"
예제 #5
0
def start_xterm() -> None:
    tab = tabs.Tab(get_tab_manager())
    tab.title_choices = ["Terminal"]
    content = tkinter.Frame(tab, container=True)
    content.pack(fill="both", expand=True)  # FIXME: doesn't stretch correctly?

    try:
        process = subprocess.Popen(["xterm", "-into", str(content.winfo_id())])
    except FileNotFoundError:
        messagebox.showerror(
            "xterm not found", "Seems like xterm is not installed. Please install it and try again."
        )
        return

    def terminal_wants_to_exit(junk: object) -> None:
        if tab in get_tab_manager().tabs():
            get_tab_manager().close_tab(tab)

    content.bind("<Destroy>", terminal_wants_to_exit, add=True)
    tab.bind("<Destroy>", (lambda event: process.terminate()), add=True)
    get_tab_manager().add_tab(tab)