示例#1
0
    def saveSettings(self):
        self.log.write(_("Save settings..."), 'conky.saveSettings', 'info')

        # Kill Conky, and remove all files
        self.removeConky()
        # Wait 5 seconds in the hope conky was stopped
        sleep(5)

        # conkyrc
        template = join(self.scriptDir, 'cfg/conkyrc')
        if exists(template):
            self.log.write(_("Copy %(template)s to %(conkyrc)s" % {"template": template, "conkyrc" :self.conkyrc}), 'conky.saveSettings', 'debug')
            shutil.copy2(template, self.conkyrc)
            functions.chownCurUsr(self.conkyrc)
        else:
            self.log.write(_("Conkyrc template not found %(template)s" % {"template": template}), 'conky.saveSettings', 'error')

        # lua
        template = join(self.scriptDir, 'cfg/clock_rings.lua')
        if exists(template):
            if not exists(self.luaDir):
                os.makedirs(self.luaDir)
            self.log.write(_("Copy %(template)s to %(lua)s" % {"template": template, "lua" :self.lua}), 'conky.saveSettings', 'debug')
            shutil.copy2(template, self.lua)
            functions.chownCurUsr(self.lua)
        else:
            self.log.write(_("Lua template not found %(template)s" % {"template": template}), 'conky.saveSettings', 'error')

        # start script
        template = join(self.scriptDir, 'cfg/conky-start')
        if os.path.exists(template):
            self.log.write(_("Copy %(template)s to %(conkyStart)s" % {"template": template, "conkyStart" :self.conkyStart}), 'conky.saveSettings', 'debug')
            shutil.copy2(template, self.conkyStart)
            functions.chownCurUsr(self.conkyStart)
            functions.makeExecutable(self.conkyStart)
        else:
            self.log.write(_("Start script not found %(template)s" % {"template": template}), 'conky.saveSettings', 'error')

        # Download and upload speed
        dl = self.txtNetwDownSpeed.get_text()
        functions.replaceStringInFile('\[DSPEED\]', str(dl), self.lua)
        self.log.write(_("Save download speed: %(dl)s" % {'dl': dl}), 'conky.saveSettings', 'debug')
        ul = self.txtNetwUpSpeed.get_text()
        functions.replaceStringInFile('\[USPEED\]', str(ul), self.lua)
        self.log.write(_("Save upload speed: %(ul)s" % {'ul': ul}), 'conky.saveSettings', 'debug')

        # Battery / Swap
        bat = '/proc/acpi/battery/BAT0/state'
        if exists(bat):
            self.log.write(_("Battery detected: replace Swap with Battery index"), 'conky.saveSettings', 'debug')
            functions.replaceStringInFile('\$\{swapperc\}', '${battery_percent BAT0}', self.conkyrc)
            functions.replaceStringInFile('\}Swap', '}BAT', self.conkyrc)
            functions.replaceStringInFile("'swapperc'", "'battery_percent'", self.lua)

        # Get selecte temperature unit, and get sensors data accordingly
        tempUnit = self.getActiveComboValue(self.cmbSysTempUnit)[1][0:1].lower()
        if tempUnit == 'c':
            # Celsius
            self.log.write(_("Temperature unit: Celsius"), 'conky.saveSettings', 'debug')
            sensorsCommand = 'sensors'
            sensors = self.ec.run(sensorsCommand, False, False)
        else:
            # Fahrenheit
            self.log.write(_("Temperature unit: Fahrenheit"), 'conky.saveSettings', 'debug')
            sensorsCommand = 'sensors -f'
            sensors = self.ec.run(sensorsCommand, False, False)

        # Core temperature
        if self.chkSysCores.get_active():
            coreList = []
            sensorsList = sensors.splitlines(True)
            for line in sensorsList:
                reObj = re.search('core\s{0,}\d.*\:', line, re.I)
                if reObj:
                    newLine = self.commandCore.replace('[CORESTR]', reObj.group(0))
                    newLine = newLine.replace('[SENSORSTR]', sensorsCommand)
                    self.log.write(_("Core found: %(core)s" % {'core': reObj.group(0)}), 'conky.saveSettings', 'debug')
                    coreList.append(newLine)

            if coreList:
                self.log.write(_("Add Core lines to .conkyrc"), 'conky.saveSettings', 'debug')
                functions.replaceStringInFile('#\s\[CORE\]', '\n'.join(coreList), self.conkyrc)

        # CPU fan speed
        if self.chkSysCpuFan.get_active():
            cpufan = functions.findRegExpInString('cpu\s{0,}fan.*\:', sensors)
            self.log.write(_("Cpu fan value = %(cpufan)s" % {'cpufan' :str(cpufan)}), 'conky.saveSettings', 'debug')
            if cpufan:
                newLine = self.commandCpu.replace('[CPUSTR]', cpufan)
                functions.replaceStringInFile('#\s\[CPUFAN\]', newLine, self.conkyrc)

        # Chassis fan speed
        if self.chkSysChassisFan.get_active():
            chafan = functions.findRegExpInString('chassis\s{0,}fan.*\:', sensors)
            self.log.write(_("Chassis fan value = %(chafan)s" % {'chafan' :str(chafan)}), 'conky.saveSettings', 'debug')
            if chafan:
                newLine = self.commandChassis.replace('[CHASTR]', chafan)
                functions.replaceStringInFile('#\s\[CHAFAN\]', newLine, self.conkyrc)

        # HD temperature unit
        if self.chkSysHd.get_active():
            self.log.write(_("Add HDD temperature to .conkyrc"), 'conky.saveSettings', 'debug')
            newLine = self.commandHdd.replace('[TEMPUNIT]', tempUnit.upper())
            hddCommand = 'hddtemp -n'
            if tempUnit == 'f':
                hddCommand = 'hddtemp -n -u f'
            newLine = newLine.replace('[HDDSTR]', hddCommand)
            functions.replaceStringInFile('#\s\[HDDTEMP\]', newLine, self.conkyrc)

        # LAN IP
        if self.chkNetwLanIP.get_active():
            self.log.write(_("Add LAN IP to .conkyrc"), 'conky.saveSettings', 'debug')
            functions.replaceStringInFile('#\s\[LANIP\]', self.commandLanIp, self.conkyrc)

        # IP
        if self.chkNetwIP.get_active():
            self.log.write(_("Add IP to .conkyrc"), 'conky.saveSettings', 'debug')
            functions.replaceStringInFile('#\s\[IP\]', self.commandIp, self.conkyrc)

        # Kernel
        if self.chkSysKernel.get_active():
            self.log.write(_("Add Kernel to .conkyrc"), 'conky.saveSettings', 'debug')
            functions.replaceStringInFile('#\s\[KERNEL\]', self.commandKernel, self.conkyrc)

        # UP
        if self.chkSysUP.get_active():
            self.log.write(_("Add Update Pack to .conkyrc"), 'conky.saveSettings', 'debug')
            functions.replaceStringInFile('#\s\[UP\]', self.commandUp, self.conkyrc)

        # Conky desktop alignment
        alignment = self.getActiveComboValue(self.cmbPrefAlign)
        self.log.write(_("Conky alignment = %(alignment)s" % {'alignment': alignment[1]}), 'conky.saveSettings', 'debug')
        if alignment[0] > 0:
            functions.replaceStringInFile('alignment\s+tr', 'alignment tl', self.conkyrc)

        # Write sleep before conky start
        sleepNr = functions.strToNumber(self.getActiveComboValue(self.cmbPrefSleep)[1], True)
        self.log.write(_("Conky sleep before start = %(sleep)d seconds" % {'sleep': sleepNr}), 'conky.saveSettings', 'debug')
        if sleepNr != 20:
            functions.replaceStringInFile('20', str(sleepNr), self.conkyStart)

        # Network interface
        eth = self.txtNetwInterface.get_text()
        self.log.write(_("Save network interface: %(interface)s" % {'interface': eth}), 'conky.saveSettings', 'debug')
        functions.replaceStringInFile('\[ETH\]', eth, self.conkyrc)
        functions.replaceStringInFile('\[ETH\]', eth, self.lua)

        # Change color scheme for SolydX
        if 'solydx' in self.dist.lower():
            self.log.write(_("Create orange theme for SolydX"), 'conky.saveSettings', 'debug')
            functions.replaceStringInFile(TEXT_BLUE, TEXT_ORANGE, self.conkyrc)
            functions.replaceStringInFile(TEXT_BLUE, TEXT_ORANGE, self.lua)

        # Automatically start Conky when the user logs in
        if self.chkPrefAutostart.get_active() and not exists(self.desktop):
            self.log.write(_("Write autostart file: %(desktop)s" % {'desktop': self.desktop}), 'conky.saveSettings', 'debug')
            if not exists(self.autostartDir):
                os.makedirs(self.autostartDir)
            desktopCont = '[Desktop Entry]\nComment=SolydXK Conky\nExec=[CONKYSTART]\nIcon=/usr/share/solydxk/logo.png\nStartupNotify=true\nTerminal=false\nType=Application\nName=SolydXK Conky\nGenericName=SolydXK Conky'
            f = open(self.desktop, 'w')
            f.write(desktopCont.replace('[CONKYSTART]', self.conkyStart))
            f.close()
            functions.makeExecutable(self.desktop)

        msg = "SolydXK Conky configuration has finished.\n\nWill now start Conky with the new configuration."
        MessageDialogSave(self.window.get_title(), msg, Gtk.MessageType.INFO, self.window).show()
        self.log.write(_("Save settings done"), 'conky.saveSettings', 'info')

        # Restart Conky
        if functions.isProcessRunning('conky'):
            os.system('killall conky')
        os.system('conky &')
