Example #1
0
    def httpRequestFinished(self, requestId, error):
        if self.httpRequestAborted:
            if self.outFile is not None:
                self.outFile.close()
                self.outFile.remove()
                self.outFile = None

            self.progressDialog.hide()
            return

        if requestId != self.httpGetId:
            return

        self.progressDialog.hide()
        self.outFile.close()

        if error:
            self.outFile.remove()
            QtGui.QMessageBox.information(
                self, self.tr("HTTP"),
                self.tr("Download failed: %s.") % (self.http.errorString()))
        else:
            fileName = QtCore.QFileInfo(
                QtCore.QUrl(self.urlLineEdit.text()).path()).fileName()
            self.statusLabel.setText(
                self.tr("Downloaded %s to current directory.") % (fileName))

        self.downloadButton.setEnabled(True)
        self.outFile = None
Example #2
0
    def findMdiChild(self, fileName):
        canonicalFilePath = QtCore.QFileInfo(fileName).canonicalFilePath()

        for window in self.mdiArea.subWindowList():
            if window.widget().currentFile() == canonicalFilePath:
                return window
        return None
    def dropEvent(self, event):
        """Event responsible for adding the dropped file to the favourites."""
        self.indicatorwidget.hide()

        if event.source() == self:
            return  # Won't allow dropping an item from itself

        mime = event.mimeData()
        if not mime.hasUrls():
            return

        event.accept()
        favourites = settings.local_settings.favourites()

        for url in mime.urls():
            file_info = QtCore.QFileInfo(url.toLocalFile())
            path = file_info.filePath().lower()

            if file_info.suffix().lower() == u'favourites':
                common.import_favourites(source=path)
            else:
                k = common.proxy_path(path).lower()
            favourites.append(k)
        settings.local_settings.setValue(u'favourites',
                                         sorted(list(set(favourites))))
        self.favouritesChanged.emit()
Example #4
0
    def _ui_execute_vcv7(self):
        vbox = QtWidgets.QVBoxLayout()
        self.executeVCv7.setLayout(vbox)

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)

        hbox.addStretch()
        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.text_button_width() + 16)
        button.setText("VALSOU check v7")
        button.setToolTip('Check VALSOU values against surface')
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_valsou_check_v7)

        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.single_line_height())
        icon_info = QtCore.QFileInfo(os.path.join(self.media, 'small_info.png'))
        button.setIcon(QtGui.QIcon(icon_info.absoluteFilePath()))
        button.setToolTip('Open the manual page')
        button.setStyleSheet("QPushButton { background-color: rgba(255, 255, 255, 0); }\n"
                             "QPushButton:hover { background-color: rgba(230, 230, 230, 100); }\n")
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_open_manual)

        hbox.addStretch()
Example #5
0
    def dropEvent(self, event):
        """Event responsible for adding the dropped file to the favourites."""
        self.drop_indicator_widget.hide()

        if event.source() == self:
            return  # Won't allow dropping an item from itself

        mime = event.mimeData()
        if not mime.hasUrls():
            return

        event.accept()

        for url in mime.urls():
            file_info = QtCore.QFileInfo(url.toLocalFile())

            # Import favourites file
            if file_info.suffix() == common.favorite_file_ext:
                actions.import_favourites(source=file_info.filePath())
                continue

            source = _check_sequence(file_info.filePath())

            # Skip files saved already
            if source in common.favourites:
                continue

            # Add the dropped file with dummy server/job/root values
            actions.add_favourite(
                common.pseudo_local_bookmark(),
                source,
            )
Example #6
0
 def findMdiChild(self, filename):
     canonicalpath = QtCore.QFileInfo(filename).canonicalFilePath()
     for window in self._workspace.windowList():
         mdiwidget = window
         if mdiwidget.currentFile() == canonicalpath:
             return mdiwidget
     return 0
