Example #1
0
 def paths():
     """ build a list of paths based on config """
     # in which prefixes to look for relative paths
     prefixes = KGlobal.dirs().kfsstnd_prefixes().split(os.pathsep)
     prefixes = set(prefixes + ['/usr/', '/usr/local/'])
     # if the path is not absolute, add it to all prefixes.
     for path in conf.readEntry("paths", defaultPaths):
         if os.path.isabs(path):
             yield path
         else:
             for pref in prefixes:
                 yield os.path.join(pref, path)
             for d in KGlobal.dirs().findDirs("data", path):
                 yield d
Example #2
0
	def __init__(self, parent = None):
		plasmascript.Applet.__init__(self, parent)

		self.kdehome = unicode(KGlobal.dirs().localkdedir())
		self.iconPath = '/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-spacer/contents/icons/Spacer.png'
		self.icon = Plasma.IconWidget()
		self.icon.setIcon(self.iconPath)
 def __init__(self, parent):
     QtCore.QObject.__init__(self)
     self.applet = parent
     self.kdehome = unicode(KGlobal.dirs().localkdedir())
     if not os.path.exists(self.kdehome+u"share/apps/%s/%s.notifyrc" % (self.applet.metadata.pluginName(), self.applet.metadata.pluginName())):
         # Install notifyrc file if required
         self.install_notifications()
Example #4
0
    def __init__(self, parent=None):
        plasmascript.Applet.__init__(self, parent)

        self.kdehome = unicode(KGlobal.dirs().localkdedir())
        self.iconPath = '/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-spacer/contents/icons/Spacer.png'
        self.icon = Plasma.IconWidget()
        self.icon.setIcon(self.iconPath)
Example #5
0
 def initializeProcess(self, p):
     rumor = config("commands").readEntry("rumor", "rumor")
     cmd = [rumor] + self.panel.getRumorArguments()
     if self.panel.keyboardEmu:
         # Run Rumor in a pty when keyboard input is used.
         runpty = KGlobal.dirs().findResource("appdata", "lib/runpty.py")
         cmd[0:0] = [sys.executable, runpty]
     p.setProgram(cmd)
     p.setOutputChannelMode(KProcess.OnlyStdoutChannel)
Example #6
0
	def user_or_sys(self, path_):
		kdehome = unicode(KGlobal.dirs().localkdedir())
		var1 = kdehome + 'share/apps/plasma/plasmoids/kde-plasma-mail-checker/contents/' + path_
		var2 = '/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-mail-checker/contents/' + path_
		if os.path.exists(var2) :
			return var2
		elif os.path.exists(var1) :
			return var1
		else :
			return os.path.expanduser('~/kde-plasma-mail-checker/contents/' + path_)
Example #7
0
 def download(self, url):
     """Download the package from given KUrl."""
     self.progress.setRange(0, 100)
     self.status.setText(i18n("Downloading %1...", url.fileName()))
     dest = KGlobal.dirs().saveLocation('tmp')
     self.job = KIO.copy(url, KUrl(dest),
         KIO.JobFlags(KIO.Overwrite | KIO.Resume | KIO.HideProgressInfo))
     QObject.connect(self.job, SIGNAL("percent(KJob*, unsigned long)"), self.slotPercent)
     QObject.connect(self.job, SIGNAL("result(KJob*)"), self.slotResult, Qt.QueuedConnection)
     self.job.start()
    def ensure_notifyrc(self):
        appdir = '{base}/share/apps/{app}/'.format(
            base=KGlobal.dirs().localkdedir(), app=self.appname)
        rcpath = os.path.join(appdir,
                              '{app}.notifyrc'.format(app=self.appname))

        if os.path.exists(rcpath):
            return

        if not os.path.exists(appdir):
            os.mkdir(appdir)

        copyfile(self.source, rcpath)
Example #9
0
File: kde.py Project: KDE/kajongg
def cacheDir():
    """the cache directory for this user"""
    if Internal.isServer:
        result = os.path.join(appdataDir(), 'cache')
    else:
        result = os.path.dirname(
            unicode(KGlobal.dirs().locateLocal("cache", "")))
        result = os.path.join(result, 'kajongg')
    if not os.path.exists(result):
        try:
            os.makedirs(result)
        except OSError:
            pass
    return result
