소스 검색

Added mission text box to human render window

Maxime Chevalier-Boisvert 7 년 전
부모
커밋
52eef49451
2개의 변경된 파일20개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 0
      gym_minigrid/minigrid.py
  2. 17 3
      gym_minigrid/rendering.py

+ 3 - 0
gym_minigrid/minigrid.py

@@ -1321,6 +1321,9 @@ class MiniGridEnv(gym.Env):
 
 
         r = self.grid_render
         r = self.grid_render
 
 
+        if r.window:
+            r.window.setText(self.mission)
+
         r.beginFrame()
         r.beginFrame()
 
 
         # Render the whole grid
         # Render the whole grid

+ 17 - 3
gym_minigrid/rendering.py

@@ -2,7 +2,7 @@ import numpy as np
 from PyQt5.QtCore import Qt
 from PyQt5.QtCore import Qt
 from PyQt5.QtGui import QImage, QPixmap, QPainter, QColor, QPolygon
 from PyQt5.QtGui import QImage, QPixmap, QPainter, QColor, QPolygon
 from PyQt5.QtCore import QPoint, QSize, QRect
 from PyQt5.QtCore import QPoint, QSize, QRect
-from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
+from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QTextEdit
 from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QLabel, QFrame
 from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QLabel, QFrame
 
 
 class Window(QMainWindow):
 class Window(QMainWindow):
@@ -15,19 +15,30 @@ class Window(QMainWindow):
 
 
         self.setWindowTitle('MiniGrid Gym Environment')
         self.setWindowTitle('MiniGrid Gym Environment')
 
 
+        # Image label to display the rendering
         self.imgLabel = QLabel()
         self.imgLabel = QLabel()
         self.imgLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
         self.imgLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
 
 
-        # Arrange widgets horizontally
+        # Text box for the mission
+        self.missionBox = QTextEdit()
+        self.missionBox.setReadOnly(True)
+        self.missionBox.setMinimumSize(400, 100)
+
+        # Center the image
         hbox = QHBoxLayout()
         hbox = QHBoxLayout()
         hbox.addStretch(1)
         hbox.addStretch(1)
         hbox.addWidget(self.imgLabel)
         hbox.addWidget(self.imgLabel)
         hbox.addStretch(1)
         hbox.addStretch(1)
 
 
+        # Arrange widgets vertically
+        vbox = QVBoxLayout()
+        vbox.addLayout(hbox)
+        vbox.addWidget(self.missionBox)
+
         # Create a main widget for the window
         # Create a main widget for the window
         mainWidget = QWidget(self)
         mainWidget = QWidget(self)
         self.setCentralWidget(mainWidget)
         self.setCentralWidget(mainWidget)
-        mainWidget.setLayout(hbox)
+        mainWidget.setLayout(vbox)
 
 
         # Show the application window
         # Show the application window
         self.show()
         self.show()
@@ -44,6 +55,9 @@ class Window(QMainWindow):
     def setPixmap(self, pixmap):
     def setPixmap(self, pixmap):
         self.imgLabel.setPixmap(pixmap)
         self.imgLabel.setPixmap(pixmap)
 
 
+    def setText(self, text):
+        self.missionBox.setPlainText(text)
+
     def setKeyDownCb(self, callback):
     def setKeyDownCb(self, callback):
         self.keyDownCb = callback
         self.keyDownCb = callback