def getMapConcat(dict_obj: 'MutableMapping[str, MutableMapping[str, Any]]',
                 *args: str) -> 'MutableMapping[str, Any]':

    return typingcast(
        'MutableMapping[str, Any]',
        getMapOp(lambda first, second: first.update(second), dict_obj, {},
                 *args))
def getListConcat(dict_obj: 'MutableMapping[str, List[Any]]',
                  *args: str) -> 'List[Any]':

    return typingcast(
        'List[Any]',
        getMapOp(lambda first, second: first.extend(second), dict_obj, [],
                 *args))
    def __loadScenarioShips(self, ships_info: 'List[ShipInfo]',
                            arg_scenario_info: 'Dict[str, Any]') \
                                -> 'Optional[List[ShipInterfaceInfo]]':

        ships: 'List[Optional[ShipInterfaceInfo]]' = [None] * len(ships_info)
        for i, ship_info in enumerate(ships_info):
            try:
                ship = self.__loadShip(ship_info, arg_scenario_info.copy())
            except Exception as err:
                traceback.print_exc()
                self.clear()
                QMessageBox.warning(
                    self, 'Error',
                    (f'An error occurred loading a ship({ship_info.model}): \n'
                     f'{type(err).__name__}: {err}'))
                return None

            if ship is None:
                self.clear()
                return None

            ships[i] = ship

        ships_after = typingcast('List[ShipInterfaceInfo]', ships)

        if self.__ship_to_follow is not None:
            try:
                ship_item = ships_after[self.__ship_to_follow].gitem
            except IndexError:
                pass
            else:
                self.__ui.view.centerOn(ship_item.pos())
                self.__center_view_on = ship_item

        return ships_after
Esempio n. 4
0
        def __getattr__(self, name: str) -> 'Any':

            device = typingcast(DeviceGroup, self._device).accessDevice(name)
            if device is None:
                return super().__getattr__(name)

            return device.mirror
Esempio n. 5
0
        def accessDevice(
                self, index: 'Union[str, int]',
                *args: 'Union[str, int]') -> 'Optional[Device.Mirror]':
            device = typingcast(DeviceGroup,
                                self._device).accessDevice(index, *args)
            if device is None:
                return None

            return device.mirror
Esempio n. 6
0
    def eval(self,
             expr: 'Union[str, ast.Module]',
             parsed_expr: bool = False,
             parsed_expr_original: str = None) -> 'Any':

        if parsed_expr is False:
            self.expr = expr
            expr = self.parse(typingcast(str, expr))
        else:
            if parsed_expr_original is None:
                self.expr = '<<Parsed expression>>'
            else:
                self.expr = parsed_expr_original

        expressions = typingcast('ast.Module', expr).body

        for i in range(len(expressions) - 1):
            self.names['_'] = self._eval(expressions[i])

        return self._eval(expressions[-1])
    def __addDevice(self, info: 'MutableMapping[str, Any]',
                    parts: 'MutableMapping[str, StructuralPart]',
                    device_type: str, **kwargs: 'Any') -> 'Sequence[QWidget]':

        part_name = typingcast(str, info.get('part'))
        part = parts.get(part_name)

        if part is None:
            raise Exception(f"{device_type} has invalid part \'{part_name}\'.")

        return self.__device_loader.load(device_type, info, part, **kwargs)[1]
    def __loadScenarioObjects(self, objects_info: 'List[ObjectInfo]') \
            -> 'Optional[List[Tuple[pymunk.Body, QGraphicsItem]]]':

        objects: 'List[Optional[Tuple[pymunk.Body, QGraphicsItem]]]' = \
            [None]*len(objects_info)

        for i, obj_info in enumerate(objects_info):
            try:
                obj = self.__loadObject(obj_info, FileInfo())
            except Exception as err:
                self.clear()
                QMessageBox.warning(self, 'Error', (
                    f'An error occurred loading an object({obj_info.model}): \n'
                    f'{type(err).__name__}: {err}'))
                return None

            objects[i] = obj

        return typingcast('List[Tuple[pymunk.Body, QGraphicsItem]]', objects)
    def readConfig(self,
                   *args: 'Any',
                   default: 'Any' = None,
                   value_type: 'Callable' = None) -> 'Any':
        current = self.__config_content
        for arg in args:
            if isinstance(current, dict):
                current = typingcast('Dict[str, Any]', current.get(arg))
                if current is None:
                    return default
            else:
                return default

        if value_type is not None:
            try:
                return value_type(current)
            except Exception:
                return default

        return current
Esempio n. 10
0
    def read(self) -> float:

        structure = self.structural_part.structure

        if structure is None:
            return self.__max_dist

        space = structure.space
        body = structure.body

        pos = self.structural_part.position

        collisions = space.point_query(pos, self.__max_dist, ShapeFilter())

        first_collision = next((col for col in collisions
                                if col.shape.body is not body), None)

        if first_collision is None:
            return self.__max_dist

        return typingcast(float, first_collision.distance)
Esempio n. 11
0
    def read(self) -> float:

        structure = self.structural_part.structure

        if structure is None:
            return self.__max_dist

        space = structure.space
        body = structure.body

        pos = self.structural_part.position
        segment_end = Vec2d(self.__max_dist, 0)
        segment_end.angle = self.structural_part.angle + self.__angle

        collisions = space.segment_query(pos, pos + segment_end, 10,
                                         ShapeFilter())

        first_collision = next((col for col in collisions
                                if col.shape.body is not body), None)

        if first_collision is None:
            return self.__max_dist

        return typingcast(float, first_collision.point.get_distance(pos))
Esempio n. 12
0
 def selectedIsLeaf(self) -> bool:
     return typingcast(bool, self.selectedItem().rowCount() == 0)
Esempio n. 13
0
 def _verifyShip(self, ship: 'Structure') -> bool:
     pos = ship.body.position
     return typingcast(
         bool,
         pos.get_dist_sqrd(self.__position) < self.__distance_sqrtd)
Esempio n. 14
0
 def loadUi(self, filename: str) -> 'Tuple[Type, Type]':
     return typingcast(
         'Tuple[Type, Type]',
         uic.loadUiType(self.getPath(self.FileDataType.UIDESIGN, filename)))
 def angle(self) -> float:
     if self.__structure is None:
         return 0
     return typingcast(float, self.__structure.body.angle)