Example #1
0
class ActivityWidget(CompositeWidget):
    """
    a widget used to input optional description text of activity
    """
    def __init__(self, parent, **params):
        super(ActivityWidget, self).__init__(parent,
                                             layout=QHBoxLayout(),
                                             **params)
        self.activityButton = CheckBoxWidget(
            self,
            i18n="activity.button",
            i18n_def="Save as activity",
            clicked_handler=self.__clickedHandler__)

        LabelWidget(self,
                    i18n="activity.description.label",
                    i18n_def="Activity description (optional):")

        self.activityDescription = LineEditWidget(self, enabled=False)

    def activityOk(self):
        return self.activityButton.isChecked()

    def description(self):
        if self.activityButton.isChecked():
            return str(self.activityDescription.text())

    def __clickedHandler__(self):
        self.activityDescription.setEnabled(self.activityButton.isChecked())
Example #2
0
class ActivityWidget(CompositeWidget):
    """
    a widget used to input optional description text of activity
    """
    def __init__(self, parent, **params):
        super(ActivityWidget, self).__init__(parent, layout=QHBoxLayout(),
                                             **params)
        self.activityButton = CheckBoxWidget(self,
                            i18n="activity.button",
                            i18n_def="Save as activity",
                            clicked_handler=self.__clickedHandler__)

        LabelWidget(self,
                     i18n="activity.description.label",
                     i18n_def="Activity description (optional):")

        self.activityDescription = LineEditWidget(self, enabled=False)

    def activityOk(self):
        return self.activityButton.isChecked()

    def description(self):
        if self.activityButton.isChecked():
            return str(self.activityDescription.text())

    def __clickedHandler__(self):
        self.activityDescription.setEnabled(self.activityButton.isChecked())
Example #3
0
    def __init__(self, parent, **params):
        super(ActivityWidget, self).__init__(parent,
                                             layout=QHBoxLayout(),
                                             **params)
        self.activityButton = CheckBoxWidget(
            self,
            i18n="activity.button",
            i18n_def="Save as activity",
            clicked_handler=self.__clickedHandler__)

        LabelWidget(self,
                    i18n="activity.description.label",
                    i18n_def="Activity description (optional):")

        self.activityDescription = LineEditWidget(self, enabled=False)
    def __createFileConstraintsComposite__(self, parent):
        fileConstraintsComposite = CompositeWidget(parent,
                                                   layout=QHBoxLayout())

        self.chooseRootDirButton = PushButtonWidget(
            fileConstraintsComposite,
            i18n="datasource.datasource.choose.root.dir.button",
            i18n_def="Choose root dir",
            clicked_handler=self.chooseRootDirAction)

        LabelWidget(fileConstraintsComposite,
                    i18n="datasource.root.dir.label",
                    i18n_def="Root dir:")
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self.rootDirLabel = LabelWidget(fileConstraintsComposite,
                                        i18n="datasource.root.dir.label",
                                        i18n_def="[Not set]",
                                        sizePolicy=sizePolicy,
                                        stretch_after_widget=1)

        LabelWidget(fileConstraintsComposite,
                    i18n="datasource.file.name.filter.label",
                    i18n_def="Files name filter")

        self.filesExtension = LineEditWidget(
            fileConstraintsComposite,
            maxLength=15,
            width=get_width_of_n_letters(14),
            text="*",
            enabled_precheck_handler=self.enabledPrecheckHandler)

        self.recursively = CheckBoxWidget(
            fileConstraintsComposite,
            i18n="datasource.search.files.recursively.label",
            i18n_def="Search files recursively",
            clicked_handler=self.reload,
            enabled_precheck_handler=self.enabledPrecheckHandler)

        self.onlyKnownTypes = CheckBoxWidget(
            fileConstraintsComposite,
            i18n="datasource.only.known.types.checkbox",
            i18n_def="Only known types",
            checked=True,
            clicked_handler=self.reload,
            enabled_precheck_handler=self.enabledPrecheckHandler)
