def test_qCleanupResources(self):
        """
        Test qCleanupResources.
        """

        file_before = QFile(':/oi/svg/document.svg')
        self.assertTrue(file_before.exists())

        qCleanupResources()

        file_after = QFile(':/oi/svg/document.svg')
        self.assertFalse(file_after.exists())
예제 #2
0
    def load_file_list(self):
        self.file_list_widget.clear()

        for image_dir in self.file_dirs:
            if not QFile.exists(image_dir):
                continue
            item = QListWidgetItem(image_dir)
            item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
            label_dir = os.path.splitext(image_dir)[0] + '.json'
            if QFile.exists(label_dir):
                item.setCheckState(Qt.Checked)
            else:
                item.setCheckState(Qt.Unchecked)
            self.file_list_widget.addItem(item)
예제 #3
0
파일: __init__.py 프로젝트: mhamid3d/jinx
def _load_stylesheet(qt_api=''):
    """
    Load the stylesheet based on QtPy abstraction layer environment variable.

    If the argument is not passed, it uses the current QT_API environment
    variable to make the imports of Qt bindings. If passed, it sets this
    variable then make the imports.

    Args:
        qt_api (str): qt binding name to set QT_API environment variable.
                      Default is ''. Possible values are pyside, pyside2
                      pyqt4, pyqt5. Not case sensitive.

    Note:
        - Note that the variable QT_API is read when first imported. So,
          pay attention to the import order.
        - If you are using another abstraction layer, i.e PyQtGraph to do
          imports on Qt things you must set both to use the same Qt
          binding (PyQt, PySide).
        - OS, binding and binding version number, and application specific
          patches are applied in this order.

    Returns:
        str: stylesheet string (css).
    """

    if qt_api:
        os.environ['QT_API'] = qt_api

    # Import is made after setting QT_API
    from qtpy.QtCore import QCoreApplication, QFile, QTextStream
    from qtpy.QtGui import QColor, QPalette

    # Then we import resources - binary qrc content
    from qdarkstyle import style_rc

    # Thus, by importing the binary we can access the resources
    package_dir = os.path.basename(PACKAGE_PATH)
    qss_rc_path = ":" + os.path.join(package_dir, QSS_FILE)

    # It gets the qss file from compiled style_rc that was import
    # not from the file QSS as we are using resources
    qss_file = QFile(qss_rc_path)

    if qss_file.exists():
        qss_file.open(QFile.ReadOnly | QFile.Text)
        text_stream = QTextStream(qss_file)
        stylesheet = text_stream.readAll()
    else:
        stylesheet = ""
        # Todo: check this raise type and add to docs
        raise FileNotFoundError("Unable to find QSS file '{}' "
                                "in resources.".format(qss_rc_path))

    # 4. Apply palette fix. See issue #139
    _apply_application_patches(QCoreApplication, QPalette, QColor)

    return stylesheet
    def test_qInitResources(self):
        """
        Test qInitResources.

        qInitResources is run during module import, but might be closed by another test so setup call it.
        """

        icon_file = QFile(':/oi/svg/document.svg')
        self.assertTrue(icon_file.exists())
예제 #5
0
 def save_settings(self) -> None:
     """Save Pyslvs settings (auto save when close event)."""
     if self.prefer.not_save_option:
         f = QFile(self.settings.fileName())
         if f.exists():
             f.remove()
         return
     self.settings.setValue("ENV", self.env)
     for field in fields(self.prefer):  # type: Field
         self.settings.setValue(field.name, getattr(self.prefer, field.name))
예제 #6
0
파일: canvas.py 프로젝트: qcuong98/clabel
    def load_file(self, image_dir):
        self.reset()
        self.pixmap = QPixmap(image_dir)
        self.cv2_image = cv2.imread(image_dir)
        self.label_dir = os.path.splitext(image_dir)[0] + '.json'
        if QFile.exists(self.label_dir):
            with open(self.label_dir) as json_file:
                data = json.load(json_file)
                self.objects = []
                for obj in data['objects']:
                    points = []
                    for point in obj['points']:
                        points.append(QPointF(point['x'], point['y']))
                    if (obj['type'] == 'rectangle'):
                        self.objects.append(Rectangle(points, obj['label']))
                    elif (obj['type'] == 'polygon'):
                        self.objects.append(Polygon(points, obj['label']))
                self.cur_object = len(self.objects) - 1
                self.parent.load_object_list(self.objects)
                self.parent.object_list_widget.setCurrentRow(self.cur_object)

        self.repaint()