Example #7
0
    def loadAirfoil(self, filename, comment='#'):
        fileinfo = QtCore.QFileInfo(filename)
        name = fileinfo.fileName()

        airfoil = Airfoil.Airfoil(name)
        loaded = airfoil.readContour(filename, comment)

        # no error during loading
        if loaded:
            # clear all items from the scene when new airfoil is loaded
            self.parent.scene.clear()
            # make contour, markers, chord and add everything to the scene
            airfoil.makeAirfoil()
            # add all airfoil items (contour markers) to the scene
            Airfoil.Airfoil.addToScene(airfoil, self.parent.scene)
            # make loaded airfoil the currently active airfoil
            self.parent.airfoil = airfoil
            # add airfoil to list of loaded airfoils
            self.parent.airfoils.append(airfoil)
            # automatically zoom airfoil so that it fits into the view
            self.fitAirfoilInView()
            logger.info('Airfoil {} loaded'.format(name))

            self.parent.centralwidget.toolbox.header.setEnabled(True)
            self.parent.centralwidget.toolbox.listwidget.setEnabled(True)
            self.parent.centralwidget.toolbox.listwidget.addItem(name)
Example #8
0
    def create_file(self):
        """Creates a new file on the disk.

        """
        if not self._create_file:
            return

        if not self.parent_folder():
            raise RuntimeError('Invalid parent folder')

        _dir = self.parent_folder()

        name = self.name()
        if not name or not _dir or '{invalid_token}' in name:
            raise RuntimeError('Invalid token in output name')

        _dir = QtCore.QDir(_dir)
        if not _dir.mkpath('.'):
            raise RuntimeError('Could name create folder.')

        file_info = QtCore.QFileInfo(self.db_source())
        if file_info.exists():
            raise RuntimeError(
                '{} already exists. Try incrementing the version number.'.
                format(name))

        path = file_info.absoluteFilePath()
        open(os.path.normpath(path), 'a').close()
        self.itemCreated.emit(path)
Example #9
0
    def _ui_execute_xyv1(self):
        vbox = QtWidgets.QVBoxLayout()
        self.executeXYv1.setLayout(vbox)

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)

        hbox.addStretch()
        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.text_button_width() + 6)
        button.setText("Grid XYZ v1")
        button.setToolTip('Export depths as a point cloud')
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_truncate)

        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.single_line_height())
        icon_info = QtCore.QFileInfo(os.path.join(self.media,
                                                  'small_info.png'))
        button.setIcon(QtGui.QIcon(icon_info.absoluteFilePath()))
        button.setToolTip('Open the manual page')
        button.setStyleSheet(
            "QPushButton { background-color: rgba(255, 255, 255, 0); }\n"
            "QPushButton:hover { background-color: rgba(230, 230, 230, 100); }\n"
        )
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_open_manual)

        hbox.addStretch()
Example #10
0
    def onOpen(self):

        dialog = QtWidgets.QFileDialog()

        provider = IconProvider.IconProvider()
        dialog.setIconProvider(provider)
        dialog.setNameFilter(DIALOGFILTER)
        dialog.setNameFilterDetailsVisible(True)
        dialog.setDirectory(AIRFOILDATA)
        dialog.setFileMode(QtWidgets.QFileDialog.ExistingFiles)

        # open custom file dialog using custom icons
        if dialog.exec_():
            filenames = dialog.selectedFiles()
            selfilter = dialog.selectedNameFilter()

        try:
            filenames
        # do nothing if CANCEL button was pressed
        except NameError as error:
            logger.info('Error during file load: {}'.format(error))
            return

        if len(filenames) == 1:
            fileinfo = QtCore.QFileInfo(filenames[0])
            if 'su2' in fileinfo.suffix().lower():
                self.loadSU2(fileinfo.fileName())
                return

        for filename in filenames:
            self.loadAirfoil(filename)
Example #11
0
 def touch_mode_lockfile(self):
     """Creates a lockfile based on the current process' PID."""
     path = get_lockfile_path()
     lockfile_info = QtCore.QFileInfo()
     lockfile_info.dir().mkpath(u'.')
     with open(path, 'w+'):
         pass
