def inspect_module(self, module): """Flush inspect_console, get module class, object attributes and heritage""" module_attributes = None self.inspect_console.flush_console() self.inspect_console.eval_command("import "+module.title) self.inspect_console.eval_command(module.title + " = reload(" + module.title + ")") self.inspect_console.eval_command( "from " + module.title + " import " + module.classname) module.parent_classes = Module.get_parent_classes(module.py_file) self.inspect_console.eval_command("attributes = None") self.inspect_console.eval_command("""attributes = inspect.getmembers({classname}, lambda a:not(inspect.isroutine(a))) """.format(classname=module.classname)) attributes_exist = self.inspect_console.eval_command( """'true' if attributes is not None else 'false'""") if eval(attributes_exist) == 'true': class_attributes = self.inspect_console.eval_command("""[a[0] for a in attributes if not(a[0].startswith('_'))]""") instance_attributes = Module.get_instance_attributes( module.py_file); module_attributes = {'class_attributes': eval(class_attributes), 'instance_attributes': instance_attributes} else: print("Errors in module : " + module.title) return module_attributes
def load_existing_modules(self): for(dirpath, dirnames, filenames) in os.walk(self.workspace): print("load existing modules") for file in filenames: if(file[-2:] == "py"): abs_path = os.path.abspath(os.path.join(dirpath, file)) first_classname = Module.get_first_classname(abs_path) if first_classname is not None: new_module = Module(self.workspace, title=file, main_class=first_classname) self.add_module(new_module, alert_collision=False) else: print("Can't found class in file " + file) break self.load_edges() self.load_existing_placement() self.redraw()
def new_module_action(self): new_module_dialog = TextDialog(self.window, "Choose new class name", "Class name", optional_field_name="Parent class", opt_placeholder="<module.Class>") self.window.wait_window(new_module_dialog.dialog) if new_module_dialog.field_value is not None: new_module = Module(self.window.workspace, main_class=new_module_dialog.field_value) opt_value = new_module_dialog.opt_field_value if opt_value is not None and opt_value != "" and re.search("\.", opt_value) is not None and re.search("\<", opt_value) is None: parent_info = new_module_dialog.opt_field_value.replace(" ", "").split(".") new_module.parent_classes.append(parent_info[1]) new_module.imports = parent_info new_module.create_python_module() new_module.init_file_module() self.schema_module.add_module(new_module) self.schema_module.refresh()