Skip to content

Commit

Permalink
Merge pull request #23 from Gold-Rush-Robotics/testGui
Browse files Browse the repository at this point in the history
Test gui
  • Loading branch information
c4glenn authored Mar 20, 2024
2 parents 7a657db + 0d33a32 commit cad52c9
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
89 changes: 74 additions & 15 deletions src/grr_guis/grr_guis/main_gui.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from PyQt5.QtCore import Qt, QEventLoop
from PyQt5.QtCore import Qt, QEventLoop, QUrl
import rclpy
from rclpy.node import Node
from ament_index_python.packages import get_package_share_directory
import PyQt5
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QLabel, QMainWindow, QHBoxLayout, QListWidget, QListWidgetItem
from PyQt5.QtWidgets import QSizePolicy, QApplication, QWidget, QPushButton, QVBoxLayout, QLabel, QMainWindow, QHBoxLayout, QListWidget, QListWidgetItem, QFileDialog
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
import sys
from std_msgs.msg import Bool, String
from PyQt5.QtGui import QPixmap


from std_msgs.msg import Bool, String

class GRR_Window(QMainWindow):
def __init__(self) -> None:
Expand All @@ -13,26 +19,74 @@ def __init__(self) -> None:
self.setWindowTitle("GRR SECON APP")
self.button = QPushButton("Ready to start? No ")
self.button.setCheckable(True)



self.label = QLabel()


#media player instance None, QMediaPlayer.VideoSurface
self.player = QMediaPlayer(None, QMediaPlayer.VideoSurface)

horiz_layout = QHBoxLayout()


self.videoWidget = QVideoWidget()
self.videoWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)



self.node_list = QListWidget()

main_pane = QVBoxLayout()
main_pane.addWidget(self.label)
main_pane.addWidget(self.button)

horiz_layout.addLayout(main_pane)
horiz_layout.addWidget(self.node_list)
self.main_pane = QVBoxLayout()
self.main_pane.addWidget(self.label)
self.main_pane.addWidget(self.button)

# self.main_pane.addWidget(self.videoWidget)

self.loadVideoButton = QPushButton('Load and Play Video')
self.main_pane.addWidget(self.loadVideoButton)


horiz_layout.addLayout(self.main_pane)
horiz_layout.addWidget(self.node_list)
horiz_layout.addWidget(self.videoWidget)

container = QWidget()
container.setLayout(horiz_layout)
self.player.setVideoOutput(self.videoWidget)
#self.setCentralWidget(videoWidget)


self.loadVideoButton.clicked.connect(self.promoVid2)

# Connect the error signal to a slot
#self.player.error.connect(self.handleError)

self.setCentralWidget(container)
self.showMaximized()
self.show()

def promoVid(self,main_pane):
pixmap = QPixmap('Logo_MainGreenBorder.png')
self.label.setPixmap(pixmap)
self.resize(pixmap.width(), pixmap.height())
self.main_pane.addWidget(self.label)

# Define a method to handle errors
def handleError(self, error):
print("Error:", error)

def promoVid2(self):
# fileName,_ = QFileDialog.getOpenFileName(self, ".","Images (*.mp4) (*.avi) (*.png)")
fileName = get_package_share_directory('grr_guis') + '/multimedia/grr_logo.mp4'
print(fileName)
# if fileName != '':
content = QUrl.fromLocalFile(fileName)
print(content)
self.player.setMedia(QMediaContent(content))
self.player.play()


class Gui(Node):
def __init__(self, application:QApplication, window:GRR_Window) -> None:
super().__init__("GUI")
Expand All @@ -50,6 +104,10 @@ def bind(self):
def send_start(self, checked):
self.window.button.setText(f"Ready to Start? {'Yes' if checked else 'No '}")
self.start_button_pub.publish(Bool(data=checked))

def run_video(self, msg:Bool):
if msg.data:
self.window.promoVid2()

def display_test(self, msg:String):
print(msg)
Expand All @@ -63,17 +121,18 @@ def gui_loop(self):
self.window.node_list.addItems(nodes)
self.previous_nodes = nodes





def main():
# create application instance
app = QApplication([])
#instance of widget
window = GRR_Window()
rclpy.init()
gui = Gui(app, window)
rclpy.spin(gui)






if __name__ == "__main__":
main()
Binary file added src/grr_guis/multimedia/Logo_MainGreenBorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/grr_guis/multimedia/grr_logo.mp4
Binary file not shown.
3 changes: 3 additions & 0 deletions src/grr_guis/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from setuptools import find_packages, setup
import os
from glob import glob

package_name = 'grr_guis'

Expand All @@ -10,6 +12,7 @@
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name, 'multimedia'), glob('multimedia/*')),
],
install_requires=['setuptools'],
zip_safe=True,
Expand Down
2 changes: 2 additions & 0 deletions src/grr_python_controllers/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from setuptools import setup
import os
from glob import glob

package_name = 'grr_python_controllers'

Expand Down

0 comments on commit cad52c9

Please sign in to comment.