Example #5
0
    def __init__(self, parent, **params):
        get_or_put(params, 'i18n_def', 'Separator')
        self.params = Params(**params)
        self.separatorsGroupBox = GroupBoxWidget(parent,
                            i18n="separator.widget.group.title",
                            i18n_def=nvl(self.params.i18n_def, "Separator"),
                            layout=QVBoxLayout())

        self.predefinedSeparatorsComposite = CompositeWidget(
                                                    self.separatorsGroupBox,
                                                    layout=QHBoxLayout())
        self.predefinedSeparatorsButtonsGroup = ButtonGroupWidget(
                                            self.predefinedSeparatorsComposite)

        self.predefinedSeparatorsSpecs = Separator.getSeparatorsSpec(
                                                    separator_label_handler)
        for separatorSpec in self.predefinedSeparatorsSpecs:
            label = separatorSpec.label
            if not label == Separator.CUSTOM.label:  # @UndefinedVariable
                predefinedSeparatorCheckBox = CheckBoxWidget(
                                            self.predefinedSeparatorsComposite)
                #attach artificially a separatorSpec object used later in
                #def setSeparator(self, _separator) method
                predefinedSeparatorCheckBox.separator_spec = separatorSpec
                predefinedSeparatorCheckBox.setText(label)
                predefinedSeparatorCheckBox.sep_spec = separatorSpec
                if self.params.default_separator and \
                    separatorSpec.id_ == self.params.default_separator.id_:
                    predefinedSeparatorCheckBox.setChecked(True)
                self.predefinedSeparatorsButtonsGroup.addButton(
                                                predefinedSeparatorCheckBox)

        self.separatorsGroupBox.connect(self.predefinedSeparatorsButtonsGroup,
                                    SIGNAL("buttonClicked(QAbstractButton *)"),
                                    self.predefinedSeparatorButtonClicked)

        if not self.params.no_custom_separator == True:
            self.customSeparatorCheckBox = CheckBoxWidget(
                                        self.predefinedSeparatorsComposite,
                                        i18n="separator.custom.checkbox",
                                        i18n_def="Custom")
            self.customSeparatorCheckBox.sep_spec = Separator.CUSTOM
            self.separatorsGroupBox.connect(self.customSeparatorCheckBox,
                                        SIGNAL("clicked()"),
                                        self.customSeparatorButtonClicked)

            self.customSeparatorEdit = LineEditWidget(
                        self.predefinedSeparatorsComposite,
                        maxLength=15,
                        width=get_width_of_n_letters(14),
                        text_changed_handler=self.customSeparatorButtonClicked,
                        enabled=False)

        self.setEnabled(self.params.enabled)
