当前位置: 首页>>代码示例>>Python>>正文


Python conf._函数代码示例

本文整理汇总了Python中meld.conf._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self):
     GObject.GObject.__init__(self)
     self.scheduler = task.FifoScheduler()
     self.num_panes = 0
     self.label_text = _("untitled")
     self.tooltip_text = _("untitled")
     self.main_actiongroup = None
开发者ID:thics,项目名称:meld,代码行数:7,代码来源:melddoc.py

示例2: populate_vcs_for_location

    def populate_vcs_for_location(self, location):
        """Display VC plugin(s) that can handle the location"""
        vcs_model = self.combobox_vcs.get_model()
        vcs_model.clear()

        # VC systems can be executed at the directory level, so make sure
        # we're checking for VC support there instead of
        # on a specific file or on deleted/unexisting path inside vc
        location = os.path.abspath(location or ".")
        while not os.path.isdir(location):
            parent_location = os.path.dirname(location)
            if len(parent_location) >= len(location):
                # no existing parent: for example unexisting drive on Windows
                break
            location = parent_location
        else:
            # existing parent directory was found
            for avc in get_vcs(location):
                err_str = ''
                vc_details = {'name': avc.NAME, 'cmd': avc.CMD}

                if not avc.is_installed():
                    # Translators: This error message is shown when a version
                    # control binary isn't installed.
                    err_str = _("%(name)s (%(cmd)s not installed)")
                elif not avc.valid_repo(location):
                    # Translators: This error message is shown when a version
                    # controlled repository is invalid.
                    err_str = _("%(name)s (Invalid repository)")

                if err_str:
                    vcs_model.append([err_str % vc_details, avc, False])
                    continue

                vcs_model.append([avc.NAME, avc(location), True])

        valid_vcs = [(i, r[1].NAME) for i, r in enumerate(vcs_model) if r[2]]
        default_active = min(valid_vcs)[0] if valid_vcs else 0

        # Keep the same VC plugin active on refresh, otherwise use the first
        current_vc_name = self.vc.NAME if self.vc else None
        same_vc = [i for i, name in valid_vcs if name == current_vc_name]
        if same_vc:
            default_active = same_vc[0]

        if not valid_vcs:
            # If we didn't get any valid vcs then fallback to null
            null_vcs = _null.Vc(location)
            vcs_model.insert(0, [null_vcs.NAME, null_vcs, True])
            tooltip = _("No valid version control system found in this folder")
        elif len(vcs_model) == 1:
            tooltip = _("Only one version control system found in this folder")
        else:
            tooltip = _("Choose which version control system to use")

        self.combobox_vcs.set_tooltip_text(tooltip)
        self.combobox_vcs.set_sensitive(len(vcs_model) > 1)
        self.combobox_vcs.set_active(default_active)
开发者ID:jiapei100,项目名称:meld,代码行数:58,代码来源:vcview.py

示例3: _search_recursively_iter

    def _search_recursively_iter(self, iterstart):
        rootname = self.model.value_path(iterstart, 0)
        prefixlen = len(self.location) + 1
        symlinks_followed = set()
        todo = [(self.model.get_path(iterstart), rootname)]

        flattened = self.actiongroup.get_action("VcFlatten").get_active()
        active_action = lambda a: self.actiongroup.get_action(a).get_active()
        filters = [a[1] for a in self.state_actions.values() if
                   active_action(a[0]) and a[1]]

        yield _("Scanning %s") % rootname
        self.vc.cache_inventory(rootname)
        while todo:
            # This needs to happen sorted and depth-first in order for our row
            # references to remain valid while we traverse.
            todo.sort()
            treepath, path = todo.pop(0)
            it = self.model.get_iter(treepath)
            yield _("Scanning %s") % path[prefixlen:]

            entries = self.vc.listdir(path)
            entries = [e for e in entries if any(f(e) for f in filters)]
            for e in entries:
                if e.isdir:
                    try:
                        st = os.lstat(e.path)
                    # Covers certain unreadable symlink cases; see bgo#585895
                    except OSError as err:
                        error_string = "%s: %s" % (e.path, err.strerror)
                        self.model.add_error(it, error_string, 0)
                        continue

                    if stat.S_ISLNK(st.st_mode):
                        key = (st.st_dev, st.st_ino)
                        if key in symlinks_followed:
                            continue
                        symlinks_followed.add(key)

                    if flattened:
                        if e.state != tree.STATE_IGNORED:
                            todo.append((Gtk.TreePath.new_first(), e.path))
                        continue

                child = self.model.add_entries(it, [e.path])
                if e.isdir and e.state != tree.STATE_IGNORED:
                    todo.append((self.model.get_path(child), e.path))
                self._update_item_state(child, e, path[prefixlen:])

            if flattened:
                root = Gtk.TreePath.new_first()
                self.treeview.expand_row(Gtk.TreePath(root), False)
            else:
                if not entries:
                    self.model.add_empty(it, _("(Empty)"))
                if any(e.state != tree.STATE_NORMAL for e in entries):
                    self.treeview.expand_to_path(treepath)
