def setup(): actions.add_command("Edit/Find and Replace", find, '<Control-f>', tabtypes=[tabs.FileTab]) utils.bind_with_data(get_tab_manager(), '<<NewTab>>', on_new_tab, add=True) get_tab_manager().bind('<<NotebookTabChanged>>', on_tab_changed, add=True)
def setup(): # the action's binding feature cannot be used because then typing # a '#' outside the main text widget inserts a # to the main widget actions.add_command("Edit/Comment Block", comment_or_uncomment, filetype_names=filetype_names) utils.bind_with_data(get_tab_manager(), '<<NewTab>>', on_new_tab, add=True)
def setup(): tabtypes = [tabs.FileTab] if pythonprompt is not None: tabtypes.append(pythonprompt.PromptTab) for name in sorted(_pastebins, key=str.casefold): assert '/' not in name, "porcupine.actions needs to be fixed" callback = functools.partial(start_pasting, name) actions.add_command("Share/" + name, callback, tabtypes=tabtypes)
def setup(): # it's possible to run full X11 on a Mac, so this is better than # e.g. platform.system() # FIXME: i think it's possible to run xterm in aqua? would that # work here? if get_tab_manager().tk.call('tk', 'windowingsystem') != 'x11': # TODO: more noob-friendly "u have the wrong os lel" message? messagebox.showerror( "Unsupported windowing system", "Sorry, the terminal plugin only works on X11 :(") return actions.add_command("Tools/Terminal", start_xterm, '<Control-T>')
def test_add_command_and_stuff(porcusession, action_path): root = get_main_window() callback_ran = False def callback(): nonlocal callback_ran callback_ran = True with action_events() as (new_events, enable_events, disable_events): action = actions.add_command(action_path, callback, '<<Test>>') assert new_events.pop().data == action_path assert actions.get_action(action_path) is action assert action in actions.get_all_actions() assert action.path == action_path assert action.kind == 'command' assert action.binding == '<<Test>>' assert action.enabled assert action.callback is callback assert not hasattr(action, 'var') assert not hasattr(action, 'choices') assert (repr(action) == str(action) == "<Action object '" + action_path + "': kind='command', enabled=True>") action.enabled = False assert disable_events.pop().data == action_path assert 'enabled=False' in repr(action) action.enabled = False assert not disable_events action.enabled = True assert enable_events.pop().data == action_path assert 'enabled=True' in repr(action) action.enabled = True assert not enable_events with pytest.raises(TypeError): action.enabled = 1 action.enabled = False assert not callback_ran root.event_generate('<<Test>>') assert not callback_ran action.enabled = True root.event_generate('<<Test>>') assert callback_ran root.unbind('<<Test>>')
def setup(): compilable = get_filetype_names('compile_command') runnable = get_filetype_names('run_command') lintable = get_filetype_names('lint_command') def create_callback(something): return functools.partial(do_something_to_this_file, something) actions.add_command("Run/Compile", create_callback('compile'), '<F4>', filetype_names=compilable) actions.add_command("Run/Run", create_callback('run'), '<F5>', filetype_names=runnable) actions.add_command("Run/Compile and Run", create_callback('compilerun'), '<F6>', filetype_names=(compilable & runnable)) actions.add_command("Run/Lint", create_callback('lint'), '<F7>', filetype_names=lintable)
def setup(): for name in sorted(pastebins, key=str.casefold): assert '/' not in name callback = functools.partial(start_pasting, name) actions.add_command("Share/" + name, callback, tabtypes=[tabs.FileTab])
def test_errors(porcusession, action_path): actions.add_command('Test Blah Blah', print) # should work without '/' with pytest.raises(ValueError): actions.add_command('/wat', print) with pytest.raises(ValueError): actions.add_command('wat/', print) with pytest.raises(TypeError): actions.add_command(action_path, print, filetype_names=['Python'], tabtypes=[tabs.Tab]) actions.add_command(action_path, print) with pytest.raises(RuntimeError): actions.add_command(action_path, print) # exists already
def setup(): actions.add_command('IRC/Chat in IRC', open_irc)
def setup(): actions.add_command( "Games/Tetris", lambda: get_tab_manager().add_tab(TetrisTab(get_tab_manager())))
def add_link(path, url): actions.add_command(path, functools.partial(webbrowser.open, url))
def _setup_actions(): def new_file(): _tab_manager.add_tab(tabs.FileTab(_tab_manager)) def open_files(): for path in _dialogs.open_files(): try: tab = tabs.FileTab.open_file(_tab_manager, path) except (UnicodeError, OSError) as e: log.exception("opening '%s' failed", path) utils.errordialog(type(e).__name__, "Opening failed!", traceback.format_exc()) continue _tab_manager.add_tab(tab) def close_selected_tab(): tab = _tab_manager.select() if tab.can_be_closed(): _tab_manager.close_tab(tab) # TODO: allow adding separators to menus actions.add_command("File/New File", new_file, '<Control-n>') actions.add_command("File/Open", open_files, '<Control-o>') actions.add_command("File/Save", (lambda: _tab_manager.select().save()), '<Control-s>', tabtypes=[tabs.FileTab]) actions.add_command("File/Save As...", (lambda: _tab_manager.select().save_as()), '<Control-S>', tabtypes=[tabs.FileTab]) # TODO: disable File/Quit when there are tabs, it's too easy to hit # Ctrl+Q accidentally actions.add_command("File/Close", close_selected_tab, '<Control-w>', tabtypes=[tabs.Tab]) actions.add_command("File/Quit", quit, '<Control-q>') # TODO: is Edit the best possible place for this? actions.add_command("Edit/Porcupine Settings...", settings.show_dialog) def change_font_size(how): config = settings.get_section('General') if how == 'reset': config.reset('font_size') else: try: config['font_size'] += (1 if how == 'bigger' else -1) except settings.InvalidValue: pass # these work only with filetabs because that way the size change is # noticable # TODO: maybe these shouldn't be bound globally? actions.add_command( "View/Bigger Font", functools.partial(change_font_size, 'bigger'), '<Control-plus>', tabtypes=[tabs.FileTab]) actions.add_command( "View/Smaller Font", functools.partial(change_font_size, 'smaller'), '<Control-minus>', tabtypes=[tabs.FileTab]) actions.add_command( "View/Reset Font Size", functools.partial(change_font_size, 'reset'), '<Control-0>', tabtypes=[tabs.FileTab]) def add_link(path, url): actions.add_command(path, functools.partial(webbrowser.open, url)) # TODO: an about dialog that shows porcupine version, Python version # and where porcupine is installed # TODO: porcupine starring button add_link("Help/Porcupine Wiki", "https://github.com/Akuli/porcupine/wiki") add_link("Help/Report a problem or request a feature", "https://github.com/Akuli/porcupine/issues/new") add_link("Help/Read Porcupine's code on GitHub", "https://github.com/Akuli/porcupine/tree/master/porcupine") add_link("Help/Python Help/Free help chat", "http://webchat.freenode.net/?channels=%23%23learnpython") add_link("Help/Python Help/My Python tutorial", "https://github.com/Akuli/python-tutorial/blob/master/README.md") add_link("Help/Python Help/Official Python documentation", "https://docs.python.org/")
def setup(): actions.add_command("Games/Tetris", play_tetris)
def setup(): actions.add_command("Tools/autopep8", callback, filetype_names=["Python"])
def setup(): actions.add_command("Edit/Find and Replace", find, '<Control-f>', tabtypes=[tabs.FileTab])
def _setup_actions(): def new_file(): _tab_manager.add_tab(tabs.FileTab(_tab_manager)) def open_files(): paths = filedialog.askopenfilenames( **filetypes.get_filedialog_kwargs()) # tkinter returns '' if the user cancels, and i'm arfaid that python # devs might "fix" a future version to return None if not paths: return for path in paths: try: tab = tabs.FileTab.open_file(_tab_manager, path) except (UnicodeError, OSError) as e: log.exception("opening '%s' failed", path) utils.errordialog( type(e).__name__, "Opening failed!", traceback.format_exc()) continue _tab_manager.add_tab(tab) def close_selected_tab(): tab = _tab_manager.select() if tab.can_be_closed(): _tab_manager.close_tab(tab) # TODO: an API for adding separators to menus nicely? or just recommend # putting related items in a submenu? actions.add_command("File/New File", new_file, '<Control-n>') actions.add_command("File/Open", open_files, '<Control-o>') actions.add_command("File/Save", (lambda: _tab_manager.select().save()), '<Control-s>', tabtypes=[tabs.FileTab]) actions.add_command("File/Save As...", (lambda: _tab_manager.select().save_as()), '<Control-S>', tabtypes=[tabs.FileTab]) # TODO: disable File/Quit when there are tabs, it's too easy to hit # Ctrl+Q accidentally actions.add_command("File/Close", close_selected_tab, '<Control-w>', tabtypes=[tabs.Tab]) actions.add_command("File/Quit", quit, '<Control-q>') # TODO: is Edit the best possible place for this? maybe a Settings menu # that could also contain plugin-specific settings, and maybe even # things like ttk themes and color styles? actions.add_command("Edit/Porcupine Settings...", settings.show_dialog) def change_font_size(how): # TODO: i think there is similar code in a couple other places too config = settings.get_section('General') if how == 'reset': config.reset('font_size') else: try: config['font_size'] += (1 if how == 'bigger' else -1) except settings.InvalidValue: pass # these work only with filetabs because that way the size change is # noticable actions.add_command("View/Bigger Font", functools.partial(change_font_size, 'bigger'), '<Control-plus>', tabtypes=[tabs.FileTab]) actions.add_command("View/Smaller Font", functools.partial(change_font_size, 'smaller'), '<Control-minus>', tabtypes=[tabs.FileTab]) actions.add_command("View/Reset Font Size", functools.partial(change_font_size, 'reset'), '<Control-0>', tabtypes=[tabs.FileTab]) def add_link(path, url): actions.add_command(path, functools.partial(webbrowser.open, url)) # TODO: porcupine starring button? add_link("Help/Porcupine Wiki", "https://github.com/Akuli/porcupine/wiki") add_link("Help/Report a problem or request a feature", "https://github.com/Akuli/porcupine/issues/new") add_link("Help/Read Porcupine's code on GitHub", "https://github.com/Akuli/porcupine/tree/master/porcupine") add_link("Help/Python Help/Free help chat", "http://webchat.freenode.net/?channels=%23%23learnpython") add_link("Help/Python Help/My Python tutorial", "https://github.com/Akuli/python-tutorial/blob/master/README.md") add_link("Help/Python Help/Official Python documentation", "https://docs.python.org/")
def setup(): actions.add_command("Edit/Go to Line", gotoline, '<Control-l>', tabtypes=[tabs.FileTab])