Example #12
0
    def verify_paths(self):
        """This slot verifies and returns the saved ``active paths`` wrapped in
        a dictionary.

        If the resulting active path is not an existing file, we will
        progressively unset the invalid path segments until we get a valid file
        path.

        Returns:
            OrderedDict:    Path segments of an existing file.

        """
        d = collections.OrderedDict()
        for k in ACTIVE_KEYS:
            d[k] = self.value(u'activepath/{}'.format(k))

        # Let's check the path and unset the invalid parts
        path = u''
        for idx, k in enumerate(d):
            if d[k]:
                path += u'/{}'.format(common.get_sequence_startpath(d[k]))
                if idx == 0:
                    path = d[k]
            if not QtCore.QFileInfo(path).exists():
                self.setValue(u'activepath/{}'.format(k), None)
                d[k] = None
        return d
Example #13
0
    def _ui_execute_ftv2(self):
        vbox = QtWidgets.QVBoxLayout()
        self.executeFTv2.setLayout(vbox)

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)

        hbox.addStretch()
        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.text_button_width())
        button.setText("S57 Truncate v2")
        button.setToolTip('Truncate the S57 input to the given decimal place')
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_truncate_to_decimeters)

        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.single_line_height())
        icon_info = QtCore.QFileInfo(os.path.join(self.media, 'small_info.png'))
        button.setIcon(QtGui.QIcon(icon_info.absoluteFilePath()))
        button.setToolTip('Open the manual page')
        button.setStyleSheet("QPushButton { background-color: rgba(255, 255, 255, 0); }\n"
                             "QPushButton:hover { background-color: rgba(230, 230, 230, 100); }\n")
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_open_manual)
        hbox.addStretch()
Example #14
0
    def update_name(self, index):
        """Updates the model data when a template's name has been edited.

        """
        if not index.isValid():
            return

        previous_path = index.data(TemplatePathRole)
        if not previous_path:
            return
        previous_name = QtCore.QFileInfo(previous_path).baseName()

        name = index.data(QtCore.Qt.DisplayRole)
        name = name.replace('.zip', '')

        new_path = '{}/{}.zip'.format(
            get_template_folder(self.mode()),
            name.replace(' ', '_')
        )

        if not new_path:
            return

        if QtCore.QFile.rename(previous_path, new_path):
            self.model().setData(index, name, QtCore.Qt.DisplayRole)
            self.model().setData(index, new_path, TemplatePathRole)
        else:
            self.model().setData(index, previous_name, QtCore.Qt.DisplayRole)
            self.model().setData(index, previous_path, TemplatePathRole)
Example #15
0
    def showFiles(self, files):
        for fn in files:
            file = QtCore.QFile(self.currentDir.absoluteFilePath(fn))
            size = QtCore.QFileInfo(file).size()

            fileNameItem = QtWidgets.QTableWidgetItem(fn)
            fileNameItem.setFlags(fileNameItem.flags()
                                  ^ QtCore.Qt.ItemIsEditable)
            sizeItem = QtWidgets.QTableWidgetItem("%d KB" % (int(
                (size + 1023) / 1024)))
            sizeItem.setTextAlignment(QtCore.Qt.AlignVCenter
                                      | QtCore.Qt.AlignRight)
            sizeItem.setFlags(sizeItem.flags() ^ QtCore.Qt.ItemIsEditable)

            # a check item to choose the spec files
            checkItem = QtWidgets.QTableWidgetItem()
            checkItem.setCheckState(QtCore.Qt.Checked)
            checkItem.setTextAlignment(QtCore.Qt.AlignVCenter
                                       | QtCore.Qt.AlignHCenter)

            row = self.filesTable.rowCount()
            self.filesTable.insertRow(row)
            self.filesTable.setItem(row, 0, checkItem)
            self.filesTable.setItem(row, 1, fileNameItem)
            self.filesTable.setItem(row, 2, sizeItem)

        self.filesFoundLabel.setText(
            "%d file(s) found (Double click on a file to open it)" %
            len(files))
Example #16
0
    def _ui_execute_fsv10(self):
        vbox = QtWidgets.QVBoxLayout()
        self.executeFSv10.setLayout(vbox)

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)

        hbox.addStretch()
        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.text_button_width())
        button.setText("Feature scan v10")
        button.setToolTip(
            'Scan features in the loaded file checking their validity')
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_feature_scan_v10)

        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.single_line_height())
        icon_info = QtCore.QFileInfo(os.path.join(self.media,
                                                  'small_info.png'))
        button.setIcon(QtGui.QIcon(icon_info.absoluteFilePath()))
        button.setToolTip('Open the manual page')
        button.setStyleSheet(
            "QPushButton { background-color: rgba(255, 255, 255, 0); }\n"
            "QPushButton:hover { background-color: rgba(230, 230, 230, 100); }\n"
        )
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_open_manual)

        hbox.addStretch()