开发者ID:ahart241,项目名称:meld,代码行数:57,代码来源:vcview.py

示例4: recompute_label

 def recompute_label(self):
     location = self.location
     if isinstance(location, str):
         location = location.decode(
             sys.getfilesystemencoding(), 'replace')
     self.label_text = os.path.basename(location)
     # TRANSLATORS: This is the location of the directory the user is diffing
     self.tooltip_text = _("%s: %s") % (_("Location"), location)
     self.label_changed()
开发者ID:fy2,项目名称:meld,代码行数:9,代码来源:vcview.py

示例5: file_saved_cb

 def file_saved_cb(self, saver, result, *args):
     gfile = saver.get_location()
     try:
         saver.save_finish(result)
     except GLib.Error as err:
         filename = GLib.markup_escape_text(gfile.get_parse_name())
         error_dialog(
             primary=_("Could not save file %s.") % filename,
             secondary=_("Couldn’t save file due to:\n%s") % (
                 GLib.markup_escape_text(str(err))),
         )
开发者ID:GNOME,项目名称:meld,代码行数:11,代码来源:patchdialog.py

示例6: populate_vcs_for_location

    def populate_vcs_for_location(self, location):
        """Display VC plugin(s) that can handle the location"""
        vcs_model = self.combobox_vcs.get_model()
        vcs_model.clear()

        # VC systems can be executed at the directory level, so make sure
        # we're checking for VC support there instead of
        # on a specific file or on deleted/unexisting path inside vc
        location = os.path.abspath(location or ".")
        while not os.path.isdir(location):
            parent_location = os.path.dirname(location)
            if len(parent_location) >= len(location):
                # no existing parent: for example unexisting drive on Windows
                break
            location = parent_location
        else:
            # existing parent directory was found
            for avc, enabled in get_vcs(location):
                err_str = ''
                vc_details = {'name': avc.NAME, 'cmd': avc.CMD}

                if not enabled:
                    # Translators: This error message is shown when no
                    # repository of this type is found.
                    err_str = _("%(name)s (not found)")
                elif not avc.is_installed():
                    # Translators: This error message is shown when a version
                    # control binary isn't installed.
                    err_str = _("%(name)s (%(cmd)s not installed)")
                elif not avc.valid_repo(location):
                    # Translators: This error message is shown when a version
                    # controlled repository is invalid.
                    err_str = _("%(name)s (invalid repository)")

                if err_str:
                    vcs_model.append([err_str % vc_details, avc, False])
                    continue

                vcs_model.append([avc.NAME, avc(location), True])

        default_active = self.get_default_vc(vcs_model)

        if not any(enabled for _, _, enabled in vcs_model):
            # If we didn't get any valid vcs then fallback to null
            null_vcs = _null.Vc(location)
            vcs_model.insert(0, [null_vcs.NAME, null_vcs, True])
            tooltip = _("No valid version control system found in this folder")
        else:
            tooltip = _("Choose which version control system to use")

        self.combobox_vcs.set_tooltip_text(tooltip)
        self.combobox_vcs.set_active(default_active)
