Example #1
0
    def __init__(self, parent=None):
        super(CSVFileSelector, self).__init__()

        self.file = None
        self.collection = None

        # Creating ui elements
        self.resize(400, 135)
        self.setWindowTitle(self.tr("Select a CSV"))
        self.setObjectName(QStringU8("CSVFileSelector"))
        self.mainlayout = QtGui.QHBoxLayout(self)
        self.icon = QtGui.QLabel()
        self.icon.setPixmap(QtGui.QPixmap(':/csvbgg.png'))
        self.mainlayout.addWidget(self.icon)

        self.layout = QtGui.QVBoxLayout()
        self.label = QtGui.QLabel(self.tr(
            QStringU8("Select the CSV file to import:")))
        self.layout.addWidget(self.label)
        self.file_selector = FileSelector(self, 'CSV (*.csv)')
        self.layout.addWidget(self.file_selector)
        self.label2 = QtGui.QLabel(self.tr(
            QStringU8("To the folder:")))
        self.layout.addWidget(self.label2)
        self.collections = QtGui.QComboBox()

        self.layout.addWidget(self.collections)
        self.mainlayout.addLayout(self.layout)
        self.options = QtGui.QDialogButtonBox(self)
        self.options.setOrientation(QtCore.Qt.Horizontal)
        self.options.setStandardButtons(QtGui.QDialogButtonBox.Cancel |
                                        QtGui.QDialogButtonBox.Ok)
        self.options.setObjectName(QStringU8("options"))
        self.layout.addWidget(self.options)

        # Add collections to the combo box
        man = Collector.get_instance().get_manager('collection')
        for i in man.collections.values():
            self.collections.addItem(i.get_name(), i.get_id())
        # Connect things
        self.options.rejected.connect(self.reject)
        self.options.accepted.connect(self.accept)
Example #2
0
class CSVFileSelector(QtGui.QDialog):
    """Widget to obtain a CSV File"""

    def __init__(self, parent=None):
        super(CSVFileSelector, self).__init__()

        self.file = None
        self.collection = None

        # Creating ui elements
        self.resize(400, 135)
        self.setWindowTitle(self.tr("Select a CSV"))
        self.setObjectName(QStringU8("CSVFileSelector"))
        self.mainlayout = QtGui.QHBoxLayout(self)
        self.icon = QtGui.QLabel()
        self.icon.setPixmap(QtGui.QPixmap(':/csvbgg.png'))
        self.mainlayout.addWidget(self.icon)

        self.layout = QtGui.QVBoxLayout()
        self.label = QtGui.QLabel(self.tr(
            QStringU8("Select the CSV file to import:")))
        self.layout.addWidget(self.label)
        self.file_selector = FileSelector(self, 'CSV (*.csv)')
        self.layout.addWidget(self.file_selector)
        self.label2 = QtGui.QLabel(self.tr(
            QStringU8("To the folder:")))
        self.layout.addWidget(self.label2)
        self.collections = QtGui.QComboBox()

        self.layout.addWidget(self.collections)
        self.mainlayout.addLayout(self.layout)
        self.options = QtGui.QDialogButtonBox(self)
        self.options.setOrientation(QtCore.Qt.Horizontal)
        self.options.setStandardButtons(QtGui.QDialogButtonBox.Cancel |
                                        QtGui.QDialogButtonBox.Ok)
        self.options.setObjectName(QStringU8("options"))
        self.layout.addWidget(self.options)

        # Add collections to the combo box
        man = Collector.get_instance().get_manager('collection')
        for i in man.collections.values():
            self.collections.addItem(i.get_name(), i.get_id())
        # Connect things
        self.options.rejected.connect(self.reject)
        self.options.accepted.connect(self.accept)

    def accept(self):
        """Saves the file path and accept"""
        self.file = self.file_selector.get_value()
        self.collection = self.collections.itemData(
            self.collections.currentIndex
        )
        if os.path.exists(self.file):
            super(CSVFileSelector, self).accept()
        else:
            self.file = None
            # Launch error message
            QtGui.QMessageBox.warning(
                self,
                self.tr("Collector"),
                self.tr("Please select an existing file."))