def getDefaultSettings(self): # Set default values in gui self.log.write("Get default settings", 'conky.getDefaultSettings', 'info') self.cmbPrefAction.set_active(0) self.cmbPrefSleep.set_active(2) self.cmbPrefAlign.set_active(0) self.chkPrefAutostart.set_active(True) eth = functions.getNetworkInterface() if eth is None: eth = 'eth0' self.txtNetwInterface.set_text(eth) self.txtNetwDownSpeed.set_text("%s0" % self.defaultSpeed) self.txtNetwUpSpeed.set_text(self.defaultSpeed) self.chkNetwLanIP.set_active(True) self.chkNetwIP.set_active(True) self.chkSysCores.set_active(True) self.chkSysHd.set_active(True) self.cmbSysTempUnit.set_active(0) self.chkSysCpuFan.set_active(True) self.chkSysChassisFan.set_active(True) self.chkSysKernel.set_active(True) self.dayClockColor = self.dayClockColorDefault self.dateTitleColor = self.dateTitleColorDefault self.systemInfoColor = self.systemInfoColorDefault self.setColorButtonColor(self.colorBtnDayClock, self.dayClockColor) self.setColorButtonColor(self.colorBtnDateTitle, self.dateTitleColor) self.setColorButtonColor(self.colorBtnSystemInfo, self.systemInfoColor)
def getDefaultSettings(self): # Set default values in gui self.log.write(_("Get default settings"), 'conky.getDefaultSettings', 'info') self.cmbPrefAction.set_active(0) self.cmbPrefSleep.set_active(2) self.cmbPrefAlign.set_active(0) self.chkPrefAutostart.set_active(True) self.txtNetwInterface.set_text(functions.getNetworkInterface()) self.txtNetwDownSpeed.set_text(self.defaultSpeed) self.txtNetwUpSpeed.set_text(self.defaultSpeed) self.chkNetwLanIP.set_active(True) self.chkNetwIP.set_active(True) self.chkSysCores.set_active(True) self.chkSysHd.set_active(True) self.cmbSysTempUnit.set_active(0) self.chkSysCpuFan.set_active(True) self.chkSysChassisFan.set_active(True) self.chkSysKernel.set_active(True) self.chkSysUP.set_active(True)
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()
if answer: functions.repaintGui() dload = int(functions.getBandwidthSpeed()) if dload <= 1024: dload = 1024 functions.log("Default speed selected: %d" % dload) else: dload *= 5 #uload = int(dload / 10) functions.replaceStringInFile('\[DSPEED\]', str(dload), lua) functions.replaceStringInFile('\[USPEED\]', str(dload), lua) # Network interface functions.log('=============================================') interface = functions.getNetworkInterface() functions.log('=============================================') if not interface: interface = 'eth0' functions.replaceStringInFile('\[ETH\]', interface, conkyrc) functions.replaceStringInFile('\[ETH\]', interface, lua) # Battery / Swap bat = '/proc/acpi/battery/BAT0/state' if os.path.exists(bat): functions.log("Battery detected: replace Swap with Battery index") functions.replaceStringInFile('\$\{swapperc\}', '${battery_percent BAT0}', conkyrc) functions.replaceStringInFile('\}Swap', '}BAT', conkyrc) functions.replaceStringInFile("'swapperc'", "'battery_percent'", lua) # Core temperature
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()