def set_current(self): idx = self.combo.currentIndex() if idx > 0: mx.cur_model(self.combo.modellist[idx]["name"]) self.combo.update_modellist(get_modellist())
def get_modellist(): modellist = [m._baseattrs for m in mx.get_models().values()] cur = mx.cur_model() if cur: modellist.insert(0, mx.cur_model()._baseattrs) else: modellist.insert(0, None) return modellist
def _get_or_create_model(self, model): """ if model is blank, current model is used if exits, otherwise new model is created. """ import modelx as mx if model: return mx.get_models()[model] else: return mx.cur_model() if mx.cur_model() else mx.new_model()
def test_defcells_cur_model_none(): if mx.cur_model(): mx.cur_model().close() assert not mx.cur_model() assert not mx.cur_space() @mx.defcells def foo(): return True assert mx.cur_space().foo is foo
def test_cur_model_change_after_cur_space(curmodel): m1 = curmodel c1 = m1.new_space() m2 = mx.new_model() mx.cur_space(c1) assert mx.cur_model() is m1 assert mx.cur_space() is c1
def get_modeltree(model=None): """Alias to :func:`get_tree`.""" if model is None: model = mx.cur_model() treemodel = ModelTreeModel(model._baseattrs) view = QTreeView() view.setModel(treemodel) view.setWindowTitle("Model %s" % model.name) view.setAlternatingRowColors(True) return view
def get_tree(model=None): """Get QTreeView object containing the model tree. Args: model: :class:`Model <modelx.core.model.Model>` object. Defaults to the current model. """ if model is None: model = mx.cur_model() treemodel = ModelTreeModel(model._baseattrs) view = QTreeView() view.setModel(treemodel) view.setWindowTitle("Model %s" % model.name) view.setAlternatingRowColors(True) return view
def mx_get_modellist(self): """Returns a list of model info. Returns a list of dicts of basic model attributes. The first element of the list is the current model info. None if not current model is set. """ import modelx as mx from modelx.core.base import Interface data = [Interface._baseattrs.fget(m) for m in mx.get_models().values()] if mx.cur_model(): cur = Interface._baseattrs.fget(mx.cur_model()) else: cur = None data.insert(0, cur) if spyder.version_info > (4, ): return data else: self.send_mx_msg("modellist", data=data)
def show_tree(model=None): """Display the model tree window. Args: model: :class:`Model <modelx.core.model.Model>` object. Defaults to the current model. Warnings: For this function to work with Spyder, *Graphics backend* option of Spyder must be set to *inline*. """ if model is None: model = mx.cur_model() view = get_modeltree(model) app = QApplication.instance() if not app: raise RuntimeError("QApplication does not exist.") view.show() app.exec_()
def mx_get_object(self, msgtype, fullname=None, attrs=None): import modelx as mx if fullname is None: obj = mx.cur_model() else: try: obj = mx.get_object(fullname, as_proxy=True) except NameError: obj = None if obj is not None: if attrs is None: data = obj._baseattrs else: data = obj._to_attrdict(attrs) else: data = None self.send_mx_msg(msgtype, data=data)
def curmodel(): m = mx.new_model() assert m is mx.cur_model() return m
def test_cur_model_on_del_model(curmodel): curmodel.close() assert mx.cur_model() is None
def test_cur_model_on_new_model(curmodel): m2 = mx.new_model() assert mx.cur_model() is m2 m = mx.cur_model(curmodel.name) assert m is mx.cur_model() is curmodel
def del_model(self): m = mx.cur_model() if m: m.close() self.combo.update_modellist(get_modellist())