How to use the bpython.translations._ function in bpython

To help you get started, we’ve selected a few bpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ivanov / bipython / bipython / __init__.py View on Github external
translations.init()

    import argparse
    parser = argparse.ArgumentParser(
            description='the boldly indiscriminate Python interpreter')
    parser.add_argument( '-v','--version', action='version',
            version='%(prog)s ' + version)
    parser.parse_known_args()

    # ok, it's not nice, i'm hiding all of these params, but LTS.
    #
    # TODO: maybe support displays other than raw_display?
    config, options, exec_args = bpargs.parse(args, (
            'Urwid options', None, [
                Option('--twisted', '-T', action='store_true',
                       help=_('Run twisted reactor.')),
                Option('--reactor', '-r',
                       help=_('Select specific reactor (see --help-reactors). '
                       'Implies --twisted.')),
                Option('--help-reactors', action='store_true',
                       help=_('List available reactors for -r.')),
                Option('--plugin', '-p',
                       help=_('twistd plugin to run (use twistd for a list). '
                       'Use "--" to pass further options to the plugin.')),
                Option('--server', '-s', type='int',
                       help=_('Port to run an eval server on (forces Twisted).')),
                ]))

    if options.help_reactors:
        try:
            from twisted.application import reactors
            # Stolen from twisted.application.app (twistd).
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
if text == for_editor:
            self.status_bar.message(
                _("Session not reevaluated because it was not edited")
            )
            return
        lines = text.split("\n")
        if not lines[-1].strip():
            lines.pop()  # strip last line if empty
        if lines[-1].startswith("### "):
            current_line = lines[-1][4:]
        else:
            current_line = ""
        from_editor = [line for line in lines if line[:3] != "###"]
        if all(not line.strip() for line in from_editor):
            self.status_bar.message(
                _("Session not reevaluated because saved file was blank")
            )
            return

        source = preprocess("\n".join(from_editor), self.interp.compile)
        lines = source.split("\n")
        self.history = lines
        self.reevaluate(insert_into_history=True)
        self.current_line = current_line
        self.cursor_offset = len(self.current_line)
        self.status_bar.message(_("Session edited and reevaluated"))
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
def toggle_file_watch(self):
        if self.watcher:
            if self.watching_files:
                msg = _("Auto-reloading deactivated.")
                self.status_bar.message(msg)
                self.watcher.deactivate()
                self.watching_files = False
            else:
                msg = _("Auto-reloading active, watching for file changes...")
                self.status_bar.message(msg)
                self.watching_files = True
                self.watcher.activate()
        else:
            self.status_bar.message(
                _(
                    "Auto-reloading not available because "
                    "watchdog not installed."
github ivanov / bipython / bipython / __init__.py View on Github external
import argparse
    parser = argparse.ArgumentParser(
            description='the boldly indiscriminate Python interpreter')
    parser.add_argument( '-v','--version', action='version',
            version='%(prog)s ' + version)
    parser.parse_known_args()

    # ok, it's not nice, i'm hiding all of these params, but LTS.
    #
    # TODO: maybe support displays other than raw_display?
    config, options, exec_args = bpargs.parse(args, (
            'Urwid options', None, [
                Option('--twisted', '-T', action='store_true',
                       help=_('Run twisted reactor.')),
                Option('--reactor', '-r',
                       help=_('Select specific reactor (see --help-reactors). '
                       'Implies --twisted.')),
                Option('--help-reactors', action='store_true',
                       help=_('List available reactors for -r.')),
                Option('--plugin', '-p',
                       help=_('twistd plugin to run (use twistd for a list). '
                       'Use "--" to pass further options to the plugin.')),
                Option('--server', '-s', type='int',
                       help=_('Port to run an eval server on (forces Twisted).')),
                ]))

    if options.help_reactors:
        try:
            from twisted.application import reactors
            # Stolen from twisted.application.app (twistd).
            for r in reactors.getReactorTypes():
                print('    %-4s\t%s' % (r.shortName, r.description))
github bpython / bpython / bpython / gtk_.py View on Github external
def file_prompt(self, s):
        chooser = gtk.FileChooserDialog(title=_("File to save to"),
                                        action=gtk.FILE_CHOOSER_ACTION_SAVE,
                                        buttons=(gtk.STOCK_CANCEL,
                                                 gtk.RESPONSE_CANCEL,
                                                 gtk.STOCK_OPEN,
                                                 gtk.RESPONSE_OK))
        chooser.set_default_response(gtk.RESPONSE_OK)
        chooser.set_current_name('test.py')
        chooser.set_current_folder(os.path.expanduser('~'))

        pyfilter = gtk.FileFilter()
        pyfilter.set_name(_("Python files"))
        pyfilter.add_pattern("*.py")
        chooser.add_filter(pyfilter)

        allfilter = gtk.FileFilter()
        allfilter.set_name(_("All files"))
github ivanov / bipython / bipython / __init__.py View on Github external
parser.add_argument( '-v','--version', action='version',
            version='%(prog)s ' + version)
    parser.parse_known_args()

    # ok, it's not nice, i'm hiding all of these params, but LTS.
    #
    # TODO: maybe support displays other than raw_display?
    config, options, exec_args = bpargs.parse(args, (
            'Urwid options', None, [
                Option('--twisted', '-T', action='store_true',
                       help=_('Run twisted reactor.')),
                Option('--reactor', '-r',
                       help=_('Select specific reactor (see --help-reactors). '
                       'Implies --twisted.')),
                Option('--help-reactors', action='store_true',
                       help=_('List available reactors for -r.')),
                Option('--plugin', '-p',
                       help=_('twistd plugin to run (use twistd for a list). '
                       'Use "--" to pass further options to the plugin.')),
                Option('--server', '-s', type='int',
                       help=_('Port to run an eval server on (forces Twisted).')),
                ]))

    if options.help_reactors:
        try:
            from twisted.application import reactors
            # Stolen from twisted.application.app (twistd).
            for r in reactors.getReactorTypes():
                print('    %-4s\t%s' % (r.shortName, r.description))
        except ImportError:
            sys.stderr.write('No reactors are available. Please install '
                'twisted for reactor support.\n')
github bpython / bpython / bpython / repl.py View on Github external
if os.path.exists(fn):
            mode = self.interact.file_prompt(
                _(
                    "%s already exists. Do you "
                    "want to (c)ancel, "
                    " (o)verwrite or "
                    "(a)ppend? "
                )
                % (fn,)
            )
            if mode in ("o", "overwrite", _("overwrite")):
                mode = "w"
            elif mode in ("a", "append", _("append")):
                mode = "a"
            else:
                self.interact.notify(_("Save cancelled."))
                return

        stdout_text = self.formatforfile(self.getstdout())

        try:
            with open(fn, mode) as f:
                f.write(stdout_text)
        except IOError as e:
            self.interact.notify(_("Error writing file '%s': %s") % (fn, e))
        else:
            self.interact.notify(_("Saved to %s.") % (fn,))
github bpython / bpython / bpython / cli.py View on Github external
status bar at the bottom with some stuff in it)"""
    # TODO: Document better what stuff is on the status bar.

    background = get_colpair(config, "background")
    h, w = gethw()

    main_win = newwin(background, h - 1, w, 0, 0)
    main_win.scrollok(True)
    main_win.keypad(1)
    # Thanks to Angus Gibson for pointing out this missing line which was causing
    # problems that needed dirty hackery to fix. :)

    commands = (
        (_("Rewind"), config.undo_key),
        (_("Save"), config.save_key),
        (_("Pastebin"), config.pastebin_key),
        (_("Pager"), config.last_output_key),
        (_("Show Source"), config.show_source_key),
    )

    message = "  ".join(
        "<%s> %s" % (key, command) for command, key in commands if key
    )

    statusbar = Statusbar(
        scr, main_win, background, config, message, get_colpair(config, "main")
    )

    return main_win, statusbar
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
config = Struct()
            loadini(config, default_config_path())

        # If creating a new interpreter on undo would be unsafe because initial
        # state was passed in
        self.weak_rewind = bool(locals_ or interp)

        if interp is None:
            interp = Interp(locals=locals_)
            interp.write = self.send_to_stdouterr
        if banner is None:
            if config.help_key:
                banner = (
                    _("Welcome to bpython!")
                    + " "
                    + _("Press <%s> for help.") % config.help_key
                )
            else:
                banner = None
        # only one implemented currently
        config.autocomplete_mode = autocomplete.SIMPLE
        if config.cli_suggestion_width <= 0 or config.cli_suggestion_width > 1:
            config.cli_suggestion_width = 1

        self.reevaluating = False
        self.fake_refresh_requested = False

        self.status_bar = StatusBar(
            config,
            "",
            request_refresh=self.request_refresh,
            schedule_refresh=self.schedule_refresh,
github bpython / bpython / bpython / paste.py View on Github external
except OSError as e:
            if e.errno == errno.ENOENT:
                raise PasteFailed(_("Helper program not found."))
            else:
                raise PasteFailed(_("Helper program could not be run."))

        if helper.returncode != 0:
            raise PasteFailed(
                _(
                    "Helper program returned non-zero exit "
                    "status %d." % (helper.returncode,)
                )
            )

        if not paste_url:
            raise PasteFailed(_("No output from helper program."))
        else:
            parsed_url = urlparse(paste_url)
            if not parsed_url.scheme or any(
                unicodedata.category(c) == "Cc" for c in paste_url
            ):
                raise PasteFailed(
                    _(
                        "Failed to recognize the helper "
                        "program's output as an URL."
                    )
                )

        return paste_url, None