示例#1
0
 def ask_add_storage(self, expr: str) -> bool:
     try:
         # Put the expression into parser to see if it is legal
         parse_params(expr)
     except Exception as error:
         logger.warn(error)
         QMessageBox.warning(
             self,
             "Loading failed",
             "Your expression is in an incorrect format."
         )
         return False
     name, ok = QInputDialog.getText(
         self,
         "Storage",
         "Please input name tag:"
     )
     if not ok:
         return False
     name_list = [
         self.mechanism_storage.item(i).text()
         for i in range(self.mechanism_storage.count())
     ]
     i = 0
     name = name or f"Prototype_{i}"
     while name in name_list:
         name = f"Prototype_{i}"
         i += 1
     self.__add_storage(name, expr)
     return True
示例#2
0
 def parse_expression(self, expr: str) -> None:
     """Parse expression."""
     try:
         args_list = parse_params(expr)
     except LarkError:
         QMessageBox.warning(
             self,
             "Loading failed",
             f"Your expression is in an incorrect format."
         )
     else:
         for args in args_list:
             links = args.links.split(',')
             link_names = {vlink.name for vlink in self.vlink_list}
             for link_name in links:
                 # If link name not exist
                 if link_name not in link_names:
                     self.add_link(link_name, 'Blue')
             row_count = self.entities_point.rowCount()
             self.command_stack.beginMacro(f"Add {{Point{row_count}}}")
             self.command_stack.push(AddTable(
                 self.vpoint_list,
                 self.entities_point
             ))
             self.command_stack.push(EditPointTable(
                 row_count,
                 self.vpoint_list,
                 self.vlink_list,
                 self.entities_point,
                 self.entities_link,
                 args
             ))
             self.command_stack.endMacro()