def main(): app = QApplication([]) QtWebEngine.initialize() engine = QQmlApplicationEngine() qml_file_path = os.path.join(os.path.dirname(__file__), 'browser.qml') qml_url = QUrl.fromLocalFile(os.path.abspath(qml_file_path)) engine.load(qml_url) app.exec_()
def set_texture(self, img_path: Path) -> None: # This is from https://stackoverflow.com/q/49887994/2826337 # and from https://forum.qt.io/topic/106370/qdiffusespecularmaterial-diffuse-texture/4 # noqa: E501 loader = Qt3DRender.QTextureLoader(self.entity) local_pathname = os.fspath(img_path.resolve()) img_url = QUrl.fromLocalFile(local_pathname) loader.setSource(img_url) self.material.setDiffuse(loader)
def create_ngl_widget(engine): # Dynamically create an instance of the rendering widget widget_url = QUrl.fromLocalFile(op.join(op.dirname(__file__), "NodeGLWidget.qml")) component = QQmlComponent(engine) component.loadUrl(widget_url) widget = component.create() # Inject it live into its placeholder app_window = engine.rootObjects()[0] placeholder = app_window.findChild(QObject, "ngl_widget_placeholder") widget.setParentItem(placeholder) return widget
def get_MIME(files_as_indexes: List[QModelIndex]) -> Tuple[List[str], List[QUrl]]: """ Converts the given files to their MIME data. :param files_as_indexes: List of indexes of files. :type files_as_indexes: List[QModelIndex] :return: files as str list of path and the MIME data of the given files. :rtype: Tuple[List[str], List[QUrl]] """ files_as_path = indexes_to_paths(files_as_indexes) file_urls = [] for file in files_as_path: file_urls.append(QUrl.fromLocalFile(file)) mime_data = QMimeData() mime_data.setUrls(file_urls) return files_as_path, mime_data
def launch(self): QDesktopServices.openUrl(QUrl.fromLocalFile(self.fileName))
colorChanged = Signal() color = Property(QColor, getColor, setColor, notify=colorChanged) name = Property(str, getName, setName) chartCleared = Signal() @Slot() # This should be something like @Invokable def clearChart(self): self.setColor(Qt.transparent) self.update() self.chartCleared.emit() if __name__ == '__main__': app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) if view.status() == QQuickView.Error: sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances # are destroyed in the correct order. del view sys.exit(res)
url = "http://country.io/names.json" response = urllib.request.urlopen(url) data = json.loads(response.read().decode('utf-8')) # print("data",data) # Format and sort the data data_list = list(data.values()) # print("data_list", data_list) data_list.sort() # Set up the application window app = QGuiApplication(sys.argv) view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) # Expose the list to the Qml code my_model = QStringListModel() my_model.setStringList(data_list) view.rootContext().setContextProperty("myModel", my_model) # Load the QML file qml_file = Path(__file__).parent / "main_view.qml" view.setSource(QUrl.fromLocalFile(os.fspath(qml_file.resolve()))) # Show the window if view.status() == QQuickView.Error: sys.exit(-1) view.show() # execute and cleanup app.exec() del view
painter.drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10) if self.rightAligned: points = [ QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0), QPointF(itemSize.width() - 20.0, itemSize.height()), QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0), ] else: points = [ QPointF(10.0, itemSize.height() - 10.0), QPointF(20.0, itemSize.height()), QPointF(30.0, itemSize.height() - 10.0), ] painter.drawConvexPolygon(points) if __name__ == "__main__": app = QApplication(sys.argv) view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qmlRegisterType(TextBalloon, "TextBalloonPlugin", 1, 0, "TextBalloon") view.setSource(QUrl.fromLocalFile("main.qml")) if view.status() == QQuickView.Error: sys.exit(-1) view.show() sys.exit(app.exec_())
all_devices = sd.query_devices() mme_devices = [] mme_id = -1 for idx, device in enumerate(sd.query_hostapis()): if "MME" in device["name"]: mme_id = idx break for device in all_devices: if device["hostapi"] == mme_id and device["max_output_channels"] > 0: mme_devices.append(device["name"]) return mme_devices if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() sounddevices = get_devices() model = SoundBoard.SoundBoard(sounddevices) engine.rootContext().setContextProperty("soundbuttons", model.soundbuttons) engine.rootContext().setContextProperty("sounddevices", sounddevices) engine.rootContext().setContextProperty("logicmodel", model) qml_file = os.path.join(os.path.dirname(__file__), "app.qml") engine.load(QUrl.fromLocalFile(os.path.abspath(qml_file))) app.aboutToQuit.connect(model.handle_close) app.exec_()
def open_file(file): QDesktopServices.openUrl(QUrl.fromLocalFile(file))
server = QWebSocketServer("QWebChannel Standalone Example Server", QWebSocketServer.NonSecureMode) if not server.listen(QHostAddress.LocalHost, 12345): print("Failed to open web socket server.") sys.exit(-1) # wrap WebSocket clients in QWebChannelAbstractTransport objects clientWrapper = WebSocketClientWrapper(server) # setup the channel channel = QWebChannel() clientWrapper.clientConnected.connect(channel.connectTo) # setup the UI dialog = Dialog() # setup the core and publish it to the QWebChannel core = Core(dialog) channel.registerObject("core", core) # open a browser window with the client HTML page url = QUrl.fromLocalFile(cur_dir + "/index.html") QDesktopServices.openUrl(url) message = "Initialization complete, opening browser at {}.".format( url.toDisplayString()) dialog.displayMessage(message) dialog.show() sys.exit(app.exec_())
def browseSnippets(self): url = QUrl.fromLocalFile(snippetPath) QDesktopServices.openUrl(url)
class Plot(Visualization): type_id = "plot" type_name = "Plot" qml_path = QUrl.fromLocalFile(str((BASE_PATH / "Plot.qml").resolve())) def __init__(self, name, service): super().__init__(name, service) matplotlib.style.use(BASE_PATH / "dark.mplstyle") self._figure, self._main_axes = subplots() self._lines = {} self._axes = {} self._canvas = FigureCanvasQQuickAgg(self._figure) self._animation = FuncAnimation(self._figure, self._update, interval=33) self._figure.canvas.draw_idle() @Visualization.outputs.setter def outputs(self, value): for output_id in set(value) - set(self.outputs): output = self.service.plugin.app.get("outputs", output_id) if len(self.outputs) < 1: axes = self._main_axes else: axes = self._main_axes.twinx() axes.spines["right"].set_position( ("outward", 48 * (len(self.outputs) - 1))) axes.set_xlim(*output.x_limits) axes.set_ylim(*output.y_limits) self._axes[output_id] = axes self._figure.canvas.draw_idle() self._outputs = value @property def figure(self): return self._figure def _update(self, y): changed_lines = [] for output_id in self.outputs: output = self.service.plugin.app.get("outputs", output_id) if output.data is None: continue x = np.linspace(*output.x_limits, len(output.data)) y = output.data if output_id not in self._lines: self._lines[output_id] = self._axes[output_id].plot( x, y, color=output.color)[0] continue self._lines[output_id].set_data(x, y) changed_lines.append(self._lines[output_id]) return changed_lines
time_cnt = time_cnt + 1 #print(time_cnt) label.send_text.emit(str(time_cnt)) if __name__ == '__main__': app = QGuiApplication(sys.argv) timer = QTimer() timer.start(1000) view = QQuickView() qml_file = "Source/away_from_keyboard/qml_test3.qml" view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) root = view.rootObject() timer.timeout.connect(root.updateRotater) #timer.timeout.connect(root.updateTime, text) timer.timeout.connect(time_out) label = PyLabel() label.send_text.connect(root.updateTime) con = Console() # Expose the object to QML.
def url_from_file(self, f): return QUrl.fromLocalFile(f)
def previewInput(self, item: QListWidgetItem): QDesktopServices.openUrl( QUrl.fromLocalFile(str(self._input_folder / item.text())))