Exemple #1
0
 def show_album(self, album):
     if album:
         self.albums.setCurrentIndex(self.albums.findData(album.id.text))
         self.widgets['description'].set_value(album.summary.text)
         self.widgets['location'].setText(album.location.text)
         self.widgets['access'].setCurrentIndex(
             self.widgets['access'].findData(album.access.text))
         self.widgets['timestamp'].setDateTime(
             QtCore.QDateTime.fromTime_t(int(album.timestamp.text) // 1000))
         if album.group.thumbnail is not None:
             QtWidgets.QApplication.processEvents()
             with Busy():
                 url = album.group.thumbnail[0].get('url')
                 image = QtGui.QPixmap(160, 160)
                 try:
                     image.loadFromData(urlopen(url).read())
                 except HTTPError as ex:
                     paint = QtGui.QPainter(image)
                     paint.fillRect(image.rect(), Qt.black)
                     paint.setPen(Qt.white)
                     paint.drawText(image.rect(),
                                    Qt.AlignLeft | Qt.TextWordWrap, str(ex))
                     paint.end()
                 self.album_thumb.setPixmap(image)
     else:
         self.widgets['description'].set_value(None)
         self.widgets['location'].clear()
         self.widgets['timestamp'].clear()
         self.album_thumb.clear()
Exemple #2
0
 def mouseMoveEvent(self, event):
     if not self.image_list.drag_icon:
         return
     if qt_version_info >= (6, 0):
         pos = event.position()
     else:
         pos = event.pos()
     if ((pos - self.drag_start_pos).manhattanLength() <
             QtWidgets.QApplication.startDragDistance()):
         return
     if not self.get_selected():
         # user has started dragging an unselected image
         self.image_list.select_image(self)
     paths = []
     for image in self.image_list.get_selected_images():
         paths.append(image.path)
     if not paths:
         return
     drag = QtGui.QDrag(self)
     # construct icon
     count = min(len(paths), 8)
     src_icon = self.image_list.drag_icon
     src_w = src_icon.width()
     src_h = src_icon.height()
     margin = (count - 1) * 4
     if count == 1:
         icon = src_icon
     else:
         icon = QtGui.QPixmap(src_w + margin, src_h + margin)
         icon.fill(Qt.transparent)
         try:
             paint = QtGui.QPainter(icon)
             for i in range(count):
                 paint.drawPixmap(QtCore.QPoint(margin - (i * 4), i * 4),
                                  src_icon)
         finally:
             del paint
     drag.setPixmap(icon)
     if self.image_list.drag_hotspot:
         x, y = self.image_list.drag_hotspot
     else:
         x, y = src_w // 2, src_h
     drag.setHotSpot(QtCore.QPoint(x, y + margin))
     mimeData = QtCore.QMimeData()
     mimeData.setData(DRAG_MIMETYPE, repr(paths).encode('utf-8'))
     drag.setMimeData(mimeData)
     if qt_version_info >= (6, 0):
         drag.exec(Qt.CopyAction)
     else:
         drag.exec_(Qt.CopyAction)
Exemple #3
0
 def get_album_thumb(self, album):
     if album.group.thumbnail is None:
         return None
     image = QtGui.QPixmap(160, 160)
     try:
         resp = self._check_response(
             self.session.get(album.group.thumbnail[0].get('url')))
         image.loadFromData(resp.content)
     except Exception as ex:
         paint = QtGui.QPainter(image)
         paint.fillRect(image.rect(), Qt.black)
         paint.setPen(Qt.white)
         paint.drawText(image.rect(), Qt.AlignLeft | Qt.TextWordWrap, str(ex))
         paint.end()
     return image
Exemple #4
0
 def mouseMoveEvent(self, event):
     if not self.image_list.drag_icon:
         return
     if ((event.pos() - self.drag_start_pos).manhattanLength() <
                                 QtWidgets.QApplication.startDragDistance()):
         return
     paths = []
     for image in self.image_list.get_selected_images():
         paths.append(image.path)
     if not paths:
         return
     drag = QtGui.QDrag(self)
     # construct icon
     count = min(len(paths), 8)
     src_icon = self.image_list.drag_icon
     src_w = src_icon.width()
     src_h = src_icon.height()
     margin = (count - 1) * 4
     if count == 1:
         icon = src_icon
     else:
         icon = QtGui.QPixmap(src_w + margin, src_h + margin)
         icon.fill(Qt.transparent)
         with QtGui.QPainter(icon) as paint:
             for i in range(count):
                 paint.drawPixmap(
                     QtCore.QPoint(margin - (i * 4), i * 4), src_icon)
     drag.setPixmap(icon)
     if src_h == src_w:
         # round marker used in Bing maps version 8
         drag.setHotSpot(QtCore.QPoint(src_w // 2, (src_h // 2) + margin))
     else:
         drag.setHotSpot(QtCore.QPoint(src_w // 2, src_h + margin))
     mimeData = QtCore.QMimeData()
     mimeData.setData(DRAG_MIMETYPE, repr(paths).encode('utf-8'))
     drag.setMimeData(mimeData)
     dropAction = drag.exec_(Qt.CopyAction)