예제 #7
0
    def _update_file_menu(self):
        """
            Set up the File menu and update the menu with recent files
        """
        self.file_menu.clear()

        newAction = QAction("&New Reduction...", self)
        newAction.setShortcut("Ctrl+N")
        newAction.setStatusTip("Start a new reduction")
        newAction.triggered.connect(self._new)

        openAction = QAction("&Open...", self)
        openAction.setShortcut("Ctrl+O")
        openAction.setStatusTip("Open an XML file containing reduction parameters")
        openAction.triggered.connect(self._file_open)

        saveAsAction = QAction("Save as...", self)
        saveAsAction.setStatusTip("Save the reduction parameters to XML")
        saveAsAction.triggered.connect(self._save_as)

        saveAction = QAction("&Save...", self)
        saveAction.setShortcut("Ctrl+S")
        saveAction.setStatusTip("Save the reduction parameters to XML")
        saveAction.triggered.connect(self._save)

        exportAction = QAction("&Export...", self)
        exportAction.setShortcut("Ctrl+E")
        exportAction.setStatusTip("Export to python script for Mantid")
        exportAction.triggered.connect(self._export)

        quitAction = QAction("&Quit", self)
        quitAction.setShortcut("Ctrl+Q")
        quitAction.triggered.connect(self.close)

        self.file_menu.addAction(newAction)
        self.file_menu.addAction(openAction)
        self.file_menu.addAction(saveAction)
        self.file_menu.addAction(saveAsAction)
        self.file_menu.addAction(exportAction)
        self.file_menu.addSeparator()

        if self.general_settings.debug:
            clearAction = QAction("&Clear settings and quit", self)
            clearAction.setStatusTip("Restore initial application settings and close the application")
            clearAction.triggered.connect(self._clear_and_close)
            self.file_menu.addAction(clearAction)

        self.file_menu.addAction(quitAction)

        # TOOLS menu
        instrAction = QAction("Change &instrument...", self)
        instrAction.setShortcut("Ctrl+I")
        instrAction.setStatusTip("Select a new instrument")
        instrAction.triggered.connect(self._change_instrument)

        debug_menu_item_str = "Turn debug mode ON"
        if self.general_settings.debug:
            debug_menu_item_str = "Turn debug mode OFF"
        debugAction = QAction(debug_menu_item_str, self)
        debugAction.setStatusTip(debug_menu_item_str)
        debugAction.triggered.connect(self._debug_mode)

        self.tools_menu.clear()
        self.tools_menu.addAction(instrAction)
        self.tools_menu.addAction(debugAction)

        recent_files = []
        for fname in self._recent_files:
            if fname != self._filename and QFile.exists(fname) and fname not in recent_files:
                recent_files.append(fname)

        if len(recent_files) > 0:
            self.file_menu.addSeparator()
            for i, fname in enumerate(recent_files):
                action = QAction("&%d %s" % (i + 1, QFileInfo(fname).fileName()), self)
                action.setData(fname)
                action.triggered.connect(self.open_file)
                self.file_menu.addAction(action)
    def _update_file_menu(self):
        """
            Set up the File menu and update the menu with recent files
        """
        self.file_menu.clear()

        newAction = QAction("&New Reduction...", self)
        newAction.setShortcut("Ctrl+N")
        newAction.setStatusTip("Start a new reduction")
        newAction.triggered.connect(self._new)

        openAction = QAction("&Open...", self)
        openAction.setShortcut("Ctrl+O")
        openAction.setStatusTip("Open an XML file containing reduction parameters")
        openAction.triggered.connect(self._file_open)

        saveAsAction = QAction("Save as...", self)
        saveAsAction.setStatusTip("Save the reduction parameters to XML")
        saveAsAction.triggered.connect(self._save_as)

        saveAction = QAction("&Save...", self)
        saveAction.setShortcut("Ctrl+S")
        saveAction.setStatusTip("Save the reduction parameters to XML")
        saveAction.triggered.connect(self._save)

        exportAction = QAction("&Export...", self)
        exportAction.setShortcut("Ctrl+E")
        exportAction.setStatusTip("Export to python script for Mantid")
        exportAction.triggered.connect(self._export)

        quitAction = QAction("&Quit", self)
        quitAction.setShortcut("Ctrl+Q")
        quitAction.triggered.connect(self.close)

        self.file_menu.addAction(newAction)
        self.file_menu.addAction(openAction)
        self.file_menu.addAction(saveAction)
        self.file_menu.addAction(saveAsAction)
        self.file_menu.addAction(exportAction)
        self.file_menu.addSeparator()

        if self.general_settings.debug:
            clearAction = QAction("&Clear settings and quit", self)
            clearAction.setStatusTip("Restore initial application settings and close the application")
            clearAction.triggered.connect(self._clear_and_close)
            self.file_menu.addAction(clearAction)

        self.file_menu.addAction(quitAction)

        # TOOLS menu
        instrAction = QAction("Change &instrument...", self)
        instrAction.setShortcut("Ctrl+I")
        instrAction.setStatusTip("Select a new instrument")
        instrAction.triggered.connect(self._change_instrument)

        debug_menu_item_str = "Turn debug mode ON"
        if self.general_settings.debug:
            debug_menu_item_str = "Turn debug mode OFF"
        debugAction = QAction(debug_menu_item_str, self)
        debugAction.setStatusTip(debug_menu_item_str)
        debugAction.triggered.connect(self._debug_mode)

        self.tools_menu.clear()
        self.tools_menu.addAction(instrAction)
        self.tools_menu.addAction(debugAction)

        recent_files = []
        for fname in self._recent_files:
            if fname != self._filename and QFile.exists(fname) and fname not in recent_files:
                recent_files.append(fname)

        if len(recent_files)>0:
            self.file_menu.addSeparator()
            for i, fname in enumerate(recent_files):
                action = QAction("&%d %s" % (i+1, QFileInfo(fname).fileName()), self)
                action.setData(fname)
                action.triggered.connect(self.open_file)
                self.file_menu.addAction(action)