def __init__(self, previewImage, fileName): super(ImageView, self).__init__() self.fileName = fileName mainLayout = QVBoxLayout(self) self.imageLabel = QLabel() self.imageLabel.setPixmap(QPixmap.fromImage(previewImage)) mainLayout.addWidget(self.imageLabel) topLayout = QHBoxLayout() self.fileNameLabel = QLabel(QDir.toNativeSeparators(fileName)) self.fileNameLabel.setTextInteractionFlags(Qt.TextBrowserInteraction) topLayout.addWidget(self.fileNameLabel) topLayout.addStretch() copyButton = QPushButton("Copy") copyButton.setToolTip("Copy file name to clipboard") topLayout.addWidget(copyButton) copyButton.clicked.connect(self.copy) launchButton = QPushButton("Launch") launchButton.setToolTip("Launch image viewer") topLayout.addWidget(launchButton) launchButton.clicked.connect(self.launch) mainLayout.addLayout(topLayout)
def _read_bookmarks(self): bookmark_file_name = os.path.join( QDir.toNativeSeparators(_config_dir()), _bookmark_file) if os.path.exists(bookmark_file_name): print('Reading {}...'.format(bookmark_file_name)) return jsons.load(open(bookmark_file_name)) return _default_bookmarks
def changeFolder(self, button): fname = QFileDialog.getExistingDirectory(self, 'Open f', '/home') if fname: # Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. # On Windows, toNativeSeparators("c:/winnt/system32") returns # "c:\winnt\system32". fname = QDir.toNativeSeparators(fname) if os.path.isdir(fname): self.download_folder_lineEdit.setText(fname)
def downloadFolderPushButtonClicked(self, button): download_path = str( self.persepolis_setting.value('settings/download_path')) fname = QFileDialog.getExistingDirectory(self, 'Select a directory', download_path) if fname: # Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. # On Windows, toNativeSeparators("c:/winnt/system32") returns # "c:\winnt\system32". fname = QDir.toNativeSeparators(fname) self.download_folder_lineEdit.setText(fname) self.persepolis_setting.setValue('settings/download_path', str(fname))
def write_bookmarks(self): if not self._modified: return dir_path = _config_dir() native_dir_path = QDir.toNativeSeparators(dir_path) dir = QFileInfo(dir_path) if not dir.isDir(): print('Creating {}...'.format(native_dir_path)) if not QDir(dir.absolutePath()).mkpath(dir.fileName()): warnings.warn('Cannot create {}.'.format(native_dir_path), RuntimeWarning) return serialized_model = _serialize_model(self._model, dir_path) bookmark_file_name = os.path.join(native_dir_path, _bookmark_file) print('Writing {}...'.format(bookmark_file_name)) with open(bookmark_file_name, 'w') as bookmark_file: jsons.dump(serialized_model, bookmark_file, indent=4)
def _update_tool_tip(self): path = self._download_item.path() tool_tip = "{}\n{}".format(self._download_item.url().toString(), QDir.toNativeSeparators(path)) total_bytes = self._download_item.totalBytes() if total_bytes > 0: tool_tip += "\n{}K".format(total_bytes / 1024) state = self.state() if state == QWebEngineDownloadItem.DownloadRequested: tool_tip += "\n(requested)" elif state == QWebEngineDownloadItem.DownloadInProgress: tool_tip += "\n(downloading)" elif state == QWebEngineDownloadItem.DownloadCompleted: tool_tip += "\n(completed)" elif state == QWebEngineDownloadItem.DownloadCancelled: tool_tip += "\n(cancelled)" else: tool_tip += "\n(interrupted)" self.setToolTip(tool_tip)