The WindowView API is a framework for developing custom simulator subwindows using PySide6.
The simulator windows run in a separate process as the robot code, requiring the use of I/O queues for handling live data between the robot code and the simulator.
Info
The WindowView API requires the usage of PySide6.
PySide6 versions not installed as a dependency of KevinbotLib, or other Python Qt bindings are not officially supported, and may not function properly.
fromPySide6.QtCoreimportQSizefromPySide6.QtGuiimportQColor,QIcon,QImage,QPixmapfromPySide6.QtWidgetsimportQLabel,QWidgetfromkevinbotlib.robotimportBaseRobotfromkevinbotlib.simulator.windowviewimportWindowView,register_window_view@register_window_view("test.mywindowview")classMyWindowView(WindowView):def__init__(self):super().__init__()@propertydeftitle(self):return"My Awesome WindowView"# ! optional - define an icon for the WindowView# Icons must be PySide6 QIcon and scalable down to 16x16deficon(self,dark_mode:bool)->QIcon:super().icon(dark_mode)# this seems like a lot, but it just generates a red icon for use in this exampleimage=QImage(QSize(16,16),QImage.Format.Format_RGB888)image.fill(QColor(255,0,0))returnQIcon(QPixmap.fromImage(image))defgenerate(self)->QWidget:returnQLabel("Hello World!")classDemoRobot(BaseRobot):def__init__(self):super().__init__(["Test"],enable_stderr_logger=True,)ifBaseRobot.IS_SIM:self.simulator.add_window("test.mywindowview",MyWindowView)self.telemetry.info(f"Registered WindowViews: {self.simulator.windows}")if__name__=="__main__":DemoRobot().run()
Tip
Each WindowView must have a different registered Window ID (in this case, test.mywindowview).
It is recommended to use reverse domain name notation (e.g., com.example.myproduct.mywindowview).
Do not use Window IDs starting with kevinbotlib or com.meowmeowahr.kevinbotlib