Example #1
0
def create_toolbutton(parent, text=None, layout=None, tooltip=None, icon=None):
    button = QtGui.QToolButton(parent)
    button.setAutoRaise(True)
    button.setAutoFillBackground(True)
    if icon:
        button.setIcon(icon)
    if text:
        button.setText(i18n.gettext(text))
        button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
    if tooltip:
        button.setToolTip(i18n.gettext(tooltip))
    if layout is not None:
        layout.addWidget(button)
    return button
Example #2
0
 def test_guards_against_qstring(self):
     """Test that random QString is passed through as-is
     """
     i18n.install('en_US.UTF-8')
     expect = 'Random'
     actual = i18n.gettext(QtCore.QString('Random'))
     self.assertEqual(expect, actual)
Example #3
0
 def test_guards_against_qstring(self):
     """Test that random QString is passed through as-is
     """
     i18n.install('en_US.UTF-8')
     expect = 'Random'
     actual = i18n.gettext(QtCore.QString('Random'))
     self.assertEqual(expect, actual)
Example #4
0
def create_button(text, layout=None, tooltip=None, icon=None):
    """Create a button, set its title, and add it to the parent."""
    button = QtGui.QPushButton()
    button.setText(i18n.gettext(text))
    if icon:
        button.setIcon(icon)
    if layout is not None:
        layout.addWidget(button)
    return button
Example #5
0
    def translate(self, domain, txt):
        """
        Translate strings with gettext

        Supports @@noun/@@verb specifiers.

        """
        trtxt = i18n.gettext(txt)
        if trtxt[-6:-4] == "@@":  # handle @@verb / @@noun
            trtxt = trtxt[:-6]
        return trtxt
Example #6
0
    def translate(self, domain, txt):
        """
        Translate strings with gettext

        Supports @@noun/@@verb specifiers.

        """
        trtxt = i18n.gettext(txt)
        if trtxt[-6:-4] == '@@': # handle @@verb / @@noun
            trtxt = trtxt[:-6]
        return trtxt
Example #7
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                del os.environ[env]
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = i18n.gettext('Are you sure you want to run %s?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                _factory.prompt_user(signals.information,
                                     'Please select a file',
                                     '"%s" requires a selected file' % cmd)
                return
            os.environ['FILENAME'] = commands.mkarg(filename)


        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = _factory.prompt_user(signals.run_config_action, cmd, opts)
                if not ok:
                    return
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    msg = ('Invalid revision:\n\n'
                           'Revision expression is empty')
                    title = 'Oops!'
                    _factory.prompt_user(signals.information, title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if not _factory.prompt_user(signals.question, title, prompt):
                return
        if rev:
            os.environ['REVISION'] = rev
        if args:
            os.environ['ARGS'] = args
        title = os.path.expandvars(cmd)
        _notifier.broadcast(signals.log_cmd, 0, 'running: ' + title)
        cmd = ['sh', '-c', cmd]

        if opts.get('noconsole'):
            status, out, err = utils.run_command(cmd, flag_error=False)
        else:
            status, out, err = _factory.prompt_user(signals.run_command,
                                                    title, cmd)

        _notifier.broadcast(signals.log_cmd, status,
                            'stdout: %s\nstatus: %s\nstderr: %s' %
                                (out.rstrip(), status, err.rstrip()))

        if not opts.get('norescan'):
            self.model.update_status()
        return status
Example #8
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = i18n.gettext('Are you sure you want to run %s?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                Interaction.information(
                        'Please select a file',
                        '"%s" requires a selected file' % cmd)
                return False
            compat.putenv('FILENAME', filename)

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = 'Invalid Revision'
                    msg = 'The revision expression cannot be empty.'
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.putenv('REVISION', rev)
        if args:
            compat.putenv('ARGS', args)
        title = os.path.expandvars(cmd)
        Interaction.log('running: ' + title)
        cmd = ['sh', '-c', cmd]

        if opts.get('noconsole'):
            status, out, err = utils.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status,
                               out and 'stdout: %s' % out,
                               err and 'stderr: %s' % err)

        if not opts.get('norescan'):
            self.model.update_status()
        return status
