Beispiel #1
0
 def func_browse_eve(self):
     folder = QDir.toNativeSeparators(
         QFileDialog.getExistingDirectory(None, "Eve Directory", "", QFileDialog.ShowDirsOnly))
     if not folder.endswith(os.sep):
         folder += os.sep
     self.ui.txt_client_path.setText(folder)
     self.settings['eve_path'] = folder
 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 json.load(open(bookmark_file_name))
     return _default_bookmarks
    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)
Beispiel #4
0
 def _put_existing_dir_path_in_lineedit(self, lineedit):
     path = QDir.toNativeSeparators(
         QFileDialog.getExistingDirectoryUrl(self.window).path())
     if (os.name == "nt"):
         # Remove the root slash
         path = path[1:]
     lineedit.setText(path)
Beispiel #5
0
    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)
Beispiel #6
0
def qt_reveal_file_in_file_manager(path):
    if not exists(path) and exists(path + FILE_LINK_SUFFIX):
        path += FILE_LINK_SUFFIX
    try:
        while not exists(path):
            path = dirname(path)
    except Exception:
        return

    system = get_platform()
    if system == 'Darwin':
        args = [
            "-e", 'tell application "Finder"', "-e", "activate", "-e",
            'select POSIX file "{}"'.format(path), "-e", "end tell", "-e",
            "return"
        ]
        process = QProcess()
        if not process.execute("/usr/bin/osascript", args):
            return

    elif system == 'Windows':
        args = [QDir.toNativeSeparators(path)]
        if not isdir(path):
            args.insert(0, "/select,")
        process = QProcess()
        if process.startDetached("explorer", args):
            return

    qt_open_path(path if isdir(path) else dirname(path))
Beispiel #7
0
 def handleUrlPath(self, path: str) -> str:
     url = QUrl(path)
     pathOk = ""
     if url.isLocalFile():
         pathOk = QDir.toNativeSeparators(url.toLocalFile())
     else:
         pathOk = path
     return pathOk
 def testQSaveFile(self):
     dir = QTemporaryDir(QDir.tempPath() + "/XXXXXX.dir")
     self.assertTrue(dir.isValid())
     saveFile = QSaveFile(dir.path() + "/test.dat")
     self.assertTrue(saveFile.open(QIODevice.WriteOnly))
     saveFile.write(py3k.b("Test"))
     self.assertTrue(saveFile.commit())
     self.assertTrue(
         os.path.exists(QDir.toNativeSeparators(saveFile.fileName())))
Beispiel #9
0
 def save_screenshot(self):
     frmat = '.png'
     initial_path = QStandardPaths.writableLocation(
         QStandardPaths.PicturesLocation)
     if not initial_path:
         initial_path = QDir.currentPath()
     initial_path += '/Screenshot-' + \
         str(datetime.now()).replace(' ', '_') + frmat
     file_dialog = QFileDialog(self, "Save as", initial_path)
     file_dialog.setAcceptMode(QFileDialog.AcceptSave)
     file_dialog.setFileMode(QFileDialog.AnyFile)
     if file_dialog.exec() != QDialog.Accepted:
         return
     file_name = file_dialog.selectedFiles()[0]
     if not self.original_pixmap.save(file_name):
         logger.error("The image could not be saved to \"{}\".".format(
             QDir.toNativeSeparators(file_name)))
         QMessageBox.warning(self, "Save Error", "The image could not be saved to \"{}\".".format(
             QDir.toNativeSeparators(file_name)))
 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:
         json.dump(serialized_model, bookmark_file, indent = 4)
 def _updateToolTip(self):
     path = self._downloadItem.path()
     toolTip = "{}\n{}".format(self._downloadItem.url().toString(),
                               QDir.toNativeSeparators(path))
     totalBytes = self._downloadItem.totalBytes()
     if totalBytes > 0:
         toolTip += "\n{}K".format(totalBytes / 1024)
     state = self.state()
     if state == QWebEngineDownloadItem.DownloadRequested:
         toolTip += "\n(requested)"
     elif state == QWebEngineDownloadItem.DownloadInProgress:
         toolTip += "\n(downloading)"
     elif state == QWebEngineDownloadItem.DownloadCompleted:
         toolTip += "\n(completed)"
     elif state == QWebEngineDownloadItem.DownloadCancelled:
         toolTip += "\n(cancelled)"
     else:
         toolTip += "\n(interrupted)"
     self.setToolTip(toolTip)
 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.total_bytes()
     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)
Beispiel #13
0
 def __del__(self):
     if self._confFileName is not None:
         os.unlink(QDir.toNativeSeparators(self._confFileName))
Beispiel #14
0
 def _on_repo_clicked(self):
     dir = QFileDialog.getExistingDirectory(self, "Select sync repo", "",
                                            QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
     self._repo_edit.setText(QDir.toNativeSeparators(dir))