def __init__(self, parent=None): QWidget.__init__(self) self.setWindowTitle('XXOO') vbox = QVBoxLayout() self.wv = QMacCocoaViewContainer(0) vbox.addWidget(self.wv) self.setLayout(vbox) self.resize(350, 250)
def initUI(self): self.setWindowTitle(self.title) self.widget = QWidget(self) self.setCentralWidget(self.widget) self.videoframe = QMacCocoaViewContainer(0) self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.widget.setLayout(self.vboxlayout) self.player.set_nsobject(int(self.videoframe.winId())) self.play()
def createUI(self): """Set up the user interface, signals & slots """ self.widget = QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor (QPalette.Window, QColor(0,0,0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.positionslider = QSlider(Qt.Horizontal, self) self.positionslider.setToolTip("Position") self.positionslider.setMaximum(1000) self.positionslider.sliderMoved.connect(self.setPosition) self.hbuttonbox = QHBoxLayout() self.playbutton = QPushButton("Play") self.hbuttonbox.addWidget(self.playbutton) self.playbutton.clicked.connect(self.PlayPause) self.stopbutton = QPushButton("Stop") self.hbuttonbox.addWidget(self.stopbutton) self.stopbutton.clicked.connect(self.Stop) self.hbuttonbox.addStretch(1) self.volumeslider = QSlider(Qt.Horizontal, self) self.volumeslider.setMaximum(100) self.volumeslider.setValue(self.mediaplayer.audio_get_volume()) self.volumeslider.setToolTip("Volume") self.hbuttonbox.addWidget(self.volumeslider) self.volumeslider.valueChanged.connect(self.setVolume) self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.vboxlayout.addWidget(self.positionslider) self.vboxlayout.addLayout(self.hbuttonbox) self.widget.setLayout(self.vboxlayout) open = QAction("&Open", self) open.triggered.connect(self.OpenFile) exit = QAction("&Exit", self) exit.triggered.connect(sys.exit) menubar = self.menuBar() filemenu = menubar.addMenu("&File") filemenu.addAction(open) filemenu.addSeparator() filemenu.addAction(exit) self.timer = QTimer(self) self.timer.setInterval(200) self.timer.timeout.connect(self.updateUI)
def setupUi(self, Form): Form.setObjectName("Form") Form.resize(500, 360) self.button_play = QtWidgets.QPushButton(Form) self.button_play.setGeometry(QtCore.QRect(9, 290, 40, 40)) self.button_play.setText("") icon = QtGui.QIcon.fromTheme("SP_MediaPlay") self.button_play.setIcon(icon) self.button_play.setObjectName("button_play") self.button_play.setIcon(self.style().standardIcon( QStyle.SP_MediaPlay)) self.video = None if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.video = QMacCocoaViewContainer(0, parent=Form) else: self.video = QtWidgets.QFrame(parent=Form) self.video.setGeometry(QtCore.QRect(9, 0, 500, 280)) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.video.sizePolicy().hasHeightForWidth()) self.video.setSizePolicy(sizePolicy) self.video.setObjectName("video") self.button_pause = QtWidgets.QPushButton(Form) self.button_pause.setGeometry(QtCore.QRect(54, 290, 40, 40)) self.button_pause.setText("") self.button_pause.setObjectName("button_pause") self.button_pause.setIcon(self.style().standardIcon( QStyle.SP_MediaPause)) self.time_slider = QtWidgets.QSlider(Form) self.time_slider.setGeometry(QtCore.QRect(140, 300, 301, 22)) self.time_slider.setOrientation(QtCore.Qt.Horizontal) self.time_slider.setObjectName("time_slider") self.label_time_passed = QtWidgets.QLabel(Form) self.label_time_passed.setGeometry(QtCore.QRect(100, 300, 61, 20)) self.label_time_passed.setObjectName("label_time_passed") self.label_time_left = QtWidgets.QLabel(Form) self.label_time_left.setGeometry(QtCore.QRect(450, 300, 60, 16)) self.label_time_left.setObjectName("label_time_left") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def createUI(self): """ Set up the window for the VLC viewer """ self.widget = QWidget(self) self.setCentralWidget(self.widget) self.test = QWidget(self) self.setMenuWidget(self.test) # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.hbuttonbox = QHBoxLayout() self.playbutton = QPushButton("Run my program") #self.hbuttonbox.addWidget(self.playbutton) #self.playbutton.clicked.connect(partial(self.drone_vision.run_user_code, self.playbutton)) self.landbutton = QPushButton("Land NOW") self.hbuttonbox.addWidget(self.landbutton) self.landbutton.clicked.connect(self.drone_vision.land) self.takeoff = QPushButton("Take off") self.hbuttonbox.addWidget(self.takeoff) self.takeoff.clicked.connect(self.drone_vision.safe_takeoff) self.stopbutton = QPushButton("Quit") self.hbuttonbox.addWidget(self.stopbutton) self.stopbutton.clicked.connect(self.drone_vision.close_exit) self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.vboxlayout.addLayout(self.hbuttonbox) self.widget.setLayout(self.vboxlayout) # the media player has to be 'connected' to the QFrame # (otherwise a video would be displayed in it's own window) # this is platform specific! # you have to give the id of the QFrame (or similar object) to # vlc, different platforms have different functions for this if sys.platform.startswith('linux'): # for Linux using the X Server self.mediaplayer.set_xwindow(self.videoframe.winId()) elif sys.platform == "win32": # for Windows self.mediaplayer.set_hwnd(self.videoframe.winId()) elif sys.platform == "darwin": # for MacOS self.mediaplayer.set_nsobject(int(self.videoframe.winId()))
class Finestra(QMainWindow): def __init__(self, master=None): QMainWindow.__init__(self, master) self.title = 'Video' self.width = 640 self.height = 480 vlcInstance = vlc.Instance() self.player = vlcInstance.media_player_new() media = vlcInstance.media_new_path(path) self.player.set_media(media) self.initUI() def initUI(self): self.setWindowTitle(self.title) self.widget = QWidget(self) self.setCentralWidget(self.widget) self.videoframe = QMacCocoaViewContainer(0) self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.widget.setLayout(self.vboxlayout) self.player.set_nsobject(int(self.videoframe.winId())) self.play() def play(self): self.resize(self.width, self.height) self.show() self.player.play()
class SigSlot(QWidget): def __init__(self, parent=None): QWidget.__init__(self) self.setWindowTitle('XXOO') vbox = QVBoxLayout() self.wv = QMacCocoaViewContainer(0) vbox.addWidget(self.wv) self.setLayout(vbox) self.resize(350, 250) def bind(self, player): player.set_nsobject(int(self.wv.winId()))
def set_media_player(self, *args): """ 获得并设置媒体播放器 :param args: :return: """ if args: self.instance = vlc.Instance(*args) self.media_player = self.instance.media_player_new() else: self.media_player = vlc.MediaPlayer() if get_system_platform() == CommonEnum.WindowsPlatform: self.media_player_frame = QFrame() self.media_player.set_hwnd(self.media_player_frame.winId()) elif get_system_platform() == CommonEnum.LinuxPlatform: self.media_player_frame = QFrame() self.media_player.set_xwindow(self.media_player_frame.winId()) elif get_system_platform() == CommonEnum.DarwinPlatform: from PyQt5.QtWidgets import QMacCocoaViewContainer self.media_player_frame = QMacCocoaViewContainer(0) self.media_player.set_nsobject(self.media_player_frame.winId()) else: self.media_player.set_hwnd(self.media_player_frame.winId())
def setUpGUI(self): self.resize(800, 480) self.widget = QWidget(self) self.setCentralWidget(self.widget) if sys.platform == "darwin": from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.videoframe.mouseDoubleClickEvent = self.openDialog self.videoframe.mouseReleaseEvent = self.PlayPause self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.videoframe self.positionSlider = QSlider(Qt.Horizontal, self) self.positionSlider.setMaximum(1000) self.positionSlider.sliderMoved.connect(self.setPosition) self.hboxLayout = QHBoxLayout() self.hboxLayout.addWidget(self.positionSlider) self.hboxLayout.setSpacing(0) self.hboxLayout.setContentsMargins(0, 0, 0, 0) self.vboxLayout = QVBoxLayout() self.vboxLayout.addWidget(self.videoframe) self.vboxLayout.addLayout(self.hboxLayout) self.vboxLayout.setSpacing(0) self.vboxLayout.setContentsMargins(0, 0, 0, 0) self.widget.setLayout(self.vboxLayout) _open = QAction("&Open", self) _open.triggered.connect(sys.exit) try: _thread.start_new_thread(self.updateUI, ()) except: print("error with positionSliderThread")
def buildVideoPlayer(self): # creating a basic vlc instance self.instance = vlc.Instance() # creating an empty vlc media player self.mediaplayer = self.instance.media_player_new() # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor (QPalette.Window, QColor(0,0,0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.timer = QTimer(self) self.timer.setInterval(50) self.timer.timeout.connect(self.updateUI) return self.videoframe
def __init__(self, *args): super(VlcPlayerWidget, self).__init__() self.media_player_frame = QFrame() self.media_player = None self.instance = None self.set_media_player(args) self.widget = QWidget(self) self.setCentralWidget(self.widget) self.palette = self.media_player_frame.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.media_player_frame.setPalette(self.palette) self.media_player_frame.setAutoFillBackground(True) self.main_layout = QVBoxLayout() self.main_layout.setContentsMargins(0, 0, 0, 0) self.main_layout.setSpacing(0) self.current_url = None self.current_url_type = None self._init_ui() self.init_cfg()
def createUI(self): """Set up the user interface, signals & slots """ self.widget = QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.videoframe.setMinimumWidth(720) self.videoframe.setMinimumHeight(480) #self.hbuttonbox = QHBoxLayout() #self.openchannel = QPushButton("Open Channel Data") #self.hbuttonbox.addWidget(self.openchannel) #self.openchannel.clicked.connect(self.PlayPause) self.hcontrolbox = QHBoxLayout() self.hinfobox = QHBoxLayout() self.icon = QLabel() self.icon.setFixedSize(200, 60) self.icon.setAlignment(Qt.AlignCenter) self.hinfobox.addWidget(self.icon) self.vinfobox = QVBoxLayout() self.ch_name = QLabel("Loading...") font = QFont() font.setBold(True) font.setFamily('Malgun Gothic') font.setPointSize(16) self.ch_name.setFont(font) self.vinfobox.addWidget(self.ch_name) self.hservicebox = QHBoxLayout() self.hservicebox.addWidget(QLabel('Service ID ')) self.service_id = QLabel("[#]") self.hservicebox.addWidget(self.service_id) self.vinfobox.addLayout(self.hservicebox) self.hinfobox.addLayout(self.vinfobox) self.hcontrolbox.addLayout(self.hinfobox) self.hcontrolbox.addStretch(1) self.volumeslider = QSlider(Qt.Horizontal, self) self.volumeslider.setMaximum(100) self.volumeslider.setValue(self.mediaplayer.audio_get_volume()) self.volumeslider.setToolTip("Volume") self.hcontrolbox.addWidget(self.volumeslider) self.volumeslider.valueChanged.connect(self.setVolume) # self.channelbox = QVBoxLayout() self.channellist = QListWidget() self.channellist.setFixedWidth(320) self.channellist.itemClicked.connect(self.selectChannel) self.channelbox.addWidget(self.channellist) self.channelfilter = QLineEdit() self.channelfilter.setFixedWidth(320) self.channelfilter.textChanged.connect(self.find_channel) self.channelbox.addWidget(self.channelfilter) self.streambox = QVBoxLayout() self.streamlist = QListWidget() self.streamlist.setFixedWidth(320) self.streamlist.itemClicked.connect(self.selectStream) self.streambox.addWidget(self.streamlist) self.mapbutton = QPushButton("Map") self.mapbutton.clicked.connect(self.map) self.streambox.addWidget(self.mapbutton) self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.vboxlayout.addLayout(self.hcontrolbox) self.hboxlayout = QHBoxLayout() self.hboxlayout.addLayout(self.vboxlayout) self.hboxlayout.addLayout(self.channelbox) self.hboxlayout.addLayout(self.streambox) self.widget.setLayout(self.hboxlayout) export = QAction("&Export", self) export.triggered.connect(self.ExportFile) exit = QAction("E&xit", self) exit.triggered.connect(sys.exit) menubar = self.menuBar() filemenu = menubar.addMenu("&File") filemenu.addAction(export) filemenu.addSeparator() filemenu.addAction(exit) self.updatePlaylist()
def createUI(self): """ Set up the window for the VLC viewer """ self.widget = QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.hbuttonbox = QHBoxLayout() self.raise_lower_box = QHBoxLayout() self.forward_box = QHBoxLayout() self.left_right_box = QHBoxLayout() self.backward_box = QHBoxLayout() self.toggle_box = QHBoxLayout() self.playbutton = QPushButton("Start") self.hbuttonbox.addWidget(self.playbutton) self.playbutton.clicked.connect(partial(self.move.restart)) self.landbutton = QPushButton("Land NOW") self.hbuttonbox.addWidget(self.landbutton) self.landbutton.clicked.connect(self.drone_vision.land) self.landsafebutton = QPushButton("Land safe") self.hbuttonbox.addWidget(self.landsafebutton) self.landsafebutton.clicked.connect(self.move.kill) self.stopbutton = QPushButton("Quit") self.hbuttonbox.addWidget(self.stopbutton) self.stopbutton.clicked.connect(self.drone_vision.close_exit) self.raise_button = QPushButton("Raise Drone") self.raise_lower_box.addWidget(self.raise_button) self.raise_button.clicked.connect(self.move.raise_drone) self.lower_button = QPushButton("Lower Drone") self.raise_lower_box.addWidget(self.lower_button) self.lower_button.clicked.connect(self.move.lower_drone) self.forward_button = QPushButton("^") self.forward_box.addWidget(self.forward_button) self.forward_button.clicked.connect(self.move.drone_forward) self.left_button = QPushButton("<") self.hover_button = QPushButton("o") self.right_button = QPushButton(">") self.left_right_box.addWidget(self.left_button) self.left_right_box.addWidget(self.hover_button) self.left_right_box.addWidget(self.right_button) self.left_button.clicked.connect(self.move.drone_left) self.hover_button.clicked.connect(self.move.drone_hover) self.right_button.clicked.connect(self.move.drone_right) self.backward_button = QPushButton("v") self.backward_box.addWidget(self.backward_button) self.backward_button.clicked.connect(self.move.drone_right) self.rotation_button = QPushButton("Rotation Track") self.toggle_box.addWidget(self.rotation_button) self.rotation_button.clicked.connect(self.move.rotate_true) self.fixed_button = QPushButton("Fixed Track") self.toggle_box.addWidget(self.fixed_button) self.fixed_button.clicked.connect(self.move.rotate_false) self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.vboxlayout.addLayout(self.hbuttonbox) self.vboxlayout.addLayout(self.raise_lower_box) self.vboxlayout.addLayout(self.forward_box) self.vboxlayout.addLayout(self.left_right_box) self.vboxlayout.addLayout(self.backward_box) self.vboxlayout.addLayout(self.toggle_box) # determined how far away from the tracked object the drone should be sld = QSlider(Qt.Horizontal, self) sld.setFocusPolicy(Qt.NoFocus) sld.setGeometry(30, 40, 100, 30) sld.setValue(60) sld.valueChanged[int].connect(self.change_box_size_max) sld1 = QSlider(Qt.Horizontal, self) sld1.setFocusPolicy(Qt.NoFocus) sld1.setGeometry(30, 40, 100, 30) sld1.setValue(40) sld1.valueChanged[int].connect(self.change_box_size_min) sld1.move(30, 60) # shows how much the drone 'wants' to rotate to the left/right # (this corresponds to where on the x-axis the tracked object is) # self.yaw_bar = QProgressBar(self) # self.yaw_bar.setGeometry(30, 40, 200, 25) # self.yaw_bar.move(0, 100) # # # shows how much the drone 'wants' to go forwards/backwards # # (corresponds to how far away the tracked object is) # self.pitch_bar = QProgressBar(self) # self.pitch_bar.setGeometry(30, 40, 200, 25) # self.pitch_bar.move(0, 200) # self.pitch_bar.setValue(60) self.label = QLabel(self) self.setGeometry(300, 300, 280, 170) self.setWindowTitle('QSlider') self.show() self.widget.setLayout(self.vboxlayout) # the media player has to be 'connected' to the QFrame # (otherwise a video would be displayed in it's own window) # this is platform specific! # you have to give the id of the QFrame (or similar object) to # vlc, different platforms have different functions for this if sys.platform.startswith('linux'): # for Linux using the X Server self.mediaplayer.set_xwindow(self.videoframe.winId()) elif sys.platform == "win32": # for Windows self.mediaplayer.set_hwnd(self.videoframe.winId()) elif sys.platform == "darwin": # for MacOS self.mediaplayer.set_nsobject(int(self.videoframe.winId()))
def createUI(self): """Set up the user interface, signals & slots """ self.widget = QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.positionslider = QSlider(Qt.Horizontal, self) self.positionslider.setToolTip("Position") self.positionslider.setMaximum(1000) self.positionslider.sliderMoved.connect(self.setPosition) self.hbuttonbox = QHBoxLayout() self.playbutton = QPushButton("►") self.hbuttonbox.addWidget(self.playbutton) self.playbutton.clicked.connect(self.PlayPause) self.stopbutton = QPushButton("⯀") self.hbuttonbox.addWidget(self.stopbutton) self.stopbutton.clicked.connect(self.Stop) self.audiobutton = QPushButton("𝅘𝅥") self.hbuttonbox.addWidget(self.audiobutton) self.audiobutton.setToolTip( "Switch to audio only mode\n(must search again)") self.audiobutton.clicked.connect(self.AudioVideo) self.hbuttonbox.addStretch(1) self.volumeslider = QSlider(Qt.Horizontal, self) self.volumeslider.setMaximum(100) self.volumeslider.setValue(self.mediaplayer.audio_get_volume()) self.volumeslider.setToolTip("Volume") self.hbuttonbox.addWidget(self.volumeslider) self.volumeslider.valueChanged.connect(self.setVolume) self.hbuttonbox2 = QHBoxLayout() self.searchline = QLineEdit() self.hbuttonbox2.addWidget(self.searchline) self.searchline.setToolTip("Enter search term here") self.searchbutton = QPushButton("Search") self.hbuttonbox2.addWidget(self.searchbutton) self.searchbutton.setToolTip("Press to search") self.searchbutton.clicked.connect(self.searchYouTube) self.searchresult = QHBoxLayout() #adding QListWidget to the layout causes the video frame #to disappear and im not sure why #self.searchresults = QListWidget(self) #self.searchresult.addWidget(self.searchresults) #self.searchresults.addItem("testing1") #self.searchresults.addItem("testing2") self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) self.vboxlayout.addWidget(self.positionslider) self.vboxlayout.addLayout(self.hbuttonbox) self.vboxlayout.addLayout(self.hbuttonbox2) #self.vboxlayout.addLayout(self.searchresult) self.widget.setLayout(self.vboxlayout) open = QAction("&Open", self) open.triggered.connect(lambda: self.OpenFile()) exit = QAction("&Exit", self) exit.triggered.connect(sys.exit) download = QAction("&Download", self) download.triggered.connect(self.downloadFile) menubar = self.menuBar() filemenu = menubar.addMenu("&File") filemenu.addAction(open) filemenu.addSeparator() filemenu.addAction(exit) filemenu.addSeparator() filemenu.addAction(download) self.timer = QTimer(self) self.timer.setInterval(200) self.timer.timeout.connect(self.updateUI)
def createUI(self): """Set up the user interface, signals & slots """ self.widget = QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.label = QtWidgets.QLabel(self.videoframe) #self.label.setGeometry(QtCore.QRect(0, 0, 1024, 631)) self.label.setText("") self.label.setScaledContents(True) self.label.setObjectName("label") # self.positionslider = QSlider(Qt.Horizontal, self) # self.positionslider.setToolTip("Position") # self.positionslider.setMaximum(1000) # self.positionslider.sliderMoved.connect(self.setPosition) # # self.hbuttonbox = QHBoxLayout() # self.playbutton = QPushButton("Play") # self.hbuttonbox.addWidget(self.playbutton) # self.playbutton.clicked.connect(self.PlayPause) # # self.stopbutton = QPushButton("Stop") # self.hbuttonbox.addWidget(self.stopbutton) # self.stopbutton.clicked.connect(self.Stop) # # self.hbuttonbox.addStretch(1) # self.volumeslider = QSlider(Qt.Horizontal, self) # self.volumeslider.setMaximum(100) # self.volumeslider.setValue(self.mediaplayer.audio_get_volume()) # self.volumeslider.setToolTip("Volume") # self.hbuttonbox.addWidget(self.volumeslider) # self.volumeslider.valueChanged.connect(self.setVolume) self.vboxlayout = QVBoxLayout() self.vboxlayout.setContentsMargins(0, 0, 0, 0) self.videoframe.setStyleSheet( "background: black; border: 0px; padding: 0px;") self.vboxlayout.addWidget(self.videoframe) # self.vboxlayout.addWidget(self.positionslider) # self.vboxlayout.addLayout(self.hbuttonbox) self.widget.setLayout(self.vboxlayout) # open = QAction("&Open", self) # open.triggered.connect(self.OpenFile) # exit = QAction("&Exit", self) # exit.triggered.connect(sys.exit) # menubar = self.menuBar() # filemenu = menubar.addMenu("&File") # #filemenu.addAction(open) # filemenu.addSeparator() # filemenu.addAction(exit) self.timer = QTimer(self) self.timer.setInterval(200) self.timer.timeout.connect(self.updateUI)
def create_reader(self): # code from github.com/devos50/vlc-pyqt5-example.git # Video UI if sys.platform == "darwin": from PyQt5.QtWidgets import QMacCocoaViewContainer self.__video_reader = QMacCocoaViewContainer(0) else: self.__video_reader = QFrame(self) self.__palette = self.__video_reader.palette() self.__palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.__video_reader.setPalette(self.__palette) self.__video_reader.setAutoFillBackground(True) self.__gr_video_reader = GraphicalObject(self.__video_reader, width=80, height=80, pos_x=10, pos_y=10, parent=self.__body) self.__videotitle = QLabel("No Video!", self) self.__videotitle.setWordWrap(True) self.__gr_videotitle = GraphicalObject(self.__videotitle, width=80, height=10, pos_x=10, pos_y=90, parent=self.__body) number_of_button = 3 btn_height = 7 btn_width = 7 ui_origin_x = 0 ui_origin_y = 100 - btn_height self.__buttonbar_video = QLabel(self) self.__buttonbar_video.setStyleSheet( "QLabel { background-color : white; color : blue; }") self.__gr_buttonbar_video = GraphicalObject( self.__buttonbar_video, width=100, height=btn_height, pos_x=0, pos_y=ui_origin_y, parent=self.__gr_video_reader) self.__previousbtn_video = TranslucidButton(self) self.__previousbtn_image = QPixmap('resources/back.svg') self.__previousbtn_video.setScaledContents(True) self.__previousbtn_video.setPixmap(self.__previousbtn_image) self.__gr_previousbtn_video = GraphicalObject( self.__previousbtn_video, width=btn_width, height=btn_height, pos_x=ui_origin_x + 0 * btn_width, pos_y=ui_origin_y, parent=self.__gr_video_reader) self.__skipbtn_video = TranslucidButton(self) self.__skipbtn_image = QPixmap('resources/skip.svg') self.__skipbtn_video.setScaledContents(True) self.__skipbtn_video.setPixmap(self.__skipbtn_image) self.__gr_skipbtn_video = GraphicalObject( self.__skipbtn_video, width=btn_width, height=btn_height, pos_x=ui_origin_x + 2 * btn_width, pos_y=ui_origin_y, parent=self.__gr_video_reader) self.__playbtn_video = TranslucidButton(self) self.__playbtn_video.clicked.connect(self.video_play_pause) self.__playbtn_image = QPixmap('resources/play.svg') self.__playbtn_video.setScaledContents(True) self.__playbtn_video.setPixmap(self.__playbtn_image) self.__gr_playbtn_video = GraphicalObject( self.__playbtn_video, width=btn_width, height=btn_height, pos_x=ui_origin_x + 1 * btn_width, pos_y=ui_origin_y, parent=self.__gr_video_reader) # Audio UI number_of_button = 3 btn_height = 5 btn_width = 10 ui_origin_x = 30 ui_origin_y = 50 - (btn_height / 2) self.__previousbtn_audio = QPushButton('Previous', self) #clicked.connect(self.handle_research) self.__gr_previousbtn_audio = GraphicalObject( self.__previousbtn_audio, width=btn_width, height=btn_height, pos_x=ui_origin_x + (0 * (100 - 2 * ui_origin_x)) / number_of_button, pos_y=ui_origin_y, parent=self.__body) self.__playbtn_audio = QPushButton('Play', self) self.__playbtn_audio.clicked.connect(self.audio_play_pause) self.__gr_playbtn_audio = GraphicalObject( self.__playbtn_audio, width=btn_width, height=btn_height, pos_x=ui_origin_x + (1 * (100 - 2 * ui_origin_x)) / number_of_button, pos_y=ui_origin_y, parent=self.__body) self.__skipbtn_audio = QPushButton('Skip', self) self.__skipbtn_audio.clicked.connect(self.__video_player.skip) self.__gr_skipbtn_audio = GraphicalObject( self.__skipbtn_audio, width=btn_width, height=btn_height, pos_x=ui_origin_x + (2 * (100 - 2 * ui_origin_x)) / number_of_button, pos_y=ui_origin_y, parent=self.__body)
class VlcPlayerWidget(QMainWindow): """ """ showFullScreen_signal = pyqtSignal() showNormal_signal = pyqtSignal() def __init__(self, *args): super(VlcPlayerWidget, self).__init__() self.media_player_frame = QFrame() self.media_player = None self.instance = None self.set_media_player(args) self.widget = QWidget(self) self.setCentralWidget(self.widget) self.palette = self.media_player_frame.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.media_player_frame.setPalette(self.palette) self.media_player_frame.setAutoFillBackground(True) self.main_layout = QVBoxLayout() self.main_layout.setContentsMargins(0, 0, 0, 0) self.main_layout.setSpacing(0) self.current_url = None self.current_url_type = None self._init_ui() self.init_cfg() def _init_ui(self): """ :return: """ self.main_layout.addWidget(self.media_player_frame) self.widget.setLayout(self.main_layout) self.widget.setContextMenuPolicy(Qt.CustomContextMenu) self.widget.customContextMenuRequested.connect(self.custom_right_menu) self.setStyleSheet( f"background-image:url({PathHelper.get_img_path('live_null.png')}); " ) def init_cfg(self): """ :return: """ self.vlc_set_volume(20) def set_media_player(self, *args): """ 获得并设置媒体播放器 :param args: :return: """ if args: self.instance = vlc.Instance(*args) self.media_player = self.instance.media_player_new() else: self.media_player = vlc.MediaPlayer() if get_system_platform() == CommonEnum.WindowsPlatform: self.media_player_frame = QFrame() self.media_player.set_hwnd(self.media_player_frame.winId()) elif get_system_platform() == CommonEnum.LinuxPlatform: self.media_player_frame = QFrame() self.media_player.set_xwindow(self.media_player_frame.winId()) elif get_system_platform() == CommonEnum.DarwinPlatform: from PyQt5.QtWidgets import QMacCocoaViewContainer self.media_player_frame = QMacCocoaViewContainer(0) self.media_player.set_nsobject(self.media_player_frame.winId()) else: self.media_player.set_hwnd(self.media_player_frame.winId()) def custom_right_menu(self, pos): """ :param pos: :return: """ if not (PlayerState.Load == PlayerEnum.LoadStopped or PlayerState.Load == PlayerEnum.LoadNothingSpecial): menu = QMenu() if PlayerState.Load == PlayerEnum.LoadPlaying: play_pause_opt = menu.addAction("暂停") elif PlayerState.Load == PlayerEnum.LoadPaused: play_pause_opt = menu.addAction("播放") else: play_pause_opt = menu.addAction("暂停") refresh_opt = menu.addAction("刷新") stop_opt = menu.addAction("停止") menu.addSeparator() if PlayerState.Size == PlayerEnum.SizeMax: fullscreen_opt = menu.addAction("复原") else: fullscreen_opt = menu.addAction("全屏") menu.addSeparator() mute_opt = menu.addAction("静音") action = menu.exec_(self.widget.mapToGlobal(pos)) if action == play_pause_opt: if PlayerState.Load == PlayerEnum.LoadPlaying: self.vlc_pause() else: self.vlc_resume() elif action == refresh_opt: self.vlc_play(self.current_url, self.current_url_type) elif action == stop_opt: self.vlc_stop() elif action == fullscreen_opt: if PlayerState.Size == PlayerEnum.SizeMax: self.vlc_set_size(False) else: self.vlc_set_size(True) elif action == mute_opt: self.vlc_set_volume(-self.vlc_get_volume()) def enterEvent(self, event: QEvent) -> None: """ :param event: :return: """ if not (PlayerState.Load == PlayerEnum.LoadStopped or PlayerState.Load == PlayerEnum.LoadNothingSpecial): # print("enterEvent") self.grabKeyboard() def leaveEvent(self, event: QEvent) -> None: """ :param event: :return: """ if not (PlayerState.Load == PlayerEnum.LoadStopped or PlayerState.Load == PlayerEnum.LoadNothingSpecial): # print("leaveEvent") self.releaseKeyboard() def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: """ :param event: :return: """ if not (PlayerState.Load == PlayerEnum.LoadStopped or PlayerState.Load == PlayerEnum.LoadNothingSpecial): # print("mouseDoubleClickEvent") if PlayerState.Size == PlayerEnum.SizeMax: self.vlc_set_size(False) else: self.vlc_set_size(True) def keyPressEvent(self, event: QKeyEvent) -> None: """ 重写键盘按下事件 :param event: :return: """ if not (PlayerState.Load == PlayerEnum.LoadStopped or PlayerState.Load == PlayerEnum.LoadNothingSpecial): # print("keyPressEvent", event) if event.key() == Qt.Key_Escape: self.vlc_set_size(False) elif event.key() == Qt.Key_Left: if PlayerState.MrlType == PlayerEnum.MrlTypeLocal: self.vlc_set_time(PlayerState.EachDecreaseTime) elif event.key() == Qt.Key_Right: if PlayerState.MrlType == PlayerEnum.MrlTypeLocal: self.vlc_set_time(PlayerState.EachIncreaseTime) elif event.key() == Qt.Key_Up: self.vlc_set_volume(PlayerState.EachIncreaseVolume) elif event.key() == Qt.Key_Down: self.vlc_set_volume(PlayerState.EachDecreaseVolume) elif event.key() == Qt.Key_Space: if PlayerState.Load == PlayerEnum.LoadPlaying: self.vlc_pause() else: self.vlc_resume() else: pass def vlc_release(self): """ 释放资源 :return: """ return self.media_player.release() def vlc_play(self, url: str, url_type: PlayerEnum): """ 播放 :param url: :param url_type: :return: """ try: if url: # self.instance = vlc.Instance("--audio-visual=visual", "--effect-list=spectrometer", # "--effect-fft-window=flattop") # self.media_player = self.instance.media_player_new() self.current_url = url self.current_url_type = url_type self.media_player.set_mrl(url) self.media_player_frame.show() self.media_player.play() PlayerState.MrlType = url_type PlayerState.Load = PlayerEnum.LoadPlaying else: pass except Exception as e: print(f'[real-live-desktop] play_url exception {e}') return False def vlc_pause(self): """ 暂停 :return: """ self.media_player.pause() PlayerState.Load = PlayerEnum.LoadPaused def vlc_resume(self): """ 恢复 :return: """ self.media_player.set_pause(0) PlayerState.Load = PlayerEnum.LoadPlaying def vlc_stop(self): """ 停止 :return: """ self.media_player_frame.hide() self.media_player.stop() PlayerState.Load = PlayerEnum.LoadStopped def vlc_get_time(self): """ 已播放时间,返回毫秒值 :return: """ return self.media_player.get_time() def vlc_get_length_or_all_time(self): """ 音视频总长度,返回毫秒值 :return: """ return self.media_player.get_length() def vlc_set_time(self, ms): """ 拖动指定的毫秒值处播放。成功返回0,失败返回-1 (需要注意,只有当前多媒体格式或流媒体协议支持才会生效) :param ms: :return: """ _time = self.vlc_get_time() + ms _all_time = self.vlc_get_length_or_all_time() if _time <= 0: return self.media_player.set_time(0) elif _time >= _all_time: return self.media_player.set_time(_all_time) else: return self.media_player.set_time(_time) def vlc_get_volume(self): """ 获取当前音量(0~100) :return: """ return self.media_player.audio_get_volume() def vlc_set_volume(self, volume): """ 设置当前音量 :param volume: :return: """ _volume = self.vlc_get_volume() + volume if _volume <= 0: PlayerState.Volume = PlayerEnum.VolumeMuted return self.media_player.audio_set_volume(0) elif _volume >= 100: PlayerState.Volume = PlayerEnum.VolumeUnmuted self.media_player.audio_set_volume(100) else: PlayerState.Volume = PlayerEnum.VolumeUnmuted self.media_player.audio_set_volume(_volume) def vlc_set_size(self, b_fullscreen: bool): """ 设置窗口大小 :return: """ if b_fullscreen: self.showFullScreen_signal.emit() # self.showFullScreen() self.media_player.set_fullscreen(True) PlayerState.Size = PlayerEnum.SizeMax else: self.showNormal_signal.emit() # self.showNormal() self.media_player.set_fullscreen(False) PlayerState.Size = PlayerEnum.SizeInitial def vlc_get_state(self): """ 返回当前状态 :return: """ # 0: 'NothingSpecial', 处于空闲状态,等待发出命令 # 1: 'Opening', 正在打开媒体资源定位器(MRL) # 2: 'Buffering', 正在缓冲 # 3: 'Playing', 正在播放媒体 # 4: 'Paused', 处于暂停状态 # 5: 'Stopped', 处于停止状态,此时关闭播放器 # 6: 'Ended', 已到达当前播放列表的末尾 # 7: 'Error', 遇到错误,无法继续 return self.media_player.get_state() def vlc_set_position(self, float_val): """ 拖动当前进度,传入0.0~1.0之间的浮点数(需要注意,只有当前多媒体格式或流媒体协议支持才会生效) :param float_val: :return: """ return self.media_player.set_position(float_val) def vlc_get_rate(self): """ 获取当前文件播放速率 :return: """ return self.media_player.get_rate() def vlc_set_rate(self, rate): """ 设置播放速率(如:1.2,表示加速1.2倍播放) :param rate: :return: """ return self.media_player.set_rate(rate) def vlc_set_ratio(self, ratio): """ 设置宽高比率(如"16:9","4:3") :param ratio: :return: """ # 必须设置为0,否则无法修改屏幕宽高 self.media_player.video_set_scale(0) self.media_player.video_set_aspect_ratio(ratio) def vlc_add_callback(self, event_type, callback): """ 注册监听器 :param event_type: VLC的监听器类型 :param callback: :return: """ self.media_player.event_manager().event_attach(event_type, callback) def vlc_remove_callback(self, event_type, callback): """ 移除监听器 :param event_type: :param callback: :return: """ self.media_player.event_manager().event_detach(event_type, callback) def vlc_set_marquee(self): """ 设置字幕 :return: """ # VideoMarqueeOption.Color :文本颜色,值为16进制数 # VideoMarqueeOption.Enable:是否开启文本显示,1表示开启 # VideoMarqueeOption.Opacity:文本透明度,0透明,255完全不透明 # VideoMarqueeOption.Position:文本显示的位置 # VideoMarqueeOption.Refresh:字符串刷新的间隔(毫秒)对时间格式字串刷新有用 # VideoMarqueeOption.Size:文字大小,单位像素 # VideoMarqueeOption.Text:要显示的文本内容 # VideoMarqueeOption.Timeout:文本停留时间。0表示永远停留(毫秒值) # VideoMarqueeOption.marquee_X:设置显示文本的x坐标值 # VideoMarqueeOption.marquee_Y:设置显示文本的y坐标值 self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Enable, 1) self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Size, 28) self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Color, 0xff0000) self.media_player.video_set_marquee_int( vlc.VideoMarqueeOption.Position, vlc.Position.Bottom) self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Timeout, 0) self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Refresh, 10000) def vlc_update_marquee(self, content="%Y-%m-%d %H:%M:%S"): """ 设置字幕内容 :param content: 默认为时间格式,会在屏幕下方显示当前时间,且每一秒刷新一次。 :return: """ self.media_player.video_set_marquee_string(vlc.VideoMarqueeOption.Text, content)
def createUI(self): """Set up the user interface, signals & slots """ self.widget = QWidget(self) self.setCentralWidget(self.widget) self.widget.setStyleSheet("background: '#EEEEEE';") image_path = os.getcwd() + "/mamaro/babybedPNG/login0.png" image_profile = QtGui.QImage(image_path) #QImage object lbl1 = QtWidgets.QLabel('bluetoothstate', self) lbl1.setObjectName('bluetoothstate') lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile)) lbl1.setScaledContents(True) lbl1.setGeometry(48, 38, 195, 120) lbl1.resize(lbl1.sizeHint()) #create background lbl1 = QtWidgets.QLabel('back1', self) lbl1.setObjectName('back1') lbl1.setText("") lbl1.setFont(QtGui.QFont("ms gothic", 28)) lbl1.setStyleSheet("background: 'white';") lbl1.setGeometry(0, 120, 297, 296) lbl1 = QtWidgets.QLabel('back2', self) lbl1.setObjectName('back2') lbl1.setText("") lbl1.setFont(QtGui.QFont("ms gothic", 28)) lbl1.setStyleSheet("background: 'white';") lbl1.setGeometry(0, 420, 297, 296) lbl1 = QtWidgets.QLabel('back3', self) lbl1.setObjectName('back3') lbl1.setText("") lbl1.setFont(QtGui.QFont("ms gothic", 28)) lbl1.setStyleSheet("background: 'white';") lbl1.setGeometry(0, 720, 297, 296) #create background #create icon image_path = os.getcwd() + "/mamaro/babybedPNG/height0.png" image_profile = QtGui.QImage(image_path) #QImage object lbl1 = QtWidgets.QLabel('heighticon', self) lbl1.setObjectName('heighticon') lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile)) lbl1.setScaledContents(True) lbl1.setStyleSheet("background: 'white';") lbl1.setGeometry(91, 180, 115, 104) image_path = os.getcwd() + "/mamaro/babybedPNG/weight0.png" image_profile = QtGui.QImage(image_path) #QImage object lbl1 = QtWidgets.QLabel('weighticon', self) lbl1.setObjectName('weighticon') lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile)) lbl1.setScaledContents(True) lbl1.setStyleSheet("background: 'white';") lbl1.setGeometry(91, 480, 115, 104) image_path = os.getcwd() + "/mamaro/babybedPNG/temp0.png" image_profile = QtGui.QImage(image_path) #QImage object lbl1 = QtWidgets.QLabel('tempicon', self) lbl1.setObjectName('tempicon') lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile)) lbl1.setScaledContents(True) lbl1.setStyleSheet("background: 'white';") lbl1.setGeometry(91, 780, 115, 104) # lbl1.resize(lbl1.sizeHint()); #create text lbl1 = None lbl1 = QtWidgets.QLabel('heighttext', self) lbl1.setObjectName('heighttext') lbl1.setText("") lbl1.setFont(QtGui.QFont("ms gothic", 28)) lbl1.setStyleSheet("color:#9EA2A2;") #lbl1.setAlignment(QtCore.Qt.AlignTop) lbl1.setAlignment(QtCore.Qt.AlignCenter) lbl1.setGeometry(91, 314, 115, 46) lbl1 = QtWidgets.QLabel('weighttext', self) lbl1.setObjectName('weighttext') lbl1.setText("") lbl1.setFont(QtGui.QFont("ms gothic", 28)) lbl1.setStyleSheet("color:#9EA2A2;") #lbl1.setAlignment(QtCore.Qt.AlignTop) lbl1.setAlignment(QtCore.Qt.AlignCenter) lbl1.setGeometry(91, 614, 115, 52) lbl1 = QtWidgets.QLabel('temptext', self) lbl1.setObjectName('temptext') lbl1.setText("") lbl1.setFont(QtGui.QFont("ms gothic", 28)) lbl1.setStyleSheet("color:#9EA2A2;") #lbl1.setAlignment(QtCore.Qt.AlignTop) lbl1.setAlignment(QtCore.Qt.AlignCenter) lbl1.setGeometry(91, 914, 115, 46) lbl1 = QtWidgets.QLabel('contentcover', self) lbl1.setObjectName('contentcover') lbl1.setText("") lbl1.setCursor(Qt.PointingHandCursor) lbl1.setGeometry(0, 0, 297, 1080) lbl1.mousePressEvent = self.contentclick # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer videoframe = QMacCocoaViewContainer(0) else: videoframe = QtWidgets.QFrame(self) self.palette = videoframe.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) videoframe.setObjectName('videoview') videoframe.setPalette(self.palette) videoframe.setAutoFillBackground(True) videoframe.mousePressEvent = self.contentclick videoframe.setGeometry(QtCore.QRect(298, 0, 1622, 1080)) global connection, roomid, readcheck, playlist, sorted_x, totalfile, oneloopindex, totalindexx, checkonetime, strings2, cou self.OpenFile(strings2[cou]) insertdata(sorted_x[cou].DBindex, sorted_x[cou].playindex, totalindexx) cou += 1 totalindexx += 1 print(self.mediaplayer.get_state())
def __init__(self): self.file_list = [] super(MainWindow, self).__init__() uic.loadUi('../Vista/interface.ui', self) ''' Actions for label buttons of widget list ''' self.Add.clicked.connect(self.Add_files) self.Select.clicked.connect(self.get_selected_item) self.Erase.clicked.connect(self.remove_selected_item) self.ChangePosition.clicked.connect(self.change_image) ''' Actions for Control the editor ''' self.export_2.clicked.connect(self.Remderize_video) self.ChangeImage.clicked.connect(self.put_image) self.ChangeAudio.clicked.connect(self.put_audio) self.get_start.clicked.connect(self.set_init_frame) self.get_end.clicked.connect(self.set_end_frame) self.label2 = QtWidgets.QLabel("Ja'mapel cocunubo", self) self.label2.setText("") ''' Actions of menu bar ''' self.actionExit.triggered.connect(self.exit) self.actionExport.triggered.connect(self.Remderize_video) self.actionOpen_Video.triggered.connect(self.OpenFile2) ''' Para entradas y salidas ''' self.to_draw = None self.selected_item = None # Variable con el item seleccionado por ej imagen ,a udio , video self.changes = None self.actvid = None self.actaud = None self.s1 = None self.s2 = None self.actimg = None self.tinicio = None self.tfin = None self.minframe = -1 self.maxframe = -1 self.newpath = None self.inicio = None # Variable con frame de inicio self.final = None # Variable con frame de terminacion self.x = None # Variable con posicion relativa en x self.y = None # Variable con posicion relative en y self.frame = None ''' DOnde puedes probar lo del VLC ''' # creating a basic vlc instance self.instance = vlc.Instance() self.mediaPlayer = self.instance.media_player_new() # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoPlayer = QMacCocoaViewContainer(0) else: self.videoPlayer = QtWidgets.QFrame() self.videoPlayer.resize(640, 360) self.palette = self.videoPlayer.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoPlayer.setPalette(self.palette) self.videoPlayer.setAutoFillBackground(True) self.isPaused = False self.Play.clicked.connect(self.play) self.Pause.clicked.connect(self.pause) self.Stop.clicked.connect(self.stop) self.Timer.setMaximum(1000) self.Timer.sliderMoved.connect(self.setPosition) self.Volume.sliderMoved.connect(self.setVolume) self.Volume.setRange(0, 100) self.lay.addWidget(self.videoPlayer) self.reloj = QtCore.QTimer(self) self.reloj.setInterval(1) self.reloj.timeout.connect(self.updateUI) self.t = Thread(target=self.counter) self.t2 = Thread(target=self.counter2) self.t3 = Thread(target=self.Draw_Image) self.timeEdit.setDisplayFormat("hh:mm:ss AP") self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.updateTime) self.timer.start(1000) self.t.start() self.t2.start() #self.selection.mousePressEvent = self.getPos #self.layout = QtWidgets.QVBoxLayout() self.counterpro.display(0) self.show()
class MainWindow(QtWidgets.QMainWindow): def __init__(self): self.file_list = [] super(MainWindow, self).__init__() uic.loadUi('../Vista/interface.ui', self) ''' Actions for label buttons of widget list ''' self.Add.clicked.connect(self.Add_files) self.Select.clicked.connect(self.get_selected_item) self.Erase.clicked.connect(self.remove_selected_item) self.ChangePosition.clicked.connect(self.change_image) ''' Actions for Control the editor ''' self.export_2.clicked.connect(self.Remderize_video) self.ChangeImage.clicked.connect(self.put_image) self.ChangeAudio.clicked.connect(self.put_audio) self.get_start.clicked.connect(self.set_init_frame) self.get_end.clicked.connect(self.set_end_frame) self.label2 = QtWidgets.QLabel("Ja'mapel cocunubo", self) self.label2.setText("") ''' Actions of menu bar ''' self.actionExit.triggered.connect(self.exit) self.actionExport.triggered.connect(self.Remderize_video) self.actionOpen_Video.triggered.connect(self.OpenFile2) ''' Para entradas y salidas ''' self.to_draw = None self.selected_item = None # Variable con el item seleccionado por ej imagen ,a udio , video self.changes = None self.actvid = None self.actaud = None self.s1 = None self.s2 = None self.actimg = None self.tinicio = None self.tfin = None self.minframe = -1 self.maxframe = -1 self.newpath = None self.inicio = None # Variable con frame de inicio self.final = None # Variable con frame de terminacion self.x = None # Variable con posicion relativa en x self.y = None # Variable con posicion relative en y self.frame = None ''' DOnde puedes probar lo del VLC ''' # creating a basic vlc instance self.instance = vlc.Instance() self.mediaPlayer = self.instance.media_player_new() # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoPlayer = QMacCocoaViewContainer(0) else: self.videoPlayer = QtWidgets.QFrame() self.videoPlayer.resize(640, 360) self.palette = self.videoPlayer.palette() self.palette.setColor(QPalette.Window, QColor(0, 0, 0)) self.videoPlayer.setPalette(self.palette) self.videoPlayer.setAutoFillBackground(True) self.isPaused = False self.Play.clicked.connect(self.play) self.Pause.clicked.connect(self.pause) self.Stop.clicked.connect(self.stop) self.Timer.setMaximum(1000) self.Timer.sliderMoved.connect(self.setPosition) self.Volume.sliderMoved.connect(self.setVolume) self.Volume.setRange(0, 100) self.lay.addWidget(self.videoPlayer) self.reloj = QtCore.QTimer(self) self.reloj.setInterval(1) self.reloj.timeout.connect(self.updateUI) self.t = Thread(target=self.counter) self.t2 = Thread(target=self.counter2) self.t3 = Thread(target=self.Draw_Image) self.timeEdit.setDisplayFormat("hh:mm:ss AP") self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.updateTime) self.timer.start(1000) self.t.start() self.t2.start() #self.selection.mousePressEvent = self.getPos #self.layout = QtWidgets.QVBoxLayout() self.counterpro.display(0) self.show() def updateTime(self): current = QtCore.QDateTime.currentDateTime() self.timeEdit.setTime(current.time()) def getPos(self, event): x = event.pos().x() y = event.pos().y() self.xspin.setValue(x * 1.0) self.yspin.setValue(y * 1.0) self.x = x self.y = y self.label.hide() print(x, y) self.ChangePosition.setEnabled(True) self.spinBox.setEnabled(False) self.spinBox_2.setEnabled(False) self.xlabel_2.setEnabled(False) self.xlabel_3.setEnabled(False) if self.tinicio == None or self.actimg == None or self.actvid == None or self.x == None or self.y == None: print("Error cargando algo") else: pos = convertPos(self.x, self.y, self.actvid) self.changes = [ self.actvid, self.actimg, self.tinicio, self.tfin, pos ] print("Exito , ", pos, self.actvid, self.actimg) def get_file(self, name): ret = None for x in self.file_list: if x.name == name: ret = x break print(ret.name) return ret def counter(self): while 1: self.counterpro.display(self.getPosition() * 1000) def counter2(self): while 1: self.Timer.setValue(self.getPosition() * 1000) def Add_files(self): image_formats = [".jpg", ".jpeg", ".png", ".ico", ".nef", ".bpm"] video_formats = [".avi", ".mp4", ".mov", ".mpeg", ".mkv"] audio_formats = [".mp3", ".wav"] options = QtWidgets.QFileDialog.Options() options |= QtWidgets.QFileDialog.DontUseNativeDialog fileName, _ = QtWidgets.QFileDialog.getOpenFileName( self, "Select Media Files", "", "All Files (*);;Image Files (*.jpeg)", options=options) name = os.path.basename(fileName) filename, file_extension = os.path.splitext(name) ubication = None if file_extension.lower() in image_formats: image = Image.open(fileName) image.thumbnail((500, 500), Image.ANTIALIAS) image.save('../Resources/' + "." + filename + ".png", 'PNG') ubication = '../Resources/' + "." + filename + ".png" typef = "image" if file_extension.lower() in audio_formats: ubication = "../Resources/audio-file.png" typef = "audio" if file_extension.lower() in video_formats: ubication = "../Resources/video-file.png" typef = "video" if ubication != None: pixmap = QIcon(ubication) item = QtWidgets.QListWidgetItem(pixmap, filename) self.file_list.append(MediaFile(filename, fileName, typef)) self.filelist.addItem(item) def get_selected_item(self): self.ChangePosition.setEnabled(False) self.ChangeImage.setEnabled(False) self.ChangeAudio.setEnabled(False) self.spinBox.setEnabled(False) self.spinBox_2.setEnabled(False) self.xlabel_2.setEnabled(False) self.xlabel_3.setEnabled(False) self.get_start.setEnabled(False) self.get_end.setEnabled(False) if len(self.filelist.selectedItems()) > 0: self.selected_item = self.get_file( self.filelist.selectedItems()[0].text()) if self.selected_item.typef == "image": self.ChangeImage.setEnabled(True) self.actimg = self.selected_item.path self.spinBox.setEnabled(True) self.spinBox_2.setEnabled(True) self.xlabel_2.setEnabled(True) self.xlabel_3.setEnabled(True) self.get_start.setEnabled(True) self.get_end.setEnabled(True) elif self.selected_item.typef == "audio": self.ChangeAudio.setEnabled(True) self.spinBox.setEnabled(True) #self.spinBox_2.setEnabled(True) self.xlabel_2.setEnabled(True) #self.xlabel_3.setEnabled(True) self.actaud = self.selected_item.path if self.selected_item.typef == "video": self.OpenFile(self.selected_item.path) self.actvid = self.selected_item.path def set_init_frame(self): self.spinBox.setValue(int(round(self.getPosition() * 1000))) def set_end_frame(self): self.spinBox_2.setValue(int(round(self.getPosition() * 1000))) def calculateTime(self): self.minframe = self.spinBox.value() self.maxframe = self.spinBox_2.value() framerate = self.mediaPlayer.get_fps() startf = self.spinBox.value() endf = self.spinBox_2.value() self.tinicio = startf / framerate self.tfin = endf / framerate def remove_selected_item(self): listItems = self.filelist.selectedItems() if len(listItems) == 0: return self.filelist.takeItem(self.filelist.row(listItems[0])) ''' Functions for edit the video ''' ''' Todos los metodos que consideres dejalos comentados y pone con que lo linkeo ''' def Remderize_video(self): # Metodo con funcion de remderizar options = QtWidgets.QFileDialog.Options() options |= QtWidgets.QFileDialog.DontUseNativeDialog self.newpath, _ = QtWidgets.QFileDialog.getSaveFileName( self, "Select Media Files", "", "All Files (*)", options=options) if False: print("Error cargando algo") else: pid = os.fork() if pid == 0: print(self.changes[0], self.newpath, self.changes[1], self.changes[2], self.changes[3], self.changes[4]) addImage(self.changes[0], self.newpath, self.changes[1], self.changes[2], self.changes[3], self.changes[4]) exit(0) def put_image(self): # Metodo que pone la imagen #self.label.show() self.get_start.setEnabled(True) self.get_end.setEnabled(True) self.label = QtWidgets.QLabel("Ja'mapel", self) self.label.setText("") self.label.setGeometry(QtCore.QRect(19, 44, 640, 360)) self.label.setMinimumSize(QtCore.QSize(640, 360)) self.label.setMaximumSize(QtCore.QSize(640, 360)) self.label.setCursor(QtCore.Qt.PointingHandCursor) self.label.mousePressEvent = self.getPos self.label.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.label.show() self.ChangeImage.setEnabled(False) self.calculateTime() self.make_mini_image() self.t3.start() def change_image(self): # Metodo que pone la imagen #self.label.show() self.label = QtWidgets.QLabel("Ja'mapel", self) self.label.setText("") self.label.setGeometry(QtCore.QRect(19, 44, 640, 360)) self.label.setMinimumSize(QtCore.QSize(640, 360)) self.label.setMaximumSize(QtCore.QSize(640, 360)) self.label.setCursor(QtCore.Qt.PointingHandCursor) self.label.mousePressEvent = self.getPos self.label.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.label.show() self.ChangeImage.setEnabled(False) def chg_image(self): # Metodo que pone la imagen self.calculateTime() if self.tinicio == None or self.actimg == None or self.actvid == None or self.x == None or self.y == None: print("Error cargando algo") else: pos = convertPos(self.x, self.y, self.actvid) self.changes = [ self.actvid, self.actimg, self.tinicio, self.tfin, pos ] def exit(self): pos = [self.x, self.y] self.changes.append( [self.actvid, self.actimg, self.tinicio, self.tfin, pos]) def put_audio(self): # Metodo que pone el audio self.calculateTime() if self.tinicio == None or self.actaud == None or self.actvid == None: print("Error cargando algo") else: addSound(self.tinicio, self.actaud, self.actvid) def exit(self): window = Form() window.show() window.exec_() exit(0) def play(self): #if self.mediaPlayer.is_playing(): self.mediaPlayer.play() self.isPaused = False self.videoPlayer.resize(640, 360) def pause(self): #if not self.mediaPlayer.is_playing(): self.mediaPlayer.pause() self.isPaused = True def stop(self): self.mediaPlayer.stop() def setVolume(self, Volume): self.mediaPlayer.audio_set_volume(Volume) def setPosition(self, position): self.mediaPlayer.set_position(position / 1000.0) def getPosition(self): return self.mediaPlayer.get_position() def updateUI(self): self.Timer.setValue(self.mediaplayer.get_position() * 1000) self.reloj.stop() if not self.isPaused: self.stop() def make_mini_image(self): image = Image.open(self.actimg) w, h = image.size self.s1 = w / 2 self.s2 = h / 2 image.thumbnail((self.s1, self.s2), Image.ANTIALIAS) image.save('../Resources/' + "." + "DRAW" + ".png", 'PNG') self.to_draw = '../Resources/' + "." + "DRAW" + ".png" def OpenFile(self, filename=None): ''' options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog filename, _ = QFileDialog.getOpenFileName(self,"Select Media Files", "","All Files (*);;Image Files (*.jpeg)", options=options) ''' if sys.version < '3': filename = unicode(filename) self.media = self.instance.media_new(filename) self.mediaPlayer.set_media(self.media) self.media.parse() if sys.platform.startswith('linux'): self.mediaPlayer.set_xwindow(self.videoPlayer.winId()) elif sys.platform == "win32": self.mediaPlayer.set_hwnd(self.videoPlayer.winId()) elif sys.platform == "darwin": self.mediaPlayer.set_nsobject(int(self.videoPlayer.winId())) self.videoPlayer.resize(640, 360) self.play() def OpenFile2(self): options = QtWidgets.QFileDialog.Options() options |= QtWidgets.QFileDialog.DontUseNativeDialog filename, _ = QtWidgets.QFileDialog.getOpenFileName( self, "Select Media Files", "", "All Files (*);;Image Files (*.jpeg)", options=options) if sys.version < '3': filename = unicode(filename) self.media = self.instance.media_new(filename) self.mediaPlayer.set_media(self.media) self.media.parse() if sys.platform.startswith('linux'): self.mediaPlayer.set_xwindow(self.videoPlayer.winId()) elif sys.platform == "win32": self.mediaPlayer.set_hwnd(self.videoPlayer.winId()) elif sys.platform == "darwin": self.mediaPlayer.set_nsobject(int(self.videoPlayer.winId())) self.videoPlayer.resize(640, 360) self.play() def Draw_Image(self): while 1: sleep(0.05) var = self.getPosition() * 1000 #print(" tengo ",var," quiero ", self.minframe , " con un " , self.maxframe) if var >= self.minframe and var <= self.maxframe: if self.actimg != None: self.label2.setGeometry( QtCore.QRect(self.x, self.y, self.s1, self.s2)) self.label2.setMinimumSize(QtCore.QSize(self.s1, self.s2)) self.label2.setMaximumSize(QtCore.QSize(self.s1, self.s2)) self.label2.setAttribute( QtCore.Qt.WA_TranslucentBackground) pixmap = QPixmap(self.to_draw) self.label2.setPixmap(pixmap) self.label2.setMask(pixmap.mask()) self.label2.show() else: self.label2.hide()
def setupUi(self, hydraMainWindow): hydraMainWindow.setObjectName("hydraMainWindow") hydraMainWindow.resize(642, 400) hydraMainWindow.setMinimumSize(QtCore.QSize(0, 400)) hydraMainWindow.setFocusPolicy(QtCore.Qt.StrongFocus) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(self.resource_path("hydra_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) hydraMainWindow.setWindowIcon(icon) hydraMainWindow.setStyleSheet("color: rgb(255, 255, 255);\n" "background-color: rgb(136, 138, 133);") self.centralwidget = QtWidgets.QWidget(hydraMainWindow) self.centralwidget.setStyleSheet("background-color: rgb(0, 0, 0);") self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setSpacing(0) self.gridLayout.setObjectName("gridLayout") if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoFrame = QMacCocoaViewContainer(self.centralwidget) else: self.videoFrame = QtWidgets.QFrame(self.centralwidget) self.videoFrame.setStyleSheet("") self.videoFrame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.videoFrame.setFrameShadow(QtWidgets.QFrame.Raised) self.videoFrame.setObjectName("videoFrame") self.gridLayout_3 = QtWidgets.QGridLayout(self.videoFrame) self.gridLayout_3.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint) self.gridLayout_3.setContentsMargins(0, 0, 0, 0) self.gridLayout_3.setHorizontalSpacing(0) self.gridLayout_3.setVerticalSpacing(6) self.gridLayout_3.setObjectName("gridLayout_3") self.frame_2 = QtWidgets.QFrame(self.videoFrame) self.frame_2.setMaximumSize(QtCore.QSize(16777215, 16777215)) self.frame_2.setStyleSheet("background-color: rgb(0, 0, 0);") self.frame_2.setFrameShape(QtWidgets.QFrame.NoFrame) self.frame_2.setFrameShadow(QtWidgets.QFrame.Plain) self.frame_2.setObjectName("frame_2") self.gridLayout_3.addWidget(self.frame_2, 0, 0, 1, 1) self.gridLayout.addWidget(self.videoFrame, 0, 0, 1, 1) self.controlsFrame = QtWidgets.QFrame(self.centralwidget) self.controlsFrame.setMinimumSize(QtCore.QSize(0, 40)) self.controlsFrame.setMaximumSize(QtCore.QSize(16777215, 40)) self.controlsFrame.setStyleSheet("color: rgb(255, 255, 255);\n" "background-color: rgb(85, 87, 83);") self.controlsFrame.setObjectName("controlsFrame") self.horizontalLayout = QtWidgets.QHBoxLayout(self.controlsFrame) self.horizontalLayout.setContentsMargins(2, 0, 2, 0) self.horizontalLayout.setObjectName("horizontalLayout") self.openMediaButton = QtWidgets.QPushButton(self.controlsFrame) self.openMediaButton.setMinimumSize(QtCore.QSize(32, 26)) self.openMediaButton.setMaximumSize(QtCore.QSize(32, 26)) self.openMediaButton.setFocusPolicy(QtCore.Qt.NoFocus) self.openMediaButton.setText("") icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(self.resource_path("open_vid.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.openMediaButton.setIcon(icon1) self.openMediaButton.setIconSize(QtCore.QSize(20, 20)) self.openMediaButton.setObjectName("openMediaButton") self.horizontalLayout.addWidget(self.openMediaButton) self.openPlaylistButton = QtWidgets.QPushButton(self.controlsFrame) self.openPlaylistButton.setMinimumSize(QtCore.QSize(32, 26)) self.openPlaylistButton.setMaximumSize(QtCore.QSize(32, 26)) self.openPlaylistButton.setFocusPolicy(QtCore.Qt.NoFocus) self.openPlaylistButton.setText("") icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(self.resource_path("load_playlist.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.openPlaylistButton.setIcon(icon2) self.openPlaylistButton.setIconSize(QtCore.QSize(20, 20)) self.openPlaylistButton.setObjectName("openPlaylistButton") self.horizontalLayout.addWidget(self.openPlaylistButton) self.previousMediaButton = QtWidgets.QPushButton(self.controlsFrame) self.previousMediaButton.setMinimumSize(QtCore.QSize(32, 26)) self.previousMediaButton.setMaximumSize(QtCore.QSize(32, 26)) self.previousMediaButton.setFocusPolicy(QtCore.Qt.NoFocus) self.previousMediaButton.setText("") icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(self.resource_path("previous_media.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.previousMediaButton.setIcon(icon3) self.previousMediaButton.setIconSize(QtCore.QSize(20, 20)) self.previousMediaButton.setObjectName("previousMediaButton") self.horizontalLayout.addWidget(self.previousMediaButton) self.playPauseButton = QtWidgets.QPushButton(self.controlsFrame) self.playPauseButton.setMinimumSize(QtCore.QSize(32, 26)) self.playPauseButton.setMaximumSize(QtCore.QSize(32, 26)) self.playPauseButton.setFocusPolicy(QtCore.Qt.NoFocus) self.playPauseButton.setText("") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(self.resource_path("play.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.playPauseButton.setIcon(icon4) self.playPauseButton.setIconSize(QtCore.QSize(20, 20)) self.playPauseButton.setObjectName("playPauseButton") self.horizontalLayout.addWidget(self.playPauseButton) self.stopButton = QtWidgets.QPushButton(self.controlsFrame) self.stopButton.setMinimumSize(QtCore.QSize(32, 26)) self.stopButton.setMaximumSize(QtCore.QSize(32, 26)) self.stopButton.setFocusPolicy(QtCore.Qt.NoFocus) self.stopButton.setText("") icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(self.resource_path("stop.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.stopButton.setIcon(icon5) self.stopButton.setIconSize(QtCore.QSize(20, 20)) self.stopButton.setObjectName("stopButton") self.horizontalLayout.addWidget(self.stopButton) self.repeatButton = QtWidgets.QPushButton(self.controlsFrame) self.repeatButton.setMinimumSize(QtCore.QSize(32, 26)) self.repeatButton.setMaximumSize(QtCore.QSize(32, 26)) self.repeatButton.setFocusPolicy(QtCore.Qt.NoFocus) self.repeatButton.setText("") icon6 = QtGui.QIcon() icon6.addPixmap(QtGui.QPixmap(self.resource_path("repeat_off.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.repeatButton.setIcon(icon6) self.repeatButton.setIconSize(QtCore.QSize(20, 20)) self.repeatButton.setCheckable(True) self.repeatButton.setObjectName("repeatButton") self.horizontalLayout.addWidget(self.repeatButton) self.nextMediaButton = QtWidgets.QPushButton(self.controlsFrame) self.nextMediaButton.setMinimumSize(QtCore.QSize(32, 26)) self.nextMediaButton.setMaximumSize(QtCore.QSize(32, 26)) self.nextMediaButton.setFocusPolicy(QtCore.Qt.NoFocus) self.nextMediaButton.setText("") icon7 = QtGui.QIcon() icon7.addPixmap(QtGui.QPixmap(self.resource_path("next_media.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.nextMediaButton.setIcon(icon7) self.nextMediaButton.setIconSize(QtCore.QSize(20, 20)) self.nextMediaButton.setObjectName("nextMediaButton") self.horizontalLayout.addWidget(self.nextMediaButton) self.line = QtWidgets.QFrame(self.controlsFrame) self.line.setFrameShape(QtWidgets.QFrame.VLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.horizontalLayout.addWidget(self.line) self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setSpacing(0) self.verticalLayout.setObjectName("verticalLayout") self.progressSlider = QtWidgets.QSlider(self.controlsFrame) self.progressSlider.setMinimumSize(QtCore.QSize(225, 0)) self.progressSlider.setFocusPolicy(QtCore.Qt.NoFocus) self.progressSlider.setStyleSheet("background-color: rgb(85, 87, 83);") self.progressSlider.setMaximum(1000) self.progressSlider.setPageStep(20) self.progressSlider.setOrientation(QtCore.Qt.Horizontal) self.progressSlider.setObjectName("progressSlider") self.verticalLayout.addWidget(self.progressSlider) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setContentsMargins(-1, -1, -1, 5) self.horizontalLayout_2.setSpacing(0) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.currentTimeLabel = QtWidgets.QLabel(self.controlsFrame) self.currentTimeLabel.setMaximumSize(QtCore.QSize(16777215, 10)) font = QtGui.QFont() font.setPointSize(10) self.currentTimeLabel.setFont(font) self.currentTimeLabel.setObjectName("currentTimeLabel") self.horizontalLayout_2.addWidget(self.currentTimeLabel) self.totalDurationLabel = QtWidgets.QLabel(self.controlsFrame) self.totalDurationLabel.setMaximumSize(QtCore.QSize(16777215, 10)) font = QtGui.QFont() font.setPointSize(10) self.totalDurationLabel.setFont(font) self.totalDurationLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) self.totalDurationLabel.setObjectName("totalDurationLabel") self.horizontalLayout_2.addWidget(self.totalDurationLabel) self.verticalLayout.addLayout(self.horizontalLayout_2) self.horizontalLayout.addLayout(self.verticalLayout) self.line_2 = QtWidgets.QFrame(self.controlsFrame) self.line_2.setFrameShape(QtWidgets.QFrame.VLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_2.setObjectName("line_2") self.horizontalLayout.addWidget(self.line_2) self.volumeSlider = QtWidgets.QSlider(self.controlsFrame) self.volumeSlider.setMinimumSize(QtCore.QSize(109, 0)) self.volumeSlider.setMaximumSize(QtCore.QSize(109, 16777215)) self.volumeSlider.setFocusPolicy(QtCore.Qt.NoFocus) self.volumeSlider.setMaximum(100) self.volumeSlider.setPageStep(5) self.volumeSlider.setProperty("value", 100) self.volumeSlider.setOrientation(QtCore.Qt.Horizontal) self.volumeSlider.setObjectName("volumeSlider") self.horizontalLayout.addWidget(self.volumeSlider) self.gridLayout.addWidget(self.controlsFrame, 1, 0, 1, 1) hydraMainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(hydraMainWindow) QtCore.QMetaObject.connectSlotsByName(hydraMainWindow)
def createUI(self): """ Set up the window for the VLC viewer """ self.widget = QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn if sys.platform == "darwin": # for MacOS from PyQt5.QtWidgets import QMacCocoaViewContainer self.videoframe = QMacCocoaViewContainer(0) else: self.videoframe = QFrame() self.palette = self.videoframe.palette() self.palette.setColor (QPalette.Window, QColor(0,0,0)) self.videoframe.setPalette(self.palette) self.videoframe.setAutoFillBackground(True) self.hbuttonbox = QHBoxLayout() self.playbutton = QPushButton("Run my program") self.hbuttonbox.addWidget(self.playbutton) self.playbutton.clicked.connect(partial(self.drone_vision.run_user_code, self.playbutton)) self.landbutton = QPushButton("Land NOW") self.hbuttonbox.addWidget(self.landbutton) self.landbutton.clicked.connect(self.drone_vision.land) self.stopbutton = QPushButton("Quit") self.hbuttonbox.addWidget(self.stopbutton) self.stopbutton.clicked.connect(self.drone_vision.close_exit) self.vboxlayout = QVBoxLayout() self.vboxlayout.addWidget(self.videoframe) if (self.drone_vision.user_draw_window_fn is not None): self.userWindow = QLabel() fullPath = inspect.getfile(DroneVisionGUI) shortPathIndex = fullPath.rfind("/") if (shortPathIndex == -1): # handle Windows paths shortPathIndex = fullPath.rfind("\\") print(shortPathIndex) shortPath = fullPath[0:shortPathIndex] pixmap = QPixmap('%s/demo_user_image.png' % shortPath) print(pixmap) print(pixmap.isNull()) self.userWindow.setPixmap(pixmap) self.vboxlayout.addWidget(self.userWindow) self.vboxlayout.addLayout(self.hbuttonbox) self.widget.setLayout(self.vboxlayout) # the media player has to be 'connected' to the QFrame # (otherwise a video would be displayed in it's own window) # this is platform specific! # you have to give the id of the QFrame (or similar object) to # vlc, different platforms have different functions for this if sys.platform.startswith('linux'): # for Linux using the X Server self.mediaplayer.set_xwindow(self.videoframe.winId()) elif sys.platform == "win32": # for Windows self.mediaplayer.set_hwnd(self.videoframe.winId()) elif sys.platform == "darwin": # for MacOS self.mediaplayer.set_nsobject(int(self.videoframe.winId()))