Beispiel #1
0
 def stopConky(self):
     max_wait = 5
     wait_cnt = 0
     os.system('killall conky')
     while functions.isProcessRunning('conky'):
         sleep(1)
         wait_cnt += 1
         if wait_cnt >= max_wait:
             break
     if not functions.isProcessRunning('conky'):
         return True
     return False
Beispiel #2
0
 def startConky(self):
     max_wait = 5
     wait_cnt = 0
     if self.stopConky():
         os.system('conky &')
         while not functions.isProcessRunning('conky'):
             sleep(1)
             wait_cnt += 1
             if wait_cnt >= max_wait:
                 break
     if functions.isProcessRunning('conky'):
         return True
     return False
Beispiel #3
0
 def removeConky(self):
     if functions.isProcessRunning('conky'):
         os.system('killall conky')
     if exists(self.conkyrc):
         os.remove(self.conkyrc)
     if exists(self.lua):
         os.remove(self.lua)
     if exists(self.desktop):
         os.remove(self.desktop)
     if exists(self.conkyStart):
         os.remove(self.conkyStart)
Beispiel #4
0
 def on_btnPrefActionApply_clicked(self, widget):
     action = self.getActiveComboValue(self.cmbPrefAction)
     if action:
         if action[0] == 0:
             # Start
             if functions.isProcessRunning('conky'):
                 os.system('killall conky')
             os.system('conky &')
             self.log.write(_("Conky started"), 'conky.on_btnPrefActionApply_clicked', 'info')
         elif action[0] == 1:
             # Stop
             if functions.isProcessRunning('conky'):
                 os.system('killall conky')
                 self.log.write(_("Conky stopped"), 'conky.on_btnPrefActionApply_clicked', 'info')
             else:
                 self.log.write(_("Conky is not running"), 'conky.on_btnPrefActionApply_clicked', 'info')
         elif action[0] == 2:
             # Remove
             self.removeConky()
             self.getDefaultSettings()
             self.log.write(_("Conky removed"), 'conky.on_btnPrefActionApply_clicked', 'info')
Beispiel #5
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 &')