def online(cpu=0, online=True): if cpu_get.online(cpu) == online: return (0, None) if online: return run_command(["cpuface_helper", str(cpu), "online"]) else: return run_command(["cpuface_helper", str(cpu), "offline"])
def speed(cpu=0, speed=800): if not (cpu_get.online(cpu)) or (cpu_get.speed(cpu) == speed): return (0, None) return run_command( ["cpuface_helper", str(cpu), "speed", str(speed * 1000)])
def save_profile(self, name=None): if type(name) is bool or name is None: name = self.sel_profile.currentText() self.profiles[name] = list() for cpu in range(0, len(self.cpuinfo)): self.profiles[name].append(dict()) self.profiles[name][cpu]["online"] = cpu_get.online(cpu) if cpu_get.online(cpu): self.profiles[name][cpu]["governor"] = cpu_get.governor(cpu) else: self.profiles[name][cpu]["governor"] = None if cpu_get.governor(cpu) == "userspace": self.profiles[name][cpu]["speed"] = cpu_get.speed(cpu) else: self.profiles[name][cpu]["speed"] = None self.update_ui() self.sel_profile.setCurrentIndex(self.sel_profile.findText(name))
def update_ui(self): # Disable all unwanted calls try: self.sel_profile.currentIndexChanged.disconnect() self.sel_cpu.currentIndexChanged.disconnect() self.check_online.stateChanged.disconnect() self.sel_governor.currentIndexChanged.disconnect() self.val_speed.valueChanged.disconnect() self.btn_new.clicked.disconnect() self.btn_save.clicked.disconnect() self.btn_remove.clicked.disconnect() except TypeError: pass # Disable all options self.sel_profile.setEnabled(False) self.sel_cpu.setEnabled(False) self.check_online.setEnabled(False) self.sel_governor.setEnabled(False) self.val_speed.setEnabled(False) self.btn_new.setEnabled(False) self.btn_save.setEnabled(False) self.btn_remove.setEnabled(False) # Update profile selection prof_index = self.sel_profile.currentIndex() if prof_index == -1: prof_index = 0 self.sel_profile.clear() self.sel_profile.addItem("No profile") for profile in self.profiles: self.sel_profile.addItem(profile) self.sel_profile.setCurrentIndex(prof_index) self.sel_profile.currentIndexChanged.connect(self.set_profile) self.sel_profile.setEnabled(True) # Update CPU selection self.cpuinfo = cpu_get.cpu_info() self.cpu = self.sel_cpu.currentIndex() if self.cpu == -1: self.cpu = 0 self.sel_cpu.clear() for i, cpu in enumerate(self.cpuinfo): self.sel_cpu.addItem("CPU %d: %s" % (i, cpu["name"])) self.sel_cpu.setCurrentIndex(self.cpu) self.sel_cpu.currentIndexChanged.connect(self.update_ui) self.sel_cpu.setEnabled(True) # Update current CPU status self.check_online.setChecked(cpu_get.online(self.cpu)) self.check_online.stateChanged.connect(self.set_online) self.check_online.setEnabled(self.cpu is not 0) # Update current CPU governor self.sel_governor.clear() for governor in cpu_get.governors(self.cpu): self.sel_governor.addItem(governor) self.sel_governor.setCurrentIndex( self.sel_governor.findText(cpu_get.governor(self.cpu))) self.sel_governor.currentIndexChanged.connect(self.set_governor) self.sel_governor.setEnabled(cpu_get.online(self.cpu)) # Update current speed self.val_speed.setMinimum(cpu_get.min_speed(self.cpu)) self.val_speed.setMaximum(cpu_get.max_speed(self.cpu)) self.val_speed.setValue(cpu_get.speed(self.cpu)) self.val_speed.valueChanged.connect(self.set_speed) self.val_speed.setEnabled( cpu_get.online(self.cpu) and (self.sel_governor.currentText() == "userspace")) # Update additional information self.lab_driver.setText(self.cpuinfo[self.cpu]["driver"]) self.lab_vendor.setText(self.cpuinfo[self.cpu]["vendor"]) self.lab_cpu_id.setText(self.cpuinfo[self.cpu]["id"]) self.lab_core_id.setText(self.cpuinfo[self.cpu]["core"]) self.lab_cache.setText(str(self.cpuinfo[self.cpu]["cache"])) # Update buttons action self.btn_new.clicked.connect(self.new_profile) self.btn_new.setEnabled(True) if self.sel_profile.currentText() != "No profile": self.btn_save.clicked.connect(self.save_profile) self.btn_save.setEnabled(True) self.btn_remove.clicked.connect(self.remove_profile) self.btn_remove.setEnabled(True)
def governor(cpu=0, governor="powersave"): if not (cpu_get.online(cpu)) or (cpu_get.governor(cpu) == governor): return (0, None) return run_command(["cpuface_helper", str(cpu), "governor", governor])