Пример #1
0
    def test_get_open_file_name_selected_filter(self):
        """
        Test that `getOpenFileName` does not modify the selectedFilter as returned by `QFileDialog.getOpenFileName`
        """
        # GIVEN: FileDialog with a mocked QDialog.get_save_file_name method
        # WHEN: Calling FileDialog.getOpenFileName, and `QFileDialog.getOpenFileName` returns a known `selectedFilter`
        with patch('PyQt5.QtWidgets.QFileDialog.getOpenFileName',
                   return_value=('', 'selected filter')):
            result = FileDialog.getOpenFileName()

            # THEN: getOpenFileName() should return a tuple with the second value set to a the selected filter
            assert result[1] == 'selected filter'
Пример #2
0
 def on_attach_file_button_clicked(self):
     """
     Attach files to the bug report e-mail.
     """
     file_path, filter_used = \
         FileDialog.getOpenFileName(self,
                                    translate('ImagePlugin.ExceptionDialog', 'Select Attachment'),
                                    Settings().value(self.settings_section + '/last directory'),
                                    '{text} (*)'.format(text=UiStrings().AllFiles))
     log.info('New files {file_path}'.format(file_path=file_path))
     if file_path:
         self.file_attachment = str(file_path)
Пример #3
0
    def test_get_open_file_name_user_abort(self):
        """
        Test that `getOpenFileName` handles the case when the user cancels the dialog
        """
        # GIVEN: FileDialog with a mocked QDialog.getOpenFileName method
        # WHEN: Calling FileDialog.getOpenFileName and the user cancels the dialog (it returns a tuple with the first
        #       value set as an empty string)
        with patch('PyQt5.QtWidgets.QFileDialog.getOpenFileName',
                   return_value=('', '')):
            result = FileDialog.getOpenFileName()

            # THEN: First value should be None
            assert result[0] is None
Пример #4
0
    def test_get_open_file_name_user_accepts(self):
        """
        Test that `getOpenFileName` handles the case when the user accepts the dialog
        """
        # GIVEN: FileDialog with a mocked QDialog.getOpenFileName method
        # WHEN: Calling FileDialog.getOpenFileName, the user chooses a file and accepts the dialog (it returns a
        #       tuple with the first value set as an string pointing to the file)
        with patch('PyQt5.QtWidgets.QFileDialog.getOpenFileName',
                   return_value=(os.path.join('test', 'chosen.file'), '')):
            result = FileDialog.getOpenFileName()

            # THEN: getOpenFileName() should return a tuple with the first value set to a Path object pointing to the
            #       chosen file
            assert result[0] == Path('test', 'chosen.file')
Пример #5
0
    def on_browse_button_clicked(self):
        """
        A handler to handle a click on the browse button.

        Show the QFileDialog and process the input from the user

        :rtype: None
        """
        caption = self.dialog_caption
        path = None
        if self._path_type == PathEditType.Directories:
            if not caption:
                caption = translate('OpenLP.PathEdit', 'Select Directory')
            path = FileDialog.getExistingDirectory(self, caption, self._path, FileDialog.ShowDirsOnly)
        elif self._path_type == PathEditType.Files:
            if not caption:
                caption = self.dialog_caption = translate('OpenLP.PathEdit', 'Select File')
            path, filter_used = FileDialog.getOpenFileName(self, caption, self._path, self.filters)
        if path:
            self.on_new_path(path)
Пример #6
0
    def get_file_name(self, title, editbox, setting_name, filters=''):
        """
        Opens a FileDialog and saves the filename to the given editbox.

        :param str title: The title of the dialog.
        :param QtWidgets.QLineEdit editbox:  An QLineEdit.
        :param str setting_name: The place where to save the last opened directory.
        :param str filters: The file extension filters. It should contain the file description
            as well as the file extension. For example::

                'OpenLP 2 Databases (*.sqlite)'
        :rtype: None
        """
        if filters:
            filters += ';;'
        filters += '%s (*)' % UiStrings().AllFiles
        file_path, filter_used = FileDialog.getOpenFileName(
            self, title, Settings().value(self.plugin.settings_section + '/' + setting_name), filters)
        if file_path:
            editbox.setText(str(file_path))
            Settings().setValue(self.plugin.settings_section + '/' + setting_name, file_path.parent)