Example #10
0
	def __init__(self, parent = None):
		plasmascript.Applet.__init__(self, parent)

		self.kdehome = unicode(KGlobal.dirs().localkdedir())

		if os.path.exists('/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png') :
			self.iconPath = '/usr/share/kde4/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png'
		elif os.path.exists(self.kdehome + '/share/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png') :
			self.iconPath = self.kdehome + '/share/apps/plasma/plasmoids/kde-plasma-cpufrequtility/contents/icons/performance.png'
			#print 'installing', self.iconPath
		else :
			self.iconPath = os.getcwd() + '/plasmaCpuFreqUtility/contents/icons/performance.png'

		self.Settings = QSettings('kde-plasma-cpufrequtility', 'kde-plasma-cpufrequtility')
Example #11
0
def getColorSchemesAndPath():
    from Core import Settings

    colorSchemes, colorSchemePaths = [], []
    colorSchemes.append("Default")
    colorSchemePaths.append("")
    if isActivePyKDE4:
        from PyKDE4.kdecore import KStandardDirs, KGlobal

        schemeFiles = KGlobal.dirs().findAllResources("data", "color-schemes/*.colors", KStandardDirs.NoDuplicates)
        for scheme in schemeFiles:
            sets = Settings.getSettings(scheme)
            colorSchemes.append(trStr(sets.value("Name", fu.getBaseName(scheme))))
            colorSchemePaths.append(scheme)
    return colorSchemes, colorSchemePaths
Example #12
0
 def init(self):
   print "init() in BasePlasmoid"
   self.setBusy(True)
   self.kdehome = unicode(KGlobal.dirs().localkdedir())
   self.metadata = self.package().metadata()
   self.show_metadata()
   #self.icon = KIcon(u"%scontents/icons/%s.png" % (self.package().path(), self.metadata.pluginName())) #.pixmap(QSize(22,22))
   self.cfg = self.config(self.metadata.pluginName())
   
   # Check version
   old = version.LooseVersion(fixType(self.cfg.readEntry("version", "0.0.0")))
   new = version.LooseVersion(str(self.metadata.version()))
   if old < new:
     print u"Updating from version '%s' to '%s'" % (str(old), str(new))
     self.update_version()
Example #13
0
    def ensure_notifyrc(self):
        appdir = '{base}/share/apps/{app}/'.format(
            base=KGlobal.dirs().localkdedir(), app=self.appname
        )
        rcpath = os.path.join(
            appdir, '{app}.notifyrc'.format(app=self.appname)
        )

        if os.path.exists(rcpath):
            return

        if not os.path.exists(appdir):
            os.mkdir(appdir)

        copyfile(self.source, rcpath)
Example #14
0
def getColorSchemesAndPath():
    from Core import Settings

    colorSchemes, colorSchemePaths = [], []
    colorSchemes.append("Default")
    colorSchemePaths.append("")
    if isActivePyKDE4:
        from PyKDE4.kdecore import KStandardDirs, KGlobal

        schemeFiles = KGlobal.dirs().findAllResources(
            "data", "color-schemes/*.colors", KStandardDirs.NoDuplicates)
        for scheme in schemeFiles:
            sets = Settings.getSettings(scheme)
            colorSchemes.append(
                trStr(sets.value("Name", fu.getBaseName(scheme))))
            colorSchemePaths.append(scheme)
    return colorSchemes, colorSchemePaths
  def init(self, needsversion=None):
    print "init() in BaseApplet"
    self.setBusy(True)
    self.kdehome = unicode(KGlobal.dirs().localkdedir())
    self.metadata = self.package().metadata()
    self.show_metadata()
    #self.icon = KIcon(u"%scontents/icons/%s.png" % (self.package().path(), self.metadata.pluginName())) #.pixmap(QSize(22,22))
    self.cfg = self.config(self.metadata.pluginName())

    if needsversion is not None:
        current = version.LooseVersion(str(versionString()))
        need = version.LooseVersion(needsversion)
        if current < need:
            self.setFailedToLaunch(True, i18n("You need at least KDE SC version " + str(needsversion)))
            exit

    # Check version
    old = version.LooseVersion(fixType(self.cfg.readEntry("version", "0.0.0")))
    new = version.LooseVersion(str(self.metadata.version()))
    if old < new:
      print u"Updating from version '%s' to '%s'" % (str(old), str(new))
      self.update_version()
