def quit(self, *rest): from .patch_info import PatchInfo log.debug("Quit command from GUI or WM") self.close_in_progress = True to_delete = [ p for p in self.patches if p.deletable ] for p in to_delete: p.delete() self.close_in_progress = False self.object_view.refresh() allpatches = MFPGUI().mfp.open_patches() guipatches = [ p.obj_id for p in self.objects if isinstance(p, PatchInfo) ] for a in allpatches: if a not in guipatches: log.debug("Some patches cannot be deleted, not quitting") return False if self.console_mgr: self.console_mgr.quitreq = True self.console_mgr.join() log.debug("Console thread reaped") self.console_mgr = None MFPGUI().appwin = False MFPGUI().finish() MFPGUI().mfp.quit() return True
def cb(fname): if fname: patch.last_filename = fname if fname != default_filename: basefile = os.path.basename(fname) parts = os.path.splitext(basefile) newname = parts[0] patch.obj_name = newname MFPGUI().mfp.rename_obj(patch.obj_id, newname) patch.send_params() self.window.refresh(patch) MFPGUI().mfp.save_file(patch.obj_name, fname)
def label_edit_finish(self, *args): # called by labeleditmode t = self.label.get_text() self.update_value(float(t)) if self.obj_id is None: self.create_obj() MFPGUI().mfp.send(self.obj_id, 0, self.value)
def get_color(self, colorspec): rgba = MFPGUI().style_defaults.get(colorspec) if not rgba: return None elif isinstance(rgba, str): return ColorDB().find(rgba) else: return ColorDB().find(rgba[0], rgba[1], rgba[2], rgba[3])
def send_params(self, **extras): if self.obj_id is None: return prms = self.synced_params() for k, v in extras.items(): prms[k] = v MFPGUI().mfp.set_params(self.obj_id, prms)
def quit(self): def quit_confirm(answer): if answer is not None: aa = answer.strip().lower() if aa in ['y', 'yes']: self.window.quit() allpatches = MFPGUI().mfp.open_patches() clean = True for p in allpatches: if MFPGUI().mfp.has_unsaved_changes(p): clean = False if not clean: self.window.get_prompted_input( "There are patches with unsaved changes. Quit anyway? [yN]", quit_confirm, '') else: self.window.quit()
def toggle_pause(self): from mfp import log try: paused = MFPGUI().mfp.toggle_pause() if paused: log.warning("Execution of all patches paused") else: log.warning("Execution of all patches resumed") except Exception as e: print("Caught exception", e)
def label_edit_finish(self, widget, new_text, aborted=False): if self.obj_id is None: self.create(self.proc_type, None) if self.obj_id is None: log.warning("TextElement: could not create obj") elif new_text != self.value and not aborted: self.value = new_text self.set_text() MFPGUI().mfp.send(self.obj_id, 0, self.value) self.update()
def label_edit_finish(self, widget=None, text=None): if text is not None: self.message_text = text for to in self.target_obj: if to is not self: MFPGUI().mfp.eval_and_send(to.obj_id, self.target_port, self.message_text) for to in self.target_obj: self.stage.select(to) self.delete()
def create_obj(self): if self.obj_id is None: self.create(self.proc_type, str(self.value)) if self.obj_id is None: print "MessageElement: could not create message obj" else: MFPGUI().mfp.set_do_onload(self.obj_id, True) self.obj_state = self.OBJ_COMPLETE self.draw_ports() self.texture.invalidate()
def toggle_tree(self): alloc = self.window.tree_canvas_pane.get_allocation() oldpos = self.window.tree_canvas_pane.get_position() self.window.tree_canvas_pane.set_position(self.next_tree_position) self.next_tree_position = oldpos # KLUDGE! MFPGUI().clutter_do_later(100, self._refresh) return False
def update_value(self, value): if value >= self.max_value: value = self.max_value if value <= self.min_value: value = self.min_value if value != self.value: self.value = value self.texture.invalidate() MFPGUI().mfp.send(self.obj_id, 0, self.value)
def show_tip(self, xpos, ypos, details): tiptxt = None orig_x, orig_y = self.get_stage_position() if self.obj_id is None: return False for (pid, pobj) in self.port_elements.items(): x, y = pobj.get_position() x += orig_x - 1 y += orig_y - 1 w, h = pobj.get_size() w += 2 h += 2 if (xpos >= x) and (xpos <= x+w) and (ypos >= y) and (ypos <= y+h): tiptxt = MFPGUI().mfp.get_tooltip(self.obj_id, pid[0], pid[1], details) if tiptxt is None: tiptxt = MFPGUI().mfp.get_tooltip(self.obj_id, None, None, details) self.stage.hud_banner(tiptxt) return True
def delete(self): self.stage.unregister(self) if self.obj_id is not None and not self.is_export: MFPGUI().mfp.delete(self.obj_id) elif self.obj_id is None: for conn in [c for c in self.connections_out]: conn.delete() for conn in [c for c in self.connections_in]: conn.delete() self.obj_id = None self.obj_state = self.OBJ_DELETED
def send_params(self, **extras): if self.obj_id is None: return prms = {} for k in self.param_list: prms[k] = getattr(self, k) for k, v in extras.items(): prms[k] = v MFPGUI().mfp.set_params(self.obj_id, prms)
def toggle_console(self): from gi.repository import Gdk alloc = self.window.content_console_pane.get_allocation() oldpos = self.window.content_console_pane.get_position() self.window.content_console_pane.set_position( alloc.height - self.next_console_position) self.next_console_position = alloc.height - oldpos # KLUDGE! MFPGUI().clutter_do_later(100, self._refresh) return False
def delete(self): if (not self.dashed and self.obj_1 and self.obj_2 and self.obj_1.obj_id is not None and self.obj_2.obj_id is not None): MFPGUI().mfp.disconnect(self.obj_1.obj_id, self.port_1, self.obj_2.obj_id, self.port_2) if self.obj_1 and self in self.obj_1.connections_out: self.obj_1.connections_out.remove(self) if self.obj_2 and self in self.obj_2.connections_in: self.obj_2.connections_in.remove(self) self.obj_1 = None self.obj_2 = None PatchElement.delete(self)
def make_connection(self): # are both ends selected? if self.reverse and self.source_obj is None and self.window.selected: self.source_obj = self.window.selected[0] if not self.reverse and self.dest_obj is None and self.window.selected: self.dest_obj = self.window.selected[0] if (self.source_obj and self.dest_obj and self.connection.obj_state != PatchElement.OBJ_DELETED): if MFPGUI().mfp.connect(self.source_obj.obj_id, self.source_port, self.dest_obj.obj_id, self.dest_port): c = ConnectionElement(self.window, self.source_obj, self.source_port, self.dest_obj, self.dest_port) MFPGUI().appwin.register(c) self.source_obj.connections_out.append(c) self.dest_obj.connections_in.append(c) else: log.debug("ConnectionMode: Cannot make connection") self.manager.disable_minor_mode(self) return True
def update_value(self, value): if self.min_value is not None and value < self.min_value: value = self.min_value if self.max_value is not None and value > self.max_value: value = self.max_value # called by enumcontrolmode str_rep = self.format_value(value) self.label.set_text(str_rep) self.value = float(str_rep) if self.obj_id is None: self.create_obj() if self.obj_id is not None: MFPGUI().mfp.send(self.obj_id, 0, self.value)
def patch_close(self): def close_confirm(answer): if answer is not None: aa = answer.strip().lower() if aa in ['y', 'yes']: self.window.patch_close() from mfp import log p = self.window.selected_patch log.debug("patch_close: checking for unsaved changes") if MFPGUI().mfp.has_unsaved_changes(p.obj_id): self.window.get_prompted_input( "Patch has unsaved changes. Close anyway? [yN]", close_confirm, '') else: self.window.patch_close()
def set_bounds(self, min_val, max_val): self.max_value = max_val self.min_value = min_val newval = False if self.value > self.max_value: self.value = self.max_value newval = True if self.value < self.min_value: self.value = self.min_value newval = True if newval: MFPGUI().mfp.send(self.obj_id, 0, self.value) self.scale_ticks = None self.update() self.send_params()
def delete(self): self.stage.unregister(self) if self.obj_id is not None and not self.is_export: MFPGUI().mfp.delete(self.obj_id) self.obj_id = None self.obj_state = self.OBJ_DELETED
def clicked(self, *args): self.clickstate = True if self.obj_id is not None: MFPGUI().mfp.send_bang(self.obj_id, 0) self.texture.invalidate() return False
def label_edit_finish(self, *args): ViaElement.label_edit_finish(self, *args) MFPGUI().mfp.send(self.obj_id, 1, self.label.get_text())
def create(self, obj_type, init_args): scopename = self.layer.scope patchname = self.layer.patch.obj_name connections_out = self.connections_out connections_in = self.connections_in self.connections_out = [] self.connections_in = [] # FIXME: optional name-root argument? Need to pass the number at all, # with the scope handling it? if self.obj_name is not None: name = self.obj_name else: name_index = self.stage.object_counts_by_type.get(self.display_type, 0) name = "%s_%03d" % (self.display_type, name_index) if self.obj_id is not None: MFPGUI().mfp.set_gui_created(self.obj_id, False) MFPGUI().mfp.delete(self.obj_id) self.obj_id = None objinfo = MFPGUI().mfp.create(obj_type, init_args, patchname, scopename, name) if self.layer is not None and objinfo: objinfo["layername"] = self.layer.name if objinfo is None: self.stage.hud_write("ERROR: Could not create, see log for details") self.connections_out = connections_out self.connections_in = connections_in return None self.obj_id = objinfo.get('obj_id') self.obj_name = objinfo.get('name') self.obj_args = objinfo.get('initargs') self.obj_type = obj_type self.scope = objinfo.get('scope') self.num_inlets = objinfo.get("num_inlets") self.num_outlets = objinfo.get("num_outlets") self.dsp_inlets = objinfo.get("dsp_inlets", []) self.dsp_outlets = objinfo.get("dsp_outlets", []) if self.obj_id is not None: self.configure(objinfo) # rebuild connections if necessary for c in connections_in: if c.obj_2 is self and c.port_2 >= self.num_inlets: c.obj_2 = None c.delete() else: self.connections_in.append(c) if not c.dashed: MFPGUI().mfp.connect(c.obj_1.obj_id, c.port_1, c.obj_2.obj_id, c.port_2) for c in connections_out: if c.obj_1 is self and c.port_1 >= self.num_outlets: c.obj_1 = None c.delete() else: self.connections_out.append(c) if not c.dashed: MFPGUI().mfp.connect(c.obj_1.obj_id, c.port_1, c.obj_2.obj_id, c.port_2) MFPGUI().remember(self) self.send_params() MFPGUI().mfp.set_gui_created(self.obj_id, True) self.stage.refresh(self) return self.obj_id
def cb(fname): MFPGUI().mfp.open_file(fname)
def cb(plugname): if plugname: MFPGUI().mfp.save_lv2(patch.obj_name, plugname)
def combine_styles(self): styles = {} for styleset in (MFPGUI().style_defaults, PatchElement.style_defaults, type(self).style_defaults, self.style): styles.update(styleset) return styles
def create(self, obj_type, init_args): scopename = self.layer.scope patchname = self.layer.patch.obj_name connections_out = self.connections_out connections_in = self.connections_in self.connections_out = [] self.connections_in = [] # FIXME: optional name-root argument? Need to pass the number at all, # with the scope handling it? if self.obj_name is not None: name = self.obj_name else: name_index = self.stage.object_counts_by_type.get( self.display_type, 0) name = "%s_%03d" % (self.display_type, name_index) if self.obj_id is not None: MFPGUI().mfp.set_gui_created(self.obj_id, False) MFPGUI().mfp.delete(self.obj_id) self.obj_id = None objinfo = MFPGUI().mfp.create(obj_type, init_args, patchname, scopename, name) if self.layer is not None and objinfo: objinfo["layername"] = self.layer.name if objinfo is None: self.stage.hud_write( "ERROR: Could not create, see log for details") self.connections_out = connections_out self.connections_in = connections_in return None self.obj_id = objinfo.get('obj_id') self.obj_name = objinfo.get('name') self.obj_args = objinfo.get('initargs') self.obj_type = obj_type self.scope = objinfo.get('scope') self.num_inlets = objinfo.get("num_inlets") self.num_outlets = objinfo.get("num_outlets") self.dsp_inlets = objinfo.get("dsp_inlets", []) self.dsp_outlets = objinfo.get("dsp_outlets", []) if self.obj_id is not None: self.configure(objinfo) # rebuild connections if necessary for c in connections_in: if c.obj_2 is self and c.port_2 >= self.num_inlets: c.obj_2 = None c.delete() else: self.connections_in.append(c) if not c.dashed: MFPGUI().mfp.connect(c.obj_1.obj_id, c.port_1, c.obj_2.obj_id, c.port_2) for c in connections_out: if c.obj_1 is self and c.port_1 >= self.num_outlets: c.obj_1 = None c.delete() else: self.connections_out.append(c) if not c.dashed: MFPGUI().mfp.connect(c.obj_1.obj_id, c.port_1, c.obj_2.obj_id, c.port_2) MFPGUI().remember(self) self.send_params() MFPGUI().mfp.set_gui_created(self.obj_id, True) self.stage.refresh(self) return self.obj_id
def get_params(self): return MFPGUI().mfp.get_params(self.obj_id)