Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
layout.setContentsMargins(0, 0, 0, 0)
self.members = {}
for key in ('sublocation', 'city', 'province_state',
'country_name', 'country_code', 'world_region'):
self.members[key] = SingleLineEdit()
self.members[key].editingFinished.connect(self.editing_finished)
self.members['country_code'].setMaximumWidth(40)
for j, text in enumerate((
translate('AddressTab', 'Street'),
translate('AddressTab', 'City'),
translate('AddressTab', 'Province'),
translate('AddressTab', 'Country'),
translate('AddressTab', 'Region'),
)):
label = QtWidgets.QLabel(text)
label.setAlignment(Qt.AlignRight)
layout.addWidget(label, j, 0)
layout.addWidget(self.members['sublocation'], 0, 1, 1, 2)
layout.addWidget(self.members['city'], 1, 1, 1, 2)
layout.addWidget(self.members['province_state'], 2, 1, 1, 2)
layout.addWidget(self.members['country_name'], 3, 1)
layout.addWidget(self.members['country_code'], 3, 2)
layout.addWidget(self.members['world_region'], 4, 1, 1, 2)
layout.setRowStretch(5, 1)
def load_thumbnail(self):
pixmap = QtGui.QPixmap()
thumb = self.metadata.thumbnail
if thumb:
pixmap.loadFromData(thumb.data)
if pixmap.isNull():
self.image.setText(translate('ImageList', 'No\nthumbnail\nin file'))
return
pixmap = self.transform(pixmap, self.metadata.orientation)
self.image.setPixmap(
pixmap.scaled(self.thumb_size, self.thumb_size,
Qt.KeepAspectRatio, Qt.SmoothTransformation))
# read metadata
self.metadata = Metadata(self.path)
self.metadata.unsaved.connect(self.show_status)
self.file_times = (os.path.getatime(self.path),
os.path.getmtime(self.path))
# set file type
self.file_type = self.metadata.mime_type
# sub widgets
layout = QtWidgets.QGridLayout()
layout.setSpacing(0)
layout.setContentsMargins(3, 3, 3, 3)
self.setLayout(layout)
self.setToolTip(self.path)
# label to display image
self.image = QtWidgets.QLabel()
self.image.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
layout.addWidget(self.image, 0, 0, 1, 2)
# label to display file name
self.label = QtWidgets.QLabel()
self.label.setAlignment(Qt.AlignRight)
scale_font(self.label, 80)
layout.addWidget(self.label, 1, 1)
# label to display status
self.status = QtWidgets.QLabel()
self.status.setAlignment(Qt.AlignLeft)
set_symbol_font(self.status)
scale_font(self.status, 80)
layout.addWidget(self.status, 1, 0)
self.setFrameStyle(QtWidgets.QFrame.Panel | QtWidgets.QFrame.Plain)
self.setObjectName("thumbnail")
self.set_selected(False)
self.show_status(False)
def get_album_list(self, album_id=None):
self.upload_config.widgets['album_choose'].clear()
self.upload_config.widgets['album_choose'].addItem(
self.tr(''), 'me')
if self.connected:
selected = 0
for album in self.session.get_albums('id,can_upload,name'):
self.upload_config.widgets['album_choose'].addItem(
album['name'], album['id'])
idx = self.upload_config.widgets['album_choose'].count() - 1
if not album['can_upload']:
self.upload_config.widgets['album_choose'].setItemData(
idx, 0, Qt.UserRole - 1)
elif album['id'] == album_id or not selected:
selected = idx
self.upload_config.widgets['album_choose'].setCurrentIndex(selected)
self.select_album(selected)
else:
self.upload_config.show_album({}, None)
def __init__(self, *arg, **kw):
super(DropdownEdit, self).__init__(*arg, **kw)
self.addItem(translate('TechnicalTab', ''), None)
self.addItem('', None)
self.setItemData(1, 0, Qt.UserRole - 1)
self.addItem(multiple_values(), None)
self.setItemData(2, 0, Qt.UserRole - 1)
self.currentIndexChanged.connect(self.current_index_changed)
def contextMenuEvent(self, event):
menu = self.createStandardContextMenu()
suggestion_group = QtWidgets.QActionGroup(menu)
if self._is_multiple:
if self.choices:
sep = menu.insertSeparator(menu.actions()[0])
fm = menu.fontMetrics()
for suggestion in self.choices:
label = six.text_type(suggestion).replace('\n', ' ')
label = fm.elidedText(label, Qt.ElideMiddle, self.width())
action = QtWidgets.QAction(label, suggestion_group)
action.setData(six.text_type(suggestion))
menu.insertAction(sep, action)
action = menu.exec_(event.globalPos())
if action and action.actionGroup() == suggestion_group:
self.set_value(action.data())
def select_files(self, since):
count = self.file_list_widget.count()
if not count:
return
self.file_list_widget.clearSelection()
first_active = None
for row in range(count):
item = self.file_list_widget.item(row)
if not (item.flags() & Qt.ItemIsSelectable):
continue
name = item.data(Qt.UserRole)
timestamp = self.file_data[name]['timestamp']
if timestamp > since:
if not first_active:
first_active = item
item.setSelected(True)
if not first_active:
first_active = item
self.file_list_widget.scrollToItem(
first_active, QtWidgets.QAbstractItemView.PositionAtTop)
def search_terms(self):
widget = QtWidgets.QLabel(
translate('MapTabGoogle', 'Search and altitude lookup')
+ '\npowered by Google')
widget.setAlignment(Qt.AlignRight)
scale_font(widget, 80)
return [widget]
def _elide_name(self):
self.status.adjustSize()
elided_name = self.label.fontMetrics().elidedText(
self.name, Qt.ElideLeft, self.thumb_size - self.status.width())
self.label.setText(elided_name)
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.api.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