示例#2
0
    def getSettings(self):
        if exists(self.conkyrc):
            self.log.write(_("Start reading existing settings"), 'conky.getSettings', 'info')
            self.cmbPrefAction.set_active(0)
            # TODO: Read values from conkyrc, and show these in the gui
            conkyrcCont = functions.getFileContents(self.conkyrc)
            luaCont = functions.getFileContents(self.lua)
            startCont = functions.getFileContents(self.conkyStart)

            if functions.findRegExpInString('\[ETH\]', conkyrcCont):
                # If the [ETH] placeholder is found, assume template
                self.getDefaultSettings()
            else:
                # Preferences
                if exists(self.desktop):
                    self.log.write(_("Autostart found"), 'conky.getSettings', 'debug')
                    self.chkPrefAutostart.set_active(True)

                sleepStr = functions.findRegExpInString('\d+', startCont)
                if sleepStr:
                    sleepNr = functions.strToNumber(sleepStr, True)
                    self.log.write(_("Current nr of seconds to sleep before starting Conky: %(sleepnr)d" % {'sleepnr': sleepNr}), 'conky.getSettings', 'debug')
                    index = -1
                    for val in self.sleep:
                        if index >= 0:
                            if sleepNr < val[0]:
                                break
                        index += 1
                    self.cmbPrefSleep.set_active(index)

                alignment = functions.findRegExpInString('alignment\s([a-z]*)', conkyrcCont, 1)
                if alignment:
                    self.log.write(_("Current alignment: %(alignment)s" % {'alignment': alignment}), 'conky.getSettings', 'debug')
                    if alignment == 'tr':
                        self.cmbPrefAlign.set_active(0)
                    else:
                        self.cmbPrefAlign.set_active(1)
                else:
                    self.cmbPrefAlign.set_active(0)

                # Network
                eth = functions.findRegExpInString('\{downspeed\s+([a-z0-9]*)', conkyrcCont, 1)
                if eth:
                    self.log.write(_("Current network interface: %(interface)s" % {'interface': eth}), 'conky.getSettings', 'debug')
                    self.txtNetwInterface.set_text(eth)
                else:
                    self.txtNetwInterface.set_text(functions.getNetworkInterface())

                dl = functions.findRegExpInString('downspeedf.*\n.*\n,*[a-z\=\s]*(\d*)', luaCont, 1)
                if dl:
                    self.log.write(_("Current download speed: %(dl)s" % {'dl': dl}), 'conky.getSettings', 'debug')
                    self.txtNetwDownSpeed.set_text(dl)
                else:
                    self.txtNetwDownSpeed.set_text(self.defaultSpeed)

                ul = functions.findRegExpInString('upspeedf.*\n.*\n,*[a-z\=\s]*(\d*)', luaCont, 1)
                if ul:
                    self.log.write(_("Current upload speed: %(ul)s" % {'ul': ul}), 'conky.getSettings', 'debug')
                    self.txtNetwUpSpeed.set_text(ul)
                else:
                    self.txtNetwUpSpeed.set_text(self.defaultSpeed)

                if functions.findRegExpInString('<inet', conkyrcCont):
                    self.log.write(_("Check LAN IP"), 'conky.getSettings', 'debug')
                    self.chkNetwLanIP.set_active(True)
                if functions.findRegExpInString('dyndns', conkyrcCont):
                    self.log.write(_("Check IP"), 'conky.getSettings', 'debug')
                    self.chkNetwIP.set_active(True)

                # System
                if functions.findRegExpInString('core\d*\s+temp', conkyrcCont):
                    self.log.write(_("Check cores"), 'conky.getSettings', 'debug')
                    self.chkSysCores.set_active(True)
                if functions.findRegExpInString('hddtemp', conkyrcCont, 0, True):
                    self.log.write(_("Check HD temperature"), 'conky.getSettings', 'debug')
                    self.chkSysHd.set_active(True)

                if functions.findRegExpInString('sensors\s+\-f', conkyrcCont):
                    self.log.write(_("Using temperature unit Fahrenheit"), 'conky.getSettings', 'debug')
                    self.cmbSysTempUnit.set_active(1)
                else:
                    self.log.write(_("Using temperature unit Celsius"), 'conky.getSettings', 'debug')
                    self.cmbSysTempUnit.set_active(0)

                if functions.findRegExpInString('cpu\s+fan', conkyrcCont):
                    self.log.write(_("Check CPU fan"), 'conky.getSettings', 'debug')
                    self.chkSysCpuFan.set_active(True)
                if functions.findRegExpInString('chassis\s+fan', conkyrcCont):
                    self.log.write(_("Check chassis fan"), 'conky.getSettings', 'debug')
                    self.chkSysChassisFan.set_active(True)
                if functions.findRegExpInString('kernel', conkyrcCont, 0, True):
                    self.log.write(_("Check kernel"), 'conky.getSettings', 'debug')
                    self.chkSysKernel.set_active(True)
                if functions.findRegExpInString('packlevel', conkyrcCont):
                    self.log.write(_("Check Update Pack"), 'conky.getSettings', 'debug')
                    self.chkSysUP.set_active(True)
        else:
            self.getDefaultSettings()
