def __getattribute__(self, name): if name in QmlWrapper._qml_wrapper_attribs: value = super().__getattribute__(name) else: qobject = super().__getattribute__("qobject") if hasattr(qobject, name): value = getattr(qobject, name) QmlWrapper.warn_name_clash(qobject, name) else: value = QQmlProperty.read(qobject, name) if isinstance(value, QJSValue): return value.toVariant() if isinstance(value, BoundSignal): # Workaround for a pqt5 bug where the qmlengine may wait for the first read to property named "name" # to make the auto-generated signal e.g. "nameChanged" active, we thus ensure property named "name" # is read at least once match = re.match(r"\d*(\D+)Changed", name) if match: QQmlProperty.read(qobject, match.group(1)) if isinstance(value, QObject): if name == "qobject": return super().__getattribute__("qobject") wrappers = super().__getattribute__("wrappers") if name not in wrappers: wrappers[name] = QmlWrapper(value) return wrappers[name] return value
def __read_qml_properties(self): controls = self.window.controls self.cursor = int(QQmlProperty.read(self.window.qobject, "cursor")) self.synchronized_cursor = int(self.window.synchronizedCursor) self.player_cursor = int(self.window.playerCursor) self.show_actor = controls.showActor self.show_bbox_2d = controls.showBBox2D self.show_seg_2d = controls.showSeg2D self.show_bbox_3d = controls.showBBox3D self.show_seg_3d = controls.showSeg3D self.show_lanes = controls.showLanes self.conf_threshold = int( controls.confThreshold)/100.0 self.undistort = bool( controls.undistort) self.undistortimage = bool( controls.undistortimage) self.has_referential = controls.hasReferential self.point_size = int( controls.pointSize) self.use_colors = bool( controls.useColors) self.use_box_colors = bool( controls.useBoxColors) self.box_labels_size = int( controls.boxLabelsSize) self.ds_colors = controls.dsColors self.box_2d_colors = controls.box2DColors self.box_3d_colors = controls.box3DColors self.log_scale = bool( controls.logScale) self.is_recording = bool( controls.video) self.category_filter = str( controls.categoryFilter) self.aspect_ratio = float( controls.aspectRatio) self.crops = [controls.cropLeft, controls.cropRight, controls.cropTop, controls.cropBottom]
def get_intervals(self): cursors = QQmlProperty.read(self.leddar_vp.root, "cursors").toVariant() intervals = [] for i in range(len(cursors) // 2): intervals.append((int(cursors[i * 2]), int(cursors[i * 2 + 1]))) return intervals
def _setup_properties(self, window): self.read_properties = \ { 'cursor': lambda: int(QQmlProperty.read(window, "cursor")) , 'recording': lambda: bool(QQmlProperty.read(window, "recording")) , 'cursors': lambda: QQmlProperty.read(window, "cursors").toVariant() , 'datasetPath': lambda: QQmlProperty.read(window, "datasetPath") } self.write_properties = \ { 'cursors': lambda value: QQmlProperty.write(window, "cursors", value) } #TODO: Investigate, for some reason signals won't trigger if we don't read properties beforehand. for _, property in self.read_properties.items(): property()
def _connect_traces_windows(self): self.traces_windows = QQmlProperty.read(self.leddar_vp.root, "tracesWindows").toVariant() self._traces_windows = [] for ds_name, window in self.traces_windows.items(): self._traces_windows.append( TracesWindow(utils.QmlWrapper(window), self.pf, self.synchronized, ds_name))
def set_custom_viewports(self, ds_names, callbacks): QQmlProperty.write(self.leddar_vp.root, "customViewports", ds_names) self.custom_viewport_windows = {} while not all(k in self.custom_viewport_windows for k in ds_names): QApplication.processEvents() self.custom_viewport_windows = QQmlProperty.read( self.leddar_vp.root, "customViewportWindows").toVariant() self.custom_datasources = {} for i, ds in enumerate(ds_names): w = self.custom_viewport_windows[ds] cb = DasCallback(w, self.pf, ds) cb.vp = QQmlProperty.read(w, "viewport") cb.cursor_callback = callbacks[i] def update(context): cursor = int(QQmlProperty.read(context.window, "cursor")) context.cursor_callback(cursor, context) cb.wrap_callback(update) cb.callback() cb.connect_to(w.cursorChanged) cb.connect_to(w.visibleChanged) self.callbacks["custom_viewport_windows"][ds] = cb sensor_type, position, datasource = platform_utils.parse_datasource_name( ds) self.custom_datasources[ds] = { 'sensor_name': f"{sensor_type}_{position}", 'ds_name': datasource, 'full_ds_name': ds, 'size': len(self.synchronized) } QQmlProperty.write(self.leddar_vp.root, "customDatasources", self.custom_datasources) return self.callbacks["custom_viewport_windows"]
def setupUi(self, Notification): msgv = QQuickView() msgv.setSource(QUrl('message.qml')) rootObj = msgv.rootObject() total_width = int(QQmlProperty.read(rootObj, "width")) total_height = int(QQmlProperty.read(rootObj, "height")) self.twidth = total_width self.theight = total_height qmlengine = msgv.engine() qmlengine.addImageProvider("bicimage", BicImageProvider()) rootObj.findChild(QObject, "img").setProperty( "source", "image://bicimage/" + Notification.mssg["icon"]) rootObj.findChild(QObject, "textprocess").setProperty( "text", Notification.mssg["process"]) rootObj.findChild(QObject, "filename").setProperty("text", Notification.mssg["file"]) rootObj.findChild(QObject, "textaction").setProperty( "text", Notification.mssg["action"]) rootObj.findChild(QObject, "textaction").setProperty("color", Notification.mssg["color"]) rootObj.findChild(QObject, "timestr").setProperty("text", Notification.mssg["time"]) Notification.setObjectName(_fromUtf8("Notification")) Notification.setMinimumSize(QtCore.QSize(total_width, total_height)) Notification.setMaximumSize(QtCore.QSize(total_width, total_height)) # Notification.setWindowOpacity(1.0) # Notification.setAutoFillBackground(False) # Notification.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) centralwidget = QWidget.createWindowContainer(msgv) centralwidget.setObjectName(_fromUtf8("centralwidget")) Notification.setCentralWidget(centralwidget)
def _generateJson(self, node: QQuickItem, offset: int) -> str: s = (' ' * (offset) * 4) + '{\n' s += (' ' * (offset + 1) * 4) + self['_generate' + QQmlProperty.read(node, 'actualName')](node) s += (' ' * (offset + 1) * 4) + "'x': " + str(node.x()) + ',\n' s += (' ' * (offset + 1) * 4) + "'y': " + str(node.y()) + ',\n' s += (' ' * (offset + 1) * 4) + "'children': [\n" rightPoint = QQmlProperty.read(node, '_rightPoint') if rightPoint is not None: try: arrows = QQmlProperty.read(rightPoint, 'arrows') if arrows.isArray(): for i in range(0, arrows.property('length').toInt()): arrow = arrows.property(i).toQObject() leftPoint = QQmlProperty.read(arrow, 'leftPoint') s += self._generateJson(leftPoint.parent(), offset + 2) + ',\n' except Exception as e: print(e) s += (' ' * (offset + 1) * 4) + '],\n' s += (' ' * (offset) * 4) + '}' return s
def dumpQMLComponents(self, root): children = root.findChildren(QObject) for item in children: # Note the QML id property is NOT the objectName print(item, "name is:", item.objectName()) try: ''' Apparently you can't just access item's properties: item.id Also, the id property apparently is not accessible via QQmlProperty. ''' foo = QQmlProperty.read(item, "shoeSize") print("shoeSize property:", foo) except AttributeError: pass
def dumpQMLComponents(self, root): children = root.findChildren(QObject) for item in children: # Note the QML id property is NOT the objectName print(item, "name is:", item.objectName()) try: """ Apparently you can't just access item's properties: item.id Also, the id property apparently is not accessible via QQmlProperty. """ foo = QQmlProperty.read(item, "shoeSize") print("shoeSize property:", foo) except AttributeError: pass
def update(context): cursor = int(QQmlProperty.read(context.window, "cursor")) context.cursor_callback(cursor, context)
def read_property(self, name:str): self._check_view() return QQmlProperty.read(self.root, name, self.engine)
def __getitem__(self, property_name): ''' Useful to force using QQmlProperty.read() in the case of a name clash ''' return QQmlProperty.read(self.qobject, property_name)