def onAblumClick(self, item): albums = self.ui.albumsTableWidget pics = self.ui.picturesTableWidget if item.checkState() == QtCore.Qt.Checked: print ('"%s" Checked' % item.text()) album = item.text() self.notificate("Checking album (%s)" % (album), 1000) aid = albums.item(item.row(), 4).text() # aid column == 4 uid = str(self.settings["target"]).rsplit("/", 1)[-1].replace("id", "") pictures = self.vk_wrapper.get_album(str(aid), str(uid)) def get_src(pic): for key in ("src_xxxbig", "src_xxbig", "src_xbig", "src_big", "src"): if pic.has_key(key): return pic[key] for pic in pictures: pics.setRowCount(pics.rowCount() + 1) row = pics.rowCount() - 1 attrs = map( lambda x: QtGui.QTableWidgetItem(x), [get_src(pic), _fromUtf8(album), Utils.to_human_time(pic["created"]), str(pic["owner_id"])], ) src = attrs[0] src.setFlags( QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled ) src.setCheckState(QtCore.Qt.Unchecked) [pics.setItem(row, i, attr) for (i, attr) in enumerate(attrs)] progressBar = QtGui.QProgressBar() progressBar.setProperty("value", 0) progressBar.setInvertedAppearance(False) pics.setCellWidget(row, len(attrs), progressBar) else: print ('"%s" Clicked' % item.text()) removed_album = str(item.text()) removed_rows = [] for row in range(pics.rowCount()): if str(pics.item(row, 1).text()) == removed_album: removed_rows.append(row) for row in sorted(removed_rows, reverse=True): pics.removeRow(row) is_removed_album = lambda x: str(x["album"]) != removed_album self.download_list = filter(is_removed_album, self.download_list) self.window.repaint()
def scanForAlbums(self): self.notificate("Started albums scanning ...", 2000) self._auth() # self.ui.picturesTableWidget.clearContent() ### albums = None if not self.settings.has_key("target"): self.notificate("Target not setted, scanning own directory ...") albums = self.vk_wrapper.get_albums() else: uid = str(self.settings["target"]).rsplit("/", 1)[-1].replace("id", "") self.show_message("", "uid: " + uid) albums = self.vk_wrapper.get_albums(uid) table = self.ui.albumsTableWidget self.ui.albumsTableWidget.setRowCount(len(albums)) if len(albums) == 0: self.show_message("sorry", "there is no albums") for (row, album) in enumerate(albums): attrs = map( lambda x: QtGui.QTableWidgetItem(x), [ _fromUtf8(album["title"]), str(album["size"]), Utils.to_human_time(album["created"]), Utils.to_human_time(album["updated"]), album["aid"], ], ) title = attrs[0] title.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) title.setCheckState(QtCore.Qt.Unchecked) [table.setItem(row, i, attr) for (i, attr) in enumerate(attrs)] table.itemClicked.connect(self.onAblumClick) self.window.repaint() self.notificate("Fetched albums successfully", 2000)