class WebControl: @pyqtSlot() def on_reInject_btn_clicked(self): """ Slot documentation goes here. """ self.browser.reInject() @pyqtSlot() def on_run_btn_clicked(self): """ Slot documentation goes here. """ cmd = self.run_js_pe.toPlainText() # print(cmd) self.page().runJavaScript(cmd) def page(self) -> QWebEnginePage: return self.browser.page() def show_debug_web(self): # 打开调试页面 self.dw = QWebEngineView() self.dw.setWindowTitle('开发人员工具') self.dw.load(QUrl('http://127.0.0.1:9966')) self.dw.move(600, 100) self.dw.show() self.dw.closeEvent = lambda *a: self.show_debug_web() def closeEvent(self, *args, **kwargs): sys.exit(0)
class App(QWidget): def __init__(self): super().__init__() self.title = 'Web Browser' self.left = 120 self.top = 120 self.width = 1200 self.height = 700 self.init_win() def init_win(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.show() self.button1 = QPushButton('Show Webpage', self) self.button1.move(450, 10) self.button1.clicked.connect(self.show_webpage) self.button1.show() self.button2 = QPushButton('Extract <li>', self) self.button2.move(550, 10) self.button2.clicked.connect(self.show_list) self.button2.show() def show_webpage(self): self.webpage = web_scraping.get_html() self.web = QWebEngineView(self) self.web.load(QUrl(HTML_URL)) self.web.move(40, 40) self.web.show() def show_list(self): self.webpage = web_scraping.get_html() self.html_list = web_scraping.get_list(self.webpage) self.table = QTableWidget(self) self.table_row = len(self.html_list) self.table.setRowCount(self.table_row) self.table.setColumnCount(1) i = 0 for each in self.html_list: self.table.setItem(i, 0, QTableWidgetItem(each)) i += 1 self.table.move(900, 40) self.table.resizeColumnsToContents() self.table.show()
def main(api_endpoint, credentials, device_model_id, device_id, lang, query, verbose, grpc_deadline, *args, **kwargs): logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) try: with open(credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) http_request = google.auth.transport.requests.Request() credentials.refresh(http_request) except Exception as e: logging.error('Error loading credentials: %s', e) logging.error('Run google-oauthlib-tool to initialize ' 'new OAuth 2.0 credentials.') return grpc_channel = google.auth.transport.grpc.secure_authorized_channel( credentials, http_request, api_endpoint) logging.info('Connecting to %s', api_endpoint) with TextAssistant(lang, query, device_model_id, device_id, True, grpc_channel, grpc_deadline) as assistant: response_text, response_html = assistant.assist(text_query=query) html_file = open( "{}/html/index.html".format( os.path.dirname(os.path.abspath(__file__))), "w") html_file.write(response_html.decode('utf-8')) html_file.close() web_app = QApplication(sys.argv) web_view = QWebEngineView() web_view.load( QUrl.fromLocalFile('{}/html/index.html'.format( os.path.dirname(os.path.abspath(__file__))))) web_view.setZoomFactor(web_view.zoomFactor() * 0.4) web_view.resize(700, 350) web_view.setWindowTitle('Micno with Assistant') desktop = web_app.desktop() geometry = desktop.screenGeometry() framesize = web_view.frameSize() web_view.move(geometry.width() - framesize.width(), geometry.height() - framesize.height()) web_view.show() web_app.exec()
def saveImage(self, image): self.progressdialog.close() # data:image/png;base64,iVBORw0KG.... if not image.startswith('data:image'): return data = base64.b64decode(image.split(';base64,')[1]) image = QPixmap() image.loadFromData(data) # 添加到左侧list中 item = QListWidgetItem(self.widgetRight) item.setIcon(QIcon(image)) item.setData(Qt.UserRole + 1, image) if __name__ == "__main__": # 开启F12 控制台功能,需要单独通过浏览器打开这个页面 # 这里可以做个保护, 发布软件,启动时把这个环境变量删掉。防止他人通过环境变量开启 os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = '9966' sys.excepthook = cgitb.enable(1, None, 5, '') app = QApplication(sys.argv) w = Window() w.show() # 打开调试页面 dw = QWebEngineView() dw.setWindowTitle('开发人员工具') dw.load(QUrl('http://127.0.0.1:9966')) dw.show() dw.move(100, 100) sys.exit(app.exec_())
class PersephonepWindow(QWidget): def __init__(self, parent=None): super(PersephonepWindow, self).__init__() self.initUI(parent=parent) def initUI(self, parent=None): # config initurl = 'https://www.google.co.jp' # setting window self.window = QWebEngineView() # disguise # profile = QWebEngineProfile() # profile.setHttpUserAgent('IE') # page = QWebEnginePage(profile) # self.window.setPage(page) # print( # # Set user agent "{}" # .format( # self.window.page().profile().httpUserAgent() # ) #) # condig url self.window.load(QUrl(initurl)) self.window.resize(1000, 600) self.window.move(200, 200) self.window.setWindowTitle(program_name()) # setting button self.back_button = QPushButton('back') self.back_button.setToolTip('Go back to previous page.') self.back_button.clicked.connect(self.window.back) self.forward_button = QPushButton('forward') self.forward_button.setToolTip('Go to the next page.') self.forward_button.clicked.connect(self.window.forward) self.reload_button = QPushButton('reload') self.reload_button.setToolTip('Reload this page.') self.reload_button.clicked.connect(self.window.reload) self.url_edit = QLineEdit() self.url_edit.setToolTip('URL box') self.move_button = QPushButton('move') self.move_button.setToolTip('Move to the page set at URL box.') self.move_button.clicked.connect(self.loadPage) self.url_edit.returnPressed.connect(self.loadPage) self.home_button = QPushButton('home') self.home_button.setToolTip('Move to the home page.') self.home_button.clicked.connect(self.loadHomePage) # signal catch from moving web pages. self.window.urlChanged.connect(self.updateCurrentUrl) self.window.page().profile().\ downloadRequested.connect(self._downloadRequested) # setting layout grid = QGridLayout() grid.setSpacing(0) grid.addWidget(self.back_button, 1, 0) grid.addWidget(self.forward_button, 1, 1) grid.addWidget(self.reload_button, 1, 2) grid.addWidget(self.url_edit, 1, 3, 1, 10) grid.addWidget(self.move_button, 1, 14) grid.addWidget(self.home_button, 1, 15) grid.addWidget(self.window, 2, 0, 5, 16) self.setLayout(grid) if parent is None: self.resize(1200, 800) self.center() self.setWindowTitle(program_name()) self.show() def center(self): ''' centering widget ''' qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def loadPage(self): ''' move web page which is set at url_edit If the head of move_url equals 'http://' or 'https://', query to google search form. If the head of move_url doed not include above protocol, but the style of *.*.*.*, add http:// to its_head ''' move_url = self.url_edit.text() if self.check_url_protocol_ipv4(move_url): move_url = 'http://' + move_url elif not self.check_url_protocol(move_url): search_word = move_url.replace(' ', '+').replace(' ', '+') google_search_url = \ 'https://www.google.co.jp' \ '/search?ie=utf-8&oe=utf-8&q={}&' \ 'hl=ja&btnG=search'.format(search_word) move_url = google_search_url move_url = QUrl(move_url) self.window.load(move_url) self.updateCurrentUrl() def check_url_protocol(self, move_url): if (move_url[0:7] == 'http://' or move_url[0:8] == "https://" or move_url[0:8] == 'file:///' or move_url[0:6] == 'ftp://'): return True else: return False def check_url_protocol_ipv4(self, move_url): ''' return True if move_url is IPv4 using Regular expression ''' pattern = '(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.)' \ '{3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' return re.match(pattern, move_url) def updateCurrentUrl(self): ''' rewriting url_edit when you move different web page. ''' # current_url = self.window.url().toString() self.url_edit.clear() self.url_edit.insert(self.window.url().toString()) def loadHomePage(self): ''' move to the home page ''' initurl = 'https://www.google.co.jp' self.window.load(QUrl(initurl)) def saveFile(self): print('download') def _downloadRequested(self, item): # QWebEngineDownloadItem # print('downloading to', item.path) item.accept() dw = DownloadWindow(item) dw.show()
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ QWebView with URL """ import sys from PyQt5.QtWidgets import QApplication, QWidget #from PyQt5.QtWebKitWidgets import QWebView from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView from PyQt5.QtCore import QUrl if __name__ == '__main__': app = QApplication(sys.argv) w = QWebView() w.resize(800, 600) w.move(300, 300) w.setWindowTitle('Simple Plot') w.load(QUrl("http://google.com/")) w.show() sys.exit(app.exec_())
class Prueba(QMainWindow): _singleton = None @classmethod def get_instance(cls, *args, **kwargs): if not cls._singleton: cls._singleton = Prueba() return cls._singleton def __init__(self): super().__init__() self.log = {} self.hMiHilo = MiHilo() self.hMiHilo.start() self.hMiHilo.signal_recive.connect(self.recibirMensaje) self.hMiHilo.signal_connected.connect(self.actualizarListaUsuarios) # hMiHilo.finished.connect(self.recibirMensaje) self.initUI() self.show() def initUI(self): # Add core elements for the window self.lblDesign = QLabel("", self) self.lblDesign.setStyleSheet( "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.lblDesign.setMinimumSize(1000, 70) self.img_logo = QLabel(self) pixmap = QPixmap("Images/mini_Teacher3.png") self.img_logo.setPixmap(pixmap) self.img_logo.move(20, -12) self.img_logo.setMinimumSize(100, 100) self.lbl_tittle1 = QLabel("Aula ", self) self.lbl_tittle1.setStyleSheet( "font-weight: b old; color: white; font-family: century gothic; font-size: 32px" ) self.lbl_tittle1.move(415, 90) self.lbl_tittle2 = QLabel("Virtual", self) self.lbl_tittle2.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 32px" ) self.lbl_tittle2.setMinimumSize(110, 30) self.lbl_tittle2.move(507, 90) # This window # self.setFixedSize(1366, 768) self.setFixedSize(1000, 700) self.setWindowTitle('Aula virtual') palette = QPalette() palette.setBrush(QPalette.Background, QBrush(QColor("#1B528A"))) # # Slides # self.lbl_slides = QLabel("", self) # self.lbl_slides.setStyleSheet( # "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px") # self.lbl_slides.setMinimumSize(645, 355) # self.lbl_slides.move(293, 140) # Camera self.lbl_camera = QVBoxLayout() self.web = QWebEngineView(self) settings = QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True) settings = QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.AllowRunningInsecureContent, True) self.web.page().featurePermissionRequested.connect(self.permisos) self.web.page().setUrl( QUrl("http://192.168.43.105:5080/demos/simpleSubscriber.html")) # self.web.load(QUrl("http://localhost:5080/demos/simpleSubscriber.html")) self.web.setMinimumSize(370, 300) self.web.move(60, 140) self.web.show() self.lbl_camera.addWidget(self.web) # self.lbl_camera.setStyleSheet( # "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px") self.lbl_camera # self.lbl_camera. # Chat self.lbl_chat = QLabel("", self) self.lbl_chat.setStyleSheet( "background-color: White; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.lbl_chat.setMinimumSize(645, 220) self.lbl_chat.move(293, 460) self.txt_messages = QTextEdit("", self) self.txt_messages.setStyleSheet( "font-weight: bold; color: black; font-family: century gothic; font-size: 16px" ) self.txt_messages.setMinimumSize(630, 130) self.txt_messages.move(300, 477) self.txt_messages.setReadOnly(True) # Text field self.txt_message = QTextEdit("", self) self.txt_message.setStyleSheet( "font-weight: bold; color: black; font-family: century gothic; font-size: 16px" ) self.txt_message.setMinimumSize(520, 55) self.txt_message.move(300, 615) # Send button self.btn_send = QPushButton('Enviar', self) self.btn_send.move(830, 635) self.btn_send.setStyleSheet( "background-color: #08AE9E; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.btn_send.clicked.connect(self.click) # Student's list self.lbl_list = QLabel("", self) self.lbl_list.setStyleSheet( "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.lbl_list.setMinimumSize(190, 19) self.lbl_list.move(60, 510) self.lbl_last_name_m = QLabel("Alumnos conectados", self) self.lbl_last_name_m.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 15px" ) self.lbl_last_name_m.setMinimumSize(190, 25) self.lbl_last_name_m.move(70, 510) self.list = QListWidget(self) self.list.setMinimumSize(190, 140) self.list.move(60, 540) self.model = QStandardItemModel(self.list) # Set default items self.list.show() # Participation button self.btn_participate = QPushButton('Pedir participacion', self) self.btn_participate.move(60, 460) self.btn_participate.setStyleSheet( "background-color: #08AE9E; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.btn_participate.setMinimumSize(190, 30) # self.btn_participate.clicked.connect(self.btn_participate) # Log out button self.lbl_logout = QLabel('Cerrar sesión', self) self.lbl_logout.move(830, 40) self.lbl_logout.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 14px" ) self.lbl_logout.setMinimumSize(100, 15) # self.lbl_clase = QLabel(self.clase["CLASE"], self) # self.lbl_clase.move(110, 40) # self.lbl_clase.setStyleSheet( # "font-weight: bold; color: white; font-family: century gothic; font-size: 16px") # self.lbl_clase.setMinimumSize(350, 15) # self.btn_logout.clicked.connect(self.btn_participate) # QListView para la lista de alumnos # self.client.enviarMensaje("Hola") # 2F4D6B" # Connect! self.setPalette(palette) self.show() def recibirMensaje(self, mensaje): self.txt_messages.append(mensaje) print("Señal recibida") def actualizarListaUsuarios(self, conectados): self.list.clear() alumnos = conectados for alumno in alumnos: self.list.addItem(alumno) # item = QStandardItem(alumno) # self.model.appendRow(item) # self.list.setModel(self.model) print("Señal recibida") def click(self): transport2 = TSocket.TSocket('localhost', 9090) # Buffering is critical. Raw sockets are very slow transport2 = TTransport.TBufferedTransport(transport2) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport2) # Create a client to use the protocol encoder client = servicios.Client(protocol) transport2.open() # handler = self # processor = servicios.Processor(handler) # transport2 = TSocket.TServerSocket(port=1010) # tfactory = TTransport.TBufferedTransportFactory() # pfactory = TBinaryProtocol.TBinaryProtocolFactory() # server = TServer.TSimpleServer(processor, transport2, tfactory, pfactory) # server.serve() # hMiHilo = MiHilo() # hMiHilo.start() self.msg = self.txt_message.toPlainText() print(self.msg) client.entrarAula("Susana", "localhost", "IA") client.enviarMensaje(self.msg) transport2.close() print("Salida") def permisos(self, url, feature): self.web.page().setFeaturePermission( QUrl("http://localhost:5080/demos/simpleBroadcaster.html"), QWebEnginePage.MediaAudioVideoCapture, QWebEnginePage.PermissionGrantedByUser)
class AutoReport(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): # Report sender _, self.email = self.makeInputCombo('Email', 20, 20, 200, 25, 'email') _, self.password = self.makeInputCombo('Password', 240, 20, 200, 25, 'password') self.password.setEchoMode(QLineEdit.Password); _, self.to = self.makeInputCombo('To', 20, 70, 420, 25, 'to') _, self.cc = self.makeInputCombo('CC', 20, 120, 420, 25, 'cc') _, self.bcc = self.makeInputCombo('BCC', 20, 170, 420, 25, 'bcc') _, self.subject = self.makeInputCombo('Subject template', 20, 220, 200, 25, 'subject') _, self.dateformat = self.makeInputCombo('Date format', 240, 220, 200, 25, 'dateformat') self.prefix = self.makeTextarea('Prefix', 20, 270, 420, 70, 'prefix') self.content = self.makeTextarea('Content', 20, 350, 420, 200, 'content') self.postfix = self.makeTextarea('Postfix', 20, 560, 420, 70, 'postfix') self.sendBtn = self.makeButton('Send', 20, 640, self.send) self.makeSubjectView() self.makeWebView() # Report picker self.loadReports() # Window configurations self.setWindowTitle('Auto Report') self.setFixedSize(1080, 680) self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) self.setBackground() self.show() def loadReports(self): self.reports = [] _ = self.makeLabel('Choose another report', 480, 20) self.createButton = self.makeButton('New report', 990, 20, self.createReport) self.reportTop = 20 for r, d, f in os.walk('sqlite'): for file in f: if '.db' in file: self.appendReport(file) def appendReport(self, file): self.reportTop += 30 name = file[0:-3] btn = self.makeButton(name, 480, self.reportTop, lambda _, file=file : self.loadConfig(file)) self.reports.append(btn) def setBackground(self): palette = self.palette() palette.setColor(self.backgroundRole(), Qt.white) self.setPalette(palette) def loadConfig(self, file): store.use(file) self.email.setText(store.readConfig('email')) self.password.setText(store.readConfig('password')) self.to.setText(store.readConfig('to')) self.cc.setText(store.readConfig('cc')) self.bcc.setText(store.readConfig('bcc')) self.dateformat.setText(store.readConfig('dateformat')) self.subject.setText(store.readConfig('subject')) self.prefix.setPlainText(store.readConfig('prefix')) self.postfix.setPlainText(store.readConfig('postfix')) self.content.setPlainText(store.readConfig('content')) def makeLabel(self, title, left, top): lbl = QLabel(title, self) lbl.move(left, top) return lbl def makeButton(self, title, left, top, callback): btn = QPushButton(title, self) btn.move(left, top) btn.clicked.connect(callback) return btn def makeTextarea(self, title, left, top, width, height, model): ta = QPlainTextEdit(self) ta.move(left, top) ta.resize(width, height) ta.textChanged.connect(lambda : store.writeConfig(model, ta.toPlainText())) return ta def makeInput(self, left, top, width, height, callback = lambda _ : _): le = QLineEdit(self) le.move(left, top) le.resize(width, height) le.textChanged.connect(callback) return le def makeInputCombo(self, title, left, top, width, height, model): title = self.makeLabel(title, left, top) text = self.makeInput(left, top + 15, width, height, lambda text : store.writeConfig(model, text)) return title, text def makeSubjectView(self): self.subjectLabel = self.makeLabel('Subject Preview', 450, 238) self.subjectLabel.resize(440, 20) self.subject.textChanged.connect(lambda text : self.subjectLabel.setText(self.getSubject())) def makeWebView(self): self.web = QWebEngineView(self) self.web.move(450, 270) self.web.resize(620, 390) self.content.textChanged.connect(lambda : self.web.setHtml(self.getBody())) def createReport(self): os.makedirs('sqlite', exist_ok=True) name, ok = QInputDialog.getText(self, 'Input dialog', 'Name of the new report:', QLineEdit.Normal) if ok and name: file = name + '.db' store.use(file) self.appendReport(file) self.update() def getSubject(self): today = datetime.today().strftime(self.dateformat.text()) subject = self.subject.text().format(today) return subject def getBody(self): prefix = self.prefix.toPlainText() content = self.content.toPlainText() postfix = self.postfix.toPlainText() return '<div style="font-family: Arial,Helvetica,sans-serif;"><p>{}</p><p>{}</p><p>{}</p></div>'.format(prefix, content, postfix) def send(self): subject = self.getSubject() body = self.getBody() sendmail( self.email.text(), self.password.text(), self.to.text(), self.cc.text(), self.bcc.text(), subject, body )
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ QWebView with URL """ import sys from PyQt5.QtWidgets import QApplication, QWidget #from PyQt5.QtWebKitWidgets import QWebView from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView from PyQt5.QtCore import QUrl if __name__ == '__main__': app = QApplication(sys.argv) w = QWebView() w.resize(800, 600) w.move(300, 300) w.setWindowTitle('Simple Plot') w.load(QUrl("http://google.com/")); w.show() sys.exit(app.exec_())
self.webview = WebEngineView(self) layout.addWidget(self.webview) layout.addWidget( QPushButton('发送自定义信号', self, clicked=self.webview.sendCustomSignal)) self.webview.windowTitleChanged.connect(self.setWindowTitle) self.webview.load( QUrl.fromLocalFile(os.path.abspath('Data/JsSignals.html'))) if __name__ == '__main__': from PyQt5.QtWidgets import QApplication import sys # 开启F12 控制台功能,需要单独通过浏览器打开这个页面 # 这里可以做个保护, 发布软件,启动时把这个环境变量删掉。防止他人通过环境变量开启 os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = '9966' app = QApplication(sys.argv) w = Window() w.show() w.move(100, 100) # 打开调试页面 dw = QWebEngineView() dw.setWindowTitle('开发人员工具') dw.load(QUrl('http://127.0.0.1:9966')) dw.move(600, 100) dw.show() sys.exit(app.exec_())
flag = 0 filepath = dirpath + '/map0.html' toggle.setText("Cases Map") x.setUrl(QUrl.fromLocalFile(filepath)) else: pass x.show() app = QApplication(sys.argv) w = QMainWindow() w.setWindowTitle('COVID-19 UPDATES') w.setGeometry(10, 10, 1200, 800) x = QWebView(w) x.setUrl(QUrl.fromLocalFile(filepath)) x.move(20, 20) x.resize(700, 600) x.show() toggle = QPushButton("Cases Map", w) toggle.resize(300, 50) toggle.move(210, 650) toggle.clicked.connect(on_toggle) toggle.setStyleSheet("background-color: yellow") lay = QPushButton("Predict", w) lay.resize(200, 50) lay.move(850, 330) lay.clicked.connect(on_predict_cases) lay.setStyleSheet("background-color: green") reset = QPushButton("Reset", w) reset.resize(200, 50)
class ColdwolfWindow(QWidget): def __init__(self, parent=None): super(ColdwolfWindow, self).__init__() self.initUI(parent=parent) def initUI(self, parent=None): initurl = 'https://www.google.com' self.browser = QWebEngineView() self.browser.load(QUrl(initurl)) self.browser.resize(1000, 600) self.browser.move(100, 100) self.browser.setWindowTitle(program_name()) self.browser.settings().setAttribute( QWebEngineSettings.WebRTCPublicInterfacesOnly, True) # button self.back_button = QPushButton('<<') self.back_button.clicked.connect(self.browser.back) self.forward_button = QPushButton('>>') self.forward_button.clicked.connect(self.browser.forward) self.reload_button = QPushButton('Reload') self.reload_button.clicked.connect(self.browser.reload) self.url_edit = QLineEdit() self.url_edit.returnPressed.connect(self.loadPage) self.browser.urlChanged.connect(self.updateUrl) self.home_button = QPushButton('Home') self.home_button.clicked.connect(self.homePage) # layout grid = QGridLayout() grid.setSpacing(10) grid.addWidget(self.back_button, 1, 0) grid.addWidget(self.forward_button, 1, 1) grid.addWidget(self.reload_button, 1, 2) grid.addWidget(self.url_edit, 1, 3, 1, 10) grid.addWidget(self.home_button, 1, 14) grid.addWidget(self.browser, 2, 0, 5, 15) self.setLayout(grid) if parent is None: self.resize(1200, 700) self.center() self.setWindowTitle(program_name()) self.show() def center(self): qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def loadPage(self): move_url = QUrl(self.url_edit.text()) self.browser.load(move_url) self.updateUrl def updateUrl(self): self.url_edit.clear() self.url_edit.insert(self.browser.url().toString()) def homePage(self): move_url = QUrl('https://twitter.com/home') self.browser.load(move_url) self.updateUrl
class WindowClassroom(QMainWindow): URL_TEACHER = "http://localhost:5080/demos/simpleBroadcaster.html" URL_STUDENT = "http://192.168.43.2:5080/demos/simpleSubscriber.html" def __init__(self, client, transport, clase, usuario, nombre): super().__init__() self.btn_participate = QPushButton('Pedir participacion', self) self.setVisible(False) self.client = client self.transport = transport self.clase = clase self.usuario = usuario self.nombre_usuario = nombre self.hMiHilo = MiHilo.get_instance() self.hMiHilo.start() self.hMiHilo.signal_recive.connect(self.recibirMensaje) self.hMiHilo.signal_connected.connect(self.actualizarListaUsuarios) self.hMiHilo.signal_activate_participation.connect( self.activar_btn_participacion) self.hMiHilo.signal_desactivate_participation.connect( self.desactivar_btn_participacion) self.hMiHilo.signal_show_solicitud.connect(self.show_reques) self.hMiHilo.signal_get_control.connect(self.tomar_control_video) self.hMiHilo.signal_leave_control.connect(self.ceder_control_video) # self.hMiHilo.signal_show_solicitud.connect(self.) # self.client=client # self.transport=transport self.initUI() self.show() def initUI(self): # Add core elements for the window # Add core elements for the window self.lblDesign = QLabel("", self) self.lblDesign.setStyleSheet( "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.lblDesign.setMinimumSize(1000, 70) self.img_logo = QLabel(self) pixmap = QPixmap("Images/mini_Teacher3.png") self.img_logo.setPixmap(pixmap) self.img_logo.move(20, -12) self.img_logo.setMinimumSize(100, 100) self.lbl_tittle1 = QLabel("Aula ", self) self.lbl_tittle1.setStyleSheet( "font-weight: b old; color: white; font-family: century gothic; font-size: 32px" ) self.lbl_tittle1.move(415, 90) self.lbl_tittle2 = QLabel("Virtual", self) self.lbl_tittle2.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 32px" ) self.lbl_tittle2.setMinimumSize(110, 30) self.lbl_tittle2.move(507, 90) # This window # self.setFixedSize(1366, 768) self.setFixedSize(1000, 700) self.setWindowTitle('Aula virtual') palette = QPalette() palette.setBrush(QPalette.Background, QBrush(QColor("#1B528A"))) # # Slides # self.lbl_slides = QLabel("", self) # self.lbl_slides.setStyleSheet( # "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px") # self.lbl_slides.setMinimumSize(645, 355) # self.lbl_slides.move(293, 140) # Camera self.lbl_camera = QVBoxLayout() self.web = QWebEngineView(self) settings = QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True) settings = QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.AllowRunningInsecureContent, True) self.web.page().featurePermissionRequested.connect(self.permisos) self.iniciar_video() # self.web.page().setUrl(QUrl("http://localhost:5080/demos/simpleSubscriber.html")) # self.web.load(QUrl("http://localhost:5080/demos/simpleSubscriber.html")) self.web.setMinimumSize(370, 300) self.web.move(60, 140) self.web.show() self.lbl_camera.addWidget(self.web) self.lbl_slides = QVBoxLayout() self.web_slides = QWebEngineView(self) print(self.clase["CARPETA_COMPARTIDA"]) self.web_slides.page().setUrl(QUrl(self.clase["CARPETA_COMPARTIDA"])) # self.web_slides.setEnabled(False) self.web_slides.setMinimumSize(480, 300) self.web_slides.move(450, 140) self.web_slides.show() self.lbl_slides.addWidget(self.web_slides) # self.lbl_camera.setStyleSheet( # "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px") # self.lbl_camera. # Chat self.lbl_chat = QLabel("", self) self.lbl_chat.setStyleSheet( "background-color: White; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.lbl_chat.setMinimumSize(645, 220) self.lbl_chat.move(293, 460) self.txt_messages = QTextEdit("", self) self.txt_messages.setStyleSheet( "font-weight: bold; color: black; font-family: century gothic; font-size: 16px" ) self.txt_messages.setMinimumSize(630, 130) self.txt_messages.move(300, 477) self.txt_messages.setReadOnly(True) # Text field self.txt_message = QTextEdit("", self) self.txt_message.setStyleSheet( "font-weight: bold; color: black; font-family: century gothic; font-size: 16px" ) self.txt_message.setMinimumSize(520, 55) self.txt_message.move(300, 615) # Send button self.btn_send = QPushButton('Enviar', self) self.btn_send.move(830, 635) self.btn_send.setStyleSheet( "background-color: #08AE9E; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.btn_send.clicked.connect(self.click_send) # Student's list self.lbl_list = QLabel("", self) self.lbl_list.setStyleSheet( "background-color: #019A74; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.lbl_list.setMinimumSize(190, 19) self.lbl_list.move(60, 510) self.lbl_last_name_m = QLabel("Alumnos conectados", self) self.lbl_last_name_m.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 15px" ) self.lbl_last_name_m.setMinimumSize(190, 25) self.lbl_last_name_m.move(70, 510) self.list = QListWidget(self) self.list.setMinimumSize(190, 140) self.list.move(60, 540) # self.model = QStandardItemModel(self.list) # # #Set default items # alumnos = ['Ana Paola', 'Susana', 'Erasmo Carlos'] # for alumno in alumnos: # item = QStandardItem(alumno) # self.model.appendRow(item) # # self.list.setModel(self.model) self.list.show() self.iniciar_conectados() #Participation button self.cargar_botones() #Log out button self.lbl_logout = QLabel('Cerrar sesión', self) self.lbl_logout.move(830, 40) self.lbl_logout.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 14px" ) self.lbl_logout.setMinimumSize(100, 15) self.lbl_logout.mousePressEvent = self.click_exit self.lbl_clase = QLabel(self.clase["CLASE"], self) self.lbl_clase.move(110, 40) self.lbl_clase.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 16px" ) self.lbl_clase.setMinimumSize(350, 15) # 2F4D6B" self.setPalette(palette) self.show() def iniciar_video(self): if self.clase["ROL"] == "Alumno": self.web.page().setUrl(QUrl(self.URL_STUDENT)) else: self.web.page().setUrl(QUrl(self.URL_TEACHER)) def cargar_botones(self): if self.clase["ROL"] == "Alumno": self.btn_participate.move(60, 460) self.btn_participate.setStyleSheet( "background-color: #08AE9E; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.btn_participate.setMinimumSize(190, 30) self.btn_participate.setEnabled(False) self.btn_participate.clicked.connect(self.click_participate) else: self.btn_give_participate = QPushButton('Ceder', self) self.btn_give_participate.move(60, 460) self.btn_give_participate.setStyleSheet( "background-color: #08AE9E; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.btn_give_participate.setMinimumSize(60, 30) self.btn_give_participate.setEnabled(False) self.btn_give_participate.clicked.connect( self.click_give_participation) self.btn_recover = QPushButton('Recuperar', self) self.btn_recover.move(160, 460) self.btn_recover.setStyleSheet( "background-color: #08AE9E; font-weight: bold; color: White; font-family: century gothic; font-size: 16px" ) self.btn_recover.setMinimumSize(100, 30) self.btn_recover.setEnabled(False) self.btn_recover.clicked.connect(self.click_recover) def activar_btn_participacion(self): self.btn_participate.setEnabled(True) self.btn_participate.clicked.connect(self.click_participate) def desactivar_btn_participacion(self): self.btn_participate.setEnabled(False) def click_participate(self): self.transport.open() nombre_equipo = socket.gethostname() direccion_equipo = socket.gethostbyname(nombre_equipo) self.client.pedirParticipacion(self.nombre_usuario, direccion_equipo) self.transport.close() def click_give_participation(self): self.lbl_reques.setVisible(False) self.btn_recover.setEnabled(True) self.transport.open() self.client.otorgarParticipacion(self.ip_solicitante) self.lbl_reques.setVisible(False) self.transport.close() def click_recover(self): self.transport.open() self.client.recuperarControl(self.ip_solicitante) self.transport.close() def iniciar_conectados(self): self.transport.open() nombre_equipo = socket.gethostname() direccion_equipo = socket.gethostbyname(nombre_equipo) print(direccion_equipo) self.rol = 1 if self.clase["ROL"] == "Alumno": self.rol = 0 self.client.entrarAula(self.nombre_usuario, direccion_equipo, self.clase["CLASE"], self.rol) # client.entrarAula("Susana González", "localhost", "Inteligencia") self.transport.close() def actualizarListaUsuarios(self, conectados): self.list.clear() alumnos = conectados for alumno in alumnos: self.list.addItem(alumno) # item = QStandardItem(alumno) # self.model.appendRow(item) # self.list.setModel(self.model) print("Señal recibida") def recibirMensaje(self, mensaje): self.txt_messages.append(mensaje) print("Señal recibida") # self.close() # windowClasses = WindowClasses def click_exit(self, event): nombre_equipo = socket.gethostname() direccion_equipo = socket.gethostbyname(nombre_equipo) self.transport.open() self.client.salirAula(self.nombre_usuario, direccion_equipo, self.clase["CLASE"], self.rol) self.transport.close() self.close() # windowClasses=WindowClasses def click_send(self): self.transport.open() self.msg = self.txt_message.toPlainText() print(self.msg) self.txt_message.setText("") self.client.enviarMensaje(self.nombre_usuario + ": " + self.msg, self.clase["CLASE"]) self.transport.close() print("Salida") def ask_participation(self): self.lbl_logout = QLabel('Cerrar sesión', self) self.lbl_logout.move(830, 40) self.lbl_logout.setStyleSheet( "font-weight: bold; color: white; font-family: century gothic; font-size: 14px" ) self.lbl_logout.setMinimumSize(100, 15) self.lbl_logout.mousePressEvent = self.click_exit def ceder_control_video(self): self.web.page().setUrl(QUrl(self.URL_STUDENT)) def tomar_control_video(self): self.web.page().setUrl(QUrl(self.URL_TEACHER)) def show_reques(self, datos_alumno): self.alumno_solicitante = datos_alumno[0] self.ip_solicitante = datos_alumno[1] self.btn_give_participate.setEnabled(True) self.lbl_reques = QLabel( 'Solicitud del control de video de: ' + datos_alumno[0], self) self.lbl_reques.move(60, 110) self.lbl_reques.setStyleSheet( "font-weight: bold; color: orange; font-family: century gothic; font-size: 14px" ) self.lbl_reques.setMinimumSize(500, 15) self.lbl_reques.setVisible(True) def permisos(self, url, feature): self.web.page().setFeaturePermission( QUrl("http://localhost:5080/demos/simpleBroadcaster.html"), QWebEnginePage.MediaAudioVideoCapture, QWebEnginePage.PermissionGrantedByUser)
import sys from PyQt5 import QtWidgets from PyQt5.QtCore import QUrl from PyQt5.QtWidgets import QApplication from PyQt5.QtWebEngineWidgets import QWebEngineView #start my_app my_app = QApplication(sys.argv) #open webpage initurl = 'https://www.google.co.jp' # setting browser browser = QWebEngineView() browser.load(QUrl(initurl)) browser.resize(1000, 600) browser.move(100, 100) browser.show() #sys exit function sys.exit(my_app.exec_())