示例#1
0
def choose_editor(parent, config):
    """
    Give the option to either choose an editor or use the default.
    """
    if config.editor and find_executable(config.editor):
        return config.editor

    buttons = (
        'Choose Editor', Gtk.ResponseType.YES,
        'Use Default', Gtk.ResponseType.NO,
        Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL
    )
    response = MessageDialogWrapper(
        parent, message_type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.NONE,
        title='Choose Editor', markup='Would you like to choose the editor to use?',
        default_response=Gtk.ResponseType.YES, extra_buttons=buttons
    ).run_and_destroy()

    # Handle the initial default/choose/cancel response
    # User wants to choose the editor to use
    editor = ''
    if response == Gtk.ResponseType.YES:
        file_dialog = Gtk.FileChooserDialog(
            'Select an Editor...', None,
            Gtk.FileChooserAction.OPEN,
            ('gtk-cancel', Gtk.ResponseType.CANCEL,
             'gtk-open', Gtk.ResponseType.OK),
            transient_for=parent
        )
        file_dialog.set_select_multiple(False)
        file_dialog.set_local_only(True)
        file_dialog.set_current_folder('/usr/bin')
        try:
            if file_dialog.run() == Gtk.ResponseType.OK:
                editor = file_dialog.get_filename()
        finally:
            file_dialog.hide()

    # Go with the default editor
    elif response == Gtk.ResponseType.NO:
        try:
            process = None
            if sys.platform.startswith('linux'):
                process = find_executable('xdg-open')
            elif sys.platform.startswith('darwin'):
                process = find_executable('open')
            if process is None:
                raise ValueError("Can't find default editor executable")
            # Save
            editor = config.editor = process
        except Exception:
            Messages.send(
                '>>> Unable to load the default editor. Please choose an editor.\n')

    if editor == '':
        Messages.send('>>> No editor selected.\n')
    return editor
示例#2
0
    def _cpp_popen(self):
        """
        Execute this C++ flow graph after generating and compiling it.
        """
        generator = self.page.get_generator()
        run_command = generator.file_path + \
            '/build/' + self.flow_graph.get_option('id')

        dirname = generator.file_path
        builddir = os.path.join(dirname, 'build')

        if os.path.isfile(run_command):
            os.remove(run_command)

        xterm_executable = find_executable(self.xterm_executable)

        nproc = Utils.get_cmake_nproc()

        run_command_args = f'cmake .. && cmake --build . -j{nproc} && cd ../.. && {xterm_executable} -e {run_command}'
        Messages.send_start_exec(run_command_args)

        return subprocess.Popen(args=run_command_args,
                                cwd=builddir,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                shell=True,
                                universal_newlines=True)
示例#3
0
    def _popen(self):
        """
        Execute this python flow graph.
        """
        generator = self.page.get_generator()
        run_command = self.flow_graph.get_run_command(generator.file_path)
        run_command_args = shlex.split(run_command)

        # When in no gui mode on linux, use a graphical terminal (looks nice)
        xterm_executable = find_executable(self.xterm_executable)
        if generator.generate_options == 'no_gui' and xterm_executable:
            if ('gnome-terminal' in xterm_executable):
                run_command_args = [xterm_executable, '--'] + run_command_args
            else:
                run_command_args = [xterm_executable, '-e', run_command]

        # this does not reproduce a shell executable command string, if a graphical
        # terminal is used. Passing run_command though shlex_quote would do it but
        # it looks really ugly and confusing in the console panel.
        Messages.send_start_exec(' '.join(run_command_args))

        dirname = Path(generator.file_path).parent

        return subprocess.Popen(args=run_command_args,
                                cwd=dirname,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                shell=False,
                                universal_newlines=True)