开发者ID:GNOME,项目名称:meld,代码行数:52,代码来源:vcview.py

示例7: _make_copy_menu

    def _make_copy_menu(self, chunk):
        copy_menu = Gtk.Menu()
        copy_up = Gtk.MenuItem.new_with_mnemonic(_('Copy _up'))
        copy_down = Gtk.MenuItem.new_with_mnemonic(_('Copy _down'))
        copy_menu.append(copy_up)
        copy_menu.append(copy_down)
        copy_menu.show_all()

        def copy_chunk(widget, action):
            self._action_on_chunk(action, chunk)

        copy_up.connect('activate', copy_chunk, ChunkAction.copy_up)
        copy_down.connect('activate', copy_chunk, ChunkAction.copy_down)
        return copy_menu
开发者ID:GNOME,项目名称:meld,代码行数:14,代码来源:actiongutter.py

示例8: shorten_names

def shorten_names(*names: str) -> List[str]:
    """Remove common parts of a list of paths

    For example, `('/tmp/foo1', '/tmp/foo2')` would be summarised as
    `('foo1', 'foo2')`. Paths that share a basename are distinguished
    by prepending an indicator, e.g., `('/a/b/c', '/a/d/c')` would be
    summarised to `['[b] c', '[d] c']`.
    """

    paths = [PurePath(n) for n in names]

    # Identify the longest common path among the list of path
    common = set(paths[0].parents)
    common = common.intersection(*(p.parents for p in paths))
    if not common:
        return list(names)
    common_parent = sorted(common, key=lambda p: -len(p.parts))[0]

    paths = [p.relative_to(common_parent) for p in paths]
    basenames = [p.name for p in paths]

    if all_same(basenames):
        def firstpart(path: PurePath) -> str:
            if len(path.parts) > 1 and path.parts[0]:
                return "[%s] " % path.parts[0]
            else:
                return ""
        return [firstpart(p) + p.name for p in paths]

    return [name or _("[None]") for name in basenames]
开发者ID:GNOME,项目名称:meld,代码行数:30,代码来源:misc.py

示例9: colour_lookup_with_fallback

def colour_lookup_with_fallback(name, attribute):
    from meld.settings import meldsettings
    source_style = meldsettings.style_scheme

    style = source_style.get_style(name)
    style_attr = getattr(style.props, attribute) if style else None
    if not style or not style_attr:
        manager = GtkSource.StyleSchemeManager.get_default()
        source_style = manager.get_scheme(MELD_STYLE_SCHEME)
        try:
            style = source_style.get_style(name)
            style_attr = getattr(style.props, attribute)
        except AttributeError:
            pass

    if not style_attr:
        import sys
        print >> sys.stderr, _(
            "Couldn't find colour scheme details for %s-%s; "
            "this is a bad install") % (name, attribute)
        sys.exit(1)

    colour = Gdk.RGBA()
    colour.parse(style_attr)
    return colour
开发者ID:KateWilkins,项目名称:meld,代码行数:25,代码来源:misc.py

示例10: shorten_names

def shorten_names(*names):
    """Remove redunant parts of a list of names (e.g. /tmp/foo{1,2} -> foo{1,2}
    """
    # TODO: Update for different path separators
    prefix = os.path.commonprefix(names)
    prefixslash = prefix.rfind("/") + 1

    names = [n[prefixslash:] for n in names]
    paths = [n.split("/") for n in names]

    try:
        basenames = [p[-1] for p in paths]
    except IndexError:
        pass
    else:
        if all_same(basenames):
            def firstpart(alist):
                if len(alist) > 1:
                    return "[%s] " % alist[0]
                else:
                    return ""
            roots = [firstpart(p) for p in paths]
            base = basenames[0].strip()
            return [r + base for r in roots]
    # no common path. empty names get changed to "[None]"
    return [name or _("[None]") for name in basenames]
开发者ID:surjit,项目名称:meld-3.14.2,代码行数:26,代码来源:misc.py