示例#3
0
    def saveSettings(self):
        self.log.write("Save settings...", 'conky.saveSettings', 'info')

        # Reset colors
        self.dayClockColor = self.dayClockColorDefault
        self.dateTitleColor = self.dateTitleColorDefault
        self.systemInfoColor = self.systemInfoColorDefault
        # Kill Conky, and remove all files
        self.removeConky()

        # conkyrc
        if exists(self.conkyrc_template):
            if not exists(self.conkyrc):
                self.log.write("Copy %(template)s to %(conkyrc)s" % {"template": self.conkyrc_template, "conkyrc" :self.conkyrc}, 'conky.saveSettings', 'debug')
                shutil.copy2(self.conkyrc_template, self.conkyrc)
                functions.chownCurUsr(self.conkyrc)
        else:
            self.log.write("Conkyrc template not found %(template)s" % {"template": self.conkyrc_template}, 'conky.saveSettings', 'error')

        # lua
        if exists(self.lua_template):
            if not exists(self.lua):
                if not exists(self.luaDir):
                    os.makedirs(self.luaDir)
                self.log.write("Copy %(template)s to %(lua)s" % {"template": self.lua_template, "lua" :self.lua}, 'conky.saveSettings', 'debug')
                shutil.copy2(self.lua_template, self.lua)
                functions.chownCurUsr(self.lua)
        else:
            self.log.write("Lua template not found %(template)s" % {"template": self.lua_template}, 'conky.saveSettings', 'error')

        # start script
        template = join(self.scriptDir, 'cfg/conky-start')
        if os.path.exists(template):
            if not exists(self.conkyStart):
                self.log.write("Copy %(template)s to %(conkyStart)s" % {"template": template, "conkyStart" :self.conkyStart}, 'conky.saveSettings', 'debug')
                shutil.copy2(template, self.conkyStart)
        else:
            self.log.write("Start script not found %(template)s" % {"template": template}, 'conky.saveSettings', 'error')

        # Download and upload speed
        dl = self.txtNetwDownSpeed.get_text()
        functions.replaceStringInFile('\[DSPEED\]', str(dl), self.lua)
        self.log.write("Save download speed: %(dl)s" % {'dl': dl}, 'conky.saveSettings', 'debug')
        ul = self.txtNetwUpSpeed.get_text()
        functions.replaceStringInFile('\[USPEED\]', str(ul), self.lua)
        self.log.write("Save upload speed: %(ul)s" % {'ul': ul}, 'conky.saveSettings', 'debug')

        # Get selecte temperature unit, and get sensor data accordingly
        tempUnit = self.getActiveComboValue(self.cmbSysTempUnit)[1][0:1].lower()
        tempUnitStr = '°C'
        if tempUnit == 'c':
            # Celsius
            self.log.write("Temperature unit: Celsius", 'conky.saveSettings', 'debug')
            sensorsCommand = 'sensors'
        else:
            # Fahrenheit
            self.log.write("Temperature unit: Fahrenheit", 'conky.saveSettings', 'debug')
            tempUnitStr = '°F'
            sensorsCommand = 'sensors -f'
        sensors = self.ec.run(sensorsCommand, False, False)

        # Localization
        functions.replaceStringInFile('\[CPU\]', _("CPU"), self.conkyrc)
        functions.replaceStringInFile('\[RAM\]', _("RAM"), self.conkyrc)
        functions.replaceStringInFile('\[DISK\]', _("Disk"), self.conkyrc)
        functions.replaceStringInFile('\[NET\]', _("Net"), self.conkyrc)

        # Core temperature
        if self.chkSysCores.get_active():
            self.commandCore = self.commandCore.replace('[TEMPUNIT]', tempUnitStr)
            self.commandCore = self.commandCore.replace("[CORELABEL]", self.corelbl)
            self.commandCore = self.commandCore.replace("[SENSORSTR]", sensorsCommand)
            functions.replaceStringInFile('#\s*\[CORE\]', self.commandCore, self.conkyrc)
            self.log.write("Core command added", 'conky.saveSettings', 'debug')

        # CPU fan speed
        if self.chkSysCpuFan.get_active():
            cpufan = functions.findRegExpInString('cpu\s{0,}fan.*\:', sensors)
            self.log.write("Cpu fan value = %(cpufan)s" % {'cpufan' :str(cpufan)}, 'conky.saveSettings', 'debug')
            if cpufan:
                self.commandCpu = self.commandCpu.replace("[CPULABEL]", self.cpulbl)
                self.commandCpu = self.commandCpu.replace('[CPUSTR]', cpufan)

                functions.replaceStringInFile('#\s*\[CPUFAN\]', self.commandCpu, self.conkyrc)

        # Chassis fan speed
        if self.chkSysChassisFan.get_active():
            chafan = functions.findRegExpInString('chassis\s{0,}fan.*\:', sensors)
            self.log.write("Chassis fan value = %(chafan)s" % {'chafan' :str(chafan)}, 'conky.saveSettings', 'debug')
            if chafan:
                self.commandChassis = self.commandChassis.replace("[CHASSISLABEL]", self.chassislbl)
                self.commandChassis = self.commandChassis.replace('[CHASTR]', chafan)
                functions.replaceStringInFile('#\s*\[CHAFAN\]', self.commandChassis, self.conkyrc)

        # HD temperature unit
        if self.chkSysHd.get_active():
            self.log.write("Add HDD temperature to .conkyrc", 'conky.saveSettings', 'debug')
            self.commandHdd = self.commandHdd.replace('[TEMPUNIT]', tempUnitStr)
            self.commandHdd = self.commandHdd.replace('[HDLABEL]', self.hdlbl)
            hddCommand = 'hddtemp -n'
            if tempUnit == 'f':
                hddCommand = 'hddtemp -n -u f'
            self.commandHdd = self.commandHdd.replace('[HDDSTR]', hddCommand)
            functions.replaceStringInFile('#\s*\[HDDTEMP\]', self.commandHdd, self.conkyrc)

        # LAN IP
        if self.chkNetwLanIP.get_active():
            self.log.write("Add LAN IP to .conkyrc", 'conky.saveSettings', 'debug')
            self.commandLanIp = self.commandLanIp.replace("[LANLABEL]", self.lanlbl)
            functions.replaceStringInFile('#\s*\[LANIP\]', self.commandLanIp, self.conkyrc)

        # IP
        if self.chkNetwIP.get_active():
            self.log.write("Add IP to .conkyrc", 'conky.saveSettings', 'debug')
            self.commandIp = self.commandIp.replace("[IPLABEL]", self.iplbl)
            functions.replaceStringInFile('#\s*\[IP\]', self.commandIp, self.conkyrc)

        # Kernel
        if self.chkSysKernel.get_active():
            self.log.write("Add Kernel to .conkyrc", 'conky.saveSettings', 'debug')
            self.commandKernel = self.commandKernel.replace("[KERNELLABEL]", self.kernellbl)
            functions.replaceStringInFile('#\s*\[KERNEL\]', self.commandKernel, self.conkyrc)

        # Conky desktop alignment
        alignment = self.getActiveComboValue(self.cmbPrefAlign)
        self.log.write("Conky alignment = %(alignment)s" % {'alignment': alignment[1]}, 'conky.saveSettings', 'debug')
        if alignment[0] > 0:
            functions.replaceStringInFile('alignment\s+tr', 'alignment tl', self.conkyrc)

        # Write sleep before conky start
        sleepNr = functions.strToNumber(self.getActiveComboValue(self.cmbPrefSleep)[1], True)
        self.log.write("Conky sleep before start = %(sleep)d seconds" % {'sleep': sleepNr}, 'conky.saveSettings', 'debug')
        if sleepNr != 20:
            functions.replaceStringInFile('20', str(sleepNr), self.conkyStart)

        # Network interface
        eth = self.txtNetwInterface.get_text()
        self.log.write("Save network interface: %(interface)s" % {'interface': eth}, 'conky.saveSettings', 'debug')
        functions.replaceStringInFile('\[ETH\]', eth, self.conkyrc)
        functions.replaceStringInFile('\[ETH\]', eth, self.lua)

        # Write colors
        if self.dayClockColorNew == self.dayClockColor:
            self.dayClockColorNew = None
        if self.dateTitleColorNew == self.dateTitleColor:
            self.dateTitleColorNew = None
        if self.systemInfoColorNew == self.systemInfoColor:
            self.systemInfoColorNew = None

        if self.dateTitleColorNew is not None:
            functions.replaceStringInFile(self.dateTitleColor, self.dateTitleColorNew, self.conkyrc)
            self.log.write("Replace Date and Title color %s with %s" % (self.dateTitleColor, self.dateTitleColorNew), 'conky.saveSettings', 'info')
            self.dateTitleColor = self.dateTitleColorNew
        if self.dayClockColorNew is not None:
            functions.replaceStringInFile(self.dayClockColor, self.dayClockColorNew, self.conkyrc)
            functions.replaceStringInFile(self.dayClockColor, self.dayClockColorNew, self.lua)
            self.log.write("Replace Day and Clock color %s with %s" % (self.dayClockColor, self.dayClockColorNew), 'conky.saveSettings', 'info')
            self.dayClockColor = self.dayClockColorNew
        if self.systemInfoColorNew is not None:
            functions.replaceStringInFile(self.systemInfoColor, self.systemInfoColorNew, self.conkyrc)
            functions.replaceStringInFile(self.systemInfoColor, self.systemInfoColorNew, self.lua)
            self.log.write("Replace System Info color %s with %s" % (self.systemInfoColor, self.systemInfoColorNew), 'conky.saveSettings', 'info')
            self.systemInfoColor = self.systemInfoColorNew

        # Automatically start Conky when the user logs in
        if self.chkPrefAutostart.get_active() and not exists(self.desktop):
            self.log.write("Write autostart file: %(desktop)s" % {'desktop': self.desktop}, 'conky.saveSettings', 'debug')
            if not exists(self.autostartDir):
                os.makedirs(self.autostartDir)
            desktopCont = '[Desktop Entry]\nComment=SolydXK Conky\nExec=[CONKYSTART]\nIcon=/usr/share/solydxk/logo.png\nStartupNotify=true\nTerminal=false\nType=Application\nName=SolydXK Conky\nGenericName=SolydXK Conky'
            f = open(self.desktop, 'w')
            f.write(desktopCont.replace('[CONKYSTART]', self.conkyStart))
            f.close()
            functions.makeExecutable(self.desktop)

        msg = "SolydXK Conky configuration has finished.\n\nWill now start Conky with the new configuration."
        MessageDialog(self.window.get_title(), msg)
        self.log.write("Save settings done", 'conky.saveSettings', 'info')

        # Restart Conky
        functions.makeExecutable(self.conkyStart)
        self.startConky()