示例#4
0
    def install_external_editor(self, param, parent=None):
        target = (param.parent_block.name, param.key)

        if target in self._external_updaters:
            editor = self._external_updaters[target]
        else:
            config = self.parent_platform.config
            editor = (find_executable(config.editor)
                      or Dialogs.choose_editor(parent, config)
                      )  # todo: pass in parent
            if not editor:
                return
            updater = functools.partial(self.handle_external_editor_change,
                                        target=target)
            editor = self._external_updaters[target] = ExternalEditor(
                editor=editor,
                name=target[0],
                value=param.get_value(),
                callback=functools.partial(GLib.idle_add, updater))
            editor.start()
        try:
            editor.open_editor()
        except Exception as e:
            # Problem launching the editor. Need to select a new editor.
            Messages.send(
                '>>> Error opening an external editor. Please select a different editor.\n'
            )
            # Reset the editor to force the user to select a new one.
            self.parent_platform.config.editor = ''
示例#5
0
def check_executable(executable):
    """
    Checks if an executable exists in $PATH.

    Arguments:
        executable -- the name of the executable (e.g. "echo")

    Returns:
        True or False
    """
    logger = logging.getLogger(__name__)
    logger.debug("Checking executable '%s'...", executable)
    executable_path = find_executable(executable)
    found = executable_path is not None
    if found:
        logger.debug("Executable '%s' found: '%s'", executable,
                     executable_path)
    else:
        logger.debug("Executable '%s' not found", executable)
    return found
示例#6
0
def _guess_opengl_mode():
    """Guess a working OpenGL configuration for opengl=auto.

    See https://github.com/brainvisa/casa-distro/issues/160 for the rationale
    behind this heuristic. If it does not work for you, please reopen that
    issue.
    """
    # Although Singularity supports --nv even without nvidia-container-cli, it
    # has been found to generate random failures at runtime, see
    # https://github.com/brainvisa/casa-distro/issues/153.
    if os.access('/dev/nvidiactl', os.R_OK | os.W_OK):
        if find_executable('nvidia-container-cli'):
            # This is the option that provides the best graphical performance
            # on NVidia hardware, and enables the use of CUDA. It seems to work
            # in all tested configurations (physical X server, CLI, Xvnc,
            # x2go).
            return 'nv'
        else:
            # Although Singularity supports --nv without nvidia-container-cli,
            # it has been found to generate random failures at runtime, see
            # https://github.com/brainvisa/casa-distro/issues/153.
            if _X_has_proprietary_nvidia():
                # In that case, we cannot fall back to 'container' because that
                # is not compatible with a X server that has the proprietary
                # NVidia module, so we have to fall back to the software-only
                # libGL.
                return 'software'
            else:
                # When nvidia-container-cli is not present, --nv causes
                # systematic segfaults on a X server that is *not* configured
                # to use the NVidia proprietary driver (such as Xvnc or x2go).
                # It seems safe to fall back to 'container' in those cases.
                return 'container'
    else:
        # When the system does not have NVidia hardware, the in-container
        # DRI-enabled OpenGL libraries seem to work in all cases. If we find
        # cases where they do not, we will need to add a quirk here.
        return 'container'
示例#7
0
# -*- coding: utf-8 -*-
# Copyright (c) 2018 SubDownloader Developers - See COPYING - GPLv3

import gettext
import subprocess

try:
    from shutil import which as find_executable
except ImportError:
    from distutils.spawn import find_executable

from gi.repository import Nautilus, GObject

SUBDOWNLOADER_PATH = find_executable('subdownloader')

if SUBDOWNLOADER_PATH:
    translator = gettext.translation(domain='SubDownloader', fallback=True)
    translator.install()

    class SubDownloaderMenu(GObject.GObject, Nautilus.MenuProvider):
        def __init__(self):
            pass

        def get_file_items(self, window, files):
            subdownloader_menu = Nautilus.MenuItem(
                name='SubDownloaderMenu::SubDownloader',
                label=_('Search SubDownloader...'),
                tip=_('Launch SubDownloader with these files.'),
            )
            subdownloader_menu.connect('activate', self.search_subdownloader,
                                       files)