Example #16
0
File: kde.py Project: KDE/kajongg
def appdataDir():
    """
    The per user directory with kajongg application information like the database.

    @return: The directory path.
    @rtype: C{str}.
    """
    serverDir = os.path.expanduser('~/.kajonggserver/')
    if Internal.isServer:
        # the server might or might not have KDE installed, so to be on
        # the safe side we use our own .kajonggserver directory
        # the following code moves an existing kajonggserver.db to .kajonggserver
        # but only if .kajonggserver does not yet exist
        kdehome = os.environ.get('KDEHOME', '~/.kde')
        oldPath = os.path.expanduser(
            kdehome +
            '/share/apps/kajongg/kajonggserver.db')
        if not os.path.exists(oldPath):
            oldPath = os.path.expanduser(
                '~/.kde4/share/apps/kajongg/kajonggserver.db')
        if os.path.exists(oldPath) and not os.path.exists(serverDir):
            # upgrading an old kajonggserver installation
            os.makedirs(serverDir)
            shutil.move(oldPath, serverDir)
        if not os.path.exists(serverDir):
            try:
                os.makedirs(serverDir)
            except OSError:
                pass
        return serverDir
    else:
        if not os.path.exists(serverDir):
            # the client wants to place the socket in serverDir
            os.makedirs(serverDir)
        result = os.path.dirname(
            unicode(KGlobal.dirs().locateLocal("appdata", ""))) + '/'
        return result