示例#4
0
sensorsList = sensors.splitlines(True)
for line in sensorsList:
    reObj = re.search('core\s{0,}\d.*\:', line, re.I)
    if reObj:
        newLine = string.replace(coreLine, '[CORESTR]', reObj.group(0))
        if 'F' in tmpUnit:
            newLine = string.replace(newLine, 'sensors', 'sensors -f')
        functions.log("Core string found: %s" % reObj.group(0))
        coreList.append(newLine)

if coreList:
    functions.log("Add Core lines to .conkyrc")
    functions.replaceStringInFile('#\s\[CORE\]', '\n'.join(coreList), conkyrc)

# CPU fan speed
cpufan = functions.findRegExpInString('cpu\s{0,}fan.*\:', sensors)
functions.log("Cpufan value = %s" % cpufan)
if cpufan:
    cpuLine = '${color 00BFFF}CPU fan:${alignr}${color FFFFFF}${execi 30 sensors | grep "[CPUSTRING]"|cut -d":" -f2|sed "s/ //g"|sed "s/+//g" | cut -d"R" -f1} RPM'
    functions.log("Write CPU fan speed: %s" % cpufan)
    newLine = string.replace(cpuLine, '[CPUSTRING]', cpufan)
    functions.replaceStringInFile('#\s\[CPUFAN\]', newLine, conkyrc)