Example #6
0
    def __init__(self, parent, **params):
        super(ActivityWidget, self).__init__(parent, layout=QHBoxLayout(),
                                             **params)
        self.activityButton = CheckBoxWidget(self,
                            i18n="activity.button",
                            i18n_def="Save as activity",
                            clicked_handler=self.__clickedHandler__)

        LabelWidget(self,
                     i18n="activity.description.label",
                     i18n_def="Activity description (optional):")

        self.activityDescription = LineEditWidget(self, enabled=False)
    def __createFileConstraintsComposite__(self, parent):
        fileConstraintsComposite = CompositeWidget(parent,
                                                   layout=QHBoxLayout())

        self.chooseRootDirButton = PushButtonWidget(fileConstraintsComposite,
                        i18n="datasource.datasource.choose.root.dir.button",
                        i18n_def="Choose root dir",
                        clicked_handler=self.chooseRootDirAction)

        LabelWidget(fileConstraintsComposite,
                     i18n="datasource.root.dir.label",
                     i18n_def="Root dir:")
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self.rootDirLabel = LabelWidget(fileConstraintsComposite,
                                        i18n="datasource.root.dir.label",
                                        i18n_def="[Not set]",
                                        sizePolicy=sizePolicy,
                                        stretch_after_widget=1)

        LabelWidget(fileConstraintsComposite,
                    i18n="datasource.file.name.filter.label",
                    i18n_def="Files name filter")

        self.filesExtension = LineEditWidget(fileConstraintsComposite,
                        maxLength=15,
                        width=get_width_of_n_letters(14),
                        text="*",
                        enabled_precheck_handler=self.enabledPrecheckHandler)

        self.recursively = CheckBoxWidget(fileConstraintsComposite,
                        i18n="datasource.search.files.recursively.label",
                        i18n_def="Search files recursively",
                        clicked_handler=self.reload,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

        self.onlyKnownTypes = CheckBoxWidget(fileConstraintsComposite,
                        i18n="datasource.only.known.types.checkbox",
                        i18n_def="Only known types",
                        checked=True,
                        clicked_handler=self.reload,
                        enabled_precheck_handler=self.enabledPrecheckHandler)
Example #8
0
class SeparatorWidget(object):
    """
    widget used to choose a separator sign
    """
    def __init__(self, parent, **params):
        get_or_put(params, 'i18n_def', 'Separator')
        self.params = Params(**params)
        self.separatorsGroupBox = GroupBoxWidget(parent,
                            i18n="separator.widget.group.title",
                            i18n_def=nvl(self.params.i18n_def, "Separator"),
                            layout=QVBoxLayout())

        self.predefinedSeparatorsComposite = CompositeWidget(
                                                    self.separatorsGroupBox,
                                                    layout=QHBoxLayout())
        self.predefinedSeparatorsButtonsGroup = ButtonGroupWidget(
                                            self.predefinedSeparatorsComposite)

        self.predefinedSeparatorsSpecs = Separator.getSeparatorsSpec(
                                                    separator_label_handler)
        for separatorSpec in self.predefinedSeparatorsSpecs:
            label = separatorSpec.label
            if not label == Separator.CUSTOM.label:  # @UndefinedVariable
                predefinedSeparatorCheckBox = CheckBoxWidget(
                                            self.predefinedSeparatorsComposite)
                #attach artificially a separatorSpec object used later in
                #def setSeparator(self, _separator) method
                predefinedSeparatorCheckBox.separator_spec = separatorSpec
                predefinedSeparatorCheckBox.setText(label)
                predefinedSeparatorCheckBox.sep_spec = separatorSpec
                if self.params.default_separator and \
                    separatorSpec.id_ == self.params.default_separator.id_:
                    predefinedSeparatorCheckBox.setChecked(True)
                self.predefinedSeparatorsButtonsGroup.addButton(
                                                predefinedSeparatorCheckBox)

        self.separatorsGroupBox.connect(self.predefinedSeparatorsButtonsGroup,
                                    SIGNAL("buttonClicked(QAbstractButton *)"),
                                    self.predefinedSeparatorButtonClicked)

        if not self.params.no_custom_separator == True:
            self.customSeparatorCheckBox = CheckBoxWidget(
                                        self.predefinedSeparatorsComposite,
                                        i18n="separator.custom.checkbox",
                                        i18n_def="Custom")
            self.customSeparatorCheckBox.sep_spec = Separator.CUSTOM
            self.separatorsGroupBox.connect(self.customSeparatorCheckBox,
                                        SIGNAL("clicked()"),
                                        self.customSeparatorButtonClicked)

            self.customSeparatorEdit = LineEditWidget(
                        self.predefinedSeparatorsComposite,
                        maxLength=15,
                        width=get_width_of_n_letters(14),
                        text_changed_handler=self.customSeparatorButtonClicked,
                        enabled=False)

        self.setEnabled(self.params.enabled)

    def getSeparatorSign(self):
        sign = self.__getPredefinedSeparatorSign__()
        if sign:
            return sign
        if not self.params.no_custom_separator == True:
            return self.__getCustomSeparatorSign__()

    def predefinedSeparatorButtonClicked(self, button):
        if not self.params.no_custom_separator == True:
            self.__customSeparatorClear__()
        if self.params.separatorHandler and \
            not self.predefinedSeparatorsButtonsGroup.checkedButton() == None:
            self.params.separatorHandler(self.__getPredefinedSeparatorSign__())

    def customSeparatorButtonClicked(self):
        checked = self.customSeparatorCheckBox.isChecked()
        separator = self.__getCustomSeparatorSign__()
        if checked and self.params.separatorHandler and separator:
            self.params.separatorHandler(separator)
        self.customSeparatorEdit.setEnabled(checked)
        if checked:
            self.__uncheckPredefinedButtons__()
            self.customSeparatorEdit.setFocus()

    def __getPredefinedSeparatorSign__(self):
        button = self.predefinedSeparatorsButtonsGroup.checkedButton()
        if not button == None:
            for (sign, _, label) in self.predefinedSeparatorsSpecs:
                if button.text() == label:
                    return sign

    def __getCustomSeparatorSign__(self):
        if self.customSeparatorCheckBox.isChecked():
            return str(self.customSeparatorEdit.text())

    def setEnabled(self, enabled):
        if not enabled == None:
            self.separatorsGroupBox.setEnabled(enabled)

    def setSeparator(self, _separator):
        if _separator:
            separatorSign = Separator.getSeparatorSign(_separator)
            if separatorSign == Separator.WHITE_SPACE:
                for button in self.predefinedSeparatorsButtonsGroup.buttons():
                    if button.separator_spec.id_ == Separator.WHITE_SPACE.id_:  # @UndefinedVariable @IgnorePep8
                        button.setChecked(True)
                        return
            elif separatorSign == Separator.CUSTOM:
                self.customSeparatorEdit.setText(_separator)
                self.__uncheckPredefinedButtons__()
            elif not separatorSign == Separator.NONE:
                for button in self.predefinedSeparatorsButtonsGroup.buttons():
                    if button.sep_spec.id_ == separatorSign.id_:
                        if not self.params.no_custom_separator == True:
                            self.__customSeparatorClear__()
                        button.setChecked(True)
                        return

    def __customSeparatorClear__(self):
        self.customSeparatorCheckBox.setChecked(False)
        self.customSeparatorEdit.setText("")
        self.customSeparatorEdit.setEnabled(False)

    def __uncheckPredefinedButtons__(self):
        #to uncheck button included in a button group one have to use a trick:
        #change to none exclusive state behaviour of the button group, then
        #uncheck checked button and reverse to previous exclusive state of
        #the button group
        if self.predefinedSeparatorsButtonsGroup.checkedButton():
            self.predefinedSeparatorsButtonsGroup.setExclusive(False)
            self.predefinedSeparatorsButtonsGroup.checkedButton().setChecked(
                                                                        False)
            self.predefinedSeparatorsButtonsGroup.setExclusive(True)
class ChooseDatasourcePage(QWizardPage):
    def __init__(self, _parent):
        QWizardPage.__init__(self, parent=_parent)

    def initializePage(self):
        title_I18N(self, "datasource.page.title", "Datasource chooser")
        #self.setSubTitle('Setup frame specific data')
        pageLayout = QVBoxLayout()
        self.setLayout(pageLayout)
        self.__createFilesGroupBox(pageLayout)

        #to force call of isComplete(self) method by the Wizard framework
        #which causes state next button to be updated
        self.emit(WIZARD_COMPLETE_CHANGED_SIGNAL)
        self.rootDir = None

    def __createFilesGroupBox(self, pageLayout):
        self.filesGroupBox = GroupBoxWidget(
            self,
            i18n="datasource.files.group.title",
            i18n_def="Files",
            layout=QVBoxLayout())

        self.__createFileConstraintsComposite__(self.filesGroupBox)

        self.__createReloadButton__(self.filesGroupBox)

        self.__createTableView__(self.filesGroupBox)

        self.__createFilesOperationsComposite__(self.filesGroupBox)

        self.changeEnablemend(False)
        self.chooseRootDirButton.setEnabled(True)

    def __createFileConstraintsComposite__(self, parent):
        fileConstraintsComposite = CompositeWidget(parent,
                                                   layout=QHBoxLayout())

        self.chooseRootDirButton = PushButtonWidget(
            fileConstraintsComposite,
            i18n="datasource.datasource.choose.root.dir.button",
            i18n_def="Choose root dir",
            clicked_handler=self.chooseRootDirAction)

        LabelWidget(fileConstraintsComposite,
                    i18n="datasource.root.dir.label",
                    i18n_def="Root dir:")
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self.rootDirLabel = LabelWidget(fileConstraintsComposite,
                                        i18n="datasource.root.dir.label",
                                        i18n_def="[Not set]",
                                        sizePolicy=sizePolicy,
                                        stretch_after_widget=1)

        LabelWidget(fileConstraintsComposite,
                    i18n="datasource.file.name.filter.label",
                    i18n_def="Files name filter")

        self.filesExtension = LineEditWidget(
            fileConstraintsComposite,
            maxLength=15,
            width=get_width_of_n_letters(14),
            text="*",
            enabled_precheck_handler=self.enabledPrecheckHandler)

        self.recursively = CheckBoxWidget(
            fileConstraintsComposite,
            i18n="datasource.search.files.recursively.label",
            i18n_def="Search files recursively",
            clicked_handler=self.reload,
            enabled_precheck_handler=self.enabledPrecheckHandler)

        self.onlyKnownTypes = CheckBoxWidget(
            fileConstraintsComposite,
            i18n="datasource.only.known.types.checkbox",
            i18n_def="Only known types",
            checked=True,
            clicked_handler=self.reload,
            enabled_precheck_handler=self.enabledPrecheckHandler)

    def __createReloadButton__(self, parent):
        self.reloadButton = PushButtonWidget(
            parent,
            i18n="datasource.reload.button",
            i18n_def="Reload",
            clicked_handler=self.reload,
            alignment=Qt.AlignRight,
            enabled_precheck_handler=self.enabledPrecheckHandler)

    def __createTableView__(self, parent):
        self.filesTableView = FilesTableView(
            parent,
            model=QStandardItemModel(self),
            onClickedAction=self.onClickedAction,
            wizardButtons=(QWizard.NextButton, ),
            wizard_handler=self.wizard,
            sorting=True,
            enabled_precheck_handler=self.enabledPrecheckHandler)

    def __createFilesOperationsComposite__(self, parent):
        filesOperations = CompositeWidget(parent, layout=QHBoxLayout())

        self.filePreviewButton = PushButtonWidget(
            filesOperations,
            i18n="datasource.file.preview.button",
            i18n_def="File preview",
            stretch_after_widget=1,
            clicked_handler=self.filePreviewAction,
            enabled_precheck_handler=self.enabledPrecheckHandler)

        self.selectAllButton = PushButtonWidget(
            filesOperations,
            i18n="datasource.accept.select.all.button",
            i18n_def="Select all",
            enabled=False,
            clicked_handler=self.__select_all_handler__,
            enabled_precheck_handler=self.enabledPrecheckHandler)

        self.unselectAllButton = PushButtonWidget(
            filesOperations,
            i18n="datasource.accept.unselect.all.button",
            i18n_def="Unselect all",
            enabled=False,
            clicked_handler=self.__unselect_all_handler__,
            enabled_precheck_handler=self.enabledPrecheckHandler)

    def chooseRootDirAction(self):
        SettingsFactory.loadSettings(self, Setter(rootDir=None))

        rootDir = QFileDialog.getExistingDirectory(
            self,
            caption=self.chooseRootDirButton.text(),
            directory=self.rootDir)
        if rootDir:
            self.rootDir = rootDir + os.path.sep
            SettingsFactory.saveSettings(self, Setter(rootDir=self.rootDir))
            self.rootDirLabel.setText(self.rootDir)
            self.reload()

    def __select_all_handler__(self):
        self.__change_selection__(True)

    def __unselect_all_handler__(self):
        self.__change_selection__(False)

    def __change_selection__(self, _select):
        self.changeEnablemend(False)
        count = self.filesTableView.getRowCount()
        progressManager = ProgressDialogManager(
            self,
            label_text=("Selecting..." if _select else "Unselecting..."),
            max_value=count)
        with progressManager as progress:
            for idx in range(count):
                if (progress.wasCanceled()):
                    break
                progress.increaseCounter()
                if _select:
                    self.filesTableView.setCheckedRowState(idx, Qt.Checked)
                else:
                    self.filesTableView.setCheckedRowState(idx, Qt.Unchecked)
        self.filesTableView.changeCompleteState()
        self.changeEnablemend(True)

    def filePreviewAction(self):
        showFilesPreviewDialog(
            self.filesTableView.getSelectedPathAndFilename())

    def reload(self):
        self.changeEnablemend(True)
        if self.rootDirLabel.text():

            self.filesTableView.clear()
            self.changeEnablemend(False)

            iteratorFlag = QDirIterator.Subdirectories \
                            if self.recursively.isChecked() \
                            else QDirIterator.NoIteratorFlags
            nameFilters = QStringList(
                    self.filesExtension.text()) \
                    if len(self.filesExtension.text()) > 0 \
                            and not self.filesExtension.text() \
                                in ("*", "*.*", "", None) \
                    else QStringList()
            self.iterator = QDirIterator(self.rootDirLabel.text(), nameFilters,
                                         QDir.Filters(QDir.Files),
                                         iteratorFlag)

            with ProgressDialogManager(self) as progress:
                while (self.iterator.next()):
                    if (progress.wasCanceled()):
                        break
                    fileInfo = self.iterator.fileInfo()
                    if fileInfo.size() == 0 or fileInfo.isFile() == False:
                        continue
                    if self.filesExtension.text() in ("*", "*.*", "", None):
                        if (sys.platform == 'win32' \
                            and fileInfo.isExecutable() == True) \
                            or is_text_file(fileInfo.filePath(),
                                    self.onlyKnownTypes.checkState()) == False:
                            continue
                    progress.increaseCounter()

                    checkable = QStandardItem("")
                    checkable.setCheckable(True)
                    filename = QStandardItem(fileInfo.fileName())
                    progress.setLabelText(fileInfo.fileName())
                    size = QStandardItem(str(fileInfo.size()))
                    path = QStandardItem(fileInfo.path())
                    self.filesTableView.addRow(
                        (checkable, filename, size, path))  # @IgnorePep8

            self.filesTableView.resizeColumnsToContents()
            self.filesExtension.setFocus()
            self.changeEnablemend(True)

    def onClickedAction(self, idx):
        self.filePreviewButton.setEnabled(True)
        self.filesTableView.onClickedAction(idx)

    def isComplete(self):
        """
        method used by QWizard to check if next/previous buttons have to
        be disabled/enabled (when False/True is returned)
        """
        return self.filesTableView.isCompletedCount()

    def changeEnablemend(self, enabled):
        self.emit(SIGNAL(ENABLED_SIGNAL_NAME), enabled)
        self.chooseRootDirButton.setEnabled(enabled)

    def enabledPrecheckHandler(self, widget):
        """
        only interested widgets return bool value others none value
        """
        if widget in (self.selectAllButton, self.unselectAllButton):
            return self.filesTableView.count() > 0
        elif widget == self.filePreviewButton:
            return self.filesTableView.getSelectedRowCount() > 0

    def getDatasourceModel(self):
        return self.filesTableView.getModel()
class ChooseDatasourcePage(QWizardPage):

    def __init__(self, _parent):
        QWizardPage.__init__(self, parent=_parent)

    def initializePage(self):
        title_I18N(self, "datasource.page.title", "Datasource chooser")
        #self.setSubTitle('Setup frame specific data')
        pageLayout = QVBoxLayout()
        self.setLayout(pageLayout)
        self.__createFilesGroupBox(pageLayout)

        #to force call of isComplete(self) method by the Wizard framework
        #which causes state next button to be updated
        self.emit(WIZARD_COMPLETE_CHANGED_SIGNAL)
        self.rootDir = None

    def __createFilesGroupBox(self, pageLayout):
        self.filesGroupBox = GroupBoxWidget(self,
                                    i18n="datasource.files.group.title",
                                    i18n_def="Files",
                                    layout=QVBoxLayout())

        self.__createFileConstraintsComposite__(self.filesGroupBox)

        self.__createReloadButton__(self.filesGroupBox)

        self.__createTableView__(self.filesGroupBox)

        self.__createFilesOperationsComposite__(self.filesGroupBox)

        self.changeEnablemend(False)
        self.chooseRootDirButton.setEnabled(True)

    def __createFileConstraintsComposite__(self, parent):
        fileConstraintsComposite = CompositeWidget(parent,
                                                   layout=QHBoxLayout())

        self.chooseRootDirButton = PushButtonWidget(fileConstraintsComposite,
                        i18n="datasource.datasource.choose.root.dir.button",
                        i18n_def="Choose root dir",
                        clicked_handler=self.chooseRootDirAction)

        LabelWidget(fileConstraintsComposite,
                     i18n="datasource.root.dir.label",
                     i18n_def="Root dir:")
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self.rootDirLabel = LabelWidget(fileConstraintsComposite,
                                        i18n="datasource.root.dir.label",
                                        i18n_def="[Not set]",
                                        sizePolicy=sizePolicy,
                                        stretch_after_widget=1)

        LabelWidget(fileConstraintsComposite,
                    i18n="datasource.file.name.filter.label",
                    i18n_def="Files name filter")

        self.filesExtension = LineEditWidget(fileConstraintsComposite,
                        maxLength=15,
                        width=get_width_of_n_letters(14),
                        text="*",
                        enabled_precheck_handler=self.enabledPrecheckHandler)

        self.recursively = CheckBoxWidget(fileConstraintsComposite,
                        i18n="datasource.search.files.recursively.label",
                        i18n_def="Search files recursively",
                        clicked_handler=self.reload,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

        self.onlyKnownTypes = CheckBoxWidget(fileConstraintsComposite,
                        i18n="datasource.only.known.types.checkbox",
                        i18n_def="Only known types",
                        checked=True,
                        clicked_handler=self.reload,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

    def __createReloadButton__(self, parent):
        self.reloadButton = PushButtonWidget(parent,
                        i18n="datasource.reload.button",
                        i18n_def="Reload",
                        clicked_handler=self.reload,
                        alignment=Qt.AlignRight,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

    def __createTableView__(self, parent):
        self.filesTableView = FilesTableView(parent,
                        model=QStandardItemModel(self),
                        onClickedAction=self.onClickedAction,
                        wizardButtons=(QWizard.NextButton,),
                        wizard_handler=self.wizard,
                        sorting=True,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

    def __createFilesOperationsComposite__(self, parent):
        filesOperations = CompositeWidget(parent,
                                            layout=QHBoxLayout())

        self.filePreviewButton = PushButtonWidget(filesOperations,
                        i18n="datasource.file.preview.button",
                        i18n_def="File preview",
                        stretch_after_widget=1,
                        clicked_handler=self.filePreviewAction,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

        self.selectAllButton = PushButtonWidget(filesOperations,
                        i18n="datasource.accept.select.all.button",
                        i18n_def="Select all",
                        enabled=False,
                        clicked_handler=self.__select_all_handler__,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

        self.unselectAllButton = PushButtonWidget(filesOperations,
                        i18n="datasource.accept.unselect.all.button",
                        i18n_def="Unselect all",
                        enabled=False,
                        clicked_handler=self.__unselect_all_handler__,
                        enabled_precheck_handler=self.enabledPrecheckHandler)

    def chooseRootDirAction(self):
        SettingsFactory.loadSettings(self, Setter(rootDir=None))

        rootDir = QFileDialog.getExistingDirectory(self,
                                    caption=self.chooseRootDirButton.text(),
                                    directory=self.rootDir)
        if rootDir:
            self.rootDir = rootDir + os.path.sep
            SettingsFactory.saveSettings(self, Setter(rootDir=self.rootDir))
            self.rootDirLabel.setText(self.rootDir)
            self.reload()

    def __select_all_handler__(self):
        self.__change_selection__(True)

    def __unselect_all_handler__(self):
        self.__change_selection__(False)

    def __change_selection__(self, _select):
        self.changeEnablemend(False)
        count = self.filesTableView.getRowCount()
        progressManager = ProgressDialogManager(self,
                label_text=("Selecting..." if _select else "Unselecting..."),
                max_value=count)
        with progressManager as progress:
            for idx in range(count):
                if (progress.wasCanceled()):
                    break
                progress.increaseCounter()
                if _select:
                    self.filesTableView.setCheckedRowState(idx, Qt.Checked)
                else:
                    self.filesTableView.setCheckedRowState(idx, Qt.Unchecked)
        self.filesTableView.changeCompleteState()
        self.changeEnablemend(True)

    def filePreviewAction(self):
        showFilesPreviewDialog(
                    self.filesTableView.getSelectedPathAndFilename())

    def reload(self):
        self.changeEnablemend(True)
        if self.rootDirLabel.text():

            self.filesTableView.clear()
            self.changeEnablemend(False)

            iteratorFlag = QDirIterator.Subdirectories \
                            if self.recursively.isChecked() \
                            else QDirIterator.NoIteratorFlags
            nameFilters = QStringList(
                    self.filesExtension.text()) \
                    if len(self.filesExtension.text()) > 0 \
                            and not self.filesExtension.text() \
                                in ("*", "*.*", "", None) \
                    else QStringList()
            self.iterator = QDirIterator(
                                self.rootDirLabel.text(),
                                nameFilters,
                                QDir.Filters(QDir.Files),
                                iteratorFlag)

            with ProgressDialogManager(self) as progress:
                while(self.iterator.next()):
                    if (progress.wasCanceled()):
                        break
                    fileInfo = self.iterator.fileInfo()
                    if fileInfo.size() == 0 or fileInfo.isFile() == False:
                        continue
                    if self.filesExtension.text() in ("*", "*.*", "", None):
                        if (sys.platform == 'win32' \
                            and fileInfo.isExecutable() == True) \
                            or is_text_file(fileInfo.filePath(),
                                    self.onlyKnownTypes.checkState()) == False:
                            continue
                    progress.increaseCounter()

                    checkable = QStandardItem("")
                    checkable.setCheckable(True)
                    filename = QStandardItem(fileInfo.fileName())
                    progress.setLabelText(fileInfo.fileName())
                    size = QStandardItem(str(fileInfo.size()))
                    path = QStandardItem(fileInfo.path())
                    self.filesTableView.addRow((checkable, filename, size, path)) # @IgnorePep8

            self.filesTableView.resizeColumnsToContents()
            self.filesExtension.setFocus()
            self.changeEnablemend(True)

    def onClickedAction(self, idx):
        self.filePreviewButton.setEnabled(True)
        self.filesTableView.onClickedAction(idx)

    def isComplete(self):
        """
        method used by QWizard to check if next/previous buttons have to
        be disabled/enabled (when False/True is returned)
        """
        return self.filesTableView.isCompletedCount()

    def changeEnablemend(self, enabled):
        self.emit(SIGNAL(ENABLED_SIGNAL_NAME), enabled)
        self.chooseRootDirButton.setEnabled(enabled)

    def enabledPrecheckHandler(self, widget):
        """
        only interested widgets return bool value others none value
        """
        if widget in (self.selectAllButton, self.unselectAllButton):
            return self.filesTableView.count() > 0
        elif widget == self.filePreviewButton:
            return self.filesTableView.getSelectedRowCount() > 0

    def getDatasourceModel(self):
        return self.filesTableView.getModel()