class SceneItemWidget(QFrame): def __init__(self, scene): QWidget.__init__(self) self.scene = scene self.properties = scene[PROPERTIES] self.setMouseTracking(True) datetime = iso8601.parse_date(self.properties["acquired"]) time = datetime.strftime("%H:%M:%S") date = datetime.strftime("%b %d, %Y") text = f"""{date}<span style="color: rgb(100,100,100);"> {time} UTC</span><br> <b>{PlanetClient.getInstance().item_types_names()[self.properties['item_type']]}</b> """ self.nameLabel = QLabel(text) self.iconLabel = QLabel() self.toolsButton = QLabel() self.toolsButton.setPixmap(COG_ICON.pixmap(QSize(18, 18))) self.toolsButton.mousePressEvent = self.showContextMenu pixmap = QPixmap(PLACEHOLDER_THUMB, "SVG") thumb = pixmap.scaled(48, 48, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.iconLabel.setPixmap(thumb) layout = QHBoxLayout() layout.setMargin(2) vlayout = QVBoxLayout() vlayout.setMargin(0) vlayout.addWidget(self.iconLabel) self.iconWidget = QWidget() self.iconWidget.setFixedSize(48, 48) self.iconWidget.setLayout(vlayout) layout.addWidget(self.iconWidget) layout.addWidget(self.nameLabel) layout.addStretch() layout.addWidget(self.toolsButton) layout.addSpacing(10) self.setLayout(layout) self.nam = QNetworkAccessManager() self.nam.finished.connect(self.iconDownloaded) url = f"{scene['_links']['thumbnail']}?api_key={PlanetClient.getInstance().api_key()}" self.nam.get(QNetworkRequest(QUrl(url))) self.footprint = QgsRubberBand(iface.mapCanvas(), QgsWkbTypes.PolygonGeometry) self.footprint.setStrokeColor(PLANET_COLOR) self.footprint.setWidth(2) self.geom = qgsgeometry_from_geojson(scene[GEOMETRY]) self.setStyleSheet("SceneItemWidget{border: 2px solid transparent;}") def showContextMenu(self, evt): menu = QMenu() add_menu_section_action("Current item", menu) zoom_act = QAction("Zoom to extent", menu) zoom_act.triggered.connect(self.zoom_to_extent) menu.addAction(zoom_act) open_act = QAction("Open in Search Panel", menu) open_act.triggered.connect(self.open_in_explorer) menu.addAction(open_act) menu.exec_(self.toolsButton.mapToGlobal(evt.pos())) def open_in_explorer(self): from .pe_explorer_dockwidget import show_explorer_and_search_daily_images request = build_search_request(string_filter("id", self.scene[ID]), [self.properties[ITEM_TYPE]]) show_explorer_and_search_daily_images(request) def zoom_to_extent(self): rect = QgsRectangle(self.geom.boundingBox()) canvasCrs = iface.mapCanvas().mapSettings().destinationCrs() transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem(4326), canvasCrs, QgsProject.instance()) newrect = transform.transform(rect) newrect.scale(1.05) iface.mapCanvas().setExtent(newrect) iface.mapCanvas().refresh() def iconDownloaded(self, reply): img = QImage() img.loadFromData(reply.readAll()) pixmap = QPixmap(img) thumb = pixmap.scaled(48, 48, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.iconLabel.setPixmap(thumb) def show_footprint(self): rect = QgsRectangle(self.geom.boundingBox()) canvasCrs = iface.mapCanvas().mapSettings().destinationCrs() transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem(4326), canvasCrs, QgsProject.instance()) newrect = transform.transform(rect) self.footprint.setToGeometry(QgsGeometry.fromRect(newrect)) def hide_footprint(self): self.footprint.reset(QgsWkbTypes.PolygonGeometry) def enterEvent(self, event): self.setStyleSheet( "SceneItemWidget{border: 2px solid rgb(0, 157, 165);}") self.show_footprint() def leaveEvent(self, event): self.setStyleSheet("SceneItemWidget{border: 2px solid transparent;}") self.hide_footprint()