# Chassis fan speed
chafan = functions.findRegExpInString('chassis\s{0,}fan.*\:', sensors)
functions.log("Chafan value = %s" % chafan)
if chafan:
    chaLine = '${color 00BFFF}Chassis fan:${alignr}${color FFFFFF}${execi 30 sensors | grep "[CHASTRING]"|cut -d":" -f2|sed "s/ //g"|sed "s/+//g" | cut -d"R" -f1} RPM'
    functions.log("Write chassis fan speed: %s" % chafan)
    newLine = string.replace(chaLine, '[CHASTRING]', chafan)
    functions.replaceStringInFile('#\s\[CHAFAN\]', newLine, conkyrc)
示例#5
0
    def getSettings(self):
        if exists(self.conkyrc):
            self.log.write("Start reading existing settings", 'conky.getSettings', 'info')
            self.cmbPrefAction.set_active(0)
            # TODO: Read values from conkyrc, and show these in the gui
            conkyrcCont = functions.getFileContents(self.conkyrc)
            luaCont = functions.getFileContents(self.lua)
            startCont = functions.getFileContents(self.conkyStart)

            if functions.findRegExpInString('\[ETH\]', conkyrcCont):
                # If the [ETH] placeholder is found, assume template
                self.getDefaultSettings()
            else:
                # Preferences
                if exists(self.desktop):
                    self.log.write("Autostart found", 'conky.getSettings', 'debug')
                    self.chkPrefAutostart.set_active(True)
                try:
                    sleepStr = functions.findRegExpInString('\d{2,}', startCont)
                    if sleepStr:
                        sleepNr = functions.strToNumber(sleepStr, True)
                        self.log.write("Current nr of seconds to sleep before starting Conky: %(sleepnr)d" % {'sleepnr': sleepNr}, 'conky.getSettings', 'debug')
                        index = -1
                        for val in self.sleep:
                            if index >= 0:
                                if sleepNr < val[0]:
                                    break
                            index += 1
                        self.cmbPrefSleep.set_active(index)
                except:
                    # Best effort
                    pass

                alignment = functions.findRegExpInString('alignment\s([a-z]*)', conkyrcCont, 1)
                if alignment:
                    self.log.write("Current alignment: %(alignment)s" % {'alignment': alignment}, 'conky.getSettings', 'debug')
                    if alignment == 'tr':
                        self.cmbPrefAlign.set_active(0)
                    else:
                        self.cmbPrefAlign.set_active(1)
                else:
                    self.cmbPrefAlign.set_active(0)

                # Network
                eth = functions.findRegExpInString('\{downspeed\s+([a-z0-9]*)', conkyrcCont, 1)
                if eth:
                    self.log.write("Current network interface: %(interface)s" % {'interface': eth}, 'conky.getSettings', 'debug')
                    self.txtNetwInterface.set_text(eth)
                else:
                    eth = functions.getNetworkInterface()
                    if eth is None:
                        eth = 'eth0'
                    self.txtNetwInterface.set_text()

                dl = functions.findRegExpInString('downspeedf.*\n.*\n,*[a-z\max=\s]*(\d*)', luaCont, 1)
                if dl:
                    self.log.write("Current download speed: %(dl)s" % {'dl': dl}, 'conky.getSettings', 'debug')
                    self.txtNetwDownSpeed.set_text(dl)
                else:
                    self.txtNetwDownSpeed.set_text("%s0" % self.defaultSpeed)

                ul = functions.findRegExpInString('upspeedf.*\n.*\n,*[a-z\max=\s]*(\d*)', luaCont, 1)
                if ul:
                    self.log.write("Current upload speed: %(ul)s" % {'ul': ul}, 'conky.getSettings', 'debug')
                    self.txtNetwUpSpeed.set_text(ul)
                else:
                    self.txtNetwUpSpeed.set_text(self.defaultSpeed)

                if functions.findRegExpInString(self.lanlbl, conkyrcCont, caseSensitive=True):
                    self.log.write("Check LAN IP", 'conky.getSettings', 'debug')
                    self.chkNetwLanIP.set_active(True)
                if functions.findRegExpInString('pre_exec myip', conkyrcCont):
                    self.log.write("Check IP", 'conky.getSettings', 'debug')
                    self.chkNetwIP.set_active(True)

                # System
                if functions.findRegExpInString(self.corelbl, conkyrcCont, caseSensitive=True):
                    self.log.write("Check cores", 'conky.getSettings', 'debug')
                    self.chkSysCores.set_active(True)
                if functions.findRegExpInString(self.hdlbl, conkyrcCont, caseSensitive=True):
                    self.log.write("Check HD temperature", 'conky.getSettings', 'debug')
                    self.chkSysHd.set_active(True)

                if functions.findRegExpInString('sensors\s+\-f', conkyrcCont):
                    self.log.write("Using temperature unit Fahrenheit", 'conky.getSettings', 'debug')
                    self.cmbSysTempUnit.set_active(1)
                else:
                    self.log.write("Using temperature unit Celsius", 'conky.getSettings', 'debug')
                    self.cmbSysTempUnit.set_active(0)

                if functions.findRegExpInString(self.cpulbl, conkyrcCont, caseSensitive=True):
                    self.log.write("Check CPU fan", 'conky.getSettings', 'debug')
                    self.chkSysCpuFan.set_active(True)
                if functions.findRegExpInString(self.chassislbl, conkyrcCont, caseSensitive=True):
                    self.log.write("Check chassis fan", 'conky.getSettings', 'debug')
                    self.chkSysChassisFan.set_active(True)
                if functions.findRegExpInString(self.kernellbl, conkyrcCont, caseSensitive=True):
                    self.log.write("Check kernel", 'conky.getSettings', 'debug')
                    self.chkSysKernel.set_active(True)

                # Colors
                hex_color = functions.findRegExpInString('\$\{color\s+([0-9a-zA-Z]{6})\}', conkyrcCont, 1)
                if hex_color is None:
                    hex_color = self.dayClockColorDefault
                else:
                    hex_color = hex_color.upper()
                self.log.write("Day and Clock color: %(hex_color)s" % {'hex_color': hex_color}, 'conky.getSettings', 'debug')
                self.dayClockColor = hex_color

                hex_color = functions.findRegExpInString('\$\{color\s+([0-9a-zA-Z]{6})\}\$\{hr\}', conkyrcCont, 1)
                if hex_color is None:
                    hex_color = self.dateTitleColorDefault
                else:
                    hex_color = hex_color.upper()
                self.log.write("Date and Title color: %(hex_color)s" % {'hex_color': hex_color}, 'conky.getSettings', 'debug')
                self.dateTitleColor = hex_color

                hex_color = functions.findRegExpInString('\$\{color\s+([0-9a-zA-Z]{6})\}\$\{goto', conkyrcCont, 1)
                if hex_color is None:
                    hex_color = self.systemInfoColorDefault
                else:
                    hex_color = hex_color.upper()
                self.log.write("System Information color: %(hex_color)s" % {'hex_color': hex_color}, 'conky.getSettings', 'debug')
                self.systemInfoColor = hex_color

                self.setColorButtonColor(self.colorBtnDayClock, self.dayClockColor)
                self.setColorButtonColor(self.colorBtnDateTitle, self.dateTitleColor)
                self.setColorButtonColor(self.colorBtnSystemInfo, self.systemInfoColor)

        else:
            self.getDefaultSettings()