Example #9
0
    def do(self):
        for env in ("FILENAME", "REVISION", "ARGS"):
            try:
                del os.environ[env]
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get("cmd")
        if "title" not in opts:
            opts["title"] = cmd

        if "prompt" not in opts or opts.get("prompt") is True:
            prompt = i18n.gettext("Are you sure you want to run %s?") % cmd
            opts["prompt"] = prompt

        if opts.get("needsfile"):
            filename = selection.filename()
            if not filename:
                _factory.prompt_user(signals.information, "Please select a file", '"%s" requires a selected file' % cmd)
                return
            os.environ["FILENAME"] = filename

        if opts.get("revprompt") or opts.get("argprompt"):
            while True:
                ok = _factory.prompt_user(signals.run_config_action, cmd, opts)
                if not ok:
                    return
                rev = opts.get("revision")
                args = opts.get("args")
                if opts.get("revprompt") and not rev:
                    title = "Invalid Revision"
                    msg = "The revision expression cannot be empty."
                    _factory.prompt_user(signals.critical, title, msg)
                    continue
                break

        elif opts.get("confirm"):
            title = os.path.expandvars(opts.get("title"))
            prompt = os.path.expandvars(opts.get("prompt"))
            if not _factory.prompt_user(signals.question, title, prompt):
                return
        if rev:
            os.environ["REVISION"] = rev
        if args:
            os.environ["ARGS"] = args
        title = os.path.expandvars(cmd)
        _notifier.broadcast(signals.log_cmd, 0, "running: " + title)
        cmd = ["sh", "-c", cmd]

        if opts.get("noconsole"):
            status, out, err = utils.run_command(cmd, flag_error=False)
        else:
            status, out, err = _factory.prompt_user(signals.run_command, title, cmd)

        _notifier.broadcast(
            signals.log_cmd, status, "stdout: %s\nstatus: %s\nstderr: %s" % (out.rstrip(), status, err.rstrip())
        )

        if not opts.get("norescan"):
            self.model.update_status()
        return status
Example #10
0
    def do(self):
        for env in ("FILENAME", "REVISION", "ARGS"):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get("cmd")
        if "title" not in opts:
            opts["title"] = cmd

        if "prompt" not in opts or opts.get("prompt") is True:
            prompt = i18n.gettext("Are you sure you want to run %s?") % cmd
            opts["prompt"] = prompt

        if opts.get("needsfile"):
            filename = selection.filename()
            if not filename:
                Interaction.information("Please select a file", '"%s" requires a selected file' % cmd)
                return False
            compat.putenv("FILENAME", filename)

        if opts.get("revprompt") or opts.get("argprompt"):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get("revision")
                args = opts.get("args")
                if opts.get("revprompt") and not rev:
                    title = "Invalid Revision"
                    msg = "The revision expression cannot be empty."
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get("confirm"):
            title = os.path.expandvars(opts.get("title"))
            prompt = os.path.expandvars(opts.get("prompt"))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.putenv("REVISION", rev)
        if args:
            compat.putenv("ARGS", args)
        title = os.path.expandvars(cmd)
        Interaction.log("running: " + title)
        cmd = ["sh", "-c", cmd]

        if opts.get("noconsole"):
            status, out, err = utils.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status, out and "stdout: %s" % out, err and "stderr: %s" % err)

        if not opts.get("norescan"):
            self.model.update_status()
        return status
