Best Python code snippet using playwright-python
dialogs.py
Source:dialogs.py
1from PyQt5.QtWidgets import QPushButton, QDialog, QWidget, QLabel, QGridLayout, QLineEdit, QApplication2import sys3class MyDialog(QDialog):4 def __init__(self, parent, caption, **kwargs):5 super(MyDialog, self).__init__(parent)6 self.caption = caption7 self.kwargs = kwargs8 self.entries = {}9 self.result = {}10 self.initUI()11 def initUI(self):12 layout = QGridLayout()13 self.setLayout(layout)14 self.setModal(True)15 layout.setColumnStretch(1, 4)16 layout.setColumnStretch(2, 4)17 row = 018 for n,v in self.kwargs.items():19 label = QLabel('%s:'%n)20 layout.addWidget(label, row, 0)21 edt = QLineEdit(self)22 edt.setText(v)23 layout.addWidget(edt, row, 1)24 self.entries[n] = edt25 row += 126 ok = QPushButton('OK')27 ok.clicked.connect(self.onOkBtn)28 layout.addWidget(ok, row, 0)29 cancel = QPushButton('Cancel')30 cancel.clicked.connect(self.onCancelBtn)31 layout.addWidget(cancel, row, 1)32 self.result = {}33 def onOkBtn(self):34 for n,edt in self.entries.items():35 self.result[n] = edt.text()36 self.close()37 def onCancelBtn(self):38 self.result = {}39 self.close()40 def run(self):41 self.exec_()42 return self.result43def makeEdit(parent, layout, caption, value, row, editedHandler=None):44 label = QLabel(caption)45 layout.addWidget(label, row, 0)46 result = QLineEdit(parent)47 result.setText(str(value))48 layout.addWidget(result, row, 1)49 if editedHandler:50 result.textEdited.connect(editedHandler)51 return result52def makeButton(parent, layout, caption, clicked, row, col):53 result = QPushButton(caption)54 result.clicked.connect(clicked)55 layout.addWidget(result, row, col)56 return result57def makeOkCancelButtons(parent, layout, clicked1, clicked2, row):58 return makeButton(parent, layout, '&Ok', clicked1, row, 0),\59 makeButton(parent, layout, '&Cancel', clicked2, row, 1)60class BrightnessConstrastFrame(QWidget):61 def __init__(self, parent, brightness, contrast, onclose, onbrightness, oncontrast):62 super(BrightnessConstrastFrame, self).__init__(parent)63 layout = QGridLayout()64 # layout.setColumnStretch(1, 4)65 # layout.setColumnStretch(2, 4)66 self.brightnessEdt = makeEdit(self, layout, 'Brightness:', brightness, 0, onbrightness)67 self.contrastEdt = makeEdit(self, layout, 'Contrast:', contrast, 1, oncontrast)68 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 2)69 self.setLayout(layout)70 self.onclose = onclose71 def onOkBtn(self):72 self.close()73 QApplication.processEvents()74 self.onclose((float(self.brightnessEdt.text()), float(self.contrastEdt.text())))75 def onCancelBtn(self):76 self.close()77 QApplication.processEvents()78 self.onclose(None)79class ConstrastFrame(QWidget):80 def __init__(self, parent, contrast, onclose):81 super(ConstrastFrame, self).__init__(parent)82 layout = QGridLayout()83 # layout.setColumnStretch(1, 4)84 # layout.setColumnStretch(2, 4)85 self.contrastEdt = makeEdit(self, layout, 'Contrast:', contrast, 1)86 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 2)87 self.setLayout(layout)88 self.onclose = onclose89 def onOkBtn(self):90 self.close()91 QApplication.processEvents()92 self.onclose(float(self.contrastEdt.text()))93 def onCancelBtn(self):94 self.close()95 QApplication.processEvents()96 self.onclose(None)97class NumValFrame(QWidget):98 def __init__(self, parent, name, value, onclose):99 super(NumValFrame, self).__init__(parent)100 layout = QGridLayout()101 # layout.setColumnStretch(1, 4)102 # layout.setColumnStretch(2, 4)103 self.edt = makeEdit(self, layout, name, value, 1)104 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 2)105 self.setLayout(layout)106 self.onclose = onclose107 def onOkBtn(self):108 self.close()109 QApplication.processEvents()110 self.onclose(float(self.edt.text()))111 def onCancelBtn(self):112 self.close()113 QApplication.processEvents()114 self.onclose(None)115class OrtonFrame(QWidget):116 #d = EntriesDialog(win.master, "Orthon effect", (("Main image brightness:","1.1"),117 # ("Blured image brightness:","1.3"), ("Blured image zoom:","1.01"), ("Blend alpha:","0.3"),))118 def __init__(self, parent, brightness, brightness2, zoom, alpha, onclose):119 #super(OrtonFrame, self).__init__(parent)120 super().__init__(parent)121 layout = QGridLayout()122 # layout.setColumnStretch(1, 4)123 # layout.setColumnStretch(2, 4)124 self.brightnessEdt = makeEdit(self, layout, 'Main image brightness:', brightness, 0)125 self.brightness2Edt = makeEdit(self, layout, 'Blured image brightness:', brightness2, 1)126 self.zoomEdt = makeEdit(self, layout, 'Blured image zoom:', zoom, 2)127 self.alphaEdt = makeEdit(self, layout, 'Blend alpha:', alpha, 3)128 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 4)129 self.setLayout(layout)130 self.onclose = onclose131 def onOkBtn(self):132 self.close()133 QApplication.processEvents()134 self.onclose((135 float(self.brightnessEdt.text()),136 float(self.brightness2Edt.text()),137 float(self.zoomEdt.text()),138 float(self.alphaEdt.text())139 ))140 def onCancelBtn(self):141 self.close()142 QApplication.processEvents()143 self.onclose(None)144if __name__ == '__main__':145 from fbs_runtime.application_context.PyQt5 import ApplicationContext146 appctxt = ApplicationContext()147 appctxt.app.setStyle('Fusion')148 #w = MyDialog(None, one='1',two='2')149 w = MyDialog(None, 'test', **{'one':'1','two':'2'})150 w.show() # real app should call w.run() which returns result dictionary151 exit_code = appctxt.app.exec_()152 for n,v in w.result.items():153 print(n,v)...
Examples_test.py
Source:Examples_test.py
...42 class FileWatchDog():43 def onOpen(self, fileName, openMode):44 print(f"File {fileName} opened with {openMode} mode")4546 def onClose(self, fileName):47 print(f"File {fileName} closed")484950 def onOpenStandaloneMethod(fileName, openMode):51 print(f"StandaloneMethod: File {fileName} opened with {openMode} mode")5253 watchDog = FileWatchDog()5455 notifier = Notifier(["onCreate", "onOpen", "onModify", "onClose", "onDelete"])5657 notifier.subscribe("onOpen", watchDog.onOpen)58 notifier.subscribe("onOpen", onOpenStandaloneMethod)59 notifier.subscribe("onClose", watchDog.onClose)6061 print("\nAfter subscription:")62 notifier.raise_event("onOpen", openMode="w+", fileName="test_file.txt")63 notifier.raise_event("onClose", fileName="test_file.txt")6465 notifier.remove_subscribers_by_event_name("onOpen")6667 print("\nAfter removal of onOpen subscribers:")68 notifier.raise_event("onOpen", openMode="w+", fileName="test_file.txt")69 notifier.raise_event("onClose", fileName="test_file.txt")7071 notifier.remove_subscribers_by_event_name("onClose")7273 print("\nAfter removal of onClose subscribers:")74 notifier.raise_event("onOpen", openMode="w+", fileName="test_file.txt")75 notifier.raise_event("onClose", fileName="test_file.txt")76777879 def test_remove_all_subscribers(self):80 from EventNotifier import Notifier81 class FileWatchDog():82 def onOpen(self, fileName, openMode):83 print(f"File {fileName} opened with {openMode} mode")8485 def onClose(self, fileName):86 print(f"File {fileName} closed")878889 def onOpenStandaloneMethod(fileName, openMode):90 print(f"StandaloneMethod: File {fileName} opened with {openMode} mode")9192 watchDog = FileWatchDog()9394 notifier = Notifier(["onCreate", "onOpen", "onModify", "onClose", "onDelete"])9596 notifier.subscribe("onOpen", watchDog.onOpen)97 notifier.subscribe("onOpen", onOpenStandaloneMethod)98 notifier.subscribe("onClose", watchDog.onClose)99
...
org_apache_sling_scripting_core_impl_scripting_resource_resolver_provider_properties.py
Source:org_apache_sling_scripting_core_impl_scripting_resource_resolver_provider_properties.py
1# coding: utf-82from __future__ import absolute_import3from datetime import date, datetime # noqa: F4014from typing import List, Dict # noqa: F4015from openapi_server.models.base_model_ import Model6from openapi_server.models.config_node_property_boolean import ConfigNodePropertyBoolean # noqa: F401,E5017from openapi_server import util8class OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties(Model):9 """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).10 Do not edit the class manually.11 """12 def __init__(self, log_stacktrace_onclose: ConfigNodePropertyBoolean=None): # noqa: E50113 """OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties - a model defined in OpenAPI14 :param log_stacktrace_onclose: The log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties. # noqa: E50115 :type log_stacktrace_onclose: ConfigNodePropertyBoolean16 """17 self.openapi_types = {18 'log_stacktrace_onclose': ConfigNodePropertyBoolean19 }20 self.attribute_map = {21 'log_stacktrace_onclose': 'log.stacktrace.onclose'22 }23 self._log_stacktrace_onclose = log_stacktrace_onclose24 @classmethod25 def from_dict(cls, dikt) -> 'OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties':26 """Returns the dict as a model27 :param dikt: A dict.28 :type: dict29 :return: The orgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties. # noqa: E50130 :rtype: OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties31 """32 return util.deserialize_model(dikt, cls)33 @property34 def log_stacktrace_onclose(self) -> ConfigNodePropertyBoolean:35 """Gets the log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.36 :return: The log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.37 :rtype: ConfigNodePropertyBoolean38 """39 return self._log_stacktrace_onclose40 @log_stacktrace_onclose.setter41 def log_stacktrace_onclose(self, log_stacktrace_onclose: ConfigNodePropertyBoolean):42 """Sets the log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.43 :param log_stacktrace_onclose: The log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.44 :type log_stacktrace_onclose: ConfigNodePropertyBoolean45 """...
websocket_client_threaded.py
Source:websocket_client_threaded.py
1import threading, Queue2from amitu import websocket_client3class _Writer(threading.Thread):4 def __init__(self, ws):5 super(_Writer, self).__init__()6 self.daemon = True7 self.ws = ws8 self.queue = Queue.Queue()9 def send(self, data):10 self.queue.put(data)11 def run(self):12 while True:13 self.ws._send(self.queue.get(block=True))14class WebSocket(websocket_client.WebSocket):15 """16 Threaded WebSocket class17 Use this class to use a threaded websocket. It reads data from server18 on the current thread, and sends data on a separate daemon thread.19 >>> def onmessage(message): print "onmessage", message20 ...21 >>> def onopen(): print "onopen"22 ...23 >>> def onclose(): print "onclose"24 ...25 >>> ws = WebSocket("ws://server.com:8080/path")26 >>> ws.onopen(onopen)27 >>> ws.onclose(onclose)28 >>> ws.onmessage(onmessage)29 >>> ws.run() # blocks30 """31 def __init__(self, *args, **kw):32 websocket_client.WebSocket.__init__(self, *args, **kw)33 self.writer = _Writer(self)34 self.onopen_handlers = []35 self.onclose_handlers = []36 self.onmessage_handlers = []37 def run(self):38 self.writer.start()39 websocket_client.WebSocket.run(self)40 def send(self, data):41 self.writer.send(data)42 def _fire_onopen(self):43 for cb in self.onopen_handlers: cb()44 def _fire_onmessage(self, data):45 for cb in self.onmessage_handlers: cb(data)46 def _fire_onclose(self):47 for cb in self.onclose_handlers: cb()48 def onopen(self, cb): self.onopen_handlers.append(cb)49 def onmessage(self, cb): self.onmessage_handlers.append(cb)50 def onclose(self, cb): self.onclose_handlers.append(cb)51class WebSocketThreaded(WebSocket, threading.Thread):52 """53 WebSocketThreaded54 This is a thread that runs in the background, reading and writing both55 in two different threads.56 >>> def onmessage(message): print "onmessage", message57 ...58 >>> def onopen(): print "onopen"59 ...60 >>> def onclose(): print "onclose"61 ...62 >>> ws = WebSocketThreaded("ws://server.com:8080/path")63 >>> ws.onopen(onopen)64 >>> ws.onclose(onclose)65 >>> ws.onmessage(onmessage)66 >>> ws.start()67 >>> ws.wait()68 """69 def __init__(self, *args, **kw):70 WebSocket.__init__(self, *args, **kw)...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!