예제 #1
0
def install_katefiletyperc():
    """
    Installs a LilyKDE group into katefiletyperc with settings
    for LilyPond files.
    """
    rc = kconfig("katefiletyperc", False, False).group("LilyKDE")
    rc["Mimetypes"] = "text/x-lilypond"
    rc["Priority"] = 10
    rc["Section"] = "LilyPond"
    rc["Wildcards"] = "*.ly; *.ily; *.lyi"
    rc["Variables"] = (
        "kate: "
        "encoding utf8; "
        "tab-width 4; "
        "indent-width 2; "
        "space-indent on; "
        "replace-tabs on; "
        "replace-tabs-save on; "
        "dynamic-word-wrap off; "
        "show-tabs off; "
        "indent-mode varindent; "
        r"var-indent-indent-after (\{[^}]*$|<<(?![^>]*>>)); "
        r"var-indent-unindent ^\s*(#?\}|>>); "
        r"var-indent-triggerchars }>; "
    )
예제 #2
0
def config(group=None):
    """
    Return the master KConfig object for "lilykderc", or
    a KConfigGroup (wrapper) object if a group name is given.
    """
    from lilykde.util import kconfig
    k = kconfig("lilykderc", False, False)
    return group and k.group(group) or k
예제 #3
0
def findDicts():
    conf = config("hyphenation")

    def paths():
        """ build a list of paths based on config """
        # in which prefixes to look for relative paths
        if 'KDEDIRS' in os.environ:
            prefixes = os.environ['KDEDIRS'].split(':')
        else:
            prefixes = ['/usr', '/usr/local']
            if 'KDEDIR' in os.environ:
                prefixes.append(os.environ['KDEDIR'])
        # if the path is not absolute, add it to all prefixes.
        for path in conf["paths"].splitlines() or defaultpaths:
            if os.path.isabs(path):
                yield path
            else:
                for pref in prefixes:
                    yield os.path.join(pref, path)

    # now find the hyph_xx_XX.dic files
    dicfiles = (f
        for p in paths() if os.path.isdir(p)
            for f in glob(os.path.join(p, 'hyph_*.dic')) if os.path.isfile(f))

    # present the user with human readable language names
    all_languages = kconfig("all_languages", True, False, "locale")

    # default to the users current locale if not used before
    defaultlang = None

    global hyphdicts
    # empty it, because we might be called again when the user changes
    # the settings.
    hyphdicts = {}
    for dic in dicfiles:
        lang = os.path.basename(dic)[5:-4]
        # find a human readable name belonging to the language code
        for i in lang, lang.split('_')[0]:
            name = all_languages.group(i).get("Name")
            if name:
                name = '%s  (%s)' % (name, lang)
                hyphdicts[name] = dic
                # set current locale as default
                if lang == language:
                    defaultlang = name
                break
        else:
            hyphdicts[lang] = dic

    # if not used before, write the current locale (if existing) as default
    if defaultlang and conf["lastused"] not in hyphdicts:
        conf["lastused"] = defaultlang
예제 #4
0
파일: pdf.py 프로젝트: Alwnikrotikz/lilykde
def openFile(pdf):
    """ Open the specified PDF document """

    global _file

    c = KApplication.dcopClient()
    kpdf = DCOPApp(c.appId(), c).kpdf

    # When LilyPond writes a PDF, it first deletes the old one.
    # So the new PDF gets a different inode number, which causes
    # KPDF to sometimes loose the 'watch' on the file.
    # So we call KPDF to open the file, and remember the page number
    # displayed ourselves, because KPDF also seems to forget the scroll
    # position due to LilyPond deleting the old PDF first.
    # It would be best that either KPDF is fixed to just look for a
    # named file, even if it has a different inode number, or that
    # LilyPond is fixed to not delete the old PDF first, but just
    # truncate it and write the new data into it.

    # Update June 17, 2008: LilyPond >= 2.11.49 does not delete the PDF
    # anymore on unix platforms!

    # Document already shown?
    if _file == pdf:
        # Yes this is the same PDF, see if we need to force KPDF to
        # reload the document. If not, we trust that KPDF automatically
        # updates its view.
        from lilykde.version import version
        if (
            # User can force reload of PDF with config option
            config('preferences')['force reload pdf'] == '1'
            # LilyPond >= 2.11.49 does not delete the PDF anymore on unix
            or version < (2, 11, 49) or os.name not in ('posix', 'mac')
            # read KPDF's 'watch file' option (default is true)
            or kconfig('kpdfpartrc', True, False).group('General')['WatchFile']
                in ('false', '0', 'off', 'no')):
            # Reopen same document, remembering page number
            page = kpdf.currentPage()[1]
            kpdf.openDocument(KURL(pdf))
            QTimer.singleShot(100, lambda: kpdf.goToPage(page))
    else:
        # This is another PDF, just open it.
        kpdf.openDocument(KURL(pdf))
        _file = pdf