Example #11
0
    def __init__(self, parent, name, opts):
        standard.StandardDialog.__init__(self, parent)
        self.name = name
        self.opts = opts

        self.layt = QtGui.QVBoxLayout()
        self.layt.setMargin(10)
        self.setLayout(self.layt)

        title = opts.get("title")
        if title:
            self.setWindowTitle(os.path.expandvars(title))

        self.prompt = QtGui.QLabel()

        prompt = opts.get("prompt")
        if prompt:
            self.prompt.setText(os.path.expandvars(prompt))
        self.layt.addWidget(self.prompt)

        self.argslabel = QtGui.QLabel()
        if "argprompt" not in opts or opts.get("argprompt") is True:
            argprompt = i18n.gettext("Arguments")
        else:
            argprompt = opts.get("argprompt")

        self.argslabel.setText(argprompt)

        self.argstxt = QtGui.QLineEdit()
        self.argslayt = QtGui.QHBoxLayout()
        self.argslayt.addWidget(self.argslabel)
        self.argslayt.addWidget(self.argstxt)
        self.layt.addLayout(self.argslayt)

        if not self.opts.get("argprompt"):
            self.argslabel.setMinimumSize(1, 1)
            self.argstxt.setMinimumSize(1, 1)
            self.argstxt.hide()
            self.argslabel.hide()

        revs = (
            ("Local Branch", gitcmds.branch_list(remote=False)),
            ("Tracking Branch", gitcmds.branch_list(remote=True)),
            ("Tag", gitcmds.tag_list()),
        )

        if "revprompt" not in opts or opts.get("revprompt") is True:
            revprompt = i18n.gettext("Revision")
        else:
            revprompt = opts.get("revprompt")
        self.revselect = revselect.RevisionSelector(self, revs=revs)
        self.revselect.set_revision_label(revprompt)
        self.layt.addWidget(self.revselect)

        if not opts.get("revprompt"):
            self.revselect.hide()

        # Close/Run buttons
        self.btnlayt = QtGui.QHBoxLayout()
        self.btnspacer = QtGui.QSpacerItem(1, 1, QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Minimum)
        self.btnlayt.addItem(self.btnspacer)
        self.closebtn = qt.create_button(self.tr("Close"), self.btnlayt)
        self.runbtn = qt.create_button(self.tr("Run"), self.btnlayt)
        self.runbtn.setDefault(True)
        self.layt.addLayout(self.btnlayt)

        self.connect(self.closebtn, SIGNAL("clicked()"), self.reject)
        self.connect(self.runbtn, SIGNAL("clicked()"), self.accept)

        # Widen the dialog by default
        self.resize(666, self.height())
Example #12
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                del os.environ[env]
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = i18n.gettext('Are you sure you want to run %s?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                _factory.prompt_user(signals.information,
                                     'Please select a file',
                                     '"%s" requires a selected file' % cmd)
                return
            os.environ['FILENAME'] = filename

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = _factory.prompt_user(signals.run_config_action, cmd, opts)
                if not ok:
                    return
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = 'Invalid Revision'
                    msg = 'The revision expression cannot be empty.'
                    _factory.prompt_user(signals.critical, title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if not _factory.prompt_user(signals.question, title, prompt):
                return
        if rev:
            os.environ['REVISION'] = rev
        if args:
            os.environ['ARGS'] = args
        title = os.path.expandvars(cmd)
        _notifier.broadcast(signals.log_cmd, 0, 'running: ' + title)
        cmd = ['sh', '-c', cmd]

        if opts.get('noconsole'):
            status, out, err = utils.run_command(cmd, flag_error=False)
        else:
            status, out, err = _factory.prompt_user(signals.run_command,
                                                    title, cmd)

        _notifier.broadcast(signals.log_cmd, status,
                            'stdout: %s\nstatus: %s\nstderr: %s' %
                                (out.rstrip(), status, err.rstrip()))

        if not opts.get('norescan'):
            self.model.update_status()
        return status
Example #13
0
 def _information(self, title, msg):
     if msg is None:
         msg = title
     title = i18n.gettext(title)
     msg = i18n.gettext(msg)
     QtGui.QMessageBox.information(self.parent, title, msg)
Example #14
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = i18n.gettext('Are you sure you want to run %s?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                Interaction.information('Please select a file',
                                        '"%s" requires a selected file' % cmd)
                return False
            compat.putenv('FILENAME', filename)

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = 'Invalid Revision'
                    msg = 'The revision expression cannot be empty.'
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.putenv('REVISION', rev)
        if args:
            compat.putenv('ARGS', args)
        title = os.path.expandvars(cmd)
        Interaction.log('running: ' + title)
        cmd = ['sh', '-c', cmd]

        if opts.get('noconsole'):
            status, out, err = utils.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status, out and 'stdout: %s' % out, err
                               and 'stderr: %s' % err)

        if not opts.get('norescan'):
            self.model.update_status()
        return status