Example #17
0
    def _draw_placeholder_text(self, painter, hover):
        if not self._placeholder_text:
            return

        v = QtCore.QFileInfo(self._placeholder_text).fileName()
        if self._drag_in_progress:
            v = 'Drop here to add file'

        painter.setOpacity(1.0 if hover else 0.8)

        o = common.size(common.WidthMargin) * 1.5

        color = common.color(common.GreenColor) if hover else common.color(
            common.TextSecondaryColor)
        color = common.color(common.TextSelectedColor) if self._path else color
        color = common.color(
            common.GreenColor) if self._drag_in_progress else color

        if self._path:
            rect = self.rect().adjusted(o * 3, o, -o, -o)
        else:
            rect = self.rect().adjusted(o, o, -o, -o)

        common.draw_aliased_text(
            painter,
            common.font_db.primary_font(common.size(common.FontSizeLarge))[0],
            rect,
            v,
            QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight,
            color,
        )
Example #18
0
    def dump_json(self, destination, force=False):
        """Save the current configuration as a JSON file.

        Args:
            destination (str): Destination path.
            force (bool, optional): Force retrieve tokens from the database.

        """
        file_info = QtCore.QFileInfo(destination)
        if not file_info.dir().exists():
            raise OSError(
                '{} does not exists. Specify a valid destination.'.format(
                    file_info.dir().path()))

        data = self.data(force=force)
        try:
            json_data = json.dumps(data, sort_keys=True, indent=4)
        except (RuntimeError, ValueError, TypeError):
            log.error('Failed to convert data to JSON.')
            raise

        with open(file_info.filePath(), 'w') as f:
            f.write(json_data)
            log.success('Asset folder configuration saved to {}'.format(
                file_info.filePath()))
Example #19
0
    def set_image(self, source, ref, oiio=False):
        """Loads an image using OpenImageIO and displays the contents as a
        QPixmap item.

        """
        self.viewer.item.setPixmap(QtGui.QPixmap())

        self._source = source
        self._ref = ref

        if oiio is False and QtCore.QFileInfo(
                source).suffix().lower() not in images.QT_IMAGE_FORMATS:
            raise RuntimeError('Qt cannot display the source image.')

        # Wait for the thread to finish loading the thumbnail
        images.wait_for_lock(source)
        with images.lock:
            pixmap = images.ImageCache.get_pixmap(source, -1, oiio=oiio)

        if pixmap and not pixmap.isNull():
            with images.lock:
                images.ImageCache.flush(source)

            self.viewer.scale(1.0, 1.0)
            self.viewer.setSceneRect(self.rect())
            self.viewer.scene().setSceneRect(self.rect())
            self.viewer.item.setPixmap(pixmap)
            self.viewer.repaint()

        br = self.viewer.item.sceneBoundingRect()
        self.viewer.item.setPos(
            self.window().rect().center().x() - (br.width() / 2),
            self.window().rect().center().y() - (br.height() / 2))
Example #20
0
    def _ui_execute_sav4(self):
        vbox = QtWidgets.QVBoxLayout()
        self.executeSEv4.setLayout(vbox)

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)

        hbox.addStretch()
        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.text_button_width() + 16)
        button.setText("SBDARE export v4")
        button.setToolTip('Export SBDARE values')
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_sbdare_export_v4)

        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.single_line_height())
        icon_info = QtCore.QFileInfo(os.path.join(self.media,
                                                  'small_info.png'))
        button.setIcon(QtGui.QIcon(icon_info.absoluteFilePath()))
        button.setToolTip('Open the manual page')
        button.setStyleSheet(
            "QPushButton { background-color: rgba(255, 255, 255, 0); }\n"
            "QPushButton:hover { background-color: rgba(230, 230, 230, 100); }\n"
        )
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_open_manual)

        hbox.addStretch()
