Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia
- from design import Ui_MainWindow
- from pynput.keyboard import Listener
- from pynput import keyboard
- import threading
- import sys
- #!/usr/bin/env python
- from subprocess import Popen, PIPE
- sudo_password = 'mypass'
- command = 'mount -t vboxsf myfolder /home/myuser/myfolder'.split()
- p = Popen(['sudo', '-S'] + command, stdin=PIPE, stderr=PIPE,
- universal_newlines=True)
- sudo_prompt = p.communicate(sudo_password + '\n')[1]
- class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
- def __init__(self, *args, **kwargs):
- QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
- processo = threading.Thread(target=self.listen_key)
- #processo.daemon = True
- processo.start()
- self.setupUi(self)
- def start_play(self, path="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"):
- try:
- self.mediaPlayer.stop()
- except:
- print('Não existia video')
- self.mediaPlayer = QtMultimedia.QMediaPlayer(self)
- self.mediaPlayer.setVideoOutput(self.widget)
- fileName = "hai.mkv"
- url = QtCore.QUrl.fromLocalFile(fileName)
- #url = QtCore.QUrl(path)
- self.mediaPlayer.setMedia(QtMultimedia.QMediaContent(url))
- self.mediaPlayer.play()
- def listen_key(self):
- def on_press(key):
- key_especial = None
- try:
- key = key.char
- except AttributeError:
- key_especial = key
- except:
- print('Algum erro relativo ao caractere')
- if key_especial is not None:
- print(key_especial)
- if key_especial == keyboard.Key.enter:
- self.start_play()
- #self.label_error.setText('foda')
- elif key:
- print(key)
- if key == 'q':
- print('q pressed')
- with Listener(on_press=on_press) as listener:
- listener.join()
- # def keyPressEvent(self, event):
- # if event.key() == QtCore.Qt.Key_Enter:
- # print('enter')
- # self.start_play()
- if __name__ == "__main__":
- import sys
- app = QtWidgets.QApplication(sys.argv)
- w = MainWindow()
- w.show()
- sys.exit(app.exec_())
- # self.listWidget.addItem('TESTE')
- # self.listWidget.addItem('massa')
- # self.listWidget.addItem('teque')
- # from PyQt5.QtMultimediaWidgets import QVideoWidget
- from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia
- from design3 import Ui_MainWindow
- from pynput.keyboard import Listener
- from pynput import keyboard
- import threading
- import sys
- import os
- class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
- def __init__(self, *args, **kwargs):
- QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
- processo = threading.Thread(target=self.listen_key)
- #processo.daemon = True
- processo.start()
- self.setupUi(self)
- self.showFullScreen()
- self.ordem = ""
- def start_play(self, path="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"):
- try:
- self.mediaPlayer.stop()
- except:
- print('Não existia video')
- self.mediaPlayer = QtMultimedia.QMediaPlayer(self)
- self.mediaPlayer.setVideoOutput(self.widget)
- fileName = path
- url = QtCore.QUrl.fromLocalFile(fileName)
- #url = QtCore.QUrl(path)
- self.mediaPlayer.setMedia(QtMultimedia.QMediaContent(url))
- self.mediaPlayer.play()
- def listen_key(self):
- def on_press(key):
- key_especial = None
- try:
- key = key.char
- except AttributeError:
- key_especial = key
- except:
- print('Algum erro relativo ao caractere')
- if key_especial is not None:
- print(key_especial)
- if key_especial == keyboard.Key.enter:
- pass
- #self.widget.setFullScreen(True)
- #self.start_play('hai.mkv')
- #info = self.search_song(self.ordem)
- #self.label_info.setText(info)
- # Apagar números
- elif key_especial == keyboard.Key.backspace:
- if len(self.ordem) != 0:
- self.ordem = self.ordem[:-1]
- self.numsearch.setText(self.ordem)
- self.info = self.search_song(self.ordem)
- self.label_info.setText(self.info)
- elif key:
- print(key)
- if key == 'q':
- pass
- # Ao digitar números; pesquisá-los nos índices do catálogo
- elif key in ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']:
- self.ordem += key
- self.numsearch.setText(self.ordem)
- self.info = self.search_song(self.ordem)
- self.label_info.setText(self.info)
- self.widget.setFullScreen(False)
- self.widget.setGeometry(QtCore.QRect(40, 100, 371, 231))
- # Encerrar função listen_ley ao apertar Ctrl+C
- elif key == "\x03":
- os.system('Cls')
- quit()
- with Listener(on_press=on_press) as listener:
- listener.join()
- def search_song(self, indice, path='dados.ini'):
- """ Retorna informações de uma música a partir do seu índice/ordem """
- if type(indice) == 'int':
- indice = str(indice)
- try:
- with open(path, 'r') as f:
- arquivo = f.readlines()
- except:
- print('Erro ao tentar abrir catálogo')
- text = ""
- for x in arquivo:
- # Caso a linha(x) contiver o indice:
- if x.strip() == f'[{indice}]':
- ind = arquivo.index(x)
- if "arquivo" in (arquivo[ind + 1]).lower():
- text += arquivo[ind + 2]
- text += arquivo[ind + 3]
- else:
- text += arquivo[ind + 1]
- text += arquivo[ind + 2]
- #self.label_info.setText(text)
- # Caso não:
- if len(text) == 0:
- text = '0'
- return text
- if __name__ == "__main__":
- import sys
- app = QtWidgets.QApplication(sys.argv)
- w = MainWindow()
- w.show()
- sys.exit(app.exec_())
- # self.listWidget.addItem('TESTE')
- # self.listWidget.addItem('massa')
- # self.listWidget.addItem('teque')
- # from PyQt5.QtMultimediaWidgets import QVideoWidget
Add Comment
Please, Sign In to add comment