示例11: _update_notebook_menu

    def _update_notebook_menu(self, *args):
        if self.tab_switch_merge_id:
            self.ui.remove_ui(self.tab_switch_merge_id)
            self.ui.remove_action_group(self.tab_switch_actiongroup)

        self.tab_switch_merge_id = self.ui.new_merge_id()
        self.tab_switch_actiongroup = Gtk.ActionGroup(name="TabSwitchActions")
        self.ui.insert_action_group(self.tab_switch_actiongroup)
        group = None
        current_page = self.notebook.get_current_page()
        for i in range(self.notebook.get_n_pages()):
            page = self.notebook.get_nth_page(i)
            label = self.notebook.get_menu_label_text(page) or ""
            name = "SwitchTab%d" % i
            tooltip = _("Switch to this tab")
            action = Gtk.RadioAction(name=name, label=label, tooltip=tooltip, stock_id=None, value=i)
            action.join_group(group)
            group = action
            action.set_active(current_page == i)

            def current_tab_changed_cb(action, current):
                if action == current:
                    self.notebook.set_current_page(action.get_current_value())
            action.connect("changed", current_tab_changed_cb)
            if i < 10:
                accel = "<Alt>%d" % ((i + 1) % 10)
            else:
                accel = None
            self.tab_switch_actiongroup.add_action_with_accel(action, accel)
            self.ui.add_ui(self.tab_switch_merge_id,
                           "/Menubar/TabMenu/TabPlaceholder",
                           name, name, Gtk.UIManagerItemType.MENUITEM, False)
开发者ID:Psykar,项目名称:meld,代码行数:32,代码来源:meldwindow.py

示例12: _update_tree_state_cache

    def _update_tree_state_cache(self, path):
        while 1:
            try:
                proc = _vc.popen(
                    [self.CMD, "status", "-v", "--xml", path],
                    cwd=self.location)
                tree = ElementTree.parse(proc)
                break
            except OSError as e:
                if e.errno != errno.EAGAIN:
                    raise

        for target in tree.findall("target") + tree.findall("changelist"):
            for entry in (t for t in target.getchildren() if t.tag == "entry"):
                path = entry.attrib["path"]
                if not path:
                    continue
                if not os.path.isabs(path):
                    path = os.path.abspath(os.path.join(self.location, path))
                for status in (e for e in entry.getchildren() \
                               if e.tag == "wc-status"):
                    item = status.attrib["item"]
                    if item == "":
                        continue
                    state = self.state_map.get(item, _vc.STATE_NONE)
                    self._tree_cache[path] = state

                    rev = status.attrib.get("revision")
                    rev_label = _("Rev %s") % rev if rev is not None else ''
                    self._tree_meta_cache[path] = rev_label
开发者ID:uestclx,项目名称:meld,代码行数:30,代码来源:svn.py

示例13: run

    def run(self):
        self.update_patch()

        while 1:
            result = self.widget.run()
            if result < 0:
                break

            buf = self.textview.get_buffer()
            start, end = buf.get_bounds()
            txt = text_type(buf.get_text(start, end, False), 'utf8')

            # Copy patch to clipboard
            if result == 1:
                clip = Gtk.clipboard_get()
                clip.set_text(txt)
                clip.store()
                break
            # Save patch as a file
            else:
                # FIXME: These filediff methods are actually general utility.
                filename = self.filediff._get_filename_for_saving(
                    _("Save Patch"))
                if filename:
                    txt = txt.encode('utf-8')
                    self.filediff._save_text_to_filename(filename, txt)
                    break

        self.widget.hide()
开发者ID:Puneeth-n,项目名称:meld,代码行数:29,代码来源:patchdialog.py