Example #21
0
    def __inport_btn_clicked(self):
        excels = 'excel (*.xlsx)'
        json_f = 'json (*.json)'

        file_path = QFileDialog.getOpenFileNames(self,
                                                 '选择.xlsx/.json文件',
                                                 filter=excels + ';;' + json_f)
        logger.debug(file_path[0])
        load_list = list()

        if file_path[1] == json_f:
            _path = file_path[0]
            self.path_edit.setText(_path[0])

            with open(_path[0], 'r') as f_json:
                load_list = json.load(f_json)

        elif file_path[1] == excels:
            paths = file_path[0]

            if len(paths) == 1:
                self.path_edit.setText(paths[0])
            else:
                f_info = QtCore.QFileInfo(paths[0])
                self.path_edit.setText(f_info.absolutePath())
                config.EXCEL_DIR = f_info.absolutePath()

            for _path in paths:
                path_dct = {}
                path_dct['url'] = _path
                path_dct['table_number'] = -1
                load_list.append(path_dct)

        if len(load_list):
            self.signal_inport_excels.emit(load_list)
Example #22
0
    def _ui_execute_gqv5(self):
        vbox = QtWidgets.QVBoxLayout()
        self.executeGQv5.setLayout(vbox)

        vbox.addStretch()

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)

        hbox.addStretch()
        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.text_button_width())
        button.setText("Grid QA v5")
        button.setToolTip('Perform quality assessment on loaded grids')
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_grid_qa_v5)

        button = QtWidgets.QPushButton()
        hbox.addWidget(button)
        button.setFixedHeight(GuiSettings.single_line_height())
        button.setFixedWidth(GuiSettings.single_line_height())
        icon_info = QtCore.QFileInfo(os.path.join(self.media,
                                                  'small_info.png'))
        button.setIcon(QtGui.QIcon(icon_info.absoluteFilePath()))
        button.setToolTip('Open the manual page')
        button.setStyleSheet(GuiSettings.stylesheet_info_button())
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.click_open_manual)

        hbox.addStretch()

        vbox.addStretch()
Example #23
0
def push_to_rv(path):
    """Uses `rvpush` to view a given footage."""
    import subprocess
    import bookmarks.log as log
    import bookmarks.common_ui as common_ui
    import bookmarks.settings as settings

    def get_preference(k):
        return settings.local_settings.value(u'preferences/{}'.format(k))

    rv_path = get_preference(u'rv_path')
    if not rv_path:
        common_ui.MessageBox(
            u'Shotgun RV not found.',
            u'To push footage to RV, set RV\'s path in Preferences.').open()
        log.error(u'RV not set')
        return

    rv_info = QtCore.QFileInfo(rv_path)
    if not rv_info.exists():
        common_ui.ErrorBox(
            u'Invalid Shotgun RV path set.',
            u'Make sure the currently set RV path is valid and try again!'
        ).open()
        log.error(u'Invalid RV path set')
        return

    if get_platform() == u'win':
        rv_push_path = u'{}/rvpush.exe'.format(rv_info.path())
        if QtCore.QFileInfo(rv_push_path).exists():
            cmd = u'"{RV}" -tag {PRODUCT} url \'rvlink:// -reuse 1 -inferSequence -l -play -fps 25 -fullscreen -nofloat -lookback 0 -nomb "{PATH}"\''.format(
                RV=rv_push_path, PRODUCT=PRODUCT, PATH=path)
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = subprocess.SW_HIDE
            subprocess.Popen(cmd, startupinfo=startupinfo)
            log.success(u'Footage sent to RV.')
            log.success(u'Command used:')
            log.success(cmd)
    else:
        common_ui.ErrorBox(
            u'Pushing to RV not yet implemented on this platform.',
            u'Sorry about this. Send me an email if you\'d like to see this work soon!'
        ).open()
        log.error(u'Function not implemented')
        return
Example #24
0
    def pick(self):
        _dir = QtWidgets.QFileDialog.getExistingDirectory(parent=self)
        if not _dir:
            return

        file_info = QtCore.QFileInfo(_dir)
        if file_info.exists():
            self.editor.setText(file_info.absoluteFilePath())