Example #17
0
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        SymbolManager.__init__(self)
        parent.addPage(self, i18n("Score settings"))

        h = QHBoxLayout(self)
        v = QVBoxLayout()
        h.addLayout(v)
        score = QGroupBox(i18n("Score settings"))
        v.addWidget(score)
        lily =  QGroupBox(i18n("LilyPond"))
        v.addWidget(lily)

        v = QVBoxLayout()
        h.addLayout(v)
        prefs = QGroupBox(i18n("General preferences"))
        v.addWidget(prefs)
        instr = QGroupBox(i18n("Instrument names"))
        v.addWidget(instr)

        # Score settings:
        v = QVBoxLayout(score)
        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Key signature:"), h)
        self.key = QComboBox(h) # the key names are filled in later
        self.mode = QComboBox(h)
        self.mode.addItems([title for name, title in ly.modes(i18n)])
        l.setBuddy(self.key)

        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Time signature:"), h)
        self.time = QComboBox(h)
        self.time.setEditable(True)
        self.time.addItems([
            '(4/4)', '(2/2)',
            '2/4', '3/4', '4/4', '5/4', '6/4', '7/4',
            '2/2', '3/2', '4/2',
            '3/8', '5/8', '6/8', '7/8', '8/8', '9/8', '12/8',
            '3/16', '6/16', '12/16'])
        # palette sensitive icons for the first two items
        self.addItemSymbol(self.time, 0, 'time_c44')
        self.addItemSymbol(self.time, 1, 'time_c22')
        l.setBuddy(self.time)

        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Pickup measure:"), h)
        self.pickup = QComboBox(h)
        self.pickup.addItem(i18n("None"))
        self.pickup.insertSeparator(1)
        durs = [('note_' + d.replace('.', 'd'), d) for d in durations]
        for icon, text in durs:
            self.addItemSymbol(self.pickup, self.pickup.count(), icon)
            self.pickup.addItem(text)
        l.setBuddy(self.pickup)

        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Metronome mark:"), h)
        self.metroDur = QComboBox(h)

        l.setBuddy(self.metroDur)
        for icon, text in durs:
            self.addItemSymbol(self.metroDur, self.metroDur.count(), icon)
            self.metroDur.addItem('')
        l = QLabel('=', h)
        l.setAlignment(Qt.AlignCenter)
        l.setMaximumWidth(20)
        self.metroVal = QComboBox(h)
        self.metroVal.setEditable(True)
        metroValues, start = [], 40
        for end, step in (60, 2), (72, 3), (120, 4), (144, 6), (210, 8):
            metroValues.extend(range(start, end, step))
            start = end
        # reverse so mousewheeling is more intuitive
        self.metroValues = metroValues[::-1]
        self.metroVal.addItems(map(str, self.metroValues))
        def tap(bpm):
            """ Tap the tempo tap button """
            l = [abs(t - bpm) for t in self.metroValues]
            m = min(l)
            if m < 6:
                self.metroVal.setCurrentIndex(l.index(m))
        TapButton(h, tap)

        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Tempo indication:"), h)
        self.tempoInd = KLineEdit(h)
        parent.complete(self.tempoInd, "tempo")
        l.setBuddy(self.tempoInd)
        h.setToolTip(i18n("A tempo indication, e.g. \"Allegro.\""))

        # LilyPond settings
        v = QVBoxLayout(lily)
        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Pitch name language:"), h)
        self.languageNames = list(sorted(ly.keyNames))
        self.lylang = QComboBox(h)
        l.setBuddy(self.lylang)
        self.lylang.addItem(i18n("Default"))
        self.lylang.insertSeparator(1)
        self.lylang.addItems([l.title() for l in self.languageNames])
        h.setToolTip(i18n(
            "The LilyPond language you want to use for the pitch names."))
        self.lylang.currentIndexChanged.connect(self.slotLanguageChanged)
        self.slotLanguageChanged(0) # init with default
        
        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Version:"), h)
        self.lyversion = QComboBox(h)
        self.lyversion.setEditable(True)
        l.setBuddy(self.lyversion)
        version = defaultVersion()
        if version:
            self.lyversion.addItem(str(version))
        self.lyversion.addItems(('2.12.0', '2.10.0'))
        h.setToolTip(i18n(
            "The LilyPond version you will be using for this document."))

        # General preferences
        v = QVBoxLayout(prefs)
        self.typq = QCheckBox(i18n("Use typographical quotes"))
        self.typq.setToolTip(i18n(
            "Replace normal quotes in titles with nice typographical quotes."))
        v.addWidget(self.typq)
        self.tagl = QCheckBox(i18n("Remove default tagline"))
        self.tagl.setToolTip(i18n(
            "Suppress the default tagline output by LilyPond."))
        v.addWidget(self.tagl)
        self.barnum = QCheckBox(i18n("Remove bar numbers"))
        self.barnum.setToolTip(i18n(
            "Suppress the display of measure numbers at the beginning of "
            "every system."))
        v.addWidget(self.barnum)
        self.midi = QCheckBox(i18n("Create MIDI output"))
        self.midi.setToolTip(i18n(
            "Create a MIDI file in addition to the PDF file."))
        v.addWidget(self.midi)
        self.metro = QCheckBox(i18n("Show metronome mark"))
        self.metro.setToolTip(i18n(
            "If checked, show the metronome mark at the beginning of the "
            "score. The MIDI output also uses the metronome setting."))
        v.addWidget(self.metro)

        self.book = QCheckBox(i18n("Wrap score in \\book block"))
        self.book.setToolTip(i18n(
            "If checked, wraps the \\score block inside a \\book block."))
        v.addWidget(self.book)

        # paper size:
        h = KHBox()
        v.addWidget(h)
        h.setSpacing(2)
        l = QLabel(i18n("Paper size:"), h)
        self.paper = QComboBox(h)
        l.setBuddy(self.paper)
        self.paperLandscape = QCheckBox(i18n("Landscape"), h)
        self.paper.addItem(i18n("Default"))
        self.paper.addItems(ly.paperSizes)
        self.paper.activated.connect(lambda i: self.paperLandscape.setEnabled(bool(i)))

        # Instrument names
        instr.setCheckable(True)
        self.instr = instr
        v = QVBoxLayout(instr)

        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("First system:"), h)
        self.instrFirst = QComboBox(h)
        l.setBuddy(self.instrFirst)
        self.instrFirst.addItems((i18n("Long"), i18n("Short")))
        h.setToolTip(i18n(
            "Use long or short instrument names before the first system."))

        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Other systems:"), h)
        self.instrOther = QComboBox(h)
        l.setBuddy(self.instrOther)
        self.instrOther.addItems((i18n("Long"), i18n("Short"), i18n("None")))
        h.setToolTip(i18n(
            "Use short, long or no instrument names before the next systems."))

        h = KHBox()
        v.addWidget(h)
        l = QLabel(i18n("Language:"), h)
        self.instrLang = QComboBox(h)
        l.setBuddy(self.instrLang)
        self.instrLang.addItems((i18n("Default"), KGlobal.locale().languageCodeToName("en")))
        h.setToolTip(i18n("Which language to use for the instrument names."))

        langs = KGlobal.dirs().findAllResources("locale", "*/LC_MESSAGES/frescobaldi.mo")
        self.instrLanguages = list(sorted(set(lang.split('/')[-3] for lang in langs)))
        self.instrLang.addItems(map(KGlobal.locale().languageCodeToName, self.instrLanguages))
        
        self.default()
        self.loadConfig()
