def get_list(self, obj): if not obj in ["sink", "sink_input", "client", "module", "card"]: return result = None func = obj + '_list' try: method = getattr(self.pulse, func) except Exception as e: handle(e) return self.lock.acquire() try: result = method() except Exception as e: handle(e) finally: self.lock.release() for ele in result: try: sample_spec = { "format": self.sformats[ele.sample_spec.format], "rate": ele.sample_spec.rate, "channels": ele.sample_spec.channels } ele.sample_spec = sample_spec except AttributeError: pass except Exception as e: opthandle(e) return result
def __init__( self, *args, **_kwargs ): self.cwd = args[1] self.skin = args[2] self.sock = SocketCom("server") result = self.sock.call_func("get","eq_channel") if result is None: return self.eqid, self.name, channel = (result) self.channel_id = channel ch_index = [] for ch_name in channel: try: index = chan_num.index(ch_name) ch_index.append(index) except Exception as e: opthandle(e) self.channel = ch_index self.profiles = [tr(32413)] + self.sock.call_func("get","eq_profiles") self.save_profile = self.sock.call_func("get","eq_base_profile") self.sock.call_func("unload","eq_profile",[self.eqid]) self.corrections =[tr(32411)] + self.sock.call_func("get","room_corrections") self.save_correction = self.sock.call_func("get","room_correction") self.sock.call_func("unset","room_correction" , [self.eqid])
def contextMenu(**kwargs): while True: result = run_dialog(ContextGui, "ContextMenu.xml", **kwargs) log("contextMenu: selected: {}".format(result)) #wait for animation time.sleep(0.3) if result["index"] is None: return None if result["type"] == "item": return result["index"] if result["type"] == "func": try: method = result["index"] if method: method() return None except Exception as e: opthandle(e) if result["type"] == "settings": kwargs["items"] = [] return None
def do_update(self): self.update_objects() self.update_kodi_info() msg_list = self.mc.get_messages_and_clear() for cmd, arg in msg_list: #log("padb: co: %s %s" % (cmd,*arg)) try: method = None try: method = getattr(self, cmd) except AttributeError: pass except Exception as e: opthandle(e) if method: method(*arg) except Exception as e: handle(e) msg_list = self.update_attr() + msg_list msg_list = self.update_output_sink() + msg_list #log("padb: {}".format(str(self))) return msg_list
def get_info(self, obj, index): if not obj in ["sink", "sink_input", "client", "module", "card"]: return result = None func = obj + '_info' try: method = getattr(self.pulse, func) except Exception: return self.lock.acquire() try: result = method(index) except PulseIndexError: return None except Exception as e: handle(e) finally: self.lock.release() try: sample_spec = { "format": self.sformats[result.sample_spec.format], "rate": result.sample_spec.rate, "channels": result.sample_spec.channels } result.sample_spec = sample_spec except AttributeError: pass except Exception as e: opthandle(e) return result
def profile_remove(self,name): if not self.profiles: self.profile_file_load() try: del self.profiles[name] except Exception as e: opthandle(e) fn = self.prof_path + "profiles.json" with open(fn, "w") as f: f.write(json.dumps(self.profiles))
def get_mic_specs(self): result = [] files = os.listdir(self.spec_path) for f in files: nb = os.path.splitext(f) try: if nb[1] == ".mic": result.append(nb[0]) except Exception as e: opthandle(e) return result
def __iter__(self): for attr in self.attributes + ["output_sink"]: val = getattr(self, attr) try: val = val.name except AttributeError: pass except Exception as e: opthandle(e) yield (attr, val)
def send_to_server(self, msg): try: s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.settimeout(1.0) s.connect(self.sock_name) self._send(s, msg) data = s.recv(8192) self._close(s) if data == b'': return None return data.decode("utf-8") except Exception as e: opthandle(e) return None
def respond(cls, conn, result): if conn is None: #log("socket: no connection, nothing to respond") return ret = json.dumps(result) if result is not None: log("socket: respond {}".format(ret)) try: cls._send(conn, ret) cls._close(conn) except Exception as e: opthandle(e)
def get_frequencies(): result = [] default = "64, 125, 250, 500, 750, 1000, 2000, 3000, 4000, 8000, 16000" freqs = get_user_setting("frequencies", default).split(",") for freq in freqs: try: if freq[-1] == 'k': result.append(float(freq[:-1]) * 1000) else: result.append(float(freq)) except ValueError as e: opthandle(e) if len(result) > 1: return sorted(result) return [float(x) for x in default]
def get_fil_specs(self): log(self.spec_path) result = [] if not os.path.exists(self.spec_path): os.makedirs(self.spec_path) files = os.listdir(self.spec_path) for f in files: log(f) if not os.path.isdir(self.spec_path + f): continue dfiles = os.listdir(self.spec_path + f) for df in dfiles: nb = os.path.splitext(df) try: if nb[1] == ".fil": result.append(f) break except Exception as e: opthandle(e) return result
def on_message(self, target, func, arg, conn): try: # filter messages if self.padb.on_message(target, func, arg): return # other messages are just forwarded cmd = "on_" + target + "_" + func methods = [] for cl in [self.padb, self, self.pamm, self.eq, self.sg]: try: methods.append(getattr(cl, cmd)) except AttributeError: pass except Exception as e: opthandle(e) if len(methods) == 0: SocketCom.respond(conn, None) return for method in methods: ret = method(*arg) SocketCom.respond(conn, ret) except PulseError as e: handle(e) logerror("pact: in {},{},{}".format(target, func, str(arg))) logerror("pact: try to recover") try: self.pc.stop() self.on_pulse_connect() except Exception as e: handle(e) logerror("pact: recover failed") except Exception as e: logerror("pact: in {},{},{}".format(target, func, str(arg))) handle(e)
def dispatch(self, conn, msg): try: try: func,target,args = json.loads(msg) cmd = "on_%s_%s" % (target,func) except Exception: #log(repr(msg)) try:conn.close() except Exception as e: opthandle(e) return try: method = getattr(self.rec_class,cmd) except Exception: method = None result = method(*args) if method else None self.respond(conn,result) try:conn.close() except Exception as e: opthandle(e) except Exception as e: handle(e)
def update_image(self): fn = self.tmp_fn % self.cnt try: os.remove(fn) except Exception as e: opthandle(e) self.cnt = self.cnt + 1 fn = self.tmp_fn % self.cnt if self.spec_file and self.mic_file: spec = self.spec_file - self.mic_file elif self.spec_file: spec = self.spec_file elif self.mic_file: spec = self.mic_file else: spec = None if spec: createGraph2(fn, spec.as_coef()) else: createGraph2(fn) self.getControl(1000).setImage(fn, False)
def createGraph2(fn, spec=None, width=1700, height=700): with Image.new("RGBA", (width, height), (0, 0, 0, 0)) as im: h = height w = width zero_x = 0 scale = h / 40 zero_y = scale * 4 xscale = w / 2.8 draw = ImageDraw.Draw(im) if spec: coords = [] for f, v in spec.freq_db: if f < 40: continue if f > 25000: break try: xl = (math.log10(f) - 1.6) * xscale + zero_x yl = v if yl > 4: yl = 4 yl = zero_y - yl * scale coords.append((xl, yl)) except Exception as e: opthandle(e) if coords: x1, y1 = coords[0] for x2, y2 in coords[1:]: draw.line((x1, y1, x2, y2), fill=(255, 255, 255, 255), width=4) x1 = x2 y1 = y2 im.save(fn, "PNG")
def stop(self): try: self.pulse.close() except Exception as e: opthandle(e)