def setup() -> None: # load_filetypes() got already called in setup_argument_parser() get_tab_manager().add_tab_callback(on_new_tab) settings.add_option("default_filetype", "Python") settings.add_combobox( "default_filetype", "Default filetype for new files:", values=sorted(filetypes.keys(), key=str.casefold), ) menubar.add_config_file_button( pathlib.Path(dirs.user_config_dir) / "filetypes.toml") set_filedialog_kwargs() for name, filetype in filetypes.items(): safe_name = name.replace("/", "\N{division slash}") # lol assert "/" not in safe_name menubar.get_menu("Filetypes").add_command(label=safe_name, command=partial( menu_callback, filetype)) menubar.set_enabled_based_on_tab( f"Filetypes/{safe_name}", (lambda tab: isinstance(tab, tabs.FileTab))) new_file_filetypes = get_parsed_args().new_file or [ ] # argparse can give None for filetype in new_file_filetypes: tab = tabs.FileTab(get_tab_manager()) get_tab_manager().add_tab(tab) # sets default filetype apply_filetype_to_tab(tab, filetype) # sets correct filetype
def setup() -> None: for name in sorted(pastebins, key=str.casefold): menubar.get_menu("Share").add_command(label=name, command=functools.partial( start_pasting, name)) assert '/' not in name menubar.set_enabled_based_on_tab( f"Share/{name}", (lambda tab: isinstance(tab, tabs.FileTab)))
def setup() -> None: # the action's binding feature cannot be used because then typing # a '#' outside the main text widget inserts a # to the main widget menubar.get_menu("Edit").add_command( label="Comment Block", command=comment_or_uncomment_in_current_tab) menubar.set_enabled_based_on_tab( "Edit/Comment Block", (lambda tab: isinstance(tab, tabs.FileTab))) utils.bind_with_data(get_tab_manager(), '<<NewTab>>', on_new_tab, add=True)
def create_filetypes_menu() -> None: for name, filetype in filetypes.items(): safe_name = name.replace('/', '\\') # TODO: unicode slash character menubar.get_menu("Filetypes").add_command(label=safe_name, command=partial( menu_callback, filetype)) menubar.set_enabled_based_on_tab( f"Filetypes/{safe_name}", (lambda tab: isinstance(tab, tabs.FileTab)))
def setup() -> None: for klass in [DPaste, Termbin]: menubar.get_menu("Pastebin").add_command(label=klass.name, command=partial( start_pasting, klass)) assert "/" not in klass.name menubar.set_enabled_based_on_tab( f"Pastebin/{klass.name}", (lambda tab: isinstance(tab, tabs.FileTab)))
def setup() -> None: manager = PopManager() get_tab_manager().bind("<Button1-Motion>", manager.on_drag, add=True) get_tab_manager().bind("<ButtonRelease-1>", manager.on_drop, add=True) menubar.get_menu("View").add_command( label="Pop Tab", command=manager.pop_next_to_current_window ) menubar.set_enabled_based_on_tab( "View/Pop Tab", (lambda tab: tab is not None and tab.get_state() is not None) ) open_tab_from_state_file()
def setup() -> None: get_tab_manager().add_tab_callback(on_new_tab) menubar.get_menu("Run").add_command(label="Compile", command=partial(do_something, "compile")) menubar.get_menu("Run").add_command(label="Run", command=partial(do_something, "run")) menubar.get_menu("Run").add_command( label="Compile and Run", command=partial(do_something, "compilerun") ) menubar.get_menu("Run").add_command(label="Lint", command=partial(do_something, "compilerun")) # TODO: disable the menu items when they don't correspond to actual commands for label in {"Compile", "Run", "Compile and Run", "Lint"}: menubar.set_enabled_based_on_tab( f"Run/{label}", (lambda tab: isinstance(tab, tabs.FileTab)) )
def setup() -> None: utils.bind_with_data(get_tab_manager(), '<<NewTab>>', on_new_tab, add=True) menubar.get_menu("Run").add_command(label="Compile", command=partial( do_something, 'compile')) menubar.get_menu("Run").add_command(label="Run", command=partial(do_something, 'run')) menubar.get_menu("Run").add_command(label="Compile and Run", command=partial( do_something, 'compilerun')) menubar.get_menu("Run").add_command(label="Lint", command=partial( do_something, 'compilerun')) # TODO: disable the menu items when they don't correspond to actual commands for label in {"Compile", "Run", "Compile and Run", "Lint"}: menubar.set_enabled_based_on_tab( f"Run/{label}", (lambda tab: isinstance(tab, tabs.FileTab)))
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"
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'
def setup() -> None: menubar.get_menu("Edit").add_command(label="Find and Replace", command=find) menubar.set_enabled_based_on_tab( "Edit/Find and Replace", (lambda tab: isinstance(tab, tabs.FileTab)))
def test_item_doesnt_exist(porcusession): with pytest.raises(LookupError, match=r"^menu item 'Asdf/BlaBlaBla' not found$"): menubar.set_enabled_based_on_tab("Asdf/BlaBlaBla", (lambda tab: True))
def setup() -> None: menubar.get_menu("Edit").add_command(label="Go to Line", command=gotoline) menubar.set_enabled_based_on_tab( "Edit/Go to Line", (lambda tab: isinstance(tab, tabs.FileTab)))
def setup() -> None: menubar.get_menu("Tools/Python").add_command(label="black", command=callback) menubar.set_enabled_based_on_tab( "Tools/Python/black", (lambda tab: isinstance(tab, tabs.FileTab)))
def setup() -> None: wrap_var = tkinter.BooleanVar() wrap_var.trace_add("write", partial(on_menu_toggled, wrap_var)) menubar.get_menu("View").add_checkbutton(label="Wrap Long Lines", variable=wrap_var) menubar.set_enabled_based_on_tab("View/Wrap Long Lines", partial(on_tab_changed, wrap_var))
def setup() -> None: menubar.get_menu("Edit").add_command(label="Sort Lines", command=sort) menubar.set_enabled_based_on_tab( "Edit/Sort Lines", (lambda tab: isinstance(tab, tabs.FileTab)))
def setup() -> None: # TODO: Python tabs only? menubar.get_menu("Tools/Python").add_command(label="autopep8", command=callback) menubar.set_enabled_based_on_tab( "Tools/Python/autopep8", (lambda tab: isinstance(tab, tabs.FileTab)))