Example #18
0
    def document(self):
        """ Get the document as a ly.dom tree structure """
        s = self.wizard.settings # easily access the settings tab.

        doc = ly.dom.Document()

        # instrument names language:
        self.translate = lambda s: s    # english (untranslated)
        i = s.instrLang.currentIndex()
        if i == 0:                      # default (translated)
            self.translate = i18n
        elif i >= 2:                    # other translation
            try:
                import gettext
                self.translate = gettext.GNUTranslations(open(
                  KGlobal.dirs().findResource("locale", s.instrLanguages[i-2] +
                    "/LC_MESSAGES/frescobaldi.mo"))).ugettext
            except IOError:
                pass
        
        # keep track of include files:
        self.includeFiles = []
        
        # keep track of arbitrary code blocks:
        self.codeBlocks = []
        
        # version:
        version = s.lyversion.currentText()
        ly.dom.Version(version, doc)
        ly.dom.BlankLine(doc)
        self.lilyPondVersion = tuple(map(int, re.findall('\\d+', version)))

        # header:
        h = ly.dom.Header()
        for name, value in self.wizard.titles.headers():
            if value:
                h[name] = value
        if 'tagline' not in h and s.tagl.isChecked():
            ly.dom.Comment(i18n("Remove default LilyPond tagline"), h)
            h['tagline'] = ly.dom.Scheme('#f')
        if len(h):
            doc.append(h)
            ly.dom.BlankLine(doc)

        # paper size:
        if s.paper.currentIndex():
            ly.dom.Scheme('(set-paper-size "{0}"{1})'.format(
                    s.paper.currentText(),
                    s.paperLandscape.isChecked() and " 'landscape" or ""),
                ly.dom.Paper(doc)).after = 1
            ly.dom.BlankLine(doc)

        # insert code blocks here later
        codeBlockOffset = len(doc)

        # get the part list
        parts = self.wizard.parts.partList()
        if parts:
            self.buildScore(doc, parts)
        
        # pitch language:
        language = s.getLanguage()
        if language:
            if self.lilyPondVersion >= (2, 13, 38):
                doc.insert(1, ly.dom.Line('\\language "{0}"'.format(language)))
            else:
                self.include("{0}.ly".format(language))

        # add code blocks, if any:
        for code in self.codeBlocks[::-1]:
            node = isinstance(code, basestring) and ly.dom.Line(code) or code()
            node.after = 2
            doc.insert(codeBlockOffset, node)
        
        # add the files that want to be included at the beginning
        if self.includeFiles:
            doc.insert(2, ly.dom.BlankLine())
            for fileName in reversed(self.includeFiles):
                doc.insert(2, ly.dom.Include(fileName))
                
        # Finally, return the document
        return doc
Example #19
0

JS_ENGINE = PyJSEngine()

# If doug crockford wasn’t special, we could do e.g.:
# LINTERS = { 'JSLint': JSModule(JS_ENGINE, p.join(p.dirname(__file__), 'jslint.js'), 'JSLINT') }

LINTERS = {}  # keys() == SETTING_LINTER.choices

_DOUG_LICENSE = 'The Software shall be used for Good, not Evil.'
NEEDS_LICENSE = {
    'JSLint': (_DOUG_LICENSE, 'JSLINT', 'https://raw.github.com/douglascrockford/JSLint/master/jslint.js'),
    'JSHint': (_DOUG_LICENSE, 'JSHINT', 'https://raw.github.com/jshint/jshint/2.x/dist/jshint.js'),
}

CACHE_DIR = KGlobal.dirs().locateLocal('appdata', 'pate/js_utils/', True)  # trailing slash necessary


def license_accepted(license):
    """asks to accept a license"""
    return KMessageBox.Yes == KMessageBox.warningYesNo(kate.mainWindow(),
        i18nc('@info:status', '''<p>
            Additionally to free software licenses like GPL and MIT,
            this functionality requires you to accept the following conditions:
            </p><p>%1</p><p>
            Do you want to accept and download the functionality?
            </p>''', license),
        i18nc('@title:window', 'Accept license?'))


def get_linter(linter_name, callback):
Example #20
0
def rumorScripts():
    return KGlobal.dirs().findAllResources("appdata", "rumor/*")