Example #25
0
    def mimeData(self, indexes):
        """The data necessary for supporting drag and drop operations are
        constructed here.

        There is ambiguity in the absence of any good documentation I could find
        regarding what mime types have to be defined exactly for fully
        supporting drag and drop on all platforms.

        Note:
            On windows, ``application/x-qt-windows-mime;value="FileName"`` and
            ``application/x-qt-windows-mime;value="FileNameW"`` types seems to be
            necessary, but on MacOS a simple uri list seem to suffice.

        """
        def add_path_to_mime(mime, path):
            """Adds the given path to the mime data."""
            if not isinstance(path, unicode):
                s = u'Expected <type \'unicode\'>, got {}'.format(type(str))
                log.error(s)
                raise TypeError(s)

            path = QtCore.QFileInfo(path).absoluteFilePath()
            mime.setUrls(mime.urls() + [QtCore.QUrl.fromLocalFile(path), ])

            path = QtCore.QDir.toNativeSeparators(path).encode('utf-8')
            _bytes = QtCore.QByteArray(path)
            mime.setData(
                u'application/x-qt-windows-mime;value="FileName"', _bytes)
            mime.setData(
                u'application/x-qt-windows-mime;value="FileNameW"', _bytes)

            return mime

        mime = QtCore.QMimeData()
        modifiers = QtWidgets.QApplication.instance().keyboardModifiers()
        no_modifier = modifiers == QtCore.Qt.NoModifier
        alt_modifier = modifiers & QtCore.Qt.AltModifier
        shift_modifier = modifiers & QtCore.Qt.ShiftModifier

        for index in indexes:
            if not index.isValid():
                continue
            path = index.data(QtCore.Qt.StatusTipRole)

            if no_modifier:
                path = common.get_sequence_endpath(path)
                add_path_to_mime(mime, path)
            elif alt_modifier and shift_modifier:
                path = QtCore.QFileInfo(path).dir().path()
                add_path_to_mime(mime, path)
            elif alt_modifier:
                path = common.get_sequence_startpath(path)
                add_path_to_mime(mime, path)
            elif shift_modifier:
                paths = common.get_sequence_paths(index)
                for path in paths:
                    add_path_to_mime(mime, path)
        return mime
Example #26
0
    def findMainWindow(self, fileName):
        canonicalFilePath = QtCore.QFileInfo(fileName).canonicalFilePath()

        for widget in QtGui.qApp.topLevelWidgets():
            if isinstance(widget,
                          MainWindow) and widget.curFile == canonicalFilePath:
                return widget

        return None
Example #27
0
 def set_rv_path(self, val):
     settings.local_settings.setValue(get_preference(u'rv_path'), val)
     file_info = QtCore.QFileInfo(val)
     if file_info.exists():
         self.rv_path.setStyleSheet(u'color: rgba({})'.format(
             common.rgb(common.ADD)))
     else:
         self.rv_path.setStyleSheet(u'color: rgba({})'.format(
             common.rgb(common.REMOVE)))
Example #28
0
 def showFiles(self, files):
     self.logConsole.append("%d file(s) found: " % len(files))
     for fn in files:
         print(fn)
         print(type(fn))
         file_ = QtCore.QFile(self.currentDir.absoluteFilePath(fn))
         info = QtCore.QFileInfo(file_)
         self.logConsole.append("Found " + info.baseName() + " with size " +
                                str(info.size()))
Example #29
0
 def open_url(self, url):
     """We're handling the clicking of anchors here manually."""
     if not url.isValid():
         return
     file_info = QtCore.QFileInfo(url.url())
     if file_info.exists():
         actions.reveal(file_info.filePath())
         QtWidgets.QApplication.clipboard().setText(file_info.filePath())
     else:
         QtGui.QDesktopServices.openUrl(url)
Example #30
0
def get_rsc(rel_path):
    """Return a resource item from the `rsc` directory.

    """
    v = os.path.normpath('/'.join(
        (__file__, os.pardir, os.pardir, 'rsc', rel_path)))
    f = QtCore.QFileInfo(v)
    if not f.exists():
        raise RuntimeError(f'{f.filePath()} does not exist.')
    return f.filePath()