示例14: _update_tree_state_cache

    def _update_tree_state_cache(self, path, tree_state):
        """ Update the state of the file(s) at tree_state['path'] """
        while 1:
            try:
                entries = self._get_modified_files(path)

                # Identify ignored files and folders
                proc = _vc.popen([self.CMD, "ls-files", "--others",
                                  "--ignored", "--exclude-standard",
                                  "--directory", path],
                                 cwd=self.location)
                ignored_entries = proc.read().split("\n")[:-1]

                # Identify unversioned files
                proc = _vc.popen([self.CMD, "ls-files", "--others",
                                  "--exclude-standard", path],
                                 cwd=self.location)
                unversioned_entries = proc.read().split("\n")[:-1]

                break
            except OSError as e:
                if e.errno != errno.EAGAIN:
                    raise

        if len(entries) == 0 and os.path.isfile(path):
            # If we're just updating a single file there's a chance that it
            # was it was previously modified, and now has been edited
            # so that it is un-modified.  This will result in an empty
            # 'entries' list, and tree_state['path'] will still contain stale
            # data.  When this corner case occurs we force tree_state['path']
            # to STATE_NORMAL.
            path = os.path.abspath(path)
            tree_state[path] = _vc.STATE_NORMAL
        else:
            # There are 1 or more modified files, parse their state
            for entry in entries:
                columns = self.DIFF_RE.search(entry).groups()
                old_mode, new_mode, statekey, name = columns
                if os.name == 'nt':
                    # Git returns unix-style paths on Windows
                    name = os.path.normpath(name.strip())
                path = os.path.join(self.root, name.strip())
                path = os.path.abspath(path)
                state = self.state_map.get(statekey.strip(), _vc.STATE_NONE)
                tree_state[path] = state
                if old_mode != new_mode:
                    msg = _("Mode changed from %s to %s" %
                            (old_mode, new_mode))
                    self._tree_meta_cache[path] = msg

            for entry in ignored_entries:
                path = os.path.join(self.location, entry.strip())
                path = os.path.abspath(path)
                tree_state[path] = _vc.STATE_IGNORED

            for entry in unversioned_entries:
                path = os.path.join(self.location, entry.strip())
                path = os.path.abspath(path)
                tree_state[path] = _vc.STATE_NONE
开发者ID:Psykar,项目名称:meld,代码行数:59,代码来源:git.py

示例15: _update_tree_state_cache

    def _update_tree_state_cache(self, path):
        """ Update the state of the file(s) at self._tree_cache['path'] """
        while 1:
            try:
                entries = self._get_modified_files(path)

                # Identify ignored files and folders
                proc = self.run(
                    "ls-files", "--others", "--ignored", "--exclude-standard",
                    "--directory", path)
                ignored_entries = proc.stdout.read().split("\n")[:-1]

                # Identify unversioned files
                proc = self.run(
                    "ls-files", "--others", "--exclude-standard", path)
                unversioned_entries = proc.stdout.read().split("\n")[:-1]

                break
            except OSError as e:
                if e.errno != errno.EAGAIN:
                    raise

        def get_real_path(name):
            name = name.strip()
            if os.name == 'nt':
                # Git returns unix-style paths on Windows
                name = os.path.normpath(name)

            # Unicode file names and file names containing quotes are
            # returned by git as quoted strings
            if name[0] == '"':
                name = name[1:-1].decode('string_escape')
            return os.path.abspath(
                os.path.join(self.location, name))

        if len(entries) == 0 and os.path.isfile(path):
            # If we're just updating a single file there's a chance that it
            # was it was previously modified, and now has been edited so that
            # it is un-modified.  This will result in an empty 'entries' list,
            # and self._tree_cache['path'] will still contain stale data.
            # When this corner case occurs we force self._tree_cache['path']
            # to STATE_NORMAL.
            self._tree_cache[get_real_path(path)] = _vc.STATE_NORMAL
        else:
            for entry in entries:
                columns = self.DIFF_RE.search(entry).groups()
                old_mode, new_mode, statekey, path = columns
                state = self.state_map.get(statekey.strip(), _vc.STATE_NONE)
                self._tree_cache[get_real_path(path)] = state
                if old_mode != new_mode:
                    msg = _("Mode changed from %s to %s" %
                            (old_mode, new_mode))
                    self._tree_meta_cache[path] = msg

            for path in ignored_entries:
                self._tree_cache[get_real_path(path)] = _vc.STATE_IGNORED

            for path in unversioned_entries:
                self._tree_cache[get_real_path(path)] = _vc.STATE_NONE
开发者ID:uestclx,项目名称:meld,代码行数:59,代码来源:git.py


注:本文中的meld.conf._函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。